finished start/stop elog and expName.sh

This commit is contained in:
Ryan Tang 2023-02-22 12:41:48 -05:00
parent 5d72b4069b
commit 848aef2b73
6 changed files with 95 additions and 46 deletions

View File

@ -67,7 +67,8 @@
"cinttypes": "cpp", "cinttypes": "cpp",
"typeinfo": "cpp", "typeinfo": "cpp",
"variant": "cpp", "variant": "cpp",
"qdatetime": "cpp" "qdatetime": "cpp",
"fstream": "cpp"
}, },
"better-comments.multilineComments": true, "better-comments.multilineComments": true,

View File

@ -33,6 +33,7 @@ void Digitizer2Gen::Initialization(){
gateway = ""; gateway = "";
outFileIndex = 0; outFileIndex = 0;
FinishedOutFilesSize = 0;
dataStartIndetifier = 0xAAA0; dataStartIndetifier = 0xAAA0;
outFile = NULL; outFile = NULL;
outFileSize = 0; outFileSize = 0;
@ -215,6 +216,10 @@ void Digitizer2Gen::StartACQ(){
SendCommand("/cmd/armacquisition"); // this will also clear data SendCommand("/cmd/armacquisition"); // this will also clear data
SendCommand("/cmd/swstartacquisition"); SendCommand("/cmd/swstartacquisition");
outFileIndex = 0;
outFileSize = 0;
FinishedOutFilesSize = 0;
acqON = true; acqON = true;
} }
@ -500,6 +505,7 @@ void Digitizer2Gen::CloseOutFile(){
void Digitizer2Gen::SaveDataToFile(){ void Digitizer2Gen::SaveDataToFile(){
if( outFileSize > (unsigned int) MaxOutFileSize){ if( outFileSize > (unsigned int) MaxOutFileSize){
FinishedOutFilesSize += ftell(outFile);
fclose(outFile); fclose(outFile);
outFileIndex ++; outFileIndex ++;
sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex); sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex);

View File

@ -8,7 +8,8 @@
#include "Event.h" #include "Event.h"
#define MaxOutFileSize 2*1024*1024*1024 #define MaxOutFileSize 2*1024*1024*1024 //2GB
//#define MaxOutFileSize 20*1024*1024 //20MB
#define MaxNumberOfChannel 64 #define MaxNumberOfChannel 64
#include "DigiParameters.h" #include "DigiParameters.h"
@ -57,6 +58,7 @@ class Digitizer2Gen {
char outFileName[100]; char outFileName[100];
FILE * outFile; FILE * outFile;
unsigned int outFileSize; unsigned int outFileSize;
uint64_t FinishedOutFilesSize;
bool acqON; bool acqON;
@ -117,7 +119,8 @@ class Digitizer2Gen {
void OpenOutFile(std::string fileName, const char * mode = "w"); void OpenOutFile(std::string fileName, const char * mode = "w");
void CloseOutFile(); void CloseOutFile();
void SaveDataToFile(); void SaveDataToFile();
unsigned int GetFileSize() {return outFileSize;} unsigned int GetFileSize() const {return outFileSize;}
uint64_t GetTotalFilesSize() const {return FinishedOutFilesSize + outFileSize;}
}; };

View File

@ -267,6 +267,9 @@ MainWindow::~MainWindow(){
void MainWindow::StartACQ(){ void MainWindow::StartACQ(){
if( chkSaveRun->isChecked() ){ if( chkSaveRun->isChecked() ){
runID ++;
leRunID->setText(QString::number(runID));
runIDStr = QString::number(runID).rightJustified(3, '0'); runIDStr = QString::number(runID).rightJustified(3, '0');
LogMsg("=========================== Start <b><font style=\"color : red;\">Run-" + runIDStr + "</font></b>"); LogMsg("=========================== Start <b><font style=\"color : red;\">Run-" + runIDStr + "</font></b>");
@ -303,8 +306,13 @@ void MainWindow::StartACQ(){
} }
//} //}
//TODO ============ elog //TODO ============ elog
QString elogMsg = "=============== Run-" + runIDStr + "<br />"
+ QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "<br />"
+ "comment : " + startComment + "<br />" +
+ "----------------------------------------------";
WriteElog(elogMsg, "Run-" + runIDStr, "Run", runID);
//TODO ============ update expName.sh //TODO ============ update expName.sh
WriteExpNameSh();
}else{ }else{
LogMsg("=========================== Start no-save Run"); LogMsg("=========================== Start no-save Run");
@ -415,8 +423,15 @@ void MainWindow::StopACQ(){
if( chkSaveRun->isChecked() ){ if( chkSaveRun->isChecked() ){
//TODO ============= elog //TODO ============= elog
runID ++; QString msg = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.z") + "<br />";
leRunID->setText(QString::number(runID));
for( int i = 0; i < nDigi; i++){
if( digi[i]->IsDummy () ) continue;
msg += "FileSize ("+ QString::number(digi[i]->GetSerialNumber()) +"): " + QString::number(digi[i]->GetTotalFilesSize()/1024./1024.) + " MB <br />";
}
msg += "comment : " + stopComment + "<br />"
+ "======================";
AppendElog(msg, chromeWindowID);
} }
//if( scalarThread->isRunning()) printf("Scalar Thread still running.\n"); //if( scalarThread->isRunning()) printf("Scalar Thread still running.\n");
//if( scalarThread->isFinished()) printf("Scalar Thread finsihed.\n"); //if( scalarThread->isFinished()) printf("Scalar Thread finsihed.\n");
@ -463,6 +478,8 @@ void MainWindow::OpenDigitizers(){
readDataThread[i] = new ReadDataThread(digi[i], this); readDataThread[i] = new ReadDataThread(digi[i], this);
connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg); connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg);
//connect(readDataThread[i], &ReadDataThread::checkFileSize, this, &MainWindow::CheckOutFileSize);
//connect(readDataThread[i], &ReadDataThread::endOfLastData, this, &MainWindow::CheckOutFileSize);
SetUpScalar(); SetUpScalar();
bnOpenScalar->setEnabled(true); bnOpenScalar->setEnabled(true);
@ -552,7 +569,6 @@ void MainWindow::OpenDigitizersSettings(){
} }
//^###################################################################### Open Scaler, when DAQ is running //^###################################################################### Open Scaler, when DAQ is running
//TODO #################################
void MainWindow::OpenScaler(){ void MainWindow::OpenScaler(){
scalar->show(); scalar->show();
} }
@ -954,21 +970,21 @@ void MainWindow::SetupInflux(){
void MainWindow::CheckElog(){ void MainWindow::CheckElog(){
WriteElog("Checking elog writing", "checking", "Testing communication"); WriteElog("Checking elog writing", "Testing communication", "checking");
if( elogID > 0 ){ if( elogID > 0 ){
LogMsg("Ckecked Elog writing. OK."); LogMsg("Ckecked Elog writing. OK.");
//TODO =========== chrome windowID //TODO =========== chrome windowID
AppendElog("Check Elog append.", 10485763); AppendElog("Check Elog append.", chromeWindowID);
if( elogID > 0 ){ if( elogID > 0 ){
LogMsg("Checked Elog Append. OK."); LogMsg("Checked Elog Append. OK.");
}else{ }else{
LogMsg("Checked Elog Append. FAIL. (no elog will be used.)"); LogMsg("<font style=\"color : red;\">Checked Elog Append. FAIL. (no elog will be used.) </font>");
} }
}else{ }else{
LogMsg("Ckecked Elog writing. FAIL. (no elog will be used.)"); LogMsg("<font style=\"color : red;\">Checked Elog Write. FAIL. (no elog will be used.) </font>");
} }
} }
@ -1304,6 +1320,13 @@ void MainWindow::CreateNewExperiment(const QString newExpName){
LogMsg("Creating new Exp. : <font style=\"color: red;\">" + newExpName + "</font>"); LogMsg("Creating new Exp. : <font style=\"color: red;\">" + newExpName + "</font>");
expName = newExpName;
runID = -1;
elogID = 0;
CreateRawDataFolderAndLink();
WriteExpNameSh();
//@----- git must be clean //@----- git must be clean
//----- creat new git branch //----- creat new git branch
if( useGit ){ if( useGit ){
@ -1322,21 +1345,6 @@ void MainWindow::CreateNewExperiment(const QString newExpName){
} }
} }
CreateRawDataFolderAndLink(newExpName);
//----- create the expName.sh
QFile file2(analysisPath + "/expName.sh");
file2.open(QIODevice::Text | QIODevice::WriteOnly);
file2.write(("expName = "+ newExpName + "\n").toStdString().c_str());
file2.write(("rawDataPath = "+ rawDataFolder + "\n").toStdString().c_str());
file2.write("runID = 0\n");
file2.write("elogID = 0\n");
file2.write("//------------end of file.");
file2.close();
LogMsg("Saved expName.sh to <b>"+ analysisPath + "/expName.sh<b>.");
//----- create git branch //----- create git branch
if( useGit ){ if( useGit ){
QProcess git; QProcess git;
@ -1350,10 +1358,6 @@ void MainWindow::CreateNewExperiment(const QString newExpName){
LogMsg("Commit branch : <b>" + newExpName + "</b> as \"initial commit\""); LogMsg("Commit branch : <b>" + newExpName + "</b> as \"initial commit\"");
} }
expName = newExpName;
runID = 0;
elogID = 0;
leRawDataPath->setText(rawDataFolder); leRawDataPath->setText(rawDataFolder);
leExpName->setText(expName); leExpName->setText(expName);
leRunID->setText(QString::number(runID)); leRunID->setText(QString::number(runID));
@ -1375,27 +1379,54 @@ void MainWindow::ChangeExperiment(const QString newExpName){
LogMsg("Swicted to branch : <b>" + newExpName + "</b>"); LogMsg("Swicted to branch : <b>" + newExpName + "</b>");
CreateRawDataFolderAndLink(newExpName); expName = newExpName;
CreateRawDataFolderAndLink();
LoadExpSettings(); LoadExpSettings();
} }
void MainWindow::CreateRawDataFolderAndLink(const QString newExpName){ void MainWindow::WriteExpNameSh(){
//----- create the expName.sh
QFile file2(analysisPath + "/expName.sh");
file2.open(QIODevice::Text | QIODevice::WriteOnly);
file2.write(("expName="+ expName + "\n").toStdString().c_str());
file2.write(("rawDataPath="+ rawDataFolder + "\n").toStdString().c_str());
file2.write(("runID="+std::to_string(runID)+"\n").c_str());
file2.write(("elogID="+std::to_string(elogID)+"\n").c_str());
file2.write("//------------end of file.");
file2.close();
LogMsg("Saved expName.sh to <b>"+ analysisPath + "/expName.sh<b>.");
}
void MainWindow::CreateRawDataFolderAndLink(){
//----- create data folder //----- create data folder
rawDataFolder = dataPath + "/" + newExpName; rawDataFolder = dataPath + "/" + expName;
QDir dir; QDir dir;
if( !dir.exists(rawDataFolder)){ if( !dir.exists(rawDataFolder)){
if( dir.mkdir(rawDataFolder)){ if( dir.mkdir(rawDataFolder)){
LogMsg("<b>" + rawDataFolder + "</b> created." ); LogMsg("<b>" + rawDataFolder + "</b> created." );
}else{ }else{
LogMsg("<b>" + rawDataFolder + "</b> cannot be created. Access right problem?" ); LogMsg("<font style=\"color:red;\"><b>" + rawDataFolder + "</b> cannot be created. Access right problem? </font>" );
} }
}else{ }else{
LogMsg("<b>" + rawDataFolder + "</b> already exist." ); LogMsg("<b>" + rawDataFolder + "</b> already exist." );
} }
//----- create analysis Folder
QDir anaDir;
if( !anaDir.exists(analysisPath)){
if( anaDir.mkdir(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.");
}
//----- create symbloic link //----- create symbloic link
QString linkName = analysisPath + "/data_raw"; QString linkName = analysisPath + "/data_raw";
QFile file; QFile file;
@ -1407,7 +1438,7 @@ void MainWindow::CreateRawDataFolderAndLink(const QString newExpName){
if (file.link(rawDataFolder, linkName)) { if (file.link(rawDataFolder, linkName)) {
LogMsg("Symbolic link <b>" + linkName +"</b> -> " + rawDataFolder + " created."); LogMsg("Symbolic link <b>" + linkName +"</b> -> " + rawDataFolder + " created.");
} else { } else {
LogMsg("Symbolic link <b>" + linkName +"</b> -> " + rawDataFolder + " cannot be created."); LogMsg("<font style=\"color:red;\">Symbolic link <b>" + linkName +"</b> -> " + rawDataFolder + " cannot be created. </font>");
} }
} }
@ -1426,15 +1457,18 @@ void MainWindow::LogMsg(QString msg){
logInfo->repaint(); logInfo->repaint();
} }
void MainWindow::WriteElog(QString htmlText, QString category, QString subject){ void MainWindow::WriteElog(QString htmlText, QString subject, QString category, int runNumber){
if( elogID < 0 ) return; if( elogID < 0 ) return;
if( expName == "" ) return; if( expName == "" ) return;
QStringList arg; QStringList arg;
arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralFSU" << "fsuphysics-888" arg << "-h" << ElogIP << "-p" << "8080" << "-l" << expName << "-u" << "GeneralFSU" << "fsuphysics-888"
<< "-a" << "Author=GeneralFSU" << "-a" << "Category=" + category << "-a" << "Author=GeneralFSU" ;
<< "-a" << "Subject=" + subject if( runNumber > 0 ) arg << "-a" << "Run=" + QString::number(runNumber);
if( category != "" ) arg << "-a" << "Category=" + category;
arg << "-a" << "Subject=" + subject
<< "-n " << "2" << htmlText ; << "-n " << "2" << htmlText ;
QProcess elogBash(this); QProcess elogBash(this);

View File

@ -19,7 +19,6 @@
#include <vector> #include <vector>
#include <time.h> // time in nano-sec #include <time.h> // time in nano-sec
#include "ClassDigitizer2Gen.h" #include "ClassDigitizer2Gen.h"
#include "influxdb.h" #include "influxdb.h"
@ -28,6 +27,8 @@
#include "digiSettings.h" #include "digiSettings.h"
#include "scope.h" #include "scope.h"
const int chromeWindowID = 10485763;
//^#===================================================== MainWindow //^#===================================================== MainWindow
class MainWindow : public QMainWindow{ class MainWindow : public QMainWindow{
Q_OBJECT Q_OBJECT
@ -64,7 +65,8 @@ private slots:
bool LoadExpSettings(); bool LoadExpSettings();
void CreateNewExperiment(const QString newExpName); void CreateNewExperiment(const QString newExpName);
void ChangeExperiment(const QString newExpName); void ChangeExperiment(const QString newExpName);
void CreateRawDataFolderAndLink(const QString newExpName); void WriteExpNameSh();
void CreateRawDataFolderAndLink();
void closeEvent(QCloseEvent * event){ void closeEvent(QCloseEvent * event){
if( digiSetting != NULL ) digiSetting->close(); if( digiSetting != NULL ) digiSetting->close();
@ -72,7 +74,7 @@ private slots:
event->accept(); event->accept();
} }
void WriteElog(QString htmlText, QString category = "", QString subject = ""); void WriteElog(QString htmlText, QString subject = "", QString category = "", int runNumber = 0);
void AppendElog(QString appendHtmlText, int screenID = -1); void AppendElog(QString appendHtmlText, int screenID = -1);
signals : signals :
@ -151,7 +153,7 @@ private:
bool useGit; bool useGit;
QString expName; QString expName;
QString rawDataFolder; QString rawDataFolder;
unsigned int runID; int runID;
QString runIDStr; QString runIDStr;
int elogID; // 0 = ready, -1 = disable, >1 = elogID int elogID; // 0 = ready, -1 = disable, >1 = elogID

View File

@ -29,6 +29,7 @@ public:
if( isSaveData) digi->SaveDataToFile(); if( isSaveData) digi->SaveDataToFile();
}else if(ret == CAEN_FELib_Stop){ }else if(ret == CAEN_FELib_Stop){
digi->ErrorMsg("No more data"); digi->ErrorMsg("No more data");
//emit endOfLastData();
break; break;
}else{ }else{
//digi->ErrorMsg("ReadDataLoop()"); //digi->ErrorMsg("ReadDataLoop()");
@ -38,8 +39,8 @@ public:
if( isSaveData ){ if( isSaveData ){
clock_gettime(CLOCK_REALTIME, &tb); clock_gettime(CLOCK_REALTIME, &tb);
if( tb.tv_sec - ta.tv_sec > 2 ) { if( tb.tv_sec - ta.tv_sec > 2 ) {
emit sendMsg("FileSize : " + QString::number(digi->GetFileSize()/1024./1024.) + " MB"); emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetTotalFilesSize()/1024./1024.) + " MB");
//emit checkFileSize();
//double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9; //double duration = tb.tv_nsec-ta.tv_nsec + tb.tv_sec*1e+9 - ta.tv_sec*1e+9;
//printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration); //printf("%4d, duration : %10.0f, %6.1f\n", readCount, duration, 1e9/duration);
ta = tb; ta = tb;
@ -49,6 +50,8 @@ public:
} }
signals: signals:
void sendMsg(const QString &msg); void sendMsg(const QString &msg);
//void endOfLastData();
//void checkFileSize();
private: private:
Digitizer2Gen * digi; Digitizer2Gen * digi;
timespec ta, tb; timespec ta, tb;