[Major] Scalar cannot be put in Thread, becuase it update QLineEdit of the MainThread and it is not thread-safe
This commit is contained in:
parent
dfdc5c4700
commit
3b3a22382b
|
@ -111,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
|
||||||
|
|
69
FSUDAQ.cpp
69
FSUDAQ.cpp
|
@ -309,11 +309,14 @@ FSUDAQ::FSUDAQ(QWidget *parent) : QMainWindow(parent){
|
||||||
FSUDAQ::~FSUDAQ(){
|
FSUDAQ::~FSUDAQ(){
|
||||||
DebugPrint("%s", "FSUDAQ");
|
DebugPrint("%s", "FSUDAQ");
|
||||||
if( scalar ) {
|
if( scalar ) {
|
||||||
scalarTimer->stop();
|
scalarTimingThread->Stop();
|
||||||
if( scalarThread->isRunning() ){
|
scalarTimingThread->quit();
|
||||||
scalarThread->quit();
|
scalarTimingThread->exit();
|
||||||
scalarThread->exit();
|
// scalarTimer->stop();
|
||||||
}
|
// if( scalarThread->isRunning() ){
|
||||||
|
// scalarThread->quit();
|
||||||
|
// scalarThread->exit();
|
||||||
|
// }
|
||||||
CleanUpScalar();
|
CleanUpScalar();
|
||||||
//don't need to delete scalar, it is managed by this
|
//don't need to delete scalar, it is managed by this
|
||||||
}
|
}
|
||||||
|
@ -762,10 +765,15 @@ void FSUDAQ::CloseDigitizers(){
|
||||||
scope = nullptr;
|
scope = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
scalarTimer->stop();
|
// scalarTimer->stop();
|
||||||
if( scalarThread->isRunning() ){
|
// if( scalarThread->isRunning() ){
|
||||||
scalarThread->quit();
|
// scalarThread->quit();
|
||||||
scalarThread->exit();
|
// scalarThread->exit();
|
||||||
|
// }
|
||||||
|
scalarTimingThread->Stop();
|
||||||
|
if( scalarTimingThread->isRunning() ){
|
||||||
|
scalarTimingThread->quit();
|
||||||
|
scalarTimingThread->exit();
|
||||||
}
|
}
|
||||||
if( scalar ) CleanUpScalar();
|
if( scalar ) CleanUpScalar();
|
||||||
|
|
||||||
|
@ -870,18 +878,18 @@ void FSUDAQ::SetupScalar(){
|
||||||
lbScalarACQStatus = nullptr;
|
lbScalarACQStatus = nullptr;
|
||||||
lbTotalFileSize = nullptr;
|
lbTotalFileSize = nullptr;
|
||||||
|
|
||||||
// scalarThread = new TimingThread(scalar);
|
scalarTimingThread = new TimingThread(scalar);
|
||||||
// scalarThread->SetWaitTimeinSec(1.0);
|
scalarTimingThread->SetWaitTimeinSec(ScalarUpdateinMiliSec / 1000.);
|
||||||
// connect(scalarThread, &TimingThread::timeUp, this, &FSUDAQ::UpdateScalar);
|
connect(scalarTimingThread, &TimingThread::timeUp, this, &FSUDAQ::UpdateScalar);
|
||||||
|
|
||||||
scalarThread = new QThread(this);
|
// scalarThread = new QThread(this);
|
||||||
scalarWorker = new ScalarWorker(this);
|
// scalarWorker = new ScalarWorker(this);
|
||||||
scalarWorker->moveToThread(scalarThread);
|
// scalarWorker->moveToThread(scalarThread);
|
||||||
|
|
||||||
scalarTimer = new QTimer(this);
|
// scalarTimer = new QTimer(this);
|
||||||
connect( scalarTimer, &QTimer::timeout, scalarWorker, &ScalarWorker::UpdateScalar);
|
// connect( scalarTimer, &QTimer::timeout, scalarWorker, &ScalarWorker::UpdateScalar);
|
||||||
|
|
||||||
scalarThread->start();
|
// scalarThread->start();
|
||||||
|
|
||||||
unsigned short maxNChannel = 0;
|
unsigned short maxNChannel = 0;
|
||||||
for( unsigned int k = 0; k < nDigi; k ++ ){
|
for( unsigned int k = 0; k < nDigi; k ++ ){
|
||||||
|
@ -1068,8 +1076,8 @@ void FSUDAQ::UpdateScalar(){
|
||||||
|
|
||||||
lbTotalFileSize->setText("Total Data Size : " + QString::number(totalFileSize/1024./1024., 'f', 3) + " MB");
|
lbTotalFileSize->setText("Total Data Size : " + QString::number(totalFileSize/1024./1024., 'f', 3) + " MB");
|
||||||
|
|
||||||
repaint();
|
// repaint();
|
||||||
scalar->repaint();
|
// scalar->repaint();
|
||||||
|
|
||||||
if( influx && chkInflux->isChecked() && scalarCount >= 3){
|
if( influx && chkInflux->isChecked() && scalarCount >= 3){
|
||||||
if( chkSaveData->isChecked() ) {
|
if( chkSaveData->isChecked() ) {
|
||||||
|
@ -1082,6 +1090,8 @@ void FSUDAQ::UpdateScalar(){
|
||||||
scalarCount = 0;
|
scalarCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// printf("end of %s\n", __func__);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSUDAQ::CleanUpScalar(){
|
void FSUDAQ::CleanUpScalar(){
|
||||||
|
@ -1162,7 +1172,8 @@ 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(ScalarUpdateinMiliSec);
|
// if( scalar ) scalarTimer->start(ScalarUpdateinMiliSec);
|
||||||
|
if( scalar ) scalarTimingThread->start();
|
||||||
|
|
||||||
if( !scalar->isVisible() ) {
|
if( !scalar->isVisible() ) {
|
||||||
scalar->show();
|
scalar->show();
|
||||||
|
@ -1239,7 +1250,13 @@ void FSUDAQ::StopACQ(){
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( scalar ) scalarTimer->stop();
|
if( scalarTimingThread->isRunning()){
|
||||||
|
scalarTimingThread->Stop();
|
||||||
|
scalarTimingThread->quit();
|
||||||
|
scalarTimingThread->wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if( scalar ) scalarTimer->stop();
|
||||||
if( singleHistograms ) singleHistograms->stopTimer();
|
if( singleHistograms ) singleHistograms->stopTimer();
|
||||||
if( onlineAnalyzer ) onlineAnalyzer->stopTimer();
|
if( onlineAnalyzer ) onlineAnalyzer->stopTimer();
|
||||||
|
|
||||||
|
@ -1731,7 +1748,8 @@ void FSUDAQ::OpenScope(){
|
||||||
|
|
||||||
if( scalar ){
|
if( scalar ){
|
||||||
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
|
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
|
||||||
scalarTimer->start(ScalarUpdateinMiliSec);
|
// scalarTimer->start(ScalarUpdateinMiliSec);
|
||||||
|
scalarTimingThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( singleHistograms ) singleHistograms->startTimer();
|
if( singleHistograms ) singleHistograms->startTimer();
|
||||||
|
@ -1742,7 +1760,10 @@ void FSUDAQ::OpenScope(){
|
||||||
|
|
||||||
if( scalar ){
|
if( scalar ){
|
||||||
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
|
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
|
||||||
scalarTimer->stop();
|
// scalarTimer->stop();
|
||||||
|
scalarTimingThread->Stop();
|
||||||
|
scalarTimingThread->quit();
|
||||||
|
scalarTimingThread->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( singleHistograms ) singleHistograms->stopTimer();
|
if( singleHistograms ) singleHistograms->stopTimer();
|
||||||
|
|
36
FSUDAQ.h
36
FSUDAQ.h
|
@ -173,9 +173,11 @@ private:
|
||||||
//@----- Scalar
|
//@----- Scalar
|
||||||
QMainWindow * scalar;
|
QMainWindow * scalar;
|
||||||
QGridLayout * scalarLayout;
|
QGridLayout * scalarLayout;
|
||||||
QThread * scalarThread;
|
TimingThread * scalarTimingThread;
|
||||||
ScalarWorker * scalarWorker;
|
// QThread * scalarThread;
|
||||||
QTimer * scalarTimer;
|
// ScalarWorker * scalarWorker;
|
||||||
|
// QTimer * scalarTimer;
|
||||||
|
|
||||||
|
|
||||||
// TimingThread * scalarThread;
|
// TimingThread * scalarThread;
|
||||||
QLineEdit *** leTrigger; // need to delete manually
|
QLineEdit *** leTrigger; // need to delete manually
|
||||||
|
@ -212,23 +214,23 @@ private:
|
||||||
|
|
||||||
//^======================== Scalar Worker
|
//^======================== Scalar Worker
|
||||||
|
|
||||||
class ScalarWorker : public QObject{
|
// class ScalarWorker : public QObject{
|
||||||
Q_OBJECT
|
// Q_OBJECT
|
||||||
public:
|
// public:
|
||||||
ScalarWorker(FSUDAQ * parent): SS(parent){}
|
// ScalarWorker(FSUDAQ * parent): SS(parent){}
|
||||||
|
|
||||||
public slots:
|
// public slots:
|
||||||
void UpdateScalar(){
|
// void UpdateScalar(){
|
||||||
SS->UpdateScalar();
|
// SS->UpdateScalar();
|
||||||
emit workDone();
|
// emit workDone();
|
||||||
}
|
// }
|
||||||
|
|
||||||
signals:
|
// signals:
|
||||||
void workDone();
|
// void workDone();
|
||||||
|
|
||||||
private:
|
// private:
|
||||||
FSUDAQ * SS;
|
// FSUDAQ * SS;
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
Loading…
Reference in New Issue
Block a user