diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index ba03401..a158977 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -31,6 +31,7 @@ FSUDAQ::FSUDAQ(QWidget *parent) : QMainWindow(parent){ digi = nullptr; nDigi = 0; + isACQStarted= false; scalar = nullptr; scalarUpdateTimeMilliSec = 1000; @@ -1002,6 +1003,88 @@ void FSUDAQ::SetupScalar(){ } +void FSUDAQ::UpdateScalar(){ + + DebugPrint("%s", "FSUDAQ"); + + // printf("================== FSUDAQ::%s\n", __func__); + + if( digi == nullptr ) return; + if( scalar == nullptr ) return; + //if( !scalar->isVisible() ) return; + + // digi[0]->GetData()->PrintAllData(); + + // lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss")); + lbLastUpdateTime->setText(QDateTime::currentDateTime().toString("MM/dd hh:mm:ss")); + scalarCount ++; + + uint64_t totalFileSize = 0; + for( unsigned int iDigi = 0; iDigi < nDigi; iDigi++){ + // printf("======== digi-%d\n", iDigi); + if( digi[iDigi]->IsBoardDisabled() ) continue; + + uint32_t acqStatus = digi[iDigi]->GetACQStatusFromMemory(); + //printf("Digi-%d : acq on/off ? : %d \n", digi[iDigi]->GetSerialNumber(), (acqStatus >> 2) & 0x1 ); + if( ( acqStatus >> 2 ) & 0x1 ){ + if( runStatus[iDigi]->styleSheet() == "") runStatus[iDigi]->setStyleSheet("background-color : green;"); + }else{ + if( runStatus[iDigi]->styleSheet() != "") runStatus[iDigi]->setStyleSheet(""); + } + + if(digiSettings && digiSettings->isVisible() && digiSettings->GetTabID() == iDigi) digiSettings->UpdateACQStatus(acqStatus); + + // digiMTX[iDigi].lock(); + + QString blockCountStr = QString::number(digi[iDigi]->GetData()->AggCount); + blockCountStr += "/" + QString::number(readDataThread[iDigi]->GetReadCount()); + readDataThread[iDigi]->SetReadCountZero(); + lbAggCount[iDigi]->setText(blockCountStr); + lbFileSize[iDigi]->setText(QString::number(digi[iDigi]->GetData()->GetTotalFileSize()/1024./1024., 'f', 3) + " MB"); + + digi[iDigi]->GetData()->CalTriggerRate(); //this will reset NumEventDecode & AggCount + if( chkSaveData->isChecked() ) totalFileSize += digi[iDigi]->GetData()->GetTotalFileSize(); + for( int i = 0; i < digi[iDigi]->GetNumInputCh(); i++){ + QString a = ""; + QString b = ""; + + if( digi[iDigi]->GetInputChannelOnOff(i) == true ) { + // printf(" %3d %2d | %7.2f %7.2f \n", digi[iDigi]->GetSerialNumber(), i, digi[iDigi]->GetData()->TriggerRate[i], digi[iDigi]->GetData()->NonPileUpRate[i]); + QString a = QString::number(digi[iDigi]->GetData()->TriggerRate[i], 'f', 2); + QString b = QString::number(digi[iDigi]->GetData()->NonPileUpRate[i], 'f', 2); + leTrigger[iDigi][i]->setText(a); + leAccept[iDigi][i]->setText(b); + + if( influx && chkInflux->isChecked() && a != "inf" ){ + influx->AddDataPoint("TrigRate,Bd="+std::to_string(digi[iDigi]->GetSerialNumber()) + ",Ch=" + QString::number(i).rightJustified(2, '0').toStdString() + " value=" + a.toStdString()); + } + + } + } + + // digiMTX[iDigi].unlock(); + // printf("============= end of FSUDAQ::%s\n", __func__); + + } + + lbTotalFileSize->setText("Total Data Size : " + QString::number(totalFileSize/1024./1024., 'f', 3) + " MB"); + + repaint(); + scalar->repaint(); + + if( influx && chkInflux->isChecked() && scalarCount >= 3){ + if( chkSaveData->isChecked() ) { + influx->AddDataPoint("RunID value=" + std::to_string(runID)); + influx->AddDataPoint("FileSize value=" + std::to_string(totalFileSize)); + } + //nflux->PrintDataPoints(); + influx->WriteData(dataBaseName.toStdString()); + influx->ClearDataPointsBuffer(); + scalarCount = 0; + } + +} + void FSUDAQ::CleanUpScalar(){ DebugPrint("%s", "FSUDAQ"); if( scalar == nullptr) return; @@ -1120,6 +1203,7 @@ void FSUDAQ::StartACQ(){ } } + isACQStarted = true; chkSaveData->setEnabled(false); // bnDigiSettings->setEnabled(false); @@ -1214,6 +1298,7 @@ void FSUDAQ::StopACQ(){ chkSaveData->setEnabled(true); // bnDigiSettings->setEnabled(true); + isACQStarted = false; repaint(); // printf("================ end of %s \n", __func__); @@ -1730,7 +1815,7 @@ void FSUDAQ::OpenAnalyzer(){ if( id == 5 ) onlineAnalyzer = new NeutronGamma(digi, nDigi, rawDataPath); if( id >= 0 ) onlineAnalyzer->show(); - if( scalarThread->isRunning() ) onlineAnalyzer->StartThread(); + if( isACQStarted ) onlineAnalyzer->StartThread(); }else{ @@ -1746,7 +1831,7 @@ void FSUDAQ::OpenAnalyzer(){ if( id >= 0 ){ onlineAnalyzer->show(); onlineAnalyzer->activateWindow(); - if( scalarThread->isRunning() ) onlineAnalyzer->StartThread(); + if( isACQStarted ) onlineAnalyzer->StartThread(); } } diff --git a/FSUDAQ.h b/FSUDAQ.h index 9899361..750a8c3 100644 --- a/FSUDAQ.h +++ b/FSUDAQ.h @@ -49,6 +49,9 @@ public: event->accept(); } +public slots: + void UpdateScalar(); + private slots: void OpenDataPath(); @@ -66,7 +69,6 @@ private slots: void SetupScalar(); void CleanUpScalar(); void OpenScalar(); - // void UpdateScalar(); void StartACQ(); void StopACQ(); @@ -94,11 +96,11 @@ private slots: void SetAndLockInfluxElog(); -// private: -public: +private: Digitizer ** digi; unsigned int nDigi; + bool isACQStarted; QString programSettingsFilePath; QString rawDataPath; @@ -219,85 +221,7 @@ public: public slots: void UpdateScalar(){ - - DebugPrint("%s", "FSUDAQ"); - - // printf("================== FSUDAQ::%s\n", __func__); - - if( SS->digi == nullptr ) return; - if( SS->scalar == nullptr ) return; - //if( !scalar->isVisible() ) return; - - // digi[0]->GetData()->PrintAllData(); - - // lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss")); - SS->lbLastUpdateTime->setText(QDateTime::currentDateTime().toString("MM/dd hh:mm:ss")); - SS->scalarCount ++; - - uint64_t totalFileSize = 0; - for( unsigned int iDigi = 0; iDigi < SS->nDigi; iDigi++){ - // printf("======== digi-%d\n", iDigi); - if( SS->digi[iDigi]->IsBoardDisabled() ) continue; - - uint32_t acqStatus = SS->digi[iDigi]->GetACQStatusFromMemory(); - //printf("Digi-%d : acq on/off ? : %d \n", digi[iDigi]->GetSerialNumber(), (acqStatus >> 2) & 0x1 ); - if( ( acqStatus >> 2 ) & 0x1 ){ - if( SS->runStatus[iDigi]->styleSheet() == "") SS->runStatus[iDigi]->setStyleSheet("background-color : green;"); - }else{ - if( SS->runStatus[iDigi]->styleSheet() != "") SS->runStatus[iDigi]->setStyleSheet(""); - } - - if(SS->digiSettings && SS->digiSettings->isVisible() && SS->digiSettings->GetTabID() == iDigi) SS->digiSettings->UpdateACQStatus(acqStatus); - - // digiMTX[iDigi].lock(); - - QString blockCountStr = QString::number(SS->digi[iDigi]->GetData()->AggCount); - blockCountStr += "/" + QString::number(SS->readDataThread[iDigi]->GetReadCount()); - SS->readDataThread[iDigi]->SetReadCountZero(); - SS->lbAggCount[iDigi]->setText(blockCountStr); - SS->lbFileSize[iDigi]->setText(QString::number(SS->digi[iDigi]->GetData()->GetTotalFileSize()/1024./1024., 'f', 3) + " MB"); - - SS->digi[iDigi]->GetData()->CalTriggerRate(); //this will reset NumEventDecode & AggCount - if( SS->chkSaveData->isChecked() ) totalFileSize += SS->digi[iDigi]->GetData()->GetTotalFileSize(); - for( int i = 0; i < SS->digi[iDigi]->GetNumInputCh(); i++){ - QString a = ""; - QString b = ""; - - if( SS->digi[iDigi]->GetInputChannelOnOff(i) == true ) { - // printf(" %3d %2d | %7.2f %7.2f \n", digi[iDigi]->GetSerialNumber(), i, digi[iDigi]->GetData()->TriggerRate[i], digi[iDigi]->GetData()->NonPileUpRate[i]); - QString a = QString::number(SS->digi[iDigi]->GetData()->TriggerRate[i], 'f', 2); - QString b = QString::number(SS->digi[iDigi]->GetData()->NonPileUpRate[i], 'f', 2); - SS->leTrigger[iDigi][i]->setText(a); - SS->leAccept[iDigi][i]->setText(b); - - if( SS->influx && SS->chkInflux->isChecked() && a != "inf" ){ - SS->influx->AddDataPoint("TrigRate,Bd="+std::to_string(SS->digi[iDigi]->GetSerialNumber()) + ",Ch=" + QString::number(i).rightJustified(2, '0').toStdString() + " value=" + a.toStdString()); - } - - } - } - - // digiMTX[iDigi].unlock(); - // printf("============= end of FSUDAQ::%s\n", __func__); - - } - - SS->lbTotalFileSize->setText("Total Data Size : " + QString::number(totalFileSize/1024./1024., 'f', 3) + " MB"); - - SS->repaint(); - SS->scalar->repaint(); - - if( SS->influx && SS->chkInflux->isChecked() && SS->scalarCount >= 3){ - if( SS->chkSaveData->isChecked() ) { - SS->influx->AddDataPoint("RunID value=" + std::to_string(SS->runID)); - SS->influx->AddDataPoint("FileSize value=" + std::to_string(totalFileSize)); - } - //nflux->PrintDataPoints(); - SS->influx->WriteData(SS->dataBaseName.toStdString()); - SS->influx->ClearDataPointsBuffer(); - SS->scalarCount = 0; - } - + SS->UpdateScalar(); emit workDone(); } diff --git a/SingleSpectra.cpp b/SingleSpectra.cpp index f996fbe..b66be9e 100644 --- a/SingleSpectra.cpp +++ b/SingleSpectra.cpp @@ -233,6 +233,86 @@ void SingleSpectra::ChangeHistView(){ } +void SingleSpectra::FillHistograms(){ + + // printf("%s | %d %d \n", __func__, chkIsFillHistogram->checkState(), isFillingHistograms); + if( chkIsFillHistogram->checkState() == Qt::Unchecked ) return; + if( isFillingHistograms) return; + + isFillingHistograms = true; + timespec t0, t1; + + QVector randomDigiList = generateNonRepeatedCombination(nDigi); + + // qDebug() << randomDigiList; + + for( int i = 0; i < nDigi; i++){ + int ID = randomDigiList[i]; + + QVector randomChList = generateNonRepeatedCombination(digi[ID]->GetNumInputCh()); + + // qDebug() << randomChList; + // digiMTX[ID].lock(); + // digi[ID]->GetData()->PrintAllData(); + + clock_gettime(CLOCK_REALTIME, &t0); + for( int k = 0; k < digi[ID]->GetNumInputCh(); k ++ ){ + int ch = randomChList[k]; + int lastIndex = digi[ID]->GetData()->GetDataIndex(ch); + if( lastIndex < 0 ) continue; + // printf("--- ch %2d | last index %d \n", ch, lastIndex); + + int loopIndex = digi[ID]->GetData()->GetLoopIndex(ch); + + int temp1 = lastIndex + loopIndex * digi[ID]->GetData()->GetDataSize(); + int temp2 = lastFilledIndex[ID][ch] + loopFilledIndex[ID][ch] * digi[ID]->GetData()->GetDataSize() + 1; + + // printf("loopIndx : %d | ID now : %d, ID old : %d \n", loopIndex, temp1, temp2); + + if( temp1 <= temp2 ) continue; + + if( temp1 - temp2 > digi[ID]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k + temp2 = temp1 - digi[ID]->GetData()->GetDataSize(); + lastFilledIndex[ID][ch] = lastIndex; + lastFilledIndex[ID][ch] = loopIndex - 1; + } + + // printf("ch %d | regulated ID now %d new %d | last fill idx %d\n", ch, temp2, temp1, lastFilledIndex[ID][ch]); + + for( int j = 0 ; j <= temp1 - temp2; j ++){ + lastFilledIndex[ID][ch] ++; + if( lastFilledIndex[ID][ch] > digi[ID]->GetData()->GetDataSize() ) { + lastFilledIndex[ID][ch] = 0; + loopFilledIndex[ID][ch] ++; + } + + uShort data = digi[ID]->GetData()->GetEnergy(ch, lastFilledIndex[ID][ch]); + + // printf(" ch: %d, last fill idx : %d | %d \n", ch, lastFilledIndex[ID][ch], data); + + hist[ID][ch]->Fill( data ); + if( digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){ + uShort e2 = digi[ID]->GetData()->GetEnergy2(ch, lastFilledIndex[ID][ch]); + // printf("%u \n", e2); + hist[ID][ch]->Fill( e2, 1); + } + hist2D[ID]->Fill(ch, data); + } + if( histVisibility[ID][ch] ) hist[ID][ch]->UpdatePlot(); + + clock_gettime(CLOCK_REALTIME, &t1); + if( t1.tv_nsec - t0.tv_nsec + (t1.tv_sec - t0.tv_sec)*1e9 > maxFillTimePerDigi * 1e6 ) break; + } + + if( hist2DVisibility[ID] ) hist2D[ID]->UpdatePlot(); + // digiMTX[ID].unlock(); + + } + + isFillingHistograms = false; + +} + void SingleSpectra::SaveSetting(){ DebugPrint("%s", "SingleSpectra"); diff --git a/SingleSpectra.h b/SingleSpectra.h index d8ee115..4e1be36 100644 --- a/SingleSpectra.h +++ b/SingleSpectra.h @@ -43,21 +43,9 @@ public: QVector generateNonRepeatedCombination(int size); - - /// This should be private.... - int lastFilledIndex[MaxNDigitizer][MaxNChannels]; - int loopFilledIndex[MaxNDigitizer][MaxNChannels]; - bool histVisibility[MaxNDigitizer][MaxNChannels]; - bool hist2DVisibility[MaxNDigitizer]; - unsigned short maxFillTimePerDigi; - - bool isFillingHistograms; - Histogram1D * hist[MaxNDigitizer][MaxNChannels]; - Histogram2D * hist2D[MaxNDigitizer]; - - Digitizer ** digi; - unsigned short nDigi; - +public slots: + void FillHistograms(); + void ChangeHistView(); void startWork(){ // printf("timer start\n"); timer->start(maxFillTimeinMilliSec); @@ -68,14 +56,23 @@ public: ClearInternalDataCount(); } - QCheckBox * chkIsFillHistogram; - -public slots: - // void FillHistograms(); - void ChangeHistView(); - private: + Digitizer ** digi; + unsigned short nDigi; + + int lastFilledIndex[MaxNDigitizer][MaxNChannels]; + int loopFilledIndex[MaxNDigitizer][MaxNChannels]; + bool histVisibility[MaxNDigitizer][MaxNChannels]; + bool hist2DVisibility[MaxNDigitizer]; + unsigned short maxFillTimePerDigi; + + bool isFillingHistograms; + Histogram1D * hist[MaxNDigitizer][MaxNChannels]; + Histogram2D * hist2D[MaxNDigitizer]; + + + QCheckBox * chkIsFillHistogram; RComboBox * cbDivision; @@ -106,82 +103,7 @@ public: public slots: void FillHistograms(){ - - // printf("%s | %d %d \n", __func__, SS->chkIsFillHistogram->checkState(), SS->isFillingHistograms); - if( SS->chkIsFillHistogram->checkState() == Qt::Unchecked ) return; - if( SS->isFillingHistograms) return; - - SS->isFillingHistograms = true; - timespec t0, t1; - - QVector randomDigiList = SS->generateNonRepeatedCombination(SS->nDigi); - - // qDebug() << randomDigiList; - - for( int i = 0; i < SS->nDigi; i++){ - int ID = randomDigiList[i]; - - QVector randomChList = SS->generateNonRepeatedCombination(SS->digi[ID]->GetNumInputCh()); - - // qDebug() << randomChList; - // digiMTX[ID].lock(); - // digi[ID]->GetData()->PrintAllData(); - - clock_gettime(CLOCK_REALTIME, &t0); - for( int k = 0; k < SS->digi[ID]->GetNumInputCh(); k ++ ){ - int ch = randomChList[k]; - int lastIndex = SS->digi[ID]->GetData()->GetDataIndex(ch); - if( lastIndex < 0 ) continue; - // printf("--- ch %2d | last index %d \n", ch, lastIndex); - - int loopIndex = SS->digi[ID]->GetData()->GetLoopIndex(ch); - - int temp1 = lastIndex + loopIndex * SS->digi[ID]->GetData()->GetDataSize(); - int temp2 = SS->lastFilledIndex[ID][ch] + SS->loopFilledIndex[ID][ch] * SS->digi[ID]->GetData()->GetDataSize() + 1; - - // printf("loopIndx : %d | ID now : %d, ID old : %d \n", loopIndex, temp1, temp2); - - if( temp1 <= temp2 ) continue; - - if( temp1 - temp2 > SS->digi[ID]->GetData()->GetDataSize() ) { //DefaultDataSize = 10k - temp2 = temp1 - SS->digi[ID]->GetData()->GetDataSize(); - SS->lastFilledIndex[ID][ch] = lastIndex; - SS->lastFilledIndex[ID][ch] = loopIndex - 1; - } - - // printf("ch %d | regulated ID now %d new %d | last fill idx %d\n", ch, temp2, temp1, lastFilledIndex[ID][ch]); - - for( int j = 0 ; j <= temp1 - temp2; j ++){ - SS->lastFilledIndex[ID][ch] ++; - if( SS->lastFilledIndex[ID][ch] > SS->digi[ID]->GetData()->GetDataSize() ) { - SS->lastFilledIndex[ID][ch] = 0; - SS->loopFilledIndex[ID][ch] ++; - } - - uShort data = SS->digi[ID]->GetData()->GetEnergy(ch, SS->lastFilledIndex[ID][ch]); - - // printf(" ch: %d, last fill idx : %d | %d \n", ch, lastFilledIndex[ID][ch], data); - - SS->hist[ID][ch]->Fill( data ); - if( SS->digi[i]->GetDPPType() == DPPTypeCode::DPP_PSD_CODE ){ - uShort e2 = SS->digi[ID]->GetData()->GetEnergy2(ch, SS->lastFilledIndex[ID][ch]); - // printf("%u \n", e2); - SS->hist[ID][ch]->Fill( e2, 1); - } - SS->hist2D[ID]->Fill(ch, data); - } - if( SS->histVisibility[ID][ch] ) SS->hist[ID][ch]->UpdatePlot(); - - clock_gettime(CLOCK_REALTIME, &t1); - if( t1.tv_nsec - t0.tv_nsec + (t1.tv_sec - t0.tv_sec)*1e9 > SS->maxFillTimePerDigi * 1e6 ) break; - } - - if( SS->hist2DVisibility[ID] ) SS->hist2D[ID]->UpdatePlot(); - // digiMTX[ID].unlock(); - - } - - SS->isFillingHistograms = false; + SS->FillHistograms(); emit workDone(); } diff --git a/analyzers/Analyser.h b/analyzers/Analyser.h index d8a57e9..084ae91 100644 --- a/analyzers/Analyser.h +++ b/analyzers/Analyser.h @@ -38,6 +38,8 @@ and recompile FSUDAQ to incorporate the changes and activate the custom analyzer #include "Histogram1D.h" #include "Histogram2D.h" +// class AnalyzerWorker; //Forward decalration + //^============================================== //^============================================== class Analyzer : public QMainWindow{ @@ -92,4 +94,25 @@ private: }; + +//^================================================ AnalyzerWorker + +// class ScalarWorker : public QObject{ +// Q_OBJECT +// public: +// ScalarWorker(Analyzer * parent): SS(parent){} + +// public slots: +// void UpdateScalar(){ +// SS->UpdateHistograms(); +// emit workDone(); +// } + +// signals: +// void workDone(); + +// private: +// Analyzer * SS; +// }; + #endif \ No newline at end of file