diff --git a/.vscode/settings.json b/.vscode/settings.json index 88215dd..3a4ca01 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -67,7 +67,8 @@ "cinttypes": "cpp", "typeinfo": "cpp", "variant": "cpp", - "qdatetime": "cpp" + "qdatetime": "cpp", + "fstream": "cpp" }, "better-comments.multilineComments": true, diff --git a/ClassDigitizer2Gen.cpp b/ClassDigitizer2Gen.cpp index 68b2cd8..872022a 100644 --- a/ClassDigitizer2Gen.cpp +++ b/ClassDigitizer2Gen.cpp @@ -33,6 +33,7 @@ void Digitizer2Gen::Initialization(){ gateway = ""; outFileIndex = 0; + FinishedOutFilesSize = 0; dataStartIndetifier = 0xAAA0; outFile = NULL; outFileSize = 0; @@ -214,7 +215,11 @@ void Digitizer2Gen::StartACQ(){ SendCommand("/cmd/armacquisition"); // this will also clear data SendCommand("/cmd/swstartacquisition"); - + + outFileIndex = 0; + outFileSize = 0; + FinishedOutFilesSize = 0; + acqON = true; } @@ -500,6 +505,7 @@ void Digitizer2Gen::CloseOutFile(){ void Digitizer2Gen::SaveDataToFile(){ if( outFileSize > (unsigned int) MaxOutFileSize){ + FinishedOutFilesSize += ftell(outFile); fclose(outFile); outFileIndex ++; sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex); diff --git a/ClassDigitizer2Gen.h b/ClassDigitizer2Gen.h index 50b5284..8b48ebc 100644 --- a/ClassDigitizer2Gen.h +++ b/ClassDigitizer2Gen.h @@ -8,7 +8,8 @@ #include "Event.h" -#define MaxOutFileSize 2*1024*1024*1024 +#define MaxOutFileSize 2*1024*1024*1024 //2GB +//#define MaxOutFileSize 20*1024*1024 //20MB #define MaxNumberOfChannel 64 #include "DigiParameters.h" @@ -57,6 +58,7 @@ class Digitizer2Gen { char outFileName[100]; FILE * outFile; unsigned int outFileSize; + uint64_t FinishedOutFilesSize; bool acqON; @@ -117,7 +119,8 @@ class Digitizer2Gen { void OpenOutFile(std::string fileName, const char * mode = "w"); void CloseOutFile(); void SaveDataToFile(); - unsigned int GetFileSize() {return outFileSize;} + unsigned int GetFileSize() const {return outFileSize;} + uint64_t GetTotalFilesSize() const {return FinishedOutFilesSize + outFileSize;} }; diff --git a/mainwindow.cpp b/mainwindow.cpp index 3ba3d01..1ff8d69 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -267,6 +267,9 @@ MainWindow::~MainWindow(){ void MainWindow::StartACQ(){ if( chkSaveRun->isChecked() ){ + runID ++; + leRunID->setText(QString::number(runID)); + runIDStr = QString::number(runID).rightJustified(3, '0'); LogMsg("=========================== Start Run-" + runIDStr + ""); @@ -303,8 +306,13 @@ void MainWindow::StartACQ(){ } //} //TODO ============ elog - + QString elogMsg = "=============== Run-" + runIDStr + "
" + + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "
" + + "comment : " + startComment + "
" + + + "----------------------------------------------"; + WriteElog(elogMsg, "Run-" + runIDStr, "Run", runID); //TODO ============ update expName.sh + WriteExpNameSh(); }else{ LogMsg("=========================== Start no-save Run"); @@ -415,8 +423,15 @@ void MainWindow::StopACQ(){ if( chkSaveRun->isChecked() ){ //TODO ============= elog - runID ++; - leRunID->setText(QString::number(runID)); + QString msg = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "
"; + + for( int i = 0; i < nDigi; i++){ + if( digi[i]->IsDummy () ) continue; + msg += "FileSize ("+ QString::number(digi[i]->GetSerialNumber()) +"): " + QString::number(digi[i]->GetTotalFilesSize()/1024./1024.) + " MB
"; + } + msg += "comment : " + stopComment + "
" + + "======================"; + AppendElog(msg, chromeWindowID); } //if( scalarThread->isRunning()) printf("Scalar Thread still running.\n"); //if( scalarThread->isFinished()) printf("Scalar Thread finsihed.\n"); @@ -463,6 +478,8 @@ void MainWindow::OpenDigitizers(){ readDataThread[i] = new ReadDataThread(digi[i], this); connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg); + //connect(readDataThread[i], &ReadDataThread::checkFileSize, this, &MainWindow::CheckOutFileSize); + //connect(readDataThread[i], &ReadDataThread::endOfLastData, this, &MainWindow::CheckOutFileSize); SetUpScalar(); bnOpenScalar->setEnabled(true); @@ -552,7 +569,6 @@ void MainWindow::OpenDigitizersSettings(){ } //^###################################################################### Open Scaler, when DAQ is running -//TODO ################################# void MainWindow::OpenScaler(){ scalar->show(); } @@ -954,21 +970,21 @@ void MainWindow::SetupInflux(){ void MainWindow::CheckElog(){ - WriteElog("Checking elog writing", "checking", "Testing communication"); + WriteElog("Checking elog writing", "Testing communication", "checking"); if( elogID > 0 ){ LogMsg("Ckecked Elog writing. OK."); //TODO =========== chrome windowID - AppendElog("Check Elog append.", 10485763); + AppendElog("Check Elog append.", chromeWindowID); if( elogID > 0 ){ LogMsg("Checked Elog Append. OK."); }else{ - LogMsg("Checked Elog Append. FAIL. (no elog will be used.)"); + LogMsg("Checked Elog Append. FAIL. (no elog will be used.) "); } }else{ - LogMsg("Ckecked Elog writing. FAIL. (no elog will be used.)"); + LogMsg("Checked Elog Write. FAIL. (no elog will be used.) "); } } @@ -1304,6 +1320,13 @@ void MainWindow::CreateNewExperiment(const QString newExpName){ LogMsg("Creating new Exp. : " + newExpName + ""); + expName = newExpName; + runID = -1; + elogID = 0; + + CreateRawDataFolderAndLink(); + WriteExpNameSh(); + //@----- git must be clean //----- creat new git branch if( useGit ){ @@ -1322,21 +1345,6 @@ void MainWindow::CreateNewExperiment(const QString newExpName){ } } - CreateRawDataFolderAndLink(newExpName); - - //----- create the expName.sh - QFile file2(analysisPath + "/expName.sh"); - - file2.open(QIODevice::Text | QIODevice::WriteOnly); - file2.write(("expName = "+ newExpName + "\n").toStdString().c_str()); - file2.write(("rawDataPath = "+ rawDataFolder + "\n").toStdString().c_str()); - file2.write("runID = 0\n"); - file2.write("elogID = 0\n"); - file2.write("//------------end of file."); - file2.close(); - LogMsg("Saved expName.sh to "+ analysisPath + "/expName.sh."); - - //----- create git branch if( useGit ){ QProcess git; @@ -1350,10 +1358,6 @@ void MainWindow::CreateNewExperiment(const QString newExpName){ LogMsg("Commit branch : " + newExpName + " as \"initial commit\""); } - expName = newExpName; - runID = 0; - elogID = 0; - leRawDataPath->setText(rawDataFolder); leExpName->setText(expName); leRunID->setText(QString::number(runID)); @@ -1375,27 +1379,54 @@ void MainWindow::ChangeExperiment(const QString newExpName){ LogMsg("Swicted to branch : " + newExpName + ""); - CreateRawDataFolderAndLink(newExpName); - + expName = newExpName; + CreateRawDataFolderAndLink(); LoadExpSettings(); } -void MainWindow::CreateRawDataFolderAndLink(const QString newExpName){ +void MainWindow::WriteExpNameSh(){ + //----- create the expName.sh + QFile file2(analysisPath + "/expName.sh"); + + file2.open(QIODevice::Text | QIODevice::WriteOnly); + file2.write(("expName="+ expName + "\n").toStdString().c_str()); + file2.write(("rawDataPath="+ rawDataFolder + "\n").toStdString().c_str()); + file2.write(("runID="+std::to_string(runID)+"\n").c_str()); + file2.write(("elogID="+std::to_string(elogID)+"\n").c_str()); + file2.write("//------------end of file."); + file2.close(); + LogMsg("Saved expName.sh to "+ analysisPath + "/expName.sh."); + +} + +void MainWindow::CreateRawDataFolderAndLink(){ //----- create data folder - rawDataFolder = dataPath + "/" + newExpName; + rawDataFolder = dataPath + "/" + expName; QDir dir; if( !dir.exists(rawDataFolder)){ if( dir.mkdir(rawDataFolder)){ LogMsg("" + rawDataFolder + " created." ); }else{ - LogMsg("" + rawDataFolder + " cannot be created. Access right problem?" ); + LogMsg("" + rawDataFolder + " cannot be created. Access right problem? " ); } }else{ LogMsg("" + rawDataFolder + " already exist." ); } + //----- create analysis Folder + QDir anaDir; + if( !anaDir.exists(analysisPath)){ + if( anaDir.mkdir(analysisPath)){ + LogMsg("" + analysisPath + " created." ); + }else{ + LogMsg("" + analysisPath + " cannot be created. Access right problem?" ); + } + }else{ + LogMsg("" + analysisPath + " already exist."); + } + //----- create symbloic link QString linkName = analysisPath + "/data_raw"; QFile file; @@ -1407,7 +1438,7 @@ void MainWindow::CreateRawDataFolderAndLink(const QString newExpName){ if (file.link(rawDataFolder, linkName)) { LogMsg("Symbolic link " + linkName +" -> " + rawDataFolder + " created."); } else { - LogMsg("Symbolic link " + linkName +" -> " + rawDataFolder + " cannot be created."); + LogMsg("Symbolic link " + linkName +" -> " + rawDataFolder + " cannot be created. "); } } @@ -1426,15 +1457,18 @@ void MainWindow::LogMsg(QString msg){ logInfo->repaint(); } -void MainWindow::WriteElog(QString htmlText, QString category, QString subject){ +void MainWindow::WriteElog(QString htmlText, QString subject, QString category, int runNumber){ if( elogID < 0 ) return; if( expName == "" ) return; QStringList arg; arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralFSU" << "fsuphysics-888" - << "-a" << "Author=GeneralFSU" << "-a" << "Category=" + category - << "-a" << "Subject=" + subject + << "-a" << "Author=GeneralFSU" ; + if( runNumber > 0 ) arg << "-a" << "Run=" + QString::number(runNumber); + if( category != "" ) arg << "-a" << "Category=" + category; + + arg << "-a" << "Subject=" + subject << "-n " << "2" << htmlText ; QProcess elogBash(this); diff --git a/mainwindow.h b/mainwindow.h index 6a0dd37..7aa9928 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,7 +19,6 @@ #include #include // time in nano-sec - #include "ClassDigitizer2Gen.h" #include "influxdb.h" @@ -28,6 +27,8 @@ #include "digiSettings.h" #include "scope.h" +const int chromeWindowID = 10485763; + //^#===================================================== MainWindow class MainWindow : public QMainWindow{ Q_OBJECT @@ -64,7 +65,8 @@ private slots: bool LoadExpSettings(); void CreateNewExperiment(const QString newExpName); void ChangeExperiment(const QString newExpName); - void CreateRawDataFolderAndLink(const QString newExpName); + void WriteExpNameSh(); + void CreateRawDataFolderAndLink(); void closeEvent(QCloseEvent * event){ if( digiSetting != NULL ) digiSetting->close(); @@ -72,7 +74,7 @@ private slots: event->accept(); } - void WriteElog(QString htmlText, QString category = "", QString subject = ""); + void WriteElog(QString htmlText, QString subject = "", QString category = "", int runNumber = 0); void AppendElog(QString appendHtmlText, int screenID = -1); signals : @@ -151,7 +153,7 @@ private: bool useGit; QString expName; QString rawDataFolder; - unsigned int runID; + int runID; QString runIDStr; int elogID; // 0 = ready, -1 = disable, >1 = elogID diff --git a/manyThread.h b/manyThread.h index ce8fcb9..81ae73b 100644 --- a/manyThread.h +++ b/manyThread.h @@ -29,6 +29,7 @@ public: if( isSaveData) digi->SaveDataToFile(); }else if(ret == CAEN_FELib_Stop){ digi->ErrorMsg("No more data"); + //emit endOfLastData(); break; }else{ //digi->ErrorMsg("ReadDataLoop()"); @@ -38,8 +39,8 @@ public: if( isSaveData ){ clock_gettime(CLOCK_REALTIME, &tb); if( tb.tv_sec - ta.tv_sec > 2 ) { - emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB"); - + emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetTotalFilesSize()/1024./1024.) + " MB"); + //emit checkFileSize(); //double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9; //printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration); ta = tb; @@ -49,6 +50,8 @@ public: } signals: void sendMsg(const QString &msg); + //void endOfLastData(); + //void checkFileSize(); private: Digitizer2Gen * digi; timespec ta, tb;