CbmRoot
Loading...
Searching...
No Matches
CbmDeviceMcbmEventBuilderWin.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
13
14
16#include "CbmEvent.h"
17#include "CbmFlesCanvasTools.h"
18#include "CbmMQDefs.h"
19#include "CbmMatch.h"
20#include "CbmMvdDigi.h"
21
22#include "TimesliceMetaData.h"
23
25#include "FairMQLogger.h"
26#include "FairMQProgOptions.h" // device->fConfig
27#include "FairParGenericSet.h"
28#include "FairRunOnline.h"
29
30#include "BoostSerializer.h"
31
32#include "RootSerializer.h"
33
35#include "TCanvas.h"
36#include "TFile.h"
37#include "TH1.h"
38#include "TList.h"
39#include "TNamed.h"
40
41#include <boost/archive/binary_iarchive.hpp>
42#include <boost/serialization/utility.hpp>
43
45#include <array>
46#include <iomanip>
47#include <stdexcept>
48#include <string>
49struct InitTaskError : std::runtime_error {
50 using std::runtime_error::runtime_error;
51};
52
53using namespace std;
54
55//Bool_t bMcbm2018MonitorTaskBmonResetHistos = kFALSE;
56
58
60try {
62 LOG(info) << "Init options for CbmDeviceMcbmEventBuilderWin.";
63 fbFillHistos = fConfig->GetValue<bool>("FillHistos");
64 fbIgnoreTsOverlap = fConfig->GetValue<bool>("IgnOverMs");
65
66 fsEvtOverMode = fConfig->GetValue<std::string>("EvtOverMode");
67 fsRefDet = fConfig->GetValue<std::string>("RefDet");
68 fvsAddDet = fConfig->GetValue<std::vector<std::string>>("AddDet");
69 fvsDelDet = fConfig->GetValue<std::vector<std::string>>("DelDet");
70 fvsSetTrigWin = fConfig->GetValue<std::vector<std::string>>("SetTrigWin");
71 fvsSetTrigMinNb = fConfig->GetValue<std::vector<std::string>>("SetTrigMinNb");
72
73 fsChannelNameDataInput = fConfig->GetValue<std::string>("TsNameIn");
74 fsChannelNameDataOutput = fConfig->GetValue<std::string>("EvtNameOut");
75 fsChannelNameHistosInput = fConfig->GetValue<std::string>("ChNameIn");
76 fsChannelNameHistosConfig = fConfig->GetValue<std::string>("ChNameHistCfg");
77 fsChannelNameCanvasConfig = fConfig->GetValue<std::string>("ChNameCanvCfg");
79
80 fuPublishFreqTs = fConfig->GetValue<uint32_t>("PubFreqTs");
81 fdMinPublishTime = fConfig->GetValue<double_t>("PubTimeMin");
82 fdMaxPublishTime = fConfig->GetValue<double_t>("PubTimeMax");
83
84 // Get the information about created channels from the device
85 // Check if the defined channels from the topology (by name)
86 // are in the list of channels which are possible/allowed
87 // for the device
88 // The idea is to check at initilization if the devices are
89 // properly connected. For the time beeing this is done with a
90 // nameing convention. It is not avoided that someone sends other
91 // data on this channel.
92 //logger::SetLogLevel("INFO");
93 int noChannel = fChannels.size();
94 LOG(info) << "Number of defined channels: " << noChannel;
95 for (auto const& entry : fChannels) {
96 LOG(info) << "Channel name: " << entry.first;
97 if (std::string::npos != entry.first.find(fsChannelNameDataInput)) {
98 if (!IsChannelNameAllowed(entry.first)) throw InitTaskError("Channel name does not match.");
99 OnData(entry.first, &CbmDeviceMcbmEventBuilderWin::HandleData);
100 } // if( entry.first.find( "ts" )
101 } // for( auto const &entry : fChannels )
102
103 // InitContainers();
104
106 /* clang-format off */
107
112 EOverlapMode mode =
113 ("NoOverlap" == fsEvtOverMode ? EOverlapMode::NoOverlap
114 : ("MergeOverlap" == fsEvtOverMode ? EOverlapMode::MergeOverlap
115 : ("AllowOverlap" == fsEvtOverMode ? EOverlapMode::AllowOverlap
120 : ("kSts" == fsRefDet ? kEventBuilderDetSts
121 : ("kMuch" == fsRefDet ? kEventBuilderDetMuch
122 : ("kTrd" == fsRefDet ? kEventBuilderDetTrd
123 : ("kTof" == fsRefDet ? kEventBuilderDetTof
124 : ("kRich" == fsRefDet ? kEventBuilderDetRich
125 : ("kPsd" == fsRefDet ? kEventBuilderDetPsd
126 : kEventBuilderDetUndef)))))));
127 if (kEventBuilderDetUndef != refDet) {
129 } // if( kEventBuilderDetUndef != refDet )
130 else {
131 LOG(info) << "CbmDeviceMcbmEventBuilderWin::InitTask => Trying to change "
132 "reference to unsupported detector, ignored! "
133 << fsRefDet;
134 } // else of if( kEventBuilderDetUndef != refDet
135
137 for (std::vector<std::string>::iterator itStrAdd = fvsAddDet.begin();
138 itStrAdd != fvsAddDet.end();
139 ++itStrAdd) {
140 EventBuilderDetector addDet = ("kBmon" == *itStrAdd ? kEventBuilderDetBmon
141 : ("kSts" == *itStrAdd ? kEventBuilderDetSts
142 : ("kMuch" == *itStrAdd ? kEventBuilderDetMuch
143 : ("kTrd" == *itStrAdd ? kEventBuilderDetTrd
144 : ("kTof" == *itStrAdd ? kEventBuilderDetTof
145 : ("kRich" == *itStrAdd ? kEventBuilderDetRich
146 : ("kPsd" == *itStrAdd ? kEventBuilderDetPsd
147 : kEventBuilderDetUndef)))))));
148 if (kEventBuilderDetUndef != addDet) {
149 fpAlgo->AddDetector(addDet);
150 } // if( kEventBuilderDetUndef != addDet )
151 else {
152 LOG(info) << "CbmDeviceMcbmEventBuilderWin::InitTask => Trying to add "
153 "unsupported detector, ignored! "
154 << (*itStrAdd);
155 continue;
156 } // else of if( kEventBuilderDetUndef != addDet )
157 } // for( std::vector< std::string >::iterator itStrAdd = fvsAddDet.begin(); itStrAdd != fvsAddDet.end(); ++itStrAdd )
158
160 for (std::vector<std::string>::iterator itStrRem = fvsDelDet.begin();
161 itStrRem != fvsDelDet.end();
162 ++itStrRem) {
163 EventBuilderDetector remDet = ("kBmon" == *itStrRem ? kEventBuilderDetBmon
164 : ("kSts" == *itStrRem ? kEventBuilderDetSts
165 : ("kMuch" == *itStrRem ? kEventBuilderDetMuch
166 : ("kTrd" == *itStrRem ? kEventBuilderDetTrd
167 : ("kTof" == *itStrRem ? kEventBuilderDetTof
168 : ("kRich" == *itStrRem ? kEventBuilderDetRich
169 : ("kPsd" == *itStrRem ? kEventBuilderDetPsd
170 : kEventBuilderDetUndef)))))));
171 if (kEventBuilderDetUndef != remDet) {
172 fpAlgo->RemoveDetector(remDet);
173 } // if( kEventBuilderDetUndef != remDet )
174 else {
175 LOG(info) << "CbmDeviceMcbmEventBuilderWin::InitTask => Trying to remove "
176 "unsupported detector, ignored! "
177 << (*itStrRem);
178 continue;
179 } // else of if( kEventBuilderDetUndef != remDet )
180 } // for( std::vector< std::string >::iterator itStrAdd = fvsAddDet.begin(); itStrAdd != fvsAddDet.end(); ++itStrAdd )
182 for (std::vector<std::string>::iterator itStrTrigWin = fvsSetTrigWin.begin();
183 itStrTrigWin != fvsSetTrigWin.end();
184 ++itStrTrigWin) {
185 size_t charPosDel = (*itStrTrigWin).find(',');
186 if (std::string::npos == charPosDel) {
187 LOG(info)
188 << "CbmDeviceMcbmEventBuilderWin::InitTask => "
189 << "Trying to set trigger window with invalid option pattern, ignored! "
190 << " (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found "
191 << (*itStrTrigWin) << " )";
192 continue;
193 } // if( std::string::npos == charPosDel )
194
196 std::string sSelDet = (*itStrTrigWin).substr(0, charPosDel);
197 ECbmModuleId selDet = ("kBmon" == sSelDet ? ECbmModuleId::kBmon
198 : ("kSts" == sSelDet ? ECbmModuleId::kSts
199 : ("kMuch" == sSelDet ? ECbmModuleId::kMuch
200 : ("kTrd" == sSelDet ? ECbmModuleId::kTrd
201 : ("kTof" == sSelDet ? ECbmModuleId::kTof
202 : ("kRich" == sSelDet ? ECbmModuleId::kRich
203 : ("kPsd" == sSelDet ? ECbmModuleId::kPsd
205 if (ECbmModuleId::kNotExist == selDet) {
206 LOG(info)
207 << "CbmDeviceMcbmEventBuilderWin::InitTask => "
208 << "Trying to set trigger window for unsupported detector, ignored! "
209 << sSelDet;
210 continue;
211 } // if( ECbmModuleId::kNotExist == selDet )
212
214 charPosDel++;
215 std::string sNext = (*itStrTrigWin).substr(charPosDel);
216 charPosDel = sNext.find(',');
217 if (std::string::npos == charPosDel) {
218 LOG(info)
219 << "CbmDeviceMcbmEventBuilderWin::InitTask => "
220 << "Trying to set trigger window with invalid option pattern, ignored! "
221 << " (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found "
222 << (*itStrTrigWin) << " )";
223 continue;
224 } // if( std::string::npos == charPosDel )
225 Double_t dWinBeg = std::stod(sNext.substr(0, charPosDel));
226
228 charPosDel++;
229 Double_t dWinEnd = std::stod(sNext.substr(charPosDel));
230
231 fpAlgo->SetTriggerWindow(selDet, dWinBeg, dWinEnd);
232 } // for( std::vector< std::string >::iterator itStrTrigWin = fvsSetTrigWin.begin(); itStrTrigWin != fvsSetTrigWin.end(); ++itStrTrigWin )
234 for (std::vector<std::string>::iterator itStrMinNb = fvsSetTrigMinNb.begin();
235 itStrMinNb != fvsSetTrigMinNb.end();
236 ++itStrMinNb) {
237 size_t charPosDel = (*itStrMinNb).find(',');
238 if (std::string::npos == charPosDel) {
239 LOG(info)
240 << "CbmDeviceMcbmEventBuilderWin::InitTask => "
241 << "Trying to set trigger min Nb with invalid option pattern, ignored! "
242 << " (Should be ECbmModuleId,uMinNb but instead found " << (*itStrMinNb)
243 << " )";
244 continue;
245 } // if( std::string::npos == charPosDel )
246
248 std::string sSelDet = (*itStrMinNb).substr(0, charPosDel);
249 ECbmModuleId selDet = ("kBmon" == sSelDet ? ECbmModuleId::kBmon
250 : ("kSts" == sSelDet ? ECbmModuleId::kSts
251 : ("kMuch" == sSelDet ? ECbmModuleId::kMuch
252 : ("kTrd" == sSelDet ? ECbmModuleId::kTrd
253 : ("kTof" == sSelDet ? ECbmModuleId::kTof
254 : ("kRich" == sSelDet ? ECbmModuleId::kRich
255 : ("kPsd" == sSelDet ? ECbmModuleId::kPsd
257 if (ECbmModuleId::kNotExist == selDet) {
258 LOG(info)
259 << "CbmDeviceMcbmEventBuilderWin::InitTask => "
260 << "Trying to set trigger min Nb for unsupported detector, ignored! "
261 << sSelDet;
262 continue;
263 } // if( ECbmModuleId::kNotExist == selDet )
264
266 charPosDel++;
267 UInt_t uMinNb = std::stoul((*itStrMinNb).substr(charPosDel));
268
269 fpAlgo->SetTriggerMinNumber(selDet, uMinNb);
270 } // for( std::vector< std::string >::iterator itStrMinNb = fvsSetTrigMinNb.begin(); itStrMinNb != fvsSetTrigMinNb.end(); ++itStrMinNb )
271
273 /* clang-format on */
274
276 fvDigiBmon = new std::vector<CbmTofDigi>();
277 fvDigiSts = new std::vector<CbmStsDigi>();
278 fvDigiMuch = new std::vector<CbmMuchBeamTimeDigi>();
279 fvDigiTrd = new std::vector<CbmTrdDigi>();
280 fvDigiTof = new std::vector<CbmTofDigi>();
281 fvDigiRich = new std::vector<CbmRichDigi>();
282 fvDigiPsd = new std::vector<CbmPsdDigi>();
283
285 fpRun = new FairRunOnline(0);
286 FairRootManager* ioman = nullptr;
287 ioman = FairRootManager::Instance();
288 if (NULL == ioman) { throw InitTaskError("No FairRootManager instance"); }
289 fTimeSliceMetaDataArray = new TClonesArray("TimesliceMetaData", 1);
290 if (NULL == fTimeSliceMetaDataArray) { throw InitTaskError("Failed creating the TS meta data TClonesarray "); }
291 ioman->Register("TimesliceMetaData", "TS Meta Data", fTimeSliceMetaDataArray, kFALSE);
293 ioman->RegisterAny("BmonDigi", fvDigiBmon, kFALSE);
294 ioman->RegisterAny("StsDigi", fvDigiSts, kFALSE);
295 ioman->RegisterAny("MuchBeamTimeDigi", fvDigiMuch, kFALSE);
296 ioman->RegisterAny("TrdDigi", fvDigiTrd, kFALSE);
297 ioman->RegisterAny("TofDigi", fvDigiTof, kFALSE);
298 ioman->RegisterAny("RichDigi", fvDigiRich, kFALSE);
299 ioman->RegisterAny("PsdDigi", fvDigiPsd, kFALSE);
302 std::vector<CbmMvdDigi>* pMvdDigi = new std::vector<CbmMvdDigi>();
303 ioman->RegisterAny("MvdDigi", pMvdDigi, kFALSE);
304 std::vector<CbmMatch>* pFakeMatch = new std::vector<CbmMatch>();
305 ioman->RegisterAny("MvdDigiMatch", pFakeMatch, kFALSE);
306 ioman->RegisterAny("StsDigiMatch", pFakeMatch, kFALSE);
307 ioman->RegisterAny("MuchBeamTimeDigiMatch", pFakeMatch, kFALSE);
308 ioman->RegisterAny("TrdDigiMatch", pFakeMatch, kFALSE);
309 ioman->RegisterAny("TofDigiMatch", pFakeMatch, kFALSE);
310 ioman->RegisterAny("RichDigiMatch", pFakeMatch, kFALSE);
311 ioman->RegisterAny("PsdDigiMatch", pFakeMatch, kFALSE);
312
315 fEvents = new TClonesArray("CbmEvent", 500);
316
318 if (kFALSE == fpAlgo->InitAlgo()) {
319 throw InitTaskError("Failed to initilize the algorithm class.");
320 } // if( kFALSE == fpAlgo->InitAlgo() )
321
323 if (kTRUE == fbFillHistos) {
325 std::vector<std::pair<TNamed*, std::string>> vHistos = fpAlgo->GetHistoVector();
327 std::vector<std::pair<TCanvas*, std::string>> vCanvases = fpAlgo->GetCanvasVector();
328
333 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
334 // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
335 // << " in " << vHistos[ uHisto ].second.data()
336 // ;
337 fArrayHisto.Add(vHistos[uHisto].first);
338 std::pair<std::string, std::string> psHistoConfig(vHistos[uHisto].first->GetName(), vHistos[uHisto].second);
339 fvpsHistosFolder.push_back(psHistoConfig);
340
342 FairMQMessagePtr messageHist(NewMessage());
343 // Serialize<BoostSerializer<std::pair<std::string, std::string>>>(*messageHist, psHistoConfig);
344 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageHist, psHistoConfig);
345
347 if (Send(messageHist, fsChannelNameHistosConfig) < 0) {
348 throw InitTaskError("Problem sending histo config");
349 } // if( Send( messageHist, fsChannelNameHistosConfig ) < 0 )
350
351 LOG(info) << "Config of hist " << psHistoConfig.first.data() << " in folder " << psHistoConfig.second.data();
352 } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
353
357 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
358 // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
359 // << " in " << vCanvases[ uCanv ].second.data();
360 std::string sCanvName = (vCanvases[uCanv].first)->GetName();
361 std::string sCanvConf = GenerateCanvasConfigString(vCanvases[uCanv].first);
362
363 std::pair<std::string, std::string> psCanvConfig(sCanvName, sCanvConf);
364
365 fvpsCanvasConfig.push_back(psCanvConfig);
366
368 FairMQMessagePtr messageCan(NewMessage());
369 // Serialize<BoostSerializer<std::pair<std::string, std::string>>>(*messageCan, psCanvConfig);
370 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageCan, psCanvConfig);
371
373 if (Send(messageCan, fsChannelNameCanvasConfig) < 0) {
374 throw InitTaskError("Problem sending canvas config");
375 } // if( Send( messageCan, fsChannelNameCanvasConfig ) < 0 )
376
377 LOG(info) << "Config string of Canvas " << psCanvConfig.first.data() << " is " << psCanvConfig.second.data();
378 } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
379 } // if( kTRUE == fbFillHistos )
380}
381catch (InitTaskError& e) {
382 LOG(error) << e.what();
383 // Wrapper defined in CbmMQDefs.h to support different FairMQ versions
385}
386
388{
389 for (auto const& entry : fsAllowedChannels) {
390 std::size_t pos1 = channelName.find(entry);
391 if (pos1 != std::string::npos) {
392 const vector<std::string>::const_iterator pos =
393 std::find(fsAllowedChannels.begin(), fsAllowedChannels.end(), entry);
394 const vector<std::string>::size_type idx = pos - fsAllowedChannels.begin();
395 LOG(info) << "Found " << entry << " in " << channelName;
396 LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
397 return true;
398 } // if (pos1!=std::string::npos)
399 } // for(auto const &entry : fsAllowedChannels)
400 LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
401 LOG(error) << "Stop device.";
402 return false;
403}
404/*
405Bool_t CbmDeviceMcbmEventBuilderWin::InitContainers()
406{
407 LOG(info) << "Init parameter containers for CbmDeviceMcbmEventBuilderWin.";
408
409 if( kFALSE == InitParameters( fpAlgo ->GetParList() ) )
410 return kFALSE;
411
413 fpAlgo ->SetIgnoreOverlapMs( fbIgnoreOverlapMs );
414
415 Bool_t initOK = fpAlgo->InitContainers();
416
417// Bool_t initOK = fMonitorAlgo->ReInitContainers();
418
419 return initOK;
420}
421
422Bool_t CbmDeviceMcbmEventBuilderWin::InitParameters( TList* fParCList )
423{
424 for( int iparC = 0; iparC < fParCList->GetEntries(); iparC++ )
425 {
426 FairParGenericSet* tempObj = (FairParGenericSet*)( fParCList->At( iparC ) );
427 fParCList->Remove( tempObj );
428 std::string paramName{ tempObj->GetName() };
429 // NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
430 // Should only be used for small data because of the cost of an additional copy
431
432 // Her must come the proper Runid
433 std::string message = paramName + ",111";
434 LOG(info) << "Requesting parameter container " << paramName << ", sending message: " << message;
435
436 FairMQMessagePtr req( NewSimpleMessage(message) );
437 FairMQMessagePtr rep( NewMessage() );
438
439 FairParGenericSet* newObj = nullptr;
440
441 if( Send(req, "parameters") > 0 )
442 {
443 if( Receive( rep, "parameters" ) >= 0)
444 {
445 if( 0 != rep->GetSize() )
446 {
447 CbmMqTMessage tmsg( rep->GetData(), rep->GetSize() );
448 newObj = static_cast< FairParGenericSet* >( tmsg.ReadObject( tmsg.GetClass() ) );
449 LOG( info ) << "Received unpack parameter from the server:";
450 newObj->print();
451 } // if( 0 != rep->GetSize() )
452 else
453 {
454 LOG( error ) << "Received empty reply. Parameter not available";
455 return kFALSE;
456 } // else of if( 0 != rep->GetSize() )
457 } // if( Receive( rep, "parameters" ) >= 0)
458 } // if( Send(req, "parameters") > 0 )
459 fParCList->AddAt( newObj, iparC );
460 delete tempObj;
461 } // for( int iparC = 0; iparC < fParCList->GetEntries(); iparC++ )
462
463 return kTRUE;
464}
465*/
466// handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
467bool CbmDeviceMcbmEventBuilderWin::HandleData(FairMQParts& parts, int /*index*/)
468{
470 LOG(debug) << "Received message number " << fulNumMessages << " with " << parts.Size() << " parts"
471 << ", size0: " << parts.At(0)->GetSize();
472
473 if (0 == fulNumMessages % 10000) LOG(info) << "Received " << fulNumMessages << " messages";
474
476 uint32_t uPartIdx = 0;
479 /*
480 std::string msgStrTsMeta( static_cast< char * >( parts.At( uPartIdx )->GetData() ),
481 ( parts.At( uPartIdx ) )->GetSize() );
482 std::istringstream issTsMeta(msgStrTsMeta);
483 boost::archive::binary_iarchive inputArchiveTsMeta(issTsMeta);
484 inputArchiveTsMeta >> (*fTsMetaData);
485 ++uPartIdx;
486*/
487 // Deserialize<RootSerializer>(*parts.At(uPartIdx), fTsMetaData);
488 RootSerializer().Deserialize(*parts.At(uPartIdx), fTsMetaData);
490 new ((*fTimeSliceMetaDataArray)[fTimeSliceMetaDataArray->GetEntriesFast()
491 // ] ) TimesliceMetaData( *fTsMetaData ) ;
492 ]) TimesliceMetaData(std::move(*fTsMetaData));
493 ++uPartIdx;
494
496 std::string msgStrBmon(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
497 std::istringstream issBmon(msgStrBmon);
498 boost::archive::binary_iarchive inputArchiveBmon(issBmon);
499 inputArchiveBmon >> *fvDigiBmon;
500 ++uPartIdx;
501
503 std::string msgStrSts(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
504 std::istringstream issSts(msgStrSts);
505 boost::archive::binary_iarchive inputArchiveSts(issSts);
506 inputArchiveSts >> *fvDigiSts;
507 ++uPartIdx;
508
510 std::string msgStrMuch(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
511 std::istringstream issMuch(msgStrMuch);
512 boost::archive::binary_iarchive inputArchiveMuch(issMuch);
513 inputArchiveMuch >> *fvDigiMuch;
514 ++uPartIdx;
515
517 std::string msgStrTrd(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
518 std::istringstream issTrd(msgStrTrd);
519 boost::archive::binary_iarchive inputArchiveTrd(issTrd);
520 inputArchiveTrd >> *fvDigiTrd;
521 ++uPartIdx;
522
524 std::string msgStrTof(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
525 std::istringstream issTof(msgStrTof);
526 boost::archive::binary_iarchive inputArchiveTof(issTof);
527 inputArchiveTof >> *fvDigiTof;
528 ++uPartIdx;
529
531 std::string msgStrRich(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
532 std::istringstream issRich(msgStrRich);
533 boost::archive::binary_iarchive inputArchiveRich(issRich);
534 inputArchiveRich >> *fvDigiRich;
535 ++uPartIdx;
536
538 std::string msgStrPsd(static_cast<char*>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
539 std::istringstream issPsd(msgStrPsd);
540 boost::archive::binary_iarchive inputArchivePsd(issPsd);
541 inputArchivePsd >> *fvDigiPsd;
542 ++uPartIdx;
543
545 fpAlgo->ProcessTs();
546
548 if (!SendEvents(parts)) return false;
549
552 // delete fTsMetaData;
553
555 fvDigiBmon->clear();
556 fvDigiSts->clear();
557 fvDigiMuch->clear();
558 fvDigiTrd->clear();
559 fvDigiTof->clear();
560 fvDigiRich->clear();
561 fvDigiPsd->clear();
562
565 fEvents->Clear("C");
566 // fEvents->Clear();
567
569 if (kTRUE == fbFillHistos) {
573 std::chrono::system_clock::time_point currentTime = std::chrono::system_clock::now();
574 std::chrono::duration<double_t> elapsedSeconds = currentTime - fLastPublishTime;
575 if ((fdMaxPublishTime < elapsedSeconds.count())
576 || (0 == fulNumMessages % fuPublishFreqTs && fdMinPublishTime < elapsedSeconds.count())) {
578 fLastPublishTime = std::chrono::system_clock::now();
579 } // if( ( fdMaxPublishTime < elapsedSeconds.count() ) || ( 0 == fulNumMessages % fuPublishFreqTs && fdMinPublishTime < elapsedSeconds.count() ) )
580 } // if( kTRUE == fbFillHistos )
581
582 return true;
583}
584
586{
588 fEvents->Delete();
589 // fEvents->Clear();
590
592 std::vector<CbmEvent*> vEvents = fpAlgo->GetEventVector();
593
595 for (CbmEvent* event : vEvents) {
596 LOG(debug) << "Vector: " << event->ToString();
597 new ((*fEvents)[fEvents->GetEntriesFast()]) CbmEvent(std::move(*event));
598 // new ( (*fEvents)[fEvents->GetEntriesFast()] ) CbmEvent( *event );
599 LOG(debug) << "TClonesArray: " << static_cast<CbmEvent*>(fEvents->At(fEvents->GetEntriesFast() - 1))->ToString();
600 } // for( CbmEvent* event: vEvents )
601
603 FairMQMessagePtr message(NewMessage());
604 // Serialize<RootSerializer>(*message, fEvents);
605 RootSerializer().Serialize(*message, fEvents);
606
609 FairMQParts partsOut(std::move(partsIn));
610 partsOut.AddPart(std::move(message));
611
612 // /// Get vector from algo
613 // fEventVector = fpAlgo->GetEventVector();
614 //
615 // /// Prepare serialized versions of the events vector
616 // std::stringstream ossEvents;
617 // boost::archive::binary_oarchive oaEvents(ossEvents);
618 // oaEvents << fpAlgo->GetEventVector();
619 // std::string* strMsgEvents = new std::string(ossEvents.str());
620 //
621 // /// Create message
622 // FairMQMessagePtr msg( NewMessage( const_cast< char * >( strMsgEvents->c_str() ), // data
623 // strMsgEvents->length(), // size
624 // []( void * /*data*/, void* object ){ delete static_cast< std::string * >( object ); },
625 // strMsgEvents ) ); // object that manages the data
626
628 // if( Send( message, fsChannelNameDataOutput ) < 0 )
629 if (Send(partsOut, fsChannelNameDataOutput) < 0) {
630 LOG(error) << "Problem sending data to " << fsChannelNameDataOutput;
631 return false;
632 }
633
634 return true;
635}
636
638{
640 FairMQMessagePtr message(NewMessage());
641 // Serialize<RootSerializer>(*message, &fArrayHisto);
642 RootSerializer().Serialize(*message, &fArrayHisto);
643
645 if (Send(message, fsChannelNameHistosInput) < 0) {
646 LOG(error) << "Problem sending data";
647 return false;
648 } // if( Send( message, fsChannelNameHistosInput ) < 0 )
649
651 fpAlgo->ResetHistograms(kFALSE);
652
653 return true;
654}
655
657{
660 delete fTsMetaData;
661
663 fvDigiBmon->clear();
664 fvDigiSts->clear();
665 fvDigiMuch->clear();
666 fvDigiTrd->clear();
667 fvDigiTof->clear();
668 fvDigiRich->clear();
669 fvDigiPsd->clear();
670
672 fEvents->Delete();
673
674 delete fpRun;
675
677 delete fEvents;
678
679 delete fpAlgo;
680}
681
ECbmModuleId
Definition CbmDefs.h:39
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kNotExist
If not found.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
std::string GenerateCanvasConfigString(TCanvas *pCanv)
static const EventBuilderDetector kEventBuilderDetSts
Pre-defined detector types.
static const EventBuilderDetector kEventBuilderDetPsd
static const EventBuilderDetector kEventBuilderDetUndef
static const EventBuilderDetector kEventBuilderDetBmon
static const EventBuilderDetector kEventBuilderDetTrd
static const EventBuilderDetector kEventBuilderDetRich
static const EventBuilderDetector kEventBuilderDetMuch
static const EventBuilderDetector kEventBuilderDetTof
bool first
CbmMcbm2019TimeWinEventBuilderAlgo * fpAlgo
Processing algos.
bool IsChannelNameAllowed(std::string channelName)
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string pairs with ( HistoName, FolderPath ) to send to the histogram server.
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
std::chrono::system_clock::time_point fLastPublishTime
std::vector< std::string > fvsSetTrigWin
std::vector< std::string > fvsSetTrigMinNb
TClonesArray * fTimeSliceMetaDataArray
Total size of all MS in a TS, [nanoseconds].
std::vector< CbmMuchBeamTimeDigi > * fvDigiMuch
uint64_t fulNumMessages
Parameters management.
std::vector< std::string > fsAllowedChannels
List of MQ channels names.
std::string fsChannelNameDataInput
message queues
std::vector< CbmTofDigi > * fvDigiBmon
Digis storage.
Bool_t fbFillHistos
Ignore data in Overlap part of the TS.
uint32_t fuPublishFreqTs
Histograms management.
std::vector< CbmRichDigi > * fvDigiRich
std::string fsEvtOverMode
Switch ON/OFF filling of histograms.
FairRunOnline * fpRun
output container of CbmEvents
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
std::string ToString() const
Definition CbmEvent.cxx:96
void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal)
void SetReferenceDetector(ECbmModuleId refDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
void AddDetector(ECbmModuleId selDet, ECbmDataType dataTypeIn, std::string sNameIn, UInt_t uTriggerMinDigisIn=0, Int_t iTriggerMaxDigisIn=-1, Double_t fdTimeWinBegIn=-100, Double_t fdTimeWinEndIn=100)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void SetEventOverlapMode(EOverlapMode mode)
Control flags.
std::vector< CbmEvent * > & GetEventVector()
Data output access.
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)
Definition CbmMQDefs.h:26
Hash for CbmL1LinkKey.