2023-02-09 18:27:20 -05:00
|
|
|
|
|
|
|
#ifndef MANYTHREADS_H
|
|
|
|
#define MANYTHREADS_H
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMutex>
|
|
|
|
|
|
|
|
#include "ClassDigitizer2Gen.h"
|
|
|
|
|
|
|
|
static QMutex digiMTX;
|
|
|
|
|
|
|
|
//^#===================================================== ReadData Thread
|
|
|
|
class ReadDataThread : public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
|
|
|
|
this->digi = dig;
|
2023-02-14 17:39:49 -05:00
|
|
|
isSaveData = false;
|
2023-02-09 18:27:20 -05:00
|
|
|
}
|
2023-02-14 17:39:49 -05:00
|
|
|
void SetSaveData(bool onOff) {this->isSaveData = onOff;}
|
2023-02-09 18:27:20 -05:00
|
|
|
void run(){
|
|
|
|
clock_gettime(CLOCK_REALTIME, &ta);
|
|
|
|
while(true){
|
|
|
|
digiMTX.lock();
|
|
|
|
int ret = digi->ReadData();
|
|
|
|
digiMTX.unlock();
|
|
|
|
|
|
|
|
if( ret == CAEN_FELib_Success){
|
2023-02-14 17:39:49 -05:00
|
|
|
if( isSaveData) digi->SaveDataToFile();
|
2023-02-09 18:27:20 -05:00
|
|
|
}else if(ret == CAEN_FELib_Stop){
|
|
|
|
digi->ErrorMsg("No more data");
|
2023-02-22 12:41:48 -05:00
|
|
|
//emit endOfLastData();
|
2023-02-09 18:27:20 -05:00
|
|
|
break;
|
|
|
|
}else{
|
2023-02-14 18:44:10 -05:00
|
|
|
//digi->ErrorMsg("ReadDataLoop()");
|
2023-02-09 18:27:20 -05:00
|
|
|
digi->evt->ClearTrace();
|
|
|
|
}
|
|
|
|
|
2023-02-14 17:39:49 -05:00
|
|
|
if( isSaveData ){
|
2023-02-09 18:27:20 -05:00
|
|
|
clock_gettime(CLOCK_REALTIME, &tb);
|
|
|
|
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
2023-02-22 12:41:48 -05:00
|
|
|
emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetTotalFilesSize()/1024./1024.) + " MB");
|
|
|
|
//emit checkFileSize();
|
2023-02-09 18:27:20 -05:00
|
|
|
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
|
|
|
|
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
|
|
|
|
ta = tb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
signals:
|
|
|
|
void sendMsg(const QString &msg);
|
2023-02-22 12:41:48 -05:00
|
|
|
//void endOfLastData();
|
|
|
|
//void checkFileSize();
|
2023-02-09 18:27:20 -05:00
|
|
|
private:
|
|
|
|
Digitizer2Gen * digi;
|
|
|
|
timespec ta, tb;
|
2023-02-14 17:39:49 -05:00
|
|
|
bool isSaveData;
|
2023-02-09 18:27:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//^#===================================================== UpdateTrace Thread
|
|
|
|
class UpdateTraceThread : public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
UpdateTraceThread(QObject * parent = 0) : QThread(parent){
|
|
|
|
waitTime = 2;
|
|
|
|
stop = false;
|
|
|
|
}
|
2023-02-17 19:30:31 -05:00
|
|
|
unsigned int GetWaitTimeSec() const {return waitTime;}
|
|
|
|
void SetWaitTimeSec(unsigned sec) {waitTime = sec;}
|
2023-02-09 18:27:20 -05:00
|
|
|
void Stop() {this->stop = true;}
|
|
|
|
void run(){
|
|
|
|
unsigned int count = 0;
|
|
|
|
stop = false;
|
|
|
|
do{
|
|
|
|
usleep(100000);
|
|
|
|
count ++;
|
|
|
|
if( count % waitTime == 0){
|
|
|
|
emit updateTrace();
|
|
|
|
}
|
|
|
|
}while(!stop);
|
|
|
|
}
|
|
|
|
signals:
|
|
|
|
void updateTrace();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool stop;
|
|
|
|
unsigned int waitTime; //100 of milisec
|
|
|
|
};
|
|
|
|
|
2023-02-13 17:07:26 -05:00
|
|
|
//^#======================================================= Scalar Thread
|
|
|
|
class ScalarThread : public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ScalarThread(QObject * parent = 0 ) : QThread(parent){
|
|
|
|
waitTime = 20; // 10 x 100 milisec
|
|
|
|
stop = false;
|
|
|
|
}
|
|
|
|
void Stop() { this->stop = true;}
|
|
|
|
unsigned int GetWaitTimeinSec() const {return waitTime/10;}
|
|
|
|
void run(){
|
|
|
|
unsigned int count = 0;
|
|
|
|
stop = false;
|
|
|
|
do{
|
|
|
|
usleep(100000);
|
|
|
|
count ++;
|
|
|
|
if( count % waitTime == 0){
|
|
|
|
emit updataScalar();
|
|
|
|
}
|
|
|
|
}while(!stop);
|
|
|
|
}
|
|
|
|
signals:
|
|
|
|
void updataScalar();
|
|
|
|
private:
|
|
|
|
bool stop;
|
|
|
|
unsigned int waitTime;
|
|
|
|
};
|
|
|
|
|
2023-02-09 18:27:20 -05:00
|
|
|
#endif
|