11 #include "StorableTimeslice.hpp"
13 #include "FairMQLogger.h"
14 #include "FairMQProgOptions.h"
15 #include "FairParGenericSet.h"
16 #include "FairRuntimeDb.h"
21 #include "THttpServer.h"
25 #include <boost/archive/binary_iarchive.hpp>
26 #include <boost/archive/binary_oarchive.hpp>
29 #include <boost/serialization/vector.hpp>
37 using std::runtime_error::runtime_error;
49 , fbMonitorMode(kFALSE)
50 , fbDebugMonitorMode(kFALSE)
51 , fbSandboxMode(kFALSE)
52 , fbEventDumpEna(kFALSE)
56 , fEventBuilderAlgo(nullptr)
59 , fpBinDumpFile(nullptr) {
78 int noChannel = fChannels.size();
79 LOG(info) <<
"Number of defined channels: " << noChannel;
80 for (
auto const& entry : fChannels) {
81 LOG(info) <<
"Channel name: " << entry.first;
84 if (entry.first ==
"syscmd") {
89 if (entry.first !=
"etofevts")
98 LOG(error) << e.what();
104 std::string channelName) {
106 LOG(info) <<
"Inspect " << entry;
107 std::size_t pos1 = channelName.find(entry);
108 if (pos1 != std::string::npos) {
109 const vector<std::string>::const_iterator
pos =
112 LOG(info) <<
"Found " << entry <<
" in " << channelName;
113 LOG(info) <<
"Channel name " << channelName
114 <<
" found in list of allowed channel names at position "
119 LOG(info) <<
"Channel name " << channelName
120 <<
" not found in list of allowed channel names.";
121 LOG(error) <<
"Stop device.";
127 <<
"Init parameter containers for CbmDeviceEventBuilderEtofStar2019.";
132 std::string message {
"CbmStar2019TofPar,111"};
134 <<
"Requesting parameter container CbmStar2019TofPar, sending message: "
137 FairMQMessagePtr req(NewSimpleMessage(
"CbmStar2019TofPar,111"));
138 FairMQMessagePtr rep(NewMessage());
140 if (Send(req,
"parameters") > 0) {
141 if (Receive(rep,
"parameters") >= 0) {
142 if (rep->GetSize() != 0) {
146 LOG(info) <<
"Received unpack parameter from parmq server: "
150 LOG(error) <<
"Received empty reply. Parameter not available";
158 Bool_t initOK = kTRUE;
167 std::vector<std::pair<TNamed*, std::string>> vHistos =
186 FairRuntimeDb* fRtdb = FairRuntimeDb::instance();
190 LOG(info) <<
"Setting parameter containers for " <<
fParCList->GetEntries()
193 for (Int_t iparC = 0; iparC <
fParCList->GetEntries(); ++iparC) {
194 FairParGenericSet* tempObj = (FairParGenericSet*) (
fParCList->At(iparC));
197 std::string sParamName {tempObj->GetName()};
199 FairParGenericSet* newObj =
200 dynamic_cast<FairParGenericSet*
>(fRtdb->getContainer(sParamName.data()));
201 LOG(info) <<
" - Get " << sParamName.data() <<
" at " << newObj;
202 if (
nullptr == newObj) {
204 LOG(error) <<
"Failed to obtain parameter container " << sParamName
205 <<
", for parameter index " << iparC;
210 LOG(info) <<
" - Mod " << sParamName.data() <<
" to " << newObj;
219 UShort_t usDetectorId) {
226 LOG(info) <<
"FIXME ===> Jumping 1st TS as corrupted with current FW + "
227 "FLESNET combination";
232 LOG(error) <<
"Failed processing TS " << ts.index()
233 <<
" in event builder algorithm class";
237 std::vector<CbmTofStarSubevent2019>& eventBuffer =
240 for (UInt_t uEvent = 0; uEvent < eventBuffer.size(); ++uEvent) {
242 Int_t iBuffSzByte = 0;
243 void* pDataBuff = eventBuffer[uEvent].BuildOutput(iBuffSzByte);
244 if (NULL != pDataBuff) {
259 SendSubevent(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(),
266 LOG(debug) <<
"Sent STAR event with size " << iBuffSzByte <<
" Bytes"
268 << eventBuffer[uEvent].GetTrigger().GetStarToken();
271 LOG(error) <<
"Invalid STAR SubEvent Output, can only happen if trigger "
272 <<
" object was not set => Do Nothing more with it!!! ";
281 <<
"ReInit parameter containers for CbmDeviceEventBuilderEtofStar2019";
293 LOG(debug) <<
"Received message number " <<
fNumMessages <<
" with size "
296 std::string msgStr(
static_cast<char*
>(msg->GetData()), msg->GetSize());
297 std::istringstream iss(msgStr);
298 boost::archive::binary_iarchive inputArchive(iss);
300 fles::StorableTimeslice component {0};
301 inputArchive >> component;
320 LOG(debug) <<
"Received message number " <<
fNumMessages <<
" with "
321 << parts.Size() <<
" parts";
323 fles::StorableTimeslice ts {0};
327 std::string msgStr(
static_cast<char*
>(parts.At(0)->GetData()),
328 (parts.At(0))->GetSize());
329 std::istringstream iss(msgStr);
330 boost::archive::binary_iarchive inputArchive(iss);
334 LOG(info) <<
"Initialize TS components list to " << ts.num_components();
335 for (
size_t c {0}; c < ts.num_components(); c++) {
336 auto systemID =
static_cast<int>(ts.descriptor(c, 0).sys_id);
337 LOG(info) <<
"Found systemID: " << std::hex << systemID << std::dec;
343 fles::StorableTimeslice component {0};
345 uint ncomp = parts.Size();
346 for (uint
i = 0;
i < ncomp;
i++) {
347 std::string msgStr(
static_cast<char*
>(parts.At(
i)->GetData()),
348 (parts.At(
i))->GetSize());
349 std::istringstream iss(msgStr);
350 boost::archive::binary_iarchive inputArchive(iss);
352 inputArchive >> component;
356 LOG(debug) <<
"HandleParts message " <<
fNumMessages <<
" with indx "
357 << component.index();
364 LOG(error) <<
"Failed processing TS " << ts.index()
365 <<
" in event builder algorithm class";
369 std::vector<CbmTofStarSubevent2019>& eventBuffer =
371 LOG(debug) <<
"Process time slice " <<
fNumMessages <<
" with "
372 << eventBuffer.size() <<
" events";
376 for (UInt_t uEvent = 0; uEvent < eventBuffer.size(); ++uEvent) {
378 Int_t iBuffSzByte = 0;
379 void* pDataBuff = eventBuffer[uEvent].BuildOutput(iBuffSzByte);
380 if (NULL != pDataBuff) {
395 SendSubevent(eventBuffer[uEvent].GetTrigger().GetStarTrigerWord(),
400 LOG(debug) <<
"Sent STAR event " << uEvent <<
" with size " << iBuffSzByte
403 << eventBuffer[uEvent].GetTrigger().GetStarToken()
405 << eventBuffer[uEvent].GetTrigger().GetStarTrigerWord();
411 <<
" TS, CPUtime: " <<
dctime / 10. <<
" ms/TS";
420 const char* cmd = (
char*) (msg->GetData());
421 const char cmda[4] = {*cmd};
422 LOG(info) <<
"Handle message " << cmd <<
", " << cmd[0];
427 if (strcmp(cmda,
"STOP")) {
443 const fles::Timeslice& ts) {
444 if (0 == ts.num_components()) {
445 LOG(error) <<
"No Component in TS " << ts.index();
448 auto tsIndex = ts.index();
450 LOG(debug) <<
"Found " << ts.num_components()
451 <<
" different components in timeslice " << tsIndex;
472 LOG(debug) <<
"Send Data for event " <<
fNumEvt <<
" with size "
473 << vdigi.size() << Form(
" at %p ", &vdigi);
476 std::stringstream oss;
477 boost::archive::binary_oarchive oa(oss);
479 std::string* strMsg =
new std::string(oss.str());
482 parts.AddPart(NewMessage(
483 const_cast<char*
>(strMsg->c_str()),
485 [](
void*,
void*
object) { delete static_cast<std::string*>(object); },
488 LOG(debug) <<
"Send data to channel " << idx <<
" "
507 LOG(debug) <<
"SendSubevent " <<
fNumEvt <<
", TrigWord " << trig
508 <<
" with size " << nData << Form(
" at %p ", pData);
510 std::stringstream ossE;
511 boost::archive::binary_oarchive oaE(ossE);
513 std::string* strMsgE =
new std::string(ossE.str());
522 std::string* strMsg =
new std::string(pData, nData);
525 parts.AddPart(NewMessage(
526 const_cast<char*
>(strMsgE->c_str()),
528 [](
void*,
void*
object) { delete static_cast<std::string*>(object); },
531 parts.AddPart(NewMessage(
532 const_cast<char*
>(strMsg->c_str()),
534 [](
void*,
void*
object) { delete static_cast<std::string*>(object); },
537 LOG(debug) <<
"Send data to channel " << idx <<
" "
555 LOG(info) <<
"Closing binary file used for event dump.";
562 std::vector<std::pair<TNamed*, std::string>> vHistos =
566 TDirectory* oldDir = NULL;
567 TFile* histoFile = NULL;
571 histoFile =
new TFile(
"data/eventBuilderMonHist.root",
"RECREATE");
575 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
577 gDirectory->mkdir(vHistos[uHisto].second.data());
578 gDirectory->cd(vHistos[uHisto].second.data());
581 vHistos[uHisto].first->Write();