2023-04-14 16:12:52 -04:00
|
|
|
#ifndef CUSTOMTHREADS_H
|
|
|
|
#define CUSTOMTHREADS_H
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMutex>
|
2023-06-29 18:59:36 -04:00
|
|
|
#include <QWaitCondition>
|
2023-10-19 14:29:28 -04:00
|
|
|
#include <QMessageBox>
|
2023-04-14 16:12:52 -04:00
|
|
|
|
|
|
|
#include "macro.h"
|
|
|
|
#include "ClassDigitizer.h"
|
|
|
|
|
|
|
|
static QMutex digiMTX[MaxNBoards * MaxNPorts];
|
|
|
|
|
|
|
|
//^#===================================================== ReadData Thread
|
|
|
|
class ReadDataThread : public QThread {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
ReadDataThread(Digitizer * dig, int digiID, QObject * parent = 0) : QThread(parent){
|
|
|
|
this->digi = dig;
|
|
|
|
this->ID = digiID;
|
|
|
|
isSaveData = false;
|
2023-04-19 16:21:14 -04:00
|
|
|
isScope = false;
|
2023-05-22 17:00:11 -04:00
|
|
|
readCount = 0;
|
|
|
|
stop = false;
|
2023-04-14 16:12:52 -04:00
|
|
|
}
|
2023-05-22 17:00:11 -04:00
|
|
|
void Stop() { this->stop = true;}
|
2023-04-19 16:21:14 -04:00
|
|
|
void SetSaveData(bool onOff) {this->isSaveData = onOff;}
|
|
|
|
void SetScopeMode(bool onOff) {this->isScope = onOff;}
|
2023-06-29 18:59:36 -04:00
|
|
|
|
2024-02-26 19:05:16 -05:00
|
|
|
void SetReadCountZero() {readCount = 0;}
|
|
|
|
unsigned long GetReadCount() const {return readCount;}
|
2023-06-29 18:59:36 -04:00
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
void run(){
|
2023-06-29 18:59:36 -04:00
|
|
|
|
|
|
|
stop = false;
|
2024-02-26 19:05:16 -05:00
|
|
|
readCount = 0;
|
2023-05-23 14:52:23 -04:00
|
|
|
clock_gettime(CLOCK_REALTIME, &t0);
|
|
|
|
ta = t0;
|
2023-06-29 18:59:36 -04:00
|
|
|
|
2023-09-08 17:21:05 -04:00
|
|
|
printf("ReadDataThread for digi-%d running.\n", digi->GetSerialNumber());
|
2023-05-22 17:00:11 -04:00
|
|
|
do{
|
|
|
|
|
|
|
|
if( stop) break;
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
digiMTX[ID].lock();
|
|
|
|
int ret = digi->ReadData();
|
|
|
|
digiMTX[ID].unlock();
|
2023-05-22 17:00:11 -04:00
|
|
|
readCount ++;
|
2023-04-14 16:12:52 -04:00
|
|
|
|
2023-05-22 17:00:11 -04:00
|
|
|
if( stop) break;
|
2023-05-26 18:06:37 -04:00
|
|
|
|
2023-05-22 17:00:11 -04:00
|
|
|
if( ret == CAEN_DGTZ_Success && !stop){
|
2023-04-14 16:12:52 -04:00
|
|
|
digiMTX[ID].lock();
|
2023-05-22 17:00:11 -04:00
|
|
|
digi->GetData()->DecodeBuffer(!isScope, 0);
|
2023-04-19 16:21:14 -04:00
|
|
|
if( isSaveData ) digi->GetData()->SaveData();
|
2023-04-14 16:12:52 -04:00
|
|
|
digiMTX[ID].unlock();
|
|
|
|
|
|
|
|
}else{
|
2023-04-19 16:21:14 -04:00
|
|
|
printf("ReadDataThread::%s------------ ret : %d \n", __func__, ret);
|
2023-05-22 17:00:11 -04:00
|
|
|
digiMTX[ID].lock();
|
2023-05-12 16:06:32 -04:00
|
|
|
digi->StopACQ();
|
2023-11-20 12:10:36 -05:00
|
|
|
if( ret == CAEN_DGTZ_OutOfMemory ){
|
|
|
|
digi->WriteRegister(DPP::SoftwareClear_W, 1);
|
|
|
|
digi->GetData()->ClearData();
|
|
|
|
}
|
|
|
|
digi->ReadACQStatus();
|
2023-05-22 17:00:11 -04:00
|
|
|
digiMTX[ID].unlock();
|
2023-11-20 12:10:36 -05:00
|
|
|
emit sendMsg("Digi-" + QString::number(digi->GetSerialNumber()) + " ACQ off.");
|
|
|
|
stop = true;
|
2023-05-12 16:06:32 -04:00
|
|
|
break;
|
2023-04-14 16:12:52 -04:00
|
|
|
}
|
2023-05-17 16:16:48 -04:00
|
|
|
|
2024-03-19 16:13:44 -04:00
|
|
|
clock_gettime(CLOCK_REALTIME, &t1);
|
|
|
|
if( t1.tv_sec - ta.tv_sec > 2 ){
|
|
|
|
digiMTX[ID].lock();
|
|
|
|
digi->ReadACQStatus();
|
|
|
|
digiMTX[ID].unlock();
|
|
|
|
ta = t1;
|
|
|
|
}
|
|
|
|
|
2023-05-22 17:00:11 -04:00
|
|
|
if( isSaveData && !stop ) {
|
2023-05-17 16:16:48 -04:00
|
|
|
clock_gettime(CLOCK_REALTIME, &tb);
|
|
|
|
if( tb.tv_sec - ta.tv_sec > 2 ) {
|
2023-05-22 17:00:11 -04:00
|
|
|
digiMTX[ID].lock();
|
2023-05-23 14:52:23 -04:00
|
|
|
emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetData()->GetTotalFileSize()/1024./1024., 'f', 4) + " MB [" + QString::number(tb.tv_sec-t0.tv_sec) + " sec]");
|
2024-02-26 19:05:16 -05:00
|
|
|
//emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetData()->GetTotalFileSize()/1024./1024., 'f', 4) + " MB [" + QString::number(tb.tv_sec-t0.tv_sec) + " sec] (" + QString::number(readCount) + ")");
|
2023-05-22 17:00:11 -04:00
|
|
|
digiMTX[ID].unlock();
|
2024-02-26 19:05:16 -05:00
|
|
|
// readCount = 0;
|
2023-05-17 16:16:48 -04:00
|
|
|
ta = tb;
|
|
|
|
}
|
|
|
|
}
|
2023-05-22 17:00:11 -04:00
|
|
|
|
|
|
|
}while(!stop);
|
2023-09-08 17:21:05 -04:00
|
|
|
printf("ReadDataThread for digi-%d stopped.\n", digi->GetSerialNumber());
|
2023-04-14 16:12:52 -04:00
|
|
|
}
|
|
|
|
signals:
|
|
|
|
void sendMsg(const QString &msg);
|
|
|
|
private:
|
|
|
|
Digitizer * digi;
|
2023-05-22 17:00:11 -04:00
|
|
|
bool stop;
|
2023-04-14 16:12:52 -04:00
|
|
|
int ID;
|
2023-05-23 14:52:23 -04:00
|
|
|
timespec ta, tb, t1, t2, t0;
|
2023-04-14 16:12:52 -04:00
|
|
|
bool isSaveData;
|
2023-04-19 16:21:14 -04:00
|
|
|
bool isScope;
|
2023-06-29 18:59:36 -04:00
|
|
|
unsigned long readCount;
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
};
|
|
|
|
|
2023-04-19 16:21:14 -04:00
|
|
|
//^#======================================================= Timing Thread
|
|
|
|
class TimingThread : public QThread {
|
2023-04-14 16:12:52 -04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2023-04-19 16:21:14 -04:00
|
|
|
TimingThread(QObject * parent = 0 ) : QThread(parent){
|
2023-10-19 14:29:28 -04:00
|
|
|
waitTime = 20; // multiple of 100 mili sec
|
2023-04-14 16:12:52 -04:00
|
|
|
stop = false;
|
|
|
|
}
|
|
|
|
void Stop() { this->stop = true;}
|
2023-04-19 16:21:14 -04:00
|
|
|
void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;}
|
2023-04-19 18:08:20 -04:00
|
|
|
float GetWaitTimeinSec() const {return waitTime/10.;}
|
2023-11-21 15:34:29 -05:00
|
|
|
void DoOnce() {emit timeUp();};
|
2023-04-14 16:12:52 -04:00
|
|
|
void run(){
|
|
|
|
unsigned int count = 0;
|
|
|
|
stop = false;
|
|
|
|
do{
|
|
|
|
usleep(100000);
|
|
|
|
count ++;
|
|
|
|
if( count % waitTime == 0){
|
2023-04-19 18:08:20 -04:00
|
|
|
emit timeUp();
|
2023-04-14 16:12:52 -04:00
|
|
|
}
|
|
|
|
}while(!stop);
|
|
|
|
}
|
|
|
|
signals:
|
2023-04-19 18:08:20 -04:00
|
|
|
void timeUp();
|
2023-04-14 16:12:52 -04:00
|
|
|
private:
|
|
|
|
bool stop;
|
|
|
|
unsigned int waitTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|