From d63a53c3a668f6098fbd6e319d3191a2ba24940c Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Mon, 31 Oct 2022 21:26:10 -0400 Subject: [PATCH] added database and elog functions --- DAQ/ClassData.h | 4 +++- DAQ/FSUDAQ.cpp | 21 ++++++++++++++++++--- DAQ/FSUDAQ.h | 4 +++- DAQ/FSUDAQ.sh | 1 - DAQ/Makefile | 11 ++++++----- DAQ/elogEntry.sh | 15 +++++++++++++++ DAQ/programSetting.cpp | 40 ++++++++++++++++++++++++++-------------- DAQ/programSetting.h | 1 + DAQ/triggerSummary.cpp | 27 +++++++++++++++++++++++++-- FSUDAQ.sh | 12 ++++++------ 10 files changed, 103 insertions(+), 33 deletions(-) delete mode 120000 DAQ/FSUDAQ.sh create mode 100755 DAQ/elogEntry.sh diff --git a/DAQ/ClassData.h b/DAQ/ClassData.h index 9211532..52e8397 100644 --- a/DAQ/ClassData.h +++ b/DAQ/ClassData.h @@ -314,7 +314,9 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ if( NumEventsDecoded[ch] > 0 ) IsNotRollOverFakeAgg = true; unsigned long long dTime = Timestamp[ch][NumEvents[ch]-1] - Timestamp[ch][NumEvents[ch] - NumEventsDecoded[ch]]; double sec = dTime * ch2ns / 1e9; - TriggerRate[ch] = NumEventsDecoded[ch]/sec; + if( sec != 0 ){ + TriggerRate[ch] = NumEventsDecoded[ch]/sec; + } firstTimestamp[ch] = Timestamp[ch][0]; lastTimestamp[ch] = Timestamp[ch][NumEvents[ch]-1]; diff --git a/DAQ/FSUDAQ.cpp b/DAQ/FSUDAQ.cpp index 8023229..a18c271 100644 --- a/DAQ/FSUDAQ.cpp +++ b/DAQ/FSUDAQ.cpp @@ -194,6 +194,9 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { cbDataRun = new TGCheckButton(hfg1, "Data Run", 1); hfg1->AddFrame(cbDataRun, hahaLayoutHints); cbDataRun->SetState(kButtonUp); + + TGHorizontalFrame *hfg2 = new TGHorizontalFrame(vframe); vframe->AddFrame(hfg2 ,new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0)); + } {///================= single Channel group @@ -258,6 +261,7 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) { LogMsg((char*)"The LogMsg is not complete for all actions. [update later]"); LogMsg((char*)"Please \"Program Setting\" to set data folder"); LogMsg((char*)"Please \"Open Digitizers\" to start."); + LogMsg((char*)"OR. \"Load Setting (Offline)\" for inspecting setting file."); //HandleMenu(M_DIGITIZER_OPEN); //HandleMenu(M_BOARD_SETTINGS); @@ -552,6 +556,15 @@ void MainWindow::UpdateExpName(){ runIDEntry->SetNumber(lastRunID); } +void MainWindow::MakeElogEntry(bool start){ + + if( ProgramSetting::EnableElog == false ) return; + + TString cmd = Form("%s/DAQ/elogEntry.sh %d", ProgramSetting::programPath.c_str(), start); + int temp = system(cmd.Data()); + +} + void MainWindow::StartRun(){ LogMsg(Form("%s",__func__)); if( digi == NULL) return; @@ -572,9 +585,11 @@ void MainWindow::StartRun(){ if( cbDataRun->GetState() == kButtonDown ) { cbMode->SetEnabled(false); - HandleMenu(M_TRIGGER_SUMMARY); + MakeElogEntry(true); } + HandleMenu(M_TRIGGER_SUMMARY); + bool threadFlag = false; for( int i = 0 ; i < nDigi; i++) { digi[i]->StartACQ(); @@ -611,9 +626,9 @@ void MainWindow::StopRun(){ ///if( cbMode->GetSelected() == Mode_DataRun ){ if( cbDataRun->GetState() == kButtonDown ) { int runID = runIDEntry->GetNumber(); - lastRunID = runID; + lastRunID = runID + 1; runIDEntry->SetNumber(runID +1); - + MakeElogEntry(false); ProgramSetting::SaveProgramSetting(); } diff --git a/DAQ/FSUDAQ.h b/DAQ/FSUDAQ.h index d1fd977..348b082 100644 --- a/DAQ/FSUDAQ.h +++ b/DAQ/FSUDAQ.h @@ -17,12 +17,12 @@ #include "macro.h" #include "ClassDigitizer.h" +#include "programSetting.h" #include "boardSetting.h" #include "channelSettingPHA.h" #include "channelSettingPSD.h" #include "registerSetting.h" #include "triggerSummary.h" -#include "programSetting.h" class TGWindow; class TGMainFrame; @@ -93,5 +93,7 @@ public: void LogMsg(char * ); void GoodBye(); static void DrawDummyGraph(); + + static void MakeElogEntry(bool start); /// call elogEntry.sh bash script }; diff --git a/DAQ/FSUDAQ.sh b/DAQ/FSUDAQ.sh deleted file mode 120000 index 260918c..0000000 --- a/DAQ/FSUDAQ.sh +++ /dev/null @@ -1 +0,0 @@ -../FSUDAQ.sh \ No newline at end of file diff --git a/DAQ/Makefile b/DAQ/Makefile index b0868ed..1dcaffc 100755 --- a/DAQ/Makefile +++ b/DAQ/Makefile @@ -25,23 +25,24 @@ ClassDigitizer.o : ClassDigitizer.cpp ClassDigitizer.h RegisterAddress.h macro.h test : test.cpp ClassDigitizer.o @echo "--------- making test" - $(CC) $(COPTS) -o test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS) + $(CC) $(COPTS) -o ../test test.cpp ClassDigitizer.o $(CAENLIBS) $(ROOTLIBS) EventBuilder : EventBuilder.cpp ClassData.h @echo "--------- making EventBuilder" - $(CC) $(COPTS) -o EventBuilder EventBuilder.cpp $(ROOTLIBS) + $(CC) $(COPTS) -o ../Analysis/EventBuilder EventBuilder.cpp $(ROOTLIBS) test_indep : test_indep.cpp RegisterAddress.h macro.h @echo "--------- making test_indep" - $(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS) + $(CC) $(COPTS) -o ../test_indep test_indep.cpp $(CAENLIBS) FSUDAQ : FSUDAQDict.cxx $(OBJS) ClassData.h @echo "----------- creating FSUDAQ" - $(CC) $(COPTS) FSUDAQDict.cxx $(OBJS) -o FSUDAQ $(CAENLIBS) $(ROOTLIBS) + $(CC) $(COPTS) FSUDAQDict.cxx $(OBJS) -o ../FSUDAQ $(CAENLIBS) $(ROOTLIBS) + @ln -s -f DAQ/FSUDAQDict_rdict.pcm ../. FSUDAQDict.cxx : FSUDAQ.h FSUDAQLinkDef.h @echo "----------- creating pcm and cxx for root" - @rootcling -f FSUDAQDict.cxx -c FSUDAQ.h -p FSUDAQLinkDef.h + @rootcling -f FSUDAQDict.cxx -c FSUDAQ.h -p FSUDAQLinkDef.h FSUDAQ.o : FSUDAQ.h FSUDAQ.cpp FSUDAQDict.cxx @echo "----------- creating FSUDAQ.o" diff --git a/DAQ/elogEntry.sh b/DAQ/elogEntry.sh new file mode 100755 index 0000000..4a7fa9e --- /dev/null +++ b/DAQ/elogEntry.sh @@ -0,0 +1,15 @@ +#!/bin/bash -l + +source ~/FSUDAQ/FSUDAQ.sh + +echo $ElogIP + +elogFileName="elogText.txt" + +#make text file for elog text +echo "**************************************" > ${elogFileName} +echo "Run-${lastRunID} start at $(date)" >> ${elogFileName} + + +#push to elog +elog -h ${ElogIP} -l ${ExpName} -u GeneralFox fsuphysics888 -a Author="GeneralFox" -a Category="Run" -a RunNo=${lastRunID} -a Subject="Start Run" -n 2 -m elogText.txt diff --git a/DAQ/programSetting.cpp b/DAQ/programSetting.cpp index f59041a..39ec75d 100644 --- a/DAQ/programSetting.cpp +++ b/DAQ/programSetting.cpp @@ -17,16 +17,18 @@ namespace fs = std::experimental::filesystem; -std::string ProgramSetting::databaseIP = "http://fsunuc.physics.fsu.edu/influx/"; +std::string ProgramSetting::databaseIP = "https://fsunuc.physics.fsu.edu/influx/"; std::string ProgramSetting::databaseName = "testing"; std::string ProgramSetting::DataSavingPath = "/home/catrina/FSUDAQ"; std::string ProgramSetting::ExpName = "Test"; std::string ProgramSetting::ElogIP = "128.186.111.127"; -bool ProgramSetting::EnableElog = false; -bool ProgramSetting::EnableDatabase = false; +bool ProgramSetting::EnableElog = true; +bool ProgramSetting::EnableDatabase = true; +/// fixed program things const std::string ProgramSetting::settingFileName = "FSUDAQ.sh"; +const std::string ProgramSetting::programPath = "~/FSUDAQ/"; ///this is declared at FSUDAQ.cpp extern unsigned short lastRunID; @@ -102,11 +104,19 @@ ProgramSetting::ProgramSetting(const TGWindow *p){ TGLabel * lbdummy0 = new TGLabel(vfOnOff, ""); vfOnOff->AddFrame(lbdummy0, haha); cbDatabase = new TGCheckButton(vfOnOff, "Enable Database", 1); vfOnOff->AddFrame(cbDatabase, kaka); - cbDatabase->SetState(kButtonUp); + if( ProgramSetting::EnableDatabase ){ + cbDatabase->SetState(kButtonDown); + }else{ + cbDatabase->SetState(kButtonUp); + } cbDatabase->Connect("Clicked()", "ProgramSetting", this, "SetDataBaseElogOnOff()"); cbElog = new TGCheckButton(vfOnOff, "Enable Elog", 1); vfOnOff->AddFrame(cbElog, kaka); - cbElog->SetState(kButtonUp); + if( ProgramSetting::EnableElog ){ + cbElog->SetState(kButtonDown); + }else{ + cbElog->SetState(kButtonUp); + } cbElog->Connect("Clicked()", "ProgramSetting", this, "SetDataBaseElogOnOff()"); } @@ -208,7 +218,7 @@ void ProgramSetting::LoadProgramSetting(){ lineNum ++; pos = line.find("="); if( pos > 1 ){ - pos += 2; + pos += 1; ///printf("%d | %s , %d \n", lineNum, line.c_str(), pos); switch ( lineNum ){ case 1: ProgramSetting::ExpName = line.substr(pos); break; @@ -235,22 +245,24 @@ void ProgramSetting::SaveProgramSetting(){ printf("+++++++ %s \n", __func__); - FILE * fileOut = fopen(ProgramSetting::settingFileName.c_str(), "w"); + std::string filePath = ProgramSetting::settingFileName; + + FILE * fileOut = fopen(filePath.c_str(), "w"); if( fileOut != NULL ){ - fputs( ("ExpName = " + ProgramSetting::ExpName + "\n").c_str(), fileOut); - fputs( ("DataPath = " + ProgramSetting::DataSavingPath + "\n").c_str(), fileOut); - fputs( ("DatabaseIP = " + ProgramSetting::databaseIP + "\n").c_str(), fileOut); - fputs( ("DatabaseName = " + ProgramSetting::databaseName + "\n").c_str(), fileOut); - fputs( ("ElogIP = " + ProgramSetting::ElogIP + "\n").c_str(), fileOut); - fputs( ("lastRunID = " + std::to_string(lastRunID) + "\n").c_str(), fileOut); + fputs( ("ExpName=" + ProgramSetting::ExpName + "\n").c_str(), fileOut); + fputs( ("DataPath=" + ProgramSetting::DataSavingPath + "\n").c_str(), fileOut); + fputs( ("DatabaseIP=" + ProgramSetting::databaseIP + "\n").c_str(), fileOut); + fputs( ("DatabaseName=" + ProgramSetting::databaseName + "\n").c_str(), fileOut); + fputs( ("ElogIP=" + ProgramSetting::ElogIP + "\n").c_str(), fileOut); + fputs( ("lastRunID=" + std::to_string(lastRunID) + "\n").c_str(), fileOut); fclose(fileOut); gSystem->CopyFile(ProgramSetting::settingFileName.c_str(), (ProgramSetting::DataSavingPath + "/FSUDAQ.sh").c_str(), true); /// overwrite }else{ - printf("%s | Cannot open file : %s.\n", __func__, ProgramSetting::settingFileName.c_str()); + printf("%s | Cannot open file : %s.\n", __func__, filePath.c_str()); } } diff --git a/DAQ/programSetting.h b/DAQ/programSetting.h index 9811f25..f3367f9 100644 --- a/DAQ/programSetting.h +++ b/DAQ/programSetting.h @@ -45,6 +45,7 @@ class ProgramSetting{ static bool EnableDatabase; const static std::string settingFileName; // fixed as FSUDAQ.sh + const static std::string programPath; void SetSetting(); // *SIGNAL* diff --git a/DAQ/triggerSummary.cpp b/DAQ/triggerSummary.cpp index 89b742b..7e048f1 100644 --- a/DAQ/triggerSummary.cpp +++ b/DAQ/triggerSummary.cpp @@ -7,11 +7,17 @@ #include #include +#include +#include + +#include "programSetting.h" #include "triggerSummary.h" extern unsigned short nDigi; extern Digitizer ** digi; +//extern bool ProgramSetting::EnableDatabase; + bool TriggerSummary::updateFlag = true; TGTextEntry * TriggerSummary::txtTrigger[MaxNBoards][MaxNChannels] = {NULL}; TGTextEntry * TriggerSummary::txtThresholdValue[MaxNBoards][MaxNChannels] = {NULL}; @@ -83,7 +89,7 @@ TriggerSummary::TriggerSummary(const TGWindow *p, UInt_t w, UInt_t h){ TGLabel * lbUpDateTime = new TGLabel(hframeSetting, "Update Period [msec]:"); hframeSetting->AddFrame(lbUpDateTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); - numUpdateTime = new TGNumberEntry(hframeSetting, 500, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); + numUpdateTime = new TGNumberEntry(hframeSetting, 3000, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); hframeSetting->AddFrame(numUpdateTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5,5,3,3)); numUpdateTime->Resize(50, 20); @@ -125,15 +131,32 @@ TriggerSummary::~TriggerSummary(){ void * TriggerSummary::UpdateTriggerRate(void * ptr){ + std::string cmd = "curl -XPOST " + ProgramSetting::databaseIP + "/write?db=" + ProgramSetting::databaseName + " --data-binary @tempDB.txt"; + + std::ofstream myfile; + while( updateFlag){ - ///printf("==================== %s\n", __func__); + + + if( ProgramSetting::EnableDatabase ) myfile.open( "tempDB.txt"); + for( int bd = 0; bd < nDigi; bd++){ for( int ch = 0; ch < digi[bd]->GetNChannel(); ch++){ txtTrigger[bd][ch]->SetText(Form("%.2f", digi[bd]->GetData()->TriggerRate[ch])); value[bd][ch] = digi[bd]->GetSettingFromMemory(Register::DPP::PHA::TriggerThreshold, ch); txtThresholdValue[bd][ch]->SetText(Form("%d", value[bd][ch]), false); + + if( ProgramSetting::EnableDatabase ) { + myfile << "Rate,Bd=" << bd << ",Ch=" << ch << " value=" << digi[bd]->GetData()->TriggerRate[ch] << "\n"; + } } } + + + if( ProgramSetting::EnableDatabase ){ + myfile.close(); + int temp = system(cmd.c_str()); + } usleep(numUpdateTime->GetNumber() * 1000); } diff --git a/FSUDAQ.sh b/FSUDAQ.sh index 773e2b5..59f11b4 100755 --- a/FSUDAQ.sh +++ b/FSUDAQ.sh @@ -1,6 +1,6 @@ -ExpName = ZZZZZ -DataPath = /home/catrina/FSUDAQ/expDir -DatabaseIP = http://fsunuc.physics.fsu.edu/influx/ -DatabaseName = testing -ElogIP = 128.186.111.127 -lastRunID = 0 +ExpName=ZZZZZ +DataPath=/home/catrina/FSUDAQ/expDir +DatabaseIP=https://fsunuc.physics.fsu.edu/influx/ +DatabaseName=testing +ElogIP=elog.physics.fsu.edu +lastRunID=8