17#include "FairParGenericSet.h"
18#include "FairRootManager.h"
20#include "FairRunOnline.h"
21#include "FairRuntimeDb.h"
26#include "THttpServer.h"
43 , fbMonitorMode(kFALSE)
44 , fbDebugMonitorMode(kFALSE)
45 , fbStoreLostEventMsg(kFALSE)
46 , fbAddStatusToEvent(kTRUE)
47 , fbSandboxMode(kFALSE)
48 , fbEventDumpEna(kFALSE)
52 , fsHistoFileName(
"data/eventBuilderMonHist.root")
54 , fEventBuilderAlgo(nullptr)
56 , fdTsCoreSizeInSec(-1.0)
62 , fdRealTimeMinAll(1e6)
63 , fdRealTimeMaxAll(0.0)
65 , fulNbEventsSinceLastPrintout(0)
66 , fhRealTimeDistr(nullptr)
67 , fhRealTimeEvo(nullptr)
68 , fhMeanRealTimeEvo(nullptr)
69 , fpBinDumpFile(nullptr)
78 LOG(info) <<
"CbmStar2019EventBuilderEtof::Init";
79 LOG(info) <<
"Initializing STAR eTOF 2018 Event Builder";
81 FairRootManager* ioman = FairRootManager::Instance();
82 if (NULL == ioman) { LOG(fatal) <<
"No FairRootManager instance"; }
89 LOG(info) <<
"Setting parameter containers for " << GetName();
93 for (Int_t iparC = 0; iparC <
fParCList->GetEntries(); ++iparC) {
94 FairParGenericSet* tempObj = (FairParGenericSet*) (
fParCList->At(iparC));
97 std::string sParamName {tempObj->GetName()};
98 FairParGenericSet* newObj =
99 dynamic_cast<FairParGenericSet*
>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
101 if (
nullptr == newObj) {
102 LOG(error) <<
"Failed to obtain parameter container " << sParamName <<
", for parameter index " << iparC;
113 LOG(info) <<
"Init parameter containers for " << GetName();
117 dynamic_cast<CbmStar2019TofPar*
>(FairRun::Instance()->GetRuntimeDb()->getContainer(
"CbmStar2019TofPar"));
118 if (
nullptr == pUnpackPar) {
119 LOG(error) <<
"Failed to obtain parameter container CbmStar2019TofPar";
124 LOG(info) <<
"Monitor mode: " << (
fbMonitorMode ?
"ON" :
"OFF");
131 LOG(info) <<
"Timeslice parameters: each MS is " <<
fdMsSizeInNs <<
" ns";
152 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
153 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
154 server->Register(Form(
"/%s", vHistos[uHisto].second.data()), vHistos[uHisto].first);
157 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
160 server->Register(Form(
"/%s", vCanvases[uCanv].second.data()),
161 gROOT->FindObject((vCanvases[uCanv].first)->GetName()));
164 server->RegisterCommand(
"/Reset_EvtBuild_Hist",
"bStarEtof2019EventBuilderResetHistos=kTRUE");
165 server->Restrict(
"/Reset_EvtBuild_Hist",
"allow=admin");
169 "Realtime for processing a TS in event "
170 "builder; Realtime [ms]; TS nb []",
173 "Realtime Processing to duration ratio for processing a TS in event "
174 "builder vs TS index; TS []; Realtime ratio []; TS Nb []",
175 1000, 0, 100000, 10000, 0.0, 100.0);
178 "Mean Realtime Processing to duration ratio for processing a TS in "
179 "event builder vs TS index; TS []; Mean Realtime ratio []; TS Nb []",
194 LOG(info) <<
"ReInit parameter containers for " << GetName();
204 LOG(info) <<
"Enabling event dump to binary file which was disabled. "
205 "File will be opened.";
207 std::time_t cTimeCurrent = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
209 std::strftime(tempBuff, 80,
"%Y_%m_%d_%H_%M_%S", localtime(&cTimeCurrent));
210 TString sFileName = Form(
"event_dump_%s.bin", tempBuff);
211 fpBinDumpFile =
new std::fstream(sFileName, std::ios::out | std::ios::binary);
214 LOG(fatal) <<
"Failed to open new binary file for event dump at " << sFileName;
217 LOG(info) <<
"Opened binary dump file at " << sFileName;
220 LOG(info) <<
"Disabling event dump to binary file which was enabled. "
221 "File will be closed.";
228 if (
fbEventDumpEna) LOG(info) <<
"Event dump to binary file is now ENABLED";
230 LOG(info) <<
"Event dump to binary file is now DISABLED";
248 LOG(info) <<
"FIXME ===> Jumping 1st TS as corrupted with current FW + "
249 "FLESNET combination";
255 LOG(info) <<
"Reset eTOF STAR histos ";
267 LOG(error) <<
"Failed processing TS " << ts.index() <<
" in event builder algorithm class";
273 for (UInt_t uEvent = 0; uEvent < eventBuffer.size(); ++uEvent) {
275 Int_t iBuffSzByte = 0;
276 void* pDataBuff = eventBuffer[uEvent].BuildOutput(iBuffSzByte);
277 if (NULL != pDataBuff) {
287 star_rhicf_write(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(), pDataBuff, iBuffSzByte);
290 LOG(debug) <<
"Sent STAR event with size " << iBuffSzByte <<
" Bytes"
291 <<
" and token " << eventBuffer[uEvent].GetTrigger().GetStarToken();
295 fpBinDumpFile->write(
reinterpret_cast<const char*
>(&iBuffSzByte),
sizeof(Int_t));
296 fpBinDumpFile->write(
reinterpret_cast<const char*
>(pDataBuff), iBuffSzByte);
301 LOG(error) <<
"Invalid STAR SubEvent Output, can only happen if trigger "
302 <<
" object was not set => Do Nothing more with it!!! ";
305 Double_t dRealT =
fTimer.RealTime();
307 LOG(debug2) << Form(
"Real time TS %12lu, Realtime: %12f ns",
static_cast<unsigned long>(
fulTsCounter),
316 LOG(debug) << Form(
"New min Real time TS %12lu, Real time: %9.6f ms Old "
317 "Min %9.6f Diff %.9f",
323 LOG(debug) << Form(
"New max Real time TS %12lu, Real time: %9.6f ms Old "
324 "Max %9.6f Diff %.9f",
333 LOG(info) << Form(
"Processed %12lu TS, Real time: %6.3f ms/TS (Min %6.3f, "
334 "Max %6.3f), Events: %12lu (%9lu since last print)",
353 LOG(info) <<
"Closing binary file used for event dump.";
368 TDirectory* oldDir = NULL;
369 TFile* histoFile = NULL;
375 if (
nullptr == histoFile)
return kFALSE;
378 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
380 TString sFolder = vHistos[uHisto].second.data();
381 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
382 gDirectory->cd(sFolder);
385 vHistos[uHisto].first->Write();
390 for (UInt_t uCanvas = 0; uCanvas < vCanvas.size(); ++uCanvas) {
392 TString sFolder = vCanvas[uCanvas].second.data();
393 if (
nullptr == gDirectory->Get(sFolder)) gDirectory->mkdir(sFolder);
394 gDirectory->cd(sFolder);
397 vCanvas[uCanvas].first->Write();
ClassImp(CbmConverterManager)
Bool_t bStarEtof2019EventBuilderResetHistos
int star_rhicf_write(unsigned int trg_word, void *dta, int bytes)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
std::vector< CbmTofStarSubevent2019 > & GetEventBuffer()
Bool_t ReInitContainers()
void SetAddStatusToEvent(Bool_t bFlagIn=kTRUE)
void SetDebugMonitorMode(Bool_t bFlagIn=kTRUE)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void SetPulserTotLimits(UInt_t uMin, UInt_t uMax)
Bool_t ProcessTs(const fles::Timeslice &ts)
Bool_t CreateHistograms()
void SetStoreLostEventMsg(Bool_t bFlagIn=kTRUE)
const UInt_t kuBinDumpBegWord
Bool_t fbSandboxMode
Switch ON the readout and insertion of STATUS pattern message (default is true)
TStopwatch fTimer
Total size of the core MS in a TS, [seconds].
TH2 * fhRealTimeEvo
Exclude from dictionary because ?!?!
Double_t fdTsCoreSizeInSec
Size of a single MS, [nanoseconds].
TProfile * fhMeanRealTimeEvo
Exclude from dictionary because ?!?!
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Bool_t fbDebugMonitorMode
Switch ON the filling of a minimal set of histograms.
Double_t fdMsSizeInNs
Processing speed watch.
Bool_t ReInitContainers()
Bool_t fbEventDumpEna
Switch OFF the emission of data toward the STAR DAQ.
std::fstream * fpBinDumpFile
Exclude from dictionary because ?!?!
UInt_t fuMinTotPulser
User settings: Data selection parameters.
CbmStar2019EventBuilderEtofAlgo * fEventBuilderAlgo
Processing algo.
Bool_t fbAddStatusToEvent
Switch ON the insertion of the LostEvent messages from GET4s with the critical errors.
virtual ~CbmStar2019EventBuilderEtof()
Bool_t fbStoreLostEventMsg
Switch ON the filling of a additional set of histograms.
void SetEventDumpEnable(Bool_t bDumpEna=kTRUE)
Bool_t fbMonitorMode
Control flags.
TList * fParCList
Switch ON the dumping of the events to a binary file.
CbmStar2019EventBuilderEtof(UInt_t uNbGdpb=1)
uint64_t fulNbEventsSinceLastPrintout
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
const UInt_t kuBinDumpEndWord
uint64_t fulTsCounter
Statistics & first TS rejection.