simplify code for multi thread

This commit is contained in:
Ryan Tang 2024-10-22 13:56:26 -04:00
parent b8011bc834
commit fe6bdb82ff
4 changed files with 17 additions and 13 deletions

View File

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

View File

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

View File

@ -169,7 +169,7 @@ void Analyzer::RedefineEventBuilder(std::vector<int> idList){
}
void Analyzer::BuildEvents(bool verbose){
// qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
// unsigned int nData = mb->GetNumOfDigitizer();
// std::vector<int> idList = mb->GetDigiIDList();
// for( unsigned int i = 0; i < nData; i++ ) digiMTX[idList[i]].lock();

View File

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