From b8011bc834f1fd4b37e6cf74b49de967a8681a8e Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS_testStation" Date: Tue, 22 Oct 2024 12:56:26 -0400 Subject: [PATCH] [Major] True parallel thread for filling histogram --- FSUDAQ.cpp | 2 ++ MultiBuilder.cpp | 6 +++--- SingleSpectra.cpp | 23 ++++++++++++++--------- SingleSpectra.h | 10 ++++++++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index 8d4eb66..d88b8c9 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -1018,6 +1018,8 @@ void FSUDAQ::UpdateScalar(){ DebugPrint("%s", "FSUDAQ"); + // qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); + // printf("================== FSUDAQ::%s\n", __func__); if( digi == nullptr ) return; diff --git a/MultiBuilder.cpp b/MultiBuilder.cpp index 2f1ffef..c71e70d 100644 --- a/MultiBuilder.cpp +++ b/MultiBuilder.cpp @@ -78,7 +78,7 @@ void MultiBuilder::PrintStat(){ printf("Total number of evet built : %ld\n", totalEventBuilt); for( int i = 0; i < nData ; i++){ for( int ch = 0; ch < data[i]->GetNChannel() ; ch++){ - if( nextIndex[i][ch] >= 0 ) printf("%d %3d %2d | %7ld (%d)\n", i, snList[i], ch, nextIndex[i][ch]); + if( nextIndex[i][ch] >= 0 ) printf("%d %3d %2d | %7ld\n", i, snList[i], ch, nextIndex[i][ch]); } } } @@ -277,7 +277,7 @@ void MultiBuilder::BuildEvents(bool isFinal, bool skipTrace, bool verbose){ break; } } - printf("%05d, %02d | %5d | %5d %llu \n", sn, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp); + printf("%05d, %02d | %7ld | %5d %llu \n", sn, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp); } if( nExhaushedCh == numTotCh ) { @@ -456,7 +456,7 @@ void MultiBuilder::BuildEventsBackWard(int maxNumEvent, bool verbose){ break; } } - printf("%5d, %02d | %5d | %5d %llu \n", sn, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp); + printf("%5d, %02d | %7ld | %5d %llu \n", sn, chxxx, nextIndex[bd][chxxx], events[eventIndex][i].energy, events[eventIndex][i].timestamp); } } diff --git a/SingleSpectra.cpp b/SingleSpectra.cpp index 962df10..6b1d366 100644 --- a/SingleSpectra.cpp +++ b/SingleSpectra.cpp @@ -153,18 +153,19 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD timer = new QTimer(this); histWorker->moveToThread(workerThread); + timer->moveToThread(workerThread); - workerThread->start(); - + isFillingHistograms = false; // connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms); connect( histWorker, &HistWorker::workDone, this, &SingleSpectra::ReplotHistograms); - connect(timer, &QTimer::timeout, this, [=](){ - if( isFillingHistograms == false){ - histWorker->FillHistograms(); - // ReplotHistograms(); - } - }); + connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms); + + connect(this, &SingleSpectra::startWorkerTimer, timer, static_cast(&QTimer::start)); + connect(this, &SingleSpectra::stopWorkerTimer, timer, &QTimer::stop); + + + workerThread->start(); } @@ -249,6 +250,8 @@ void SingleSpectra::FillHistograms(){ timespec ta, tb; printf("####################### SingleSpectra::%s\n", __func__); + // qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); + clock_gettime(CLOCK_REALTIME, &ta); std::vector digiChList; // (digi*1000 + ch) @@ -315,7 +318,7 @@ void SingleSpectra::FillHistograms(){ } hist2D[ID]->Fill(ch, data); - QCoreApplication::processEvents(); + // QCoreApplication::processEvents(); clock_gettime(CLOCK_REALTIME, &tb); }while( isFillingHistograms && (tb.tv_nsec - ta.tv_nsec)/1e6 + (tb.tv_sec - ta.tv_sec)*1e3 < maxFillTimeinMilliSec ); @@ -334,6 +337,8 @@ void SingleSpectra::FillHistograms(){ void SingleSpectra::ReplotHistograms(){ + // qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); + int ID = cbDigi->currentData().toInt(); int ch = cbCh->currentData().toInt(); diff --git a/SingleSpectra.h b/SingleSpectra.h index 56d9ef8..3cae9d2 100644 --- a/SingleSpectra.h +++ b/SingleSpectra.h @@ -45,16 +45,22 @@ public: void ReplotHistograms(); +signals: + void startWorkerTimer(int interval); + void stopWorkerTimer(); + public slots: void FillHistograms(); void ChangeHistView(); void startTimer(){ // printf("timer start\n"); - timer->start(maxFillTimeinMilliSec); + // timer->start(maxFillTimeinMilliSec); + emit startWorkerTimer(maxFillTimeinMilliSec); } void stopTimer(){ // printf("timer stop\n"); - timer->stop(); + // timer->stop(); + emit stopWorkerTimer(); isFillingHistograms = false; // this will also break the FillHistogram do-loop ClearInternalDataCount(); }