finished solaris pannel- basic setting

This commit is contained in:
Ryan Tang 2023-03-20 15:52:04 -04:00
parent a024d001ff
commit 259bc9d244
5 changed files with 198 additions and 45 deletions

View File

@ -1,9 +1,16 @@
#include "SOLARISpanel.h" #include "SOLARISpanel.h"
#include <QFile> #include <QFile>
#include <QLabel>
#include <QSet> #include <QSet>
#include <QList> #include <QList>
#define NCOL 20 // number of column
std::vector<Reg> SettingItems = {PHA::CH::TriggerThreshold, PHA::CH::DC_Offset};
const std::vector<QString> arrayLabel = {"e", "xf", "xn"};
SOLARISpanel::SOLARISpanel(Digitizer2Gen **digi, unsigned short nDigi, SOLARISpanel::SOLARISpanel(Digitizer2Gen **digi, unsigned short nDigi,
std::vector<std::vector<int>> mapping, std::vector<std::vector<int>> mapping,
QStringList detType, QStringList detType,
@ -11,7 +18,7 @@ SOLARISpanel::SOLARISpanel(Digitizer2Gen **digi, unsigned short nDigi,
QWidget *parent) : QWidget(parent){ QWidget *parent) : QWidget(parent){
setWindowTitle("SOLARIS Settings"); setWindowTitle("SOLARIS Settings");
setGeometry(0, 0, 1850, 1000); setGeometry(0, 0, 1850, 750);
printf("%s\n", __func__); printf("%s\n", __func__);
@ -21,97 +28,218 @@ SOLARISpanel::SOLARISpanel(Digitizer2Gen **digi, unsigned short nDigi,
this->detType = detType; this->detType = detType;
this->detMaxID = detMaxID; this->detMaxID = detMaxID;
nDigiMapping = mapping.size();
for( int i = 0; i < nDigiMapping; i++) nChMapping.push_back(mapping[i].size());
//Check number of detector type; Array 0-199, Recoil 200-299, other 300- //Check number of detector type; Array 0-199, Recoil 200-299, other 300-
int nDetType = detType.size(); int nDetType = detType.size();
int nDet[nDetType]; int nDet[nDetType];
for( int k = 0 ; k < nDetType; k++) nDet[k] = 0; for( int k = 0 ; k < nDetType; k++) nDet[k] = 0;
QList<int> detIDList; //consolidated QList<QList<int>> detIDListTemp; //to be consolidated
for( int i = 0; i < (int) mapping.size() ; i++){ printf("################################# \n");
for( int j = 0; j < (int) mapping[i].size(); j++ ){ for( int i = 0; i < nDigiMapping ; i++){
for( int j = 0; j < nChMapping[i]; j++ ){
printf("%3d,", mapping[i][j]); printf("%3d,", mapping[i][j]);
if( mapping[i][j] >= 0 ) detIDList << mapping[i][j]; QList<int> haha ;
haha << i << mapping[i][j];
if( mapping[i][j] >= 0 ) detIDListTemp << haha;
for( int k = 0 ; k < nDetType; k++){ for( int k = 0 ; k < nDetType; k++){
int lowID = (k == 0 ? 0 : detMaxID[k-1]); int lowID = (k == 0 ? 0 : detMaxID[k-1]);
if( lowID <= mapping[i][j] && mapping[i][j] < detMaxID[k] ) nDet[k] ++ ; if( lowID <= mapping[i][j] && mapping[i][j] < detMaxID[k] ) nDet[k] ++ ;
} }
if( j % 16 == 0 ) printf("\n"); if( j % 16 == 15 ) printf("\n");
} }
printf("------------------ \n"); printf("------------------ \n");
} }
//----- consolidate detIDList; //----- consolidate detIDList;
QSet<int> mySet(detIDList.begin(), detIDList.end()); QList<QList<int>> detIDList;
detIDList = mySet.values(); detIDList << detIDListTemp[0];
bool repeated = false;
for( int i = 0; i < detIDListTemp.size(); i++ ){
repeated = false;
for( int j = 0; j < detIDList.size() ; j++){
if( detIDList[j] == detIDListTemp[i] ) {
repeated = true;
break;
}
}
if( !repeated ) detIDList << detIDListTemp [i];
}
for( int i = 0 ; i < detIDList.size(); i++) printf("%d\n", detIDList[i]); //------------ create Widgets
leDisplay = new QLineEdit***[(int) SettingItems.size()];
sbSetting = new RSpinBox***[(int) SettingItems.size()];
for( int k = 0; k < (int) SettingItems.size() ; k ++){
leDisplay[k] = new QLineEdit**[nDigiMapping];
sbSetting[k] = new RSpinBox**[nDigiMapping];
for( int i = 0; i < nDigiMapping; i++){
sbSetting[k][i] = new RSpinBox*[(int) mapping[i].size()];
leDisplay[k][i] = new QLineEdit*[(int) mapping[i].size()];
}
}
//---------- Set Panel
QVBoxLayout * mainLayout = new QVBoxLayout(this); this->setLayout(mainLayout); QVBoxLayout * mainLayout = new QVBoxLayout(this); this->setLayout(mainLayout);
QTabWidget * tabWidget = new QTabWidget(this); mainLayout->addWidget(tabWidget); QTabWidget * tabWidget = new QTabWidget(this); mainLayout->addWidget(tabWidget);
for( int detTypeID = 0; detTypeID < nDetType; detTypeID ++ ){ for( int detTypeID = 0; detTypeID < nDetType; detTypeID ++ ){
QWidget * tab = new QWidget(this); QTabWidget * tab2 = new QTabWidget(tabWidget);
tabWidget->addTab(tab, detType[detTypeID]); tabWidget->addTab(tab2, detType[detTypeID]);
QGridLayout * layout = new QGridLayout(tab); for( int SettingID = 0; SettingID < (int) SettingItems.size(); SettingID ++){
layout->setAlignment(Qt::AlignLeft|Qt::AlignTop);
layout->setSpacing(0);
//QLineEdit * leNDet = new QLineEdit(QString::number(nDet[detTypeID]), tab); QWidget * tab = new QWidget(tab2);
//layout->addWidget(leNDet, 0, 0); tab2->addTab(tab, QString::fromStdString(SettingItems[SettingID]));
//ranege of detID QGridLayout * layout = new QGridLayout(tab);
int lowID = (detTypeID == 0 ? 0 : detMaxID[detTypeID-1]); layout->setAlignment(Qt::AlignLeft|Qt::AlignTop);
layout->setSpacing(0);
QCheckBox * chkAll = new QCheckBox("Set for all", tab);
layout->addWidget(chkAll, 0, 0);
//range of detID
int lowID = (detTypeID == 0 ? 0 : detMaxID[detTypeID-1]);
for(int i = 0; i < detIDList.size(); i++){
if( detIDList[i][1] >= detMaxID[detTypeID] || lowID > detIDList[i][1] ) continue;
CreateSpinBoxGroup(SettingID, detIDList[i], layout, i/NCOL + 1, i%NCOL);
}
for(int i = 0; i < detIDList.size(); i++){
if( detIDList[i] < lowID || detIDList[i] > detMaxID[detTypeID]) continue;
CreateSpinBoxGroup(PHA::CH::TriggerThreshold, i, layout, i/20, i%20);
} }
} }
} }
SOLARISpanel::~SOLARISpanel(){ SOLARISpanel::~SOLARISpanel(){
} }
void SOLARISpanel::CreateSpinBoxGroup(const Reg para, int detID, QGridLayout * &layout, int row, int col){ void SOLARISpanel::CreateSpinBoxGroup(int SettingID, QList<int> detID, QGridLayout * &layout, int row, int col){
//find all chID = (iDigi << 8 + ch) for detID //find all chID = (iDigi << 8 + ch) for detID
std::vector<int> chID; std::vector<int> chID;
for( int i = 0; i < (int) mapping.size() ; i++){ for( int i = 0; i < nDigiMapping ; i++){
for( int j = 0; j < (int) mapping[i].size(); j++ ){ for( int j = 0; j < nChMapping[i]; j++ ){
if( mapping[i][j] == detID ) chID.push_back((i << 8) + j); if( mapping[i][j] == detID[1] ) chID.push_back((i << 8) + j);
} }
} }
QGroupBox * groupbox = new QGroupBox("det-" + QString::number(detID), this); QGroupBox * groupbox = new QGroupBox("Det-" + QString::number(detID[1]), this);
groupbox->setFixedWidth(80); groupbox->setFixedWidth(100);
QVBoxLayout * layout0 = new QVBoxLayout(groupbox); QGridLayout * layout0 = new QGridLayout(groupbox);
for( int i = 0; i < (int) chID.size(); i ++){ for( int i = 0; i < (int) chID.size(); i ++){
QLineEdit * leTrigRate = new QLineEdit(this);
leTrigRate->setFixedWidth(50);
layout0->addWidget(leTrigRate);
RSpinBox * sbThre = new RSpinBox(this); QLabel * lb = new QLabel(arrayLabel[i], this);
sbThre->setToolTip( "Digi-,Ch-" + QString::number(chID[i])); layout0->addWidget(lb, 2*i, 0, 2, 1);
sbThre->setToolTipDuration(-1);
sbThre->setFixedWidth(50); int digiID = (chID[i] >> 8);
layout0->addWidget(sbThre); int ch = (chID[i] & 0xFF);
leDisplay[SettingID][digiID][ch] = new QLineEdit(this);
leDisplay[SettingID][digiID][ch]->setFixedWidth(50);
layout0->addWidget(leDisplay[SettingID][digiID][ch], 2*i, 1);
sbSetting[SettingID][digiID][ch] = new RSpinBox(this);
if( digiID < nDigi ) sbSetting[SettingID][digiID][ch]->setToolTip( "Digi-" + QString::number(digi[digiID]->GetSerialNumber()) + ",Ch-" + QString::number(ch));
sbSetting[SettingID][digiID][ch]->setToolTipDuration(-1);
sbSetting[SettingID][digiID][ch]->setFixedWidth(50);
layout0->addWidget(sbSetting[SettingID][digiID][ch], 2*i+1, 1);
RSpinBox * spb = sbSetting[SettingID][digiID][ch];
const Reg para = SettingItems[SettingID];
connect(spb, &RSpinBox::valueChanged, this, [=](){
if( !enableSignalSlot ) return;
spb->setStyleSheet("color:blue;");
});
connect(spb, &RSpinBox::returnPressed, this, [=](){
if( !enableSignalSlot ) return;
//printf("%s %d %d \n", para.GetPara().c_str(), index, spb->value());
if( spb->decimals() == 0 && spb->singleStep() != 1) {
double step = spb->singleStep();
double value = spb->value();
spb->setValue( (std::round(value/step) * step) );
}
QString msg;
msg = QString::fromStdString(para.GetPara()) + "|DIG:"+ QString::number(digi[digiID]->GetSerialNumber());
if( para.GetType() == TYPE::CH ) msg += ",CH:" + QString::number(ch);
msg += " = " + QString::number(spb->value());
if( digi[digiID]->WriteValue(para, std::to_string(spb->value()), ch)){
SendLogMsg(msg + "|OK.");
spb->setStyleSheet("");
}else{
SendLogMsg(msg + "|Fail.");
spb->setStyleSheet("color:red;");
}
});
} }
if( detID[0] >= nDigi || detID[1] >= digi[detID[0]]->GetNChannels() ) groupbox->setEnabled(false);
layout->addWidget(groupbox, row, col); layout->addWidget(groupbox, row, col);
} }
void SOLARISpanel::CreateTab(const Reg para){
void SOLARISpanel::UpdatePanel(){
} enableSignalSlot = false;
for( int SettingID = 0; SettingID < (int) SettingItems.size() ; SettingID ++){
for( int DigiID = 0; DigiID < (int) mapping.size(); DigiID ++){
if( DigiID >= nDigi ) continue;;
for( int chID = 0; chID < (int) mapping[DigiID].size(); chID++){
if( chID >= digi[DigiID]->GetNChannels() ) continue;
if( mapping[DigiID][chID] < 0 ) continue;
std::string haha = digi[DigiID]->GetSettingValue(SettingItems[SettingID], chID);
sbSetting[SettingID][DigiID][chID]->setValue( atof(haha.c_str()));
if( SettingItems[SettingID].GetPara() == PHA::CH::TriggerThreshold.GetPara() ){
std::string haha = digi[DigiID]->GetSettingValue(PHA::CH::SelfTrgRate, chID);
leDisplay[SettingID][DigiID][chID]->setText(QString::fromStdString(haha));
}else{
leDisplay[SettingID][DigiID][chID]->setText(QString::fromStdString(haha));
}
///printf("====== %d %d %d |%s|\n", SettingID, DigiID, chID, haha.c_str());
}
}
}
enableSignalSlot = true;
}
void SOLARISpanel::UpdateThreshold(){
for( int SettingID = 0; SettingID < (int) SettingItems.size() ; SettingID ++){
if( SettingItems[SettingID].GetPara() != PHA::CH::TriggerThreshold.GetPara() ) continue;
for( int DigiID = 0; DigiID < (int) mapping.size(); DigiID ++){
if( DigiID >= nDigi ) continue;;
for( int chID = 0; chID < (int) mapping[DigiID].size(); chID++){
if( chID >= digi[DigiID]->GetNChannels() ) continue;
if( mapping[DigiID][chID] < 0 ) continue;
std::string haha = digi[DigiID]->GetSettingValue(PHA::CH::SelfTrgRate, chID);
leDisplay[SettingID][DigiID][chID]->setText(QString::fromStdString(haha));
///printf("====== %d %d %d |%s|\n", SettingID, DigiID, chID, haha.c_str());
}
}
}
}

View File

@ -36,19 +36,32 @@ public:
private slots: private slots:
void CreateSpinBoxGroup(const Reg para, int detID, QGridLayout * &layout, int row, int col);
void CreateTab(const Reg para); public slots:
void UpdatePanel();
void UpdateThreshold();
signals: signals:
void SendLogMsg(const QString str);
private: private:
void CreateSpinBoxGroup(int SettingID, QList<int> detID, QGridLayout * &layout, int row, int col);
Digitizer2Gen ** digi; Digitizer2Gen ** digi;
unsigned short nDigi; unsigned short nDigi;
std::vector<std::vector<int>> mapping; std::vector<std::vector<int>> mapping;
QStringList detType; QStringList detType;
std::vector<int> detMaxID; std::vector<int> detMaxID;
int nDigiMapping;
std::vector<int> nChMapping;
QLineEdit **** leDisplay; // [SettingID][DigiID][ChID]
RSpinBox **** sbSetting;
bool enableSignalSlot;
}; };
#endif #endif

View File

@ -1604,6 +1604,8 @@ void DigiSettingsPanel::LoadSettings(){
fileDialog.setNameFilter("Data file (*.dat);;Text file (*.txt);;All file (*.*)"); fileDialog.setNameFilter("Data file (*.dat);;Text file (*.txt);;All file (*.*)");
fileDialog.exec(); fileDialog.exec();
if( fileDialog.selectedFiles().size() == 0 ) return; // when no file selected.
QString fileName = fileDialog.selectedFiles().at(0); QString fileName = fileDialog.selectedFiles().at(0);
leSettingFile[ID]->setText(fileName); leSettingFile[ID]->setText(fileName);
@ -1611,11 +1613,11 @@ void DigiSettingsPanel::LoadSettings(){
if( digi[ID]->LoadSettingsFromFile(fileName.toStdString().c_str()) ){ if( digi[ID]->LoadSettingsFromFile(fileName.toStdString().c_str()) ){
SendLogMsg("Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber())); SendLogMsg("Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber()));
ShowSettingsToPanel();
}else{ }else{
SendLogMsg("Fail to Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber())); SendLogMsg("Fail to Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber()));
} }
ShowSettingsToPanel();
} }
void DigiSettingsPanel::SetDefaultPHASettigns(){ void DigiSettingsPanel::SetDefaultPHASettigns(){

View File

@ -109,6 +109,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnSOLSettings->setEnabled(false); bnSOLSettings->setEnabled(false);
connect(bnSOLSettings, SIGNAL(clicked()), this, SLOT(OpenSOLARISpanel())); connect(bnSOLSettings, SIGNAL(clicked()), this, SLOT(OpenSOLARISpanel()));
QPushButton * bnEventBuilder = new QPushButton("Event Builder", this);
bnEventBuilder->setEnabled(false);
layout1->addWidget(bnProgramSettings, 0, 0); layout1->addWidget(bnProgramSettings, 0, 0);
layout1->addWidget(bnNewExp, 0, 1); layout1->addWidget(bnNewExp, 0, 1);
layout1->addWidget(lExpName, 0, 2); layout1->addWidget(lExpName, 0, 2);
@ -121,6 +124,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
layout1->addWidget(bnDigiSettings, 2, 1); layout1->addWidget(bnDigiSettings, 2, 1);
layout1->addWidget(bnSOLSettings, 2, 2, 1, 2); layout1->addWidget(bnSOLSettings, 2, 2, 1, 2);
layout1->addWidget(bnEventBuilder, 3, 0);
layout1->setColumnStretch(0, 2); layout1->setColumnStretch(0, 2);
layout1->setColumnStretch(1, 2); layout1->setColumnStretch(1, 2);
layout1->setColumnStretch(2, 1); layout1->setColumnStretch(2, 1);
@ -746,6 +751,7 @@ void MainWindow::OpenDigitizersSettings(){
//^###################################################################### Open SOLARIS setting panel //^###################################################################### Open SOLARIS setting panel
void MainWindow::OpenSOLARISpanel(){ void MainWindow::OpenSOLARISpanel(){
solarisSetting->show(); solarisSetting->show();
solarisSetting->UpdatePanel();
} }
bool MainWindow::CheckSOLARISpanelOK(){ bool MainWindow::CheckSOLARISpanelOK(){
@ -840,6 +846,7 @@ bool MainWindow::CheckSOLARISpanelOK(){
//@============= Create SOLAIRS panel //@============= Create SOLAIRS panel
solarisSetting = new SOLARISpanel(digi, nDigi, mapping, detType, detMaxID); solarisSetting = new SOLARISpanel(digi, nDigi, mapping, detType, detMaxID);
connect(solarisSetting, &SOLARISpanel::SendLogMsg, this, &MainWindow::LogMsg);
return true; return true;
} }
@ -998,6 +1005,9 @@ void MainWindow::UpdateScalar(){
influx->WriteData(DatabaseName.toStdString()); influx->WriteData(DatabaseName.toStdString());
influx->ClearDataPointsBuffer(); influx->ClearDataPointsBuffer();
} }
if( solarisSetting && solarisSetting->isVisible() ) solarisSetting->UpdateThreshold();
} }
//^###################################################################### Program Settings //^###################################################################### Program Settings

View File

@ -273,7 +273,7 @@ Scope::Scope(Digitizer2Gen **digi, unsigned int nDigi, ReadDataThread ** readDat
plotView->setRenderHints(QPainter::Antialiasing); plotView->setRenderHints(QPainter::Antialiasing);
layout->addWidget(plotView, rowID, 0, 1, 6); layout->addWidget(plotView, rowID, 0, 1, 6);
//------------- Ketbinding //------------- Key binding
rowID ++; rowID ++;
QLabel * lbhints = new QLabel("Type 'r' to restore view.", this); QLabel * lbhints = new QLabel("Type 'r' to restore view.", this);
layout->addWidget(lbhints, rowID, 0, 1, 3); layout->addWidget(lbhints, rowID, 0, 1, 3);