[Major] True parallel thread for filling histogram

This commit is contained in:
Ryan Tang 2024-10-22 12:56:26 -04:00
parent 0d379fec92
commit b8011bc834
4 changed files with 27 additions and 14 deletions

View File

@ -1018,6 +1018,8 @@ void FSUDAQ::UpdateScalar(){
DebugPrint("%s", "FSUDAQ");
// qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
// printf("================== FSUDAQ::%s\n", __func__);
if( digi == nullptr ) return;

View File

@ -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);
}
}

View File

@ -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<void(QTimer::*)(int)>(&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<int> 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();

View File

@ -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();
}