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-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
MainWindow : : MainWindow ( QWidget * parent ) : QMainWindow ( parent ) {
setWindowTitle ( " FSU DAQ " ) ;
2023-05-09 12:16:08 -04:00
setGeometry ( 500 , 100 , 1100 , 500 ) ;
2023-04-11 11:13:23 -04:00
2023-04-14 16:12:52 -04:00
digi = nullptr ;
nDigi = 0 ;
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 ;
2023-05-17 17:40:32 -04:00
canvas = nullptr ;
2023-04-18 13:12:05 -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-04-17 15:17:25 -04:00
bnOpenDigitizers = new QPushButton ( " Open Digitizers " , this ) ;
2023-04-14 16:12:52 -04:00
layout - > addWidget ( bnOpenDigitizers , 0 , 0 ) ;
connect ( bnOpenDigitizers , & QPushButton : : clicked , this , & MainWindow : : OpenDigitizers ) ;
2023-04-17 15:17:25 -04:00
bnCloseDigitizers = new QPushButton ( " Close Digitizers " , this ) ;
2023-05-24 17:10:36 -04:00
layout - > addWidget ( bnCloseDigitizers , 1 , 0 ) ;
2023-04-17 15:17:25 -04:00
connect ( bnCloseDigitizers , & QPushButton : : clicked , this , & MainWindow : : 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 ) ;
2023-04-24 16:37:57 -04:00
connect ( bnDigiSettings , & QPushButton : : clicked , this , & MainWindow : : 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 ) ;
connect ( bnOpenScope , & QPushButton : : clicked , this , & MainWindow : : OpenScope ) ;
2023-05-22 17:00:11 -04:00
bnCanvas = new QPushButton ( " Online 1D Histograms " , this ) ;
2023-05-24 17:10:36 -04:00
layout - > addWidget ( bnCanvas , 1 , 2 ) ;
2023-05-17 17:40:32 -04:00
connect ( bnCanvas , & QPushButton : : clicked , this , & MainWindow : : OpenCanvas ) ;
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 ) ;
2023-05-24 17:10:36 -04: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
connect ( bnLock , & QPushButton : : clicked , this , [ = ] ( ) {
if ( leInfluxIP - > isReadOnly ( ) ) {
bnLock - > setText ( " Lock and Set " ) ;
leInfluxIP - > setReadOnly ( false ) ;
leDatabaseName - > setReadOnly ( false ) ;
leElogIP - > setReadOnly ( false ) ;
2023-05-25 14:20:55 -04:00
leElogName - > setReadOnly ( false ) ;
leInfluxIP - > setEnabled ( true ) ;
leDatabaseName - > setEnabled ( true ) ;
leElogIP - > setEnabled ( true ) ;
leElogName - > setEnabled ( true ) ;
2023-05-24 17:10:36 -04:00
leInfluxIP - > setStyleSheet ( " color : blue; " ) ;
leDatabaseName - > setStyleSheet ( " color : blue; " ) ;
leElogIP - > setStyleSheet ( " color : blue; " ) ;
2023-05-25 14:20:55 -04:00
leElogName - > setStyleSheet ( " color : blue; " ) ;
2023-05-24 17:10:36 -04:00
} else {
bnLock - > setText ( " Unlock " ) ;
leInfluxIP - > setReadOnly ( true ) ;
leDatabaseName - > setReadOnly ( true ) ;
leElogIP - > setReadOnly ( true ) ;
2023-05-25 14:20:55 -04:00
leElogName - > setReadOnly ( true ) ;
2023-05-24 17:10:36 -04:00
leInfluxIP - > setStyleSheet ( " " ) ;
leDatabaseName - > setStyleSheet ( " " ) ;
leElogIP - > setStyleSheet ( " " ) ;
2023-05-25 14:20:55 -04:00
leElogName - > setStyleSheet ( " " ) ;
2023-05-24 17:10:36 -04:00
influxIP = leInfluxIP - > text ( ) ;
dataBaseName = leDatabaseName - > text ( ) ;
elogIP = leElogIP - > text ( ) ;
2023-05-25 14:20:55 -04:00
elogName = leElogName - > text ( ) ;
2023-05-24 17:10:36 -04:00
SaveProgramSettings ( ) ;
SetUpInflux ( ) ;
2023-05-25 14:20:55 -04:00
if ( elogName ! = " " ) CheckElog ( ) ;
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 ) ;
connect ( bnSetDataPath , & QPushButton : : clicked , this , & MainWindow : : OpenDataPath ) ;
layout - > addWidget ( lbDataPath , rowID , 0 ) ;
2023-04-18 13:12:05 -04:00
layout - > addWidget ( leDataPath , rowID , 1 , 1 , 6 ) ;
layout - > addWidget ( bnSetDataPath , 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-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-05-18 17:14:24 -04:00
cbAutoRun = new RComboBox ( this ) ;
2023-04-18 13:12:05 -04:00
cbAutoRun - > addItem ( " Single Infinite " , 0 ) ;
cbAutoRun - > addItem ( " Single 30 mins " , 30 ) ;
cbAutoRun - > addItem ( " Single 60 mins " , 60 ) ;
cbAutoRun - > addItem ( " Repeat 60 mins " , - 60 ) ;
cbAutoRun - > setEnabled ( false ) ;
bnStartACQ = new QPushButton ( " Start ACQ " , this ) ;
connect ( bnStartACQ , & QPushButton : : clicked , this , & MainWindow : : StartACQ ) ;
bnStopACQ = new QPushButton ( " Stop ACQ " , this ) ;
connect ( bnStopACQ , & QPushButton : : clicked , this , & MainWindow : : StopACQ ) ;
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 ) ;
connect ( bnOpenScaler , & QPushButton : : clicked , this , & MainWindow : : 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 = " " ;
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 ( ) ;
2023-04-11 11:13:23 -04:00
}
MainWindow : : ~ MainWindow ( ) {
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
2023-04-24 16:37:57 -04:00
if ( digiSettings ) delete digiSettings ;
2023-05-17 17:40:32 -04:00
if ( canvas ) delete canvas ;
2023-04-19 16:21:14 -04:00
if ( scalar ) {
CleanUpScalar ( ) ;
scalarThread - > Stop ( ) ;
scalarThread - > quit ( ) ;
scalarThread - > exit ( ) ;
delete scalarThread ;
}
2023-04-18 13:12:05 -04:00
2023-05-24 16:04:32 -04:00
delete influx ;
2023-04-17 14:09:21 -04:00
}
//***************************************************************
//***************************************************************
2023-04-17 15:17:25 -04:00
void MainWindow : : OpenDataPath ( ) {
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 ( ) ;
bnStartACQ - > setEnabled ( true ) ;
2023-04-17 15:17:25 -04:00
} else {
leDataPath - > clear ( ) ;
2023-05-25 14:20:55 -04:00
rawDataPath = " " ;
bnStartACQ - > setEnabled ( false ) ;
2023-04-17 15:17:25 -04:00
}
2023-05-24 17:10:36 -04:00
SaveProgramSettings ( ) ;
2023-04-17 15:17:25 -04:00
}
2023-04-17 14:09:21 -04:00
void MainWindow : : LoadProgramSettings ( ) {
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 ;
if ( count = = 3 ) elogIP = line ;
2023-05-25 14:20:55 -04:00
if ( count = = 4 ) elogName = line ;
if ( count = = 5 ) elogUser = line ;
if ( count = = 6 ) 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 ;
LogMsg ( " Raw Data Path : " + rawDataPath ) ;
LogMsg ( " Influx IP : " + influxIP ) ;
LogMsg ( " Database Name : " + dataBaseName ) ;
LogMsg ( " Elog IP : " + elogIP ) ;
LogMsg ( " Elog Name : " + elogName ) ;
LogMsg ( " Elog User : " + elogUser ) ;
LogMsg ( " Elog PWD : " + elogPWD ) ;
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 {
LogMsg ( " <font style= \" color:red; \" ><b> " + rawDataPath + " </b> cannot be created. Access right problem? </font> " ) ;
}
} else {
LogMsg ( " <b> " + rawDataPath + " </b> already exist. " ) ;
}
2023-04-17 14:09:21 -04:00
LoadLastRunFile ( ) ;
}
}
void MainWindow : : SaveProgramSettings ( ) {
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 ( ) ) ;
file . write ( ( elogIP + " \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>. " ) ;
}
void MainWindow : : LoadLastRunFile ( ) {
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 ) ;
leRunID - > setText ( QString : : number ( runID ) ) ;
}
}
void MainWindow : : SaveLastRunFile ( ) {
QFile file ( rawDataPath + " /lastRun.sh " ) ;
file . open ( QIODevice : : Text | QIODevice : : WriteOnly ) ;
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
}
//***************************************************************
//***************************************************************
void MainWindow : : OpenDigitizers ( ) {
//sereach for digitizers
LogMsg ( " Searching digitizers via optical link.....Please wait " ) ;
logMsgHTMLMode = false ;
nDigi = 0 ;
std : : vector < std : : pair < int , int > > portList ; //boardID, portID
for ( int port = 0 ; port < MaxNPorts ; port + + ) {
for ( int board = 0 ; board < MaxNBoards ; board + + ) { /// max number of iasy chain
2023-04-19 13:41:43 -04:00
Digitizer dig ;
2023-04-14 16:12:52 -04:00
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 ( ) ) ) ;
} //else{
//LogMsg(QString("... Nothing at port: %1, board: %2.").arg(port).arg(board));
//}
2023-04-19 13:41:43 -04:00
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 ) {
LogMsg ( QString ( " Done seraching. No digitizer found. " ) ) ;
return ;
} else {
LogMsg ( QString ( " Done seraching. Found %1 digitizer(s). Opening digitizer(s).... " ) . arg ( nDigi ) ) ;
}
2023-04-14 16:12:52 -04:00
digi = new Digitizer * [ nDigi ] ;
readDataThread = new ReadDataThread * [ nDigi ] ;
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
///============== load settings
2023-05-17 17:12:35 -04:00
QString fileName = rawDataPath + " /Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " _ " + QString : : fromStdString ( digi [ i ] - > GetData ( ) - > DPPTypeStr ) + " .bin " ;
2023-05-02 15:43:05 -04:00
QFile file ( fileName ) ;
if ( ! file . open ( QIODevice : : Text | QIODevice : : ReadOnly ) ) {
2023-05-09 12:16:08 -04:00
if ( digi [ i ] - > GetDPPType ( ) = = V1730_DPP_PHA_CODE ) {
2023-05-12 16:06:32 -04:00
//digi[i]->ProgramPHABoard();
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PHA settings.");
LogMsg ( " <b> " + fileName + " </b> not found. " ) ;
2023-05-09 12:16:08 -04:00
}
if ( digi [ i ] - > GetDPPType ( ) = = V1730_DPP_PSD_CODE ) {
2023-05-12 16:06:32 -04:00
//digi[i]->ProgramPSDBoard();
//LogMsg("<b>" + fileName + "</b> not found. Program predefined PSD settings.");
LogMsg ( " <b> " + fileName + " </b> not found. " ) ;
2023-05-09 12:16:08 -04:00
}
2023-05-02 15:43:05 -04:00
} else {
LogMsg ( " Found <b> " + fileName + " </b> for digitizer settings. " ) ;
if ( digi [ i ] - > LoadSettingBinaryToMemory ( fileName . toStdString ( ) . c_str ( ) ) = = 0 ) {
2023-05-17 17:12:35 -04:00
LogMsg ( " Loaded settings file <b> " + fileName + " </b> for Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ) ;
2023-05-02 15:43:05 -04:00
digi [ i ] - > ProgramSettingsToBoard ( ) ;
} else {
LogMsg ( " Fail to Loaded settings file " + fileName + " for Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) ) ;
}
}
2023-05-12 16:06:32 -04:00
digi [ i ] - > ReadAllSettingsFromBoard ( true ) ;
2023-05-02 15:43:05 -04:00
2023-04-14 16:12:52 -04:00
readDataThread [ i ] = new ReadDataThread ( digi [ i ] , i ) ;
2023-04-17 11:52:06 -04:00
connect ( readDataThread [ i ] , & ReadDataThread : : sendMsg , this , & MainWindow : : 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
}
2023-05-23 17:02:39 -04:00
canvas = new Canvas ( digi , nDigi ) ;
2023-05-19 16:23:04 -04:00
histThread = new TimingThread ( this ) ;
2023-05-19 16:49:01 -04:00
histThread - > SetWaitTimeinSec ( 0.5 ) ;
2023-05-19 16:23:04 -04:00
connect ( histThread , & TimingThread : : timeUp , this , [ = ] ( ) {
if ( canvas = = nullptr ) return ;
canvas - > UpdateCanvas ( ) ;
} ) ;
2023-04-14 16:12:52 -04:00
LogMsg ( QString ( " Done. Opened %1 digitizer(s). " ) . arg ( nDigi ) ) ;
2023-04-19 13:41:43 -04:00
WaitForDigitizersOpen ( false ) ;
2023-05-12 16:06:32 -04:00
bnStopACQ - > setEnabled ( false ) ;
2023-04-19 13:41:43 -04:00
2023-05-25 14:20:55 -04:00
if ( rawDataPath = = " " ) bnStartACQ - > setEnabled ( false ) ;
2023-04-17 15:17:25 -04:00
SetupScalar ( ) ;
2023-04-14 16:12:52 -04:00
}
void MainWindow : : CloseDigitizers ( ) {
LogMsg ( " Closing Digitizer(s).... " ) ;
2023-04-17 15:17:25 -04:00
CleanUpScalar ( ) ;
2023-04-24 16:37:57 -04:00
if ( scope ) {
scope - > close ( ) ;
delete scope ;
scope = nullptr ;
}
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 + + ) {
digi [ i ] - > CloseDigitizer ( ) ;
delete digi [ i ] ;
2023-05-23 11:19:43 -04:00
if ( readDataThread [ i ] - > isRunning ( ) ) {
readDataThread [ i ] - > Stop ( ) ;
readDataThread [ i ] - > quit ( ) ;
readDataThread [ i ] - > wait ( ) ;
}
2023-04-14 16:12:52 -04:00
delete readDataThread [ i ] ;
}
delete [ ] digi ;
digi = nullptr ;
delete [ ] readDataThread ;
readDataThread = nullptr ;
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 ) ;
}
void MainWindow : : WaitForDigitizersOpen ( bool onOff ) {
bnOpenDigitizers - > setEnabled ( onOff ) ;
bnCloseDigitizers - > setEnabled ( ! onOff ) ;
bnOpenScope - > setEnabled ( ! onOff ) ;
bnDigiSettings - > setEnabled ( ! onOff ) ;
bnOpenScaler - > setEnabled ( ! onOff ) ;
bnStartACQ - > setEnabled ( ! onOff ) ;
bnStopACQ - > setEnabled ( ! onOff ) ;
chkSaveData - > setEnabled ( ! onOff ) ;
2023-05-19 16:49:01 -04:00
bnCanvas - > setEnabled ( ! onOff ) ;
2023-04-19 13:41:43 -04:00
2023-04-14 16:12:52 -04:00
}
//***************************************************************
//***************************************************************
2023-04-17 15:17:25 -04:00
void MainWindow : : SetupScalar ( ) {
2023-04-14 16:12:52 -04:00
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 ;
scalarThread = new TimingThread ( ) ;
connect ( scalarThread , & TimingThread : : timeUp , this , & MainWindow : : UpdateScalar ) ;
2023-05-24 16:04:32 -04:00
scalar - > setGeometry ( 0 , 0 , 10 + nDigi * 200 , 110 + MaxNChannels * 20 ) ;
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 ) ;
}
lbLastUpdateTime - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > removeWidget ( lbLastUpdateTime ) ;
scalarLayout - > addWidget ( lbLastUpdateTime , 0 , 1 , 1 , 1 + nDigi ) ;
lbScalarACQStatus - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > removeWidget ( lbScalarACQStatus ) ;
scalarLayout - > addWidget ( lbScalarACQStatus , 1 , 1 , 1 , 1 + nDigi ) ;
int rowID = 3 ;
2023-04-18 13:12:05 -04:00
///==== create the header row
for ( int ch = 0 ; ch < MaxNChannels ; 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 ) ;
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 ;
leTrigger [ iDigi ] = new QLineEdit * [ digi [ iDigi ] - > GetNChannels ( ) ] ;
leAccept [ iDigi ] = new QLineEdit * [ digi [ iDigi ] - > GetNChannels ( ) ] ;
2023-05-24 16:04:32 -04:00
uint32_t chMask = digi [ iDigi ] - > GetChannelMask ( ) ;
2023-04-17 15:17:25 -04:00
for ( int ch = 0 ; ch < MaxNChannels ; ch + + ) {
2023-04-18 13:12:05 -04:00
if ( ch = = 0 ) {
QLabel * lbDigi = new QLabel ( " Digi- " + QString : : number ( digi [ iDigi ] - > GetSerialNumber ( ) ) , scalar ) ;
lbDigi - > setAlignment ( Qt : : AlignCenter ) ;
scalarLayout - > addWidget ( lbDigi , rowID , 2 * iDigi + 1 , 1 , 2 ) ;
rowID + + ;
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 ) ;
}
rowID + + ;
2023-04-17 15:17:25 -04:00
leTrigger [ iDigi ] [ ch ] = new QLineEdit ( scalar ) ;
leTrigger [ iDigi ] [ ch ] - > setReadOnly ( true ) ;
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 ) ;
leAccept [ iDigi ] [ ch ] - > setAlignment ( Qt : : AlignRight ) ;
leAccept [ iDigi ] [ ch ] - > setStyleSheet ( " background-color: #F0F0F0; " ) ;
2023-05-24 16:04:32 -04:00
leTrigger [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > ch ) & 0x1 ) ;
leAccept [ iDigi ] [ ch ] - > setEnabled ( ( chMask > > ch ) & 0x1 ) ;
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-04-17 15:17:25 -04:00
void MainWindow : : CleanUpScalar ( ) {
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 + + ) {
for ( int ch = 0 ; ch < digi [ i ] - > GetNChannels ( ) ; ch + + ) {
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__ ) ;
}
void MainWindow : : OpenScalar ( ) {
scalar - > show ( ) ;
}
void MainWindow : : UpdateScalar ( ) {
2023-04-19 16:21:14 -04:00
if ( digi = = nullptr ) return ;
2023-05-17 16:16:48 -04:00
if ( scalar = = nullptr ) return ;
2023-05-24 16:04:32 -04:00
//if( !scalar->isVisible() ) return;
2023-04-19 16:21:14 -04:00
lbLastUpdateTime - > setText ( " Last update: " + QDateTime : : currentDateTime ( ) . toString ( " MM.dd hh:mm:ss " ) ) ;
2023-05-22 17:00:11 -04:00
//printf("----------------------\n");
2023-05-25 14:20:55 -04:00
uint64_t totalFileSize = 0 ;
2023-04-19 16:21:14 -04:00
for ( unsigned int iDigi = 0 ; iDigi < nDigi ; iDigi + + ) {
2023-05-22 17:00:11 -04:00
digiMTX [ iDigi ] . lock ( ) ;
2023-05-25 14:20:55 -04:00
if ( chkSaveData - > isChecked ( ) ) totalFileSize + = digi [ iDigi ] - > GetData ( ) - > GetTotalFileSize ( ) ;
2023-04-19 16:21:14 -04:00
for ( int i = 0 ; i < digi [ iDigi ] - > GetNChannels ( ) ; i + + ) {
2023-05-24 16:04:32 -04:00
if ( digi [ iDigi ] - > GetChannelOnOff ( i ) = = true ) {
//printf(" %3d %2d | %7.2f %7.2f \n", digi[iDigi]->GetSerialNumber(), i, digi[iDigi]->GetData()->TriggerRate[i], digi[iDigi]->GetData()->NonPileUpRate[i]);
leTrigger [ iDigi ] [ i ] - > setText ( QString : : number ( digi [ iDigi ] - > GetData ( ) - > TriggerRate [ i ] , ' f ' , 2 ) ) ;
leAccept [ iDigi ] [ i ] - > setText ( QString : : number ( digi [ iDigi ] - > GetData ( ) - > NonPileUpRate [ i ] , ' f ' , 2 ) ) ;
if ( influx ) {
influx - > AddDataPoint ( " Rate,Bd= " + std : : to_string ( digi [ iDigi ] - > GetSerialNumber ( ) ) + " ,Ch= " + QString : : number ( i ) . rightJustified ( 2 , ' 0 ' ) . toStdString ( ) + " value= " + QString : : number ( digi [ iDigi ] - > GetData ( ) - > TriggerRate [ i ] , ' f ' , 2 ) . toStdString ( ) ) ;
}
}
2023-04-19 16:21:14 -04:00
}
2023-05-22 17:00:11 -04:00
digiMTX [ iDigi ] . unlock ( ) ;
2023-04-19 16:21:14 -04:00
}
2023-04-17 15:17:25 -04:00
2023-05-24 16:04:32 -04:00
if ( influx ) {
2023-05-25 14:20:55 -04:00
if ( chkSaveData - > isChecked ( ) ) influx - > AddDataPoint ( " FileSize value= " + std : : to_string ( totalFileSize ) ) ;
2023-05-24 17:10:36 -04:00
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
2023-05-24 16:04:32 -04:00
influx - > ClearDataPointsBuffer ( ) ;
}
2023-04-17 15:17:25 -04:00
}
//***************************************************************
//***************************************************************
2023-04-14 16:12:52 -04:00
void MainWindow : : StartACQ ( ) {
if ( digi = = nullptr ) return ;
2023-04-19 16:21:14 -04:00
bool commentResult = true ;
if ( chkSaveData - > isChecked ( ) ) commentResult = CommentDialog ( true ) ;
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-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-04-14 16:12:52 -04:00
for ( unsigned int i = 0 ; i < nDigi ; i + + ) {
2023-05-16 14:31:19 -04:00
if ( chkSaveData - > isChecked ( ) ) {
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-05-23 14:52:23 -04:00
digi [ i ] - > GetData ( ) - > SetSaveWaveToMemory ( false ) ;
2023-04-14 16:12:52 -04:00
digi [ i ] - > StartACQ ( ) ;
readDataThread [ i ] - > start ( ) ;
}
2023-04-19 16:21:14 -04:00
if ( chkSaveData - > isChecked ( ) ) SaveLastRunFile ( ) ;
2023-05-22 17:00:11 -04:00
2023-04-19 16:21:14 -04:00
scalarThread - > 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
2023-05-23 17:02:39 -04:00
if ( canvas ! = nullptr ) histThread - > start ( ) ;
2023-05-19 16:23:04 -04:00
2023-04-19 18:08:20 -04:00
bnStartACQ - > setEnabled ( false ) ;
bnStopACQ - > setEnabled ( true ) ;
2023-05-16 14:31:19 -04:00
bnOpenScope - > setEnabled ( false ) ;
2023-05-25 14:20:55 -04:00
{ //^=== elog and database
if ( influx ) {
influx - > AddDataPoint ( " RunID value= " + std : : to_string ( runID ) ) ;
influx - > AddDataPoint ( " SavingData,ExpName= " + elogName . toStdString ( ) + " value=1 " ) ;
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
}
if ( elogID > 0 & & chkSaveData - > isChecked ( ) ) {
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 ) ;
}
}
2023-04-14 16:12:52 -04:00
}
void MainWindow : : StopACQ ( ) {
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 ) ) ;
} 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-05-17 16:16:48 -04:00
LogMsg ( " Digi- " + QString : : number ( digi [ i ] - > GetSerialNumber ( ) ) + " is stoping ACQ. " ) ;
2023-04-14 16:12:52 -04:00
if ( readDataThread [ i ] - > isRunning ( ) ) {
2023-05-22 17:00:11 -04:00
readDataThread [ i ] - > Stop ( ) ;
2023-04-14 16:12:52 -04:00
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-04-14 16:12:52 -04:00
}
2023-04-19 16:21:14 -04:00
if ( scalarThread - > isRunning ( ) ) {
scalarThread - > Stop ( ) ;
scalarThread - > quit ( ) ;
scalarThread - > wait ( ) ;
}
2023-05-19 16:23:04 -04:00
if ( histThread - > isRunning ( ) ) {
histThread - > Stop ( ) ;
histThread - > quit ( ) ;
histThread - > wait ( ) ;
}
2023-04-14 16:12:52 -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 ) ;
bnStopACQ - > setEnabled ( false ) ;
2023-05-16 14:31:19 -04:00
bnOpenScope - > setEnabled ( true ) ;
2023-05-25 14:20:55 -04:00
{ //^=== elog and database
if ( influx ) {
influx - > AddDataPoint ( " SavingData,ExpName= " + elogName . toStdString ( ) + " value=0 " ) ;
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
}
if ( elogID > 0 & & chkSaveData - > isChecked ( ) ) {
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 ) ;
}
}
2023-04-14 16:12:52 -04:00
}
2023-04-11 11:13:23 -04:00
2023-05-22 17:00:11 -04:00
void MainWindow : : AutoRun ( ) { //TODO
2023-04-18 13:12:05 -04:00
}
bool MainWindow : : CommentDialog ( bool isStartRun ) {
if ( isStartRun ) runID + + ;
QString runIDStr = QString : : number ( runID ) . rightJustified ( 3 , ' 0 ' ) ;
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 ) ;
QLineEdit * lineEdit = new QLineEdit ( dOpen ) ;
QPushButton * button1 = new QPushButton ( " OK " , dOpen ) ;
QPushButton * button2 = new QPushButton ( " Cancel " , dOpen ) ;
vlayout - > addWidget ( label , 0 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( lineEdit , 1 , 0 , 1 , 2 ) ;
vlayout - > addWidget ( button1 , 2 , 0 ) ;
vlayout - > addWidget ( button2 , 2 , 1 ) ;
connect ( button1 , & QPushButton : : clicked , dOpen , & QDialog : : accept ) ;
connect ( button2 , & QPushButton : : clicked , dOpen , & QDialog : : reject ) ;
int result = dOpen - > exec ( ) ;
if ( result = = QDialog : : Accepted ) {
if ( isStartRun ) {
startComment = lineEdit - > text ( ) ;
if ( startComment = = " " ) startComment = " No commet was typed. " ;
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 ;
}
void MainWindow : : WriteRunTimestamp ( bool isStartRun ) {
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 ) {
file . write ( ( " Start Run | " + QString : : number ( runID ) + " | " + dateTime + " | " + startComment + " \n " ) . toStdString ( ) . c_str ( ) ) ;
} else {
file . write ( ( " Stop Run | " + QString : : number ( runID ) + " | " + dateTime + " | " + stopComment + " \n " ) . toStdString ( ) . c_str ( ) ) ;
}
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 ( ) ;
}
}
//***************************************************************
//***************************************************************
void MainWindow : : OpenScope ( ) {
if ( scope = = nullptr ) {
scope = new Scope ( digi , nDigi , readDataThread ) ;
2023-04-20 18:15:30 -04:00
connect ( scope , & Scope : : SendLogMsg , this , & MainWindow : : LogMsg ) ;
2023-05-16 14:31:19 -04:00
connect ( scope , & Scope : : CloseWindow , this , [ = ] ( ) {
bnStartACQ - > setEnabled ( true ) ;
bnStopACQ - > setEnabled ( false ) ;
} ) ;
2023-05-17 16:16:48 -04:00
connect ( scope , & Scope : : TellACQOnOff , this , [ = ] ( bool onOff ) {
2023-05-19 16:49:01 -04:00
if ( scope ) {
if ( onOff ) {
lbScalarACQStatus - > setText ( " <font style= \" color: green; \" ><b>ACQ On</b></font> " ) ;
} else {
lbScalarACQStatus - > setText ( " <font style= \" color: red; \" ><b>ACQ Off</b></font> " ) ;
}
}
if ( canvas ) {
if ( onOff ) {
histThread - > start ( ) ;
} else {
if ( histThread - > isRunning ( ) ) {
histThread - > Stop ( ) ;
histThread - > quit ( ) ;
histThread - > wait ( ) ;
}
}
2023-05-17 16:16:48 -04:00
}
} ) ;
connect ( scope , & Scope : : UpdateScaler , this , & MainWindow : : UpdateScalar ) ;
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 ) ;
bnStopACQ - > setEnabled ( false ) ;
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
//***************************************************************
//***************************************************************
void MainWindow : : OpenDigiSettings ( ) {
2023-04-18 13:12:05 -04:00
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 ) ;
2023-04-24 16:37:57 -04:00
//connect(scope, &Scope::SendLogMsg, this, &MainWindow::LogMsg);
2023-05-23 17:02:39 -04:00
connect ( digiSettings , & DigiSettingsPanel : : UpdateOtherPanels , this , [ = ] ( ) { UpdateAllPanels ( 2 ) ; } ) ;
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
//***************************************************************
//***************************************************************
void MainWindow : : OpenCanvas ( ) {
if ( canvas = = nullptr ) {
2023-05-18 17:14:24 -04:00
canvas = new Canvas ( digi , nDigi ) ;
2023-05-17 17:40:32 -04:00
canvas - > show ( ) ;
} else {
canvas - > show ( ) ;
canvas - > activateWindow ( ) ;
}
}
2023-05-23 17:02:39 -04:00
//***************************************************************
//***************************************************************
void MainWindow : : UpdateAllPanels ( int panelID ) {
//panelID is the source panel that call
// scope = 1;
// digiSetting = 2;
if ( panelID = = 1 ) { // from scope
if ( digiSettings & & digiSettings - > isVisible ( ) ) digiSettings - > UpdatePanelFromMemory ( ) ;
}
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 + + ) {
uint32_t chMask = digi [ iDigi ] - > GetChannelMask ( ) ;
for ( int i = 0 ; i < digi [ iDigi ] - > GetNChannels ( ) ; i + + ) {
leTrigger [ iDigi ] [ i ] - > setEnabled ( ( chMask > > i ) & 0x1 ) ;
leAccept [ iDigi ] [ i ] - > setEnabled ( ( chMask > > i ) & 0x1 ) ;
}
}
}
2023-05-23 17:02:39 -04:00
}
}
2023-05-24 17:10:36 -04:00
//***************************************************************
//***************************************************************
void MainWindow : : SetUpInflux ( ) {
if ( influxIP = = " " ) return ;
if ( influx ) {
delete influx ;
influx = nullptr ;
}
influx = new InfluxDB ( influxIP . toStdString ( ) , false ) ;
if ( influx - > TestingConnection ( ) ) {
LogMsg ( " <font style= \" color : green; \" > InfluxDB URL (<b> " + influxIP + " </b>) is Valid </font> " ) ;
//==== chck database exist
//LogMsg("List of database:");
std : : vector < std : : string > databaseList = influx - > GetDatabaseList ( ) ;
bool foundDatabase = false ;
for ( int i = 0 ; i < ( int ) databaseList . size ( ) ; i + + ) {
if ( databaseList [ i ] = = dataBaseName . toStdString ( ) ) foundDatabase = true ;
//LogMsg(QString::number(i) + "|" + QString::fromStdString(databaseList[i]));
}
if ( foundDatabase ) {
LogMsg ( " <font style= \" color : green; \" > Database <b> " + dataBaseName + " </b> found. " ) ;
influx - > AddDataPoint ( " ProgramStart value=1 " ) ;
influx - > WriteData ( dataBaseName . toStdString ( ) ) ;
influx - > ClearDataPointsBuffer ( ) ;
if ( influx - > IsWriteOK ( ) ) {
LogMsg ( " <font style= \" color : green; \" >test write database OK.</font> " ) ;
} else {
LogMsg ( " <font style= \" color : red; \" >test write database FAIL.</font> " ) ;
}
} else {
LogMsg ( " <font style= \" color : red; \" > Database <b> " + dataBaseName + " </b> NOT found. " ) ;
delete influx ;
influx = 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 ) ;
}
}
void MainWindow : : CheckElog ( ) {
if ( elogIP ! = " " & & elogName ! = " " & & elogUser ! = " " & & elogPWD ! = " " ) {
WriteElog ( " Testing communication. " , " Testing communication. " , " Other " , 0 ) ;
AppendElog ( " test append elog. " ) ;
}
if ( elogID > = 0 ) {
LogMsg ( " Elog testing OK. " ) ;
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 " ) ;
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. " ) ;
if ( elogID < 0 ) LogMsg ( " Possible elog IP, Name, User name, or pwd incorrect " ) ;
leElogIP - > setEnabled ( false ) ;
leElogName - > setEnabled ( false ) ;
}
void MainWindow : : WriteElog ( QString htmlText , QString subject , QString category , int runNumber ) {
//if( elogID < 0 ) return;
if ( elogName = = " " ) return ;
if ( elogUser = = " " ) return ;
if ( elogPWD = = " " ) return ;
QStringList arg ;
arg < < " -h " < < elogIP < < " -p " < < " 8080 " < < " -l " < < elogName < < " -u " < < elogUser < < elogPWD < < " -a " < < " Author=FSUDAQ " ;
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 ;
}
}
void MainWindow : : AppendElog ( QString appendHtmlText ) {
if ( elogID < 1 ) return ;
if ( elogName = = " " ) return ;
QProcess elogBash ( this ) ;
QStringList arg ;
arg < < " -h " < < elogIP < < " -p " < < " 8080 " < < " -l " < < elogName < < " -u " < < elogUser < < elogPWD < < " -w " < < QString : : number ( elogID ) ;
//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 ( ) ;
arg < < " -h " < < elogIP < < " -p " < < " 8080 " < < " -l " < < elogName < < " -u " < < elogUser < < elogPWD < < " -e " < < QString : : number ( elogID )
< < " -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
//***************************************************************
//***************************************************************
void MainWindow : : LogMsg ( QString msg ) {
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-23 14:52:23 -04:00
qDebug ( ) < < outputStr ;
2023-04-14 16:12:52 -04:00
logInfo - > repaint ( ) ;
2023-04-11 11:13:23 -04:00
}