simplify code for multi thread
This commit is contained in:
parent
b8011bc834
commit
fe6bdb82ff
|
@ -153,16 +153,18 @@ SingleSpectra::SingleSpectra(Digitizer ** digi, unsigned int nDigi, QString rawD
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
|
||||||
histWorker->moveToThread(workerThread);
|
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;
|
isFillingHistograms = false;
|
||||||
// connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms);
|
connect(timer, &QTimer::timeout, histWorker, &HistWorker::FillHistograms);
|
||||||
connect( histWorker, &HistWorker::workDone, this, &SingleSpectra::ReplotHistograms);
|
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();
|
workerThread->start();
|
||||||
|
@ -250,7 +252,7 @@ void SingleSpectra::FillHistograms(){
|
||||||
timespec ta, tb;
|
timespec ta, tb;
|
||||||
|
|
||||||
printf("####################### SingleSpectra::%s\n", __func__);
|
printf("####################### SingleSpectra::%s\n", __func__);
|
||||||
// qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
|
qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
|
||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &ta);
|
clock_gettime(CLOCK_REALTIME, &ta);
|
||||||
|
|
||||||
|
|
|
@ -46,21 +46,21 @@ public:
|
||||||
void ReplotHistograms();
|
void ReplotHistograms();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void startWorkerTimer(int interval);
|
// void startWorkerTimer(int interval);
|
||||||
void stopWorkerTimer();
|
// void stopWorkerTimer();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void FillHistograms();
|
void FillHistograms();
|
||||||
void ChangeHistView();
|
void ChangeHistView();
|
||||||
void startTimer(){
|
void startTimer(){
|
||||||
// printf("timer start\n");
|
// printf("timer start\n");
|
||||||
// timer->start(maxFillTimeinMilliSec);
|
timer->start(maxFillTimeinMilliSec);
|
||||||
emit startWorkerTimer(maxFillTimeinMilliSec);
|
// emit startWorkerTimer(maxFillTimeinMilliSec);
|
||||||
}
|
}
|
||||||
void stopTimer(){
|
void stopTimer(){
|
||||||
// printf("timer stop\n");
|
// printf("timer stop\n");
|
||||||
// timer->stop();
|
timer->stop();
|
||||||
emit stopWorkerTimer();
|
// emit stopWorkerTimer();
|
||||||
isFillingHistograms = false; // this will also break the FillHistogram do-loop
|
isFillingHistograms = false; // this will also break the FillHistogram do-loop
|
||||||
ClearInternalDataCount();
|
ClearInternalDataCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ void Analyzer::RedefineEventBuilder(std::vector<int> idList){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Analyzer::BuildEvents(bool verbose){
|
void Analyzer::BuildEvents(bool verbose){
|
||||||
|
// qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
|
||||||
// unsigned int nData = mb->GetNumOfDigitizer();
|
// unsigned int nData = mb->GetNumOfDigitizer();
|
||||||
// std::vector<int> idList = mb->GetDigiIDList();
|
// std::vector<int> idList = mb->GetDigiIDList();
|
||||||
// for( unsigned int i = 0; i < nData; i++ ) digiMTX[idList[i]].lock();
|
// for( unsigned int i = 0; i < nData; i++ ) digiMTX[idList[i]].lock();
|
||||||
|
|
|
@ -185,6 +185,8 @@ inline void NeutronGamma::UpdateHistograms(){
|
||||||
if( !fillHistograms ) return;
|
if( !fillHistograms ) return;
|
||||||
if( this->isVisible() == false ) return;
|
if( this->isVisible() == false ) return;
|
||||||
|
|
||||||
|
// qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
|
||||||
|
|
||||||
int ID = cbDigi->currentData().toInt();
|
int ID = cbDigi->currentData().toInt();
|
||||||
int ch = cbCh->currentData().toInt();
|
int ch = cbCh->currentData().toInt();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user