thread on read data

This commit is contained in:
Ryan Tang 2023-01-30 18:40:24 -05:00
parent b358bdb2c9
commit 01641e38f4
6 changed files with 298 additions and 80 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# This file is used to ignore files which are generated # This file is used to ignore files which are generated
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
SOLARIS_DAQ SOLARIS_DAQ
*.sol
*~ *~
*.autosave *.autosave

View File

@ -106,6 +106,7 @@ class Digitizer2Gen {
void OpenOutFile(std::string fileName); void OpenOutFile(std::string fileName);
void CloseOutFile(); void CloseOutFile();
void SaveDataToFile(); void SaveDataToFile();
unsigned int GetFileSize() {return outFileSize;}
}; };

View File

@ -28,31 +28,24 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
{"Input Impedance [Ohm] : ", "/par/Zin"} {"Input Impedance [Ohm] : ", "/par/Zin"}
}; };
QVBoxLayout * mainLayout = new QVBoxLayout(this); QVBoxLayout * mainLayout = new QVBoxLayout(this); this->setLayout(mainLayout);
this->setLayout(mainLayout); QTabWidget * tabWidget = new QTabWidget(this); mainLayout->addWidget(tabWidget);
QTabWidget * tabWidget = new QTabWidget(this);
mainLayout->addWidget(tabWidget);
//============ Tab for each digitizer //============ Tab for each digitizer
for(unsigned short i = 0; i < this->nDigi; i++){ for(unsigned short iDigi = 0; iDigi < this->nDigi; iDigi++){
QWidget * tab = new QWidget(tabWidget); QWidget * tab = new QWidget(tabWidget);
QScrollArea * scrollArea = new QScrollArea(this); scrollArea->setWidget(tab);
QScrollArea * scrollArea = new QScrollArea;
scrollArea->setWidget(tab);
scrollArea->setWidgetResizable(true); scrollArea->setWidgetResizable(true);
scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tabWidget->addTab(scrollArea, "Digi-" + QString::number(digi->GetSerialNumber())); tabWidget->addTab(scrollArea, "Digi-" + QString::number(digi->GetSerialNumber()));
QGridLayout *tabLayout = new QGridLayout(tab); QGridLayout *tabLayout = new QGridLayout(tab); tab->setLayout(tabLayout);
tab->setLayout(tabLayout);
{//-------- Group of Digitizer Info {//-------- Group of Digitizer Info
QGroupBox * infoBox = new QGroupBox("Board Info", tab); QGroupBox * infoBox = new QGroupBox("Board Info", tab);
QGridLayout * infoLayout = new QGridLayout(infoBox); QGridLayout * infoLayout = new QGridLayout(infoBox);
infoBox->setLayout(infoLayout);
tabLayout->addWidget(infoBox, 0, 0); tabLayout->addWidget(infoBox, 0, 0);
const unsigned short nRow = 4; const unsigned short nRow = 4;
@ -70,23 +63,23 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
{//------- Group Board status {//------- Group Board status
QGroupBox * statusBox = new QGroupBox("Board Status", tab); QGroupBox * statusBox = new QGroupBox("Board Status", tab);
QGridLayout * statusLayout = new QGridLayout(statusBox); QGridLayout * statusLayout = new QGridLayout(statusBox);
statusBox->setLayout(statusLayout); tabLayout->addWidget(statusBox, 0, 1);
tabLayout->addWidget(statusBox, 1, 0);
} }
{//------- Group digitizer settings {//------- Group digitizer settings
QGroupBox * digiBox = new QGroupBox("Board Settings", tab); QGroupBox * digiBox = new QGroupBox("Board Settings", tab);
QGridLayout * boardLayout = new QGridLayout(digiBox); QGridLayout * boardLayout = new QGridLayout(digiBox);
digiBox->setLayout(boardLayout); tabLayout->addWidget(digiBox, 1, 0);
tabLayout->addWidget(digiBox, 2, 0);
int rowId = 0; int rowId = 0;
//------------------------------------- //-------------------------------------
QPushButton * bnResetBd = new QPushButton("Reset Board", tab); QPushButton * bnResetBd = new QPushButton("Reset Board", tab);
boardLayout->addWidget(bnResetBd, rowId, 0, 1, 2); boardLayout->addWidget(bnResetBd, rowId, 0, 1, 2);
connect(bnResetBd, &QPushButton::clicked, this, &DigiSettings::onReset);
QPushButton * bnDefaultSetting = new QPushButton("Set Default Settings", tab); QPushButton * bnDefaultSetting = new QPushButton("Set Default Settings", tab);
boardLayout->addWidget(bnDefaultSetting, rowId, 2, 1, 2); boardLayout->addWidget(bnDefaultSetting, rowId, 2, 1, 2);
connect(bnDefaultSetting, &QPushButton::clicked, this, &DigiSettings::onDefault);
//------------------------------------- //-------------------------------------
rowId ++; rowId ++;
@ -288,18 +281,65 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
} }
{//------- Group channel settings {//------- Group channel settings
QGroupBox * chBox = new QGroupBox("Channel Settings", tab); QGroupBox * chBox = new QGroupBox("Channel Settings", tab); tabLayout->addWidget(chBox, 1, 1, 1, 1);
QGridLayout * chLayout = new QGridLayout(chBox); QGridLayout * chLayout = new QGridLayout(chBox); //chBox->setLayout(chLayout);
chBox->setLayout(chLayout);
tabLayout->addWidget(chBox, 0, 1, 10, 1);
//chLayout->setVerticalSpacing(0);
QSignalMapper * onOffMapper = new QSignalMapper(tab); QSignalMapper * onOffMapper = new QSignalMapper(tab);
connect(onOffMapper, &QSignalMapper::mappedInt, this, &DigiSettings::onChannelonOff); connect(onOffMapper, &QSignalMapper::mappedInt, this, &DigiSettings::onChannelonOff);
QTabWidget * chTabWidget = new QTabWidget(tab); chLayout->addWidget(chTabWidget);
{//.......... All Settings tab
QWidget * tab_All = new QWidget(tab);
chTabWidget->addTab(tab_All, "All Settings");
tab_All->setStyleSheet("background-color: #EEEEEE");
QGridLayout * allLayout = new QGridLayout(tab_All);
allLayout->setHorizontalSpacing(0);
allLayout->setVerticalSpacing(0);
unsigned short ch = digi->GetNChannels();
cbCh[iDigi][ch] = new QCheckBox("On/Off", tab); allLayout->addWidget(cbCh[iDigi][ch], 0, 0);
onOffMapper->setMapping(cbCh[iDigi][ch], (iDigi << 12) + ch);
connect(cbCh[iDigi][ch], SIGNAL(clicked()), onOffMapper, SLOT(map()));
QLabel * lbRL = new QLabel("Record Length [ns]", tab); allLayout->addWidget(lbRL, 1, 0);
lbRL->setAlignment(Qt::AlignRight);
sbRecordLength[ch] = new QSpinBox(tab); allLayout->addWidget(sbRecordLength[ch], 1, 1);
QLabel * lbPT = new QLabel("Pre Trigger [ns]", tab); allLayout->addWidget(lbPT, 1, 2);
lbPT->setAlignment(Qt::AlignRight);
sbPreTrigger[ch] = new QSpinBox(tab); allLayout->addWidget(sbPreTrigger[ch], 1, 3);
}
{//.......... Ch On/Off
QWidget * tab_onOff = new QWidget(tab); chTabWidget->addTab(tab_onOff, "On/Off");
tab_onOff->setStyleSheet("background-color: #EEEEEE");
QGridLayout * allLayout = new QGridLayout(tab_onOff);
allLayout->setHorizontalSpacing(0);
allLayout->setVerticalSpacing(0);
for( int ch = 0; ch < digi->GetNChannels(); ch++){
cbCh[iDigi][ch] = new QCheckBox(QString::number(ch)); allLayout->addWidget(cbCh[iDigi][ch], ch/8, ch%8);
cbCh[iDigi][ch]->setLayoutDirection(Qt::RightToLeft);
onOffMapper->setMapping(cbCh[iDigi][ch], (iDigi << 12) + ch);
connect(cbCh[iDigi][ch], SIGNAL(clicked()), onOffMapper, SLOT(map()));
}
}
/*
for( unsigned short rowID = 0; rowID < digi->GetNChannels() + 2; rowID++){ for( unsigned short rowID = 0; rowID < digi->GetNChannels() + 2; rowID++){
//------ set Labels //------ set Labels
@ -372,7 +412,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
//------ set all channel //------ set all channel
if( rowID == 0 || rowID >= 2){ if( rowID == 0 || rowID >= 2){
unsigned int ch = (rowID == 0 ? 0 : rowID-2); unsigned int ch = (rowID == 0 ? 64 : rowID-2);
unsigned short colID = 0; unsigned short colID = 0;
QLabel * labCh = new QLabel(rowID == 0 ? "All" : QString::number(ch), tab); QLabel * labCh = new QLabel(rowID == 0 ? "All" : QString::number(ch), tab);
@ -547,14 +587,14 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
} }
} }*/ //-- end of ch loop;
} }
{//------- Group trigger settings {//------- Group trigger settings
QGroupBox * triggerBox = new QGroupBox("Trigger Map", tab); QGroupBox * triggerBox = new QGroupBox("Trigger Map", tab);
QGridLayout * triggerLayout = new QGridLayout(triggerBox); QGridLayout * triggerLayout = new QGridLayout(triggerBox);
triggerBox->setLayout(triggerLayout); //triggerBox->setLayout(triggerLayout);
tabLayout->addWidget(triggerBox, 3, 0); tabLayout->addWidget(triggerBox, 2, 0);
triggerLayout->setHorizontalSpacing(0); triggerLayout->setHorizontalSpacing(0);
triggerLayout->setVerticalSpacing(0); triggerLayout->setVerticalSpacing(0);
@ -581,7 +621,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
} }
triggerLayout->addWidget(bn[i][j], rowID, colID); triggerLayout->addWidget(bn[i][j], rowID, colID);
triggerMapper->setMapping(bn[i][j], 100*i+j); triggerMapper->setMapping(bn[i][j], (iDigi << 12) + (i << 8) + j);
connect(bn[i][j], SIGNAL(clicked()), triggerMapper, SLOT(map())); connect(bn[i][j], SIGNAL(clicked()), triggerMapper, SLOT(map()));
colID ++; colID ++;
@ -617,4 +657,10 @@ DigiSettings::~DigiSettings(){
printf("%s\n", __func__); printf("%s\n", __func__);
for( int iDig = 0; iDig < nDigi; iDig ++){
for( int i =0 ; i < MaxNumberOfChannel; i++){
if( cbCh[iDig][i] != NULL) delete cbCh[iDig][i];
}
}
} }

View File

@ -19,6 +19,8 @@
#include "ClassDigitizer2Gen.h" #include "ClassDigitizer2Gen.h"
#define MaxNumberOfDigitizer 10
class DigiSettings : public QWidget{ class DigiSettings : public QWidget{
Q_OBJECT Q_OBJECT
@ -27,10 +29,23 @@ public:
~DigiSettings(); ~DigiSettings();
private slots: private slots:
void onReset(){
emit sendLogMsg("Reset Digitizer-" + QString::number(digi->GetSerialNumber()));
digi->Reset();
}
void onDefault(){
emit sendLogMsg("Program Digitizer-" + QString::number(digi->GetSerialNumber()) + " to default PHA.");
digi->ProgramPHA();
}
void onTriggerClick(int haha){ void onTriggerClick(int haha){
unsigned short ch = haha/100; unsigned short iDig = haha >> 12;
unsigned short ch2 = haha - ch*100; unsigned short ch = (haha >> 8 ) & 0xF;
unsigned short ch2 = haha & 0xFF;
qDebug() << "Digi-" << iDig << ", Ch-" << ch << ", " << ch2;
if(bnClickStatus[ch][ch2]){ if(bnClickStatus[ch][ch2]){
bn[ch][ch2]->setStyleSheet(""); bn[ch][ch2]->setStyleSheet("");
@ -41,24 +56,41 @@ private slots:
} }
} }
void onChannelonOff(int haha){ void onChannelonOff(int haha){
qDebug() << haha;
unsigned short iDig = haha >> 12;
//qDebug()<< "nDigi-" << iDig << ", ch-" << (haha & 0xFF);
if( (haha & 0xFF) == 64){
if( haha == 64){ if( cbCh[iDig][64]->isChecked() ){
if( cbCh[64]->isChecked() ){
for( int i = 0 ; i < digi->GetNChannels() ; i++){ for( int i = 0 ; i < digi->GetNChannels() ; i++){
cbCh[i]->setChecked(true); cbCh[iDig][i]->setChecked(true);
} }
}else{ }else{
for( int i = 0 ; i < digi->GetNChannels() ; i++){ for( int i = 0 ; i < digi->GetNChannels() ; i++){
cbCh[i]->setChecked(false); cbCh[iDig][i]->setChecked(false);
} }
} }
}else{
unsigned int nOn = 0;
for( int i = 0; i < digi->GetNChannels(); i++){
nOn += (cbCh[iDig][i]->isChecked() ? 1 : 0);
}
if( nOn == 64){
cbCh[iDig][64]->setChecked(true);
}else{
cbCh[iDig][64]->setChecked(false);
}
} }
} }
signals: signals:
void sendLogMsg(const QString &msg);
private: private:
Digitizer2Gen * digi; Digitizer2Gen * digi;
@ -67,10 +99,11 @@ private:
QPushButton *bn[MaxNumberOfChannel][MaxNumberOfChannel]; QPushButton *bn[MaxNumberOfChannel][MaxNumberOfChannel];
bool bnClickStatus[MaxNumberOfChannel][MaxNumberOfChannel]; bool bnClickStatus[MaxNumberOfChannel][MaxNumberOfChannel];
QCheckBox * cbCh[MaxNumberOfChannel + 1]; // index = 64 is for all channels QCheckBox * cbCh[MaxNumberOfDigitizer][MaxNumberOfChannel + 1]; // index = 64 is for all channels
QSpinBox * sbRecordLength[MaxNumberOfChannel + 1]; QSpinBox * sbRecordLength[MaxNumberOfChannel + 1];
QSpinBox * sbPreTrigger[MaxNumberOfChannel + 1]; QSpinBox * sbPreTrigger[MaxNumberOfChannel + 1];
QComboBox * cmbWaveRes[MaxNumberOfChannel + 1]; QComboBox * cmbWaveRes[MaxNumberOfChannel + 1];
QComboBox * cmbAnaProbe0[MaxNumberOfChannel + 1]; QComboBox * cmbAnaProbe0[MaxNumberOfChannel + 1];
@ -87,7 +120,7 @@ private:
QComboBox * cmbChVetoSrc[MaxNumberOfChannel + 1]; QComboBox * cmbChVetoSrc[MaxNumberOfChannel + 1];
QSpinBox * sbChADCVetoWidth[MaxNumberOfChannel + 1]; QSpinBox * sbChADCVetoWidth[MaxNumberOfChannel + 1];
}; };

View File

@ -3,10 +3,15 @@
#include <QLabel> #include <QLabel>
#include <QGridLayout> #include <QGridLayout>
#include <unistd.h>
//------ static memeber
Digitizer2Gen * MainWindow::digi = NULL;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
setWindowTitle("SOLARIS DAQ"); setWindowTitle("SOLARIS DAQ");
setGeometry(500, 500, 1000, 500); setGeometry(500, 100, 1000, 500);
QIcon icon("SOLARIS_favicon.png"); QIcon icon("SOLARIS_favicon.png");
setWindowIcon(icon); setWindowIcon(icon);
@ -16,16 +21,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
QWidget * mainLayoutWidget = new QWidget(this); QWidget * mainLayoutWidget = new QWidget(this);
setCentralWidget(mainLayoutWidget); setCentralWidget(mainLayoutWidget);
QVBoxLayout * layout1 = new QVBoxLayout(mainLayoutWidget); QVBoxLayout * layoutMain = new QVBoxLayout(mainLayoutWidget);
mainLayoutWidget->setLayout(layout1); mainLayoutWidget->setLayout(layoutMain);
{
QGridLayout *layout = new QGridLayout(); {//====================== General
layout1->addLayout(layout); QGroupBox * box1 = new QGroupBox("General", mainLayoutWidget);
layout1->addStretch(); layoutMain->addWidget(box1);
layout1->setStretchFactor(layout, 8);
QGridLayout * layout1 = new QGridLayout(box1);
bnProgramSettings = new QPushButton("Program Settings", this); bnProgramSettings = new QPushButton("Program Settings", this);
bnProgramSettings->setEnabled(false);
bnOpenDigitizers = new QPushButton("Open Digitizers", this); bnOpenDigitizers = new QPushButton("Open Digitizers", this);
connect(bnOpenDigitizers, SIGNAL(clicked()), this, SLOT(bnOpenDigitizers_clicked())); connect(bnOpenDigitizers, SIGNAL(clicked()), this, SLOT(bnOpenDigitizers_clicked()));
@ -38,42 +45,55 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnDigiSettings->setEnabled(false); bnDigiSettings->setEnabled(false);
connect(bnDigiSettings, SIGNAL(clicked()), this, SLOT(OpenDigitizersSettings())); connect(bnDigiSettings, SIGNAL(clicked()), this, SLOT(OpenDigitizersSettings()));
bnStartACQ = new QPushButton("Start ACQ", this);
bnStartACQ->setEnabled(false);
bnStopACQ = new QPushButton("Stop ACQ", this);
bnStopACQ->setEnabled(false);
layout->addWidget(bnProgramSettings, 0, 0); layout1->addWidget(bnProgramSettings, 0, 0);
layout->addWidget(bnOpenDigitizers, 0, 1); layout1->addWidget(bnOpenDigitizers, 0, 1);
layout->addWidget(bnCloseDigitizers, 0, 2); layout1->addWidget(bnCloseDigitizers, 0, 2);
layout->addWidget(bnDigiSettings, 1, 1); layout1->addWidget(bnDigiSettings, 1, 1);
QFrame * separator = new QFrame(this);
separator->setFrameShape(QFrame::HLine);
layout->addWidget(separator, 2, 0, 1, 3);
layout->addWidget(bnStartACQ, 3, 0);
layout->addWidget(bnStopACQ, 3, 1);
} }
logInfo = new QPlainTextEdit(this);
logInfo->isReadOnly();
logInfo->setGeometry(100, 200, 500, 100);
layout1->addWidget(logInfo); {//====================== ACD control
layout1->setStretchFactor(logInfo, 1); QGroupBox * box2 = new QGroupBox("ACQ control", mainLayoutWidget);
layoutMain->addWidget(box2);
QGridLayout * layout2 = new QGridLayout(box2);
bnStartACQ = new QPushButton("Start ACQ", this);
bnStartACQ->setEnabled(false);
connect(bnStartACQ, &QPushButton::clicked, this, &MainWindow::StartACQ);
bnStopACQ = new QPushButton("Stop ACQ", this);
bnStopACQ->setEnabled(false);
connect(bnStopACQ, &QPushButton::clicked, this, &MainWindow::StopACQ);
layout2->addWidget(bnStartACQ, 0, 0);
layout2->addWidget(bnStopACQ, 0, 1);
}
//StartRunThread = new QThread(this); layoutMain->addStretch();
//connect(StartRunThread, &QThread::started, this, &MainWindow::onThreadStarted);
//connect(StartRunThread, &QThread::finished, this, &MainWindow::onThreadFinished);
{//===================== Log Msg
QGroupBox * box3 = new QGroupBox("Log Message", mainLayoutWidget);
layoutMain->addWidget(box3);
layoutMain->setStretchFactor(box3, 1);
QGridLayout * layout3 = new QGridLayout(box3);
logInfo = new QPlainTextEdit(this);
logInfo->isReadOnly();
logInfo->setGeometry(100, 200, 500, 100);
layout3->addWidget(logInfo);
}
LogMsg("Welcome to SOLARIS DAQ."); LogMsg("Welcome to SOLARIS DAQ.");
bnOpenDigitizers_clicked(); //bnOpenDigitizers_clicked();
OpenDigitizersSettings(); //OpenDigitizersSettings();
} }
@ -92,9 +112,49 @@ MainWindow::~MainWindow(){
delete digi; delete digi;
} }
//StartRunThread->quit(); readDataThread->Stop();
//StartRunThread->wait(); readDataThread->quit();
//delete StartRunThread; readDataThread->wait();
delete readDataThread;
}
//################################################################
void MainWindow::StartACQ(){
digi->Reset();
digi->ProgramPHA(false);
digi->SetPHADataFormat(1);// only save 1 trace
remove("haha_000.sol"); // remove file
digi->OpenOutFile("haha");// haha_000.sol
digi->StartACQ();
LogMsg("Start Run....");
readDataThread->start();
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(true);
LogMsg("end of " + QString::fromStdString(__func__));
}
void MainWindow::StopACQ(){
digi->StopACQ();
//readDataThread->Stop();
readDataThread->quit();
readDataThread->wait();
digi->CloseOutFile();
LogMsg("Stop Run");
bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
} }
@ -115,6 +175,10 @@ void MainWindow::bnOpenDigitizers_clicked(){
bnCloseDigitizers->setEnabled(true); bnCloseDigitizers->setEnabled(true);
bnDigiSettings->setEnabled(true); bnDigiSettings->setEnabled(true);
bnStartACQ->setEnabled(true); bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
readDataThread = new ReadDataThread(digi, this);
connect(readDataThread, &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
}else{ }else{
LogMsg("Cannot open digitizer"); LogMsg("Cannot open digitizer");
@ -126,6 +190,7 @@ void MainWindow::bnOpenDigitizers_clicked(){
nDigi ++; nDigi ++;
} }
} }
void MainWindow::bnCloseDigitizers_clicked(){ void MainWindow::bnCloseDigitizers_clicked(){
@ -143,6 +208,9 @@ void MainWindow::bnCloseDigitizers_clicked(){
bnDigiSettings->setEnabled(false); bnDigiSettings->setEnabled(false);
bnStartACQ->setEnabled(false); bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(false); bnStopACQ->setEnabled(false);
if( digiSetting != NULL ) digiSetting->close();
} }
} }
@ -151,6 +219,7 @@ void MainWindow::OpenDigitizersSettings(){
if( digiSetting == NULL){ if( digiSetting == NULL){
digiSetting = new DigiSettings(digi, nDigi); digiSetting = new DigiSettings(digi, nDigi);
connect(digiSetting, &DigiSettings::sendLogMsg, this, &MainWindow::LogMsg);
digiSetting->show(); digiSetting->show();
}else{ }else{
digiSetting->show(); digiSetting->show();
@ -163,6 +232,6 @@ void MainWindow::LogMsg(QString msg){
logInfo->appendPlainText(countStr); logInfo->appendPlainText(countStr);
QScrollBar *v = logInfo->verticalScrollBar(); QScrollBar *v = logInfo->verticalScrollBar();
v->setValue(v->maximum()); v->setValue(v->maximum());
qDebug() << msg; //qDebug() << msg;
logInfo->repaint(); logInfo->repaint();
} }

View File

@ -10,13 +10,78 @@
#include <QDateTime> #include <QDateTime>
#include <QScrollBar> #include <QScrollBar>
#include <QPushButton> #include <QPushButton>
#include <QMutex>
#include <vector> #include <vector>
#include <time.h> // time in nano-sec
#include "ClassDigitizer2Gen.h"
#include "digiSettings.h" #include "digiSettings.h"
static Digitizer2Gen * digi = NULL; #include "ClassDigitizer2Gen.h"
#include "influxdb.h"
static QMutex digiMTX;
class ReadDataThread : public QThread{
Q_OBJECT
public:
ReadDataThread(Digitizer2Gen * dig, QObject * parent = 0) : QThread(parent){
stop = false;
this->digi = dig;
readCount = 0;
}
void Stop() {stop = true;}
void run(){
clock_gettime(CLOCK_REALTIME, &ta);
readCount = 0;
//for( int i = 0; i < 10; i ++){
// emit sendMsg(QString::number(i));
// if( stop ) break;
//}
while(true){
digiMTX.lock();
int ret = digi->ReadData();
digiMTX.unlock();
if( ret == CAEN_FELib_Success){
digi->SaveDataToFile();
}else if(ret == CAEN_FELib_Stop){
digi->ErrorMsg("No more data");
break;
}else{
digi->ErrorMsg("ReadDataLoop()");
}
if( readCount % 1000 == 0 ) {
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()) + " Bytes");
clock_gettime(CLOCK_REALTIME, &tb);
//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;
}
readCount++;
}
}
signals:
void sendMsg(const QString &msg);
private:
bool stop;
Digitizer2Gen * digi;
timespec ta, tb;
unsigned int readCount;
};
//=================================================
class MainWindow : public QMainWindow{ class MainWindow : public QMainWindow{
Q_OBJECT Q_OBJECT
@ -25,11 +90,9 @@ public:
MainWindow(QWidget *parent = nullptr); MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
private slots: private slots:
//void onThreadStarted(){ qDebug() << "kkkkkkkkkkk"; }
//void onThreadFinished(){ qDebug() << "thread done"; }
void bnOpenDigitizers_clicked(); void bnOpenDigitizers_clicked();
void bnCloseDigitizers_clicked(); void bnCloseDigitizers_clicked();
@ -39,6 +102,7 @@ signals :
private: private:
QPushButton * bnProgramSettings; QPushButton * bnProgramSettings;
QPushButton * bnOpenDigitizers; QPushButton * bnOpenDigitizers;
QPushButton * bnCloseDigitizers; QPushButton * bnCloseDigitizers;
@ -49,15 +113,19 @@ private:
DigiSettings * digiSetting; DigiSettings * digiSetting;
QPlainTextEdit * logInfo; QPlainTextEdit * logInfo;
static Digitizer2Gen * digi;
unsigned short nDigi; unsigned short nDigi;
std::vector<unsigned short> digiSerialNum; std::vector<unsigned short> digiSerialNum;
//QThread * StartRunThread; void StartACQ();
void StopACQ();
ReadDataThread * readDataThread;
void LogMsg(QString msg); void LogMsg(QString msg);
}; };