diff --git a/mainwindow.cpp b/mainwindow.cpp index 1e114d9..630a54c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -305,10 +305,10 @@ MainWindow::~MainWindow(){ LogMsg("Closing SOLARIS DAQ."); - QDir dir(analysisPath + "/working/Logs/"); + QDir dir(rawDataPath + "/Logs/"); if( !dir.exists() ) dir.mkpath("."); - QFile file(analysisPath + "/working/Logs/Log_" + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".dat"); + QFile file(rawDataPath + "/Logs/Log_" + QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss") + ".dat"); printf("-------- Save log msg to %s\n", file.fileName().toStdString().c_str()); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream stream(&file); @@ -1324,7 +1324,7 @@ void MainWindow::ProgramSettingsPanel(){ QDialog dialog(this); dialog.setWindowTitle("Program Settings"); - dialog.setGeometry(0, 0, 700, 530); + dialog.setGeometry(0, 0, 700, 600); dialog.setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); QGridLayout * layout = new QGridLayout(&dialog); @@ -1344,6 +1344,8 @@ void MainWindow::ProgramSettingsPanel(){ helpInfo->appendHtml("

"); helpInfo->appendHtml(" Analysis Path is the path of \ the folder of the analysis code. Can be omitted."); + + helpInfo->appendHtml("

"); helpInfo->appendHtml(" Data Path is the path of the \ parents folder of data will store. e.g. /mnt/data0/, \ experiment data will be saved under this folder. e.g. /mnt/data0/exp1"); @@ -1351,8 +1353,6 @@ void MainWindow::ProgramSettingsPanel(){ This set the exp. folder under the Data Path .\ This will override by New/Change/Reload Exp"); - helpInfo->appendHtml("

"); - helpInfo->appendHtml("These 2 paths will be used when New/Change/Reload Exp "); helpInfo->appendHtml("

"); helpInfo->appendHtml(" Digitizers IP List is the list of IP \ digi of the digitizers IP. Break by \",\", continue by \"-\". e.g. 192.168.0.100,102 for 2 digitizers, or 192.168.0.100-102 for 3 digitizers."); @@ -1508,6 +1508,8 @@ bool MainWindow::LoadProgramSettings(){ rawDataPath = expDataPath + "/" + expName + "/data_raw/"; rootDataPath = expDataPath + "/" + expName + "/root_data/"; + + leExpName->setText(expName); ret = true; }else{ @@ -1518,14 +1520,47 @@ bool MainWindow::LoadProgramSettings(){ if( ret ){ - DecodeIPList(); - SetupInflux(); - CheckElog(); + //CHeck data path exist + QDir dir(rawDataPath); - leRawDataPath->setText(rawDataPath); - leExpName->setText(expName); + if (!dir.exists()) { + LogMsg("Raw data path " + rawDataPath + " does not exist."); + bnProgramSettings->setStyleSheet("color: red;"); + bnOpenDigitizers->setEnabled(false); + bnNewExp->setEnabled(false); + return false; + }else{ + QFileInfo dirInfo(dir.absolutePath()); + if( !dirInfo.isWritable() ){ + LogMsg("Raw data path " + rawDataPath + " is not writable."); + bnProgramSettings->setStyleSheet("color: red;"); + bnOpenDigitizers->setEnabled(false); + bnNewExp->setEnabled(false); + return false; + }else{ + leRawDataPath->setText(rawDataPath); + leExpName->setText(expName); + } + } - if(analysisPath.isEmpty()) bnNewExp->setEnabled(false); + if( !IPListStr.isEmpty() ){ + bnOpenDigitizers->setEnabled(true); + DecodeIPList(); + SetupInflux(); + CheckElog(); + }else{ + LogMsg("Digitizer IP list is empty."); + bnProgramSettings->setStyleSheet("color: red;"); + bnOpenDigitizers->setEnabled(false); + return false; + } + + if(analysisPath.isEmpty()) { + LogMsg("Analysis Path is empty."); + bnNewExp->setEnabled(false); + bnNewExp->setStyleSheet(""); + return false; + } return true; @@ -1548,7 +1583,9 @@ void MainWindow::SaveProgramSettings(){ programSettingsPath = lSaveSettingPath->text(); analysisPath = lAnalysisPath->text(); expDataPath = lExpDataPath->text(); - expName = leExpName->text(); + expName = lExpNameTemp->text(); + + if( programSettingsPath.isEmpty() ) return; QFile file(programSettingsPath + "/programSettings.txt"); @@ -1567,22 +1604,56 @@ void MainWindow::SaveProgramSettings(){ file.close(); LogMsg("Saved program settings to "+programSettingsPath + "/programSettings.txt."); + bnProgramSettings->setStyleSheet(""); bnNewExp->setEnabled(true); - bnOpenDigitizers->setEnabled(true); - DecodeIPList(); + if( !IPListStr.isEmpty() ){ + DecodeIPList(); + bnOpenDigitizers->setEnabled(true); + }else{ + bnProgramSettings->setStyleSheet("color: red;"); + LogMsg("Digitizer IP list is empty."); + } + SetupInflux(); CheckElog(); rawDataPath = expDataPath + "/" + expName + "/data_raw/"; rootDataPath = expDataPath + "/" + expName + "/root_data/"; - leRawDataPath->setText(rawDataPath); leExpName->setText(expName); + //check rawDataPath exit, if not create + QDir dirRawData(rawDataPath); + if (!dirRawData.exists()) { + // Attempt to create the directory + if (dirRawData.mkpath(rawDataPath)) { + LogMsg("Create Raw Data Directory : " + rawDataPath); + leRawDataPath->setText(rawDataPath); + } else { + LogMsg("Failed to create Raw Data Directory : " + rawDataPath + ""); + bnProgramSettings->setStyleSheet("color: red;"); + leRawDataPath->setText("Cannot create folder : " + rawDataPath + "!!!!"); + return; + } + } else { + LogMsg("Raw Data Directory : " + rawDataPath + " | already exist."); + } + + QDir dirRootData(rootDataPath); + if (!dirRootData.exists()) { + // Attempt to create the directory + if (dirRootData.mkpath(rootDataPath)) { + LogMsg("Create Root Data Directory : " + rootDataPath); + } else { + LogMsg("Failed to create Root Data Directory : " + rootDataPath); + } + } else { + LogMsg("Root Data Directory : " + rootDataPath + " | already exist."); + } + if(analysisPath.isEmpty()) bnNewExp->setEnabled(false); - // LoadExpNameSh(); } @@ -1647,17 +1718,11 @@ void MainWindow::SetupNewExpPanel(){ instr->appendHtml("0, Check the git repository in Analysis Path"); instr->appendHtml("1, Create folder in Data Path and Root Data Path"); instr->appendHtml("2, Create Symbolic links in Analysis Path"); - instr->appendHtml("3, Create expName.sh in Analysis Path "); instr->appendHtml("

"); instr->appendHtml("If Use Git is checked, \ the repository MUST be clean. \ It will then create a new branch with the New Exp Name \ or change to pre-exist branch."); - instr->appendHtml("

"); - instr->appendHtml("If there is no git repository in Analysis Path, \ - it will create one with a branch name of New Exp Name ."); - instr->appendHtml("

"); - instr->appendHtml("expName.sh stores the exp name, runID, and elogID."); //------- Analysis Path rowID ++; @@ -2027,6 +2092,31 @@ void MainWindow::CreateNewExperiment(const QString newExpName){ rawDataPath = expDataPath + "/" + newExpName + "/raw_data/"; rootDataPath = expDataPath + "/" + newExpName + "/root_data/"; + //check rawDataPath exit, if not create + QDir dirRawData(rawDataPath); + if (!dirRawData.exists()) { + // Attempt to create the directory + if (dirRawData.mkpath(rawDataPath)) { + LogMsg("Create Raw Data Directory : " + rawDataPath); + } else { + LogMsg("Failed to create Raw Data Directory : " + rawDataPath); + } + } else { + LogMsg("Raw Data Directory : " + rawDataPath + " | already exist."); + } + + QDir dirRootData(rootDataPath); + if (!dirRootData.exists()) { + // Attempt to create the directory + if (dirRootData.mkpath(rootDataPath)) { + LogMsg("Create Root Data Directory : " + rootDataPath); + } else { + LogMsg("Failed to create Root Data Directory : " + rootDataPath); + } + } else { + LogMsg("Root Data Directory : " + rootDataPath + " | already exist."); + } + leRawDataPath->setText(rawDataPath); leExpName->setText(expName); leRunID->setText(QString::number(runID));