diff --git a/.gitignore b/.gitignore index 869cd46..8e86b85 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ FSUDAQ_Qt6 test test_indep +programSettings.txt + +data *~ *.autosave diff --git a/mainWindow.C b/mainWindow.C index b92fe6a..9194687 100644 --- a/mainWindow.C +++ b/mainWindow.C @@ -61,6 +61,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ lbDataPath->setAlignment(Qt::AlignRight | Qt::AlignCenter); leDataPath = new QLineEdit(this); leDataPath->setEnabled(false); + leDataPath->setStyleSheet("color : black;"); QPushButton * bnSetDataPath = new QPushButton("Set Path", this); connect(bnSetDataPath, &QPushButton::clicked, this, &MainWindow::OpenDataPath); @@ -75,8 +76,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ QLabel * lbRunID = new QLabel("Run No. :", this); lbRunID->setAlignment(Qt::AlignRight | Qt::AlignCenter); - QLineEdit * leRunID = new QLineEdit(this); + leRunID = new QLineEdit(this); leRunID->setEnabled(false); + leRunID->setStyleSheet("color : black;"); QPushButton * bnOpenScaler = new QPushButton("Scalar", this); @@ -131,11 +133,123 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ LogMsg("Welcome to FSU DAQ."); + rawDataPath = ""; + prefix = "temp"; + runID = 0; + elogID = 0; + programSettingsFilePath = QDir::current().absolutePath() + "/programSettings.txt"; + LoadProgramSettings(); + + } MainWindow::~MainWindow(){ if( digi ) CloseDigitizers(); + SaveProgramSettings(); + +} + +//*************************************************************** +//*************************************************************** + +void MainWindow::LoadProgramSettings(){ + + LogMsg("Loading " + programSettingsFilePath + " for Program Settings."); + QFile file(programSettingsFilePath); + + if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) { + LogMsg("" + programSettingsFilePath + " 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; + count ++; + line = in.readLine(); + } + + //looking for the lastRun.sh for + leDataPath->setText(rawDataPath); + LoadLastRunFile(); + } + +} + +void MainWindow::SaveProgramSettings(){ + + rawDataPath = leDataPath->text(); + + QFile file(programSettingsFilePath); + + file.open(QIODevice::Text | QIODevice::WriteOnly); + + file.write((rawDataPath+"\n").toStdString().c_str()); + file.write("//------------end of file."); + + file.close(); + LogMsg("Saved program settings to "+ programSettingsFilePath + "."); + +} + +void MainWindow::LoadLastRunFile(){ + + QFile file(rawDataPath + "/lastRun.sh"); + + if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) { + LogMsg("" + rawDataPath + "/lastRun.sh 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 "+ rawDataPath + "/lastRun.sh."); } @@ -220,12 +334,14 @@ void MainWindow::StartACQ(){ if( digi == nullptr ) return; for( unsigned int i = 0; i < nDigi ; i++){ - digi[i]->GetData()->OpenSaveFile("haha"); + digi[i]->GetData()->OpenSaveFile((rawDataPath + "/" + prefix).toStdString()); digi[i]->StartACQ(); readDataThread[i]->SetSaveData(true); readDataThread[i]->start(); } + SaveLastRunFile(); + } void MainWindow::StopACQ(){ diff --git a/mainWindow.h b/mainWindow.h index d0fcbc2..81591ec 100644 --- a/mainWindow.h +++ b/mainWindow.h @@ -20,6 +20,11 @@ public: private slots: + void LoadProgramSettings(); + void SaveProgramSettings(); + void LoadLastRunFile(); + void SaveLastRunFile(); + void OpenDigitizers(); void CloseDigitizers(); @@ -33,6 +38,12 @@ private: Digitizer ** digi; unsigned int nDigi; + QString programSettingsFilePath; + QString rawDataPath; + QString prefix; + unsigned int runID; + unsigned int elogID; + //@----- log msg QPlainTextEdit * logInfo; void LogMsg(QString msg); @@ -42,6 +53,7 @@ private: QLineEdit * leDataPath; QLineEdit * lePrefix; QLineEdit * leComment; + QLineEdit * leRunID; //@----- Scalar QMainWindow * scalar;