2023-04-18 13:12:05 -04:00
# include "FSUDAQ.h"
2023-04-11 11:13:23 -04:00
# include <QWidget>
2023-04-14 16:12:52 -04:00
# include <QVBoxLayout>
# include <QGroupBox>
# include <QDateTime>
# include <QLabel>
# include <QScrollBar>
# include <QCoreApplication>
# include <QDialog>
# include <QFileDialog>
2023-12-12 16:17:11 -05:00
# include <QInputDialog>
2023-04-17 15:17:25 -04:00
# include <QScrollArea>
2023-05-25 14:20:55 -04:00
# include <QProcess>
# include <QMessageBox>
2023-04-11 11:13:23 -04:00
2023-11-16 19:20:29 -05:00
# include "analyzers/CoincidentAnalyzer.h"
2023-08-25 11:23:23 -04:00
# include "analyzers/SplitPoleAnalyzer.h"
# include "analyzers/EncoreAnalyzer.h"
2024-07-30 12:56:10 -04:00
# include "analyzers/MUSICAnalyzer.h"
2024-08-20 14:59:22 -04:00
# include "analyzers/NeutronGamma.h"
2024-09-30 18:38:48 -04:00
# include "analyzers/Cross.h"
2023-10-16 16:07:14 -04:00
2024-09-30 18:38:48 -04:00
std : : vector < std : : string > onlineAnalyzerList = { " Coincident " , " Splie-Pole " , " Encore " , " MUSICS " , " Neutron-Gamma " , " Cross " } ;
2023-06-12 16:32:01 -04:00
2024-06-26 16:40:40 -04:00
FSUDAQ : : FSUDAQ ( QWidget * parent ) : QMainWindow ( parent ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-11 11:13:23 -04:00
setWindowTitle ( " FSU DAQ " ) ;
2023-07-11 18:02:42 -04:00
setGeometry ( 500 , 100 , 1100 , 600 ) ;
2023-04-11 11:13:23 -04:00
2023-04-14 16:12:52 -04:00
digi = nullptr ;
nDigi = 0 ;
2024-08-28 17:58:12 -04:00
isACQStarted = false ;
2023-04-14 16:12:52 -04:00
2023-05-16 14:31:19 -04:00
scalar = nullptr ;
2023-04-18 13:12:05 -04:00
scope = nullptr ;
2023-04-24 16:37:57 -04:00
digiSettings = nullptr ;
2024-08-20 14:59:22 -04:00
singleHistograms = nullptr ;
2023-05-26 18:06:37 -04:00
onlineAnalyzer = nullptr ;
2023-07-11 18:02:42 -04:00
runTimer = new QTimer ( ) ;
breakAutoRepeat = true ;
needManualComment = true ;
runRecord = nullptr ;
model = nullptr ;
2023-08-14 11:26:52 -04:00
influx = nullptr ;
2024-04-18 10:06:55 -04:00
scalarCount = 0 ;
2023-10-19 14:29:28 -04:00
2023-04-14 16:12:52 -04:00
QWidget * mainLayoutWidget = new QWidget ( this ) ;
setCentralWidget ( mainLayoutWidget ) ;
QVBoxLayout * layoutMain = new QVBoxLayout ( mainLayoutWidget ) ;
mainLayoutWidget - > setLayout ( layoutMain ) ;
{ //^=======================
QGroupBox * box = new QGroupBox ( " Digitizer(s) " , mainLayoutWidget ) ;
layoutMain - > addWidget ( box ) ;
QGridLayout * layout = new QGridLayout ( box ) ;
2023-10-26 17:57:06 -04:00
cbOpenDigitizers = new RComboBox ( this ) ;
cbOpenDigitizers - > addItem ( " Open Digitizers ... " , 0 ) ;
2024-06-10 16:22:01 -04:00
cbOpenDigitizers - > addItem ( " Open Digitizers via Optical/USB " , 1 ) ;
2024-05-06 16:42:17 -04:00
cbOpenDigitizers - > addItem ( " Open Digitizers via A4818(s) " , 4 ) ;
2023-10-26 17:57:06 -04:00
layout - > addWidget ( cbOpenDigitizers , 0 , 0 ) ;
2024-06-26 16:40:40 -04:00
connect ( cbOpenDigitizers , & RComboBox : : currentIndexChanged , this , & FSUDAQ : : OpenDigitizers ) ;
2023-04-14 16:12:52 -04:00
2024-01-19 14:15:37 -05:00
cbOpenMethod = new RComboBox ( this ) ;
cbOpenMethod - > addItem ( " w/o settings " , 0 ) ;
cbOpenMethod - > addItem ( " w/ settings " , 1 ) ;
2024-01-24 12:58:50 -05:00
cbOpenMethod - > addItem ( " default Program " , 2 ) ;
2024-01-19 14:15:37 -05:00
layout - > addWidget ( cbOpenMethod , 1 , 0 ) ;
2023-04-17 15:17:25 -04:00
bnCloseDigitizers = new QPushButton ( " Close Digitizers " , this ) ;
2024-01-19 14:15:37 -05:00
layout - > addWidget ( bnCloseDigitizers , 2 , 0 ) ;
2024-06-26 16:40:40 -04:00
connect ( bnCloseDigitizers , & QPushButton : : clicked , this , & FSUDAQ : : CloseDigitizers ) ;
2023-04-14 16:12:52 -04:00
2023-04-17 15:17:25 -04:00
bnDigiSettings = new QPushButton ( " Digitizers Settings " , this ) ;
2023-05-24 17:10:36 -04:00
layout - > addWidget ( bnDigiSettings , 0 , 1 ) ;
2024-06-26 16:40:40 -04:00
connect ( bnDigiSettings , & QPushButton : : clicked , this , & FSUDAQ : : OpenDigiSettings ) ;
2023-04-14 16:12:52 -04:00
2023-05-24 17:10:36 -04:00
bnOpenScope = new QPushButton ( " Open Scope " , this ) ;
layout - > addWidget ( bnOpenScope , 1 , 1 ) ;
2024-06-26 16:40:40 -04:00
connect ( bnOpenScope , & QPushButton : : clicked , this , & FSUDAQ : : OpenScope ) ;
2023-05-24 17:10:36 -04:00
2023-08-28 15:02:56 -04:00
cbAnalyzer = new RComboBox ( this ) ;
layout - > addWidget ( cbAnalyzer , 0 , 2 ) ;
cbAnalyzer - > addItem ( " Choose Online Analyzer " , - 1 ) ;
2023-10-16 16:07:14 -04:00
for ( int i = 0 ; i < ( int ) onlineAnalyzerList . size ( ) ; i + + ) cbAnalyzer - > addItem ( onlineAnalyzerList [ i ] . c_str ( ) , i ) ;
2024-06-26 16:40:40 -04:00
connect ( cbAnalyzer , & RComboBox : : currentIndexChanged , this , & FSUDAQ : : OpenAnalyzer ) ;
2023-05-25 18:50:42 -04:00
2024-08-20 11:20:12 -04:00
bnCanvas = new QPushButton ( " Online Histograms " , this ) ;
2023-05-24 17:10:36 -04:00
layout - > addWidget ( bnCanvas , 1 , 2 ) ;
2024-08-20 14:59:22 -04:00
connect ( bnCanvas , & QPushButton : : clicked , this , & FSUDAQ : : OpenSingleHistograms ) ;
2023-05-17 17:40:32 -04:00
2023-06-29 18:59:36 -04:00
bnSync = new QPushButton ( " Sync Boards " , this ) ;
2024-01-19 14:15:37 -05:00
layout - > addWidget ( bnSync , 2 , 1 ) ;
2024-06-26 16:40:40 -04:00
connect ( bnSync , & QPushButton : : clicked , this , & FSUDAQ : : SetSyncMode ) ;
2023-06-27 15:47:34 -04:00
2023-04-14 16:12:52 -04:00
}
2023-05-24 17:10:36 -04:00
{ //^====================== influx and Elog
2023-05-25 14:20:55 -04:00
QGroupBox * otherBox = new QGroupBox ( " Database and Elog " , mainLayoutWidget ) ;
2023-05-24 17:10:36 -04:00
layoutMain - > addWidget ( otherBox ) ;
QGridLayout * layout = new QGridLayout ( otherBox ) ;
2023-05-25 14:20:55 -04:00
layout - > setVerticalSpacing ( 1 ) ;
2023-05-24 17:10:36 -04:00
2023-05-25 14:20:55 -04:00
int rowID = 0 ;
bnLock = new QPushButton ( " Unlock " , this ) ;
bnLock - > setChecked ( true ) ;
layout - > addWidget ( bnLock , rowID , 0 ) ;
2023-05-24 17:10:36 -04:00
QLabel * lbInfluxIP = new QLabel ( " Influx IP : " , this ) ;
lbInfluxIP - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2023-05-25 14:20:55 -04:00
layout - > addWidget ( lbInfluxIP , rowID , 1 ) ;
2023-05-24 17:10:36 -04:00
leInfluxIP = new QLineEdit ( this ) ;
leInfluxIP - > setReadOnly ( true ) ;
2023-05-25 14:20:55 -04:00
layout - > addWidget ( leInfluxIP , rowID , 2 ) ;
2023-05-24 17:10:36 -04:00
QLabel * lbDatabaseName = new QLabel ( " Database Name : " , this ) ;
lbDatabaseName - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2023-05-25 14:20:55 -04:00
layout - > addWidget ( lbDatabaseName , rowID , 3 ) ;
2023-05-24 17:10:36 -04:00
leDatabaseName = new QLineEdit ( this ) ;
leDatabaseName - > setReadOnly ( true ) ;
2023-05-25 14:20:55 -04:00
layout - > addWidget ( leDatabaseName , rowID , 4 ) ;
2024-06-27 17:27:28 -04:00
chkInflux = new QCheckBox ( " Enable " , this ) ;
2024-08-13 12:45:24 -04:00
chkInflux - > setChecked ( true ) ;
2024-06-27 17:27:28 -04:00
layout - > addWidget ( chkInflux , rowID , 5 ) ;
2024-03-01 19:18:23 -05:00
2023-05-25 14:20:55 -04:00
rowID + + ;
2023-05-24 17:10:36 -04:00
QLabel * lbElogIP = new QLabel ( " Elog IP : " , this ) ;
lbElogIP - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2023-05-25 14:20:55 -04:00
layout - > addWidget ( lbElogIP , rowID , 1 ) ;
2023-05-24 17:10:36 -04:00
leElogIP = new QLineEdit ( this ) ;
leElogIP - > setReadOnly ( true ) ;
2023-05-25 14:20:55 -04:00
layout - > addWidget ( leElogIP , rowID , 2 ) ;
2023-05-24 17:10:36 -04:00
2023-05-25 14:20:55 -04:00
QLabel * lbElogName = new QLabel ( " Elog Name : " , this ) ;
lbElogName - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
layout - > addWidget ( lbElogName , rowID , 3 ) ;
leElogName = new QLineEdit ( this ) ;
leElogName - > setReadOnly ( true ) ;
layout - > addWidget ( leElogName , rowID , 4 ) ;
2023-05-24 17:10:36 -04:00
2024-06-27 17:27:28 -04:00
chkElog = new QCheckBox ( " Enable " , this ) ;
2024-08-13 12:45:24 -04:00
chkElog - > setChecked ( true ) ;
2024-06-27 17:27:28 -04:00
layout - > addWidget ( chkElog , rowID , 5 ) ;
2024-06-26 16:40:40 -04:00
connect ( bnLock , & QPushButton : : clicked , this , & FSUDAQ : : SetAndLockInfluxElog ) ;
2023-05-24 17:10:36 -04:00
}
2023-04-14 16:12:52 -04:00
{ //^====================== ACQ control
QGroupBox * box = new QGroupBox ( " ACQ Control " , mainLayoutWidget ) ;
layoutMain - > addWidget ( box ) ;
QGridLayout * layout = new QGridLayout ( box ) ;
int rowID = 0 ;
2023-04-18 13:12:05 -04:00
//------------------------------------------
2023-04-14 16:12:52 -04:00
QLabel * lbDataPath = new QLabel ( " Data Path : " , this ) ;
lbDataPath - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
leDataPath = new QLineEdit ( this ) ;
2023-04-17 15:17:25 -04:00
leDataPath - > setReadOnly ( true ) ;
2023-04-14 16:12:52 -04:00
QPushButton * bnSetDataPath = new QPushButton ( " Set Path " , this ) ;
2024-06-26 16:40:40 -04:00
connect ( bnSetDataPath , & QPushButton : : clicked , this , & FSUDAQ : : OpenDataPath ) ;
2023-04-14 16:12:52 -04:00
2023-07-11 18:02:42 -04:00
QPushButton * bnOpenRecord = new QPushButton ( " Open Record " , this ) ;
2024-06-26 16:40:40 -04:00
connect ( bnOpenRecord , & QPushButton : : clicked , this , & FSUDAQ : : OpenRecord ) ;
2023-07-11 18:02:42 -04:00
2023-04-14 16:12:52 -04:00
layout - > addWidget ( lbDataPath , rowID , 0 ) ;
2023-07-11 18:02:42 -04:00
layout - > addWidget ( leDataPath , rowID , 1 , 1 , 5 ) ;
layout - > addWidget ( bnSetDataPath , rowID , 6 ) ;
layout - > addWidget ( bnOpenRecord , rowID , 7 ) ;
2023-04-14 16:12:52 -04:00
2023-04-18 13:12:05 -04:00
//------------------------------------------
2023-04-14 16:12:52 -04:00
rowID + + ;
QLabel * lbPrefix = new QLabel ( " Prefix : " , this ) ;
lbPrefix - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
lePrefix = new QLineEdit ( this ) ;
2023-04-18 13:12:05 -04:00
lePrefix - > setAlignment ( Qt : : AlignHCenter ) ;
2023-09-06 15:05:27 -04:00
connect ( lePrefix , & QLineEdit : : textChanged , this , [ = ] ( ) {
lePrefix - > setStyleSheet ( " color:blue; " ) ;
} ) ;
2024-06-26 16:40:40 -04:00
connect ( lePrefix , & QLineEdit : : returnPressed , this , & FSUDAQ : : SaveLastRunFile ) ;
2023-04-14 16:12:52 -04:00
QLabel * lbRunID = new QLabel ( " Run No. : " , this ) ;
lbRunID - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
2023-04-17 14:09:21 -04:00
leRunID = new QLineEdit ( this ) ;
2023-04-17 15:17:25 -04:00
leRunID - > setReadOnly ( true ) ;
2023-04-18 13:12:05 -04:00
leRunID - > setAlignment ( Qt : : AlignHCenter ) ;
2023-04-14 16:12:52 -04:00
2023-04-18 13:12:05 -04:00
chkSaveData = new QCheckBox ( " Save Data " , this ) ;
2023-07-11 18:02:42 -04:00
connect ( chkSaveData , & QCheckBox : : stateChanged , this , [ = ] ( int state ) {
cbAutoRun - > setEnabled ( state ) ;
if ( state = = 0 ) cbAutoRun - > setCurrentIndex ( 0 ) ;
} ) ;
2023-05-18 17:14:24 -04:00
cbAutoRun = new RComboBox ( this ) ;
2023-04-18 13:12:05 -04:00
cbAutoRun - > addItem ( " Single Infinite " , 0 ) ;
2023-07-11 18:02:42 -04:00
cbAutoRun - > addItem ( " Single 1 min " , 1 ) ;
2023-04-18 13:12:05 -04:00
cbAutoRun - > addItem ( " Single 30 mins " , 30 ) ;
cbAutoRun - > addItem ( " Single 60 mins " , 60 ) ;
2023-08-24 13:27:16 -04:00
cbAutoRun - > addItem ( " Single 120 mins " , 120 ) ;
2023-07-11 18:02:42 -04:00
cbAutoRun - > addItem ( " Repeat 1 mins " , - 1 ) ;
2023-04-18 13:12:05 -04:00
cbAutoRun - > addItem ( " Repeat 60 mins " , - 60 ) ;
2023-06-30 17:32:09 -04:00
cbAutoRun - > addItem ( " Repeat 120 mins " , - 120 ) ;
2023-04-18 13:12:05 -04:00
cbAutoRun - > setEnabled ( false ) ;
bnStartACQ = new QPushButton ( " Start ACQ " , this ) ;
2024-06-26 16:40:40 -04:00
connect ( bnStartACQ , & QPushButton : : clicked , this , & FSUDAQ : : AutoRun ) ;
2023-04-18 13:12:05 -04:00
bnStopACQ = new QPushButton ( " Stop ACQ " , this ) ;
2023-07-11 18:02:42 -04:00
connect ( bnStopACQ , & QPushButton : : clicked , this , [ = ] ( ) {
2023-10-19 14:29:28 -04:00
if ( runTimer - > isActive ( ) ) {
runTimer - > stop ( ) ;
runTimer - > disconnect ( runTimerConnection ) ;
} else {
breakAutoRepeat = true ;
runTimer - > disconnect ( runTimerConnection ) ;
}
needManualComment = true ;
StopACQ ( ) ;
2023-10-19 15:32:44 -04:00
} ) ;
2023-04-11 11:50:52 -04:00
2023-04-14 16:12:52 -04:00
layout - > addWidget ( lbPrefix , rowID , 0 ) ;
layout - > addWidget ( lePrefix , rowID , 1 ) ;
layout - > addWidget ( lbRunID , rowID , 2 ) ;
layout - > addWidget ( leRunID , rowID , 3 ) ;
2023-04-18 13:12:05 -04:00
layout - > addWidget ( chkSaveData , rowID , 4 ) ;
layout - > addWidget ( cbAutoRun , rowID , 5 ) ;
layout - > addWidget ( bnStartACQ , rowID , 6 ) ;
layout - > addWidget ( bnStopACQ , rowID , 7 ) ;
2023-04-14 16:12:52 -04:00
2023-04-18 13:12:05 -04:00
//------------------------------------------
2023-04-14 16:12:52 -04:00
rowID + + ;
QLabel * lbComment = new QLabel ( " Run Comment : " , this ) ;
lbComment - > setAlignment ( Qt : : AlignRight | Qt : : AlignCenter ) ;
leComment = new QLineEdit ( this ) ;
2023-05-17 16:16:48 -04:00
leComment - > setReadOnly ( true ) ;
2023-04-14 16:12:52 -04:00
2023-04-18 13:12:05 -04:00
bnOpenScaler = new QPushButton ( " Scalar " , this ) ;
2024-06-26 16:40:40 -04:00
connect ( bnOpenScaler , & QPushButton : : clicked , this , & FSUDAQ : : OpenScalar ) ;
2023-04-14 16:12:52 -04:00
layout - > addWidget ( lbComment , rowID , 0 ) ;
2023-04-18 13:12:05 -04:00
layout - > addWidget ( leComment , rowID , 1 , 1 , 6 ) ;
layout - > addWidget ( bnOpenScaler , rowID , 7 ) ;
2023-04-14 16:12:52 -04:00
layout - > setColumnStretch ( 0 , 1 ) ;
layout - > setColumnStretch ( 1 , 2 ) ;
layout - > setColumnStretch ( 2 , 1 ) ;
2023-04-18 13:12:05 -04:00
layout - > setColumnStretch ( 3 , 1 ) ;
layout - > setColumnStretch ( 4 , 1 ) ;
layout - > setColumnStretch ( 5 , 1 ) ;
layout - > setColumnStretch ( 6 , 3 ) ;
layout - > setColumnStretch ( 7 , 3 ) ;
2023-04-14 16:12:52 -04:00
}
{ //^===================== Log Msg
logMsgHTMLMode = true ;
QGroupBox * box3 = new QGroupBox ( " Log Message " , mainLayoutWidget ) ;
layoutMain - > addWidget ( box3 ) ;
layoutMain - > setStretchFactor ( box3 , 1 ) ;
QVBoxLayout * layout3 = new QVBoxLayout ( box3 ) ;
logInfo = new QPlainTextEdit ( this ) ;
2023-05-24 17:10:36 -04:00
logInfo - > setReadOnly ( true ) ;
2023-04-14 16:12:52 -04:00
QFont font ;
font . setFamily ( " Courier New " ) ;
logInfo - > setFont ( font ) ;
layout3 - > addWidget ( logInfo ) ;
}
LogMsg ( " <font style= \" color: blue; \" ><b>Welcome to FSU DAQ.</b></font> " ) ;
2023-04-11 11:13:23 -04:00
2023-04-17 14:09:21 -04:00
rawDataPath = " " ;
prefix = " temp " ;
runID = 0 ;
elogID = 0 ;
2023-05-25 14:20:55 -04:00
elogName = " " ;
elogUser = " " ;
elogPWD = " " ;
influxIP = " " ;
dataBaseName = " " ;
2024-03-01 19:18:23 -05:00
influxToken = " " ;
2023-04-17 14:09:21 -04:00
programSettingsFilePath = QDir : : current ( ) . absolutePath ( ) + " /programSettings.txt " ;
LoadProgramSettings ( ) ;
2023-04-19 13:41:43 -04:00
//=========== disable widget
WaitForDigitizersOpen ( true ) ;
2023-05-24 17:10:36 -04:00
SetUpInflux ( ) ;
2023-05-24 16:04:32 -04:00
2023-05-25 14:20:55 -04:00
CheckElog ( ) ;
2024-05-17 17:45:30 -04:00
LogMsg ( " ====== <font style= \" color: blue; \" ><b>FSU DAQ is ready.</b></font> ====== " ) ;
2023-04-11 11:13:23 -04:00
}
2024-06-26 16:40:40 -04:00
FSUDAQ : : ~ FSUDAQ ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-10-12 16:27:56 -04:00
if ( scalar ) {
2024-09-04 17:50:59 -04:00
scalarTimingThread - > Stop ( ) ;
scalarTimingThread - > quit ( ) ;
scalarTimingThread - > exit ( ) ;
// scalarTimer->stop();
// if( scalarThread->isRunning() ){
// scalarThread->quit();
// scalarThread->exit();
// }
2023-10-12 16:27:56 -04:00
CleanUpScalar ( ) ;
2023-10-13 18:02:19 -04:00
//don't need to delete scalar, it is managed by this
2023-10-12 16:27:56 -04:00
}
2023-04-14 16:12:52 -04:00
if ( digi ) CloseDigitizers ( ) ;
2023-04-17 14:09:21 -04:00
SaveProgramSettings ( ) ;
2023-04-18 13:12:05 -04:00
if ( scope ) delete scope ;
2023-04-19 16:21:14 -04:00
2024-08-20 14:59:22 -04:00
if ( singleHistograms ) delete singleHistograms ;
2023-05-17 17:40:32 -04:00
2023-05-26 18:06:37 -04:00
if ( onlineAnalyzer ) delete onlineAnalyzer ;
2023-06-01 17:51:00 -04:00
if ( digiSettings ) delete digiSettings ;
2023-04-18 13:12:05 -04:00
2023-05-24 16:04:32 -04:00
delete influx ;
2023-08-17 12:50:45 -04:00
printf ( " -------- remove %s \n " , DAQLockFile ) ;
remove ( DAQLockFile ) ;
2023-04-17 14:09:21 -04:00
}
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenDataPath ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-17 15:17:25 -04:00
QFileDialog fileDialog ( this ) ;
fileDialog . setFileMode ( QFileDialog : : Directory ) ;
int result = fileDialog . exec ( ) ;
//qDebug() << fileDialog.selectedFiles();
if ( result > 0 ) {
leDataPath - > setText ( fileDialog . selectedFiles ( ) . at ( 0 ) ) ;
2023-05-25 14:20:55 -04:00
rawDataPath = leDataPath - > text ( ) ;
2023-04-17 15:17:25 -04:00
} else {
leDataPath - > clear ( ) ;
2023-05-25 14:20:55 -04:00
rawDataPath = " " ;
2023-04-17 15:17:25 -04:00
}
2024-02-23 18:31:39 -05:00
if ( ! rawDataPath . isEmpty ( ) ) chkSaveData - > setEnabled ( true ) ;
2023-05-24 17:10:36 -04:00
SaveProgramSettings ( ) ;
2023-10-19 14:29:28 -04:00
LoadLastRunFile ( ) ;
2023-08-14 11:26:52 -04:00
2023-04-17 15:17:25 -04:00
}
2023-04-17 14:09:21 -04:00
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenRecord ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-07-11 18:02:42 -04:00
QString filePath = leDataPath - > text ( ) + " /RunTimeStamp.dat " ;
if ( runRecord = = nullptr ) {
runRecord = new QMainWindow ( this ) ;
runRecord - > setGeometry ( 0 , 0 , 500 , 500 ) ;
runRecord - > setWindowTitle ( " Run Record " ) ;
QWidget * widget = new QWidget ( runRecord ) ;
runRecord - > setCentralWidget ( widget ) ;
QVBoxLayout * layout = new QVBoxLayout ( widget ) ;
widget - > setLayout ( layout ) ;
QLabel * lbFilePath = new QLabel ( widget ) ;
lbFilePath - > setText ( filePath ) ;
layout - > addWidget ( lbFilePath ) ;
tableView = new QTableView ( widget ) ;
layout - > addWidget ( tableView ) ;
model = new QStandardItemModel ( runRecord ) ;
tableView - > setModel ( model ) ;
}
UpdateRecord ( ) ;
runRecord - > show ( ) ;
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : UpdateRecord ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-07-11 18:02:42 -04:00
if ( ! runRecord ) return ;
QString filePath = leDataPath - > text ( ) + " /RunTimeStamp.dat " ;
model - > clear ( ) ;
if ( ! filePath . isEmpty ( ) ) {
QFile file ( filePath ) ;
if ( file . open ( QIODevice : : ReadOnly | QIODevice : : Text ) ) {
QTextStream stream ( & file ) ;
while ( ! stream . atEnd ( ) ) {
QString line = stream . readLine ( ) ;
QStringList fields = line . split ( ' | ' ) ;
QList < QStandardItem * > items ;
for ( const QString & field : fields ) {
items . append ( new QStandardItem ( field ) ) ;
}
model - > appendRow ( items ) ;
}
file . close ( ) ;
tableView - > resizeColumnsToContents ( ) ;
}
}
tableView - > scrollToBottom ( ) ;
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : LoadProgramSettings ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-17 14:09:21 -04:00
LogMsg ( " Loading <b> " + programSettingsFilePath + " </b> for Program Settings. " ) ;
QFile file ( programSettingsFilePath ) ;
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
LogMsg ( " <b> " + programSettingsFilePath + " </b> not found. " ) ;
} else {
QTextStream in ( & file ) ;
QString line = in . readLine ( ) ;
int count = 0 ;
while ( ! line . isNull ( ) ) {
if ( line . left ( 6 ) = = " //---- " ) break ;
if ( count = = 0 ) rawDataPath = line ;
2023-05-24 17:10:36 -04:00
if ( count = = 1 ) influxIP = line ;
if ( count = = 2 ) dataBaseName = line ;
2024-03-01 19:18:23 -05:00
if ( count = = 3 ) influxToken = line ;
if ( count = = 4 ) elogIP = line ;
2024-10-18 16:30:21 -04:00
if ( count = = 5 ) elogPort = line ;
if ( count = = 6 ) elogName = line ;
if ( count = = 7 ) elogUser = line ;
if ( count = = 8 ) elogPWD = line ;
2023-05-24 17:10:36 -04:00
2023-04-17 14:09:21 -04:00
count + + ;
line = in . readLine ( ) ;
}
//looking for the lastRun.sh for
leDataPath - > setText ( rawDataPath ) ;
2023-05-24 17:10:36 -04:00
leInfluxIP - > setText ( influxIP ) ;
leDatabaseName - > setText ( dataBaseName ) ;
leElogIP - > setText ( elogIP ) ;
2023-05-25 14:20:55 -04:00
leElogName - > setText ( elogName ) ;
logMsgHTMLMode = false ;
2024-03-01 19:18:23 -05:00
LogMsg ( " Raw Data Path : " + rawDataPath ) ;
LogMsg ( " Influx IP : " + influxIP ) ;
LogMsg ( " Database Name : " + dataBaseName ) ;
2024-09-09 14:22:21 -04:00
LogMsg ( " Database Token : " + maskText ( influxToken ) ) ;
2024-03-01 19:18:23 -05:00
LogMsg ( " Elog IP : " + elogIP ) ;
2024-10-18 16:30:21 -04:00
LogMsg ( " Elog Port : " + elogPort ) ;
2024-03-01 19:18:23 -05:00
LogMsg ( " Elog Name : " + elogName ) ;
2024-09-09 14:22:21 -04:00
LogMsg ( " Elog User : " + maskText ( elogUser ) ) ;
LogMsg ( " Elog PWD : " + maskText ( elogPWD ) ) ;
2023-05-25 14:20:55 -04:00
logMsgHTMLMode = true ;
2023-04-18 13:12:05 -04:00
//check is rawDataPath exist, if not, create one
QDir rawDataDir ;
if ( ! rawDataDir . exists ( rawDataPath ) ) {
if ( rawDataDir . mkdir ( rawDataPath ) ) {
LogMsg ( " Created folder <b> " + rawDataPath + " </b> for storing root files. " ) ;
} else {
2024-02-23 18:31:39 -05:00
LogMsg ( " <font style= \" color:red; \" ><b> " + rawDataPath + " </b> Raw data folder cannot be created. Access right problem? </font> " ) ;
2023-04-18 13:12:05 -04:00
}
} else {
LogMsg ( " <b> " + rawDataPath + " </b> already exist. " ) ;
}
2023-04-17 14:09:21 -04:00
LoadLastRunFile ( ) ;
}
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : SaveProgramSettings ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-17 14:09:21 -04:00
rawDataPath = leDataPath - > text ( ) ;
QFile file ( programSettingsFilePath ) ;
file . open ( QIODevice : : Text | QIODevice : : WriteOnly ) ;
file . write ( ( rawDataPath + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-05-24 17:10:36 -04:00
file . write ( ( influxIP + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( dataBaseName + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-03-01 19:18:23 -05:00
file . write ( ( influxToken + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-05-24 17:10:36 -04:00
file . write ( ( elogIP + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2024-10-18 16:30:21 -04:00
file . write ( ( elogPort + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-05-25 14:20:55 -04:00
file . write ( ( elogName + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( elogUser + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( elogPWD + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-05-24 17:10:36 -04:00
file . write ( " //------------end of file. \n " ) ;
2023-04-17 14:09:21 -04:00
file . close ( ) ;
LogMsg ( " Saved program settings to <b> " + programSettingsFilePath + " <b>. " ) ;
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : LoadLastRunFile ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-17 14:09:21 -04:00
QFile file ( rawDataPath + " /lastRun.sh " ) ;
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
LogMsg ( " <b> " + rawDataPath + " /lastRun.sh</b> not found. " ) ;
runID = 0 ;
prefix = " temp " ;
leRunID - > setText ( QString : : number ( runID ) ) ;
lePrefix - > setText ( prefix ) ;
} else {
QTextStream in ( & file ) ;
QString line = in . readLine ( ) ;
int count = 0 ;
while ( ! line . isNull ( ) ) {
int index = line . indexOf ( " = " ) ;
QString haha = line . mid ( index + 1 ) . remove ( " " ) ;
//qDebug() << haha;
switch ( count ) {
case 0 : prefix = haha ; break ;
case 1 : runID = haha . toInt ( ) ; break ;
case 2 : elogID = haha . toInt ( ) ; break ;
}
count + + ;
line = in . readLine ( ) ;
}
lePrefix - > setText ( prefix ) ;
2023-09-06 15:05:27 -04:00
lePrefix - > setStyleSheet ( " " ) ;
2023-04-17 14:09:21 -04:00
leRunID - > setText ( QString : : number ( runID ) ) ;
}
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : SaveLastRunFile ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-17 14:09:21 -04:00
QFile file ( rawDataPath + " /lastRun.sh " ) ;
2023-09-06 15:05:27 -04:00
prefix = lePrefix - > text ( ) ;
lePrefix - > setStyleSheet ( " " ) ;
2023-04-17 14:09:21 -04:00
2023-09-06 15:05:27 -04:00
file . open ( QIODevice : : Text | QIODevice : : WriteOnly ) ;
2023-04-17 14:09:21 -04:00
file . write ( ( " prefix= " + prefix + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( " runID= " + QString : : number ( runID ) + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( ( " elogID= " + QString : : number ( elogID ) + " \n " ) . toStdString ( ) . c_str ( ) ) ;
file . write ( " //------------end of file. " ) ;
file . close ( ) ;
LogMsg ( " Saved program settings to <b> " + rawDataPath + " /lastRun.sh<b>. " ) ;
2023-04-14 16:12:52 -04:00
}
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenDigitizers ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-10-26 17:57:06 -04:00
if ( cbOpenDigitizers - > currentIndex ( ) = = 0 ) return ;
2023-12-15 16:47:11 -05:00
// placeholder for USB
// if( cbOpenDigitizers->currentData().toInt() == 3 ) {
// return;
// }
2024-05-06 16:42:17 -04:00
QStringList a4818PIDs ;
2023-12-15 16:47:11 -05:00
if ( cbOpenDigitizers - > currentData ( ) . toInt ( ) = = 4 ) {
2024-05-06 16:42:17 -04:00
QString a4818Path = QDir : : current ( ) . absolutePath ( ) + " /a4818_list.txt " ;
LogMsg ( " Looking <b> " + a4818Path + " </b> " ) ;
QFile file ( a4818Path ) ;
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
LogMsg ( " <b> " + a4818Path + " </b> not found. " ) ;
LogMsg ( " Please create such file and put the a4818 PIDs inseperate lines. " ) ;
2024-06-11 16:15:50 -04:00
cbOpenDigitizers - > setCurrentIndex ( 0 ) ;
2024-05-06 16:42:17 -04:00
return ;
} else {
QTextStream in ( & file ) ;
QString line = in . readLine ( ) ;
while ( ! line . isNull ( ) ) {
a4818PIDs . push_back ( line ) ;
line = in . readLine ( ) ;
}
}
2023-12-15 16:47:11 -05:00
2024-05-06 16:42:17 -04:00
if ( a4818PIDs . isEmpty ( ) ) {
LogMsg ( " <b> " + a4818Path + " </b> is empty. " ) ;
2023-12-15 16:47:11 -05:00
cbOpenDigitizers - > setCurrentIndex ( 0 ) ;
return ;
2024-05-06 16:42:17 -04:00
} else {
2024-06-11 16:15:50 -04:00
if ( a4818PIDs . size ( ) > MaxNPorts ) {
LogMsg ( " There are more than " + QString : : number ( MaxNPorts ) + " a4818, please edit the MaxNPorts in macro.h and recompile. " ) ;
2024-05-06 16:42:17 -04:00
}
2023-12-15 16:47:11 -05:00
}
}
if ( cbOpenDigitizers - > currentData ( ) . toInt ( ) = = 4 ) {
LogMsg ( " Searching digitizers via A4818 .....Please wait " ) ;
} else {
LogMsg ( " Searching digitizers via optical link or USB .....Please wait " ) ;
}
2024-01-19 14:15:37 -05:00
2023-04-14 16:12:52 -04:00
logMsgHTMLMode = false ;
nDigi = 0 ;
std : : vector < std : : pair < int , int > > portList ; //boardID, portID
2024-05-06 16:42:17 -04:00
if ( cbOpenDigitizers - > currentData ( ) . toInt ( ) = = 4 ) { //for A4818
for ( int i = 0 ; i < std : : min ( ( int ) a4818PIDs . size ( ) , MaxNPorts ) ; i + + ) {
int port = a4818PIDs . at ( i ) . toInt ( ) ;
for ( int board = 0 ; board < MaxNBoards ; board + + ) { /// max number of diasy chain
Digitizer dig ;
dig . OpenDigitizer ( board , port ) ;
if ( dig . IsConnected ( ) ) {
nDigi + + ;
portList . push_back ( std : : pair ( board , port ) ) ;
LogMsg ( QString ( " ... Found at port: %1, board: %2. SN: %3 %4 " ) . arg ( port ) . arg ( board ) . arg ( dig . GetSerialNumber ( ) , 3 , 10 , QChar ( ' ' ) ) . arg ( dig . GetDPPString ( ) . c_str ( ) ) ) ;
}
dig . CloseDigitizer ( ) ;
QCoreApplication : : processEvents ( ) ; //to prevent Qt said application not responding.
}
}
} else { // optical fiber
for ( int port = 0 ; port < MaxNPorts ; port + + ) {
for ( int board = 0 ; board < MaxNBoards ; board + + ) { /// max number of diasy chain
Digitizer dig ;
dig . OpenDigitizer ( board , port ) ;
if ( dig . IsConnected ( ) ) {
nDigi + + ;
portList . push_back ( std : : pair ( board , port ) ) ;
LogMsg ( QString ( " ... Found at port: %1, board: %2. SN: %3 %4 " ) . arg ( port ) . arg ( board ) . arg ( dig . GetSerialNumber ( ) , 3 , 10 , QChar ( ' ' ) ) . arg ( dig . GetDPPString ( ) . c_str ( ) ) ) ;
}
dig . CloseDigitizer ( ) ;
QCoreApplication : : processEvents ( ) ; //to prevent Qt said application not responding.
}
2023-04-14 16:12:52 -04:00
}
}
logMsgHTMLMode = true ;
2023-05-03 17:53:35 -04:00
if ( nDigi = = 0 ) {
2023-12-15 16:47:11 -05:00
LogMsg ( QString ( " Done seraching. No digitizer found from port 0 to " ) + QString : : number ( MaxNPorts ) + " and board 0 to " + QString : : number ( MaxNBoards ) + " . " ) ;
cbOpenDigitizers - > setCurrentIndex ( 0 ) ;
2023-05-03 17:53:35 -04:00
return ;
} else {
2024-01-19 14:15:37 -05:00
if ( cbOpenMethod - > currentData ( ) . toInt ( ) = = 0 ) LogMsg ( QString ( " Done seraching. Found %1 digitizer(s). Opening digitizer(s).... " ) . arg ( nDigi ) ) ;
if ( cbOpenMethod - > currentData ( ) . toInt ( ) = = 1 ) LogMsg ( QString ( " Done seraching. Found %1 digitizer(s). Opening digitizer(s) and program default.... " ) . arg ( nDigi ) ) ;
if ( cbOpenMethod - > currentData ( ) . toInt ( ) = = 2 ) LogMsg ( QString ( " Done seraching. Found %1 digitizer(s). Opening digitizer(s) and load settings.... " ) . arg ( nDigi ) ) ;
2023-05-03 17:53:35 -04:00
}
2023-04-14 16:12:52 -04:00
digi = new Digitizer * [ nDigi ] ;
readDataThread = new ReadDataThread * [ nDigi ] ;
2023-10-26 17:57:06 -04:00
2023-04-14 16:12:52 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
digi [ i ] = new Digitizer ( portList [ i ] . first , portList [ i ] . second ) ;
2023-05-12 16:06:32 -04:00
//digi[i]->Reset();
2023-05-02 15:43:05 -04:00
2024-01-24 12:58:50 -05:00
if ( cbOpenMethod - > currentData ( ) . toInt ( ) = = 2 ) {
2024-01-18 23:09:50 -05:00
digi [ i ] - > ProgramBoard ( ) ;
}
2023-05-09 12:16:08 -04:00
2024-01-18 23:09:50 -05:00
///============== load settings
2024-01-24 12:58:50 -05:00
if ( cbOpenMethod - > currentData ( ) . toInt ( ) < = 1 ) {
2024-01-18 23:09:50 -05:00
QString fileName = rawDataPath + " /Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " _ " + QString : : fromStdString ( digi [ i ] - > GetData ( ) - > DPPTypeStr ) + " .bin " ;
QFile file ( fileName ) ;
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
if ( digi [ i ] - > GetDPPType ( ) = = V1730_DPP_PHA_CODE ) {
//digi[i]->ProgramBoard_PHA();
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PHA settings.");
LogMsg ( " <b> " + fileName + " </b> not found. " ) ;
}
if ( digi [ i ] - > GetDPPType ( ) = = V1730_DPP_PSD_CODE ) {
//digi[i]->ProgramBoard_PSD();
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
LogMsg ( " <b> " + fileName + " </b> not found. " ) ;
}
if ( digi [ i ] - > GetDPPType ( ) = = V1740_DPP_QDC_CODE ) {
//digi[i]->ProgramBoard_QDC();
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
LogMsg ( " <b> " + fileName + " </b> not found. " ) ;
}
} else {
LogMsg ( " Found <b> " + fileName + " </b> for digitizer settings. " ) ;
2024-01-24 12:58:50 -05:00
if ( cbOpenMethod - > currentData ( ) . toInt ( ) = = 1 ) {
if ( digi [ i ] - > LoadSettingBinaryToMemory ( fileName . toStdString ( ) . c_str ( ) ) = = 0 ) {
LogMsg ( " Loaded settings file <b> " + fileName + " </b> for Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ) ;
digi [ i ] - > ProgramSettingsToBoard ( ) ;
} else {
LogMsg ( " Fail to Loaded settings file " + fileName + " for Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ) ;
}
2023-10-26 17:57:06 -04:00
} else {
2024-01-24 12:58:50 -05:00
LogMsg ( " Save the setting file path, but not load. " ) ;
digi [ i ] - > SetSettingBinaryPath ( fileName . toStdString ( ) ) ;
2023-10-26 17:57:06 -04:00
}
2024-01-24 12:58:50 -05:00
2023-10-26 17:57:06 -04:00
}
2023-05-02 15:43:05 -04:00
}
2023-05-12 16:06:32 -04:00
digi [ i ] - > ReadAllSettingsFromBoard ( true ) ;
2023-05-02 15:43:05 -04:00
2024-09-30 18:38:48 -04:00
//===== set no trace, even when FSQDAQ segfault at scope, the digitizer will save no trace
digi [ i ] - > SetTrace ( false ) ;
// if( digi[i]->GetDPPType() == V1730_DPP_PHA_CODE) digi[i]->WriteRegister(DPP::BoardConfiguration, 0xE8915);
2023-04-14 16:12:52 -04:00
readDataThread [ i ] = new ReadDataThread ( digi [ i ] , i ) ;
2024-06-26 16:40:40 -04:00
connect ( readDataThread [ i ] , & ReadDataThread : : sendMsg , this , & FSUDAQ : : LogMsg ) ;
2023-05-03 17:53:35 -04:00
QCoreApplication : : processEvents ( ) ; //to prevent Qt said application not responding.
2023-04-14 16:12:52 -04:00
}
2024-08-20 14:59:22 -04:00
singleHistograms = new SingleSpectra ( digi , nDigi , rawDataPath ) ;
2023-05-19 16:23:04 -04:00
2024-05-17 17:45:30 -04:00
LogMsg ( " ====== <font style= \" color: blue; \" ><b> " + QString ( " Done. Opened %1 digitizer(s). " ) . arg ( nDigi ) + " </b></font> ===== " ) ;
2023-04-14 16:12:52 -04:00
2023-04-19 13:41:43 -04:00
WaitForDigitizersOpen ( false ) ;
2023-06-23 13:50:21 -04:00
bnStartACQ - > setStyleSheet ( " background-color: green; " ) ;
2023-05-12 16:06:32 -04:00
bnStopACQ - > setEnabled ( false ) ;
2023-06-23 13:50:21 -04:00
bnStopACQ - > setStyleSheet ( " " ) ;
2023-04-19 13:41:43 -04:00
2023-06-29 18:59:36 -04:00
bnSync - > setEnabled ( nDigi > = 1 ) ;
2023-06-01 17:51:00 -04:00
if ( rawDataPath = = " " ) {
chkSaveData - > setChecked ( false ) ;
chkSaveData - > setEnabled ( false ) ;
}
2023-05-25 14:20:55 -04:00
2023-04-17 15:17:25 -04:00
SetupScalar ( ) ;
2023-10-26 17:57:06 -04:00
cbOpenDigitizers - > setCurrentIndex ( 0 ) ;
}
2023-04-14 16:12:52 -04:00
2024-06-26 16:40:40 -04:00
void FSUDAQ : : CloseDigitizers ( ) {
LogMsg ( " FSUDAQ::Closing Digitizer(s).... " ) ;
2023-04-14 16:12:52 -04:00
2023-04-24 16:37:57 -04:00
if ( scope ) {
scope - > close ( ) ;
delete scope ;
scope = nullptr ;
}
2024-09-04 17:50:59 -04:00
// scalarTimer->stop();
// if( scalarThread->isRunning() ){
// scalarThread->quit();
// scalarThread->exit();
// }
scalarTimingThread - > Stop ( ) ;
if ( scalarTimingThread - > isRunning ( ) ) {
scalarTimingThread - > quit ( ) ;
scalarTimingThread - > exit ( ) ;
2024-08-28 17:22:41 -04:00
}
if ( scalar ) CleanUpScalar ( ) ;
2023-11-17 11:44:28 -05:00
2023-11-21 16:50:22 -05:00
if ( onlineAnalyzer ) {
onlineAnalyzer - > close ( ) ;
delete onlineAnalyzer ;
onlineAnalyzer = nullptr ;
}
2024-08-20 14:59:22 -04:00
if ( singleHistograms ) {
singleHistograms - > close ( ) ;
delete singleHistograms ;
singleHistograms = nullptr ;
2023-06-01 17:51:00 -04:00
}
2023-04-24 16:37:57 -04:00
if ( digiSettings ) {
digiSettings - > close ( ) ;
delete digiSettings ;
digiSettings = nullptr ;
}
2023-04-18 13:12:05 -04:00
if ( digi = = nullptr ) return ;
2023-04-14 16:12:52 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2023-10-12 16:27:56 -04:00
readDataThread [ i ] - > Stop ( ) ;
readDataThread [ i ] - > quit ( ) ;
readDataThread [ i ] - > wait ( ) ;
2023-04-14 16:12:52 -04:00
delete readDataThread [ i ] ;
2023-10-12 16:27:56 -04:00
printf ( " readDataThread[%d] is deleted. \n " , i ) ;
2023-04-14 16:12:52 -04:00
}
delete [ ] readDataThread ;
readDataThread = nullptr ;
2023-10-12 16:27:56 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2024-03-20 15:35:48 -04:00
digi [ i ] - > StopACQ ( ) ;
2023-10-12 16:27:56 -04:00
digi [ i ] - > CloseDigitizer ( ) ;
delete digi [ i ] ;
}
delete [ ] digi ;
digi = nullptr ;
2023-04-14 16:12:52 -04:00
LogMsg ( " Done. Closed " + QString : : number ( nDigi ) + " Digitizer(s). " ) ;
nDigi = 0 ;
2023-04-17 15:17:25 -04:00
2023-04-19 13:41:43 -04:00
WaitForDigitizersOpen ( true ) ;
2023-07-11 18:02:42 -04:00
bnStartACQ - > setStyleSheet ( " " ) ;
bnStopACQ - > setStyleSheet ( " " ) ;
2023-04-19 13:41:43 -04:00
2024-06-26 16:40:40 -04:00
printf ( " End of FSUDAQ::%s \n " , __func__ ) ;
2023-10-12 16:27:56 -04:00
2023-04-19 13:41:43 -04:00
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : WaitForDigitizersOpen ( bool onOff ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-10-26 17:57:06 -04:00
// bnOpenDigitizers->setEnabled(onOff);
cbOpenDigitizers - > setEnabled ( onOff ) ;
2024-01-19 14:15:37 -05:00
cbOpenMethod - > setEnabled ( onOff ) ;
2023-10-26 17:57:06 -04:00
2023-04-19 13:41:43 -04:00
bnCloseDigitizers - > setEnabled ( ! onOff ) ;
bnOpenScope - > setEnabled ( ! onOff ) ;
bnDigiSettings - > setEnabled ( ! onOff ) ;
bnOpenScaler - > setEnabled ( ! onOff ) ;
bnStartACQ - > setEnabled ( ! onOff ) ;
bnStopACQ - > setEnabled ( ! onOff ) ;
2023-06-23 13:50:21 -04:00
bnStopACQ - > setStyleSheet ( " " ) ;
2023-04-19 13:41:43 -04:00
chkSaveData - > setEnabled ( ! onOff ) ;
2023-05-19 16:49:01 -04:00
bnCanvas - > setEnabled ( ! onOff ) ;
2023-08-28 15:02:56 -04:00
cbAnalyzer - > setEnabled ( ! onOff ) ;
2023-04-19 13:41:43 -04:00
2023-07-11 18:02:42 -04:00
cbAutoRun - > setEnabled ( chkSaveData - > isChecked ( ) ) ;
2023-06-29 18:59:36 -04:00
bnSync - > setEnabled ( false ) ;
2023-04-14 16:12:52 -04:00
}
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : SetupScalar ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-10-09 13:12:48 -04:00
// printf("%s\n", __func__);
2023-05-02 15:43:05 -04:00
scalar = new QMainWindow ( this ) ;
scalar - > setWindowTitle ( " Scalar " ) ;
QScrollArea * scopeScroll = new QScrollArea ( scalar ) ;
scalar - > setCentralWidget ( scopeScroll ) ;
scopeScroll - > setWidgetResizable ( true ) ;
scopeScroll - > setSizePolicy ( QSizePolicy : : Expanding , QSizePolicy : : Expanding ) ;
QWidget * layoutWidget = new QWidget ( scalar ) ;
scopeScroll - > setWidget ( layoutWidget ) ;
scalarLayout = new QGridLayout ( layoutWidget ) ;
scalarLayout - > setSpacing ( 0 ) ;
scalarLayout - > setAlignment ( Qt : : AlignTop ) ;
leTrigger = nullptr ;
leAccept = nullptr ;
lbLastUpdateTime = nullptr ;
lbScalarACQStatus = nullptr ;
2024-04-25 17:01:45 -04:00
lbTotalFileSize = nullptr ;
2023-05-02 15:43:05 -04:00
2024-09-04 17:50:59 -04:00
scalarTimingThread = new TimingThread ( scalar ) ;
scalarTimingThread - > SetWaitTimeinSec ( ScalarUpdateinMiliSec / 1000. ) ;
connect ( scalarTimingThread , & TimingThread : : timeUp , this , & FSUDAQ : : UpdateScalar ) ;
2024-08-28 17:22:41 -04:00
2024-09-04 17:50:59 -04:00
// scalarThread = new QThread(this);
// scalarWorker = new ScalarWorker(this);
// scalarWorker->moveToThread(scalarThread);
2024-08-28 17:22:41 -04:00
2024-09-04 17:50:59 -04:00
// scalarTimer = new QTimer(this);
// connect( scalarTimer, &QTimer::timeout, scalarWorker, &ScalarWorker::UpdateScalar);
2024-08-28 17:22:41 -04:00
2024-09-04 17:50:59 -04:00
// scalarThread->start();
2023-05-02 15:43:05 -04:00
2023-10-04 18:03:42 -04:00
unsigned short maxNChannel = 0 ;
for ( unsigned int k = 0 ; k < nDigi ; k + + ) {
2023-10-09 17:46:32 -04:00
if ( digi [ k ] - > GetNumInputCh ( ) > maxNChannel ) maxNChannel = digi [ k ] - > GetNumInputCh ( ) ;
2023-10-04 18:03:42 -04:00
}
2024-04-25 17:01:45 -04:00
scalar - > setGeometry ( 0 , 0 , 50 + nDigi * 240 , 160 + maxNChannel * 25 ) ;
2023-04-14 16:12:52 -04:00
2023-04-17 15:17:25 -04:00
if ( lbLastUpdateTime = = nullptr ) {
lbLastUpdateTime = new QLabel ( " Last update : NA " , scalar ) ;
lbScalarACQStatus = new QLabel ( " ACQ status " , scalar ) ;
2024-04-25 17:01:45 -04:00
lbTotalFileSize = new QLabel ( " Total File Size " , scalar ) ;
2023-04-17 15:17:25 -04:00
}
2023-10-19 15:32:44 -04:00
lbLastUpdateTime - > setAlignment ( Qt : : AlignRight ) ;
2023-04-17 15:17:25 -04:00
scalarLayout - > removeWidget ( lbLastUpdateTime ) ;
2023-10-19 15:32:44 -04:00
scalarLayout - > addWidget ( lbLastUpdateTime , 0 , 0 , 1 , 1 + nDigi ) ;
2023-04-17 15:17:25 -04:00
lbScalarACQStatus - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > removeWidget ( lbScalarACQStatus ) ;
2023-10-19 15:32:44 -04:00
scalarLayout - > addWidget ( lbScalarACQStatus , 0 , 1 + nDigi ) ;
2023-04-17 15:17:25 -04:00
2024-04-25 17:01:45 -04:00
lbTotalFileSize - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > removeWidget ( lbTotalFileSize ) ;
scalarLayout - > addWidget ( lbTotalFileSize , 1 , 0 , 1 , 1 + 2 * nDigi ) ;
2023-10-04 18:03:42 -04:00
2024-04-25 17:01:45 -04:00
///==== create the header row
int rowID = 4 ;
2023-10-04 18:03:42 -04:00
for ( int ch = 0 ; ch < maxNChannel ; ch + + ) {
2023-04-17 15:17:25 -04:00
2023-04-18 13:12:05 -04:00
if ( ch = = 0 ) {
QLabel * lbCH_H = new QLabel ( " Ch " , scalar ) ;
2024-04-25 17:01:45 -04:00
lbCH_H - > setAlignment ( Qt : : AlignCenter ) ;
2023-04-18 13:12:05 -04:00
scalarLayout - > addWidget ( lbCH_H , rowID , 0 ) ;
}
2023-04-17 15:17:25 -04:00
2023-04-18 13:12:05 -04:00
rowID + + ;
QLabel * lbCH = new QLabel ( QString : : number ( ch ) , scalar ) ;
lbCH - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbCH , rowID , 0 ) ;
2023-04-17 15:17:25 -04:00
}
///===== create the trigger and accept
leTrigger = new QLineEdit * * [ nDigi ] ;
leAccept = new QLineEdit * * [ nDigi ] ;
for ( unsigned int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
rowID = 2 ;
2024-04-25 17:01:45 -04:00
uint32_t chMask = digi [ iDigi ] - > GetRegChannelMask ( ) ;
QWidget * hBox = new QWidget ( scalar ) ;
QHBoxLayout * hBoxLayout = new QHBoxLayout ( hBox ) ;
scalarLayout - > addWidget ( hBox , rowID , 2 * iDigi + 1 , 1 , 2 ) ;
QLabel * lbDigi = new QLabel ( " Digi- " + QString : : number ( digi [ iDigi ] - > GetSerialNumber ( ) ) , scalar ) ;
// QLabel * lbDigi = new QLabel(QString::number(digi[iDigi]->GetSerialNumber()), scalar);
// lbDigi->setAlignment(Qt::AlignRight | Qt::AlignCenter);
lbDigi - > setAlignment ( Qt : : AlignCenter ) ;
hBoxLayout - > addWidget ( lbDigi ) ;
runStatus [ iDigi ] = new QPushButton ( " " , scalar ) ;
runStatus [ iDigi ] - > setEnabled ( false ) ;
runStatus [ iDigi ] - > setFixedSize ( QSize ( 20 , 20 ) ) ;
runStatus [ iDigi ] - > setToolTip ( " ACQ RUN On/OFF " ) ;
runStatus [ iDigi ] - > setToolTipDuration ( - 1 ) ;
hBoxLayout - > addWidget ( runStatus [ iDigi ] ) ;
rowID = 3 ;
QWidget * hBox2 = new QWidget ( scalar ) ;
QHBoxLayout * hBoxLayout2 = new QHBoxLayout ( hBox2 ) ;
scalarLayout - > addWidget ( hBox2 , rowID , 2 * iDigi + 1 , 1 , 2 ) ;
lbAggCount [ iDigi ] = new QLabel ( " AggCount/ReadCount " , scalar ) ;
lbAggCount [ iDigi ] - > setAlignment ( Qt : : AlignLeft | Qt : : AlignCenter ) ;
hBoxLayout2 - > addWidget ( lbAggCount [ iDigi ] ) ;
lbFileSize [ iDigi ] = new QLabel ( " File Size " , scalar ) ;
lbFileSize [ iDigi ] - > setAlignment ( Qt : : AlignLeft | Qt : : AlignCenter ) ;
hBoxLayout2 - > addWidget ( lbFileSize [ iDigi ] ) ;
rowID = 4 ;
QLabel * lbA = new QLabel ( " Trig. [Hz] " , scalar ) ;
lbA - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbA , rowID , 2 * iDigi + 1 ) ;
QLabel * lbB = new QLabel ( " Accp. [Hz] " , scalar ) ;
lbB - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbB , rowID , 2 * iDigi + 2 ) ;
2023-10-09 17:46:32 -04:00
leTrigger [ iDigi ] = new QLineEdit * [ digi [ iDigi ] - > GetNumInputCh ( ) ] ;
leAccept [ iDigi ] = new QLineEdit * [ digi [ iDigi ] - > GetNumInputCh ( ) ] ;
2023-04-17 15:17:25 -04:00
2024-04-25 17:01:45 -04:00
for ( int ch = 0 ; ch < digi [ iDigi ] - > GetNumInputCh ( ) ; ch + + ) {
2023-04-18 13:12:05 -04:00
rowID + + ;
2023-04-17 15:17:25 -04:00
leTrigger [ iDigi ] [ ch ] = new QLineEdit ( scalar ) ;
leTrigger [ iDigi ] [ ch ] - > setReadOnly ( true ) ;
2024-04-25 17:01:45 -04:00
leTrigger [ iDigi ] [ ch ] - > setFixedSize ( 120 , 25 ) ;
2023-04-17 15:17:25 -04:00
leTrigger [ iDigi ] [ ch ] - > setAlignment ( Qt : : AlignRight ) ;
scalarLayout - > addWidget ( leTrigger [ iDigi ] [ ch ] , rowID , 2 * iDigi + 1 ) ;
leAccept [ iDigi ] [ ch ] = new QLineEdit ( scalar ) ;
leAccept [ iDigi ] [ ch ] - > setReadOnly ( true ) ;
2024-04-25 17:01:45 -04:00
leAccept [ iDigi ] [ ch ] - > setFixedSize ( 120 , 25 ) ;
2023-04-17 15:17:25 -04:00
leAccept [ iDigi ] [ ch ] - > setAlignment ( Qt : : AlignRight ) ;
leAccept [ iDigi ] [ ch ] - > setStyleSheet ( " background-color: #F0F0F0; " ) ;
2023-05-24 16:04:32 -04:00
2023-10-09 17:46:32 -04:00
if ( digi [ iDigi ] - > IsInputChEqRegCh ( ) ) {
2023-10-09 13:12:48 -04:00
leTrigger [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > ch ) & 0x1 ) ;
leAccept [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > ch ) & 0x1 ) ;
} else {
2023-10-09 17:46:32 -04:00
int grpID = ch / digi [ iDigi ] - > GetNumRegChannels ( ) ;
2023-10-09 13:12:48 -04:00
leTrigger [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > grpID ) & 0x1 ) ;
leAccept [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > grpID ) & 0x1 ) ;
}
2023-05-24 16:04:32 -04:00
2023-04-17 15:17:25 -04:00
scalarLayout - > addWidget ( leAccept [ iDigi ] [ ch ] , rowID , 2 * iDigi + 2 ) ;
}
2023-04-14 16:12:52 -04:00
}
2023-10-09 13:12:48 -04:00
2023-04-14 16:12:52 -04:00
}
2024-08-28 17:58:12 -04:00
void FSUDAQ : : UpdateScalar ( ) {
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-10-22 12:56:26 -04:00
// qDebug() << __func__ << "| thread:" << QThread::currentThreadId();
2024-08-28 17:58:12 -04:00
// printf("================== FSUDAQ::%s\n", __func__);
if ( digi = = nullptr ) return ;
if ( scalar = = nullptr ) return ;
//if( !scalar->isVisible() ) return;
// digi[0]->GetData()->PrintAllData();
// lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
lbLastUpdateTime - > setText ( QDateTime : : currentDateTime ( ) . toString ( " MM/dd hh:mm:ss " ) ) ;
scalarCount + + ;
uint64_t totalFileSize = 0 ;
for ( unsigned int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
// printf("======== digi-%d\n", iDigi);
if ( digi [ iDigi ] - > IsBoardDisabled ( ) ) continue ;
uint32_t acqStatus = digi [ iDigi ] - > GetACQStatusFromMemory ( ) ;
//printf("Digi-%d : acq on/off ? : %d \n", digi[iDigi]->GetSerialNumber(), (acqStatus >> 2) & 0x1 );
if ( ( acqStatus > > 2 ) & 0x1 ) {
if ( runStatus [ iDigi ] - > styleSheet ( ) = = " " ) runStatus [ iDigi ] - > setStyleSheet ( " background-color : green; " ) ;
} else {
if ( runStatus [ iDigi ] - > styleSheet ( ) ! = " " ) runStatus [ iDigi ] - > setStyleSheet ( " " ) ;
}
if ( digiSettings & & digiSettings - > isVisible ( ) & & digiSettings - > GetTabID ( ) = = iDigi ) digiSettings - > UpdateACQStatus ( acqStatus ) ;
// digiMTX[iDigi].lock();
QString blockCountStr = QString : : number ( digi [ iDigi ] - > GetData ( ) - > AggCount ) ;
blockCountStr + = " / " + QString : : number ( readDataThread [ iDigi ] - > GetReadCount ( ) ) ;
readDataThread [ iDigi ] - > SetReadCountZero ( ) ;
lbAggCount [ iDigi ] - > setText ( blockCountStr ) ;
lbFileSize [ iDigi ] - > setText ( QString : : number ( digi [ iDigi ] - > GetData ( ) - > GetTotalFileSize ( ) / 1024. / 1024. , ' f ' , 3 ) + " MB " ) ;
digi [ iDigi ] - > GetData ( ) - > CalTriggerRate ( ) ; //this will reset NumEventDecode & AggCount
if ( chkSaveData - > isChecked ( ) ) totalFileSize + = digi [ iDigi ] - > GetData ( ) - > GetTotalFileSize ( ) ;
for ( int i = 0 ; i < digi [ iDigi ] - > GetNumInputCh ( ) ; i + + ) {
QString a = " " ;
QString b = " " ;
if ( digi [ iDigi ] - > GetInputChannelOnOff ( i ) = = true ) {
// printf(" %3d %2d | %7.2f %7.2f \n", digi[iDigi]->GetSerialNumber(), i, digi[iDigi]->GetData()->TriggerRate[i], digi[iDigi]->GetData()->NonPileUpRate[i]);
QString a = QString : : number ( digi [ iDigi ] - > GetData ( ) - > TriggerRate [ i ] , ' f ' , 2 ) ;
QString b = QString : : number ( digi [ iDigi ] - > GetData ( ) - > NonPileUpRate [ i ] , ' f ' , 2 ) ;
leTrigger [ iDigi ] [ i ] - > setText ( a ) ;
leAccept [ iDigi ] [ i ] - > setText ( b ) ;
if ( influx & & chkInflux - > isChecked ( ) & & a ! = " inf " ) {
influx - > AddDataPoint ( " TrigRate,Bd= " + std : : to_string ( digi [ iDigi ] - > GetSerialNumber ( ) ) + " ,Ch= " + QString : : number ( i ) . rightJustified ( 2 , ' 0 ' ) . toStdString ( ) + " value= " + a . toStdString ( ) ) ;
}
}
}
// digiMTX[iDigi].unlock();
// printf("============= end of FSUDAQ::%s\n", __func__);
}
lbTotalFileSize - > setText ( " Total Data Size : " + QString : : number ( totalFileSize / 1024. / 1024. , ' f ' , 3 ) + " MB " ) ;
2024-09-04 17:50:59 -04:00
// repaint();
// scalar->repaint();
2024-08-28 17:58:12 -04:00
if ( influx & & chkInflux - > isChecked ( ) & & scalarCount > = 3 ) {
if ( chkSaveData - > isChecked ( ) ) {
influx - > AddDataPoint ( " RunID value= " + std : : to_string ( runID ) ) ;
influx - > AddDataPoint ( " FileSize value= " + std : : to_string ( totalFileSize ) ) ;
}
//nflux->PrintDataPoints();
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
scalarCount = 0 ;
}
2024-09-04 17:50:59 -04:00
// printf("end of %s\n", __func__);
2024-08-28 17:58:12 -04:00
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : CleanUpScalar ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-05-15 17:18:53 -04:00
if ( scalar = = nullptr ) return ;
2023-04-17 15:17:25 -04:00
scalar - > close ( ) ;
if ( leTrigger = = nullptr ) return ;
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2023-10-09 17:46:32 -04:00
for ( int ch = 0 ; ch < digi [ i ] - > GetNumInputCh ( ) ; ch + + ) {
2023-04-17 15:17:25 -04:00
delete leTrigger [ i ] [ ch ] ;
delete leAccept [ i ] [ ch ] ;
}
delete [ ] leTrigger [ i ] ;
delete [ ] leAccept [ i ] ;
}
delete [ ] leTrigger ;
leTrigger = nullptr ;
leAccept = nullptr ;
2023-04-18 13:12:05 -04:00
//Clean up QLabel
QList < QLabel * > labelChildren = scalar - > findChildren < QLabel * > ( ) ;
for ( int i = 0 ; i < labelChildren . size ( ) ; i + + ) delete labelChildren [ i ] ;
2023-04-17 15:17:25 -04:00
printf ( " ---- end of %s \n " , __func__ ) ;
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenScalar ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-17 15:17:25 -04:00
scalar - > show ( ) ;
}
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : StartACQ ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-14 16:12:52 -04:00
if ( digi = = nullptr ) return ;
2023-04-19 16:21:14 -04:00
bool commentResult = true ;
2023-07-11 18:02:42 -04:00
if ( chkSaveData - > isChecked ( ) ) commentResult = CommentDialog ( true ) ;
2023-04-19 16:21:14 -04:00
if ( commentResult = = false ) return ;
2023-04-18 13:12:05 -04:00
2023-05-19 16:23:04 -04:00
if ( chkSaveData - > isChecked ( ) ) {
2023-05-22 17:00:11 -04:00
LogMsg ( " <font style= \" color: orange; \" >===================== <b>Start a new Run- " + QString : : number ( runID ) + " </b></font> " ) ;
2023-06-01 17:51:00 -04:00
WriteRunTimestamp ( true ) ;
2023-05-19 16:23:04 -04:00
} else {
2023-05-22 17:00:11 -04:00
LogMsg ( " <font style= \" color: orange; \" >===================== <b>Start a non-save Run</b></font> " ) ;
2023-05-19 16:23:04 -04:00
}
2023-05-17 16:16:48 -04:00
2023-06-30 15:35:21 -04:00
//assume master board is the 0-th board
for ( int i = ( int ) nDigi - 1 ; i > = 0 ; i - - ) {
2023-11-06 17:59:16 -05:00
if ( digi [ i ] - > IsBoardDisabled ( ) ) continue ;
2023-05-16 14:31:19 -04:00
if ( chkSaveData - > isChecked ( ) ) {
2024-02-26 16:17:41 -05:00
std : : string runSettingName = ( rawDataPath + " / " + prefix + " _ " + QString : : number ( runID ) . rightJustified ( 3 , ' 0 ' ) + " _ " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ) . toStdString ( ) ;
runSettingName + = " _ " + digi [ i ] - > GetData ( ) - > DPPTypeStr + " .bin " ;
digi [ i ] - > SaveAllSettingsAsTextForRun ( runSettingName ) ;
2023-05-17 16:16:48 -04:00
if ( digi [ i ] - > GetData ( ) - > OpenSaveFile ( ( rawDataPath + " / " + prefix + " _ " + QString : : number ( runID ) . rightJustified ( 3 , ' 0 ' ) ) . toStdString ( ) ) = = false ) {
LogMsg ( " Cannot open save file : " + QString : : fromStdString ( digi [ i ] - > GetData ( ) - > GetOutFileName ( ) ) + " . Probably read-only? " ) ;
continue ;
} ;
2023-05-16 14:31:19 -04:00
}
2023-05-17 16:16:48 -04:00
readDataThread [ i ] - > SetSaveData ( chkSaveData - > isChecked ( ) ) ;
LogMsg ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " is starting ACQ. " ) ;
2023-05-23 11:19:43 -04:00
digi [ i ] - > WriteRegister ( DPP : : SoftwareClear_W , 1 ) ;
2023-06-09 13:51:02 -04:00
2023-06-30 15:35:21 -04:00
digi [ i ] - > StartACQ ( ) ;
2023-04-14 16:12:52 -04:00
readDataThread [ i ] - > start ( ) ;
}
2023-11-06 17:59:16 -05:00
if ( chkSaveData - > isChecked ( ) ) SaveLastRunFile ( ) ;
2023-06-29 18:59:36 -04:00
2023-06-30 15:35:21 -04:00
// printf("------------ wait for 2 sec \n");
// usleep(1000*1000);
// printf("------------ Go! \n");
// for( unsigned int i = 0; i < nDigi; i++) readDataThread[i]->go();
2023-06-29 18:59:36 -04:00
2024-09-04 17:50:59 -04:00
// if( scalar ) scalarTimer->start(ScalarUpdateinMiliSec);
if ( scalar ) scalarTimingThread - > start ( ) ;
2023-04-14 16:12:52 -04:00
2023-04-19 16:21:14 -04:00
if ( ! scalar - > isVisible ( ) ) {
scalar - > show ( ) ;
} else {
scalar - > activateWindow ( ) ;
}
lbScalarACQStatus - > setText ( " <font style= \" color: green; \" ><b>ACQ On</b></font> " ) ;
2023-04-17 14:09:21 -04:00
2024-08-30 12:27:24 -04:00
if ( singleHistograms ) singleHistograms - > startTimer ( ) ;
if ( onlineAnalyzer ) onlineAnalyzer - > startTimer ( ) ;
2023-05-19 16:23:04 -04:00
2023-04-19 18:08:20 -04:00
bnStartACQ - > setEnabled ( false ) ;
2023-06-23 13:50:21 -04:00
bnStartACQ - > setStyleSheet ( " " ) ;
2023-04-19 18:08:20 -04:00
bnStopACQ - > setEnabled ( true ) ;
2023-06-23 13:50:21 -04:00
bnStopACQ - > setStyleSheet ( " background-color: red; " ) ;
2023-05-16 14:31:19 -04:00
bnOpenScope - > setEnabled ( false ) ;
2023-07-11 18:02:42 -04:00
cbAutoRun - > setEnabled ( false ) ;
2024-04-09 15:18:48 -04:00
bnSync - > setEnabled ( false ) ;
2023-05-25 14:20:55 -04:00
2024-08-23 16:24:17 -04:00
if ( digiSettings ) digiSettings - > EnableButtons ( false ) ;
2023-09-06 15:05:27 -04:00
2023-05-30 10:08:39 -04:00
2023-05-25 14:20:55 -04:00
{ //^=== elog and database
2024-06-27 17:27:28 -04:00
if ( influx & & chkInflux - > isChecked ( ) ) {
2023-05-25 14:20:55 -04:00
influx - > AddDataPoint ( " RunID value= " + std : : to_string ( runID ) ) ;
2023-11-17 12:06:21 -05:00
if ( ! elogName . isEmpty ( ) ) influx - > AddDataPoint ( " SavingData,ExpName= " + elogName . toStdString ( ) + " value=1 " ) ;
2023-05-25 14:20:55 -04:00
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
}
2024-09-30 18:38:48 -04:00
if ( elogID > 0 & & chkElog - > isChecked ( ) & & chkSaveData - > isChecked ( ) ) {
2023-05-25 14:20:55 -04:00
QString msg = " ================================= Run- " + QString : : number ( runID ) . rightJustified ( 3 , ' 0 ' ) + " <p> "
+ QDateTime : : currentDateTime ( ) . toString ( " MM.dd hh:mm:ss " ) + " <p> "
+ startComment + " <p> "
" ---------------------------------<p> " ;
WriteElog ( msg , " Run Log " , " Run " , runID ) ;
}
}
2024-08-28 17:58:12 -04:00
isACQStarted = true ;
2024-02-21 18:50:40 -05:00
chkSaveData - > setEnabled ( false ) ;
2024-08-22 15:56:19 -04:00
// bnDigiSettings->setEnabled(false);
2024-02-21 18:50:40 -05:00
2023-04-14 16:12:52 -04:00
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : StopACQ ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-04-09 15:18:48 -04:00
QCoreApplication : : processEvents ( ) ;
2023-04-14 16:12:52 -04:00
if ( digi = = nullptr ) return ;
2023-05-22 17:00:11 -04:00
bool commentResult = true ;
2023-05-25 14:20:55 -04:00
if ( chkSaveData - > isChecked ( ) ) commentResult = CommentDialog ( false ) ;
2023-05-22 17:00:11 -04:00
if ( commentResult = = false ) return ;
2023-05-19 16:23:04 -04:00
if ( chkSaveData - > isChecked ( ) ) {
LogMsg ( " ===================== Stop Run- " + QString : : number ( runID ) ) ;
2023-06-01 17:51:00 -04:00
WriteRunTimestamp ( false ) ;
2023-05-19 16:23:04 -04:00
} else {
LogMsg ( " ===================== Stop a non-save Run " ) ;
}
2023-05-17 16:16:48 -04:00
2023-04-14 16:12:52 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2023-11-06 17:59:16 -05:00
if ( digi [ i ] - > IsBoardDisabled ( ) ) continue ;
2023-10-12 16:27:56 -04:00
readDataThread [ i ] - > Stop ( ) ;
readDataThread [ i ] - > quit ( ) ;
readDataThread [ i ] - > wait ( ) ;
2023-05-22 17:00:11 -04:00
digiMTX [ i ] . lock ( ) ;
digi [ i ] - > StopACQ ( ) ;
digiMTX [ i ] . unlock ( ) ;
if ( chkSaveData - > isChecked ( ) ) digi [ i ] - > GetData ( ) - > CloseSaveFile ( ) ;
2023-09-08 17:21:05 -04:00
LogMsg ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " ACQ is stopped. " ) ;
2024-01-25 16:18:47 -05:00
QCoreApplication : : processEvents ( ) ;
2023-04-14 16:12:52 -04:00
}
2023-04-19 16:21:14 -04:00
2024-09-04 17:50:59 -04:00
if ( scalarTimingThread - > isRunning ( ) ) {
scalarTimingThread - > Stop ( ) ;
scalarTimingThread - > quit ( ) ;
scalarTimingThread - > wait ( ) ;
}
// if( scalar ) scalarTimer->stop();
2024-08-30 12:27:24 -04:00
if ( singleHistograms ) singleHistograms - > stopTimer ( ) ;
if ( onlineAnalyzer ) onlineAnalyzer - > stopTimer ( ) ;
2024-08-28 16:45:23 -04:00
2023-04-19 16:21:14 -04:00
lbScalarACQStatus - > setText ( " <font style= \" color: red; \" ><b>ACQ Off</b></font> " ) ;
2023-04-19 18:08:20 -04:00
bnStartACQ - > setEnabled ( true ) ;
2023-06-23 13:50:21 -04:00
bnStartACQ - > setStyleSheet ( " background-color: green; " ) ;
2023-04-19 18:08:20 -04:00
bnStopACQ - > setEnabled ( false ) ;
2023-06-23 13:50:21 -04:00
bnStopACQ - > setStyleSheet ( " " ) ;
2023-05-16 14:31:19 -04:00
bnOpenScope - > setEnabled ( true ) ;
2023-07-11 18:02:42 -04:00
cbAutoRun - > setEnabled ( true ) ;
2024-04-09 15:18:48 -04:00
bnSync - > setEnabled ( true ) ;
2023-05-25 14:20:55 -04:00
2023-10-19 15:32:44 -04:00
if ( scalar ) {
for ( unsigned int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
uint32_t acqStatus = digi [ iDigi ] - > ReadRegister ( DPP : : AcquisitionStatus_R ) ;
if ( ( acqStatus > > 2 ) & 0x1 ) {
runStatus [ iDigi ] - > setStyleSheet ( " background-color : green; " ) ;
} else {
runStatus [ iDigi ] - > setStyleSheet ( " " ) ;
}
2024-01-25 16:18:47 -05:00
QCoreApplication : : processEvents ( ) ;
2023-10-19 15:32:44 -04:00
}
}
2024-08-23 16:24:17 -04:00
if ( digiSettings ) {
digiSettings - > EnableButtons ( true ) ;
digiSettings - > ReadSettingsFromBoard ( ) ;
}
2023-09-06 15:05:27 -04:00
2023-05-25 14:20:55 -04:00
{ //^=== elog and database
2024-06-27 17:27:28 -04:00
if ( influx & & chkInflux - > isChecked ( ) & & elogName ! = " " ) {
2023-11-17 12:06:21 -05:00
if ( ! elogName . isEmpty ( ) ) influx - > AddDataPoint ( " SavingData,ExpName= " + elogName . toStdString ( ) + " value=0 " ) ;
2023-05-25 14:20:55 -04:00
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
}
2024-09-30 18:38:48 -04:00
if ( elogID > 0 & & chkElog - > isChecked ( ) & & chkSaveData - > isChecked ( ) ) {
2023-05-25 14:20:55 -04:00
QString msg = QDateTime : : currentDateTime ( ) . toString ( " MM.dd hh:mm:ss " ) + " <p> " + stopComment + " <p> " ;
uint64_t totalFileSize = 0 ;
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
uint64_t fileSize = digi [ i ] - > GetData ( ) - > GetTotalFileSize ( ) ;
totalFileSize + = fileSize ;
msg + = " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " Size : " + QString : : number ( fileSize / 1024. / 1024. , ' f ' , 2 ) + " MB<p> " ;
}
msg + = " ..... Total File Size : " + QString : : number ( totalFileSize / 1024. / 1024. , ' f ' , 2 ) + " MB<p> " +
" =================================<p> " ;
AppendElog ( msg ) ;
}
}
2024-02-21 18:50:40 -05:00
chkSaveData - > setEnabled ( true ) ;
2024-08-22 15:56:19 -04:00
// bnDigiSettings->setEnabled(true);
2024-08-28 17:58:12 -04:00
isACQStarted = false ;
2024-02-21 18:50:40 -05:00
2024-04-18 10:06:55 -04:00
repaint ( ) ;
2024-08-28 16:53:25 -04:00
// printf("================ end of %s \n", __func__);
2024-04-18 10:06:55 -04:00
2023-04-14 16:12:52 -04:00
}
2023-04-11 11:13:23 -04:00
2024-06-26 16:40:40 -04:00
void FSUDAQ : : AutoRun ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-08-24 13:27:16 -04:00
runTimer - > disconnect ( runTimerConnection ) ;
2023-06-30 17:32:09 -04:00
if ( chkSaveData - > isChecked ( ) = = false ) {
StartACQ ( ) ;
return ;
}
2023-07-11 18:02:42 -04:00
if ( cbAutoRun - > currentData ( ) . toInt ( ) = = 0 ) {
StartACQ ( ) ;
//disconnect(runTimer, runTimerConnection);
//runTimer->disconnect(runTimerConnection);
return ;
} else { // auto run
needManualComment = true ;
StartACQ ( ) ;
runTimerConnection = connect ( runTimer , & QTimer : : timeout , this , [ = ] ( ) {
needManualComment = false ;
2023-08-24 13:27:16 -04:00
LogMsg ( " Time Up, Stopping ACQ... " ) ;
2023-07-11 18:02:42 -04:00
StopACQ ( ) ;
if ( cbAutoRun - > currentData ( ) . toInt ( ) < 0 ) {
bnStartACQ - > setEnabled ( false ) ;
bnStartACQ - > setStyleSheet ( " " ) ;
bnStopACQ - > setEnabled ( true ) ;
bnStopACQ - > setStyleSheet ( " background-color : red; " ) ;
LogMsg ( " Wait for 10 sec for next Run .... " ) ;
QElapsedTimer elapsedTimer ;
elapsedTimer . invalidate ( ) ;
elapsedTimer . start ( ) ;
while ( elapsedTimer . elapsed ( ) < 10000 ) {
if ( breakAutoRepeat ) {
LogMsg ( " Break Auto repeat. " ) ;
bnStartACQ - > setEnabled ( true ) ;
bnStartACQ - > setStyleSheet ( " background-color : green " ) ;
bnStopACQ - > setEnabled ( false ) ;
bnStopACQ - > setStyleSheet ( " " ) ;
return ;
}
QCoreApplication : : processEvents ( ) ;
}
needManualComment = false ;
StartACQ ( ) ;
runTimer - > setSingleShot ( true ) ;
runTimer - > start ( qAbs ( cbAutoRun - > currentData ( ) . toInt ( ) * 60 * 1000 ) ) ;
}
} ) ;
}
int timeMiliSec = cbAutoRun - > currentData ( ) . toInt ( ) * 60 * 1000 ;
runTimer - > setSingleShot ( true ) ;
runTimer - > start ( qAbs ( timeMiliSec ) ) ;
if ( timeMiliSec ) breakAutoRepeat = false ;
// ///=========== single run
// if ( timeMiliSec > 0 ){
// runTimer->setSingleShot(true);
// runTimer->start(timeMiliSec);
// }
// ///=========== infinite repeat run
// if ( timeMiliSec < 0 ){
// runTimer->setSingleShot(false);
// runTimer->start(qAbs(timeMiliSec));
// }
2023-06-30 17:32:09 -04:00
2023-06-29 18:59:36 -04:00
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : SetSyncMode ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-06-30 15:35:21 -04:00
QDialog dialog ;
dialog . setWindowTitle ( " Board Synchronization " ) ;
QVBoxLayout * layout = new QVBoxLayout ( & dialog ) ;
2023-06-30 17:32:09 -04:00
QLabel * lbInfo1 = new QLabel ( " This will reset 0x8100 and 0x811C \n Master must be the 1st board. \n (could be 100 ticks offset) " , & dialog ) ;
2023-06-30 15:35:21 -04:00
lbInfo1 - > setStyleSheet ( " color : red; " ) ;
QPushButton * bnNoSync = new QPushButton ( " No Sync " ) ;
2023-06-30 17:32:09 -04:00
QPushButton * bnMethod1 = new QPushButton ( " Software TRG-OUT --> TRG-IN " ) ;
QPushButton * bnMethod2 = new QPushButton ( " Software TRG-OUT --> S-IN " ) ;
2023-10-19 14:29:28 -04:00
QPushButton * bnMethod3 = new QPushButton ( " External --> 1st S-IN, \n TRG-OUT --> S-IN " ) ;
QPushButton * bnMethod4 = new QPushButton ( " External All S-IN " ) ;
2023-06-29 18:59:36 -04:00
2023-06-30 15:35:21 -04:00
layout - > addWidget ( lbInfo1 , 0 ) ;
layout - > addWidget ( bnNoSync , 2 ) ;
layout - > addWidget ( bnMethod1 , 3 ) ;
layout - > addWidget ( bnMethod2 , 4 ) ;
layout - > addWidget ( bnMethod3 , 5 ) ;
2023-10-19 14:29:28 -04:00
layout - > addWidget ( bnMethod4 , 6 ) ;
2023-06-29 18:59:36 -04:00
2023-06-30 15:35:21 -04:00
bnNoSync - > setFixedHeight ( 40 ) ;
bnMethod1 - > setFixedHeight ( 40 ) ;
bnMethod2 - > setFixedHeight ( 40 ) ;
bnMethod3 - > setFixedHeight ( 40 ) ;
2023-10-19 14:29:28 -04:00
bnMethod4 - > setFixedHeight ( 40 ) ;
2023-06-30 15:35:21 -04:00
2023-10-19 14:29:28 -04:00
connect ( bnNoSync , & QPushButton : : clicked , [ & ] ( ) { /// No Sync
2023-10-20 16:17:50 -04:00
LogMsg ( " Set No Sync across digitizers. " ) ;
LogMsg ( " Software start ACQ, internal clock. " ) ;
2023-06-30 15:35:21 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
digi [ i ] - > WriteRegister ( DPP : : AcquisitionControl , 0 ) ;
digi [ i ] - > WriteRegister ( DPP : : FrontPanelIOControl , 0 ) ;
}
2023-10-11 18:28:19 -04:00
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
2023-06-30 15:35:21 -04:00
dialog . accept ( ) ;
} ) ;
2023-10-19 14:29:28 -04:00
connect ( bnMethod1 , & QPushButton : : clicked , [ & ] ( ) { /// Software TRG-OUT --> TRG-IN
2023-10-20 16:17:50 -04:00
LogMsg ( " Set Software TRG-OUT -> TRG-IN " ) ;
LogMsg ( " Set master saftware ACQ, internal clock. " ) ;
LogMsg ( " Set slaves TRG-IN, external clock " ) ;
2023-06-30 15:35:21 -04:00
digi [ 0 ] - > WriteRegister ( DPP : : AcquisitionControl , 0 ) ;
digi [ 0 ] - > WriteRegister ( DPP : : FrontPanelIOControl , 0x10000 ) ; //RUN
for ( unsigned int i = 1 ; i < nDigi ; i + + ) {
2023-10-11 18:28:19 -04:00
digi [ i ] - > WriteRegister ( DPP : : AcquisitionControl , 0x42 ) ;
2023-06-30 15:35:21 -04:00
digi [ i ] - > WriteRegister ( DPP : : FrontPanelIOControl , 0x10000 ) ; // S-IN
}
2023-10-11 18:28:19 -04:00
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
2023-06-30 15:35:21 -04:00
dialog . accept ( ) ;
} ) ;
2023-10-19 14:29:28 -04:00
connect ( bnMethod2 , & QPushButton : : clicked , [ & ] ( ) { /// Software TRG-OUT --> S-IN
2023-10-20 16:17:50 -04:00
LogMsg ( " Set Software TRG-OUT -> S-IN " ) ;
LogMsg ( " Set master saftware ACQ, internal clock. " ) ;
LogMsg ( " Set slaves S-IN, external clock " ) ;
2023-06-30 15:35:21 -04:00
digi [ 0 ] - > WriteRegister ( DPP : : AcquisitionControl , 0 ) ;
digi [ 0 ] - > WriteRegister ( DPP : : FrontPanelIOControl , 0x10000 ) ; //RUN
for ( unsigned int i = 1 ; i < nDigi ; i + + ) {
2023-10-11 18:28:19 -04:00
digi [ i ] - > WriteRegister ( DPP : : AcquisitionControl , 0x41 ) ;
2023-06-30 15:35:21 -04:00
digi [ i ] - > WriteRegister ( DPP : : FrontPanelIOControl , 0x30000 ) ; // S-IN
}
2023-10-11 18:28:19 -04:00
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
2023-06-30 15:35:21 -04:00
dialog . accept ( ) ;
} ) ;
2023-06-29 18:59:36 -04:00
2023-10-19 14:29:28 -04:00
connect ( bnMethod3 , & QPushButton : : clicked , [ & ] ( ) { ///External TRG-OUT --> S-IN
2023-10-20 16:17:50 -04:00
LogMsg ( " Set master External -> S-IN, slave TRG-OUT -> S-IN " ) ;
LogMsg ( " Set master external S-IN, internal clock. " ) ;
LogMsg ( " Set slaves S-IN, external clock " ) ;
2023-10-19 14:29:28 -04:00
digi [ 0 ] - > WriteRegister ( DPP : : AcquisitionControl , 0x01 ) ;
2023-06-30 15:35:21 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2023-10-11 18:28:19 -04:00
digi [ i ] - > WriteRegister ( DPP : : AcquisitionControl , 0x41 ) ;
2023-06-30 15:35:21 -04:00
digi [ i ] - > WriteRegister ( DPP : : FrontPanelIOControl , 0x30000 ) ; // S-IN
}
2023-10-11 18:28:19 -04:00
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
2023-06-30 15:35:21 -04:00
dialog . accept ( ) ;
} ) ;
2023-06-29 18:59:36 -04:00
2023-10-19 14:29:28 -04:00
connect ( bnMethod4 , & QPushButton : : clicked , [ & ] ( ) { /// External All S-IN
2023-10-20 16:17:50 -04:00
LogMsg ( " Set all External -> S-IN " ) ;
LogMsg ( " Set master internal clock, slaves external clock " ) ;
2023-10-19 14:29:28 -04:00
digi [ 0 ] - > WriteRegister ( DPP : : AcquisitionControl , 0x01 ) ;
for ( unsigned int i = 1 ; i < nDigi ; i + + ) {
digi [ i ] - > WriteRegister ( DPP : : AcquisitionControl , 0x41 ) ;
}
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
dialog . accept ( ) ;
} ) ;
2023-06-30 15:35:21 -04:00
dialog . exec ( ) ;
2023-06-29 18:59:36 -04:00
2023-04-18 13:12:05 -04:00
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : SetAndLockInfluxElog ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-12-12 16:17:11 -05:00
if ( leInfluxIP - > isReadOnly ( ) ) {
bnLock - > setText ( " Lock and Set " ) ;
leInfluxIP - > setReadOnly ( false ) ;
leDatabaseName - > setReadOnly ( false ) ;
leElogIP - > setReadOnly ( false ) ;
leElogName - > setReadOnly ( false ) ;
leInfluxIP - > setEnabled ( true ) ;
leDatabaseName - > setEnabled ( true ) ;
leElogIP - > setEnabled ( true ) ;
leElogName - > setEnabled ( true ) ;
leInfluxIP - > setStyleSheet ( " color : blue; " ) ;
leDatabaseName - > setStyleSheet ( " color : blue; " ) ;
leElogIP - > setStyleSheet ( " color : blue; " ) ;
leElogName - > setStyleSheet ( " color : blue; " ) ;
} else {
bnLock - > setText ( " Unlock " ) ;
leInfluxIP - > setReadOnly ( true ) ;
leDatabaseName - > setReadOnly ( true ) ;
leElogIP - > setReadOnly ( true ) ;
leElogName - > setReadOnly ( true ) ;
leInfluxIP - > setStyleSheet ( " " ) ;
leDatabaseName - > setStyleSheet ( " " ) ;
leElogIP - > setStyleSheet ( " " ) ;
leElogName - > setStyleSheet ( " " ) ;
influxIP = leInfluxIP - > text ( ) ;
dataBaseName = leDatabaseName - > text ( ) ;
elogIP = leElogIP - > text ( ) ;
elogName = leElogName - > text ( ) ;
2024-03-01 20:22:51 -05:00
if ( ! influxIP . isEmpty ( ) & & ! dataBaseName . isEmpty ( ) ) {
QDialog dialog ;
dialog . setWindowTitle ( " Database Token " ) ;
QVBoxLayout layout ( & dialog ) ;
QLineEdit tokenLineEdit ;
tokenLineEdit . setFixedSize ( 1000 , 20 ) ;
tokenLineEdit . setText ( influxToken ) ;
layout . addWidget ( new QLabel ( " Only for version 2+, version 1+ can be skipped. " ) ) ;
layout . addWidget ( & tokenLineEdit ) ;
// Buttons for OK and Cancel
QDialogButtonBox buttonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
layout . addWidget ( & buttonBox ) ;
QObject : : connect ( & buttonBox , & QDialogButtonBox : : accepted , & dialog , & QDialog : : accept ) ;
QObject : : connect ( & buttonBox , & QDialogButtonBox : : rejected , & dialog , & QDialog : : reject ) ;
dialog . resize ( 400 , dialog . sizeHint ( ) . height ( ) ) ; // Set the width to 400 pixels
// Show the dialog and get the result
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
influxToken = tokenLineEdit . text ( ) ;
}
}
2023-12-12 16:17:11 -05:00
if ( ! elogIP . isEmpty ( ) & & ! elogName . isEmpty ( ) ) {
QDialog dialog ;
dialog . setWindowTitle ( " ELog Login info. " ) ;
QVBoxLayout layout ( & dialog ) ;
QFormLayout formLayout ;
2024-10-18 16:30:21 -04:00
QLineEdit portLineEdit ;
2023-12-12 16:17:11 -05:00
QLineEdit usernameLineEdit ;
QLineEdit passwordLineEdit ;
2023-12-15 16:53:41 -05:00
//passwordLineEdit.setEchoMode(QLineEdit::Password);
2023-12-12 16:17:11 -05:00
2024-10-18 16:30:21 -04:00
formLayout . addRow ( " Port: " , & portLineEdit ) ;
2023-12-12 16:17:11 -05:00
formLayout . addRow ( " Username: " , & usernameLineEdit ) ;
formLayout . addRow ( " Password: " , & passwordLineEdit ) ;
2024-10-18 16:30:21 -04:00
portLineEdit . setText ( elogPort ) ;
2023-12-12 16:17:11 -05:00
usernameLineEdit . setText ( elogUser ) ;
passwordLineEdit . setText ( elogPWD ) ;
layout . addLayout ( & formLayout ) ;
// Buttons for OK and Cancel
QDialogButtonBox buttonBox ( QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
layout . addWidget ( & buttonBox ) ;
QObject : : connect ( & buttonBox , & QDialogButtonBox : : accepted , & dialog , & QDialog : : accept ) ;
QObject : : connect ( & buttonBox , & QDialogButtonBox : : rejected , & dialog , & QDialog : : reject ) ;
2023-12-15 16:47:11 -05:00
dialog . resize ( 400 , dialog . sizeHint ( ) . height ( ) ) ; // Set the width to 400 pixels
2023-12-12 16:17:11 -05:00
// Show the dialog and get the result
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
2024-10-18 16:30:21 -04:00
QString portNum = portLineEdit . text ( ) ;
QString username = usernameLineEdit . text ( ) ;
QString password = passwordLineEdit . text ( ) ;
// Check if username and password are not empty
if ( ! portNum . isEmpty ( ) & & ! username . isEmpty ( ) & & ! password . isEmpty ( ) ) {
elogPort = portNum ;
elogUser = username ;
elogPWD = password ;
} else {
qDebug ( ) < < " Please enter both port, username, and password. " ;
}
2023-12-12 16:17:11 -05:00
}
}
SaveProgramSettings ( ) ;
SetUpInflux ( ) ;
CheckElog ( ) ;
}
}
2024-06-26 16:40:40 -04:00
bool FSUDAQ : : CommentDialog ( bool isStartRun ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-18 13:12:05 -04:00
if ( isStartRun ) runID + + ;
QString runIDStr = QString : : number ( runID ) . rightJustified ( 3 , ' 0 ' ) ;
2023-07-11 18:02:42 -04:00
int result = QDialog : : Rejected ;
QLineEdit * lineEdit = new QLineEdit ( this ) ;
if ( needManualComment ) {
QDialog * dOpen = new QDialog ( this ) ;
if ( isStartRun ) {
dOpen - > setWindowTitle ( " Start Run Comment " ) ;
} else {
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 <font style= \" color : red; \" >Run- " + runIDStr + " </font> : " , 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 ) ;
result = dOpen - > exec ( ) ;
2023-04-18 13:12:05 -04:00
} else {
2023-07-11 18:02:42 -04:00
if ( isStartRun ) {
lineEdit - > setText ( " Auto Start, repeat every " + QString : : number ( qAbs ( cbAutoRun - > currentData ( ) . toInt ( ) ) ) + " mins. " ) ;
} else {
lineEdit - > setText ( " Auto Stop, after " + QString : : number ( qAbs ( cbAutoRun - > currentData ( ) . toInt ( ) ) ) + " mins. " ) ;
}
result = QDialog : : Accepted ;
2023-04-18 13:12:05 -04:00
}
if ( result = = QDialog : : Accepted ) {
if ( isStartRun ) {
startComment = lineEdit - > text ( ) ;
if ( startComment = = " " ) startComment = " No commet was typed. " ;
2023-07-11 18:02:42 -04:00
if ( needManualComment ) {
int minute = cbAutoRun - > currentData ( ) . toInt ( ) ;
if ( minute > 0 ) {
startComment + = " , single run of " + QString : : number ( minute ) + " mins. " ;
} else {
startComment + = " , repeat run of " + QString : : number ( qAbs ( minute ) ) + " mins. " ;
}
}
2023-04-18 13:12:05 -04:00
startComment = " Start Comment: " + startComment ;
leComment - > setText ( startComment ) ;
2023-05-17 16:16:48 -04:00
leRunID - > setText ( QString : : number ( runID ) ) ;
2023-04-18 13:12:05 -04:00
} else {
stopComment = lineEdit - > text ( ) ;
if ( stopComment = = " " ) stopComment = " No commet was typed. " ;
stopComment = " Stop Comment: " + stopComment ;
leComment - > setText ( stopComment ) ;
}
} else {
if ( isStartRun ) {
LogMsg ( " Start Run aborted. " ) ;
runID - - ;
leRunID - > setText ( QString : : number ( runID ) ) ;
} else {
LogMsg ( " Stop Run cancelled. " ) ;
}
return false ;
}
return true ;
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : WriteRunTimestamp ( bool isStartRun ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-18 13:12:05 -04:00
QFile file ( rawDataPath + " /RunTimeStamp.dat " ) ;
QString dateTime = QDateTime : : currentDateTime ( ) . toString ( " yyyy.MM.dd hh:mm:ss " ) ;
if ( file . open ( QIODevice : : Text | QIODevice : : WriteOnly | QIODevice : : Append ) ) {
if ( isStartRun ) {
2024-06-10 16:22:01 -04:00
file . write ( ( " Start Run | " + QString : : number ( runID ) + " | " + dateTime + " | " + lePrefix - > text ( ) + " | " + startComment + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-04-18 13:12:05 -04:00
} else {
2024-06-10 16:22:01 -04:00
file . write ( ( " Stop Run | " + QString : : number ( runID ) + " | " + dateTime + " | " + lePrefix - > text ( ) + " | " + stopComment + " \n " ) . toStdString ( ) . c_str ( ) ) ;
2023-04-18 13:12:05 -04:00
}
file . close ( ) ;
}
QFile fileCSV ( rawDataPath + " /RunTimeStamp.csv " ) ;
if ( fileCSV . open ( QIODevice : : Text | QIODevice : : WriteOnly | QIODevice : : Append ) ) {
QTextStream out ( & fileCSV ) ;
if ( isStartRun ) {
out < < QString : : number ( runID ) + " , " + dateTime + " , " + startComment ;
} else {
out < < " , " + dateTime + " , " + stopComment + " \n " ;
}
fileCSV . close ( ) ;
}
2023-07-11 18:02:42 -04:00
UpdateRecord ( ) ;
2023-04-18 13:12:05 -04:00
}
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenScope ( ) {
2024-04-18 10:06:55 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
QCoreApplication : : processEvents ( ) ;
2023-04-18 13:12:05 -04:00
if ( scope = = nullptr ) {
scope = new Scope ( digi , nDigi , readDataThread ) ;
2024-06-26 16:40:40 -04:00
connect ( scope , & Scope : : SendLogMsg , this , & FSUDAQ : : LogMsg ) ;
2024-08-29 17:15:36 -04:00
2023-05-16 14:31:19 -04:00
connect ( scope , & Scope : : CloseWindow , this , [ = ] ( ) {
bnStartACQ - > setEnabled ( true ) ;
2023-06-23 13:50:21 -04:00
bnStartACQ - > setStyleSheet ( " background-color: green; " ) ;
2023-05-16 14:31:19 -04:00
bnStopACQ - > setEnabled ( false ) ;
2023-06-23 13:50:21 -04:00
bnStopACQ - > setStyleSheet ( " " ) ;
2023-05-16 14:31:19 -04:00
} ) ;
2024-08-29 17:15:36 -04:00
2023-05-17 16:16:48 -04:00
connect ( scope , & Scope : : TellACQOnOff , this , [ = ] ( bool onOff ) {
2024-08-29 17:15:36 -04:00
isACQStarted = onOff ;
if ( onOff ) {
if ( influx & & chkInflux - > isChecked ( ) & & ! elogName . isEmpty ( ) ) influx - > AddDataPoint ( " SavingData,ExpName= " + elogName . toStdString ( ) + " value=1 " ) ;
if ( scalar ) {
2023-05-19 16:49:01 -04:00
lbScalarACQStatus - > setText ( " <font style= \" color: green; \" ><b>ACQ On</b></font> " ) ;
2024-09-04 17:50:59 -04:00
// scalarTimer->start(ScalarUpdateinMiliSec);
scalarTimingThread - > start ( ) ;
2023-08-22 14:38:37 -04:00
}
2023-05-19 16:49:01 -04:00
2024-08-30 12:27:24 -04:00
if ( singleHistograms ) singleHistograms - > startTimer ( ) ;
if ( onlineAnalyzer ) onlineAnalyzer - > startTimer ( ) ;
2024-08-29 17:15:36 -04:00
} else {
if ( influx & & chkInflux - > isChecked ( ) & & ! elogName . isEmpty ( ) ) influx - > AddDataPoint ( " SavingData,ExpName= " + elogName . toStdString ( ) + " value=0 " ) ;
if ( scalar ) {
lbScalarACQStatus - > setText ( " <font style= \" color: red; \" ><b>ACQ Off</b></font> " ) ;
2024-09-04 17:50:59 -04:00
// scalarTimer->stop();
scalarTimingThread - > Stop ( ) ;
scalarTimingThread - > quit ( ) ;
scalarTimingThread - > wait ( ) ;
2023-05-19 16:49:01 -04:00
}
2024-08-29 17:15:36 -04:00
2024-08-30 12:27:24 -04:00
if ( singleHistograms ) singleHistograms - > stopTimer ( ) ;
if ( onlineAnalyzer ) onlineAnalyzer - > stopTimer ( ) ;
2024-08-29 17:15:36 -04:00
2023-05-17 16:16:48 -04:00
}
2024-08-28 16:45:23 -04:00
2024-08-29 17:15:36 -04:00
if ( digiSettings ) digiSettings - > EnableButtons ( ! onOff ) ;
2023-05-17 16:16:48 -04:00
} ) ;
2023-05-23 17:02:39 -04:00
connect ( scope , & Scope : : UpdateOtherPanels , this , [ = ] ( ) { UpdateAllPanels ( 1 ) ; } ) ;
2023-04-18 13:12:05 -04:00
scope - > show ( ) ;
} else {
scope - > show ( ) ;
2023-04-19 18:08:20 -04:00
scope - > activateWindow ( ) ;
2023-04-18 13:12:05 -04:00
}
2023-05-16 14:31:19 -04:00
bnStartACQ - > setEnabled ( false ) ;
2023-06-23 13:50:21 -04:00
bnStartACQ - > setStyleSheet ( " " ) ;
2023-05-16 14:31:19 -04:00
bnStopACQ - > setEnabled ( false ) ;
2023-06-23 13:50:21 -04:00
bnStopACQ - > setStyleSheet ( " " ) ;
2023-05-23 14:52:23 -04:00
chkSaveData - > setChecked ( false ) ;
2023-04-18 13:12:05 -04:00
}
2023-04-24 16:37:57 -04:00
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenDigiSettings ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-24 16:37:57 -04:00
if ( digiSettings = = nullptr ) {
2023-05-02 14:49:45 -04:00
digiSettings = new DigiSettingsPanel ( digi , nDigi , rawDataPath ) ;
2024-06-26 16:40:40 -04:00
//connect(scope, &Scope::SendLogMsg, this, &FSUDAQ::LogMsg);
2023-05-23 17:02:39 -04:00
connect ( digiSettings , & DigiSettingsPanel : : UpdateOtherPanels , this , [ = ] ( ) { UpdateAllPanels ( 2 ) ; } ) ;
2024-10-14 17:47:11 -04:00
connect ( digiSettings , & DigiSettingsPanel : : SendLogMsg , this , & FSUDAQ : : LogMsg ) ;
2023-05-23 17:02:39 -04:00
2023-04-24 16:37:57 -04:00
digiSettings - > show ( ) ;
} else {
digiSettings - > show ( ) ;
digiSettings - > activateWindow ( ) ;
}
}
2023-04-18 13:12:05 -04:00
2023-05-17 17:40:32 -04:00
//***************************************************************
//***************************************************************
2024-08-20 14:59:22 -04:00
void FSUDAQ : : OpenSingleHistograms ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-08-20 14:59:22 -04:00
if ( singleHistograms = = nullptr ) {
singleHistograms = new SingleSpectra ( digi , nDigi , rawDataPath ) ;
singleHistograms - > show ( ) ;
2023-05-17 17:40:32 -04:00
} else {
2024-08-20 14:59:22 -04:00
singleHistograms - > show ( ) ;
singleHistograms - > activateWindow ( ) ;
singleHistograms - > LoadSetting ( ) ;
2023-05-17 17:40:32 -04:00
}
2023-05-26 18:06:37 -04:00
}
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : OpenAnalyzer ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-04-18 10:06:55 -04:00
2023-08-28 15:02:56 -04:00
int id = cbAnalyzer - > currentData ( ) . toInt ( ) ;
if ( id < 0 ) return ;
2023-05-26 18:06:37 -04:00
if ( onlineAnalyzer = = nullptr ) {
2024-06-28 15:08:58 -04:00
if ( id = = 0 ) onlineAnalyzer = new CoincidentAnalyzer ( digi , nDigi , rawDataPath ) ;
2023-11-16 19:20:29 -05:00
if ( id = = 1 ) onlineAnalyzer = new SplitPole ( digi , nDigi ) ;
if ( id = = 2 ) onlineAnalyzer = new Encore ( digi , nDigi ) ;
2024-09-30 18:38:48 -04:00
if ( id = = 3 ) onlineAnalyzer = new MUSIC ( digi , nDigi ) ;
if ( id = = 4 ) onlineAnalyzer = new NeutronGamma ( digi , nDigi , rawDataPath ) ;
if ( id = = 5 ) onlineAnalyzer = new Cross ( digi , nDigi ) ;
2023-08-28 15:02:56 -04:00
if ( id > = 0 ) onlineAnalyzer - > show ( ) ;
2024-08-22 12:42:08 -04:00
2024-08-30 12:27:24 -04:00
if ( isACQStarted ) onlineAnalyzer - > startTimer ( ) ;
2024-08-22 12:42:08 -04:00
2023-05-26 18:06:37 -04:00
} else {
2023-08-28 15:02:56 -04:00
delete onlineAnalyzer ;
2024-06-28 15:08:58 -04:00
if ( id = = 0 ) onlineAnalyzer = new CoincidentAnalyzer ( digi , nDigi , rawDataPath ) ;
2023-11-16 19:20:29 -05:00
if ( id = = 1 ) onlineAnalyzer = new SplitPole ( digi , nDigi ) ;
if ( id = = 2 ) onlineAnalyzer = new Encore ( digi , nDigi ) ;
2024-09-30 18:38:48 -04:00
if ( id = = 3 ) onlineAnalyzer = new MUSIC ( digi , nDigi ) ;
if ( id = = 4 ) onlineAnalyzer = new NeutronGamma ( digi , nDigi , rawDataPath ) ;
if ( id = = 5 ) onlineAnalyzer = new Cross ( digi , nDigi ) ;
2023-08-28 15:02:56 -04:00
if ( id > = 0 ) {
onlineAnalyzer - > show ( ) ;
onlineAnalyzer - > activateWindow ( ) ;
2024-08-30 12:27:24 -04:00
if ( isACQStarted ) onlineAnalyzer - > stopTimer ( ) ;
2023-08-28 15:02:56 -04:00
}
2023-05-26 18:06:37 -04:00
}
2023-08-28 15:02:56 -04:00
cbAnalyzer - > setCurrentIndex ( 0 ) ;
2023-05-17 17:40:32 -04:00
}
2023-05-23 17:02:39 -04:00
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : UpdateAllPanels ( int panelID ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-05-23 17:02:39 -04:00
//panelID is the source panel that call
// scope = 1;
// digiSetting = 2;
if ( panelID = = 1 ) { // from scope
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
2023-11-21 15:34:29 -05:00
if ( scalar ) {
for ( unsigned int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
if ( digi [ iDigi ] - > IsBoardDisabled ( ) ) continue ;
uint32_t acqStatus = digi [ iDigi ] - > GetACQStatusFromMemory ( ) ;
if ( ( acqStatus > > 2 ) & 0x1 ) {
runStatus [ iDigi ] - > setStyleSheet ( " background-color : green; " ) ;
} else {
runStatus [ iDigi ] - > setStyleSheet ( " " ) ;
}
}
}
2023-05-23 17:02:39 -04:00
}
if ( panelID = = 2 ) {
if ( scope & & scope - > isVisible ( ) ) scope - > UpdatePanelFromMomeory ( ) ;
2023-05-24 16:04:32 -04:00
if ( scalar ) {
for ( unsigned int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
2023-10-09 17:46:32 -04:00
uint32_t chMask = digi [ iDigi ] - > GetRegChannelMask ( ) ;
2023-10-11 18:28:19 -04:00
uint32_t subChMask = 0 ;
2023-10-09 17:46:32 -04:00
for ( int ch = 0 ; ch < digi [ iDigi ] - > GetNumInputCh ( ) ; ch + + ) {
2023-10-09 17:18:38 -04:00
// leTrigger[iDigi][i]->setEnabled( (chMask >> i) & 0x1 );
// leAccept[iDigi][i]->setEnabled( (chMask >> i) & 0x1 );
2023-10-09 17:46:32 -04:00
if ( digi [ iDigi ] - > IsInputChEqRegCh ( ) ) {
2023-10-09 17:18:38 -04:00
leTrigger [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > ch ) & 0x1 ) ;
leAccept [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > ch ) & 0x1 ) ;
} else {
2023-10-09 17:46:32 -04:00
int grpID = ch / digi [ iDigi ] - > GetNumRegChannels ( ) ;
2023-10-09 17:18:38 -04:00
leTrigger [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > grpID ) & 0x1 ) ;
leAccept [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > grpID ) & 0x1 ) ;
2023-10-11 18:28:19 -04:00
if ( ( chMask > > grpID ) & 0x1 ) {
int subCh = ch % digi [ iDigi ] - > GetNumRegChannels ( ) ;
if ( subCh = = 0 ) subChMask = digi [ iDigi ] - > GetSettingFromMemory ( DPP : : QDC : : SubChannelMask , grpID ) ;
leTrigger [ iDigi ] [ ch ] - > setEnabled ( ( subChMask > > subCh ) & 0x1 ) ;
leAccept [ iDigi ] [ ch ] - > setEnabled ( ( subChMask > > subCh ) & 0x1 ) ;
}
2023-10-09 17:18:38 -04:00
}
2023-10-11 18:28:19 -04:00
2023-05-24 16:04:32 -04:00
}
}
}
2023-05-23 17:02:39 -04:00
}
}
2023-05-24 17:10:36 -04:00
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : SetUpInflux ( ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-03-06 20:10:33 -05:00
if ( influxIP = = " " ) {
LogMsg ( " <font style= \" color : red; \" >Influx missing inputs. skip.</font> " ) ;
leInfluxIP - > setEnabled ( false ) ;
leDatabaseName - > setEnabled ( false ) ;
return ;
}
2023-05-24 17:10:36 -04:00
if ( influx ) {
delete influx ;
influx = nullptr ;
}
influx = new InfluxDB ( influxIP . toStdString ( ) , false ) ;
if ( influx - > TestingConnection ( ) ) {
2024-03-01 19:18:23 -05:00
LogMsg ( " <font style= \" color : green; \" > InfluxDB URL (<b> " + influxIP + " </b>) is Valid. Version : " + QString : : fromStdString ( influx - > GetVersionString ( ) ) + " </font> " ) ;
if ( influx - > GetVersionNo ( ) > 1 & & influxToken . isEmpty ( ) ) {
LogMsg ( " <font style= \" color : red; \" >A Token is required for accessing the database.</font> " ) ;
delete influx ;
influx = nullptr ;
return ;
}
influx - > SetToken ( influxToken . toStdString ( ) ) ;
2023-05-24 17:10:36 -04:00
//==== chck database exist
2024-03-01 19:18:23 -05:00
influx - > CheckDatabases ( ) ;
2023-05-24 17:10:36 -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 ;
2024-03-01 19:18:23 -05:00
// LogMsg(QString::number(i) + "|" + QString::fromStdString(databaseList[i]));
2023-05-24 17:10:36 -04:00
}
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 = nullptr ;
}
} else {
LogMsg ( " <font style= \" color : red; \" > InfluxDB URL (<b> " + influxIP + " </b>) is NOT Valid </font> " ) ;
delete influx ;
influx = nullptr ;
}
2023-05-25 14:20:55 -04:00
if ( influx = = nullptr ) {
leInfluxIP - > setEnabled ( false ) ;
leDatabaseName - > setEnabled ( false ) ;
}
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : CheckElog ( ) {
2024-06-27 17:27:28 -04:00
elogID = - 1 ;
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-06-27 17:27:28 -04:00
if ( ! chkElog - > isChecked ( ) ) {
LogMsg ( " Elog is disabled. Please chick the checkbox and lock again to check elog connectivity. " ) ;
leElogIP - > setEnabled ( false ) ;
leElogName - > setEnabled ( false ) ;
return ;
}
2024-04-18 10:06:55 -04:00
LogMsg ( " ---- Checking elog... please wait.... " ) ;
2024-06-27 17:27:28 -04:00
// printf("---- Checking elog... please wait....\n");
2023-05-25 14:20:55 -04:00
if ( elogIP ! = " " & & elogName ! = " " & & elogUser ! = " " & & elogPWD ! = " " ) {
WriteElog ( " Testing communication. " , " Testing communication. " , " Other " , 0 ) ;
AppendElog ( " test append elog. " ) ;
2023-10-09 13:12:48 -04:00
} else {
2023-10-09 17:18:38 -04:00
LogMsg ( " <font style= \" color : red; \" >Elog missing inputs. skip.</font> " ) ;
2023-12-12 16:17:11 -05:00
leElogIP - > setEnabled ( false ) ;
leElogName - > setEnabled ( false ) ;
2023-10-09 13:12:48 -04:00
return ;
2023-05-25 14:20:55 -04:00
}
if ( elogID > = 0 ) {
LogMsg ( " Elog testing OK. " ) ;
2024-06-27 17:27:28 -04:00
// printf("Elog testing OK.\n");
2023-05-25 14:20:55 -04:00
return ;
}
//QMessageBox::information(nullptr, "Information", "Elog write Fail.\nPlease set the elog User and PWD in the programSettings.txt.\nline 6 = user.\nline 7 = pwd.");
LogMsg ( " Elog testing Fail " ) ;
2024-06-27 17:27:28 -04:00
// printf("Elog testing Fail\n");
2023-05-25 14:20:55 -04:00
if ( elogIP = = " " ) LogMsg ( " no elog IP " ) ;
if ( elogName = = " " ) LogMsg ( " no elog Name " ) ;
if ( elogUser = = " " ) LogMsg ( " no elog User name. Please set it in the programSettings.txt, line 6. " ) ;
if ( elogPWD = = " " ) LogMsg ( " no elog User pwd. Please set it in the programSettings.txt, line 7. " ) ;
2024-05-06 14:06:00 -04:00
if ( elogID < 0 ) LogMsg ( " Possible elog IP, Name, User name, pwd incorrect, or elog not installed. " ) ;
2023-05-25 14:20:55 -04:00
leElogIP - > setEnabled ( false ) ;
leElogName - > setEnabled ( false ) ;
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : WriteElog ( QString htmlText , QString subject , QString category , int runNumber ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-05-25 14:20:55 -04:00
//if( elogID < 0 ) return;
2024-06-27 17:27:28 -04:00
if ( ! chkElog - > isChecked ( ) ) return ;
2023-05-25 14:20:55 -04:00
if ( elogName = = " " ) return ;
if ( elogUser = = " " ) return ;
if ( elogPWD = = " " ) return ;
QStringList arg ;
2024-10-18 16:30:21 -04:00
arg < < " -h " < < elogIP < < " -p " < < elogPort < < " -l " < < elogName < < " -u " < < elogUser < < elogPWD < < " -a " < < " Author=FSUDAQ " ;
2023-05-25 14:20:55 -04:00
if ( runNumber > 0 ) arg < < " -a " < < " RunNo= " + QString : : number ( runNumber ) ;
if ( category ! = " " ) arg < < " -a " < < " Category= " + category ;
arg < < " -a " < < " Subject= " + subject
< < " -n " < < " 2 " < < htmlText ;
QProcess elogBash ( this ) ;
elogBash . start ( " elog " , arg ) ;
elogBash . waitForFinished ( ) ;
QString output = QString : : fromUtf8 ( elogBash . readAllStandardOutput ( ) ) ;
QRegularExpression regex ( " ID=( \\ d+) " ) ;
QRegularExpressionMatch match = regex . match ( output ) ;
if ( match . hasMatch ( ) ) {
QString id = match . captured ( 1 ) ;
elogID = id . toInt ( ) ;
} else {
elogID = - 1 ;
}
}
2024-06-26 16:40:40 -04:00
void FSUDAQ : : AppendElog ( QString appendHtmlText ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2024-06-27 17:27:28 -04:00
if ( ! chkElog - > isChecked ( ) ) return ;
2023-05-25 14:20:55 -04:00
if ( elogID < 1 ) return ;
if ( elogName = = " " ) return ;
QProcess elogBash ( this ) ;
QStringList arg ;
2024-10-18 16:30:21 -04:00
arg < < " -h " < < elogIP < < " -p " < < elogPort < < " -l " < < elogName < < " -u " < < elogUser < < elogPWD < < " -w " < < QString : : number ( elogID ) ;
2023-05-25 14:20:55 -04: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-18 16:30:21 -04:00
arg < < " -h " < < elogIP < < " -p " < < elogPort < < " -l " < < elogName < < " -u " < < elogUser < < elogPWD < < " -e " < < QString : : number ( elogID )
2023-05-25 14:20:55 -04:00
< < " -n " < < " 2 " < < originalHtml + " <br> " + appendHtmlText ;
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-05-24 17:10:36 -04:00
}
2023-04-14 16:12:52 -04:00
//***************************************************************
//***************************************************************
2024-06-26 16:40:40 -04:00
void FSUDAQ : : LogMsg ( QString msg ) {
2024-03-22 16:47:33 -04:00
DebugPrint ( " %s " , " FSUDAQ " ) ;
2023-04-14 16:12:52 -04: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 ) ;
}
QScrollBar * v = logInfo - > verticalScrollBar ( ) ;
v - > setValue ( v - > maximum ( ) ) ;
2023-05-30 13:57:45 -04:00
//qDebug() << outputStr;
2023-04-14 16:12:52 -04:00
logInfo - > repaint ( ) ;
2023-04-11 11:13:23 -04:00
}