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
# ----------------------------------------------------------------------------
SOLARIS_DAQ
*.sol
*~
*.autosave

View File

@ -106,6 +106,7 @@ class Digitizer2Gen {
void OpenOutFile(std::string fileName);
void CloseOutFile();
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"}
};
QVBoxLayout * mainLayout = new QVBoxLayout(this);
this->setLayout(mainLayout);
QTabWidget * tabWidget = new QTabWidget(this);
mainLayout->addWidget(tabWidget);
QVBoxLayout * mainLayout = new QVBoxLayout(this); this->setLayout(mainLayout);
QTabWidget * tabWidget = new QTabWidget(this); mainLayout->addWidget(tabWidget);
//============ 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);
QScrollArea * scrollArea = new QScrollArea;
scrollArea->setWidget(tab);
QScrollArea * scrollArea = new QScrollArea(this); scrollArea->setWidget(tab);
scrollArea->setWidgetResizable(true);
scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tabWidget->addTab(scrollArea, "Digi-" + QString::number(digi->GetSerialNumber()));
QGridLayout *tabLayout = new QGridLayout(tab);
tab->setLayout(tabLayout);
QGridLayout *tabLayout = new QGridLayout(tab); tab->setLayout(tabLayout);
{//-------- Group of Digitizer Info
QGroupBox * infoBox = new QGroupBox("Board Info", tab);
QGridLayout * infoLayout = new QGridLayout(infoBox);
infoBox->setLayout(infoLayout);
tabLayout->addWidget(infoBox, 0, 0);
const unsigned short nRow = 4;
@ -70,23 +63,23 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
{//------- Group Board status
QGroupBox * statusBox = new QGroupBox("Board Status", tab);
QGridLayout * statusLayout = new QGridLayout(statusBox);
statusBox->setLayout(statusLayout);
tabLayout->addWidget(statusBox, 1, 0);
tabLayout->addWidget(statusBox, 0, 1);
}
{//------- Group digitizer settings
QGroupBox * digiBox = new QGroupBox("Board Settings", tab);
QGridLayout * boardLayout = new QGridLayout(digiBox);
digiBox->setLayout(boardLayout);
tabLayout->addWidget(digiBox, 2, 0);
tabLayout->addWidget(digiBox, 1, 0);
int rowId = 0;
//-------------------------------------
QPushButton * bnResetBd = new QPushButton("Reset Board", tab);
boardLayout->addWidget(bnResetBd, rowId, 0, 1, 2);
connect(bnResetBd, &QPushButton::clicked, this, &DigiSettings::onReset);
QPushButton * bnDefaultSetting = new QPushButton("Set Default Settings", tab);
boardLayout->addWidget(bnDefaultSetting, rowId, 2, 1, 2);
connect(bnDefaultSetting, &QPushButton::clicked, this, &DigiSettings::onDefault);
//-------------------------------------
rowId ++;
@ -288,18 +281,65 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
}
{//------- Group channel settings
QGroupBox * chBox = new QGroupBox("Channel Settings", tab);
QGridLayout * chLayout = new QGridLayout(chBox);
chBox->setLayout(chLayout);
tabLayout->addWidget(chBox, 0, 1, 10, 1);
//chLayout->setVerticalSpacing(0);
QGroupBox * chBox = new QGroupBox("Channel Settings", tab); tabLayout->addWidget(chBox, 1, 1, 1, 1);
QGridLayout * chLayout = new QGridLayout(chBox); //chBox->setLayout(chLayout);
QSignalMapper * onOffMapper = new QSignalMapper(tab);
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++){
//------ set Labels
@ -372,7 +412,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
//------ set all channel
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;
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
QGroupBox * triggerBox = new QGroupBox("Trigger Map", tab);
QGridLayout * triggerLayout = new QGridLayout(triggerBox);
triggerBox->setLayout(triggerLayout);
tabLayout->addWidget(triggerBox, 3, 0);
//triggerBox->setLayout(triggerLayout);
tabLayout->addWidget(triggerBox, 2, 0);
triggerLayout->setHorizontalSpacing(0);
triggerLayout->setVerticalSpacing(0);
@ -581,7 +621,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
}
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()));
colID ++;
@ -617,4 +657,10 @@ DigiSettings::~DigiSettings(){
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"
#define MaxNumberOfDigitizer 10
class DigiSettings : public QWidget{
Q_OBJECT
@ -27,10 +29,23 @@ public:
~DigiSettings();
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){
unsigned short ch = haha/100;
unsigned short ch2 = haha - ch*100;
unsigned short iDig = haha >> 12;
unsigned short ch = (haha >> 8 ) & 0xF;
unsigned short ch2 = haha & 0xFF;
qDebug() << "Digi-" << iDig << ", Ch-" << ch << ", " << ch2;
if(bnClickStatus[ch][ch2]){
bn[ch][ch2]->setStyleSheet("");
@ -41,24 +56,41 @@ private slots:
}
}
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[64]->isChecked() ){
if( cbCh[iDig][64]->isChecked() ){
for( int i = 0 ; i < digi->GetNChannels() ; i++){
cbCh[i]->setChecked(true);
cbCh[iDig][i]->setChecked(true);
}
}else{
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:
void sendLogMsg(const QString &msg);
private:
Digitizer2Gen * digi;
@ -67,10 +99,11 @@ private:
QPushButton *bn[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 * sbPreTrigger[MaxNumberOfChannel + 1];
QComboBox * cmbWaveRes[MaxNumberOfChannel + 1];
QComboBox * cmbAnaProbe0[MaxNumberOfChannel + 1];
@ -87,7 +120,7 @@ private:
QComboBox * cmbChVetoSrc[MaxNumberOfChannel + 1];
QSpinBox * sbChADCVetoWidth[MaxNumberOfChannel + 1];
};

View File

@ -3,10 +3,15 @@
#include <QLabel>
#include <QGridLayout>
#include <unistd.h>
//------ static memeber
Digitizer2Gen * MainWindow::digi = NULL;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
setWindowTitle("SOLARIS DAQ");
setGeometry(500, 500, 1000, 500);
setGeometry(500, 100, 1000, 500);
QIcon icon("SOLARIS_favicon.png");
setWindowIcon(icon);
@ -16,16 +21,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
QWidget * mainLayoutWidget = new QWidget(this);
setCentralWidget(mainLayoutWidget);
QVBoxLayout * layout1 = new QVBoxLayout(mainLayoutWidget);
mainLayoutWidget->setLayout(layout1);
QVBoxLayout * layoutMain = new QVBoxLayout(mainLayoutWidget);
mainLayoutWidget->setLayout(layoutMain);
{
QGridLayout *layout = new QGridLayout();
layout1->addLayout(layout);
layout1->addStretch();
layout1->setStretchFactor(layout, 8);
{//====================== General
QGroupBox * box1 = new QGroupBox("General", mainLayoutWidget);
layoutMain->addWidget(box1);
QGridLayout * layout1 = new QGridLayout(box1);
bnProgramSettings = new QPushButton("Program Settings", this);
bnProgramSettings->setEnabled(false);
bnOpenDigitizers = new QPushButton("Open Digitizers", this);
connect(bnOpenDigitizers, SIGNAL(clicked()), this, SLOT(bnOpenDigitizers_clicked()));
@ -38,42 +45,55 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnDigiSettings->setEnabled(false);
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);
layout->addWidget(bnOpenDigitizers, 0, 1);
layout->addWidget(bnCloseDigitizers, 0, 2);
layout->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);
layout1->addWidget(bnProgramSettings, 0, 0);
layout1->addWidget(bnOpenDigitizers, 0, 1);
layout1->addWidget(bnCloseDigitizers, 0, 2);
layout1->addWidget(bnDigiSettings, 1, 1);
}
logInfo = new QPlainTextEdit(this);
logInfo->isReadOnly();
logInfo->setGeometry(100, 200, 500, 100);
layout1->addWidget(logInfo);
layout1->setStretchFactor(logInfo, 1);
{//====================== ACD control
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);
//connect(StartRunThread, &QThread::started, this, &MainWindow::onThreadStarted);
//connect(StartRunThread, &QThread::finished, this, &MainWindow::onThreadFinished);
layoutMain->addStretch();
{//===================== 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.");
bnOpenDigitizers_clicked();
OpenDigitizersSettings();
//bnOpenDigitizers_clicked();
//OpenDigitizersSettings();
}
@ -92,9 +112,49 @@ MainWindow::~MainWindow(){
delete digi;
}
//StartRunThread->quit();
//StartRunThread->wait();
//delete StartRunThread;
readDataThread->Stop();
readDataThread->quit();
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);
bnDigiSettings->setEnabled(true);
bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
readDataThread = new ReadDataThread(digi, this);
connect(readDataThread, &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
}else{
LogMsg("Cannot open digitizer");
@ -126,6 +190,7 @@ void MainWindow::bnOpenDigitizers_clicked(){
nDigi ++;
}
}
void MainWindow::bnCloseDigitizers_clicked(){
@ -143,6 +208,9 @@ void MainWindow::bnCloseDigitizers_clicked(){
bnDigiSettings->setEnabled(false);
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(false);
if( digiSetting != NULL ) digiSetting->close();
}
}
@ -151,6 +219,7 @@ void MainWindow::OpenDigitizersSettings(){
if( digiSetting == NULL){
digiSetting = new DigiSettings(digi, nDigi);
connect(digiSetting, &DigiSettings::sendLogMsg, this, &MainWindow::LogMsg);
digiSetting->show();
}else{
digiSetting->show();
@ -163,6 +232,6 @@ void MainWindow::LogMsg(QString msg){
logInfo->appendPlainText(countStr);
QScrollBar *v = logInfo->verticalScrollBar();
v->setValue(v->maximum());
qDebug() << msg;
//qDebug() << msg;
logInfo->repaint();
}

View File

@ -10,13 +10,78 @@
#include <QDateTime>
#include <QScrollBar>
#include <QPushButton>
#include <QMutex>
#include <vector>
#include <time.h> // time in nano-sec
#include "ClassDigitizer2Gen.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{
Q_OBJECT
@ -25,11 +90,9 @@ public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
//void onThreadStarted(){ qDebug() << "kkkkkkkkkkk"; }
//void onThreadFinished(){ qDebug() << "thread done"; }
void bnOpenDigitizers_clicked();
void bnCloseDigitizers_clicked();
@ -39,6 +102,7 @@ signals :
private:
QPushButton * bnProgramSettings;
QPushButton * bnOpenDigitizers;
QPushButton * bnCloseDigitizers;
@ -49,15 +113,19 @@ private:
DigiSettings * digiSetting;
QPlainTextEdit * logInfo;
static Digitizer2Gen * digi;
unsigned short nDigi;
std::vector<unsigned short> digiSerialNum;
//QThread * StartRunThread;
void StartACQ();
void StopACQ();
ReadDataThread * readDataThread;
void LogMsg(QString msg);
};