2023-01-25 14:59:48 -05:00
# include "mainwindow.h"
# include <QLabel>
# include <QGridLayout>
2023-01-31 18:59:12 -05:00
# include <QDialog>
2023-02-01 16:38:02 -05:00
# include <QFileDialog>
2023-01-31 18:59:12 -05:00
# include <QStorageInfo>
2023-02-01 16:38:02 -05:00
# include <QDir>
# include <QFile>
2023-02-01 18:58:51 -05:00
# include <QProcess>
2023-02-03 17:44:36 -05:00
# include <QRandomGenerator>
2023-02-06 15:58:21 -05:00
# include <QVariant>
2023-04-18 10:38:40 -04:00
# include <QCoreApplication>
2023-02-03 16:58:27 -05:00
# include <QChartView>
# include <QValueAxis>
2023-02-06 15:58:21 -05:00
# include <QStandardItemModel>
2023-02-09 18:27:20 -05:00
# include <QApplication>
2023-02-13 17:56:15 -05:00
# include <QDateTime>
2023-02-17 19:30:31 -05:00
# include <QProcess>
# include <QScreen>
# include <X11/Xlib.h>
# include <X11/Xatom.h>
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
# include <unistd.h>
//------ static memeber
2023-03-23 16:36:47 -04:00
Digitizer2Gen * * MainWindow : : digi = nullptr ;
2023-01-30 18:40:24 -05:00
2023-01-25 14:59:48 -05:00
MainWindow : : MainWindow ( QWidget * parent ) : QMainWindow ( parent ) {
2023-03-01 18:27:17 -05:00
setWindowTitle ( " FSU SOLARIS DAQ " ) ;
2023-01-30 18:40:24 -05:00
setGeometry ( 500 , 100 , 1000 , 500 ) ;
2023-01-25 14:59:48 -05:00
QIcon icon ( " SOLARIS_favicon.png " ) ;
setWindowIcon ( icon ) ;
2024-07-01 17:19:23 -04:00
programPath = QDir : : currentPath ( ) ;
2023-01-25 14:59:48 -05:00
nDigi = 0 ;
2023-03-27 18:34:22 -04:00
nDigiConnected = 0 ;
2023-03-23 16:36:47 -04:00
digiSetting = nullptr ;
influx = nullptr ;
readDataThread = nullptr ;
2023-02-17 19:30:31 -05:00
runTimer = new QTimer ( ) ;
2023-03-15 15:48:33 -04:00
needManualComment = true ;
2024-04-08 20:17:26 -04:00
ACQStopButtonPressed = false ;
2023-12-07 18:10:17 -05:00
isACQRunning = false ;
2023-02-13 15:22:24 -05:00
{
2023-09-19 12:57:42 -04:00
scalarOutputInflux = false ;
2023-02-13 15:22:24 -05:00
scalar = new QMainWindow ( this ) ;
scalar - > setWindowTitle ( " Scalar " ) ;
scalar - > setGeometry ( 0 , 0 , 1000 , 800 ) ;
2023-02-13 17:56:15 -05:00
QScrollArea * scopeScroll = new QScrollArea ( scalar ) ;
scalar - > setCentralWidget ( scopeScroll ) ;
scopeScroll - > setWidgetResizable ( true ) ;
scopeScroll - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Expanding ) ;
2023-02-13 15:22:24 -05:00
QWidget * layoutWidget = new QWidget ( scalar ) ;
2023-02-13 17:56:15 -05:00
scopeScroll - > setWidget ( layoutWidget ) ;
2023-02-13 15:22:24 -05:00
scalarLayout = new QGridLayout ( layoutWidget ) ;
scalarLayout - > setSpacing ( 0 ) ;
2023-03-10 17:28:02 -05:00
scalarLayout - > setAlignment ( Qt : : AlignTop ) ;
2023-02-13 15:22:24 -05:00
2023-03-23 16:36:47 -04:00
leTrigger = nullptr ;
leAccept = nullptr ;
2024-04-08 20:41:57 -04:00
lbFileSize = nullptr ;
2023-02-13 17:07:26 -05:00
2023-04-25 17:23:50 -04:00
scalarThread = new TimingThread ( ) ;
connect ( scalarThread , & TimingThread : : TimeUp , this , & MainWindow : : UpdateScalar ) ;
2023-03-15 19:10:17 -04:00
2023-02-13 15:22:24 -05:00
}
2023-03-23 16:36:47 -04:00
solarisSetting = nullptr ;
scope = nullptr ;
digiSetting = nullptr ;
2023-01-25 14:59:48 -05:00
QWidget * mainLayoutWidget = new QWidget ( this ) ;
setCentralWidget ( mainLayoutWidget ) ;
2023-01-30 18:40:24 -05:00
QVBoxLayout * layoutMain = new QVBoxLayout ( mainLayoutWidget ) ;
mainLayoutWidget - > setLayout ( layoutMain ) ;
{ //====================== General
QGroupBox * box1 = new QGroupBox ( " General " , mainLayoutWidget ) ;
layoutMain - > addWidget ( box1 ) ;
QGridLayout * layout1 = new QGridLayout ( box1 ) ;
2023-01-25 14:59:48 -05:00
bnProgramSettings = new QPushButton ( " Program Settings " , this ) ;
2023-02-17 19:30:31 -05:00
connect ( bnProgramSettings , & QPushButton : : clicked , this , & MainWindow : : ProgramSettingsPanel ) ;
2023-01-25 14:59:48 -05:00
2023-02-02 17:27:39 -05:00
bnNewExp = new QPushButton ( " New/Change/Reload Exp " , this ) ;
2023-02-17 19:30:31 -05:00
connect ( bnNewExp , & QPushButton : : clicked , this , & MainWindow : : SetupNewExpPanel ) ;
2023-02-01 18:58:51 -05:00
QLabel * lExpName = new QLabel ( " Exp Name " , this ) ;
lExpName - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
leExpName = new QLineEdit ( " <Exp Name> " , this ) ;
leExpName - > setAlignment ( Qt : : AlignHCenter ) ;
leExpName - > setReadOnly ( true ) ;
2023-02-03 16:58:27 -05:00
bnOpenScope = new QPushButton ( " Open scope " , this ) ;
2023-02-01 18:58:51 -05:00
bnOpenScope - > setEnabled ( false ) ;
2023-02-09 18:40:47 -05:00
connect ( bnOpenScope , & QPushButton : : clicked , this , & MainWindow : : OpenScope ) ;
2023-02-01 18:58:51 -05:00
2023-01-25 14:59:48 -05:00
bnOpenDigitizers = new QPushButton ( " Open Digitizers " , this ) ;
2023-09-15 17:31:07 -04:00
connect ( bnOpenDigitizers , & QPushButton : : clicked , this , & MainWindow : : OpenDigitizers ) ;
2023-01-25 14:59:48 -05:00
bnCloseDigitizers = new QPushButton ( " Close Digitizers " , this ) ;
bnCloseDigitizers - > setEnabled ( false ) ;
2023-09-15 17:31:07 -04:00
connect ( bnCloseDigitizers , & QPushButton : : clicked , this , & MainWindow : : CloseDigitizers ) ;
2023-01-25 14:59:48 -05:00
bnDigiSettings = new QPushButton ( " Digitizers Settings " , this ) ;
bnDigiSettings - > setEnabled ( false ) ;
2023-09-15 17:31:07 -04:00
connect ( bnDigiSettings , & QPushButton : : clicked , this , & MainWindow : : OpenDigitizersSettings ) ;
2023-01-25 14:59:48 -05:00
2023-02-03 16:58:27 -05:00
bnSOLSettings = new QPushButton ( " SOLARIS Settings " , this ) ;
2023-01-31 18:59:12 -05:00
bnSOLSettings - > setEnabled ( false ) ;
2023-09-15 17:31:07 -04:00
connect ( bnSOLSettings , & QPushButton : : clicked , this , & MainWindow : : OpenSOLARISpanel ) ;
2024-04-08 13:57:31 -04:00
bnSyncHelper = new QPushButton ( " Sync Helper (Not Set) " , this ) ;
2023-09-15 17:31:07 -04:00
bnSyncHelper - > setEnabled ( false ) ;
connect ( bnSyncHelper , & QPushButton : : clicked , this , & MainWindow : : OpenSyncHelper ) ;
2023-01-31 18:59:12 -05:00
2023-01-30 18:40:24 -05:00
layout1 - > addWidget ( bnProgramSettings , 0 , 0 ) ;
2023-02-01 16:38:02 -05:00
layout1 - > addWidget ( bnNewExp , 0 , 1 ) ;
layout1 - > addWidget ( lExpName , 0 , 2 ) ;
2023-02-01 18:58:51 -05:00
layout1 - > addWidget ( leExpName , 0 , 3 ) ;
2023-02-01 16:38:02 -05:00
2023-09-15 17:31:07 -04:00
layout1 - > addWidget ( bnSyncHelper , 1 , 0 ) ;
2023-02-01 16:38:02 -05:00
layout1 - > addWidget ( bnOpenDigitizers , 1 , 1 ) ;
2023-02-01 18:58:51 -05:00
layout1 - > addWidget ( bnCloseDigitizers , 1 , 2 , 1 , 2 ) ;
2023-02-17 19:30:31 -05:00
layout1 - > addWidget ( bnOpenScope , 2 , 0 ) ;
2023-02-01 16:38:02 -05:00
layout1 - > addWidget ( bnDigiSettings , 2 , 1 ) ;
2023-02-01 18:58:51 -05:00
layout1 - > addWidget ( bnSOLSettings , 2 , 2 , 1 , 2 ) ;
2023-01-31 18:59:12 -05:00
2023-02-01 18:58:51 -05:00
layout1 - > setColumnStretch ( 0 , 2 ) ;
layout1 - > setColumnStretch ( 1 , 2 ) ;
layout1 - > setColumnStretch ( 2 , 1 ) ;
layout1 - > setColumnStretch ( 3 , 1 ) ;
2023-01-30 18:40:24 -05:00
}
{ //====================== ACD control
QGroupBox * box2 = new QGroupBox ( " ACQ control " , mainLayoutWidget ) ;
layoutMain - > addWidget ( box2 ) ;
QGridLayout * layout2 = new QGridLayout ( box2 ) ;
2023-02-02 17:27:39 -05:00
QLabel * lbRawDataPath = new QLabel ( " Raw Data Path : " , this ) ;
lbRawDataPath - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
leRawDataPath = new QLineEdit ( this ) ;
leRawDataPath - > setReadOnly ( true ) ;
leRawDataPath - > setStyleSheet ( " background-color: #F3F3F3; " ) ;
2024-10-15 10:59:26 -04:00
2023-02-13 15:22:24 -05:00
bnOpenScalar = new QPushButton ( " Open Scalar " , this ) ;
bnOpenScalar - > setEnabled ( false ) ;
connect ( bnOpenScalar , & QPushButton : : clicked , this , & MainWindow : : OpenScaler ) ;
2023-02-13 17:56:15 -05:00
QLabel * lbRunID = new QLabel ( " Run ID : " , this ) ;
lbRunID - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
leRunID = new QLineEdit ( this ) ;
leRunID - > setAlignment ( Qt : : AlignHCenter ) ;
leRunID - > setReadOnly ( true ) ;
2023-02-14 17:39:49 -05:00
leRunID - > setStyleSheet ( " background-color: #F3F3F3; " ) ;
2023-02-13 17:56:15 -05:00
chkSaveRun = new QCheckBox ( " Save Run " , this ) ;
2023-09-15 17:31:07 -04:00
chkSaveRun - > setChecked ( false ) ;
2023-02-14 17:39:49 -05:00
chkSaveRun - > setEnabled ( false ) ;
2023-03-15 15:48:33 -04:00
connect ( chkSaveRun , & QCheckBox : : clicked , this , [ = ] ( ) { cbAutoRun - > setEnabled ( chkSaveRun - > isChecked ( ) ) ; } ) ;
2023-02-13 17:56:15 -05:00
cbAutoRun = new QComboBox ( this ) ;
2023-03-15 15:48:33 -04:00
cbAutoRun - > addItem ( " Single infinte " , 0 ) ;
2024-04-08 20:17:26 -04:00
cbAutoRun - > addItem ( " Single 1 min " , 1 ) ;
2023-02-17 19:30:31 -05:00
cbAutoRun - > addItem ( " Single 30 mins " , 30 ) ;
cbAutoRun - > addItem ( " Single 60 mins " , 60 ) ;
cbAutoRun - > addItem ( " Single 2 hrs " , 120 ) ;
cbAutoRun - > addItem ( " Single 3 hrs " , 180 ) ;
cbAutoRun - > addItem ( " Single 5 hrs " , 300 ) ;
2024-04-08 20:17:26 -04:00
cbAutoRun - > addItem ( " Every 1 mins " , - 1 ) ;
2023-02-17 19:30:31 -05:00
cbAutoRun - > addItem ( " Every 30 mins " , - 30 ) ;
cbAutoRun - > addItem ( " Every 60 mins " , - 60 ) ;
cbAutoRun - > addItem ( " Every 2 hrs " , - 120 ) ;
cbAutoRun - > addItem ( " Every 3 hrs " , - 180 ) ;
cbAutoRun - > addItem ( " Every 5 hrs " , - 300 ) ;
2023-02-13 17:56:15 -05:00
cbAutoRun - > setEnabled ( false ) ;
2023-09-15 17:31:07 -04:00
cbDataFormat = new QComboBox ( this ) ;
2023-11-06 13:44:55 -05:00
cbDataFormat - > addItem ( " Everything " , DataFormat : : ALL ) ;
cbDataFormat - > addItem ( " 1 trace " , DataFormat : : OneTrace ) ;
cbDataFormat - > addItem ( " No trace " , DataFormat : : NoTrace ) ;
cbDataFormat - > addItem ( " Minimum " , DataFormat : : Minimum ) ;
cbDataFormat - > addItem ( " Min + fineTimestamp " , DataFormat : : MiniWithFineTime ) ;
2023-09-15 17:31:07 -04:00
cbDataFormat - > setCurrentIndex ( 3 ) ;
2023-04-12 13:52:42 -04:00
cbDataFormat - > setEnabled ( false ) ;
2023-01-25 14:59:48 -05:00
bnStartACQ = new QPushButton ( " Start ACQ " , this ) ;
bnStartACQ - > setEnabled ( false ) ;
2023-03-15 15:48:33 -04:00
//connect(bnStartACQ, &QPushButton::clicked, this, &MainWindow::StartACQ);
connect ( bnStartACQ , & QPushButton : : clicked , this , & MainWindow : : AutoRun ) ;
2023-01-30 18:40:24 -05:00
2023-01-25 14:59:48 -05:00
bnStopACQ = new QPushButton ( " Stop ACQ " , this ) ;
bnStopACQ - > setEnabled ( false ) ;
2023-03-15 15:48:33 -04:00
connect ( bnStopACQ , & QPushButton : : clicked , this , [ = ] ( ) {
2024-04-08 20:17:26 -04:00
LogMsg ( " @@@@@@@@@ Stop ACQ Button Pressed. " ) ;
ACQStopButtonPressed = true ;
2023-03-15 15:48:33 -04:00
needManualComment = true ;
runTimer - > stop ( ) ;
StopACQ ( ) ;
2023-12-07 18:10:17 -05:00
if ( ! isACQRunning ) {
2023-09-19 19:19:07 -04:00
bnStartACQ - > setEnabled ( true ) ;
bnStopACQ - > setEnabled ( false ) ;
bnComment - > setEnabled ( false ) ;
bnOpenScope - > setEnabled ( true ) ;
chkSaveRun - > setEnabled ( true ) ;
2023-09-21 17:24:13 -04:00
cbDataFormat - > setEnabled ( true ) ;
2023-09-19 19:19:07 -04:00
if ( chkSaveRun - > isChecked ( ) ) cbAutoRun - > setEnabled ( true ) ;
if ( digiSetting ) digiSetting - > EnableControl ( ) ;
}
2023-03-15 15:48:33 -04:00
} ) ;
2023-01-31 18:59:12 -05:00
QLabel * lbRunComment = new QLabel ( " Run Comment : " , this ) ;
lbRunComment - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2023-02-14 18:44:10 -05:00
leRunComment = new QLineEdit ( this ) ;
2023-02-14 17:39:49 -05:00
leRunComment - > setReadOnly ( true ) ;
leRunComment - > setStyleSheet ( " background-color: #F3F3F3; " ) ;
2023-03-27 15:48:41 -04:00
bnComment = new QPushButton ( " Append Comment " , this ) ;
connect ( bnComment , & QPushButton : : clicked , this , & MainWindow : : AppendComment ) ;
bnComment - > setEnabled ( false ) ;
2023-01-31 18:59:12 -05:00
2023-02-02 17:27:39 -05:00
layout2 - > addWidget ( lbRawDataPath , 0 , 0 ) ;
2023-04-12 13:52:42 -04:00
layout2 - > addWidget ( leRawDataPath , 0 , 1 , 1 , 5 ) ;
layout2 - > addWidget ( bnOpenScalar , 0 , 6 ) ;
2023-02-02 17:27:39 -05:00
2023-04-12 13:52:42 -04:00
layout2 - > addWidget ( lbRunID , 1 , 0 ) ;
layout2 - > addWidget ( leRunID , 1 , 1 ) ;
layout2 - > addWidget ( chkSaveRun , 1 , 2 ) ;
layout2 - > addWidget ( cbAutoRun , 1 , 3 ) ;
layout2 - > addWidget ( cbDataFormat , 1 , 4 ) ;
layout2 - > addWidget ( bnStartACQ , 1 , 5 ) ;
layout2 - > addWidget ( bnStopACQ , 1 , 6 ) ;
2023-02-01 18:58:51 -05:00
2023-02-02 17:27:39 -05:00
layout2 - > addWidget ( lbRunComment , 2 , 0 ) ;
2023-04-12 13:52:42 -04:00
layout2 - > addWidget ( leRunComment , 2 , 1 , 1 , 5 ) ;
layout2 - > addWidget ( bnComment , 2 , 6 ) ;
2023-01-31 18:59:12 -05:00
2023-04-12 13:52:42 -04:00
layout2 - > setColumnStretch ( 0 , 1 ) ;
2023-02-01 18:58:51 -05:00
layout2 - > setColumnStretch ( 1 , 1 ) ;
2023-02-13 17:56:15 -05:00
layout2 - > setColumnStretch ( 2 , 1 ) ;
layout2 - > setColumnStretch ( 3 , 1 ) ;
2023-04-12 13:52:42 -04:00
layout2 - > setColumnStretch ( 4 , 1 ) ;
2023-02-13 17:56:15 -05:00
layout2 - > setColumnStretch ( 5 , 3 ) ;
2023-04-12 13:52:42 -04:00
layout2 - > setColumnStretch ( 6 , 3 ) ;
2023-01-25 14:59:48 -05:00
}
2023-01-30 18:40:24 -05:00
layoutMain - > addStretch ( ) ;
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
{ //===================== Log Msg
QGroupBox * box3 = new QGroupBox ( " Log Message " , mainLayoutWidget ) ;
layoutMain - > addWidget ( box3 ) ;
layoutMain - > setStretchFactor ( box3 , 1 ) ;
2023-01-25 14:59:48 -05:00
2023-02-01 16:38:02 -05:00
QVBoxLayout * layout3 = new QVBoxLayout ( box3 ) ;
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
logInfo = new QPlainTextEdit ( this ) ;
logInfo - > isReadOnly ( ) ;
2023-02-01 16:38:02 -05:00
QFont font ;
font . setFamily ( " Courier New " ) ;
logInfo - > setFont ( font ) ;
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
layout3 - > addWidget ( logInfo ) ;
2023-01-25 14:59:48 -05:00
2023-01-30 18:40:24 -05:00
}
2023-02-01 16:38:02 -05:00
LogMsg ( " <font style= \" color: blue; \" ><b>Welcome to SOLARIS DAQ.</b></font> " ) ;
2024-06-28 18:30:35 -04:00
if ( LoadProgramSettings ( ) ) LoadExpNameSh ( ) ;
2023-01-25 14:59:48 -05:00
}
MainWindow : : ~ MainWindow ( ) {
2023-02-09 18:27:20 -05:00
printf ( " - %s \n " , __func__ ) ;
2023-01-25 17:16:14 -05:00
2023-03-27 15:48:41 -04:00
LogMsg ( " Closing SOLARIS DAQ. " ) ;
2024-07-01 17:19:23 -04:00
if ( ! expDataPath . isEmpty ( ) ) {
QDir dir ( expDataPath + " /Logs/ " ) ;
if ( ! dir . exists ( ) ) dir . mkpath ( " . " ) ;
2023-03-27 15:58:20 -04:00
2024-07-01 17:19:23 -04:00
QFile file ( expDataPath + " /Logs/Log_ " + QDateTime : : currentDateTime ( ) . toString ( " yyyyMMdd_hhmmss " ) + " .dat " ) ;
printf ( " -------- Save log msg to %s \n " , file . fileName ( ) . toStdString ( ) . c_str ( ) ) ;
if ( file . open ( QIODevice : : WriteOnly | QIODevice : : Text ) ) {
QTextStream stream ( & file ) ;
stream < < logInfo - > toPlainText ( ) ;
file . close ( ) ;
}
2023-03-27 15:48:41 -04:00
}
2023-03-22 18:16:26 -04:00
printf ( " -------- remove %s \n " , DAQLockFile ) ;
remove ( DAQLockFile ) ;
printf ( " -------- delete Solaris panel \n " ) ;
2023-03-23 16:36:47 -04:00
if ( solarisSetting ) {
2023-03-22 18:16:26 -04:00
delete solarisSetting ;
solarisSetting = nullptr ;
}
printf ( " -------- delete scope \n " ) ;
2023-03-23 16:36:47 -04:00
if ( scope ) {
2023-03-22 18:16:26 -04:00
delete scope ;
scope = nullptr ;
}
printf ( " -------- delete digiSetting \n " ) ;
2023-03-23 16:36:47 -04:00
if ( digiSetting ) {
2023-03-22 18:16:26 -04:00
delete digiSetting ;
digiSetting = nullptr ;
}
2024-07-01 17:19:23 -04:00
printf ( " -------- delete readData Thread \n " ) ;
2023-02-17 19:30:31 -05:00
if ( digi ) {
for ( int i = 0 ; i < nDigi ; i + + ) {
2023-02-22 20:07:39 -05:00
if ( digi [ i ] - > IsDummy ( ) ) continue ;
2023-03-10 14:42:29 -05:00
//printf("=== %d %p\n", i, readDataThread[i]);
2023-02-17 19:30:31 -05:00
if ( readDataThread [ i ] - > isRunning ( ) ) StopACQ ( ) ;
}
2023-02-14 17:39:49 -05:00
}
2023-03-22 18:16:26 -04:00
CloseDigitizers ( ) ; // SOlaris panel, digiSetting, scope are also deleted.
2023-02-14 17:39:49 -05:00
2024-07-01 17:19:23 -04:00
printf ( " -------- delete scalar Thread \n " ) ;
2023-09-19 12:57:42 -04:00
if ( scalarThread - > isRunning ( ) ) {
scalarThread - > Stop ( ) ;
scalarThread - > quit ( ) ;
scalarThread - > wait ( ) ;
}
2023-04-18 10:38:40 -04:00
CleanUpScalar ( ) ;
2023-02-13 17:07:26 -05:00
delete scalarThread ;
2023-02-09 18:27:20 -05:00
2023-02-22 20:07:39 -05:00
printf ( " -------- delete influx \n " ) ;
2023-03-15 19:10:17 -04:00
if ( influx ! = NULL ) {
influx - > ClearDataPointsBuffer ( ) ;
influx - > AddDataPoint ( " ProgramStart value=0 " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
delete influx ;
}
2023-02-13 18:40:02 -05:00
2023-03-22 18:16:26 -04:00
printf ( " --- end of %s \n " , __func__ ) ;
2023-03-17 17:08:56 -04:00
2023-01-30 18:40:24 -05:00
}
2023-04-18 10:38:40 -04:00
//*################################################################
//*################################################################ ACQ control
2023-04-03 18:20:36 -04:00
int MainWindow : : StartACQ ( ) {
2023-01-30 18:40:24 -05:00
2024-04-08 20:17:26 -04:00
ACQStopButtonPressed = false ;
2023-02-14 17:39:49 -05:00
if ( chkSaveRun - > isChecked ( ) ) {
2023-02-22 12:41:48 -05:00
runID + + ;
leRunID - > setText ( QString : : number ( runID ) ) ;
2023-02-14 17:39:49 -05:00
runIDStr = QString : : number ( runID ) . rightJustified ( 3 , ' 0 ' ) ;
LogMsg ( " =========================== Start <b><font style= \" color : red; \" >Run- " + runIDStr + " </font></b> " ) ;
2023-03-15 15:48:33 -04:00
if ( needManualComment ) {
2023-02-17 19:30:31 -05:00
QDialog * dOpen = new QDialog ( this ) ;
dOpen - > setWindowTitle ( " Start Run Comment " ) ;
dOpen - > setWindowFlags ( Qt : : Dialog | Qt : : WindowTitleHint | Qt : : CustomizeWindowHint ) ;
dOpen - > setMinimumWidth ( 600 ) ;
connect ( dOpen , & QDialog : : finished , dOpen , & QDialog : : deleteLater ) ;
QGridLayout * vlayout = new QGridLayout ( dOpen ) ;
QLabel * label = new QLabel ( " Enter Run comment for <font style= \" color : red; \" >Run- " + runIDStr + " </font> : " , dOpen ) ;
QLineEdit * lineEdit = new QLineEdit ( dOpen ) ;
QPushButton * button1 = new QPushButton ( " OK " , dOpen ) ;
QPushButton * button2 = new QPushButton ( " Cancel " , dOpen ) ;
vlayout - > addWidget ( label , 0 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( lineEdit , 1 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( button1 , 2 , 0 ) ;
vlayout - > addWidget ( button2 , 2 , 1 ) ;
connect ( button1 , & QPushButton : : clicked , dOpen , & QDialog : : accept ) ;
connect ( button2 , & QPushButton : : clicked , dOpen , & QDialog : : reject ) ;
int result = dOpen - > exec ( ) ;
if ( result = = QDialog : : Accepted ) {
startComment = lineEdit - > text ( ) ;
2023-03-30 13:09:11 -04:00
if ( startComment = = " " ) startComment = " No commet was typed. " ;
startComment = " Start Comment: " + startComment ;
2023-02-17 19:30:31 -05:00
} else {
LogMsg ( " Start Run aborted. " ) ;
2023-04-03 18:20:36 -04:00
runID - - ;
leRunID - > setText ( QString : : number ( runID ) ) ;
return 0 ;
2023-02-17 19:30:31 -05:00
}
2023-03-30 13:09:11 -04:00
if ( cbAutoRun - > currentData ( ) . toInt ( ) ! = 0 ) {
startComment = startComment + " . AutoRun for " + cbAutoRun - > currentText ( ) ;
}
leRunComment - > setText ( startComment ) ;
2023-03-15 15:48:33 -04:00
} else {
//==========TODO auto run comment
startComment = " AutoRun for " + cbAutoRun - > currentText ( ) ;
leRunComment - > setText ( startComment ) ;
}
2023-03-15 19:10:17 -04:00
2023-02-14 17:39:49 -05:00
} else {
LogMsg ( " =========================== Start no-save Run " ) ;
}
2023-02-17 19:30:31 -05:00
//============================= start digitizer
2023-09-15 17:53:08 -04:00
for ( int i = nDigi - 1 ; i > = 0 ; i - - ) {
2023-02-02 19:26:47 -05:00
if ( digi [ i ] - > IsDummy ( ) ) continue ;
2023-03-27 15:48:41 -04:00
2023-03-15 19:10:17 -04:00
for ( int ch = 0 ; ch < ( int ) digi [ i ] - > GetNChannels ( ) ; ch + + ) oldTimeStamp [ i ] [ ch ] = 0 ;
2023-09-15 17:31:07 -04:00
//digi[i]->SetPHADataFormat(1);// only save 1 trace
int dataFormatID = cbDataFormat - > currentData ( ) . toInt ( ) ;
2023-09-22 15:58:28 -04:00
digi [ i ] - > SetDataFormat ( dataFormatID ) ;
2023-01-30 18:40:24 -05:00
2024-04-08 13:42:13 -04:00
if ( dataFormatID = = DataFormat : : ALL | | dataFormatID = = DataFormat : : OneTrace ) {
digi [ i ] - > WriteValue ( PHA : : CH : : WaveSaving , " Always " , - 1 ) ;
} else {
digi [ i ] - > WriteValue ( PHA : : CH : : WaveSaving , " OnRequest " , - 1 ) ;
}
2023-09-21 17:24:13 -04:00
//Additional settings, it is better user to control
//if( cbDataFormat->currentIndex() < 2 ) {
// digi[i]->WriteValue("/ch/0..63/par/WaveAnalogProbe0", "ADCInput");
// digi[i]->WriteValue(PHA::CH::WaveSaving, "True", -1);
//}
2023-03-27 15:48:41 -04:00
2023-02-14 17:39:49 -05:00
if ( chkSaveRun - > isChecked ( ) ) {
2023-03-27 15:48:41 -04:00
2024-10-15 10:59:26 -04:00
QString runFolder = rawDataPath + " / " ;
if ( isSaveSubFolder ) {
runFolder + = " run " + runIDStr + " / " ;
CreateFolder ( runFolder , " for " + runIDStr ) ;
}
//Save setting to raw data with run ID
QString fileSetting = runFolder + expName + " _ " + runIDStr + " XSetting_ " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " .dat " ;
2023-03-27 18:21:51 -04:00
// name should be [ExpName]_[runID]_[digiID]_[digiSerialNumber]_[acculmulate_count].sol
2024-10-15 10:59:26 -04:00
QString outFileName = runFolder + expName + " _ " + runIDStr + " _ " + QString : : number ( i ) . rightJustified ( 2 , ' 0 ' ) + " _ " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ;
digi [ i ] - > SaveSettingsToFile ( fileSetting . toStdString ( ) . c_str ( ) ) ;
2023-02-14 17:39:49 -05:00
qDebug ( ) < < outFileName ;
digi [ i ] - > OpenOutFile ( outFileName . toStdString ( ) ) ; // overwrite
}
2023-02-02 19:01:10 -05:00
digi [ i ] - > StartACQ ( ) ;
2023-02-03 14:54:55 -05:00
//TODO ========================== Sync start.
2023-02-14 17:39:49 -05:00
readDataThread [ i ] - > SetSaveData ( chkSaveRun - > isChecked ( ) ) ;
2023-02-02 19:01:10 -05:00
readDataThread [ i ] - > start ( ) ;
2023-12-07 18:10:17 -05:00
}
if ( chkSaveRun - > isChecked ( ) ) {
QString startTimeStr = QDateTime : : currentDateTime ( ) . toString ( " yyyy.MM.dd hh:mm:ss " ) ;
LogMsg ( " <font style= \" color : blue; \" > All Digitizers started. </font> " ) ;
// ============ elog
QString elogMsg = " =============== Run- " + runIDStr + " <br /> "
+ startTimeStr + " <br /> "
+ " comment : " + startComment + " <br /> " +
+ " ---------------------------------------------- " ;
WriteElog ( elogMsg , " Run- " + runIDStr , " Run " , runID ) ;
// ============ update expName.sh
WriteExpNameSh ( ) ;
2023-03-15 19:10:17 -04:00
2023-12-07 18:10:17 -05:00
WriteRunTimeStampDat ( true , startTimeStr ) ;
2023-03-15 19:10:17 -04:00
}
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
if ( chkSaveRun - > isChecked ( ) ) {
2023-03-29 15:24:53 -04:00
influx - > AddDataPoint ( " RunID,start=1 value= " + std : : to_string ( runID ) + " ,expName= \" " + expName . toStdString ( ) + " \" ,comment= \" " + startComment . replace ( ' ' , ' _ ' ) . toStdString ( ) + " \" " ) ;
2023-03-15 19:10:17 -04:00
}
influx - > AddDataPoint ( " StartStop value=1 " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
2023-02-02 19:01:10 -05:00
}
2023-01-30 18:40:24 -05:00
2023-09-19 19:19:07 -04:00
if ( ! scalar - > isVisible ( ) ) {
scalar - > show ( ) ;
if ( ! scalarThread - > isRunning ( ) ) scalarThread - > start ( ) ;
}
2023-12-07 18:10:17 -05:00
isACQRunning = True ;
2023-02-22 12:48:54 -05:00
lbScalarACQStatus - > setText ( " <font style= \" color: green; \" ><b>ACQ On</b></font> " ) ;
2023-09-19 12:57:42 -04:00
//scalarThread->start();
scalarOutputInflux = true ;
2023-02-13 17:07:26 -05:00
2023-04-03 18:20:36 -04:00
return 1 ;
2023-01-30 18:40:24 -05:00
}
void MainWindow : : StopACQ ( ) {
2023-12-07 18:10:17 -05:00
if ( ! isACQRunning ) return ;
2023-02-14 18:44:10 -05:00
if ( chkSaveRun - > isChecked ( ) ) {
//============ stop comment
2023-03-15 15:48:33 -04:00
if ( needManualComment ) {
QDialog * dOpen = new QDialog ( this ) ;
dOpen - > setWindowTitle ( " Stop Run Comment " ) ;
dOpen - > setWindowFlags ( Qt : : Dialog | Qt : : WindowTitleHint | Qt : : CustomizeWindowHint ) ;
dOpen - > setMinimumWidth ( 600 ) ;
connect ( dOpen , & QDialog : : finished , dOpen , & QDialog : : deleteLater ) ;
QGridLayout * vlayout = new QGridLayout ( dOpen ) ;
QLabel * label = new QLabel ( " Enter Run comment for ending <font style= \" color : red; \" >Run- " + runIDStr + " </font> : " , dOpen ) ;
QLineEdit * lineEdit = new QLineEdit ( dOpen ) ;
QPushButton * button1 = new QPushButton ( " OK " , dOpen ) ;
QPushButton * button2 = new QPushButton ( " Cancel " , dOpen ) ;
vlayout - > addWidget ( label , 0 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( lineEdit , 1 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( button1 , 2 , 0 ) ;
vlayout - > addWidget ( button2 , 2 , 1 ) ;
connect ( button1 , & QPushButton : : clicked , dOpen , & QDialog : : accept ) ;
connect ( button2 , & QPushButton : : clicked , dOpen , & QDialog : : reject ) ;
int result = dOpen - > exec ( ) ;
if ( result = = QDialog : : Accepted ) {
stopComment = lineEdit - > text ( ) ;
2023-03-30 13:09:11 -04:00
if ( stopComment = = " " ) stopComment = " No commet was typed. " ;
stopComment = " Stop Comment: " + stopComment ;
leRunComment - > setText ( stopComment ) ;
2023-03-15 15:48:33 -04:00
} else {
LogMsg ( " Cancel Run aborted. " ) ;
return ;
}
2023-02-14 18:44:10 -05:00
} else {
2023-03-15 15:48:33 -04:00
stopComment = " End of AutoRun for " + cbAutoRun - > currentText ( ) ;
leRunComment - > setText ( stopComment ) ;
2023-02-14 18:44:10 -05:00
}
}
2023-02-17 19:30:31 -05:00
//=============== Stop digitizer
2023-09-26 13:15:10 -04:00
for ( int i = nDigi - 1 ; i > = 0 ; i - - ) {
2023-02-02 19:26:47 -05:00
if ( digi [ i ] - > IsDummy ( ) ) continue ;
2024-04-08 20:41:57 -04:00
digiMTX [ i ] . lock ( ) ;
2023-02-02 19:01:10 -05:00
digi [ i ] - > StopACQ ( ) ;
2024-04-08 20:41:57 -04:00
// readDataThread[i]->SuppressFileSizeMsg();
2024-04-08 13:42:13 -04:00
digi [ i ] - > WriteValue ( PHA : : CH : : WaveSaving , " OnRequest " , - 1 ) ;
2024-04-08 20:41:57 -04:00
digiMTX [ i ] . unlock ( ) ;
2023-02-02 19:01:10 -05:00
}
2023-12-07 18:10:17 -05:00
isACQRunning = false ;
lbScalarACQStatus - > setText ( " <font style= \" color: red; \" ><b>ACQ Off</b></font> " ) ;
2023-01-30 18:40:24 -05:00
2023-12-07 18:10:17 -05:00
QString stopTimeStr = QDateTime : : currentDateTime ( ) . toString ( " yyyy.MM.dd hh:mm:ss " ) ;
2023-09-19 12:57:42 -04:00
scalarOutputInflux = false ;
2023-03-15 19:10:17 -04:00
if ( chkSaveRun - > isChecked ( ) ) {
LogMsg ( " =========================== <b><font style= \" color : red; \" >Run- " + runIDStr + " </font></b> stopped. " ) ;
2023-12-07 18:10:17 -05:00
LogMsg ( " <font style= \" color : blue; \" >Please wait for collecting all remaining data.</font> " ) ;
WriteRunTimeStampDat ( false , stopTimeStr ) ;
2023-03-15 19:10:17 -04:00
2023-03-15 15:48:33 -04:00
// ============= elog
2023-12-07 18:10:17 -05:00
QString msg = stopTimeStr + " <br /> " ;
2023-02-22 12:41:48 -05:00
for ( int i = 0 ; i < nDigi ; i + + ) {
if ( digi [ i ] - > IsDummy ( ) ) continue ;
msg + = " FileSize ( " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " ): " + QString : : number ( digi [ i ] - > GetTotalFilesSize ( ) / 1024. / 1024. ) + " MB <br /> " ;
}
msg + = " comment : " + stopComment + " <br /> "
+ " ====================== " ;
AppendElog ( msg , chromeWindowID ) ;
2023-03-15 19:10:17 -04:00
} else {
LogMsg ( " =========================== no-Save Run stopped. " ) ;
2023-02-13 17:56:15 -05:00
}
2023-02-22 12:48:54 -05:00
2023-12-07 18:10:17 -05:00
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
if ( chkSaveRun - > isChecked ( ) ) {
influx - > AddDataPoint ( " RunID,start=0 value= " + std : : to_string ( runID ) + " ,expName= \" " + expName . toStdString ( ) + " \" ,comment= \" " + stopComment . replace ( ' ' , ' _ ' ) . toStdString ( ) + " \" " ) ;
}
influx - > AddDataPoint ( " StartStop value=0 " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
}
2023-02-22 12:48:54 -05:00
2024-04-08 20:41:57 -04:00
if ( chkSaveRun - > isChecked ( ) ) LogMsg ( " Collecting remaining data from the digitizers... " ) ;
2023-12-07 17:06:33 -05:00
for ( int i = nDigi - 1 ; i > = 0 ; i - - ) {
if ( readDataThread [ i ] - > isRunning ( ) ) {
2024-04-08 20:41:57 -04:00
if ( ! chkSaveRun - > isChecked ( ) ) readDataThread [ i ] - > Stop ( ) ; // if it is a save run, don't force stop the readDataThread, wait for it.
2023-12-07 17:06:33 -05:00
readDataThread [ i ] - > quit ( ) ;
readDataThread [ i ] - > wait ( ) ;
}
if ( chkSaveRun - > isChecked ( ) ) {
digi [ i ] - > CloseOutFile ( ) ;
LogMsg ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " is done collecting all data. " ) ;
}
}
2023-12-07 18:10:17 -05:00
if ( chkSaveRun - > isChecked ( ) ) {
2024-07-01 17:19:23 -04:00
LogMsg ( " Run " + programPath + " /scripts/endRunScript.sh " ) ;
QProcess : : startDetached ( programPath + " /scripts/endRunScript.sh " ) ;
2023-12-07 18:10:17 -05:00
}
LogMsg ( " <b><font style= \" color : green; \" >SOLARIS DAQ is ready for next run.</font></b> " ) ;
2023-01-25 14:59:48 -05:00
}
2023-02-17 19:30:31 -05:00
void MainWindow : : AutoRun ( ) {
2023-03-15 15:48:33 -04:00
if ( chkSaveRun - > isChecked ( ) = = false ) {
2023-04-03 18:20:36 -04:00
if ( StartACQ ( ) ) {
bnStartACQ - > setEnabled ( false ) ;
bnStopACQ - > setEnabled ( true ) ;
bnComment - > setEnabled ( false ) ;
bnOpenScope - > setEnabled ( false ) ;
chkSaveRun - > setEnabled ( false ) ;
cbAutoRun - > setEnabled ( false ) ;
2023-09-21 17:24:13 -04:00
cbDataFormat - > setEnabled ( false ) ;
2023-04-03 18:20:36 -04:00
if ( digiSetting ) digiSetting - > EnableControl ( ) ;
}
2023-03-15 15:48:33 -04:00
return ;
}
2023-02-17 19:30:31 -05:00
2023-03-15 15:48:33 -04:00
needManualComment = true ;
2023-04-03 18:20:36 -04:00
int isRun = 0 ;
2023-03-15 15:48:33 -04:00
///=========== infinite single run
if ( cbAutoRun - > currentData ( ) . toInt ( ) = = 0 ) {
2023-04-03 18:20:36 -04:00
isRun = StartACQ ( ) ;
2023-03-30 13:09:11 -04:00
disconnect ( runTimer , & QTimer : : timeout , nullptr , nullptr ) ;
2023-02-17 19:30:31 -05:00
} else {
2023-04-03 18:20:36 -04:00
isRun = StartACQ ( ) ;
2023-03-15 15:48:33 -04:00
connect ( runTimer , & QTimer : : timeout , this , [ = ] ( ) {
2023-03-30 13:09:11 -04:00
StopACQ ( ) ;
if ( cbAutoRun - > currentData ( ) . toInt ( ) > 0 ) {
bnStartACQ - > setEnabled ( true ) ;
bnStopACQ - > setEnabled ( false ) ;
bnComment - > setEnabled ( false ) ;
2023-04-04 11:46:02 -04:00
bnOpenScope - > setEnabled ( true ) ;
chkSaveRun - > setEnabled ( true ) ;
cbAutoRun - > setEnabled ( true ) ;
2023-09-15 17:31:07 -04:00
cbDataFormat - > setEnabled ( true ) ;
2023-04-04 11:46:02 -04:00
if ( digiSetting ) digiSetting - > EnableControl ( ) ;
2023-03-30 13:09:11 -04:00
} else {
LogMsg ( " Wait for 10 sec for next Run.... " ) ;
elapsedTimer . invalidate ( ) ;
elapsedTimer . start ( ) ;
2024-04-08 20:17:26 -04:00
while ( elapsedTimer . elapsed ( ) < 10000 ) {
QCoreApplication : : processEvents ( ) ;
if ( ACQStopButtonPressed ) {
ACQStopButtonPressed = false ;
return ;
}
}
2023-03-15 15:48:33 -04:00
StartACQ ( ) ;
2023-03-30 13:09:11 -04:00
}
2023-03-15 15:48:33 -04:00
} ) ;
}
2023-03-15 19:10:17 -04:00
2023-04-03 18:20:36 -04:00
if ( isRun = = 0 ) return ;
2023-03-15 15:48:33 -04:00
int timeMiliSec = cbAutoRun - > currentData ( ) . toInt ( ) * 60 * 1000 ;
///=========== single timed run
if ( cbAutoRun - > currentData ( ) . toInt ( ) > 0 ) {
runTimer - > setSingleShot ( true ) ;
runTimer - > start ( timeMiliSec ) ;
needManualComment = false ;
}
///=========== infinite timed run
if ( cbAutoRun - > currentData ( ) . toInt ( ) < 0 ) {
runTimer - > setSingleShot ( false ) ;
2024-04-08 20:17:26 -04:00
runTimer - > start ( abs ( timeMiliSec ) ) ;
2023-03-15 15:48:33 -04:00
needManualComment = false ;
2023-02-17 19:30:31 -05:00
}
2023-03-15 15:48:33 -04:00
bnStartACQ - > setEnabled ( false ) ;
bnStopACQ - > setEnabled ( true ) ;
2023-03-27 15:48:41 -04:00
if ( chkSaveRun - > isChecked ( ) ) bnComment - > setEnabled ( true ) ;
2023-03-15 15:48:33 -04:00
bnOpenScope - > setEnabled ( false ) ;
chkSaveRun - > setEnabled ( false ) ;
2023-09-21 17:24:13 -04:00
cbDataFormat - > setEnabled ( false ) ;
2023-03-15 15:48:33 -04:00
cbAutoRun - > setEnabled ( false ) ;
if ( digiSetting ) digiSetting - > EnableControl ( ) ;
2023-02-17 19:30:31 -05:00
}
2023-04-18 10:38:40 -04:00
//*######################################################################
//*###################################################################### open and close digitizer
2023-02-02 19:01:10 -05:00
void MainWindow : : OpenDigitizers ( ) {
2023-02-03 16:58:27 -05:00
LogMsg ( " <font style= \" color:blue; \" >Opening " + QString : : number ( nDigi ) + " Digitizers..... </font> " ) ;
2023-01-25 14:59:48 -05:00
2023-02-02 19:01:10 -05:00
digi = new Digitizer2Gen * [ nDigi ] ;
readDataThread = new ReadDataThread * [ nDigi ] ;
2023-01-25 14:59:48 -05:00
2023-03-27 18:34:22 -04:00
nDigiConnected = 0 ;
2023-03-16 16:05:55 -04:00
2023-03-27 15:48:41 -04:00
//Check path exist
2024-07-03 14:09:23 -04:00
QDir dir ( expDataPath + " /Settings/ " ) ;
2023-03-27 15:48:41 -04:00
if ( ! dir . exists ( ) ) dir . mkpath ( " . " ) ;
2023-02-02 19:01:10 -05:00
for ( int i = 0 ; i < nDigi ; i + + ) {
2023-01-25 14:59:48 -05:00
2023-02-03 14:54:55 -05:00
LogMsg ( " IP : " + IPList [ i ] + " | " + QString : : number ( i + 1 ) + " / " + QString : : number ( nDigi ) ) ;
2023-01-25 14:59:48 -05:00
2023-02-02 19:01:10 -05:00
digi [ i ] = new Digitizer2Gen ( ) ;
2023-02-03 14:54:55 -05:00
digi [ i ] - > OpenDigitizer ( ( " dig2:// " + IPList [ i ] ) . toStdString ( ) . c_str ( ) ) ;
2023-01-25 17:16:14 -05:00
2023-02-02 19:01:10 -05:00
if ( digi [ i ] - > IsConnected ( ) ) {
2023-01-30 18:40:24 -05:00
2023-02-02 19:26:47 -05:00
LogMsg ( " Opened digitizer : <font style= \" color:red; \" > " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " </font> " ) ;
2023-01-27 18:52:03 -05:00
2023-03-16 17:28:55 -04:00
readDataThread [ i ] = new ReadDataThread ( digi [ i ] , i , this ) ;
2023-02-02 19:01:10 -05:00
connect ( readDataThread [ i ] , & ReadDataThread : : sendMsg , this , & MainWindow : : LogMsg ) ;
2023-01-27 18:52:03 -05:00
2024-06-11 14:25:56 -04:00
//*------ search for settings_XXX_YYY.dat, YYY is DPP-type, XXX is serial number
2024-07-03 14:09:23 -04:00
QString settingFile = expDataPath + " /Settings/setting_ " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " _ " + QString : : fromStdString ( digi [ i ] - > GetFPGAType ( ) . substr ( 4 ) ) + " .dat " ;
2023-02-23 12:24:39 -05:00
if ( digi [ i ] - > LoadSettingsFromFile ( settingFile . toStdString ( ) . c_str ( ) ) ) {
2023-03-10 14:42:29 -05:00
LogMsg ( " Found setting file <b> " + settingFile + " </b> and loading. please wait. " ) ;
2023-02-23 16:08:47 -05:00
digi [ i ] - > SetSettingFileName ( settingFile . toStdString ( ) ) ;
2023-03-10 14:42:29 -05:00
LogMsg ( " done settings. " ) ;
2023-02-23 12:24:39 -05:00
} else {
LogMsg ( " <font style= \" color: red; \" >Unable to found setting file <b> " + settingFile + " </b>. </font> " ) ;
2023-02-23 16:08:47 -05:00
digi [ i ] - > SetSettingFileName ( " " ) ;
2023-09-15 17:31:07 -04:00
//LogMsg("Reset digitizer And set default PHA settings.");
//digi[i]->Reset();
2023-09-22 17:57:43 -04:00
//digi[i]->ProgramBoard(false);
2023-02-23 12:24:39 -05:00
}
2023-09-25 14:29:27 -04:00
2023-03-16 16:05:55 -04:00
nDigiConnected + + ;
2023-02-14 17:39:49 -05:00
2023-03-15 19:10:17 -04:00
for ( int ch = 0 ; ch < ( int ) digi [ i ] - > GetNChannels ( ) ; ch + + ) {
oldTimeStamp [ i ] [ ch ] = 0 ;
oldSavedCount [ i ] [ ch ] = 0 ;
}
2023-02-02 19:01:10 -05:00
} else {
2023-02-13 15:22:24 -05:00
digi [ i ] - > SetDummy ( i ) ;
LogMsg ( " Cannot open digitizer. Use a dummy with serial number " + QString : : number ( i ) + " and " + QString : : number ( digi [ i ] - > GetNChannels ( ) ) + " ch. " ) ;
2023-02-02 19:01:10 -05:00
2023-02-02 19:26:47 -05:00
readDataThread [ i ] = NULL ;
2023-02-02 19:01:10 -05:00
}
2023-04-18 10:38:40 -04:00
QCoreApplication : : processEvents ( ) ; // to prevent application busy.
2023-02-02 19:01:10 -05:00
}
2023-02-02 19:26:47 -05:00
2023-03-16 16:05:55 -04:00
if ( nDigiConnected > 0 ) {
SetUpScalar ( ) ;
bnStartACQ - > setEnabled ( true ) ;
bnStopACQ - > setEnabled ( false ) ;
2023-03-27 15:48:41 -04:00
bnComment - > setEnabled ( false ) ;
2023-03-16 16:05:55 -04:00
bnOpenScope - > setEnabled ( true ) ;
chkSaveRun - > setEnabled ( true ) ;
2023-09-15 17:31:07 -04:00
bnSyncHelper - > setEnabled ( true ) ;
2023-03-16 16:05:55 -04:00
bnOpenDigitizers - > setEnabled ( false ) ;
bnOpenDigitizers - > setStyleSheet ( " " ) ;
cbAutoRun - > setEnabled ( true ) ;
2023-09-15 17:31:07 -04:00
cbDataFormat - > setEnabled ( true ) ;
2023-03-16 16:05:55 -04:00
bnOpenScalar - > setEnabled ( true ) ;
}
2023-02-02 19:26:47 -05:00
bnDigiSettings - > setEnabled ( true ) ;
bnCloseDigitizers - > setEnabled ( true ) ;
2023-02-08 17:35:04 -05:00
2023-03-13 16:51:11 -04:00
bnProgramSettings - > setEnabled ( false ) ;
bnNewExp - > setEnabled ( false ) ;
2023-03-31 20:01:27 -04:00
bnSOLSettings - > setEnabled ( CheckSOLARISpanelOK ( ) ) ;
2023-03-17 17:08:56 -04:00
2023-01-25 14:59:48 -05:00
}
2023-02-02 19:01:10 -05:00
void MainWindow : : CloseDigitizers ( ) {
2023-02-03 16:58:27 -05:00
if ( digi = = NULL ) return ;
2023-02-13 15:22:24 -05:00
2023-03-23 16:36:47 -04:00
if ( scope ) {
2023-03-10 14:42:29 -05:00
scope - > close ( ) ;
delete scope ;
scope = NULL ;
}
2023-04-25 17:36:20 -04:00
if ( scalar & & nDigiConnected > 0 ) { // scalar is child of this, This MUST after scope, because scope tell scalar to update ACQ status
scalar - > close ( ) ;
2023-09-19 19:19:07 -04:00
if ( scalarThread - > isRunning ( ) ) {
scalarThread - > Stop ( ) ;
scalarThread - > quit ( ) ;
scalarThread - > wait ( ) ;
}
2023-04-25 17:36:20 -04:00
CleanUpScalar ( ) ; // this use digi->GetNChannels();
}
2023-02-02 19:01:10 -05:00
2023-03-23 16:36:47 -04:00
if ( digiSetting ) {
2023-03-10 14:42:29 -05:00
digiSetting - > close ( ) ;
delete digiSetting ;
digiSetting = NULL ;
}
2023-03-01 18:27:17 -05:00
2023-03-22 18:16:26 -04:00
if ( solarisSetting ) {
solarisSetting - > close ( ) ;
delete solarisSetting ;
solarisSetting = NULL ;
}
2023-02-09 18:27:20 -05:00
for ( int i = 0 ; i < nDigi ; i + + ) {
if ( digi [ i ] = = NULL ) return ;
2023-04-12 13:52:42 -04:00
if ( digi [ i ] - > IsConnected ( ) ) {
int digiSN = digi [ i ] - > GetSerialNumber ( ) ;
2024-07-01 17:19:23 -04:00
LogMsg ( " Save digi- " + QString : : number ( digiSN ) + " Settings to " + programPath + " /tempSettings/ " ) ;
digi [ i ] - > SaveSettingsToFile ( ( programPath + " /tempSettings/Setting_ " + QString : : number ( digiSN ) ) . toStdString ( ) . c_str ( ) ) ;
2023-04-12 13:52:42 -04:00
}
2023-02-02 19:26:47 -05:00
digi [ i ] - > CloseDigitizer ( ) ;
delete digi [ i ] ;
2023-02-13 15:22:24 -05:00
LogMsg ( " Closed Digitizer : " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ) ;
2023-01-30 18:40:24 -05:00
2023-02-02 19:26:47 -05:00
if ( readDataThread [ i ] ! = NULL ) {
2023-03-17 17:08:56 -04:00
LogMsg ( " Waiting for readData Thread ..... " ) ;
2023-09-15 17:31:07 -04:00
readDataThread [ i ] - > Stop ( ) ;
2023-02-02 19:01:10 -05:00
readDataThread [ i ] - > quit ( ) ;
readDataThread [ i ] - > wait ( ) ;
delete readDataThread [ i ] ;
}
2023-01-25 14:59:48 -05:00
}
2023-02-02 19:01:10 -05:00
delete [ ] digi ;
delete [ ] readDataThread ;
digi = NULL ;
readDataThread = NULL ;
2023-02-02 19:26:47 -05:00
2023-09-15 17:31:07 -04:00
bnSyncHelper - > setEnabled ( false ) ;
2023-02-13 15:22:24 -05:00
bnOpenDigitizers - > setEnabled ( true ) ;
2023-02-17 19:30:31 -05:00
bnOpenDigitizers - > setFocus ( ) ;
2023-02-13 15:22:24 -05:00
bnCloseDigitizers - > setEnabled ( false ) ;
bnDigiSettings - > setEnabled ( false ) ;
2023-03-17 17:08:56 -04:00
bnSOLSettings - > setEnabled ( false ) ;
2023-02-13 15:22:24 -05:00
bnStartACQ - > setEnabled ( false ) ;
bnStopACQ - > setEnabled ( false ) ;
2023-03-27 15:48:41 -04:00
bnComment - > setEnabled ( false ) ;
2023-02-17 19:30:31 -05:00
bnOpenScope - > setEnabled ( false ) ;
2023-02-13 15:22:24 -05:00
bnOpenScalar - > setEnabled ( false ) ;
2023-02-14 17:39:49 -05:00
chkSaveRun - > setEnabled ( false ) ;
2023-02-17 19:30:31 -05:00
cbAutoRun - > setEnabled ( false ) ;
2023-09-15 17:31:07 -04:00
cbDataFormat - > setEnabled ( false ) ;
2023-02-13 15:22:24 -05:00
2023-03-13 16:51:11 -04:00
bnProgramSettings - > setEnabled ( true ) ;
bnNewExp - > setEnabled ( true ) ;
2023-03-17 17:08:56 -04:00
LogMsg ( " Closed all digitizers and readData Threads. " ) ;
2023-01-25 14:59:48 -05:00
}
2023-09-15 17:31:07 -04:00
void MainWindow : : OpenSyncHelper ( ) {
LogMsg ( " Open <b>Sync Helper</b>. " ) ;
QDialog dialog ( this ) ;
dialog . setWindowTitle ( " Sync Helper " ) ;
dialog . setWindowFlags ( Qt : : Dialog | Qt : : WindowTitleHint ) ;
QVBoxLayout * layout = new QVBoxLayout ( & dialog ) ;
QPushButton * bnNoSync = new QPushButton ( " No Sync " , & dialog ) ;
2023-09-18 12:52:15 -04:00
QPushButton * bnMethod1 = new QPushButton ( " Software CLK-OUT --> CLK-IN \n (Master = 1st Digi) " , & dialog ) ;
2023-09-15 17:31:07 -04:00
layout - > addWidget ( bnNoSync , 1 ) ;
layout - > addWidget ( bnMethod1 , 2 ) ;
bnNoSync - > setFixedHeight ( 40 ) ;
bnMethod1 - > setFixedHeight ( 40 ) ;
connect ( bnNoSync , & QPushButton : : clicked , [ & ] ( ) {
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2023-09-18 12:52:15 -04:00
digi [ i ] - > WriteValue ( PHA : : DIG : : ClockSource , " Internal " ) ;
digi [ i ] - > WriteValue ( PHA : : DIG : : StartSource , " SWcmd " ) ;
digi [ i ] - > WriteValue ( PHA : : DIG : : SyncOutMode , " Disabled " ) ;
}
if ( digiSetting ) digiSetting - > UpdatePanelFromMemory ( ) ;
2024-04-08 13:57:31 -04:00
bnSyncHelper - > setText ( " Sync Helper (No Sync) " ) ;
2023-09-18 12:52:15 -04:00
dialog . accept ( ) ;
} ) ;
2023-09-15 17:31:07 -04:00
2023-09-18 12:52:15 -04:00
connect ( bnMethod1 , & QPushButton : : clicked , [ & ] ( ) {
digi [ 0 ] - > WriteValue ( PHA : : DIG : : ClockSource , " Internal " ) ;
digi [ 0 ] - > WriteValue ( PHA : : DIG : : EnableClockOutFrontPanel , " True " ) ;
digi [ 0 ] - > WriteValue ( PHA : : DIG : : StartSource , " SWcmd " ) ;
digi [ 0 ] - > WriteValue ( PHA : : DIG : : SyncOutMode , " Run " ) ;
for ( unsigned int i = 1 ; i < nDigi ; i + + ) {
digi [ i ] - > WriteValue ( PHA : : DIG : : ClockSource , " FPClkIn " ) ;
digi [ i ] - > WriteValue ( PHA : : DIG : : EnableClockOutFrontPanel , " True " ) ;
digi [ i ] - > WriteValue ( PHA : : DIG : : StartSource , " EncodedClkIn " ) ;
digi [ i ] - > WriteValue ( PHA : : DIG : : SyncOutMode , " SyncIn " ) ;
2023-09-15 17:31:07 -04:00
}
2023-09-18 12:52:15 -04:00
if ( digiSetting ) digiSetting - > UpdatePanelFromMemory ( ) ;
2024-04-08 13:57:31 -04:00
bnSyncHelper - > setText ( " Sync Helper (Software) " ) ;
2023-09-15 17:31:07 -04:00
dialog . accept ( ) ;
} ) ;
2023-09-18 12:52:15 -04:00
2023-09-15 17:31:07 -04:00
dialog . exec ( ) ;
}
2023-04-18 10:38:40 -04:00
//*######################################################################
//*###################################################################### Open Scope
2023-02-09 18:40:47 -05:00
void MainWindow : : OpenScope ( ) {
if ( digi ) {
if ( ! scope ) {
2023-02-13 15:22:24 -05:00
scope = new Scope ( digi , nDigi , readDataThread ) ;
2023-02-13 17:56:15 -05:00
connect ( scope , & Scope : : CloseWindow , this , [ = ] ( ) { bnStartACQ - > setEnabled ( true ) ; } ) ;
2023-09-19 12:57:42 -04:00
//connect(scope, &Scope::UpdateScalar, this, &MainWindow::UpdateScalar);
2023-02-13 17:56:15 -05:00
connect ( scope , & Scope : : SendLogMsg , this , & MainWindow : : LogMsg ) ;
2023-03-24 17:23:59 -04:00
connect ( scope , & Scope : : UpdateOtherPanels , this , [ = ] ( ) { UpdateAllPanel ( 0 ) ; } ) ;
2023-03-16 17:28:55 -04:00
connect ( scope , & Scope : : TellACQOnOff , this , [ = ] ( const bool onOff ) {
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
influx - > AddDataPoint ( onOff ? " StartStop value=1 " : " StartStop value=0 " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
}
2023-04-12 13:52:42 -04:00
if ( onOff ) {
lbScalarACQStatus - > setText ( " <font style= \" color: green; \" ><b>ACQ On</b></font> " ) ;
} else {
lbScalarACQStatus - > setText ( " <font style= \" color: red; \" ><b>ACQ Off</b></font> " ) ;
}
2023-03-16 17:28:55 -04:00
} ) ;
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
influx - > AddDataPoint ( " StartStop value=1 " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
}
2023-03-24 17:23:59 -04:00
if ( digiSetting ) {
2023-03-10 17:28:02 -05:00
connect ( scope , & Scope : : TellSettingsPanelControlOnOff , digiSetting , & DigiSettingsPanel : : EnableControl ) ;
2023-03-24 17:23:59 -04:00
digiSetting - > EnableControl ( ) ;
}
2023-03-10 18:09:25 -05:00
2023-09-15 17:31:07 -04:00
//scope->StartScope();
2023-04-12 13:52:42 -04:00
2023-02-09 18:40:47 -05:00
} else {
scope - > show ( ) ;
2023-09-19 19:19:07 -04:00
if ( scope - > isVisible ( ) ) scope - > activateWindow ( ) ;
2023-09-15 17:31:07 -04:00
//scope->StartScope();
2023-03-16 17:28:55 -04:00
if ( digiSetting ) digiSetting - > EnableControl ( ) ;
2023-02-09 18:40:47 -05:00
}
}
bnStartACQ - > setEnabled ( false ) ;
}
2023-02-03 16:58:27 -05:00
//^###################################################################### Open digitizer setting panel
2023-01-25 17:16:14 -05:00
void MainWindow : : OpenDigitizersSettings ( ) {
LogMsg ( " Open digitizers Settings Panel " ) ;
if ( digiSetting = = NULL ) {
2024-07-03 14:09:23 -04:00
digiSetting = new DigiSettingsPanel ( digi , nDigi , expDataPath + " /Settings/ " ) ;
2023-03-10 17:28:02 -05:00
connect ( digiSetting , & DigiSettingsPanel : : SendLogMsg , this , & MainWindow : : LogMsg ) ;
2023-03-24 17:23:59 -04:00
connect ( digiSetting , & DigiSettingsPanel : : UpdateOtherPanels , this , [ = ] ( ) { UpdateAllPanel ( 1 ) ; } ) ;
2023-03-10 17:28:02 -05:00
2023-01-25 17:16:14 -05:00
} else {
digiSetting - > show ( ) ;
2023-04-18 17:37:30 -04:00
if ( digiSetting - > isVisible ( ) ) digiSetting - > activateWindow ( ) ;
2023-01-25 17:16:14 -05:00
}
2023-03-24 17:23:59 -04:00
digiSetting - > UpdatePanelFromMemory ( ) ;
2023-01-25 17:16:14 -05:00
}
2023-01-31 18:59:12 -05:00
2023-03-17 17:08:56 -04:00
//^###################################################################### Open SOLARIS setting panel
void MainWindow : : OpenSOLARISpanel ( ) {
2023-03-27 15:48:41 -04:00
LogMsg ( " Open SOLARIS Panel. " ) ;
2023-03-17 17:08:56 -04:00
solarisSetting - > show ( ) ;
2023-03-24 17:23:59 -04:00
solarisSetting - > UpdatePanelFromMemory ( ) ;
2023-04-18 17:37:30 -04:00
if ( solarisSetting - > isVisible ( ) ) solarisSetting - > activateWindow ( ) ;
2023-03-17 17:08:56 -04:00
}
bool MainWindow : : CheckSOLARISpanelOK ( ) {
2023-03-27 15:48:41 -04:00
QFile file ( analysisPath + " /working/Mapping.h " ) ;
2023-03-17 17:08:56 -04:00
if ( ! file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) {
2023-03-27 15:48:41 -04:00
LogMsg ( " Fail to open <b> " + file . fileName ( ) + " </b>. SOLARIS panel disabled. " ) ;
2023-03-17 17:08:56 -04:00
//TODO ----- Create a template of the mapping
return false ;
}
2023-10-25 14:57:07 -04:00
LogMsg ( " Found <b> " + file . fileName ( ) + " </b>. Setting up SOLARIS panel. " ) ;
2023-03-17 17:08:56 -04:00
mapping . clear ( ) ;
std : : vector < int > singleDigiMap ;
detType . clear ( ) ;
2023-03-31 20:01:27 -04:00
detGroupID . clear ( ) ;
2023-03-17 17:08:56 -04:00
detMaxID . clear ( ) ;
2023-03-31 20:01:27 -04:00
detGroupName . clear ( ) ;
2023-03-17 17:08:56 -04:00
bool startRecord = false ;
QTextStream in ( & file ) ;
while ( ! in . atEnd ( ) ) {
QString line = in . readLine ( ) ;
2023-10-20 11:47:39 -04:00
2023-03-20 19:53:47 -04:00
if ( line . contains ( " //^ " ) ) continue ;
2023-10-20 11:47:39 -04:00
if ( line . contains ( " // // " ) ) continue ;
if ( line . contains ( " //// " ) ) continue ;
if ( line . contains ( " //C= " ) ) { // detType
2023-03-17 17:08:56 -04:00
int in1 = line . indexOf ( " { " ) ;
int in2 = line . lastIndexOf ( " } " ) ;
if ( in2 > in1 ) {
QString subLine = line . mid ( in1 + 1 , in2 - in1 - 1 ) . trimmed ( ) . remove ( QRegularExpression ( " [ \" \\ \\ ] " ) ) ;
detType = subLine . split ( " , " ) ;
} else {
LogMsg ( " Problem Found for the Mapping.h. " ) ;
return false ;
}
}
2023-10-20 11:47:39 -04:00
if ( line . contains ( " //C% " ) ) { // groupName
2023-03-31 20:01:27 -04:00
int in1 = line . indexOf ( " { " ) ;
int in2 = line . lastIndexOf ( " } " ) ;
if ( in2 > in1 ) {
QString subLine = line . mid ( in1 + 1 , in2 - in1 - 1 ) . trimmed ( ) . remove ( QRegularExpression ( " [ \" \\ \\ ] " ) ) ;
detGroupName = subLine . split ( " , " ) ;
} else {
LogMsg ( " Problem Found for the Mapping.h. " ) ;
return false ;
}
}
2023-10-20 11:47:39 -04:00
if ( line . contains ( " //C& " ) ) { //groupID
2023-03-31 20:01:27 -04:00
int in1 = line . indexOf ( " { " ) ;
int in2 = line . lastIndexOf ( " } " ) ;
if ( in2 > in1 ) {
QString subLine = line . mid ( in1 + 1 , in2 - in1 - 1 ) . trimmed ( ) . remove ( QRegularExpression ( " [ \" \\ \\ ] " ) ) ;
QStringList haha = subLine . split ( " , " ) ;
for ( int i = 0 ; i < haha . size ( ) ; i + + ) detGroupID . push_back ( haha [ i ] . toInt ( ) ) ;
} else {
LogMsg ( " Problem Found for the Mapping.h. " ) ;
return false ;
}
}
2023-10-20 11:47:39 -04:00
if ( line . contains ( " //C# " ) ) { //detMaxID
2023-03-17 17:08:56 -04:00
int in1 = line . indexOf ( " { " ) ;
int in2 = line . lastIndexOf ( " } " ) ;
if ( in2 > in1 ) {
QString subLine = line . mid ( in1 + 1 , in2 - in1 - 1 ) . trimmed ( ) . remove ( QRegularExpression ( " [ \" \\ \\ ] " ) ) ;
QStringList haha = subLine . split ( " , " ) ;
for ( int i = 0 ; i < haha . size ( ) ; i + + ) detMaxID . push_back ( haha [ i ] . toInt ( ) ) ;
} else {
LogMsg ( " Problem Found for the Mapping.h. " ) ;
return false ;
}
}
2023-03-30 13:09:11 -04:00
if ( line . contains ( " //C " ) ) {
2023-03-17 17:08:56 -04:00
startRecord = true ;
singleDigiMap . clear ( ) ;
continue ;
}
2023-03-30 13:09:11 -04:00
if ( startRecord & & line . contains ( " //C---- " ) ) {
2023-03-17 17:08:56 -04:00
startRecord = false ;
mapping . push_back ( singleDigiMap ) ;
continue ;
}
if ( startRecord ) {
int index = line . lastIndexOf ( " /// " ) ;
if ( index ! = - 1 ) {
line = line . left ( index ) . trimmed ( ) ;
if ( line . endsWith ( " , " ) ) {
line . remove ( line . length ( ) - 1 , 1 ) ;
}
}
QStringList list = line . replace ( ' ' , " " ) . split ( " , " ) ;
for ( int i = 0 ; i < list . size ( ) ; i + + ) {
singleDigiMap . push_back ( list [ i ] . toInt ( ) ) ;
}
}
}
file . close ( ) ;
LogMsg ( " Mapping.h | Num. Digi : " + QString : : number ( mapping . size ( ) ) ) ;
for ( int i = 0 ; i < ( int ) mapping . size ( ) ; i + + ) {
2023-03-17 18:13:36 -04:00
if ( i < nDigi ) {
LogMsg ( " Digi- " + QString : : number ( i ) + " : " + QString : : number ( mapping [ i ] . size ( ) ) + " Ch. | Digi- "
2023-03-17 17:08:56 -04:00
+ QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " : "
2023-03-17 18:13:36 -04:00
+ QString : : number ( digi [ i ] - > GetNChannels ( ) ) + " Ch. " ) ;
} else {
LogMsg ( " Digi- " + QString : : number ( i ) + " : " + QString : : number ( mapping [ i ] . size ( ) ) + " Ch. | No Conneted Digitizer " ) ;
}
2023-03-17 17:08:56 -04:00
}
if ( ( int ) detMaxID . size ( ) ! = detType . size ( ) ) {
LogMsg ( " Size of detector Name and detctor max ID does not match. " ) ;
return false ;
}
2023-03-31 20:01:27 -04:00
if ( nDigiConnected = = 0 ) return false ;
2023-03-17 17:08:56 -04:00
//@============= Create SOLAIRS panel
2023-03-31 20:01:27 -04:00
solarisSetting = new SOLARISpanel ( digi , nDigi , analysisPath , mapping , detType , detGroupName , detGroupID , detMaxID ) ;
2023-03-20 15:52:04 -04:00
connect ( solarisSetting , & SOLARISpanel : : SendLogMsg , this , & MainWindow : : LogMsg ) ;
2023-03-24 17:23:59 -04:00
connect ( solarisSetting , & SOLARISpanel : : UpdateOtherPanels , this , [ = ] ( ) { UpdateAllPanel ( 2 ) ; } ) ;
2023-03-17 17:08:56 -04:00
2023-03-23 16:36:47 -04:00
if ( solarisSetting = = nullptr ) return false ;
2023-03-17 17:08:56 -04:00
return true ;
}
2023-03-24 17:23:59 -04:00
void MainWindow : : UpdateAllPanel ( int panelID ) {
printf ( " %s %d \n " , __func__ , panelID ) ;
switch ( panelID ) {
case 0 : {
if ( digiSetting & & digiSetting - > isVisible ( ) ) digiSetting - > UpdatePanelFromMemory ( ) ;
if ( solarisSetting & & solarisSetting - > isVisible ( ) ) solarisSetting - > UpdatePanelFromMemory ( ) ;
} ; break ;
case 1 : {
if ( scope & & scope - > isVisible ( ) ) scope - > ReadScopeSettings ( ) ;
if ( solarisSetting & & solarisSetting - > isVisible ( ) ) solarisSetting - > UpdatePanelFromMemory ( ) ;
} ; break ;
case 2 : {
if ( scope & & scope - > isVisible ( ) ) scope - > ReadScopeSettings ( ) ;
if ( digiSetting & & digiSetting - > isVisible ( ) ) digiSetting - > UpdatePanelFromMemory ( ) ;
}
}
}
2023-02-13 15:22:24 -05:00
//^###################################################################### Open Scaler, when DAQ is running
void MainWindow : : OpenScaler ( ) {
scalar - > show ( ) ;
2023-12-07 18:10:17 -05:00
if ( isACQRunning ) {
2023-09-19 12:57:42 -04:00
lbScalarACQStatus - > setText ( " <font style= \" color: green; \" ><b>ACQ On</b></font> " ) ;
} else {
lbScalarACQStatus - > setText ( " <font style= \" color: red; \" ><b>ACQ Off</b></font> " ) ;
}
scalarThread - > start ( ) ;
2023-04-18 17:37:30 -04:00
if ( scalar - > isVisible ( ) ) scalar - > activateWindow ( ) ;
2023-02-13 15:22:24 -05:00
}
void MainWindow : : SetUpScalar ( ) {
2023-03-17 17:08:56 -04:00
scalar - > setGeometry ( 0 , 0 , 10 + nDigi * 230 , 1500 ) ;
2023-02-13 17:56:15 -05:00
2023-04-18 10:38:40 -04:00
lbLastUpdateTime = new QLabel ( " Last update : " , scalar ) ;
2023-02-13 17:56:15 -05:00
lbLastUpdateTime - > setAlignment ( Qt : : AlignCenter ) ;
2023-04-12 13:52:42 -04:00
scalarLayout - > removeWidget ( lbLastUpdateTime ) ;
2023-02-13 17:56:15 -05:00
scalarLayout - > addWidget ( lbLastUpdateTime , 0 , 1 , 1 , 1 + nDigi ) ;
2023-02-13 15:22:24 -05:00
2023-04-18 10:38:40 -04:00
lbScalarACQStatus = new QLabel ( " ACQ status " , scalar ) ;
2023-02-22 12:48:54 -05:00
lbScalarACQStatus - > setAlignment ( Qt : : AlignCenter ) ;
2023-04-12 13:52:42 -04:00
scalarLayout - > removeWidget ( lbScalarACQStatus ) ;
2023-02-22 12:48:54 -05:00
scalarLayout - > addWidget ( lbScalarACQStatus , 1 , 1 , 1 , 1 + nDigi ) ;
2023-09-19 12:57:42 -04:00
// QPushButton * bnUpdateScaler = new QPushButton("Manual Update", scalar);
// scalarLayout->addWidget(bnUpdateScaler, 2, 1, 1, 1 + nDigi);
// connect(bnUpdateScaler, &QPushButton::clicked, this, &MainWindow::UpdateScalar);
2023-02-13 17:56:15 -05:00
///==== create the 1st row
2024-04-08 20:41:57 -04:00
int rowID = 5 ;
2023-02-13 15:22:24 -05:00
for ( int ch = 0 ; ch < MaxNumberOfChannel ; ch + + ) {
if ( ch = = 0 ) {
2023-04-18 10:38:40 -04:00
QLabel * lbCH_H = new QLabel ( " Ch " , scalar ) ;
scalarLayout - > addWidget ( lbCH_H , rowID , 0 ) ;
2023-02-13 15:22:24 -05:00
}
rowID + + ;
2023-04-18 10:38:40 -04:00
QLabel * lbCH = new QLabel ( QString : : number ( ch ) , scalar ) ;
lbCH - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbCH , rowID , 0 ) ;
2023-02-13 15:22:24 -05:00
}
2023-02-13 17:56:15 -05:00
///===== create the trigger and accept
2023-02-13 15:22:24 -05:00
leTrigger = new QLineEdit * * [ nDigi ] ;
2023-02-13 17:07:26 -05:00
leAccept = new QLineEdit * * [ nDigi ] ;
2024-04-08 20:41:57 -04:00
lbFileSize = new QLabel * [ nDigi ] ;
2023-02-13 15:22:24 -05:00
for ( int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
2023-09-19 12:57:42 -04:00
rowID = 3 ;
2024-04-08 20:41:57 -04:00
lbFileSize [ iDigi ] = new QLabel ( " file Size " , scalar ) ;
lbFileSize [ iDigi ] - > setAlignment ( Qt : : AlignCenter ) ;
2023-02-13 15:22:24 -05:00
leTrigger [ iDigi ] = new QLineEdit * [ digi [ iDigi ] - > GetNChannels ( ) ] ;
2023-02-13 17:07:26 -05:00
leAccept [ iDigi ] = new QLineEdit * [ digi [ iDigi ] - > GetNChannels ( ) ] ;
2024-06-28 18:30:35 -04:00
for ( int ch = 0 ; ch < digi [ iDigi ] - > GetNChannels ( ) ; ch + + ) {
2023-02-13 15:22:24 -05:00
if ( ch = = 0 ) {
QLabel * lbDigi = new QLabel ( " Digi- " + QString : : number ( digi [ iDigi ] - > GetSerialNumber ( ) ) , scalar ) ;
lbDigi - > setAlignment ( Qt : : AlignCenter ) ;
2023-02-13 17:07:26 -05:00
scalarLayout - > addWidget ( lbDigi , rowID , 2 * iDigi + 1 , 1 , 2 ) ;
2024-04-08 20:41:57 -04:00
rowID + + ;
2023-02-13 17:56:15 -05:00
2024-04-08 20:41:57 -04:00
scalarLayout - > addWidget ( lbFileSize [ iDigi ] , rowID , 2 * iDigi + 1 , 1 , 2 ) ;
2023-02-13 17:56:15 -05:00
rowID + + ;
2023-09-19 19:19:07 -04:00
QLabel * lbA = new QLabel ( " Input [Hz] " , scalar ) ;
2023-02-13 17:56:15 -05:00
lbA - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbA , rowID , 2 * iDigi + 1 ) ;
2023-09-19 19:19:07 -04:00
QLabel * lbB = new QLabel ( " Trig. [Hz] " , scalar ) ;
2023-02-13 17:56:15 -05:00
lbB - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbB , rowID , 2 * iDigi + 2 ) ;
2023-02-13 15:22:24 -05:00
}
rowID + + ;
2023-04-12 13:52:42 -04:00
leTrigger [ iDigi ] [ ch ] = new QLineEdit ( scalar ) ;
2023-02-13 15:22:24 -05:00
leTrigger [ iDigi ] [ ch ] - > setReadOnly ( true ) ;
2023-02-13 17:07:26 -05:00
leTrigger [ iDigi ] [ ch ] - > setAlignment ( Qt : : AlignRight ) ;
scalarLayout - > addWidget ( leTrigger [ iDigi ] [ ch ] , rowID , 2 * iDigi + 1 ) ;
2023-04-12 13:52:42 -04:00
leAccept [ iDigi ] [ ch ] = new QLineEdit ( scalar ) ;
2023-02-13 17:07:26 -05:00
leAccept [ iDigi ] [ ch ] - > setReadOnly ( true ) ;
leAccept [ iDigi ] [ ch ] - > setAlignment ( Qt : : AlignRight ) ;
2023-02-13 17:56:15 -05:00
leAccept [ iDigi ] [ ch ] - > setStyleSheet ( " background-color: #F0F0F0; " ) ;
2023-02-13 17:07:26 -05:00
scalarLayout - > addWidget ( leAccept [ iDigi ] [ ch ] , rowID , 2 * iDigi + 2 ) ;
2023-02-13 15:22:24 -05:00
}
}
}
2023-04-12 13:52:42 -04:00
2023-04-18 10:38:40 -04:00
void MainWindow : : CleanUpScalar ( ) {
2023-02-13 15:22:24 -05:00
2023-04-18 10:38:40 -04:00
if ( leTrigger = = nullptr ) return ;
2023-02-13 15:22:24 -05:00
for ( int i = 0 ; i < nDigi ; i + + ) {
for ( int ch = 0 ; ch < digi [ i ] - > GetNChannels ( ) ; ch + + ) {
delete leTrigger [ i ] [ ch ] ;
2023-02-13 17:07:26 -05:00
delete leAccept [ i ] [ ch ] ;
2023-02-13 15:22:24 -05:00
}
2024-04-08 20:41:57 -04:00
delete lbFileSize [ i ] ;
2023-02-13 15:22:24 -05:00
delete [ ] leTrigger [ i ] ;
2023-02-13 17:07:26 -05:00
delete [ ] leAccept [ i ] ;
2023-02-13 15:22:24 -05:00
}
2024-04-08 20:41:57 -04:00
delete [ ] lbFileSize ;
2023-02-13 15:22:24 -05:00
delete [ ] leTrigger ;
2024-04-08 20:41:57 -04:00
delete [ ] leAccept ;
lbFileSize = nullptr ;
2023-04-18 10:38:40 -04:00
leTrigger = nullptr ;
leAccept = nullptr ;
//Clean up QLabel
QList < QLabel * > labelChildren = scalar - > findChildren < QLabel * > ( ) ;
for ( int i = 0 ; i < labelChildren . size ( ) ; i + + ) delete labelChildren [ i ] ;
2023-02-13 17:07:26 -05:00
}
void MainWindow : : UpdateScalar ( ) {
if ( ! digi ) return ;
2023-02-13 17:56:15 -05:00
lbLastUpdateTime - > setText ( " Last update: " + QDateTime : : currentDateTime ( ) . toString ( " MM.dd hh:mm:ss " ) ) ;
2023-09-19 12:57:42 -04:00
if ( influx & & scalarOutputInflux ) influx - > ClearDataPointsBuffer ( ) ;
2023-02-14 17:39:49 -05:00
std : : string haha [ MaxNumberOfChannel ] = { " " } ;
double acceptRate [ MaxNumberOfChannel ] = { 0 } ;
2023-02-13 18:40:02 -05:00
2023-02-13 17:07:26 -05:00
///===== Get trigger for all channel
2023-03-15 19:10:17 -04:00
unsigned long totalFileSize = 0 ;
2023-02-13 17:07:26 -05:00
for ( int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
if ( digi [ iDigi ] - > IsDummy ( ) ) return ;
//=========== another method, directly readValue
for ( int ch = 0 ; ch < digi [ iDigi ] - > GetNChannels ( ) ; ch + + ) {
2023-03-16 17:28:55 -04:00
digiMTX [ iDigi ] . lock ( ) ;
2023-03-15 19:10:17 -04:00
std : : string timeStr = digi [ iDigi ] - > ReadValue ( PHA : : CH : : ChannelRealtime , ch ) ; // for refreashing SelfTrgRate and SavedCount
2023-03-14 16:17:22 -04:00
haha [ ch ] = digi [ iDigi ] - > ReadValue ( PHA : : CH : : SelfTrgRate , ch ) ;
2023-03-15 19:10:17 -04:00
std : : string kakaStr = digi [ iDigi ] - > ReadValue ( PHA : : CH : : ChannelSavedCount , ch ) ;
2023-03-16 17:28:55 -04:00
digiMTX [ iDigi ] . unlock ( ) ;
2023-03-15 19:10:17 -04:00
unsigned long kaka = std : : stoul ( kakaStr . c_str ( ) ) ;
unsigned long time = std : : stoul ( timeStr . c_str ( ) ) ;
2023-02-13 18:40:02 -05:00
leTrigger [ iDigi ] [ ch ] - > setText ( QString : : fromStdString ( haha [ ch ] ) ) ;
2023-03-17 17:08:56 -04:00
2023-03-20 19:53:47 -04:00
if ( oldTimeStamp [ iDigi ] [ ch ] > 0 & & time - oldTimeStamp [ iDigi ] [ ch ] > 1e9 & & kaka > oldSavedCount [ iDigi ] [ ch ] ) {
2023-03-15 19:10:17 -04:00
acceptRate [ ch ] = ( kaka - oldSavedCount [ iDigi ] [ ch ] ) * 1e9 * 1.0 / ( time - oldTimeStamp [ iDigi ] [ ch ] ) ;
} else {
acceptRate [ ch ] = 0 ;
}
2023-03-20 19:53:47 -04:00
//if( acceptRate[ch] > 10000 ) printf("%d-%2d | old (%lu, %lu), new (%lu, %lu)\n", iDigi, ch, oldTimeStamp[iDigi][ch], oldSavedCount[iDigi][ch], time, kaka);
2023-03-17 17:08:56 -04:00
2023-03-15 19:10:17 -04:00
oldSavedCount [ iDigi ] [ ch ] = kaka ;
oldTimeStamp [ iDigi ] [ ch ] = time ;
2023-02-14 18:44:10 -05:00
//if( kaka != "0" ) printf("%s, %s | %.2f\n", time.c_str(), kaka.c_str(), acceptRate);
2023-02-13 18:40:02 -05:00
leAccept [ iDigi ] [ ch ] - > setText ( QString : : number ( acceptRate [ ch ] , ' f ' , 1 ) ) ;
2024-04-08 20:41:57 -04:00
lbFileSize [ iDigi ] - > setText ( QString : : number ( digi [ iDigi ] - > GetTotalFilesSize ( ) / 1024. / 1024. ) + " MB " ) ;
2023-02-13 17:07:26 -05:00
}
2023-02-13 18:40:02 -05:00
///============== push the trigger, acceptRate rate database
2023-09-19 12:57:42 -04:00
if ( influx & & scalarOutputInflux ) {
2023-02-13 18:40:02 -05:00
for ( int ch = 0 ; ch < digi [ iDigi ] - > GetNChannels ( ) ; ch + + ) {
2023-03-15 19:10:17 -04:00
influx - > AddDataPoint ( " Rate,Bd= " + std : : to_string ( digi [ iDigi ] - > GetSerialNumber ( ) ) + " ,Ch= " + QString : : number ( ch ) . rightJustified ( 2 , ' 0 ' ) . toStdString ( ) + " value= " + haha [ ch ] ) ;
if ( ! std : : isnan ( acceptRate [ ch ] ) ) influx - > AddDataPoint ( " AccpRate,Bd= " + std : : to_string ( digi [ iDigi ] - > GetSerialNumber ( ) ) + " ,Ch= " + QString : : number ( ch ) . rightJustified ( 2 , ' 0 ' ) . toStdString ( ) + " value= " + std : : to_string ( acceptRate [ ch ] ) ) ;
2023-02-13 18:40:02 -05:00
}
}
2023-03-15 19:10:17 -04:00
totalFileSize + = digi [ iDigi ] - > GetTotalFilesSize ( ) ;
2023-02-13 17:07:26 -05:00
}
2023-02-13 15:22:24 -05:00
2023-09-19 12:57:42 -04:00
if ( influx & & influx - > GetDataLength ( ) > 0 & & scalarOutputInflux ) {
2023-03-15 19:10:17 -04:00
if ( chkSaveRun - > isChecked ( ) ) influx - > AddDataPoint ( " FileSize value= " + std : : to_string ( totalFileSize ) ) ;
2023-02-14 17:39:49 -05:00
//influx->PrintDataPoints();
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
}
2023-03-20 15:52:04 -04:00
2023-04-14 14:10:02 -04:00
//TODO record ADC temperature, and status. In this case, the digiSetting is only UpdateFromMemory, manually looping digitizers and get the status.
if ( digiSetting & & digiSetting - > isVisible ( ) ) digiSetting - > UpdateStatus ( ) ;
2023-03-20 15:52:04 -04:00
if ( solarisSetting & & solarisSetting - > isVisible ( ) ) solarisSetting - > UpdateThreshold ( ) ;
2023-02-13 15:22:24 -05:00
}
2023-04-18 10:38:40 -04:00
//*######################################################################
//*###################################################################### Program Settings
2023-02-17 19:30:31 -05:00
void MainWindow : : ProgramSettingsPanel ( ) {
2023-01-31 18:59:12 -05:00
2023-02-01 16:38:02 -05:00
LogMsg ( " Open <b>Program Settings</b>. " ) ;
2023-01-31 18:59:12 -05:00
QDialog dialog ( this ) ;
dialog . setWindowTitle ( " Program Settings " ) ;
2024-10-15 10:59:26 -04:00
dialog . setGeometry ( 0 , 0 , 700 , 800 ) ;
2023-02-02 17:27:39 -05:00
dialog . setWindowFlags ( Qt : : Dialog | Qt : : WindowTitleHint ) ;
2023-01-31 18:59:12 -05:00
QGridLayout * layout = new QGridLayout ( & dialog ) ;
2023-02-01 18:58:51 -05:00
layout - > setVerticalSpacing ( 5 ) ;
2023-02-01 16:38:02 -05:00
unsigned int rowID = 0 ;
//-------- Instruction
QPlainTextEdit * helpInfo = new QPlainTextEdit ( & dialog ) ;
helpInfo - > setReadOnly ( true ) ;
2023-02-02 17:27:39 -05:00
helpInfo - > setStyleSheet ( " background-color: #F3F3F3; " ) ;
2023-02-01 16:38:02 -05:00
helpInfo - > setLineWrapMode ( QPlainTextEdit : : LineWrapMode : : WidgetWidth ) ;
2024-06-28 18:30:35 -04:00
2024-07-01 17:19:23 -04:00
helpInfo - > appendHtml ( " <p></p> " ) ;
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Analysis Path </font> is the path of \
the folder of the analysis code . Can be omitted . " );
helpInfo - > appendHtml ( " <p></p> " ) ;
2023-02-01 16:38:02 -05:00
helpInfo - > appendHtml ( " <p></p> " ) ;
2023-02-02 17:27:39 -05:00
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Analysis Path </font> is the path of \
2024-06-28 18:30:35 -04:00
the folder of the analysis code . Can be omitted . " );
2024-07-01 13:33:49 -04:00
helpInfo - > appendHtml ( " <p></p> " ) ;
2023-02-02 17:27:39 -05:00
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Data Path </font> is the path of the \
2024-07-01 17:19:23 -04:00
< b > parents folder < / b > of data will store . " );
2024-10-15 10:59:26 -04:00
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Exp Name </font> is the name of the experiment and <b>Elog Folder</b>. \
2024-06-28 18:30:35 -04:00
This set the exp . folder under the < font style = \ " color : blue; \" > Data Path </font>. \
2024-10-15 10:59:26 -04:00
The experiment data will be saved under this folder . e . g . < font style = \ " color : blue; \" >Data Path/Exp Name</font>. " ) ;
helpInfo - > appendHtml ( " <p></p> " ) ;
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Save runs in sub-folders </font> means \
saving each run in indivuial subfolder . e . g . < font style = \ " color : blue; \" >Data Path/Exp Name/runXXX</font>. " ) ;
2024-06-28 18:30:35 -04:00
2023-02-01 16:38:02 -05:00
helpInfo - > appendHtml ( " <p></p> " ) ;
2023-02-02 19:01:10 -05:00
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Digitizers IP List </font> is the list of IP \
2023-02-03 14:54:55 -05:00
digi of the digitizers IP . Break by \ " , \" , continue by \" - \" . e.g. 192.168.0.100,102 for 2 digitizers, or 192.168.0.100-102 for 3 digitizers. " ) ;
2024-07-01 17:19:23 -04:00
2023-02-01 16:38:02 -05:00
helpInfo - > appendHtml ( " <p></p> " ) ;
2024-07-01 17:19:23 -04:00
helpInfo - > appendHtml ( " <font style= \" color : blue; \" > Analysis Path </font> is the path of \
the folder of the analysis code . Can be omitted . " );
2023-02-02 17:27:39 -05:00
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. " ) ;
2024-06-28 18:30:35 -04:00
helpInfo - > appendHtml ( " <p></p> " ) ;
helpInfo - > appendHtml ( " * items can be ommitted " ) ;
2023-02-01 16:38:02 -05:00
layout - > addWidget ( helpInfo , rowID , 0 , 1 , 4 ) ;
2023-01-31 18:59:12 -05:00
2024-07-01 17:19:23 -04:00
//-------- Program Setting Path
// rowID ++;
// QLabel *lbSaveSettingPath = new QLabel("Settings Save Path", &dialog);
// lbSaveSettingPath->setAlignment(Qt::AlignRight | Qt::AlignCenter);
// layout->addWidget(lbSaveSettingPath, rowID, 0);
// lSaveSettingPath = new QLineEdit(programSettingsPath, &dialog); layout->addWidget(lSaveSettingPath, rowID, 1, 1, 2);
2023-02-01 16:38:02 -05:00
2024-07-01 17:19:23 -04:00
// QPushButton * bnSaveSettingPath = new QPushButton("browser", &dialog); layout->addWidget(bnSaveSettingPath, rowID, 3);
// connect(bnSaveSettingPath, &QPushButton::clicked, this, [=](){this->OpenDirectory(0);});
2023-01-31 18:59:12 -05:00
2023-02-01 16:38:02 -05:00
//-------- data Path
rowID + + ;
QLabel * lbDataPath = new QLabel ( " Data Path " , & dialog ) ;
lbDataPath - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbDataPath , rowID , 0 ) ;
2024-07-01 17:19:23 -04:00
lExpDataPath = new QLineEdit ( masterExpDataPath , & dialog ) ; layout - > addWidget ( lExpDataPath , rowID , 1 , 1 , 2 ) ;
2023-02-01 16:38:02 -05:00
QPushButton * bnDataPath = new QPushButton ( " browser " , & dialog ) ; layout - > addWidget ( bnDataPath , rowID , 3 ) ;
connect ( bnDataPath , & QPushButton : : clicked , this , [ = ] ( ) { this - > OpenDirectory ( 2 ) ; } ) ;
2024-10-15 10:59:26 -04:00
//-------- Is Save single folder
rowID + + ;
chkSaveSubFolder = new QCheckBox ( " Save runs in sub-folders " , this ) ;
chkSaveSubFolder - > setChecked ( isSaveSubFolder ) ;
layout - > addWidget ( chkSaveSubFolder , rowID , 1 ) ;
2024-06-28 18:30:35 -04:00
//-------- Exp Name Temp
rowID + + ;
2024-07-01 17:19:23 -04:00
QLabel * lbExpNameTemp = new QLabel ( " Exp Name " , & dialog ) ;
2024-06-28 18:30:35 -04:00
lbExpNameTemp - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbExpNameTemp , rowID , 0 ) ;
2024-07-01 17:19:23 -04:00
lExpName = new QLineEdit ( expName , & dialog ) ; layout - > addWidget ( lExpName , rowID , 1 , 1 , 2 ) ;
2023-03-28 16:58:46 -04:00
2024-07-01 17:19:23 -04:00
//-------- Digitizer IP
2023-02-01 16:38:02 -05:00
rowID + + ;
2023-02-02 19:01:10 -05:00
QLabel * lbIPDomain = new QLabel ( " Digitizers IP List " , & dialog ) ;
2023-02-01 16:38:02 -05:00
lbIPDomain - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbIPDomain , rowID , 0 ) ;
2023-02-03 14:54:55 -05:00
lIPDomain = new QLineEdit ( IPListStr , & dialog ) ; layout - > addWidget ( lIPDomain , rowID , 1 , 1 , 2 ) ;
2024-07-01 17:19:23 -04:00
//------- add a separator
rowID + + ;
QFrame * line = new QFrame ;
line - > setFrameShape ( QFrame : : HLine ) ;
line - > setFrameShadow ( QFrame : : Sunken ) ;
layout - > addWidget ( line , rowID , 0 , 1 , 4 ) ;
//-------- analysis Path
rowID + + ;
QLabel * lbAnalysisPath = new QLabel ( " Analysis Path * " , & dialog ) ;
lbAnalysisPath - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbAnalysisPath , rowID , 0 ) ;
lAnalysisPath = new QLineEdit ( analysisPath , & dialog ) ; layout - > addWidget ( lAnalysisPath , rowID , 1 , 1 , 2 ) ;
QPushButton * bnAnalysisPath = new QPushButton ( " browser " , & dialog ) ; layout - > addWidget ( bnAnalysisPath , rowID , 3 ) ;
connect ( bnAnalysisPath , & QPushButton : : clicked , this , [ = ] ( ) { this - > OpenDirectory ( 1 ) ; } ) ;
2023-02-01 16:38:02 -05:00
//-------- DataBase IP
rowID + + ;
2024-06-28 18:30:35 -04:00
QLabel * lbDatbaseIP = new QLabel ( " Database IP * " , & dialog ) ;
2023-02-01 16:38:02 -05:00
lbDatbaseIP - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbDatbaseIP , rowID , 0 ) ;
2023-02-03 14:54:55 -05:00
lDatbaseIP = new QLineEdit ( DatabaseIP , & dialog ) ; layout - > addWidget ( lDatbaseIP , rowID , 1 , 1 , 2 ) ;
2023-01-31 18:59:12 -05:00
//-------- DataBase name
2023-02-01 16:38:02 -05:00
rowID + + ;
2024-06-28 18:30:35 -04:00
QLabel * lbDatbaseName = new QLabel ( " Database Name * " , & dialog ) ;
2023-02-01 16:38:02 -05:00
lbDatbaseName - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbDatbaseName , rowID , 0 ) ;
2023-02-03 14:54:55 -05:00
lDatbaseName = new QLineEdit ( DatabaseName , & dialog ) ; layout - > addWidget ( lDatbaseName , rowID , 1 , 1 , 2 ) ;
2024-07-31 14:54:50 -04:00
//-------- DataBase Token
rowID + + ;
QLabel * lbDatbaseToken = new QLabel ( " Database Token * " , & dialog ) ;
lbDatbaseToken - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbDatbaseToken , rowID , 0 ) ;
lDatbaseToken = new QLineEdit ( DatabaseToken , & dialog ) ; layout - > addWidget ( lDatbaseToken , rowID , 1 , 1 , 2 ) ;
2023-01-31 18:59:12 -05:00
//-------- Elog IP
2023-02-01 16:38:02 -05:00
rowID + + ;
2024-06-28 18:30:35 -04:00
QLabel * lbElogIP = new QLabel ( " Elog IP * " , & dialog ) ;
2023-02-01 16:38:02 -05:00
lbElogIP - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbElogIP , rowID , 0 ) ;
2023-02-03 14:54:55 -05:00
lElogIP = new QLineEdit ( ElogIP , & dialog ) ; layout - > addWidget ( lElogIP , rowID , 1 , 1 , 2 ) ;
2023-02-01 16:38:02 -05:00
2024-10-15 10:59:26 -04:00
//-------- Elog User
rowID + + ;
QLabel * lbElogUser = new QLabel ( " Elog User * " , & dialog ) ;
lbElogUser - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbElogUser , rowID , 0 ) ;
lElogUser = new QLineEdit ( ElogUser , & dialog ) ; layout - > addWidget ( lElogUser , rowID , 1 , 1 , 2 ) ;
//-------- Elog User
rowID + + ;
QLabel * lbElogPWD = new QLabel ( " Elog Password * " , & dialog ) ;
lbElogPWD - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbElogPWD , rowID , 0 ) ;
lElogPWD = new QLineEdit ( ElogPWD , & dialog ) ; layout - > addWidget ( lElogPWD , rowID , 1 , 1 , 2 ) ;
2023-02-01 16:38:02 -05:00
rowID + + ;
QPushButton * button1 = new QPushButton ( " OK and Save " , & dialog ) ;
layout - > addWidget ( button1 , rowID , 1 ) ;
2024-07-01 17:19:23 -04:00
QObject : : connect ( button1 , & QPushButton : : clicked , this , [ = ] ( ) {
IPListStr = lIPDomain - > text ( ) ;
DatabaseIP = lDatbaseIP - > text ( ) ;
DatabaseName = lDatbaseName - > text ( ) ;
2024-07-31 14:54:50 -04:00
DatabaseToken = lDatbaseToken - > text ( ) ;
2024-07-01 17:19:23 -04:00
ElogIP = lElogIP - > text ( ) ;
analysisPath = lAnalysisPath - > text ( ) ;
masterExpDataPath = lExpDataPath - > text ( ) ;
expName = lExpName - > text ( ) ;
SaveProgramSettings ( ) ;
bnProgramSettings - > setStyleSheet ( " " ) ;
bnNewExp - > setEnabled ( true ) ;
if ( ! IPListStr . isEmpty ( ) ) {
DecodeIPList ( ) ;
bnOpenDigitizers - > setEnabled ( true ) ;
} else {
bnProgramSettings - > setStyleSheet ( " color: red; " ) ;
LogMsg ( " <font style= \" color : red; \" >Digitizer IP list is empty.</font> " ) ;
}
SetupInflux ( ) ;
CheckElog ( ) ;
expDataPath = masterExpDataPath + " / " + expName ;
rawDataPath = expDataPath + " /data_raw/ " ;
rootDataPath = expDataPath + " /root_data/ " ;
leExpName - > setText ( expName ) ;
2024-07-01 18:19:36 -04:00
leRawDataPath - > setText ( rawDataPath ) ;
2024-07-01 17:19:23 -04:00
CreateRawDataFolder ( ) ;
LoadExpNameSh ( ) ;
if ( analysisPath . isEmpty ( ) ) bnNewExp - > setEnabled ( false ) ;
} ) ;
2023-01-31 18:59:12 -05:00
QObject : : connect ( button1 , & QPushButton : : clicked , & dialog , & QDialog : : accept ) ;
2023-02-01 16:38:02 -05:00
QPushButton * button2 = new QPushButton ( " Cancel " , & dialog ) ;
layout - > addWidget ( button2 , rowID , 2 ) ;
2023-02-01 18:58:51 -05:00
QObject : : connect ( button2 , & QPushButton : : clicked , this , [ = ] ( ) { this - > LogMsg ( " Cancel <b>Program Settings</b> " ) ; } ) ;
2023-02-01 16:38:02 -05:00
QObject : : connect ( button2 , & QPushButton : : clicked , & dialog , & QDialog : : reject ) ;
layout - > setColumnStretch ( 0 , 2 ) ;
layout - > setColumnStretch ( 1 , 2 ) ;
layout - > setColumnStretch ( 2 , 2 ) ;
layout - > setColumnStretch ( 3 , 1 ) ;
2023-01-31 18:59:12 -05:00
2023-09-26 10:31:55 -04:00
button1 - > setFocus ( ) ;
2023-01-31 18:59:12 -05:00
dialog . exec ( ) ;
}
2023-01-25 14:59:48 -05:00
2023-02-17 19:30:31 -05:00
bool MainWindow : : LoadProgramSettings ( ) {
2023-02-01 16:38:02 -05:00
QString settingFile = QDir : : current ( ) . absolutePath ( ) + " /programSettings.txt " ;
LogMsg ( " Loading <b> " + settingFile + " </b> for Program Settings. " ) ;
QFile file ( settingFile ) ;
2023-02-01 18:58:51 -05:00
bool ret = false ;
2024-10-15 10:59:26 -04:00
//initialized
masterExpDataPath = " " ;
isSaveSubFolder = false ;
expName = " " ;
IPListStr = " " ;
analysisPath = " " ;
DatabaseIP = " " ;
DatabaseName = " " ;
DatabaseToken = " " ;
ElogIP = " " ;
ElogUser = " " ;
ElogPWD = " " ;
2023-02-01 16:38:02 -05:00
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
LogMsg ( " <b> " + settingFile + " </b> not found. " ) ;
LogMsg ( " Please Open the <font style= \" color : red; \" >Program Settings </font> " ) ;
2023-02-01 18:58:51 -05:00
} else {
2023-02-01 16:38:02 -05:00
2023-02-01 18:58:51 -05:00
QTextStream in ( & file ) ;
QString line = in . readLine ( ) ;
int count = 0 ;
while ( ! line . isNull ( ) ) {
if ( line . left ( 6 ) = = " //---- " ) break ;
switch ( count ) {
2024-10-15 10:59:26 -04:00
case 0 : masterExpDataPath = line ; break ;
case 1 : isSaveSubFolder = ( line = = " SubFolder " ? true : false ) ; break ;
case 2 : expName = line ; break ;
case 3 : IPListStr = line ; break ;
case 4 : analysisPath = line ; break ;
case 5 : DatabaseIP = line ; break ;
case 6 : DatabaseName = line ; break ;
case 7 : DatabaseToken = line ; break ;
case 8 : ElogIP = line ; break ;
case 9 : ElogUser = line ; break ;
case 10 : ElogPWD = line ; break ;
2023-02-01 18:58:51 -05:00
}
count + + ;
line = in . readLine ( ) ;
2024-10-15 10:59:26 -04:00
// printf("%d | %s \n", count, line.toStdString().c_str());
2023-02-01 16:38:02 -05:00
}
2024-10-15 10:59:26 -04:00
if ( count > = 3 ) {
2023-02-01 18:58:51 -05:00
logMsgHTMLMode = false ;
2024-07-01 17:19:23 -04:00
// LogMsg("Setting File Path : " + programSettingsPath);
2024-10-15 10:59:26 -04:00
LogMsg ( " Analysis Path : " + analysisPath ) ;
LogMsg ( " Database IP : " + DatabaseIP ) ;
LogMsg ( " Database Name : " + DatabaseName ) ;
LogMsg ( " Database Token : " + maskText ( DatabaseToken ) ) ;
LogMsg ( " ElogIP : " + ElogIP ) ;
LogMsg ( " Elog User : " + ElogUser ) ;
LogMsg ( " Elog Password : " + maskText ( ElogPWD ) ) ;
LogMsg ( " Exp Data Path : " + masterExpDataPath ) ;
LogMsg ( " Save Runs in SubFolders : " + QString ( isSaveSubFolder ? " Yes " : " No " ) ) ;
LogMsg ( " Exp. Name (Elog Name) : " + expName ) ;
LogMsg ( " Digi. IP List : " + IPListStr ) ;
2023-02-01 18:58:51 -05:00
logMsgHTMLMode = true ;
2024-06-28 18:30:35 -04:00
2024-07-01 17:19:23 -04:00
expDataPath = masterExpDataPath + " / " + expName ;
rawDataPath = expDataPath + " /data_raw/ " ;
rootDataPath = expDataPath + " /root_data/ " ;
2024-07-01 13:33:49 -04:00
leExpName - > setText ( expName ) ;
2023-02-01 18:58:51 -05:00
ret = true ;
} else {
LogMsg ( " Settings are not complete. " ) ;
LogMsg ( " Please Open the <font style= \" color : red; \" >Program Settings </font> " ) ;
}
2023-02-01 16:38:02 -05:00
}
2023-02-01 18:58:51 -05:00
if ( ret ) {
2024-07-01 13:33:49 -04:00
//CHeck data path exist
QDir dir ( rawDataPath ) ;
2024-06-28 18:30:35 -04:00
2024-07-01 13:33:49 -04:00
if ( ! dir . exists ( ) ) {
LogMsg ( " <font style= \" color : red; \" >Raw data path " + rawDataPath + " does not exist.</font> " ) ;
bnProgramSettings - > setStyleSheet ( " color: red; " ) ;
bnOpenDigitizers - > setEnabled ( false ) ;
bnNewExp - > setEnabled ( false ) ;
2024-07-01 17:19:23 -04:00
// return false;
2024-07-01 13:33:49 -04:00
} else {
QFileInfo dirInfo ( dir . absolutePath ( ) ) ;
if ( ! dirInfo . isWritable ( ) ) {
LogMsg ( " <font style= \" color : red; \" >Raw data path " + rawDataPath + " is not writable.</font> " ) ;
bnProgramSettings - > setStyleSheet ( " color: red; " ) ;
bnOpenDigitizers - > setEnabled ( false ) ;
bnNewExp - > setEnabled ( false ) ;
2024-07-01 17:19:23 -04:00
// return false;
2024-07-01 13:33:49 -04:00
} else {
leRawDataPath - > setText ( rawDataPath ) ;
leExpName - > setText ( expName ) ;
}
}
2024-06-28 18:30:35 -04:00
2024-07-01 17:19:23 -04:00
if ( ! IPListStr . isEmpty ( ) & & dir . exists ( ) ) {
2024-07-01 13:33:49 -04:00
bnOpenDigitizers - > setEnabled ( true ) ;
2024-07-01 17:19:23 -04:00
bnOpenDigitizers - > setStyleSheet ( " color:red; " ) ;
2024-07-01 13:33:49 -04:00
DecodeIPList ( ) ;
SetupInflux ( ) ;
CheckElog ( ) ;
} else {
LogMsg ( " <font style= \" color : red; \" >Digitizer IP list is empty.</font> " ) ;
bnProgramSettings - > setStyleSheet ( " color: red; " ) ;
bnOpenDigitizers - > setEnabled ( false ) ;
return false ;
}
if ( analysisPath . isEmpty ( ) ) {
LogMsg ( " Analysis Path is empty. " ) ;
bnNewExp - > setEnabled ( false ) ;
2024-07-01 17:19:23 -04:00
// return false;
2024-07-01 13:33:49 -04:00
}
2024-06-28 18:30:35 -04:00
2023-02-03 14:54:55 -05:00
return true ;
2023-02-01 18:58:51 -05:00
2023-02-01 16:38:02 -05:00
} else {
2023-02-01 18:58:51 -05:00
bnProgramSettings - > setStyleSheet ( " color: red; " ) ;
bnNewExp - > setEnabled ( false ) ;
bnOpenDigitizers - > setEnabled ( false ) ;
2023-02-01 16:38:02 -05:00
return false ;
}
}
void MainWindow : : SaveProgramSettings ( ) {
2024-07-01 17:19:23 -04:00
if ( masterExpDataPath . isEmpty ( ) ) {
LogMsg ( " <font style= \" color : red; \" >Exp Data Path is empty.</font> " ) ;
return ;
}
2023-02-01 16:38:02 -05:00
2024-07-01 17:19:23 -04:00
QFile file ( programPath + " /programSettings.txt " ) ;
2023-02-01 16:38:02 -05:00
file . open ( QIODevice : : Text | QIODevice : : WriteOnly ) ;
2024-07-01 17:19:23 -04:00
// file.write((programSettingsPath+"\n").toStdString().c_str());
file . write ( ( masterExpDataPath + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-10-15 10:59:26 -04:00
file . write ( chkSaveSubFolder - > isChecked ( ) ? " SubFolder \n " : " SingleFolder \n " ) ;
2024-06-28 18:30:35 -04:00
file . write ( ( expName + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-02-03 14:54:55 -05:00
file . write ( ( IPListStr + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-07-01 17:19:23 -04:00
file . write ( ( analysisPath + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-02-01 16:38:02 -05:00
file . write ( ( DatabaseIP + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( DatabaseName + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-07-31 14:54:50 -04:00
file . write ( ( DatabaseToken + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-02-01 16:38:02 -05:00
file . write ( ( ElogIP + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-10-15 10:59:26 -04:00
file . write ( ( ElogUser + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( ElogPWD + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-02-01 16:38:02 -05:00
file . write ( " //------------end of file. " ) ;
file . close ( ) ;
2024-07-01 17:19:23 -04:00
LogMsg ( " Saved program settings to <b> " + programPath + " /programSettings.txt<b>. " ) ;
2023-02-01 18:58:51 -05:00
}
2023-04-18 10:38:40 -04:00
void MainWindow : : OpenDirectory ( int id ) {
QFileDialog fileDialog ( this ) ;
fileDialog . setFileMode ( QFileDialog : : Directory ) ;
fileDialog . exec ( ) ;
//qDebug() << fileDialog.selectedFiles();
switch ( id ) {
2024-07-01 17:19:23 -04:00
// case 0 : lSaveSettingPath->setText(fileDialog.selectedFiles().at(0)); break;
2023-04-18 10:38:40 -04:00
case 1 : lAnalysisPath - > setText ( fileDialog . selectedFiles ( ) . at ( 0 ) ) ; break ;
2024-06-28 18:30:35 -04:00
case 2 : lExpDataPath - > setText ( fileDialog . selectedFiles ( ) . at ( 0 ) ) ; break ;
// case 3 : lRootDataPath->setText(fileDialog.selectedFiles().at(0)); break;
2023-04-18 10:38:40 -04:00
}
}
void MainWindow : : DecodeIPList ( ) {
//------- decode IPListStr
nDigi = 0 ;
IPList . clear ( ) ;
QStringList parts = IPListStr . replace ( ' ' , " " ) . split ( " . " ) ;
QString IPDomain = parts [ 0 ] + " . " + parts [ 1 ] + " . " + parts [ 2 ] + " . " ;
parts = parts [ 3 ] . split ( " , " ) ;
for ( int i = 0 ; i < parts . size ( ) ; i + + ) {
if ( parts [ i ] . indexOf ( " - " ) ! = - 1 ) {
QStringList haha = parts [ i ] . split ( " - " ) ;
for ( int j = haha [ 0 ] . toInt ( ) ; j < = haha . last ( ) . toInt ( ) ; j + + ) {
IPList < < IPDomain + QString : : number ( j ) ;
}
} else {
IPList < < IPDomain + parts [ i ] ;
}
}
nDigi = IPList . size ( ) ;
}
//*######################################################################
//*###################################################################### Setup new exp
2023-02-01 18:58:51 -05:00
2023-02-17 19:30:31 -05:00
void MainWindow : : SetupNewExpPanel ( ) {
2023-02-01 18:58:51 -05:00
2023-02-02 17:27:39 -05:00
LogMsg ( " Open <b>New/Change/Reload Exp</b>. " ) ;
2023-02-01 18:58:51 -05:00
QDialog dialog ( this ) ;
dialog . setWindowTitle ( " Setup / change Experiment " ) ;
2024-07-01 17:19:23 -04:00
dialog . setGeometry ( 0 , 0 , 500 , 400 ) ;
2023-02-02 17:27:39 -05:00
dialog . setWindowFlags ( Qt : : Dialog | Qt : : WindowTitleHint | Qt : : CustomizeWindowHint ) ;
2023-02-01 18:58:51 -05:00
QGridLayout * layout = new QGridLayout ( & dialog ) ;
layout - > setVerticalSpacing ( 5 ) ;
unsigned short rowID = 0 ;
//------- instruction
QPlainTextEdit * instr = new QPlainTextEdit ( & dialog ) ;
layout - > addWidget ( instr , rowID , 0 , 1 , 4 ) ;
instr - > setReadOnly ( true ) ;
2023-02-02 17:27:39 -05:00
instr - > setStyleSheet ( " background-color: #F3F3F3; " ) ;
instr - > appendHtml ( " Setup new experiment will do following things: " ) ;
instr - > appendHtml ( " <b>0,</b> Check the git repository in <font style= \" color:blue; \" >Analysis Path</font> " ) ;
2023-03-28 16:58:46 -04:00
instr - > appendHtml ( " <b>1,</b> Create folder in <font style= \" color:blue; \" >Data Path</font> and <font style= \" color:blue; \" >Root Data Path</font> " ) ;
2023-02-02 17:27:39 -05:00
instr - > appendHtml ( " <b>2,</b> Create Symbolic links in <font style= \" color:blue; \" >Analysis Path</font> " ) ;
instr - > appendHtml ( " <p></p> " ) ;
instr - > appendHtml ( " If <font style= \" color:blue; \" >Use Git</font> is <b>checked</b>, \
the repository < b > MUST < / b > be clean . \
It will then create a new branch with the < font style = \ " color:blue; \" >New Exp Name </font> \
or change to pre - exist branch . " );
2023-02-01 18:58:51 -05:00
//------- Analysis Path
rowID + + ;
QLabel * l1 = new QLabel ( " Analysis Path " , & dialog ) ;
l1 - > setAlignment ( Qt : : AlignCenter | Qt : : AlignRight ) ;
layout - > addWidget ( l1 , rowID , 0 ) ;
QLineEdit * le1 = new QLineEdit ( analysisPath , & dialog ) ;
le1 - > setReadOnly ( true ) ;
layout - > addWidget ( le1 , rowID , 1 , 1 , 3 ) ;
2024-07-01 17:19:23 -04:00
// //------- Exp Data Path
rowID + + ;
QLabel * l2 = new QLabel ( " Data Path " , & dialog ) ;
l2 - > setAlignment ( Qt : : AlignCenter | Qt : : AlignRight ) ;
layout - > addWidget ( l2 , rowID , 0 ) ;
2023-02-01 18:58:51 -05:00
2024-07-01 17:19:23 -04:00
QLineEdit * le2 = new QLineEdit ( masterExpDataPath , & dialog ) ;
le2 - > setReadOnly ( true ) ;
layout - > addWidget ( le2 , rowID , 1 , 1 , 3 ) ;
2023-02-01 18:58:51 -05:00
2024-06-28 18:30:35 -04:00
// //------- Root Data Path
// rowID ++;
// QLabel * l2a = new QLabel("Root Data Path ", &dialog);
// l2a->setAlignment(Qt::AlignCenter | Qt::AlignRight);
// layout->addWidget(l2a, rowID, 0);
2023-03-28 16:58:46 -04:00
2024-06-28 18:30:35 -04:00
// QLineEdit * le2a = new QLineEdit(rootDataPath, &dialog);
// le2a->setReadOnly(true);
// layout->addWidget(le2a, rowID, 1, 1, 3);
2023-03-28 16:58:46 -04:00
2023-02-01 18:58:51 -05:00
//------- get harddisk space;
rowID + + ;
QStorageInfo storage = QStorageInfo : : root ( ) ;
qint64 availableSpace = storage . bytesAvailable ( ) ;
QLabel * lbDiskSpace = new QLabel ( " Disk space avalible " , & dialog ) ;
lbDiskSpace - > setAlignment ( Qt : : AlignCenter | Qt : : AlignRight ) ;
layout - > addWidget ( lbDiskSpace , rowID , 0 ) ;
QLineEdit * leDiskSpace = new QLineEdit ( QString : : number ( availableSpace / 1024. / 1024. / 1024. ) + " [GB] " , & dialog ) ;
leDiskSpace - > setReadOnly ( true ) ;
layout - > addWidget ( leDiskSpace , rowID , 1 , 1 , 3 ) ;
//*---------- get git branch
2023-02-02 17:27:39 -05:00
isGitExist = false ;
2023-02-01 18:58:51 -05:00
QProcess git ;
git . setWorkingDirectory ( analysisPath ) ;
2023-03-29 11:26:32 -04:00
git . start ( " git " , QStringList ( ) < < " fetch " ) ;
git . waitForFinished ( ) ;
2023-02-01 18:58:51 -05:00
git . start ( " git " , QStringList ( ) < < " branch " < < " -a " ) ;
git . waitForFinished ( ) ;
QByteArray output = git . readAllStandardOutput ( ) ;
2024-07-01 18:19:36 -04:00
existGitBranches = ( QString : : fromLocal8Bit ( output ) ) . split ( " \n " ) ;
existGitBranches . removeAll ( " " ) ;
2023-02-01 18:58:51 -05:00
2023-02-02 17:27:39 -05:00
//qDebug() << branches;
2024-07-01 18:19:36 -04:00
if ( existGitBranches . size ( ) = = 0 ) {
2023-02-02 17:27:39 -05:00
isGitExist = false ;
} else {
isGitExist = true ;
}
QString presentBranch ;
unsigned short bID = 0 ; // id of the present branch
2024-07-01 18:19:36 -04:00
for ( unsigned short i = 0 ; i < existGitBranches . size ( ) ; i + + ) {
if ( existGitBranches [ i ] . indexOf ( " * " ) ! = - 1 ) {
presentBranch = existGitBranches [ i ] . remove ( " * " ) . remove ( " " ) ;
2023-02-02 17:27:39 -05:00
bID = i ;
break ;
}
}
//*----------- check git branch is clean for git exist
bool isCleanGit = false ;
if ( isGitExist ) {
git . start ( " git " , QStringList ( ) < < " status " < < " --porcelain " < < " --untracked-files=no " ) ;
git . waitForFinished ( ) ;
output = git . readAllStandardOutput ( ) ;
if ( ( QString : : fromLocal8Bit ( output ) ) . isEmpty ( ) ) isCleanGit = true ;
}
2023-02-01 18:58:51 -05:00
//------- present git branch
rowID + + ;
QLabel * l3 = new QLabel ( " Present Git Branches " , & dialog ) ;
l3 - > setAlignment ( Qt : : AlignCenter | Qt : : AlignRight ) ;
layout - > addWidget ( l3 , rowID , 0 ) ;
2023-02-02 17:27:39 -05:00
QLineEdit * le3 = new QLineEdit ( presentBranch , & dialog ) ;
2023-02-01 18:58:51 -05:00
if ( isGitExist = = false ) {
le3 - > setText ( " No git repository!!! " ) ;
le3 - > setStyleSheet ( " color: red; " ) ;
}
le3 - > setReadOnly ( true ) ;
layout - > addWidget ( le3 , rowID , 1 , 1 , 3 ) ;
//------- add a separator
rowID + + ;
QFrame * line = new QFrame ;
line - > setFrameShape ( QFrame : : HLine ) ;
line - > setFrameShadow ( QFrame : : Sunken ) ;
layout - > addWidget ( line , rowID , 0 , 1 , 4 ) ;
2023-02-02 17:27:39 -05:00
//------- use git checkbox
rowID + + ;
QCheckBox * cbUseGit = new QCheckBox ( " Use Git " , & dialog ) ;
cbUseGit - > setChecked ( true ) ;
useGit = true ;
layout - > addWidget ( cbUseGit , rowID , 1 ) ;
connect ( cbUseGit , & QCheckBox : : clicked , this , [ = ] ( ) { this - > useGit = cbUseGit - > isChecked ( ) ; } ) ;
//------- display git cleanness
if ( isGitExist ) {
if ( ! isCleanGit ) {
QLabel * lCleanGit = new QLabel ( " Git not CLEAN!!! Nothing can be done. " , & dialog ) ;
lCleanGit - > setStyleSheet ( " color: red; " ) ;
layout - > addWidget ( lCleanGit , rowID , 2 , 1 , 2 ) ;
}
}
2023-02-01 18:58:51 -05:00
//------- show list of exisiting git repository
rowID + + ;
QLabel * l4 = new QLabel ( " Existing Git Branches " , & dialog ) ;
l4 - > setAlignment ( Qt : : AlignCenter | Qt : : AlignRight ) ;
layout - > addWidget ( l4 , rowID , 0 ) ;
QComboBox * cb = new QComboBox ( & dialog ) ;
layout - > addWidget ( cb , rowID , 1 , 1 , 2 ) ;
QPushButton * bnChangeBranch = new QPushButton ( " Change " , & dialog ) ;
layout - > addWidget ( bnChangeBranch , rowID , 3 ) ;
2023-04-14 13:14:10 -04:00
bnChangeBranch - > setAutoDefault ( false ) ;
2023-02-02 17:27:39 -05:00
connect ( bnChangeBranch , & QPushButton : : clicked , this , [ = ] ( ) { this - > ChangeExperiment ( cb - > currentText ( ) ) ; } ) ;
connect ( bnChangeBranch , & QPushButton : : clicked , & dialog , & QDialog : : accept ) ;
2023-02-01 18:58:51 -05:00
if ( isGitExist = = false ) {
cb - > setEnabled ( false ) ;
bnChangeBranch - > setEnabled ( false ) ;
} else {
2024-07-01 18:19:36 -04:00
for ( int i = 0 ; i < existGitBranches . size ( ) ; i + + ) {
2023-02-02 17:27:39 -05:00
if ( i = = bID ) continue ;
2024-07-01 18:19:36 -04:00
if ( existGitBranches [ i ] . contains ( " HEAD " ) ) continue ;
if ( existGitBranches [ i ] . contains ( presentBranch ) ) continue ;
cb - > addItem ( existGitBranches [ i ] . remove ( " " ) ) ;
2023-02-01 18:58:51 -05:00
}
2023-04-14 13:14:10 -04:00
if ( cb - > count ( ) = = 0 ) {
2023-02-02 17:27:39 -05:00
cb - > setEnabled ( false ) ;
cb - > addItem ( " no other branch " ) ;
bnChangeBranch - > setEnabled ( false ) ;
}
2023-02-01 18:58:51 -05:00
}
2023-02-02 17:27:39 -05:00
connect ( cbUseGit , & QCheckBox : : clicked , this , [ = ] ( ) {
2023-04-14 13:14:10 -04:00
if ( cb - > count ( ) > 1 ) {
cb - > setEnabled ( cbUseGit - > isChecked ( ) ) ;
bnChangeBranch - > setEnabled ( cbUseGit - > isChecked ( ) ) ;
}
} ) ;
2023-02-02 17:27:39 -05:00
2023-02-01 18:58:51 -05:00
//------- type existing or new experiment
rowID + + ;
QLabel * lNewExp = new QLabel ( " New Exp Name " , & dialog ) ;
lNewExp - > setAlignment ( Qt : : AlignCenter | Qt : : AlignRight ) ;
layout - > addWidget ( lNewExp , rowID , 0 ) ;
2023-02-02 17:27:39 -05:00
QLineEdit * newExp = new QLineEdit ( " type and Enter " , & dialog ) ;
2023-02-01 18:58:51 -05:00
layout - > addWidget ( newExp , rowID , 1 , 1 , 2 ) ;
2023-04-14 13:14:10 -04:00
//newExp->setFocus();
QPushButton * bnCreateNewExp = new QPushButton ( " Create " , & dialog ) ;
layout - > addWidget ( bnCreateNewExp , rowID , 3 ) ;
bnCreateNewExp - > setEnabled ( false ) ;
bnCreateNewExp - > setAutoDefault ( false ) ;
connect ( newExp , & QLineEdit : : textChanged , this , [ = ] ( ) {
newExp - > setStyleSheet ( " color : blue; " ) ;
if ( newExp - > text ( ) = = " " ) bnCreateNewExp - > setEnabled ( false ) ;
} ) ;
connect ( newExp , & QLineEdit : : returnPressed , this , [ = ] ( ) {
if ( newExp - > text ( ) ! = " " ) {
newExp - > setStyleSheet ( " " ) ;
bnCreateNewExp - > setEnabled ( true ) ;
}
2023-02-01 18:58:51 -05:00
2023-04-14 13:14:10 -04:00
} ) ;
2023-02-02 17:27:39 -05:00
2023-04-14 13:14:10 -04:00
connect ( bnCreateNewExp , & QPushButton : : clicked , this , [ = ] ( ) { this - > CreateNewExperiment ( newExp - > text ( ) ) ; } ) ;
connect ( bnCreateNewExp , & QPushButton : : clicked , & dialog , & QDialog : : accept ) ;
2023-02-02 17:27:39 -05:00
//----- diable all possible actions
if ( isGitExist ) {
if ( ! isCleanGit ) {
cbUseGit - > setEnabled ( false ) ;
cb - > setEnabled ( false ) ;
bnChangeBranch - > setEnabled ( false ) ;
newExp - > setEnabled ( false ) ;
2023-04-14 13:14:10 -04:00
bnCreateNewExp - > setEnabled ( false ) ;
2023-02-02 17:27:39 -05:00
}
}
2023-02-01 18:58:51 -05:00
//--------- cancel
rowID + + ;
2024-07-01 17:19:23 -04:00
QPushButton * bnCancel = new QPushButton ( " Cancel/Exit " , & dialog ) ;
2023-04-14 13:14:10 -04:00
bnCancel - > setAutoDefault ( false ) ;
2023-02-01 18:58:51 -05:00
layout - > addWidget ( bnCancel , rowID , 0 , 1 , 4 ) ;
2023-02-02 17:27:39 -05:00
connect ( bnCancel , & QPushButton : : clicked , this , [ = ] ( ) { this - > LogMsg ( " Cancel <b>New/Change/Reload Exp</b> " ) ; } ) ;
connect ( bnCancel , & QPushButton : : clicked , & dialog , & QDialog : : reject ) ;
2023-02-01 18:58:51 -05:00
layout - > setRowStretch ( 0 , 1 ) ;
for ( int i = 1 ; i < rowID ; i + + ) layout - > setRowStretch ( i , 2 ) ;
2024-06-28 18:30:35 -04:00
LoadExpNameSh ( ) ;
2023-02-02 17:27:39 -05:00
2023-02-01 18:58:51 -05:00
dialog . exec ( ) ;
}
2024-06-28 18:30:35 -04:00
bool MainWindow : : LoadExpNameSh ( ) {
2023-02-01 18:58:51 -05:00
//this method set the analysis setting ann symbloic link to raw data
//ONLY load file, not check the git
2024-06-28 18:30:35 -04:00
if ( rawDataPath = = " " ) return false ;
2023-02-01 18:58:51 -05:00
2024-06-28 18:30:35 -04:00
QString settingFile = rawDataPath + " /expName.sh " ;
2023-02-01 18:58:51 -05:00
LogMsg ( " Loading <b> " + settingFile + " </b> for Experiment. " ) ;
QFile file ( settingFile ) ;
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
2024-07-01 17:19:23 -04:00
LogMsg ( " <b> " + settingFile + " </b> not found. Create one. " ) ;
// LogMsg("Please Open the <font style=\"color : red;\">New/Change/Reload Exp</font>");
runID = - 1 ;
elogID = 0 ;
//bnOpenDigitizers->setEnabled(false);
//leExpName->setText("no expName found.");
2023-02-01 18:58:51 -05:00
2024-07-01 17:19:23 -04:00
WriteExpNameSh ( ) ;
2023-02-01 18:58:51 -05:00
2024-07-01 17:19:23 -04:00
// return false;
2023-02-01 18:58:51 -05:00
}
QTextStream in ( & file ) ;
QString line = in . readLine ( ) ;
int count = 0 ;
while ( ! line . isNull ( ) ) {
int index = line . indexOf ( " = " ) ;
QString haha = line . mid ( index + 1 ) . remove ( " " ) . remove ( " \" " ) ;
//qDebug() << haha;
switch ( count ) {
case 0 : expName = haha ; break ;
2024-07-01 17:19:23 -04:00
// case 1 : masterExpDataPath = haha; break;
2024-06-28 18:30:35 -04:00
case 1 : runID = haha . toInt ( ) ; break ;
case 2 : elogID = haha . toInt ( ) ; break ;
2023-02-01 18:58:51 -05:00
}
count + + ;
line = in . readLine ( ) ;
}
2024-07-01 17:19:23 -04:00
// rawDataPath = masterExpDataPath + "/" + expName + "/data_raw/";
// rootDataPath = masterExpDataPath + "/" + expName + "/root_data/";
2024-06-28 18:30:35 -04:00
2024-07-01 17:19:23 -04:00
// leRawDataPath->setText(rawDataPath);
2023-02-01 18:58:51 -05:00
leExpName - > setText ( expName ) ;
leRunID - > setText ( QString : : number ( runID ) ) ;
return true ;
}
2023-04-18 10:38:40 -04:00
void MainWindow : : WriteExpNameSh ( ) {
2024-06-28 18:30:35 -04:00
QDir dir ( rawDataPath ) ;
2023-04-18 10:38:40 -04:00
if ( ! dir . exists ( ) ) dir . mkpath ( " . " ) ;
//----- create the expName.sh
2024-06-28 18:30:35 -04:00
QFile file2 ( rawDataPath + " /expName.sh " ) ;
2023-04-18 10:38:40 -04:00
file2 . open ( QIODevice : : Text | QIODevice : : WriteOnly ) ;
file2 . write ( ( " expName= " + expName + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-07-01 17:19:23 -04:00
// file2.write(("ExpDataPath="+ masterExpDataPath + "\n").toStdString().c_str());
2023-04-18 10:38:40 -04:00
file2 . write ( ( " runID= " + std : : to_string ( runID ) + " \n " ) . c_str ( ) ) ;
file2 . write ( ( " elogID= " + std : : to_string ( elogID ) + " \n " ) . c_str ( ) ) ;
file2 . write ( " #------------end of file. " ) ;
file2 . close ( ) ;
2024-06-28 18:30:35 -04:00
LogMsg ( " Saved expName.sh to <b> " + rawDataPath + " /expName.sh<b>. " ) ;
2023-04-18 10:38:40 -04:00
}
2023-02-02 17:27:39 -05:00
void MainWindow : : CreateNewExperiment ( const QString newExpName ) {
2023-02-01 18:58:51 -05:00
2024-07-01 18:19:36 -04:00
if ( newExpName = = " HEAD " | | newExpName = = " head " ) {
LogMsg ( " Cannot name new exp as HEAD or head " ) ;
return ;
}
if ( newExpName = = expName ) {
LogMsg ( " Already at this branch. " ) ;
return ;
}
//Check if newExpName already exist, if exist, go to run ChanegExperiment()
for ( int i = 0 ; i < existGitBranches . size ( ) ; i + + ) {
if ( existGitBranches [ i ] . contains ( " HEAD " ) ) continue ;
if ( existGitBranches [ i ] = = newExpName ) {
ChangeExperiment ( newExpName ) ;
return ;
}
}
2023-04-14 13:14:10 -04:00
LogMsg ( " ====================================== " ) ;
2023-02-02 17:27:39 -05:00
LogMsg ( " Creating new Exp. : <font style= \" color: red; \" > " + newExpName + " </font> " ) ;
2023-02-22 12:41:48 -05:00
expName = newExpName ;
runID = - 1 ;
elogID = 0 ;
2024-07-01 17:56:03 -04:00
expDataPath = masterExpDataPath + " / " + expName ;
rawDataPath = expDataPath + " /data_raw/ " ;
rootDataPath = expDataPath + " /root_data/ " ;
2024-07-01 17:19:23 -04:00
CreateRawDataFolder ( ) ;
2023-02-22 12:41:48 -05:00
WriteExpNameSh ( ) ;
2023-02-02 17:27:39 -05:00
//@----- git must be clean
//----- creat new git branch
if ( useGit ) {
QProcess git ;
git . setWorkingDirectory ( analysisPath ) ;
if ( ! isGitExist ) {
git . start ( " git " , QStringList ( ) < < " init " < < " -b " < < newExpName ) ;
git . waitForFinished ( ) ;
LogMsg ( " Initialzed a git repositiory with branch name <b> " + newExpName + " </b> " ) ;
} else {
git . start ( " git " , QStringList ( ) < < " checkout " < < " -b " < < newExpName ) ;
git . waitForFinished ( ) ;
LogMsg ( " Creat name branch : <b> " + newExpName + " </b> " ) ;
}
}
2024-07-01 17:56:03 -04:00
//check if .gitignore exist
QFile gitIgnore ( analysisPath + " /.gitignore " ) ;
if ( ! gitIgnore . exists ( ) ) {
if ( gitIgnore . open ( QIODevice : : Text | QIODevice : : WriteOnly ) ) {
gitIgnore . write ( " data_raw \n " ) ;
gitIgnore . write ( " root_data \n " ) ;
gitIgnore . write ( " *.root \n " ) ;
gitIgnore . write ( " *.d \n " ) ;
gitIgnore . write ( " *.so \n " ) ;
gitIgnore . close ( ) ;
}
}
2023-02-02 17:27:39 -05:00
//----- create git branch
if ( useGit ) {
QProcess git ;
git . setWorkingDirectory ( analysisPath ) ;
git . start ( " git " , QStringList ( ) < < " add " < < " -A " ) ;
git . waitForFinished ( ) ;
2024-07-01 17:19:23 -04:00
git . start ( " git " , QStringList ( ) < < " commit " < < " --allow-empty " < < " -m " < < " initial commit. " ) ;
2023-02-02 17:27:39 -05:00
git . waitForFinished ( ) ;
2023-04-14 13:14:10 -04:00
LogMsg ( " Commit branch : <b> " + expName + " </b> as \" initial commit \" " ) ;
//check if remote exist, if exist, push to remote
git . start ( " git " , QStringList ( ) < < " remote " ) ;
git . waitForFinished ( ) ;
QString haha = QString : : fromLocal8Bit ( git . readAllStandardOutput ( ) ) ;
if ( haha ! = " " ) {
git . start ( " git " , QStringList ( ) < < " push " < < " --set-upstream " < < haha . remove ( ' \n ' ) < < expName ) ;
git . waitForFinished ( ) ;
qDebug ( ) < < QString : : fromLocal8Bit ( git . readAllStandardOutput ( ) ) ;
LogMsg ( " Pushed new branch : <b> " + expName + " </b> to remote repositiory. " ) ;
}
2023-02-02 17:27:39 -05:00
}
2023-04-14 14:10:02 -04:00
//TODO is there anyway to create a new elog ?? direct edit the config.cfg??
2023-04-14 13:14:10 -04:00
//CheckElog();
logMsgHTMLMode = true ;
LogMsg ( " <font style= \" color red; \" > !!!! Please Create a new Elog with name <b> " + newExpName + " </b>. </font> " ) ;
2023-03-13 18:31:10 -04:00
2024-07-01 17:19:23 -04:00
expDataPath = masterExpDataPath + " / " + newExpName ;
rawDataPath = expDataPath + " /data_raw/ " ;
rootDataPath = expDataPath + " /root_data/ " ;
2024-07-01 13:33:49 -04:00
2024-07-01 17:19:23 -04:00
CreateRawDataFolder ( ) ;
CreateDataSymbolicLink ( ) ;
2024-07-01 13:33:49 -04:00
2024-06-28 18:30:35 -04:00
leRawDataPath - > setText ( rawDataPath ) ;
2023-02-02 17:27:39 -05:00
leExpName - > setText ( expName ) ;
leRunID - > setText ( QString : : number ( runID ) ) ;
2024-07-01 17:19:23 -04:00
SaveProgramSettings ( ) ;
2023-02-02 17:27:39 -05:00
bnOpenDigitizers - > setEnabled ( true ) ;
bnOpenDigitizers - > setStyleSheet ( " color:red; " ) ;
2023-03-29 15:24:53 -04:00
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
startComment = " New experiment [ " + expName + " ] was created. " ;
influx - > AddDataPoint ( " RunID,start=0 value= " + std : : to_string ( runID ) + " ,expName= \" " + expName . toStdString ( ) + " \" ,comment= \" " + startComment . replace ( ' ' , ' _ ' ) . toStdString ( ) + " \" " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
}
2023-02-01 18:58:51 -05:00
}
2023-02-02 17:27:39 -05:00
void MainWindow : : ChangeExperiment ( const QString newExpName ) {
2023-04-14 13:14:10 -04:00
expName = newExpName ;
if ( newExpName . contains ( " remotes " ) ) {
QStringList haha = newExpName . split ( ' / ' ) ;
expName = haha . last ( ) ;
}
2023-02-02 17:27:39 -05:00
2023-04-14 13:14:10 -04:00
//@---- git must exist.
2023-02-02 17:27:39 -05:00
QProcess git ;
git . setWorkingDirectory ( analysisPath ) ;
2023-04-14 13:14:10 -04:00
git . start ( " git " , QStringList ( ) < < " checkout " < < expName ) ;
2023-02-02 17:27:39 -05:00
git . waitForFinished ( ) ;
2023-02-01 18:58:51 -05:00
2023-02-02 17:27:39 -05:00
2023-04-14 13:14:10 -04:00
LogMsg ( " ============================================= " ) ;
LogMsg ( " Swicted to branch : <b> " + expName + " </b> " ) ;
2024-07-01 17:56:03 -04:00
expDataPath = masterExpDataPath + " / " + newExpName ;
rawDataPath = expDataPath + " /data_raw/ " ;
rootDataPath = expDataPath + " /root_data/ " ;
2024-07-01 17:19:23 -04:00
CreateRawDataFolder ( ) ;
2024-07-01 17:56:03 -04:00
CreateDataSymbolicLink ( ) ;
SaveProgramSettings ( ) ;
2024-06-28 18:30:35 -04:00
LoadExpNameSh ( ) ;
2023-02-02 17:27:39 -05:00
2023-03-29 15:24:53 -04:00
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
startComment = " Switched to experiment [ " + expName + " ]. " ;
influx - > AddDataPoint ( " RunID,start=0 value= " + std : : to_string ( runID ) + " ,expName= \" " + expName . toStdString ( ) + " \" ,comment= \" " + startComment . replace ( ' ' , ' _ ' ) . toStdString ( ) + " \" " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
}
2023-02-02 17:27:39 -05:00
}
2024-10-15 10:59:26 -04:00
void MainWindow : : CreateFolder ( QString path , QString AdditionalMsg ) {
2023-02-02 17:27:39 -05:00
2024-10-15 10:59:26 -04:00
QDir dir ( path ) ;
2024-07-01 17:19:23 -04:00
if ( ! dir . exists ( ) ) {
2024-10-15 10:59:26 -04:00
if ( dir . mkpath ( path ) ) {
LogMsg ( " Created folder <b> " + path + " </b> " + AdditionalMsg ) ;
2023-02-02 17:27:39 -05:00
} else {
2024-10-15 10:59:26 -04:00
LogMsg ( " Folder \" <font style= \" color:red; \" ><b> " + rawDataPath + " </b> \" cannot be created. Access right problem? </font> " ) ;
2023-02-02 17:27:39 -05:00
}
} else {
2024-10-15 10:59:26 -04:00
LogMsg ( " Folder \" <b> " + rawDataPath + " </b> \" already exist. " ) ;
2023-02-02 17:27:39 -05:00
}
2024-10-15 10:59:26 -04:00
}
void MainWindow : : CreateRawDataFolder ( ) {
//----- create data folder
CreateFolder ( rawDataPath , " for storing raw data. " ) ;
2023-03-28 16:58:46 -04:00
//----- create root data folder
2024-10-15 10:59:26 -04:00
CreateFolder ( rootDataPath , " for storing root file. " ) ;
2023-03-28 16:58:46 -04:00
2023-02-22 12:41:48 -05:00
//----- create analysis Folder
2024-10-15 10:59:26 -04:00
if ( ! analysisPath . isEmpty ( ) ) {
CreateFolder ( analysisPath , " for analysis. " ) ;
2023-02-22 12:41:48 -05:00
}
2024-07-01 17:19:23 -04:00
}
void MainWindow : : CreateDataSymbolicLink ( ) {
2023-02-02 17:27:39 -05:00
QString linkName = analysisPath + " /data_raw " ;
QFile file ;
if ( file . exists ( linkName ) ) {
file . remove ( linkName ) ;
2023-04-14 13:14:10 -04:00
LogMsg ( " removing existing Link " ) ;
2023-02-02 17:27:39 -05:00
}
2024-06-28 18:30:35 -04:00
if ( file . link ( rawDataPath , linkName ) ) {
LogMsg ( " Symbolic link <b> " + linkName + " </b> -> " + rawDataPath + " created. " ) ;
2023-02-02 17:27:39 -05:00
} else {
2024-06-28 18:30:35 -04:00
LogMsg ( " <font style= \" color:red; \" >Symbolic link <b> " + linkName + " </b> -> " + rawDataPath + " cannot be created. </font> " ) ;
2023-02-02 17:27:39 -05:00
}
2023-03-28 16:58:46 -04:00
2023-04-14 13:14:10 -04:00
linkName = analysisPath + " /root_data " ;
2023-03-28 16:58:46 -04:00
if ( file . exists ( linkName ) ) {
file . remove ( linkName ) ;
2023-04-14 13:14:10 -04:00
LogMsg ( " removing existing Link " ) ;
2023-03-28 16:58:46 -04:00
}
2024-06-28 18:30:35 -04:00
if ( file . link ( rootDataPath , linkName ) ) {
LogMsg ( " Symbolic link <b> " + linkName + " </b> -> " + rootDataPath + " created. " ) ;
2023-03-28 16:58:46 -04:00
} else {
2024-06-28 18:30:35 -04:00
LogMsg ( " <font style= \" color:red; \" >Symbolic link <b> " + linkName + " </b> -> " + rootDataPath + " cannot be created. </font> " ) ;
2023-03-28 16:58:46 -04:00
}
2024-07-01 17:19:23 -04:00
2023-02-01 16:38:02 -05:00
}
2023-04-18 10:38:40 -04:00
//*######################################################################
//*###################################################################### log msg and others
2023-03-17 17:08:56 -04:00
2023-01-25 14:59:48 -05:00
void MainWindow : : LogMsg ( QString msg ) {
2023-02-01 16:38:02 -05:00
QString outputStr = QStringLiteral ( " [%1] %2 " ) . arg ( QDateTime : : currentDateTime ( ) . toString ( " MM.dd hh:mm:ss " ) , msg ) ;
if ( logMsgHTMLMode ) {
logInfo - > appendHtml ( outputStr ) ;
} else {
logInfo - > appendPlainText ( outputStr ) ;
}
2023-01-25 14:59:48 -05:00
QScrollBar * v = logInfo - > verticalScrollBar ( ) ;
v - > setValue ( v - > maximum ( ) ) ;
2023-01-30 18:40:24 -05:00
//qDebug() << msg;
2023-01-25 14:59:48 -05:00
logInfo - > repaint ( ) ;
}
2023-02-17 19:30:31 -05:00
2023-04-18 10:38:40 -04:00
void MainWindow : : SetupInflux ( ) {
if ( influx ) {
delete influx ;
influx = NULL ;
}
2024-06-28 18:30:35 -04:00
if ( DatabaseIP . isEmpty ( ) | | DatabaseName . isEmpty ( ) ) {
LogMsg ( " No Database IP or Name. No database will be used. " ) ;
return ;
}
2023-04-18 10:38:40 -04:00
if ( DatabaseIP ! = " " ) {
influx = new InfluxDB ( DatabaseIP . toStdString ( ) , false ) ;
if ( influx - > TestingConnection ( ) ) {
2024-07-31 14:54:50 -04:00
LogMsg ( " <font style= \" color : green; \" > InfluxDB URL (<b> " + DatabaseIP + " </b>) is Valid. Version : " + QString : : fromStdString ( influx - > GetVersionString ( ) ) + " </font> " ) ;
if ( influx - > GetVersionNo ( ) > 1 & & DatabaseToken . isEmpty ( ) ) {
LogMsg ( " <font style= \" color : red; \" >A Token is required for accessing the database.</font> " ) ;
delete influx ;
influx = nullptr ;
return ;
}
influx - > SetToken ( DatabaseToken . toStdString ( ) ) ;
2023-04-18 10:38:40 -04:00
//==== chck database exist
LogMsg ( " List of database: " ) ;
2024-07-31 14:54:50 -04:00
influx - > CheckDatabases ( ) ;
2023-04-18 10:38:40 -04:00
std : : vector < std : : string > databaseList = influx - > GetDatabaseList ( ) ;
bool foundDatabase = false ;
for ( int i = 0 ; i < ( int ) databaseList . size ( ) ; i + + ) {
if ( databaseList [ i ] = = DatabaseName . toStdString ( ) ) foundDatabase = true ;
LogMsg ( QString : : number ( i ) + " | " + QString : : fromStdString ( databaseList [ i ] ) ) ;
}
if ( foundDatabase ) {
LogMsg ( " <font style= \" color : green; \" > Database <b> " + DatabaseName + " </b> found. " ) ;
influx - > AddDataPoint ( " ProgramStart value=1 " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
if ( influx - > IsWriteOK ( ) ) {
LogMsg ( " <font style= \" color : green; \" >test write database OK.</font> " ) ;
} else {
LogMsg ( " <font style= \" color : red; \" >test write database FAIL.</font> " ) ;
}
} else {
LogMsg ( " <font style= \" color : red; \" > Database <b> " + DatabaseName + " </b> NOT found. " ) ;
delete influx ;
influx = NULL ;
}
} else {
LogMsg ( " <font style= \" color : red; \" > InfluxDB URL (<b> " + DatabaseIP + " </b>) is NOT Valid </font> " ) ;
delete influx ;
influx = NULL ;
}
} else {
LogMsg ( " No database is provided. " ) ;
}
}
void MainWindow : : CheckElog ( ) {
2024-06-28 18:30:35 -04:00
if ( ElogIP . isEmpty ( ) ) {
LogMsg ( " No Elog IP. No elog will be used. " ) ;
2024-07-01 17:19:23 -04:00
elogID = - 1 ;
2024-06-28 18:30:35 -04:00
return ;
}
2023-04-18 10:38:40 -04:00
WriteElog ( " Checking elog writing " , " Testing communication " , " checking " ) ;
if ( elogID > 0 ) {
LogMsg ( " Checked Elog writing. OK. " ) ;
AppendElog ( " Check Elog append. " , - 1 ) ;
if ( elogID > 0 ) {
LogMsg ( " Checked Elog Append. OK. " ) ;
} else {
LogMsg ( " <font style= \" color : red; \" >Checked Elog Append. FAIL. (no elog will be used.) </font> " ) ;
}
} else {
LogMsg ( " <font style= \" color : red; \" >Checked Elog Write. FAIL. (no elog will be used.) (probably logbook <b> " + expName + " </b> does not exist) </font> " ) ;
}
}
2023-02-22 12:41:48 -05:00
void MainWindow : : WriteElog ( QString htmlText , QString subject , QString category , int runNumber ) {
2023-02-17 19:30:31 -05:00
2023-03-17 17:08:56 -04:00
//if( elogID < 0 ) return;
2023-02-17 19:30:31 -05:00
if ( expName = = " " ) return ;
2023-03-10 14:42:29 -05:00
//TODO ===== user name and pwd load from a file.
2023-02-17 19:30:31 -05:00
QStringList arg ;
2024-10-15 10:59:26 -04:00
arg < < " -h " < < ElogIP < < " -p " < < " 8080 " < < " -l " < < expName < < " -u " < < ElogUser < < ElogPWD
< < " -a " < < " Author=SOLARIS_DAQ " ;
2023-03-30 13:09:11 -04:00
if ( runNumber > 0 ) arg < < " -a " < < " RunNo= " + QString : : number ( runNumber ) ;
2023-02-22 12:41:48 -05:00
if ( category ! = " " ) arg < < " -a " < < " Category= " + category ;
arg < < " -a " < < " Subject= " + subject
2023-02-17 19:30:31 -05:00
< < " -n " < < " 2 " < < htmlText ;
2023-03-17 17:08:56 -04:00
2023-02-17 19:30:31 -05:00
QProcess elogBash ( this ) ;
elogBash . start ( " elog " , arg ) ;
elogBash . waitForFinished ( ) ;
QString output = QString : : fromUtf8 ( elogBash . readAllStandardOutput ( ) ) ;
int index = output . indexOf ( " ID= " ) ;
if ( index ! = - 1 ) {
elogID = output . mid ( index + 3 ) . toInt ( ) ;
} else {
elogID = - 1 ;
}
}
void MainWindow : : AppendElog ( QString appendHtmlText , int screenID ) {
if ( elogID < 1 ) return ;
if ( expName = = " " ) return ;
QProcess elogBash ( this ) ;
QStringList arg ;
2024-10-15 10:59:26 -04:00
arg < < " -h " < < ElogIP < < " -p " < < " 8080 " < < " -l " < < expName < < " -u " < < ElogUser < < ElogPWD < < " -w " < < QString : : number ( elogID ) ;
2023-02-17 19:30:31 -05:00
//retrevie the elog
elogBash . start ( " elog " , arg ) ;
elogBash . waitForFinished ( ) ;
QString output = QString : : fromUtf8 ( elogBash . readAllStandardOutput ( ) ) ;
//qDebug() << output;
QString separator = " ======================================== " ;
int index = output . indexOf ( separator ) ;
if ( index ! = - 1 ) {
QString originalHtml = output . mid ( index + separator . length ( ) ) ;
arg . clear ( ) ;
2024-10-15 10:59:26 -04:00
arg < < " -h " < < ElogIP < < " -p " < < " 8080 " < < " -l " < < expName < < " -u " < < ElogUser < < ElogPWD < < " -e " < < QString : : number ( elogID )
2023-02-17 19:30:31 -05:00
< < " -n " < < " 2 " < < originalHtml + " <br> " + appendHtmlText ;
if ( screenID > = 0 ) {
//TODO =========== chrome windowID
QScreen * screen = QGuiApplication : : primaryScreen ( ) ;
if ( screen ) {
QPixmap screenshot = screen - > grabWindow ( screenID ) ;
screenshot . save ( " screenshot.png " ) ;
arg < < " -f " < < " screenshot.png " ;
}
}
2023-03-30 18:01:54 -04:00
//TODO ========= add elog bash script to tell mac, capture screenshot and send it back.
2023-02-17 19:30:31 -05:00
elogBash . start ( " elog " , arg ) ;
elogBash . waitForFinished ( ) ;
output = QString : : fromUtf8 ( elogBash . readAllStandardOutput ( ) ) ;
index = output . indexOf ( " ID= " ) ;
if ( index ! = - 1 ) {
elogID = output . mid ( index + 3 ) . toInt ( ) ;
} else {
elogID = - 1 ;
}
} else {
elogID = - 1 ;
}
}
2023-12-07 18:10:17 -05:00
void MainWindow : : WriteRunTimeStampDat ( bool isStartRun , QString timeStr ) {
2023-03-15 19:10:17 -04:00
2024-07-01 17:19:23 -04:00
QFile file ( masterExpDataPath + " / " + expName + " /data_raw/RunTimeStamp.dat " ) ;
2023-03-15 19:10:17 -04:00
2023-04-03 18:20:36 -04:00
if ( file . open ( QIODevice : : Text | QIODevice : : WriteOnly | QIODevice : : Append ) ) {
2023-03-15 19:10:17 -04:00
2023-04-03 18:20:36 -04:00
if ( isStartRun ) {
2023-12-07 18:10:17 -05:00
file . write ( ( " Start Run | " + QString : : number ( runID ) + " | " + timeStr + " | " + startComment + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-04-03 18:20:36 -04:00
} else {
2023-12-07 18:10:17 -05:00
file . write ( ( " Stop Run | " + QString : : number ( runID ) + " | " + timeStr + " | " + stopComment + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-04-03 18:20:36 -04:00
}
file . close ( ) ;
}
2024-07-01 17:19:23 -04:00
QFile fileCSV ( masterExpDataPath + " / " + expName + " /data_raw/RunTimeStamp.csv " ) ;
2023-04-03 18:20:36 -04:00
if ( fileCSV . open ( QIODevice : : Text | QIODevice : : WriteOnly | QIODevice : : Append ) ) {
QTextStream out ( & fileCSV ) ;
if ( isStartRun ) {
2023-12-07 18:10:17 -05:00
out < < QString : : number ( runID ) + " , " + timeStr + " , " + startComment ;
2023-04-03 18:20:36 -04:00
} else {
2023-12-07 18:10:17 -05:00
out < < " , " + timeStr + " , " + stopComment + " \n " ;
2023-04-03 18:20:36 -04:00
}
fileCSV . close ( ) ;
2023-03-15 19:10:17 -04:00
}
}
2023-03-27 15:48:41 -04:00
void MainWindow : : AppendComment ( ) {
//if Started ACQ, append Comment, if ACQ stopped, disbale
if ( ! chkSaveRun - > isChecked ( ) ) return ;
QDialog * dOpen = new QDialog ( this ) ;
dOpen - > setWindowTitle ( " Append Run Comment " ) ;
dOpen - > setWindowFlags ( Qt : : Dialog | Qt : : WindowTitleHint | Qt : : CustomizeWindowHint ) ;
dOpen - > setMinimumWidth ( 600 ) ;
connect ( dOpen , & QDialog : : finished , dOpen , & QDialog : : deleteLater ) ;
QGridLayout * vlayout = new QGridLayout ( dOpen ) ;
QLabel * label = new QLabel ( " Enter Append Run comment for <font style= \" color : red; \" >Run- " + runIDStr + " </font> : " , dOpen ) ;
QLineEdit * lineEdit = new QLineEdit ( dOpen ) ;
QPushButton * button1 = new QPushButton ( " OK " , dOpen ) ;
QPushButton * button2 = new QPushButton ( " Cancel " , dOpen ) ;
vlayout - > addWidget ( label , 0 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( lineEdit , 1 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( button1 , 2 , 0 ) ;
vlayout - > addWidget ( button2 , 2 , 1 ) ;
connect ( button1 , & QPushButton : : clicked , dOpen , & QDialog : : accept ) ;
connect ( button2 , & QPushButton : : clicked , dOpen , & QDialog : : reject ) ;
int result = dOpen - > exec ( ) ;
if ( result = = QDialog : : Accepted ) {
appendComment = lineEdit - > text ( ) ;
if ( appendComment = = " " ) return ;
appendComment = QDateTime : : currentDateTime ( ) . toString ( " [MM.dd hh:mm:ss] " ) + appendComment ;
AppendElog ( appendComment ) ;
leRunComment - > setText ( " Append Comment: " + appendComment ) ;
if ( influx ) {
influx - > ClearDataPointsBuffer ( ) ;
influx - > AddDataPoint ( " RunID,start=1 value= " + std : : to_string ( runID ) + " ,expName= \" " + expName . toStdString ( ) + + " \" ,comment= \" " + appendComment . replace ( ' ' , ' _ ' ) . toStdString ( ) + " \" " ) ;
influx - > WriteData ( DatabaseName . toStdString ( ) ) ;
}
} else {
return ;
}
}