added Save-runs-in-subFolders setting

This commit is contained in:
Ryan Tang 2024-10-15 10:59:26 -04:00
parent 7092ceaa84
commit b21e0fe37b
3 changed files with 137 additions and 84 deletions

View File

@ -125,15 +125,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
bnSyncHelper->setEnabled(false); bnSyncHelper->setEnabled(false);
connect(bnSyncHelper, &QPushButton::clicked, this, &MainWindow::OpenSyncHelper); 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(bnProgramSettings, 0, 0);
layout1->addWidget(bnNewExp, 0, 1); layout1->addWidget(bnNewExp, 0, 1);
layout1->addWidget(lExpName, 0, 2); layout1->addWidget(lExpName, 0, 2);
@ -147,10 +138,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
layout1->addWidget(bnDigiSettings, 2, 1); layout1->addWidget(bnDigiSettings, 2, 1);
layout1->addWidget(bnSOLSettings, 2, 2, 1, 2); 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(0, 2);
layout1->setColumnStretch(1, 2); layout1->setColumnStretch(1, 2);
layout1->setColumnStretch(2, 1); layout1->setColumnStretch(2, 1);
@ -455,12 +442,20 @@ int MainWindow::StartACQ(){
//} //}
if( chkSaveRun->isChecked() ){ 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 // 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; qDebug() << outFileName;
digi[i]->OpenOutFile(outFileName.toStdString());// overwrite digi[i]->OpenOutFile(outFileName.toStdString());// overwrite
} }
@ -1328,7 +1323,7 @@ void MainWindow::ProgramSettingsPanel(){
QDialog dialog(this); QDialog dialog(this);
dialog.setWindowTitle("Program Settings"); dialog.setWindowTitle("Program Settings");
dialog.setGeometry(0, 0, 700, 500); dialog.setGeometry(0, 0, 700, 800);
dialog.setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); dialog.setWindowFlags(Qt::Dialog | Qt::WindowTitleHint);
QGridLayout * layout = new QGridLayout(&dialog); QGridLayout * layout = new QGridLayout(&dialog);
@ -1356,9 +1351,14 @@ void MainWindow::ProgramSettingsPanel(){
helpInfo->appendHtml("<p></p>"); helpInfo->appendHtml("<p></p>");
helpInfo->appendHtml("<font style=\"color : blue;\"> Data Path </font> is the path of the \ helpInfo->appendHtml("<font style=\"color : blue;\"> Data Path </font> is the path of the \
<b>parents folder</b> of data will store. "); <b>parents folder</b> of data will store. ");
helpInfo->appendHtml("<font style=\"color : blue;\"> Exp Name </font> is the name of the experiment. \ helpInfo->appendHtml("<font style=\"color : blue;\"> Exp Name </font> is the name of the experiment and <b>Elog Folder</b>. \
This set the exp. folder under the <font style=\"color : blue;\"> Data Path </font>.\ This set the exp. folder under the <font style=\"color : blue;\"> Data Path </font>.\
The experiment data will be saved under this folder. e.g. <font style=\"color : blue;\">Data Path</font>/<font style=\"color : blue;\">Exp Name</font>"); The experiment data will be saved under this folder. e.g. <font style=\"color : blue;\">Data Path/Exp Name</font>.");
helpInfo->appendHtml("<p></p>");
helpInfo->appendHtml("<font style=\"color : blue;\"> Save runs in sub-folders </font> means \
saving each run in indivuial subfolder. e.g. <font style=\"color : blue;\">Data Path/Exp Name/runXXX</font>.");
helpInfo->appendHtml("<p></p>"); helpInfo->appendHtml("<p></p>");
helpInfo->appendHtml("<font style=\"color : blue;\"> Digitizers IP List </font> is the list of IP \ helpInfo->appendHtml("<font style=\"color : blue;\"> Digitizers IP List </font> is the list of IP \
@ -1394,15 +1394,11 @@ void MainWindow::ProgramSettingsPanel(){
QPushButton * bnDataPath = new QPushButton("browser", &dialog); layout->addWidget(bnDataPath, rowID, 3); QPushButton * bnDataPath = new QPushButton("browser", &dialog); layout->addWidget(bnDataPath, rowID, 3);
connect(bnDataPath, &QPushButton::clicked, this, [=](){this->OpenDirectory(2);}); connect(bnDataPath, &QPushButton::clicked, this, [=](){this->OpenDirectory(2);});
//-------- root data Path //-------- Is Save single folder
// rowID ++; rowID ++;
// QLabel *lbRootDataPath = new QLabel("Root Data Path", &dialog); chkSaveSubFolder = new QCheckBox("Save runs in sub-folders", this);
// lbRootDataPath->setAlignment(Qt::AlignRight | Qt::AlignCenter); chkSaveSubFolder->setChecked(isSaveSubFolder);
// layout->addWidget(lbRootDataPath, rowID, 0); layout->addWidget(chkSaveSubFolder, rowID, 1);
// 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);});
//-------- Exp Name Temp //-------- Exp Name Temp
rowID ++; rowID ++;
@ -1462,6 +1458,20 @@ void MainWindow::ProgramSettingsPanel(){
layout->addWidget(lbElogIP, rowID, 0); layout->addWidget(lbElogIP, rowID, 0);
lElogIP = new QLineEdit(ElogIP, &dialog); layout->addWidget(lElogIP, rowID, 1, 1, 2); 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 ++; rowID ++;
QPushButton *button1 = new QPushButton("OK and Save", &dialog); QPushButton *button1 = new QPushButton("OK and Save", &dialog);
layout->addWidget(button1, rowID, 1); layout->addWidget(button1, rowID, 1);
@ -1532,6 +1542,19 @@ bool MainWindow::LoadProgramSettings(){
bool ret = false; bool ret = false;
//initialized
masterExpDataPath = "";
isSaveSubFolder = false;
expName = "";
IPListStr = "";
analysisPath = "";
DatabaseIP = "";
DatabaseName = "";
DatabaseToken = "";
ElogIP = "";
ElogUser = "";
ElogPWD = "";
if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) { if( !file.open(QIODevice::Text | QIODevice::ReadOnly) ) {
LogMsg("<b>" + settingFile + "</b> not found."); LogMsg("<b>" + settingFile + "</b> not found.");
LogMsg("Please Open the <font style=\"color : red;\">Program Settings </font>"); LogMsg("Please Open the <font style=\"color : red;\">Program Settings </font>");
@ -1545,32 +1568,38 @@ bool MainWindow::LoadProgramSettings(){
if( line.left(6) == "//----") break; if( line.left(6) == "//----") break;
switch (count){ switch (count){
// case 0 : programSettingsPath = line; break; case 0 : masterExpDataPath = line; break;
case 0 : masterExpDataPath = line; break; case 1 : isSaveSubFolder = (line == "SubFolder" ? true : false); break;
case 1 : expName = line; break; case 2 : expName = line; break;
case 2 : IPListStr = line; break; case 3 : IPListStr = line; break;
case 3 : analysisPath = line; break; case 4 : analysisPath = line; break;
case 4 : DatabaseIP = line; break; case 5 : DatabaseIP = line; break;
case 5 : DatabaseName = line; break; case 6 : DatabaseName = line; break;
case 6 : DatabaseToken = line; break; case 7 : DatabaseToken = line; break;
case 7 : ElogIP = line; break; case 8 : ElogIP = line; break;
case 9 : ElogUser = line; break;
case 10 : ElogPWD = line; break;
} }
count ++; count ++;
line = in.readLine(); line = in.readLine();
// printf("%d | %s \n", count, line.toStdString().c_str());
} }
if( count == 7 ) { if( count >= 3 ) {
logMsgHTMLMode = false; logMsgHTMLMode = false;
// LogMsg("Setting File Path : " + programSettingsPath); // LogMsg("Setting File Path : " + programSettingsPath);
LogMsg(" Analysis Path : " + analysisPath); LogMsg(" Analysis Path : " + analysisPath);
LogMsg(" Database IP : " + DatabaseIP); LogMsg(" Database IP : " + DatabaseIP);
LogMsg(" Database Name : " + DatabaseName); LogMsg(" Database Name : " + DatabaseName);
LogMsg(" Database Token : " + DatabaseToken); LogMsg(" Database Token : " + maskText(DatabaseToken));
LogMsg(" ElogIP : " + ElogIP); LogMsg(" ElogIP : " + ElogIP);
LogMsg(" Exp Data Path : " + masterExpDataPath); LogMsg(" Elog User : " + ElogUser);
LogMsg(" Temp Exp. Name : " + expName); LogMsg(" Elog Password : " + maskText(ElogPWD));
LogMsg(" Digi. IP List : " + IPListStr); 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; logMsgHTMLMode = true;
expDataPath = masterExpDataPath + "/" + expName; expDataPath = masterExpDataPath + "/" + expName;
@ -1654,6 +1683,7 @@ void MainWindow::SaveProgramSettings(){
// file.write((programSettingsPath+"\n").toStdString().c_str()); // file.write((programSettingsPath+"\n").toStdString().c_str());
file.write((masterExpDataPath+"\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((expName+"\n").toStdString().c_str());
file.write((IPListStr+"\n").toStdString().c_str()); file.write((IPListStr+"\n").toStdString().c_str());
file.write((analysisPath+"\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((DatabaseName+"\n").toStdString().c_str());
file.write((DatabaseToken+"\n").toStdString().c_str()); file.write((DatabaseToken+"\n").toStdString().c_str());
file.write((ElogIP+"\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.write("//------------end of file.");
file.close(); 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 <b>" + path + "</b> " + AdditionalMsg );
}else{
LogMsg("Folder \"<font style=\"color:red;\"><b>" + rawDataPath + "</b>\" cannot be created. Access right problem? </font>" );
}
}else{
LogMsg("Folder \"<b>" + rawDataPath + "</b>\" already exist." );
}
}
void MainWindow::CreateRawDataFolder(){ void MainWindow::CreateRawDataFolder(){
//----- create data folder //----- create data folder
QDir dir(rawDataPath); CreateFolder(rawDataPath, "for storing raw data.");
if( !dir.exists()){
if( dir.mkpath(rawDataPath)){
LogMsg("Created folder <b>" + rawDataPath + "</b> for storing raw data." );
}else{
LogMsg("<font style=\"color:red;\"><b>" + rawDataPath + "</b> cannot be created. Access right problem? </font>" );
}
}else{
LogMsg("<b>" + rawDataPath + "</b> already exist." );
}
//----- create root data folder //----- create root data folder
QDir rootDir(rootDataPath); CreateFolder(rootDataPath, "for storing root file.");
if( !rootDir.exists()) {
if( rootDir.mkpath(rootDataPath) ){
LogMsg("Created folder <b>" + rootDataPath + "</b> for storing root files.");
}else{
LogMsg("<font style=\"color:red;\"><b>" + rootDataPath + "</b> cannot be created. Access right problem? </font>" );
}
}else{
LogMsg("<b>" + rootDataPath + "</b> already exist." );
}
//----- create analysis Folder //----- create analysis Folder
QDir anaDir; if( !analysisPath.isEmpty() ){
if( !anaDir.exists(analysisPath)){ CreateFolder(analysisPath, "for analysis.");
if( anaDir.mkpath(analysisPath)){
LogMsg("<b>" + analysisPath + "</b> created." );
}else{
LogMsg("<font style=\"color:red;\"><b>" + analysisPath + "</b> cannot be created. Access right problem?</font>" );
}
}else{
LogMsg("<b>" + analysisPath + "</b> already exist.");
} }
} }
@ -2380,8 +2402,8 @@ void MainWindow::WriteElog(QString htmlText, QString subject, QString category,
//TODO ===== user name and pwd load from a file. //TODO ===== user name and pwd load from a file.
QStringList arg; QStringList arg;
arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralSOLARIS" << "solaris" arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << ElogUser << ElogPWD
<< "-a" << "Author=\'General SOLARIS\'" ; << "-a" << "Author=SOLARIS_DAQ" ;
if( runNumber > 0 ) arg << "-a" << "RunNo=" + QString::number(runNumber); if( runNumber > 0 ) arg << "-a" << "RunNo=" + QString::number(runNumber);
if( category != "" ) arg << "-a" << "Category=" + category; if( category != "" ) arg << "-a" << "Category=" + category;
@ -2410,7 +2432,7 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){
QProcess elogBash(this); QProcess elogBash(this);
QStringList arg; 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 //retrevie the elog
elogBash.start("elog", arg); elogBash.start("elog", arg);
@ -2427,7 +2449,7 @@ void MainWindow::AppendElog(QString appendHtmlText, int screenID){
QString originalHtml = output.mid(index + separator.length()); QString originalHtml = output.mid(index + separator.length());
arg.clear(); 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 + "<br>" + appendHtmlText; << "-n" << "2" << originalHtml + "<br>" + appendHtmlText;
if( screenID >= 0) { if( screenID >= 0) {

View File

@ -75,6 +75,7 @@ private slots:
void CreateNewExperiment(const QString newExpName); void CreateNewExperiment(const QString newExpName);
void ChangeExperiment(const QString newExpName); void ChangeExperiment(const QString newExpName);
void WriteExpNameSh(); void WriteExpNameSh();
void CreateFolder(QString path, QString AdditionalMsg);
void CreateRawDataFolder(); void CreateRawDataFolder();
void CreateDataSymbolicLink(); void CreateDataSymbolicLink();
@ -115,6 +116,7 @@ private:
QPushButton * bnDigiSettings; QPushButton * bnDigiSettings;
QPushButton * bnSOLSettings; QPushButton * bnSOLSettings;
//@----- scope //@----- scope
Scope * scope; Scope * scope;
QPushButton * bnOpenScope; QPushButton * bnOpenScope;
@ -166,7 +168,6 @@ private:
QStringList detGroupName; QStringList detGroupName;
//@----- Program settings //@----- Program settings
// QLineEdit * lSaveSettingPath;
QLineEdit * lAnalysisPath; //for git QLineEdit * lAnalysisPath; //for git
QLineEdit * lExpDataPath; QLineEdit * lExpDataPath;
@ -177,6 +178,11 @@ private:
QLineEdit * lDatbaseName; QLineEdit * lDatbaseName;
QLineEdit * lDatbaseToken; QLineEdit * lDatbaseToken;
QLineEdit * lElogIP; QLineEdit * lElogIP;
QLineEdit * lElogUser;
QLineEdit * lElogPWD;
QCheckBox * chkSaveSubFolder;
bool isSaveSubFolder;
QStringList existGitBranches; QStringList existGitBranches;
@ -192,6 +198,8 @@ private:
QString DatabaseName; QString DatabaseName;
QString DatabaseToken; QString DatabaseToken;
QString ElogIP; QString ElogIP;
QString ElogUser;
QString ElogPWD;
//@------ experiment settings //@------ experiment settings
bool isGitExist; bool isGitExist;
@ -212,6 +220,18 @@ private:
QPushButton * bnComment; QPushButton * bnComment;
void AppendComment(); 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);
}
}
}; };

View File

@ -1,8 +1,19 @@
#!/bin/bash -l #!/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 -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" echo "################# done"