remove TimingThread, Scope::UpdateScope() in Qthread via a worker. ScalarUpdateTimeinMiliSec in macro.h

This commit is contained in:
Ryan Tang 2024-08-29 16:49:52 -04:00
parent 2abdc83549
commit c2265f3cc6
8 changed files with 102 additions and 83 deletions

View File

@ -606,6 +606,8 @@ void Digitizer::StopACQ(){
data->ClearBuffer(); data->ClearBuffer();
data->ClearReferenceTime(); data->ClearReferenceTime();
data->ZeroTotalFileSize(); data->ZeroTotalFileSize();
ReadACQStatus();
} }
unsigned int Digitizer::CalByteForBuffer(bool verbose){ unsigned int Digitizer::CalByteForBuffer(bool verbose){

View File

@ -69,7 +69,6 @@ public:
digi->WriteRegister(DPP::SoftwareClear_W, 1); digi->WriteRegister(DPP::SoftwareClear_W, 1);
digi->GetData()->ClearData(); digi->GetData()->ClearData();
} }
digi->ReadACQStatus();
digiMTX[ID].unlock(); digiMTX[ID].unlock();
emit sendMsg("Digi-" + QString::number(digi->GetSerialNumber()) + " ACQ off."); emit sendMsg("Digi-" + QString::number(digi->GetSerialNumber()) + " ACQ off.");
stop = true; stop = true;
@ -112,34 +111,34 @@ private:
}; };
//^#======================================================= Timing Thread //^#======================================================= Timing Thread
class TimingThread : public QThread { // class TimingThread : public QThread {
Q_OBJECT // Q_OBJECT
public: // public:
TimingThread(QObject * parent = 0 ) : QThread(parent){ // TimingThread(QObject * parent = 0 ) : QThread(parent){
waitTime = 20; // multiple of 100 mili sec // waitTime = 20; // multiple of 100 mili sec
stop = false; // stop = false;
} // }
bool isStopped() const {return stop;} // bool isStopped() const {return stop;}
void Stop() { this->stop = true;} // void Stop() { this->stop = true;}
void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;} // void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;}
float GetWaitTimeinSec() const {return waitTime/10.;} // float GetWaitTimeinSec() const {return waitTime/10.;}
void DoOnce() {emit timeUp();}; // void DoOnce() {emit timeUp();};
void run(){ // void run(){
unsigned int count = 0; // unsigned int count = 0;
stop = false; // stop = false;
do{ // do{
usleep(100000); // usleep(100000);
count ++; // count ++;
if( count % waitTime == 0){ // if( count % waitTime == 0){
emit timeUp(); // emit timeUp();
} // }
}while(!stop); // }while(!stop);
} // }
signals: // signals:
void timeUp(); // void timeUp();
private: // private:
bool stop; // bool stop;
unsigned int waitTime; // unsigned int waitTime;
}; // };
#endif #endif

View File

@ -34,7 +34,6 @@ FSUDAQ::FSUDAQ(QWidget *parent) : QMainWindow(parent){
isACQStarted= false; isACQStarted= false;
scalar = nullptr; scalar = nullptr;
scalarUpdateTimeMilliSec = 1000;
scope = nullptr; scope = nullptr;
digiSettings = nullptr; digiSettings = nullptr;
singleHistograms = nullptr; singleHistograms = nullptr;
@ -1163,7 +1162,7 @@ void FSUDAQ::StartACQ(){
// printf("------------ Go! \n"); // printf("------------ Go! \n");
// for( unsigned int i = 0; i < nDigi; i++) readDataThread[i]->go(); // for( unsigned int i = 0; i < nDigi; i++) readDataThread[i]->go();
if( scalar ) scalarTimer->start(scalarUpdateTimeMilliSec); if( scalar ) scalarTimer->start(ScalarUpdateinMiliSec);
if( !scalar->isVisible() ) { if( !scalar->isVisible() ) {
scalar->show(); scalar->show();
@ -1238,7 +1237,6 @@ void FSUDAQ::StopACQ(){
if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile(); if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile();
LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " ACQ is stopped." ); LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " ACQ is stopped." );
QCoreApplication::processEvents(); QCoreApplication::processEvents();
digi[i]->ReadACQStatus();
} }
if( scalar ) scalarTimer->stop(); if( scalar ) scalarTimer->stop();

View File

@ -187,8 +187,6 @@ private:
QLabel * lbFileSize[MaxNDigitizer]; QLabel * lbFileSize[MaxNDigitizer];
QLabel * lbTotalFileSize; QLabel * lbTotalFileSize;
unsigned short scalarUpdateTimeMilliSec;
//@----- Run Record //@----- Run Record
QMainWindow * runRecord; QMainWindow * runRecord;
QStandardItemModel *model; QStandardItemModel *model;

View File

@ -6,7 +6,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QLabel> #include <QLabel>
// #include <QScreen> #include <QScreen>
QVector<QPointF> Scope::TrapezoidFilter(QVector<QPointF> data, int baseLineEndS, int riseTimeS, int flatTopS, float decayTime_ns){ QVector<QPointF> Scope::TrapezoidFilter(QVector<QPointF> data, int baseLineEndS, int riseTimeS, int flatTopS, float decayTime_ns){
DebugPrint("%s", "Scope"); DebugPrint("%s", "Scope");
@ -42,11 +42,11 @@ QVector<QPointF> Scope::TrapezoidFilter(QVector<QPointF> data, int baseLineEndS,
trapezoid.append(QPointF(data[i].x(), sn / decayTime_ns / riseTimeS)); trapezoid.append(QPointF(data[i].x(), sn / decayTime_ns / riseTimeS));
} }
return trapezoid; return trapezoid;
} }
//^========================================================
//^========================================================
Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent) : QMainWindow(parent){ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent) : QMainWindow(parent){
DebugPrint("%s", "Scope"); DebugPrint("%s", "Scope");
this->digi = digi; this->digi = digi;
@ -64,7 +64,6 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
}else{ }else{
setGeometry(0, 0, 1000, 800); setGeometry(0, 0, 1000, 800);
} }
// setGeometry(0, 0, 1000, 800);
enableSignalSlot = false; enableSignalSlot = false;
@ -100,16 +99,6 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
xaxis->setLabelFormat("%.0f"); xaxis->setLabelFormat("%.0f");
xaxis->setTitleText("Time [ns]"); xaxis->setTitleText("Time [ns]");
updateTraceThread = new TimingThread();
updateTraceThread->SetWaitTimeinSec(ScopeUpdateMiliSec / 1000.);
connect(updateTraceThread, &TimingThread::timeUp, this, &Scope::UpdateScope);
updateScalarThread = new TimingThread();
updateScalarThread->SetWaitTimeinSec(2);
connect(updateScalarThread, &TimingThread::timeUp, this, [=](){
emit UpdateScaler();
});
NullThePointers(); NullThePointers();
//*================================== UI //*================================== UI
@ -226,7 +215,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
QLabel * lbhints = new QLabel("Type 'r' to restore view, '+/-' Zoom in/out, arrow key to pan.", this); QLabel * lbhints = new QLabel("Type 'r' to restore view, '+/-' Zoom in/out, arrow key to pan.", this);
layout->addWidget(lbhints, rowID, 0, 1, 4); layout->addWidget(lbhints, rowID, 0, 1, 4);
QLabel * lbinfo = new QLabel("Trace updates every " + QString::number(updateTraceThread->GetWaitTimeinSec()) + " sec.", this); QLabel * lbinfo = new QLabel("Trace updates every " + QString::number(ScopeUpdateMiliSec / 1000.) + " sec.", this);
lbinfo->setAlignment(Qt::AlignRight); lbinfo->setAlignment(Qt::AlignRight);
layout->addWidget(lbinfo, rowID, 6); layout->addWidget(lbinfo, rowID, 6);
@ -288,22 +277,35 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
yaxis->setRange(0, 0xFFF); yaxis->setRange(0, 0xFFF);
} }
workerThread = new QThread(this);
scopeWorker = new ScopeWorker(this);
scopeTimer = new QTimer(this);
scopeWorker->moveToThread(workerThread);
// Setup the timer to trigger every second
connect(scopeTimer, &QTimer::timeout, scopeWorker, [=](){
scopeWorker->UpdateScope();
});
workerThread->start();
scalarTimer = new QTimer(this);
connect(scalarTimer, &QTimer::timeout, this, &Scope::UpdateScaler);
enableSignalSlot = true; enableSignalSlot = true;
} }
Scope::~Scope(){ Scope::~Scope(){
DebugPrint("%s", "Scope"); DebugPrint("%s", "Scope");
updateTraceThread->Stop();
updateTraceThread->quit();
updateTraceThread->wait();
delete updateTraceThread;
updateScalarThread->Stop(); scopeTimer->stop();
updateScalarThread->quit(); scalarTimer->stop();
updateScalarThread->wait();
delete updateScalarThread; if( workerThread->isRunning() ){
workerThread->quit();
workerThread->wait();
}
for( int i = 0; i < MaxNumberOfTrace; i++) delete dataTrace[i]; for( int i = 0; i < MaxNumberOfTrace; i++) delete dataTrace[i];
delete plot; delete plot;
@ -432,8 +434,8 @@ void Scope::StartScope(){
} }
updateTraceThread->start(); scopeTimer->start(ScopeUpdateMiliSec);
updateScalarThread->start(); scalarTimer->start(ScalarUpdateinMiliSec);
bnScopeStart->setEnabled(false); bnScopeStart->setEnabled(false);
bnScopeStart->setStyleSheet(""); bnScopeStart->setStyleSheet("");
@ -444,7 +446,7 @@ void Scope::StartScope(){
EnableControl(false); EnableControl(false);
TellACQOnOff(true); emit TellACQOnOff(true);
isACQStarted = true; isACQStarted = true;
@ -455,13 +457,8 @@ void Scope::StopScope(){
if( !digi ) return; if( !digi ) return;
// printf("------ Scope::%s \n", __func__); // printf("------ Scope::%s \n", __func__);
updateTraceThread->Stop(); scopeTimer->stop();
updateTraceThread->quit(); scalarTimer->stop();
updateTraceThread->exit();
updateScalarThread->Stop();
updateScalarThread->quit();
updateScalarThread->exit();
if( chkSoleRun->isChecked() ){ if( chkSoleRun->isChecked() ){
@ -477,7 +474,6 @@ void Scope::StopScope(){
digiMTX[ID].lock(); digiMTX[ID].lock();
digi[ID]->StopACQ(); digi[ID]->StopACQ();
digi[ID]->ReadACQStatus();
digiMTX[ID].unlock(); digiMTX[ID].unlock();
//restore setting //restore setting
@ -508,9 +504,9 @@ void Scope::StopScope(){
readDataThread[iDigi]->wait(); readDataThread[iDigi]->wait();
readDataThread[iDigi]->SetScopeMode(false); readDataThread[iDigi]->SetScopeMode(false);
} }
digiMTX[iDigi].lock(); digiMTX[iDigi].lock();
digi[iDigi]->StopACQ(); digi[iDigi]->StopACQ();
digi[iDigi]->ReadACQStatus();
//digi[iDigi]->GetData()->PrintAllData(); //digi[iDigi]->GetData()->PrintAllData();
digiMTX[iDigi].unlock(); digiMTX[iDigi].unlock();
@ -521,6 +517,8 @@ void Scope::StopScope(){
} }
runStatus->setStyleSheet(""); // cheated, don;t know why digi[iDigi]->GetACQStatusFromMemory(), sometimes return ACQ on
emit UpdateOtherPanels(); emit UpdateOtherPanels();
bnScopeStart->setEnabled(true); bnScopeStart->setEnabled(true);
@ -533,7 +531,7 @@ void Scope::StopScope(){
EnableControl(true); EnableControl(true);
TellACQOnOff(false); emit TellACQOnOff(false);
isACQStarted = false; isACQStarted = false;

29
Scope.h
View File

@ -12,6 +12,7 @@
#include <QComboBox> #include <QComboBox>
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QTimer>
#include <QLineSeries> #include <QLineSeries>
#include <QRubberBand> #include <QRubberBand>
#include <QMouseEvent> #include <QMouseEvent>
@ -22,6 +23,8 @@
#include "CustomThreads.h" #include "CustomThreads.h"
#include "CustomWidgets.h" #include "CustomWidgets.h"
class ScopeWorker; //Forward declaration
//^==================================================== //^====================================================
//^==================================================== //^====================================================
class Scope : public QMainWindow{ class Scope : public QMainWindow{
@ -87,8 +90,7 @@ private:
unsigned short oldCh, oldDigi; unsigned short oldCh, oldDigi;
ReadDataThread ** readDataThread; ReadDataThread ** readDataThread;
TimingThread * updateTraceThread; // TimingThread * updateScalarThread;
TimingThread * updateScalarThread;
bool enableSignalSlot; bool enableSignalSlot;
@ -147,8 +149,31 @@ private:
//sbGateOffset -> GateOffset //sbGateOffset -> GateOffset
//sbTriggerHoldOff ->Trigger Hold Off //sbTriggerHoldOff ->Trigger Hold Off
QThread * workerThread;
ScopeWorker * scopeWorker;
QTimer * scopeTimer;
QTimer * scalarTimer;
}; };
//^#======================================================== ScopeWorker
class ScopeWorker : public QObject{
Q_OBJECT
public:
ScopeWorker(Scope * parent): SS(parent){}
public slots:
void UpdateScope(){
SS->UpdateScope();
emit workDone();
}
signals:
void workDone();
private:
Scope * SS;
};
#endif #endif

View File

@ -30,8 +30,7 @@ public:
RedefineEventBuilder({0}); // only build for the 0-th digitizer, otherwise, it will build event accross all digitizers RedefineEventBuilder({0}); // only build for the 0-th digitizer, otherwise, it will build event accross all digitizers
tick2ns = digi[0]->GetTick2ns(); tick2ns = digi[0]->GetTick2ns();
SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100. SetBackwardBuild(false, 100); // using normal building (acceding in time) or backward building, int the case of backward building, default events to be build is 100.
evtbder = GetEventBuilder(); mb->SetTimeWindow(3000);
evtbder->SetTimeWindow(3000);
//========== use the influx from the Analyzer //========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/"); influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
@ -67,8 +66,6 @@ public slots:
private: private:
MultiBuilder *evtbder;
// declaie histograms // declaie histograms
Histogram2D * hPID; Histogram2D * hPID;
@ -224,7 +221,7 @@ inline void SplitPole::SetUpCanvas(){
boxLayout->addWidget(sbEventWin, 4, 1); boxLayout->addWidget(sbEventWin, 4, 1);
sbEventWin->setValue(3000); sbEventWin->setValue(3000);
connect(sbEventWin, &RSpinBox::returnPressed, this, [=](){ connect(sbEventWin, &RSpinBox::returnPressed, this, [=](){
evtbder->SetTimeWindow(sbEventWin->value()); mb->SetTimeWindow(sbEventWin->value());
}); });
chkRunAnalyzer = new QCheckBox("Run Analyzer", this); chkRunAnalyzer = new QCheckBox("Run Analyzer", this);
@ -352,7 +349,7 @@ inline void SplitPole::UpdateHistograms(){
BuildEvents(); // call the event builder to build events BuildEvents(); // call the event builder to build events
//============ Get events, and do analysis //============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt; long eventBuilt = mb->eventBuilt;
if( eventBuilt == 0 ) return; if( eventBuilt == 0 ) return;
//============ Get the cut list, if any //============ Get the cut list, if any
@ -362,12 +359,12 @@ inline void SplitPole::UpdateHistograms(){
unsigned int count[nCut]={0}; unsigned int count[nCut]={0};
//============ Processing data and fill histograms //============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex; long eventIndex = mb->eventIndex;
long eventStart = eventIndex - eventBuilt + 1; long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent; if(eventStart < 0 ) eventStart += MaxNEvent;
for( long i = eventStart ; i <= eventIndex; i ++ ){ for( long i = eventStart ; i <= eventIndex; i ++ ){
std::vector<Hit> event = evtbder->events[i]; std::vector<Hit> event = mb->events[i];
//printf("-------------- %ld\n", i); //printf("-------------- %ld\n", i);
hMulti->Fill((int) event.size()); hMulti->Fill((int) event.size());

View File

@ -11,6 +11,8 @@
#define MaxRecordLength 0x3fff * 8 #define MaxRecordLength 0x3fff * 8
#define MaxSaveFileSize 1024 * 1024 * 1024 * 2 #define MaxSaveFileSize 1024 * 1024 * 1024 * 2
#define ScalarUpdateinMiliSec 1000 // msec
#define MaxDisplayTraceTimeLength 20000 //ns #define MaxDisplayTraceTimeLength 20000 //ns
#define ScopeUpdateMiliSec 200 // msec #define ScopeUpdateMiliSec 200 // msec
#define MaxNumberOfTrace 5 // in an event #define MaxNumberOfTrace 5 // in an event