From b21e0fe37bff4556521dae17ff20a1023f52032c Mon Sep 17 00:00:00 2001 From: "Ryan@SOLARIS_testStation" Date: Tue, 15 Oct 2024 10:59:26 -0400 Subject: [PATCH] added Save-runs-in-subFolders setting --- mainwindow.cpp | 184 ++++++++++++++++++++++------------------ mainwindow.h | 22 ++++- scripts/endRunScript.sh | 15 +++- 3 files changed, 137 insertions(+), 84 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index bdb15be..9560e94 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -125,15 +125,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ bnSyncHelper->setEnabled(false); connect(bnSyncHelper, &QPushButton::clicked, this, &MainWindow::OpenSyncHelper); - // QPushButton * bnEventBuilder = new QPushButton("Event Builder", this); - // bnEventBuilder->setEnabled(false); - - // QPushButton * bnHVController = new QPushButton("HV Controller", this); - // bnHVController->setEnabled(false); - - // QPushButton * bnTargetFanController = new QPushButton("Target Fan", this); - // bnTargetFanController->setEnabled(false); - layout1->addWidget(bnProgramSettings, 0, 0); layout1->addWidget(bnNewExp, 0, 1); layout1->addWidget(lExpName, 0, 2); @@ -147,10 +138,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ layout1->addWidget(bnDigiSettings, 2, 1); layout1->addWidget(bnSOLSettings, 2, 2, 1, 2); - // layout1->addWidget(bnEventBuilder, 3, 0); - // layout1->addWidget(bnHVController, 3, 1); - // layout1->addWidget(bnTargetFanController, 3, 2, 1, 2); - layout1->setColumnStretch(0, 2); layout1->setColumnStretch(1, 2); layout1->setColumnStretch(2, 1); @@ -169,7 +156,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ leRawDataPath = new QLineEdit(this); leRawDataPath->setReadOnly(true); leRawDataPath->setStyleSheet("background-color: #F3F3F3;"); - + bnOpenScalar = new QPushButton("Open Scalar", this); bnOpenScalar->setEnabled(false); connect(bnOpenScalar, &QPushButton::clicked, this, &MainWindow::OpenScaler); @@ -455,12 +442,20 @@ int MainWindow::StartACQ(){ //} if( chkSaveRun->isChecked() ){ - //Save setting to raw data with run ID - QString fileSetting = rawDataPath + "/" + expName + "_" + runIDStr + "XSetting_" + QString::number(digi[i]->GetSerialNumber()) + ".dat"; - digi[i]->SaveSettingsToFile(fileSetting.toStdString().c_str()); + QString runFolder = rawDataPath + "/"; + if( isSaveSubFolder ) { + runFolder += "run" + runIDStr + "/"; + CreateFolder(runFolder, "for " + runIDStr); + } + + //Save setting to raw data with run ID + QString fileSetting = runFolder + expName + "_" + runIDStr + "XSetting_" + QString::number(digi[i]->GetSerialNumber()) + ".dat"; // name should be [ExpName]_[runID]_[digiID]_[digiSerialNumber]_[acculmulate_count].sol - QString outFileName = rawDataPath + "/" + expName + "_" + runIDStr + "_" + QString::number(i).rightJustified(2, '0') + "_" + QString::number(digi[i]->GetSerialNumber()); + QString outFileName = runFolder + expName + "_" + runIDStr + "_" + QString::number(i).rightJustified(2, '0') + "_" + QString::number(digi[i]->GetSerialNumber()); + + + digi[i]->SaveSettingsToFile(fileSetting.toStdString().c_str()); qDebug() << outFileName; digi[i]->OpenOutFile(outFileName.toStdString());// overwrite } @@ -1328,7 +1323,7 @@ void MainWindow::ProgramSettingsPanel(){ QDialog dialog(this); dialog.setWindowTitle("Program Settings"); - dialog.setGeometry(0, 0, 700, 500); + dialog.setGeometry(0, 0, 700, 800); dialog.setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); QGridLayout * layout = new QGridLayout(&dialog); @@ -1356,9 +1351,14 @@ void MainWindow::ProgramSettingsPanel(){ helpInfo->appendHtml("

"); helpInfo->appendHtml(" Data Path is the path of the \ parents folder of data will store. "); - helpInfo->appendHtml(" Exp Name is the name of the experiment. \ + helpInfo->appendHtml(" Exp Name is the name of the experiment and Elog Folder. \ This set the exp. folder under the Data Path .\ - The experiment data will be saved under this folder. e.g. Data Path/Exp Name"); + The experiment data will be saved under this folder. e.g. Data Path/Exp Name."); + + helpInfo->appendHtml("

"); + helpInfo->appendHtml(" Save runs in sub-folders means \ + saving each run in indivuial subfolder. e.g. Data Path/Exp Name/runXXX."); + helpInfo->appendHtml("

"); helpInfo->appendHtml(" Digitizers IP List is the list of IP \ @@ -1394,15 +1394,11 @@ void MainWindow::ProgramSettingsPanel(){ QPushButton * bnDataPath = new QPushButton("browser", &dialog); layout->addWidget(bnDataPath, rowID, 3); connect(bnDataPath, &QPushButton::clicked, this, [=](){this->OpenDirectory(2);}); - //-------- root data Path - // rowID ++; - // QLabel *lbRootDataPath = new QLabel("Root Data Path", &dialog); - // lbRootDataPath->setAlignment(Qt::AlignRight | Qt::AlignCenter); - // layout->addWidget(lbRootDataPath, rowID, 0); - // lRootDataPath = new QLineEdit(rootDataPath, &dialog); layout->addWidget(lRootDataPath, rowID, 1, 1, 2); - - // QPushButton * bnRootDataPath = new QPushButton("browser", &dialog); layout->addWidget(bnRootDataPath, rowID, 3); - // connect(bnRootDataPath, &QPushButton::clicked, this, [=](){this->OpenDirectory(3);}); + //-------- Is Save single folder + rowID ++; + chkSaveSubFolder = new QCheckBox("Save runs in sub-folders", this); + chkSaveSubFolder->setChecked(isSaveSubFolder); + layout->addWidget(chkSaveSubFolder, rowID, 1); //-------- Exp Name Temp rowID ++; @@ -1462,6 +1458,20 @@ void MainWindow::ProgramSettingsPanel(){ layout->addWidget(lbElogIP, rowID, 0); lElogIP = new QLineEdit(ElogIP, &dialog); layout->addWidget(lElogIP, rowID, 1, 1, 2); + //-------- Elog User + rowID ++; + QLabel *lbElogUser = new QLabel("Elog User *", &dialog); + lbElogUser->setAlignment(Qt::AlignRight | Qt::AlignCenter); + layout->addWidget(lbElogUser, rowID, 0); + lElogUser = new QLineEdit(ElogUser, &dialog); layout->addWidget(lElogUser, rowID, 1, 1, 2); + + //-------- Elog User + rowID ++; + QLabel *lbElogPWD = new QLabel("Elog Password *", &dialog); + lbElogPWD->setAlignment(Qt::AlignRight | Qt::AlignCenter); + layout->addWidget(lbElogPWD, rowID, 0); + lElogPWD = new QLineEdit(ElogPWD, &dialog); layout->addWidget(lElogPWD, rowID, 1, 1, 2); + rowID ++; QPushButton *button1 = new QPushButton("OK and Save", &dialog); layout->addWidget(button1, rowID, 1); @@ -1532,6 +1542,19 @@ bool MainWindow::LoadProgramSettings(){ bool ret = false; + //initialized + masterExpDataPath = ""; + isSaveSubFolder = false; + expName = ""; + IPListStr = ""; + analysisPath = ""; + DatabaseIP = ""; + DatabaseName = ""; + DatabaseToken = ""; + ElogIP = ""; + ElogUser = ""; + ElogPWD = ""; + if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) { LogMsg("" + settingFile + " not found."); LogMsg("Please Open the Program Settings "); @@ -1545,32 +1568,38 @@ bool MainWindow::LoadProgramSettings(){ if( line.left(6) == "//----") break; switch (count){ - // case 0 : programSettingsPath = line; break; - case 0 : masterExpDataPath = line; break; - case 1 : expName = line; break; - case 2 : IPListStr = line; break; - case 3 : analysisPath = line; break; - case 4 : DatabaseIP = line; break; - case 5 : DatabaseName = line; break; - case 6 : DatabaseToken = line; break; - case 7 : ElogIP = line; break; + case 0 : masterExpDataPath = line; break; + case 1 : isSaveSubFolder = (line == "SubFolder" ? true : false); break; + case 2 : expName = line; break; + case 3 : IPListStr = line; break; + case 4 : analysisPath = line; break; + case 5 : DatabaseIP = line; break; + case 6 : DatabaseName = line; break; + case 7 : DatabaseToken = line; break; + case 8 : ElogIP = line; break; + case 9 : ElogUser = line; break; + case 10 : ElogPWD = line; break; } count ++; line = in.readLine(); + // printf("%d | %s \n", count, line.toStdString().c_str()); } - if( count == 7 ) { + if( count >= 3 ) { logMsgHTMLMode = false; // LogMsg("Setting File Path : " + programSettingsPath); - LogMsg(" Analysis Path : " + analysisPath); - LogMsg(" Database IP : " + DatabaseIP); - LogMsg(" Database Name : " + DatabaseName); - LogMsg(" Database Token : " + DatabaseToken); - LogMsg(" ElogIP : " + ElogIP); - LogMsg(" Exp Data Path : " + masterExpDataPath); - LogMsg(" Temp Exp. Name : " + expName); - LogMsg(" Digi. IP List : " + IPListStr); + LogMsg(" Analysis Path : " + analysisPath); + LogMsg(" Database IP : " + DatabaseIP); + LogMsg(" Database Name : " + DatabaseName); + LogMsg(" Database Token : " + maskText(DatabaseToken)); + LogMsg(" ElogIP : " + ElogIP); + LogMsg(" Elog User : " + ElogUser); + LogMsg(" Elog Password : " + maskText(ElogPWD)); + LogMsg(" Exp Data Path : " + masterExpDataPath); + LogMsg("Save Runs in SubFolders : " + QString(isSaveSubFolder ? "Yes" : "No") ); + LogMsg(" Exp. Name (Elog Name) : " + expName); + LogMsg(" Digi. IP List : " + IPListStr); logMsgHTMLMode = true; expDataPath = masterExpDataPath + "/" + expName; @@ -1654,6 +1683,7 @@ void MainWindow::SaveProgramSettings(){ // file.write((programSettingsPath+"\n").toStdString().c_str()); file.write((masterExpDataPath+"\n").toStdString().c_str()); + file.write( chkSaveSubFolder->isChecked() ? "SubFolder\n" : "SingleFolder\n" ); file.write((expName+"\n").toStdString().c_str()); file.write((IPListStr+"\n").toStdString().c_str()); file.write((analysisPath+"\n").toStdString().c_str()); @@ -1661,6 +1691,8 @@ void MainWindow::SaveProgramSettings(){ file.write((DatabaseName+"\n").toStdString().c_str()); file.write((DatabaseToken+"\n").toStdString().c_str()); file.write((ElogIP+"\n").toStdString().c_str()); + file.write((ElogUser+"\n").toStdString().c_str()); + file.write((ElogPWD+"\n").toStdString().c_str()); file.write("//------------end of file."); file.close(); @@ -2195,42 +2227,32 @@ void MainWindow::ChangeExperiment(const QString newExpName){ } +void MainWindow::CreateFolder(QString path, QString AdditionalMsg){ + + QDir dir(path); + if( !dir.exists()){ + if( dir.mkpath(path)){ + LogMsg("Created folder " + path + " " + AdditionalMsg ); + }else{ + LogMsg("Folder \"" + rawDataPath + "\" cannot be created. Access right problem? " ); + } + }else{ + LogMsg("Folder \"" + rawDataPath + "\" already exist." ); + } + +} + void MainWindow::CreateRawDataFolder(){ //----- create data folder - QDir dir(rawDataPath); - if( !dir.exists()){ - if( dir.mkpath(rawDataPath)){ - LogMsg("Created folder " + rawDataPath + " for storing raw data." ); - }else{ - LogMsg("" + rawDataPath + " cannot be created. Access right problem? " ); - } - }else{ - LogMsg("" + rawDataPath + " already exist." ); - } + CreateFolder(rawDataPath, "for storing raw data."); //----- create root data folder - QDir rootDir(rootDataPath); - if( !rootDir.exists()) { - if( rootDir.mkpath(rootDataPath) ){ - LogMsg("Created folder " + rootDataPath + " for storing root files."); - }else{ - LogMsg("" + rootDataPath + " cannot be created. Access right problem? " ); - } - }else{ - LogMsg("" + rootDataPath + " already exist." ); - } + CreateFolder(rootDataPath, "for storing root file."); //----- create analysis Folder - QDir anaDir; - if( !anaDir.exists(analysisPath)){ - if( anaDir.mkpath(analysisPath)){ - LogMsg("" + analysisPath + " created." ); - }else{ - LogMsg("" + analysisPath + " cannot be created. Access right problem?" ); - } - }else{ - LogMsg("" + analysisPath + " already exist."); + if( !analysisPath.isEmpty() ){ + CreateFolder(analysisPath, "for analysis."); } } @@ -2380,8 +2402,8 @@ void MainWindow::WriteElog(QString htmlText, QString subject, QString category, //TODO ===== user name and pwd load from a file. QStringList arg; - arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralSOLARIS" << "solaris" - << "-a" << "Author=\'General SOLARIS\'" ; + arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << ElogUser << ElogPWD + << "-a" << "Author=SOLARIS_DAQ" ; if( runNumber > 0 ) arg << "-a" << "RunNo=" + QString::number(runNumber); if( category != "" ) arg << "-a" << "Category=" + category; @@ -2410,7 +2432,7 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){ QProcess elogBash(this); QStringList arg; - arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralSOLARIS" << "solaris" << "-w" << QString::number(elogID); + arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << ElogUser << ElogPWD << "-w" << QString::number(elogID); //retrevie the elog elogBash.start("elog", arg); @@ -2427,7 +2449,7 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){ QString originalHtml = output.mid(index + separator.length()); arg.clear(); - arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralSOLARIS" << "solaris" << "-e" << QString::number(elogID) + arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << ElogUser << ElogPWD << "-e" << QString::number(elogID) << "-n" << "2" << originalHtml + "
" + appendHtmlText; if( screenID >= 0) { diff --git a/mainwindow.h b/mainwindow.h index c107d5b..5724e4a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -75,6 +75,7 @@ private slots: void CreateNewExperiment(const QString newExpName); void ChangeExperiment(const QString newExpName); void WriteExpNameSh(); + void CreateFolder(QString path, QString AdditionalMsg); void CreateRawDataFolder(); void CreateDataSymbolicLink(); @@ -115,6 +116,7 @@ private: QPushButton * bnDigiSettings; QPushButton * bnSOLSettings; + //@----- scope Scope * scope; QPushButton * bnOpenScope; @@ -166,7 +168,6 @@ private: QStringList detGroupName; //@----- Program settings - // QLineEdit * lSaveSettingPath; QLineEdit * lAnalysisPath; //for git QLineEdit * lExpDataPath; @@ -177,6 +178,11 @@ private: QLineEdit * lDatbaseName; QLineEdit * lDatbaseToken; QLineEdit * lElogIP; + QLineEdit * lElogUser; + QLineEdit * lElogPWD; + + QCheckBox * chkSaveSubFolder; + bool isSaveSubFolder; QStringList existGitBranches; @@ -192,6 +198,8 @@ private: QString DatabaseName; QString DatabaseToken; QString ElogIP; + QString ElogUser; + QString ElogPWD; //@------ experiment settings bool isGitExist; @@ -212,6 +220,18 @@ private: QPushButton * bnComment; void AppendComment(); + QString maskText(const QString &password) { + if (password.length() <= 3) { + return password; // No masking needed for short passwords + } else if (password.length() <= 10) { + QString maskedPassword = password.left(3); + maskedPassword += QString("*").repeated(password.length() - 3); + return maskedPassword; + } else { + return password.left(3) + QString("*").repeated(7); + } + } + }; diff --git a/scripts/endRunScript.sh b/scripts/endRunScript.sh index aec9618..8e2aec9 100755 --- a/scripts/endRunScript.sh +++ b/scripts/endRunScript.sh @@ -1,8 +1,19 @@ #!/bin/bash -l -echo "################# end Run Script" +echo "################# End-Run Script" #xterm -T endRunScript -hold -geometry 100x20+0+0 -sb -sl 1000 -e "Process_Run" "lastRun" -xterm -T endRunScript -geometry 100x20+0+0 -sb -sl 1000 -e "source ~/Analysis/SOLARIS.sh; Process_Run lastRun 2 0" +#xterm -T endRunScript -geometry 100x20+0+0 -sb -sl 1000 -e "source ~/Analysis/SOLARIS.sh; Process_Run lastRun 2 0" + +#master data path +dataPath=~/ExpData/SOLARISDAQ/Haha/ + +#load the runID from expName +source $dataPath/data_raw/expName.sh + +#format runID to 3 digit +runIDStr=$(printf "run%03d" $runID) + +cp $dataPath/ExpSetup.txt $dataPath/data_raw/$runIDStr/. echo "################# done" \ No newline at end of file