diff --git a/CustomThreads.h b/CustomThreads.h index 4f2c823..3aea96e 100644 --- a/CustomThreads.h +++ b/CustomThreads.h @@ -19,10 +19,13 @@ public: this->ID = digiID; isSaveData = false; stop = false; + canSendMsg = true; } + void SuppressFileSizeMsg() {canSendMsg = false;} void Stop(){ this->stop = true;} void SetSaveData(bool onOff) {this->isSaveData = onOff;} void run(){ + canSendMsg = true; stop = false; clock_gettime(CLOCK_REALTIME, &ta); emit sendMsg("Digi-" + QString::number(digi->GetSerialNumber()) + " ReadDataThread started."); @@ -43,7 +46,7 @@ public: digi->hit->ClearTrace(); } - if( isSaveData ){ + if( isSaveData && canSendMsg ){ clock_gettime(CLOCK_REALTIME, &tb); if( tb.tv_sec - ta.tv_sec > 2 ) { emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetTotalFilesSize()/1024./1024.) + " MB"); @@ -66,7 +69,7 @@ private: Digitizer2Gen * digi; int ID; timespec ta, tb; - bool isSaveData, stop; + bool isSaveData, stop, canSendMsg; }; //^#======================================================= Timing Thread, for some action need to be done periodically diff --git a/mainwindow.cpp b/mainwindow.cpp index e69b2fc..dcfdce4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -42,7 +42,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ runTimer = new QTimer(); needManualComment = true; - isRunning = false; + isACQRunning = false; { scalarOutputInflux = false; @@ -219,7 +219,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ runTimer->stop(); StopACQ(); - if( !isRunning ){ + if( !isACQRunning ){ bnStartACQ->setEnabled(true); bnStopACQ->setEnabled(false); bnComment->setEnabled(false); @@ -415,16 +415,6 @@ int MainWindow::StartACQ(){ startComment = "AutoRun for " + cbAutoRun->currentText(); leRunComment->setText(startComment); } - // ============ elog - QString elogMsg = "=============== Run-" + runIDStr + "
" - + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "
" - + "comment : " + startComment + "
" + - + "----------------------------------------------"; - WriteElog(elogMsg, "Run-" + runIDStr, "Run", runID); - // ============ update expName.sh - WriteExpNameSh(); - - WriteRunTimeStampDat(true); }else{ LogMsg("=========================== Start no-save Run"); @@ -461,7 +451,21 @@ int MainWindow::StartACQ(){ //TODO ========================== Sync start. readDataThread[i]->SetSaveData(chkSaveRun->isChecked()); readDataThread[i]->start(); + } + if(chkSaveRun->isChecked() ){ + QString startTimeStr = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss"); + LogMsg(" All Digitizers started. "); + // ============ elog + QString elogMsg = "=============== Run-" + runIDStr + "
" + + startTimeStr + "
" + + "comment : " + startComment + "
" + + + "----------------------------------------------"; + WriteElog(elogMsg, "Run-" + runIDStr, "Run", runID); + // ============ update expName.sh + WriteExpNameSh(); + + WriteRunTimeStampDat(true, startTimeStr); } if( influx ){ @@ -477,7 +481,7 @@ int MainWindow::StartACQ(){ scalar->show(); if( !scalarThread->isRunning() ) scalarThread->start(); } - isRunning = True; + isACQRunning = True; lbScalarACQStatus->setText("ACQ On"); //scalarThread->start(); scalarOutputInflux = true; @@ -488,6 +492,10 @@ int MainWindow::StartACQ(){ void MainWindow::StopACQ(){ + if( !isACQRunning ) return; + + bnStopACQ->setEnabled(false); + if( chkSaveRun->isChecked() ){ //============ stop comment if( needManualComment ){ @@ -531,10 +539,33 @@ void MainWindow::StopACQ(){ for( int i = nDigi - 1; i >= 0; i--){ if( digi[i]->IsDummy () ) continue; digi[i]->StopACQ(); + readDataThread[i]->SuppressFileSizeMsg(); } + isACQRunning = false; + lbScalarACQStatus->setText("ACQ Off"); + QString stopTimeStr = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss"); scalarOutputInflux = false; + if( chkSaveRun->isChecked() ){ + LogMsg("=========================== Run-" + runIDStr + " stopped."); + LogMsg("Please wait for collecting all remaining data."); + WriteRunTimeStampDat(false, stopTimeStr); + + // ============= elog + QString msg = stopTimeStr + "
"; + 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); + + }else{ + LogMsg("=========================== no-Save Run stopped."); + } + if( influx ){ influx->ClearDataPointsBuffer(); if( chkSaveRun->isChecked() ){ @@ -544,31 +575,6 @@ void MainWindow::StopACQ(){ influx->WriteData(DatabaseName.toStdString()); } - if( chkSaveRun->isChecked() ){ - LogMsg("=========================== Run-" + runIDStr + " stopped."); - LogMsg("Please wait for collecting all remaining data."); - WriteRunTimeStampDat(false); - - // ============= elog - 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); - - LogMsg("Run " + programSettingsPath + "/scripts/endRunScript.sh" ); - QProcess::startDetached(programSettingsPath + "/scripts/endRunScript.sh"); - - }else{ - LogMsg("=========================== no-Save Run stopped."); - } - - isRunning = false; - lbScalarACQStatus->setText("ACQ Off"); - if( !chkSaveRun->isChecked() ) LogMsg("Collecting remaining data from the digitizers... "); for( int i = nDigi -1; i >=0; i--){ if( readDataThread[i]->isRunning()){ @@ -582,6 +588,13 @@ void MainWindow::StopACQ(){ } } + if( chkSaveRun->isChecked() ){ + LogMsg("Run " + programSettingsPath + "/scripts/endRunScript.sh" ); + QProcess::startDetached(programSettingsPath + "/scripts/endRunScript.sh"); + } + + LogMsg("SOLARIS DAQ is ready for next run."); + } void MainWindow::AutoRun(){ @@ -1097,7 +1110,7 @@ void MainWindow::UpdateAllPanel(int panelID){ //^###################################################################### Open Scaler, when DAQ is running void MainWindow::OpenScaler(){ scalar->show(); - if( isRunning ) { + if( isACQRunning ) { lbScalarACQStatus->setText("ACQ On"); }else{ lbScalarACQStatus->setText("ACQ Off"); @@ -2247,17 +2260,16 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){ } -void MainWindow::WriteRunTimeStampDat(bool isStartRun){ +void MainWindow::WriteRunTimeStampDat(bool isStartRun, QString timeStr){ QFile file(dataPath + "/" + expName + "/RunTimeStamp.dat"); - QString dateTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss"); if( file.open(QIODevice::Text | QIODevice::WriteOnly | QIODevice::Append) ){ if( isStartRun ){ - file.write(("Start Run | " + QString::number(runID) + " | " + dateTime + " | " + startComment + "\n").toStdString().c_str()); + file.write(("Start Run | " + QString::number(runID) + " | " + timeStr + " | " + startComment + "\n").toStdString().c_str()); }else{ - file.write((" Stop Run | " + QString::number(runID) + " | " + dateTime + " | " + stopComment + "\n").toStdString().c_str()); + file.write((" Stop Run | " + QString::number(runID) + " | " + timeStr + " | " + stopComment + "\n").toStdString().c_str()); } file.close(); @@ -2271,9 +2283,9 @@ void MainWindow::WriteRunTimeStampDat(bool isStartRun){ QTextStream out(&fileCSV); if( isStartRun){ - out << QString::number(runID) + "," + dateTime + "," + startComment; + out << QString::number(runID) + "," + timeStr + "," + startComment; }else{ - out << "," + dateTime + "," + stopComment + "\n"; + out << "," + timeStr + "," + stopComment + "\n"; } fileCSV.close(); diff --git a/mainwindow.h b/mainwindow.h index f66a119..8ceccaf 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -86,7 +86,7 @@ private slots: void WriteElog(QString htmlText, QString subject = "", QString category = "", int runNumber = 0); void AppendElog(QString appendHtmlText, int screenID = -1); - void WriteRunTimeStampDat(bool isStartRun); + void WriteRunTimeStampDat(bool isStartRun, QString timeStr); signals : @@ -144,7 +144,7 @@ private: QString stopComment; QString appendComment; bool needManualComment; - bool isRunning; + bool isACQRunning; QTimer * runTimer; QElapsedTimer elapsedTimer; unsigned int autoRunStartRunID;