From fe6bdb82ff3fce3b111fe27f9e1754aec19ea123 Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS_testStation" Date: Tue, 22 Oct 2024 13:56:26 -0400 Subject: [PATCH] simplify code for multi thread --- SingleSpectra.cpp | 14 ++++++++------ SingleSpectra.h | 12 ++++++------ analyzers/Analyser.cpp | 2 +- analyzers/NeutronGamma.h | 2 ++ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/SingleSpectra.cpp b/SingleSpectra.cpp index 6b1d366..adef1b9 100644 --- a/SingleSpectra.cpp +++ b/SingleSpectra.cpp @@ -153,16 +153,18 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD timer = new QTimer(this); histWorker->moveToThread(workerThread); - timer->moveToThread(workerThread); + + // this is another way + // timer = new QTimer(); + // timer->moveToThread(workerThread); + // connect(this, &SingleSpectra::startWorkerTimer, timer, static_cast(&QTimer::start)); + // connect(this, &SingleSpectra::stopWorkerTimer, timer, &QTimer::stop); isFillingHistograms = false; - // connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms); + connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms); connect( histWorker, &HistWorker::workDone, this, &SingleSpectra::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(); @@ -250,7 +252,7 @@ void SingleSpectra::FillHistograms(){ timespec ta, tb; printf("####################### SingleSpectra::%s\n", __func__); - // qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); + qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); clock_gettime(CLOCK_REALTIME, &ta); diff --git a/SingleSpectra.h b/SingleSpectra.h index 3cae9d2..2808187 100644 --- a/SingleSpectra.h +++ b/SingleSpectra.h @@ -46,21 +46,21 @@ public: void ReplotHistograms(); signals: - void startWorkerTimer(int interval); - void stopWorkerTimer(); + // void startWorkerTimer(int interval); + // void stopWorkerTimer(); public slots: void FillHistograms(); void ChangeHistView(); void startTimer(){ // printf("timer start\n"); - // timer->start(maxFillTimeinMilliSec); - emit startWorkerTimer(maxFillTimeinMilliSec); + timer->start(maxFillTimeinMilliSec); + // emit startWorkerTimer(maxFillTimeinMilliSec); } void stopTimer(){ // printf("timer stop\n"); - // timer->stop(); - emit stopWorkerTimer(); + timer->stop(); + // emit stopWorkerTimer(); isFillingHistograms = false; // this will also break the FillHistogram do-loop ClearInternalDataCount(); } diff --git a/analyzers/Analyser.cpp b/analyzers/Analyser.cpp index bcfd5ed..dad6212 100644 --- a/analyzers/Analyser.cpp +++ b/analyzers/Analyser.cpp @@ -169,7 +169,7 @@ void Analyzer::RedefineEventBuilder(std::vector idList){ } void Analyzer::BuildEvents(bool verbose){ - + // qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); // unsigned int nData = mb->GetNumOfDigitizer(); // std::vector idList = mb->GetDigiIDList(); // for( unsigned int i = 0; i < nData; i++ ) digiMTX[idList[i]].lock(); diff --git a/analyzers/NeutronGamma.h b/analyzers/NeutronGamma.h index 65996b0..850a5b2 100644 --- a/analyzers/NeutronGamma.h +++ b/analyzers/NeutronGamma.h @@ -185,6 +185,8 @@ inline void NeutronGamma::UpdateHistograms(){ if( !fillHistograms ) return; if( this->isVisible() == false ) return; + // qDebug() << __func__ << "| thread:" << QThread::currentThreadId(); + int ID = cbDigi->currentData().toInt(); int ch = cbCh->currentData().toInt();