change digi to be pointer of pointer

This commit is contained in:
Ryan Tang 2023-02-02 19:01:10 -05:00
parent 8ffdc2d75c
commit 100c9c9feb
4 changed files with 128 additions and 99 deletions

View File

@ -2,7 +2,7 @@
#include <QLabel>
DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget * parent) : QWidget(parent){
DigiSettings::DigiSettings(Digitizer2Gen ** digi, unsigned short nDigi, QWidget * parent) : QWidget(parent){
qDebug() << "DigiSettings constructor";
@ -39,7 +39,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
scrollArea->setWidgetResizable(true);
scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tabWidget->addTab(scrollArea, "Digi-" + QString::number(digi->GetSerialNumber()));
tabWidget->addTab(scrollArea, "Digi-" + QString::number(digi[iDigi]->GetSerialNumber()));
QGridLayout *tabLayout = new QGridLayout(tab); tab->setLayout(tabLayout);
@ -54,7 +54,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
lab->setAlignment(Qt::AlignRight);
QLineEdit * txt = new QLineEdit(tab);
txt->setReadOnly(true);
txt->setText(QString::fromStdString(digi->ReadValue(info[j][1].c_str())));
txt->setText(QString::fromStdString(digi[iDigi]->ReadValue(info[j][1].c_str())));
infoLayout->addWidget(lab, j%nRow, 2*(j/nRow));
infoLayout->addWidget(txt, j%nRow, 2*(j/nRow) +1);
}
@ -301,7 +301,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
allLayout->setHorizontalSpacing(0);
allLayout->setVerticalSpacing(0);
unsigned short ch = digi->GetNChannels();
unsigned short ch = digi[iDigi]->GetNChannels();
cbCh[iDigi][ch] = new QCheckBox("On/Off", tab); allLayout->addWidget(cbCh[iDigi][ch], 0, 0);
onOffMapper->setMapping(cbCh[iDigi][ch], (iDigi << 12) + ch);
@ -327,7 +327,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
allLayout->setVerticalSpacing(0);
for( int ch = 0; ch < digi->GetNChannels(); ch++){
for( int ch = 0; ch < digi[iDigi]->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);
@ -605,9 +605,9 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
int rowID = 1;
int colID = 0;
for(int i = 0; i < digi->GetNChannels(); i++){
for(int i = 0; i < digi[iDigi]->GetNChannels(); i++){
colID = 0;
for(int j = 0; j < digi->GetNChannels(); j++){
for(int j = 0; j < digi[iDigi]->GetNChannels(); j++){
bn[i][j] = new QPushButton(tab);
bn[i][j]->setFixedSize(QSize(10,10));
@ -624,7 +624,7 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
colID ++;
if( j%4 == 3 && j!= digi->GetNChannels() - 1){
if( j%4 == 3 && j!= digi[iDigi]->GetNChannels() - 1){
QFrame * vSeparator = new QFrame(tab);
vSeparator->setFrameShape(QFrame::VLine);
triggerLayout->addWidget(vSeparator, rowID, colID);
@ -634,10 +634,10 @@ DigiSettings::DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget *
rowID++;
if( i%4 == 3 && i != digi->GetNChannels() - 1){
if( i%4 == 3 && i != digi[iDigi]->GetNChannels() - 1){
QFrame * hSeparator = new QFrame(tab);
hSeparator->setFrameShape(QFrame::HLine);
triggerLayout->addWidget(hSeparator, rowID, 0, 1, digi->GetNChannels() + 15);
triggerLayout->addWidget(hSeparator, rowID, 0, 1, digi[iDigi]->GetNChannels() + 15);
rowID++;
}

View File

@ -25,18 +25,18 @@ class DigiSettings : public QWidget{
Q_OBJECT
public:
DigiSettings(Digitizer2Gen * digi, unsigned short nDigi, QWidget * parent = nullptr);
DigiSettings(Digitizer2Gen ** digi, unsigned short nDigi, QWidget * parent = nullptr);
~DigiSettings();
private slots:
void onReset(){
emit sendLogMsg("Reset Digitizer-" + QString::number(digi->GetSerialNumber()));
digi->Reset();
void onReset(int id){
emit sendLogMsg("Reset Digitizer-" + QString::number(digi[id]->GetSerialNumber()));
digi[id]->Reset();
}
void onDefault(){
emit sendLogMsg("Program Digitizer-" + QString::number(digi->GetSerialNumber()) + " to default PHA.");
digi->ProgramPHA();
void onDefault(int id){
emit sendLogMsg("Program Digitizer-" + QString::number(digi[id]->GetSerialNumber()) + " to default PHA.");
digi[id]->ProgramPHA();
}
void onTriggerClick(int haha){
@ -64,17 +64,17 @@ private slots:
if( (haha & 0xFF) == 64){
if( cbCh[iDig][64]->isChecked() ){
for( int i = 0 ; i < digi->GetNChannels() ; i++){
for( int i = 0 ; i < digi[iDig]->GetNChannels() ; i++){
cbCh[iDig][i]->setChecked(true);
}
}else{
for( int i = 0 ; i < digi->GetNChannels() ; i++){
for( int i = 0 ; i < digi[iDig]->GetNChannels() ; i++){
cbCh[iDig][i]->setChecked(false);
}
}
}else{
unsigned int nOn = 0;
for( int i = 0; i < digi->GetNChannels(); i++){
for( int i = 0; i < digi[iDig]->GetNChannels(); i++){
nOn += (cbCh[iDig][i]->isChecked() ? 1 : 0);
}
@ -93,14 +93,13 @@ signals:
private:
Digitizer2Gen * digi;
Digitizer2Gen ** digi;
unsigned short nDigi;
QPushButton *bn[MaxNumberOfChannel][MaxNumberOfChannel];
bool bnClickStatus[MaxNumberOfChannel][MaxNumberOfChannel];
QCheckBox * cbCh[MaxNumberOfDigitizer][MaxNumberOfChannel + 1]; // index = 64 is for all channels
//QCheckBox * cbCh[MaxNumberOfChannel + 1]; // index = 64 is for all channels
QSpinBox * sbRecordLength[MaxNumberOfChannel + 1];
QSpinBox * sbPreTrigger[MaxNumberOfChannel + 1];

View File

@ -12,7 +12,7 @@
#include <unistd.h>
//------ static memeber
Digitizer2Gen * MainWindow::digi = NULL;
Digitizer2Gen ** MainWindow::digi = NULL;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
@ -55,11 +55,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnOpenScope->setEnabled(false);
bnOpenDigitizers = new QPushButton("Open Digitizers", this);
connect(bnOpenDigitizers, SIGNAL(clicked()), this, SLOT(bnOpenDigitizers_clicked()));
connect(bnOpenDigitizers, SIGNAL(clicked()), this, SLOT(OpenDigitizers()));
bnCloseDigitizers = new QPushButton("Close Digitizers", this);
bnCloseDigitizers->setEnabled(false);
connect(bnCloseDigitizers, SIGNAL(clicked()), this, SLOT(bnCloseDigitizers_clicked()));
connect(bnCloseDigitizers, SIGNAL(clicked()), this, SLOT(CloseDigitizers()));
bnDigiSettings = new QPushButton("Digitizers Settings", this);
bnDigiSettings->setEnabled(false);
@ -181,15 +181,21 @@ MainWindow::~MainWindow(){
if( digiSetting != NULL ) delete digiSetting;
if( digi != NULL ){
digi->CloseDigitizer();
delete digi;
for( int i = 0 ; i < nDigi; i++) {
digi[i]->CloseDigitizer();
delete digi[i];
}
delete [] digi;
}
if( readDataThread != NULL){
readDataThread->Stop();
readDataThread->quit();
readDataThread->wait();
delete readDataThread;
for( int i = 0; i < nDigi; i++){
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
delete readDataThread[i];
}
delete [] readDataThread;
}
}
@ -197,16 +203,19 @@ MainWindow::~MainWindow(){
//^################################################################ ACQ control
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....");
for( int i =0 ; i < nDigi; i ++){
digi[i]->Reset();
digi[i]->ProgramPHA(false);
digi[i]->SetPHADataFormat(1);// only save 1 trace
readDataThread->start();
//TODO :: save file
remove("haha_000.sol"); // remove file
digi[i]->OpenOutFile("haha");// haha_000.sol
digi[i]->StartACQ();
readDataThread[i]->start();
}
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(true);
@ -216,80 +225,101 @@ void MainWindow::StartACQ(){
void MainWindow::StopACQ(){
digi->StopACQ();
for( int i = 0; i < nDigi; i++){
digi[i]->StopACQ();
//readDataThread->Stop();
//readDataThread->Stop();
readDataThread->quit();
readDataThread->wait();
readDataThread[i]->quit();
readDataThread[i]->wait();
digi[i]->CloseOutFile();
digi->CloseOutFile();
}
LogMsg("Stop Run");
bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
}
//^###################################################################### open and close digitizer
void MainWindow::OpenDigitizers(){
//------- decode IPList
nDigi = 1;
void MainWindow::bnOpenDigitizers_clicked(){
LogMsg("Opening digitizer.....");
digi = new Digitizer2Gen();
digi = new Digitizer2Gen*[nDigi];
readDataThread = new ReadDataThread*[nDigi];
digi->OpenDigitizer("dig2://192.168.0.100/");
for( int i = 0; i < nDigi; i++){
if(digi->IsConnected()){
printf("=============================== %d/%d\n" , i, nDigi);
digiSerialNum.push_back(digi->GetSerialNumber());
nDigi ++;
digi[i] = new Digitizer2Gen();
digi[i]->OpenDigitizer("dig2://192.168.0.100/");
LogMsg("Opened digitizer : " + QString::number(digi->GetSerialNumber()));
bnOpenDigitizers->setEnabled(false);
bnOpenDigitizers->setStyleSheet("");
bnCloseDigitizers->setEnabled(true);
bnDigiSettings->setEnabled(true);
bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
if(digi[i]->IsConnected()){
readDataThread = new ReadDataThread(digi, this);
connect(readDataThread, &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
digiSerialNum.push_back(digi[i]->GetSerialNumber());
}else{
LogMsg("Cannot open digitizer");
LogMsg("Opened digitizer : " + QString::number(digi[i]->GetSerialNumber()));
bnOpenDigitizers->setEnabled(false);
bnOpenDigitizers->setStyleSheet("");
bnCloseDigitizers->setEnabled(true);
bnDigiSettings->setEnabled(true);
bnStartACQ->setEnabled(true);
bnStopACQ->setEnabled(false);
//LogMsg("use a dummy.");
//digi->SetDummy();
//digiSerialNum.push_back(0000);
//nDigi ++;
readDataThread[i] = new ReadDataThread(digi[i], this);
connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
delete digi;
}else{
LogMsg("Cannot open digitizer");
//LogMsg("use a dummy.");
//digi->SetDummy();
//digiSerialNum.push_back(0000);
//nDigi ++;
delete digi;
}
}
}
//^###################################################################### open and close digitizer
void MainWindow::bnCloseDigitizers_clicked(){
if( digi != NULL ){
digi->CloseDigitizer();
delete digi;
digi = NULL;
LogMsg("Closed Digitizer : " + QString::number(digiSerialNum[0]));
void MainWindow::CloseDigitizers(){
nDigi = 0;
digiSerialNum.clear();
for( int i = 0; i < nDigi; i++){
if( digi[i] != NULL ){
digi[i]->CloseDigitizer();
delete digi[i];
LogMsg("Closed Digitizer : " + QString::number(digiSerialNum[0]));
bnOpenDigitizers->setEnabled(true);
bnCloseDigitizers->setEnabled(false);
bnDigiSettings->setEnabled(false);
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(false);
nDigi = 0;
digiSerialNum.clear();
if( digiSetting != NULL ) digiSetting->close();
bnOpenDigitizers->setEnabled(true);
bnCloseDigitizers->setEnabled(false);
bnDigiSettings->setEnabled(false);
bnStartACQ->setEnabled(false);
bnStopACQ->setEnabled(false);
if( digiSetting != NULL ) digiSetting->close();
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
delete readDataThread[i];
}
}
delete [] digi;
delete [] readDataThread;
digi = NULL;
readDataThread = NULL;
}
void MainWindow::OpenDigitizersSettings(){
@ -336,8 +366,8 @@ void MainWindow::ProgramSettings(){
helpInfo->appendHtml("<p></p>");
helpInfo->appendHtml("These 2 paths will be used when <font style=\"color : blue;\"> New/Change/Reload Exp </font>");
helpInfo->appendHtml("<p></p>");
helpInfo->appendHtml("<font style=\"color : blue;\"> Digitizers IP Domain </font> is the frist 6 \
digi of the digitizers IP. The program will search for all digitizers under this domain.");
helpInfo->appendHtml("<font style=\"color : blue;\"> Digitizers IP List </font> is the list of IP \
digi of the digitizers IP. e.g. 192.168.0.100,102 for 2 digitizers, or 192.168.0.100-102 for 3 digitizers.");
helpInfo->appendHtml("<p></p>");
helpInfo->appendHtml("<font style=\"color : blue;\"> Database IP </font> or <font style=\"color : blue;\"> Elog IP </font> can be empty. In that case, no database and elog will be used.");
@ -376,10 +406,10 @@ void MainWindow::ProgramSettings(){
//-------- IP Domain
rowID ++;
QLabel *lbIPDomain = new QLabel("Digitizers IP Domain", &dialog);
QLabel *lbIPDomain = new QLabel("Digitizers IP List", &dialog);
lbIPDomain->setAlignment(Qt::AlignRight | Qt::AlignCenter);
layout->addWidget(lbIPDomain, rowID, 0);
lIPDomain = new QLineEdit("192.168.0", &dialog); layout->addWidget(lIPDomain, rowID, 1, 1, 2);
lIPDomain = new QLineEdit("192.168.0.100", &dialog); layout->addWidget(lIPDomain, rowID, 1, 1, 2);
//-------- DataBase IP
rowID ++;
QLabel *lbDatbaseIP = new QLabel("Database IP", &dialog);
@ -459,7 +489,7 @@ bool MainWindow::OpenProgramSettings(){
case 0 : settingFilePath = line; break;
case 1 : analysisPath = line; break;
case 2 : dataPath = line; break;
case 3 : IPDomain = line; break;
case 3 : IPList = line; break;
case 4 : DatabaseIP = line; break;
case 5 : DatabaseName = line; break;
case 6 : ElogIP = line; break;
@ -474,7 +504,7 @@ bool MainWindow::OpenProgramSettings(){
LogMsg("Setting File Path : " + settingFilePath);
LogMsg(" Analysis Path : " + analysisPath);
LogMsg(" Data Path : " + dataPath);
LogMsg(" Digi. IP Domain : " + IPDomain);
LogMsg(" Digi. IP Domain : " + IPList);
LogMsg(" Database IP : " + DatabaseIP);
LogMsg(" Database Name : " + DatabaseName);
LogMsg(" ElogIP : " + ElogIP);
@ -503,7 +533,7 @@ bool MainWindow::OpenProgramSettings(){
void MainWindow::SaveProgramSettings(){
IPDomain = lIPDomain->text();
IPList = lIPDomain->text();
DatabaseIP = lDatbaseIP->text();
DatabaseName = lDatbaseName->text();
ElogIP = lElogIP->text();
@ -519,7 +549,7 @@ void MainWindow::SaveProgramSettings(){
file.write((settingFilePath+"\n").toStdString().c_str());
file.write((analysisPath+"\n").toStdString().c_str());
file.write((dataPath+"\n").toStdString().c_str());
file.write((IPDomain+"\n").toStdString().c_str());
file.write((IPList+"\n").toStdString().c_str());
file.write((DatabaseIP+"\n").toStdString().c_str());
file.write((DatabaseName+"\n").toStdString().c_str());
file.write((ElogIP+"\n").toStdString().c_str());

View File

@ -94,8 +94,8 @@ public:
private slots:
void bnOpenDigitizers_clicked();
void bnCloseDigitizers_clicked();
void OpenDigitizers();
void CloseDigitizers();
void OpenDigitizersSettings();
@ -133,14 +133,14 @@ private:
QPlainTextEdit * logInfo;
static Digitizer2Gen * digi;
static Digitizer2Gen ** digi;
unsigned short nDigi;
std::vector<unsigned short> digiSerialNum;
void StartACQ();
void StopACQ();
ReadDataThread * readDataThread;
ReadDataThread ** readDataThread;
void LogMsg(QString msg);
bool logMsgHTMLMode = true;
@ -158,7 +158,7 @@ private:
QString settingFilePath;
QString analysisPath;
QString dataPath;
QString IPDomain;
QString IPList;
QString DatabaseIP;
QString DatabaseName;
QString ElogIP;