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->ClearReferenceTime();
data->ZeroTotalFileSize();
ReadACQStatus();
}
unsigned int Digitizer::CalByteForBuffer(bool verbose){

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
#include <QGroupBox>
#include <QStandardItemModel>
#include <QLabel>
// #include <QScreen>
#include <QScreen>
QVector<QPointF> Scope::TrapezoidFilter(QVector<QPointF> data, int baseLineEndS, int riseTimeS, int flatTopS, float decayTime_ns){
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));
}
return trapezoid;
}
//^========================================================
//^========================================================
Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent) : QMainWindow(parent){
DebugPrint("%s", "Scope");
this->digi = digi;
@ -64,7 +64,6 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
}else{
setGeometry(0, 0, 1000, 800);
}
// setGeometry(0, 0, 1000, 800);
enableSignalSlot = false;
@ -100,16 +99,6 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
xaxis->setLabelFormat("%.0f");
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();
//*================================== 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);
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);
layout->addWidget(lbinfo, rowID, 6);
@ -288,22 +277,35 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
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;
}
Scope::~Scope(){
DebugPrint("%s", "Scope");
updateTraceThread->Stop();
updateTraceThread->quit();
updateTraceThread->wait();
delete updateTraceThread;
updateScalarThread->Stop();
updateScalarThread->quit();
updateScalarThread->wait();
delete updateScalarThread;
scopeTimer->stop();
scalarTimer->stop();
if( workerThread->isRunning() ){
workerThread->quit();
workerThread->wait();
}
for( int i = 0; i < MaxNumberOfTrace; i++) delete dataTrace[i];
delete plot;
@ -432,8 +434,8 @@ void Scope::StartScope(){
}
updateTraceThread->start();
updateScalarThread->start();
scopeTimer->start(ScopeUpdateMiliSec);
scalarTimer->start(ScalarUpdateinMiliSec);
bnScopeStart->setEnabled(false);
bnScopeStart->setStyleSheet("");
@ -444,7 +446,7 @@ void Scope::StartScope(){
EnableControl(false);
TellACQOnOff(true);
emit TellACQOnOff(true);
isACQStarted = true;
@ -455,13 +457,8 @@ void Scope::StopScope(){
if( !digi ) return;
// printf("------ Scope::%s \n", __func__);
updateTraceThread->Stop();
updateTraceThread->quit();
updateTraceThread->exit();
updateScalarThread->Stop();
updateScalarThread->quit();
updateScalarThread->exit();
scopeTimer->stop();
scalarTimer->stop();
if( chkSoleRun->isChecked() ){
@ -477,7 +474,6 @@ void Scope::StopScope(){
digiMTX[ID].lock();
digi[ID]->StopACQ();
digi[ID]->ReadACQStatus();
digiMTX[ID].unlock();
//restore setting
@ -508,9 +504,9 @@ void Scope::StopScope(){
readDataThread[iDigi]->wait();
readDataThread[iDigi]->SetScopeMode(false);
}
digiMTX[iDigi].lock();
digi[iDigi]->StopACQ();
digi[iDigi]->ReadACQStatus();
//digi[iDigi]->GetData()->PrintAllData();
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();
bnScopeStart->setEnabled(true);
@ -533,7 +531,7 @@ void Scope::StopScope(){
EnableControl(true);
TellACQOnOff(false);
emit TellACQOnOff(false);
isACQStarted = false;

29
Scope.h
View File

@ -12,6 +12,7 @@
#include <QComboBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QTimer>
#include <QLineSeries>
#include <QRubberBand>
#include <QMouseEvent>
@ -22,6 +23,8 @@
#include "CustomThreads.h"
#include "CustomWidgets.h"
class ScopeWorker; //Forward declaration
//^====================================================
//^====================================================
class Scope : public QMainWindow{
@ -87,8 +90,7 @@ private:
unsigned short oldCh, oldDigi;
ReadDataThread ** readDataThread;
TimingThread * updateTraceThread;
TimingThread * updateScalarThread;
// TimingThread * updateScalarThread;
bool enableSignalSlot;
@ -147,8 +149,31 @@ private:
//sbGateOffset -> GateOffset
//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

View File

@ -30,8 +30,7 @@ public:
RedefineEventBuilder({0}); // only build for the 0-th digitizer, otherwise, it will build event accross all digitizers
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.
evtbder = GetEventBuilder();
evtbder->SetTimeWindow(3000);
mb->SetTimeWindow(3000);
//========== use the influx from the Analyzer
influx = new InfluxDB("https://fsunuc.physics.fsu.edu/influx/");
@ -67,8 +66,6 @@ public slots:
private:
MultiBuilder *evtbder;
// declaie histograms
Histogram2D * hPID;
@ -224,7 +221,7 @@ inline void SplitPole::SetUpCanvas(){
boxLayout->addWidget(sbEventWin, 4, 1);
sbEventWin->setValue(3000);
connect(sbEventWin, &RSpinBox::returnPressed, this, [=](){
evtbder->SetTimeWindow(sbEventWin->value());
mb->SetTimeWindow(sbEventWin->value());
});
chkRunAnalyzer = new QCheckBox("Run Analyzer", this);
@ -352,7 +349,7 @@ inline void SplitPole::UpdateHistograms(){
BuildEvents(); // call the event builder to build events
//============ Get events, and do analysis
long eventBuilt = evtbder->eventBuilt;
long eventBuilt = mb->eventBuilt;
if( eventBuilt == 0 ) return;
//============ Get the cut list, if any
@ -362,12 +359,12 @@ inline void SplitPole::UpdateHistograms(){
unsigned int count[nCut]={0};
//============ Processing data and fill histograms
long eventIndex = evtbder->eventIndex;
long eventIndex = mb->eventIndex;
long eventStart = eventIndex - eventBuilt + 1;
if(eventStart < 0 ) eventStart += MaxNEvent;
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);
hMulti->Fill((int) event.size());

View File

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