13 #include "FairLogger.h"
14 #include "FairParGenericSet.h"
15 #include "FairRootManager.h"
17 #include "FairRunOnline.h"
18 #include "FairRuntimeDb.h"
22 #include "THttpServer.h"
38 , fbMonitorMode(kFALSE)
39 , fbDebugMonitorMode(kFALSE)
40 , fbStoreLostEventMsg(kFALSE)
41 , fbAddStatusToEvent(kTRUE)
42 , fbSandboxMode(kFALSE)
43 , fbEventDumpEna(kFALSE)
47 , fsHistoFileName(
"data/eventBuilderMonHist.root")
49 , fEventBuilderAlgo(nullptr)
51 , fdTsCoreSizeInSec(-1.0)
57 , fdRealTimeMinAll(1e6)
58 , fdRealTimeMaxAll(0.0)
60 , fulNbEventsSinceLastPrintout(0)
61 , fhRealTimeDistr(nullptr)
62 , fhRealTimeEvo(nullptr)
63 , fhMeanRealTimeEvo(nullptr)
64 , fpBinDumpFile(nullptr) {
73 LOG(info) <<
"CbmStar2019EventBuilderEtof::Init";
74 LOG(info) <<
"Initializing STAR eTOF 2018 Event Builder";
76 FairRootManager* ioman = FairRootManager::Instance();
77 if (NULL == ioman) { LOG(fatal) <<
"No FairRootManager instance"; }
83 LOG(info) <<
"Setting parameter containers for " << GetName();
87 for (Int_t iparC = 0; iparC <
fParCList->GetEntries(); ++iparC) {
88 FairParGenericSet* tempObj = (FairParGenericSet*) (
fParCList->At(iparC));
91 std::string sParamName {tempObj->GetName()};
92 FairParGenericSet* newObj =
dynamic_cast<FairParGenericSet*
>(
93 FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
95 if (
nullptr == newObj) {
96 LOG(error) <<
"Failed to obtain parameter container " << sParamName
97 <<
", for parameter index " << iparC;
107 LOG(info) <<
"Init parameter containers for " << GetName();
111 FairRun::Instance()->GetRuntimeDb()->getContainer(
"CbmStar2019TofPar"));
112 if (
nullptr == pUnpackPar) {
113 LOG(error) <<
"Failed to obtain parameter container CbmStar2019TofPar";
118 LOG(info) <<
"Monitor mode: " << (
fbMonitorMode ?
"ON" :
"OFF");
125 LOG(info) <<
"Timeslice parameters: each MS is " <<
fdMsSizeInNs <<
" ns";
141 std::vector<std::pair<TNamed*, std::string>> vHistos =
144 std::vector<std::pair<TCanvas*, std::string>> vCanvases =
148 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
149 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
150 server->Register(Form(
"/%s", vHistos[uHisto].second.data()),
151 vHistos[uHisto].first);
154 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
157 server->Register(Form(
"/%s", vCanvases[uCanv].second.data()),
158 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
161 server->RegisterCommand(
"/Reset_EvtBuild_Hist",
162 "bStarEtof2019EventBuilderResetHistos=kTRUE");
163 server->Restrict(
"/Reset_EvtBuild_Hist",
"allow=admin");
167 "Realtime for processing a TS in event "
168 "builder; Realtime [ms]; TS nb []",
173 "hEvtBuildRealTimeEvo",
174 "Realtime Processing to duration ratio for processing a TS in event "
175 "builder vs TS index; TS []; Realtime ratio []; TS Nb []",
184 "hEvtBuildMeanRealTimeEvo",
185 "Mean Realtime Processing to duration ratio for processing a TS in "
186 "event builder vs TS index; TS []; Mean Realtime ratio []; TS Nb []",
202 LOG(info) <<
"ReInit parameter containers for " << GetName();
211 LOG(info) <<
"Enabling event dump to binary file which was disabled. "
212 "File will be opened.";
214 std::time_t cTimeCurrent =
215 std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
218 tempBuff, 80,
"%Y_%m_%d_%H_%M_%S", localtime(&cTimeCurrent));
219 TString sFileName = Form(
"event_dump_%s.bin", tempBuff);
221 new std::fstream(sFileName, std::ios::out | std::ios::binary);
224 LOG(fatal) <<
"Failed to open new binary file for event dump at "
228 LOG(info) <<
"Opened binary dump file at " << sFileName;
231 LOG(info) <<
"Disabling event dump to binary file which was enabled. "
232 "File will be closed.";
240 LOG(info) <<
"Event dump to binary file is now ENABLED";
242 LOG(info) <<
"Event dump to binary file is now DISABLED";
246 UShort_t usDetectorId) {
260 LOG(info) <<
"FIXME ===> Jumping 1st TS as corrupted with current FW + "
261 "FLESNET combination";
267 LOG(info) <<
"Reset eTOF STAR histos ";
279 LOG(error) <<
"Failed processing TS " << ts.index()
280 <<
" in event builder algorithm class";
284 std::vector<CbmTofStarSubevent2019>& eventBuffer =
287 for (UInt_t uEvent = 0; uEvent < eventBuffer.size(); ++uEvent) {
289 Int_t iBuffSzByte = 0;
290 void* pDataBuff = eventBuffer[uEvent].BuildOutput(iBuffSzByte);
291 if (NULL != pDataBuff) {
306 LOG(debug) <<
"Sent STAR event with size " << iBuffSzByte <<
" Bytes"
308 << eventBuffer[uEvent].GetTrigger().GetStarToken();
313 fpBinDumpFile->write(
reinterpret_cast<const char*
>(&iBuffSzByte),
315 fpBinDumpFile->write(
reinterpret_cast<const char*
>(pDataBuff),
322 LOG(error) <<
"Invalid STAR SubEvent Output, can only happen if trigger "
323 <<
" object was not set => Do Nothing more with it!!! ";
326 Double_t dRealT =
fTimer.RealTime();
328 LOG(debug2) << Form(
"Real time TS %12lu, Realtime: %12f ns",
338 LOG(debug) << Form(
"New min Real time TS %12lu, Real time: %9.6f ms Old "
339 "Min %9.6f Diff %.9f",
348 LOG(debug) << Form(
"New max Real time TS %12lu, Real time: %9.6f ms Old "
349 "Max %9.6f Diff %.9f",
361 LOG(info) << Form(
"Processed %12lu TS, Real time: %6.3f ms/TS (Min %6.3f, "
362 "Max %6.3f), Events: %12lu (%9lu since last print)",
383 LOG(info) <<
"Closing binary file used for event dump.";
396 std::vector<std::pair<TNamed*, std::string>> vHistos =
398 std::vector<std::pair<TCanvas*, std::string>> vCanvas =
402 TDirectory* oldDir = NULL;
403 TFile* histoFile = NULL;
409 if (
nullptr == histoFile)
return kFALSE;
412 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
414 TString sFolder = vHistos[uHisto].second.data();
415 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
416 gDirectory->cd(sFolder);
419 vHistos[uHisto].first->Write();
424 for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
426 TString sFolder = vCanvas[uCanvas].second.data();
427 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
428 gDirectory->cd(sFolder);
431 vCanvas[uCanvas].first->Write();