CbmRoot
CbmDeviceMcbmEventBuilderWin.cxx
Go to the documentation of this file.
1 
9 
10 
12 #include "CbmMQDefs.h"
13 
14 #include "CbmEvent.h"
15 #include "CbmFlesCanvasTools.h"
16 #include "CbmMatch.h"
17 #include "CbmMvdDigi.h"
18 #include "TimesliceMetaData.h"
19 
21 #include "BoostSerializer.h"
22 #include "FairMQLogger.h"
23 #include "FairMQProgOptions.h" // device->fConfig
24 #include "FairParGenericSet.h"
25 #include "FairRunOnline.h"
26 #include "RootSerializer.h"
27 
29 #include "TCanvas.h"
30 #include "TFile.h"
31 #include "TH1.h"
32 #include "TList.h"
33 #include "TNamed.h"
34 #include <boost/archive/binary_iarchive.hpp>
35 #include <boost/serialization/utility.hpp>
36 
38 #include <array>
39 #include <iomanip>
40 #include <string>
41 
42 #include <stdexcept>
43 struct InitTaskError : std::runtime_error {
44  using std::runtime_error::runtime_error;
45 };
46 
47 using namespace std;
48 
49 //Bool_t bMcbm2018MonitorTaskT0ResetHistos = kFALSE;
50 
53 }
54 
57  LOG(info) << "Init options for CbmDeviceMcbmEventBuilderWin.";
58  fbFillHistos = fConfig->GetValue<bool>("FillHistos");
59  fbIgnoreTsOverlap = fConfig->GetValue<bool>("IgnOverMs");
60 
61  fsEvtOverMode = fConfig->GetValue<std::string>("EvtOverMode");
62  fsRefDet = fConfig->GetValue<std::string>("RefDet");
63  fvsAddDet = fConfig->GetValue<std::vector<std::string>>("AddDet");
64  fvsDelDet = fConfig->GetValue<std::vector<std::string>>("DelDet");
65  fvsSetTrigWin = fConfig->GetValue<std::vector<std::string>>("SetTrigWin");
66  fvsSetTrigMinNb = fConfig->GetValue<std::vector<std::string>>("SetTrigMinNb");
67 
68  fsChannelNameDataInput = fConfig->GetValue<std::string>("TsNameIn");
69  fsChannelNameDataOutput = fConfig->GetValue<std::string>("EvtNameOut");
70  fsChannelNameHistosInput = fConfig->GetValue<std::string>("ChNameIn");
71  fsChannelNameHistosConfig = fConfig->GetValue<std::string>("ChNameHistCfg");
72  fsChannelNameCanvasConfig = fConfig->GetValue<std::string>("ChNameCanvCfg");
73  fsAllowedChannels[0] = fsChannelNameDataInput;
74 
75  fuPublishFreqTs = fConfig->GetValue<uint32_t>("PubFreqTs");
76  fdMinPublishTime = fConfig->GetValue<double_t>("PubTimeMin");
77  fdMaxPublishTime = fConfig->GetValue<double_t>("PubTimeMax");
78 
79  // Get the information about created channels from the device
80  // Check if the defined channels from the topology (by name)
81  // are in the list of channels which are possible/allowed
82  // for the device
83  // The idea is to check at initilization if the devices are
84  // properly connected. For the time beeing this is done with a
85  // nameing convention. It is not avoided that someone sends other
86  // data on this channel.
87  //logger::SetLogLevel("INFO");
88  int noChannel = fChannels.size();
89  LOG(info) << "Number of defined channels: " << noChannel;
90  for (auto const& entry : fChannels) {
91  LOG(info) << "Channel name: " << entry.first;
92  if (std::string::npos != entry.first.find(fsChannelNameDataInput)) {
93  if (!IsChannelNameAllowed(entry.first))
94  throw InitTaskError("Channel name does not match.");
95  OnData(entry.first, &CbmDeviceMcbmEventBuilderWin::HandleData);
96  } // if( entry.first.find( "ts" )
97  } // for( auto const &entry : fChannels )
98 
99  // InitContainers();
100 
102  /* clang-format off */
103 
105  fpAlgo->SetFillHistos(fbFillHistos);
106  fpAlgo->SetIgnoreTsOverlap(fbIgnoreTsOverlap);
108  EOverlapMode mode =
109  ("NoOverlap" == fsEvtOverMode ? EOverlapMode::NoOverlap
110  : ("MergeOverlap" == fsEvtOverMode ? EOverlapMode::MergeOverlap
111  : ("AllowOverlap" == fsEvtOverMode ? EOverlapMode::AllowOverlap
113  fpAlgo->SetEventOverlapMode(mode);
115  EventBuilderDetector refDet = ("kT0" == fsRefDet ? kEventBuilderDetT0
116  : ("kSts" == fsRefDet ? kEventBuilderDetMuch
117  : ("kMuch" == fsRefDet ? kEventBuilderDetTrd
118  : ("kTrd" == fsRefDet ? kEventBuilderDetTrd
119  : ("kTof" == fsRefDet ? kEventBuilderDetTof
120  : ("kRich" == fsRefDet ? kEventBuilderDetRich
121  : ("kPsd" == fsRefDet ? kEventBuilderDetPsd
122  : kEventBuilderDetUndef)))))));
123  if (kEventBuilderDetUndef != refDet) {
124  fpAlgo->SetReferenceDetector(refDet);
125  } // if( kEventBuilderDetUndef != refDet )
126  else {
127  LOG(info) << "CbmDeviceMcbmEventBuilderWin::InitTask => Trying to change "
128  "reference to unsupported detector, ignored! "
129  << fsRefDet;
130  } // else of if( kEventBuilderDetUndef != refDet
131 
133  for (std::vector<std::string>::iterator itStrAdd = fvsAddDet.begin();
134  itStrAdd != fvsAddDet.end();
135  ++itStrAdd) {
136  EventBuilderDetector addDet = ("kT0" == *itStrAdd ? kEventBuilderDetT0
137  : ("kSts" == *itStrAdd ? kEventBuilderDetSts
138  : ("kMuch" == *itStrAdd ? kEventBuilderDetMuch
139  : ("kTrd" == *itStrAdd ? kEventBuilderDetTrd
140  : ("kTof" == *itStrAdd ? kEventBuilderDetTof
141  : ("kRich" == *itStrAdd ? kEventBuilderDetRich
142  : ("kPsd" == *itStrAdd ? kEventBuilderDetPsd
143  : kEventBuilderDetUndef)))))));
144  if (kEventBuilderDetUndef != addDet) {
145  fpAlgo->AddDetector(addDet);
146  } // if( kEventBuilderDetUndef != addDet )
147  else {
148  LOG(info) << "CbmDeviceMcbmEventBuilderWin::InitTask => Trying to add "
149  "unsupported detector, ignored! "
150  << (*itStrAdd);
151  continue;
152  } // else of if( kEventBuilderDetUndef != addDet )
153  } // for( std::vector< std::string >::iterator itStrAdd = fvsAddDet.begin(); itStrAdd != fvsAddDet.end(); ++itStrAdd )
154 
156  for (std::vector<std::string>::iterator itStrRem = fvsDelDet.begin();
157  itStrRem != fvsDelDet.end();
158  ++itStrRem) {
159  EventBuilderDetector remDet = ("kT0" == *itStrRem ? kEventBuilderDetT0
160  : ("kSts" == *itStrRem ? kEventBuilderDetSts
161  : ("kMuch" == *itStrRem ? kEventBuilderDetMuch
162  : ("kTrd" == *itStrRem ? kEventBuilderDetTrd
163  : ("kTof" == *itStrRem ? kEventBuilderDetTof
164  : ("kRich" == *itStrRem ? kEventBuilderDetRich
165  : ("kPsd" == *itStrRem ? kEventBuilderDetPsd
166  : kEventBuilderDetUndef)))))));
167  if (kEventBuilderDetUndef != remDet) {
168  fpAlgo->RemoveDetector(remDet);
169  } // if( kEventBuilderDetUndef != remDet )
170  else {
171  LOG(info) << "CbmDeviceMcbmEventBuilderWin::InitTask => Trying to remove "
172  "unsupported detector, ignored! "
173  << (*itStrRem);
174  continue;
175  } // else of if( kEventBuilderDetUndef != remDet )
176  } // for( std::vector< std::string >::iterator itStrAdd = fvsAddDet.begin(); itStrAdd != fvsAddDet.end(); ++itStrAdd )
178  for (std::vector<std::string>::iterator itStrTrigWin = fvsSetTrigWin.begin();
179  itStrTrigWin != fvsSetTrigWin.end();
180  ++itStrTrigWin) {
181  size_t charPosDel = (*itStrTrigWin).find(',');
182  if (std::string::npos == charPosDel) {
183  LOG(info)
184  << "CbmDeviceMcbmEventBuilderWin::InitTask => "
185  << "Trying to set trigger window with invalid option pattern, ignored! "
186  << " (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found "
187  << (*itStrTrigWin) << " )";
188  continue;
189  } // if( std::string::npos == charPosDel )
190 
192  std::string sSelDet = (*itStrTrigWin).substr(0, charPosDel);
193  ECbmModuleId selDet = ("kT0" == sSelDet ? ECbmModuleId::kT0
194  : ("kSts" == sSelDet ? ECbmModuleId::kSts
195  : ("kMuch" == sSelDet ? ECbmModuleId::kMuch
196  : ("kTrd" == sSelDet ? ECbmModuleId::kTrd
197  : ("kTof" == sSelDet ? ECbmModuleId::kTof
198  : ("kRich" == sSelDet ? ECbmModuleId::kRich
199  : ("kPsd" == sSelDet ? ECbmModuleId::kPsd
200  : ECbmModuleId::kNotExist)))))));
201  if (ECbmModuleId::kNotExist == selDet) {
202  LOG(info)
203  << "CbmDeviceMcbmEventBuilderWin::InitTask => "
204  << "Trying to set trigger window for unsupported detector, ignored! "
205  << sSelDet;
206  continue;
207  } // if( ECbmModuleId::kNotExist == selDet )
208 
210  charPosDel++;
211  std::string sNext = (*itStrTrigWin).substr(charPosDel);
212  charPosDel = sNext.find(',');
213  if (std::string::npos == charPosDel) {
214  LOG(info)
215  << "CbmDeviceMcbmEventBuilderWin::InitTask => "
216  << "Trying to set trigger window with invalid option pattern, ignored! "
217  << " (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found "
218  << (*itStrTrigWin) << " )";
219  continue;
220  } // if( std::string::npos == charPosDel )
221  Double_t dWinBeg = std::stod(sNext.substr(0, charPosDel));
222 
224  charPosDel++;
225  Double_t dWinEnd = std::stod(sNext.substr(charPosDel));
226 
227  fpAlgo->SetTriggerWindow(selDet, dWinBeg, dWinEnd);
228  } // for( std::vector< std::string >::iterator itStrTrigWin = fvsSetTrigWin.begin(); itStrTrigWin != fvsSetTrigWin.end(); ++itStrTrigWin )
230  for (std::vector<std::string>::iterator itStrMinNb = fvsSetTrigMinNb.begin();
231  itStrMinNb != fvsSetTrigMinNb.end();
232  ++itStrMinNb) {
233  size_t charPosDel = (*itStrMinNb).find(',');
234  if (std::string::npos == charPosDel) {
235  LOG(info)
236  << "CbmDeviceMcbmEventBuilderWin::InitTask => "
237  << "Trying to set trigger min Nb with invalid option pattern, ignored! "
238  << " (Should be ECbmModuleId,uMinNb but instead found " << (*itStrMinNb)
239  << " )";
240  continue;
241  } // if( std::string::npos == charPosDel )
242 
244  std::string sSelDet = (*itStrMinNb).substr(0, charPosDel);
245  ECbmModuleId selDet = ("kT0" == sSelDet ? ECbmModuleId::kT0
246  : ("kSts" == sSelDet ? ECbmModuleId::kSts
247  : ("kMuch" == sSelDet ? ECbmModuleId::kMuch
248  : ("kTrd" == sSelDet ? ECbmModuleId::kTrd
249  : ("kTof" == sSelDet ? ECbmModuleId::kTof
250  : ("kRich" == sSelDet ? ECbmModuleId::kRich
251  : ("kPsd" == sSelDet ? ECbmModuleId::kPsd
252  : ECbmModuleId::kNotExist)))))));
253  if (ECbmModuleId::kNotExist == selDet) {
254  LOG(info)
255  << "CbmDeviceMcbmEventBuilderWin::InitTask => "
256  << "Trying to set trigger min Nb for unsupported detector, ignored! "
257  << sSelDet;
258  continue;
259  } // if( ECbmModuleId::kNotExist == selDet )
260 
262  charPosDel++;
263  UInt_t uMinNb = std::stoul((*itStrMinNb).substr(charPosDel));
264 
265  fpAlgo->SetTriggerMinNumber(selDet, uMinNb);
266  } // for( std::vector< std::string >::iterator itStrMinNb = fvsSetTrigMinNb.begin(); itStrMinNb != fvsSetTrigMinNb.end(); ++itStrMinNb )
267 
269  /* clang-format on */
270 
272  fvDigiT0 = new std::vector<CbmTofDigi>();
273  fvDigiSts = new std::vector<CbmStsDigi>();
274  fvDigiMuch = new std::vector<CbmMuchBeamTimeDigi>();
275  fvDigiTrd = new std::vector<CbmTrdDigi>();
276  fvDigiTof = new std::vector<CbmTofDigi>();
277  fvDigiRich = new std::vector<CbmRichDigi>();
278  fvDigiPsd = new std::vector<CbmPsdDigi>();
279 
281  fpRun = new FairRunOnline(0);
282  FairRootManager* ioman = nullptr;
283  ioman = FairRootManager::Instance();
284  if (NULL == ioman) { throw InitTaskError("No FairRootManager instance"); }
285  fTimeSliceMetaDataArray = new TClonesArray("TimesliceMetaData", 1);
286  if (NULL == fTimeSliceMetaDataArray) {
287  throw InitTaskError("Failed creating the TS meta data TClonesarray ");
288  }
289  ioman->Register(
290  "TimesliceMetaData", "TS Meta Data", fTimeSliceMetaDataArray, kFALSE);
292  ioman->RegisterAny("T0Digi", fvDigiT0, kFALSE);
293  ioman->RegisterAny("StsDigi", fvDigiSts, kFALSE);
294  ioman->RegisterAny("MuchBeamTimeDigi", fvDigiMuch, kFALSE);
295  ioman->RegisterAny("TrdDigi", fvDigiTrd, kFALSE);
296  ioman->RegisterAny("TofDigi", fvDigiTof, kFALSE);
297  ioman->RegisterAny("RichDigi", fvDigiRich, kFALSE);
298  ioman->RegisterAny("PsdDigi", fvDigiPsd, kFALSE);
301  std::vector<CbmMvdDigi>* pMvdDigi = new std::vector<CbmMvdDigi>();
302  ioman->RegisterAny("MvdDigi", pMvdDigi, kFALSE);
303  std::vector<CbmMatch>* pFakeMatch = new std::vector<CbmMatch>();
304  ioman->RegisterAny("MvdDigiMatch", pFakeMatch, kFALSE);
305  ioman->RegisterAny("StsDigiMatch", pFakeMatch, kFALSE);
306  ioman->RegisterAny("MuchBeamTimeDigiMatch", pFakeMatch, kFALSE);
307  ioman->RegisterAny("TrdDigiMatch", pFakeMatch, kFALSE);
308  ioman->RegisterAny("TofDigiMatch", pFakeMatch, kFALSE);
309  ioman->RegisterAny("RichDigiMatch", pFakeMatch, kFALSE);
310  ioman->RegisterAny("PsdDigiMatch", pFakeMatch, kFALSE);
311 
314  fEvents = new TClonesArray("CbmEvent", 500);
315 
317  if (kFALSE == fpAlgo->InitAlgo()) {
318  throw InitTaskError("Failed to initilize the algorithm class.");
319  } // if( kFALSE == fpAlgo->InitAlgo() )
320 
322  if (kTRUE == fbFillHistos) {
324  std::vector<std::pair<TNamed*, std::string>> vHistos =
325  fpAlgo->GetHistoVector();
327  std::vector<std::pair<TCanvas*, std::string>> vCanvases =
328  fpAlgo->GetCanvasVector();
329 
334  for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
335  // LOG(info) << "Registering " << vHistos[ uHisto ].first->GetName()
336  // << " in " << vHistos[ uHisto ].second.data()
337  // ;
338  fArrayHisto.Add(vHistos[uHisto].first);
339  std::pair<std::string, std::string> psHistoConfig(
340  vHistos[uHisto].first->GetName(), vHistos[uHisto].second);
341  fvpsHistosFolder.push_back(psHistoConfig);
342 
344  FairMQMessagePtr messageHist(NewMessage());
345  Serialize<BoostSerializer<std::pair<std::string, std::string>>>(
346  *messageHist, psHistoConfig);
347 
349  if (Send(messageHist, fsChannelNameHistosConfig) < 0) {
350  throw InitTaskError("Problem sending histo config");
351  } // if( Send( messageHist, fsChannelNameHistosConfig ) < 0 )
352 
353  LOG(info) << "Config of hist " << psHistoConfig.first.data()
354  << " in folder " << psHistoConfig.second.data();
355  } // for( UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto )
356 
360  for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
361  // LOG(info) << "Registering " << vCanvases[ uCanv ].first->GetName()
362  // << " in " << vCanvases[ uCanv ].second.data();
363  std::string sCanvName = (vCanvases[uCanv].first)->GetName();
364  std::string sCanvConf =
365  GenerateCanvasConfigString(vCanvases[uCanv].first);
366 
367  std::pair<std::string, std::string> psCanvConfig(sCanvName, sCanvConf);
368 
369  fvpsCanvasConfig.push_back(psCanvConfig);
370 
372  FairMQMessagePtr messageCan(NewMessage());
373  Serialize<BoostSerializer<std::pair<std::string, std::string>>>(
374  *messageCan, psCanvConfig);
375 
377  if (Send(messageCan, fsChannelNameCanvasConfig) < 0) {
378  throw InitTaskError("Problem sending canvas config");
379  } // if( Send( messageCan, fsChannelNameCanvasConfig ) < 0 )
380 
381  LOG(info) << "Config string of Canvas " << psCanvConfig.first.data()
382  << " is " << psCanvConfig.second.data();
383  } // for( UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv )
384  } // if( kTRUE == fbFillHistos )
385 
386 } catch (InitTaskError& e) {
387  LOG(error) << e.what();
388  // Wrapper defined in CbmMQDefs.h to support different FairMQ versions
390 }
391 
393  std::string channelName) {
394  for (auto const& entry : fsAllowedChannels) {
395  std::size_t pos1 = channelName.find(entry);
396  if (pos1 != std::string::npos) {
397  const vector<std::string>::const_iterator pos =
398  std::find(fsAllowedChannels.begin(), fsAllowedChannels.end(), entry);
399  const vector<std::string>::size_type idx =
400  pos - fsAllowedChannels.begin();
401  LOG(info) << "Found " << entry << " in " << channelName;
402  LOG(info) << "Channel name " << channelName
403  << " found in list of allowed channel names at position "
404  << idx;
405  return true;
406  } // if (pos1!=std::string::npos)
407  } // for(auto const &entry : fsAllowedChannels)
408  LOG(info) << "Channel name " << channelName
409  << " not found in list of allowed channel names.";
410  LOG(error) << "Stop device.";
411  return false;
412 }
413 /*
414 Bool_t CbmDeviceMcbmEventBuilderWin::InitContainers()
415 {
416  LOG(info) << "Init parameter containers for CbmDeviceMcbmEventBuilderWin.";
417 
418  if( kFALSE == InitParameters( fpAlgo ->GetParList() ) )
419  return kFALSE;
420 
422  fpAlgo ->SetIgnoreOverlapMs( fbIgnoreOverlapMs );
423 
424  Bool_t initOK = fpAlgo->InitContainers();
425 
426 // Bool_t initOK = fMonitorAlgo->ReInitContainers();
427 
428  return initOK;
429 }
430 
431 Bool_t CbmDeviceMcbmEventBuilderWin::InitParameters( TList* fParCList )
432 {
433  for( int iparC = 0; iparC < fParCList->GetEntries(); iparC++ )
434  {
435  FairParGenericSet* tempObj = (FairParGenericSet*)( fParCList->At( iparC ) );
436  fParCList->Remove( tempObj );
437  std::string paramName{ tempObj->GetName() };
438  // NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
439  // Should only be used for small data because of the cost of an additional copy
440 
441  // Her must come the proper Runid
442  std::string message = paramName + ",111";
443  LOG(info) << "Requesting parameter container " << paramName << ", sending message: " << message;
444 
445  FairMQMessagePtr req( NewSimpleMessage(message) );
446  FairMQMessagePtr rep( NewMessage() );
447 
448  FairParGenericSet* newObj = nullptr;
449 
450  if( Send(req, "parameters") > 0 )
451  {
452  if( Receive( rep, "parameters" ) >= 0)
453  {
454  if( 0 != rep->GetSize() )
455  {
456  CbmMQTMessage tmsg( rep->GetData(), rep->GetSize() );
457  newObj = static_cast< FairParGenericSet* >( tmsg.ReadObject( tmsg.GetClass() ) );
458  LOG( info ) << "Received unpack parameter from the server:";
459  newObj->print();
460  } // if( 0 != rep->GetSize() )
461  else
462  {
463  LOG( error ) << "Received empty reply. Parameter not available";
464  return kFALSE;
465  } // else of if( 0 != rep->GetSize() )
466  } // if( Receive( rep, "parameters" ) >= 0)
467  } // if( Send(req, "parameters") > 0 )
468  fParCList->AddAt( newObj, iparC );
469  delete tempObj;
470  } // for( int iparC = 0; iparC < fParCList->GetEntries(); iparC++ )
471 
472  return kTRUE;
473 }
474 */
475 // handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
477  int /*index*/) {
478  fulNumMessages++;
479  LOG(debug) << "Received message number " << fulNumMessages << " with "
480  << parts.Size() << " parts"
481  << ", size0: " << parts.At(0)->GetSize();
482 
483  if (0 == fulNumMessages % 10000)
484  LOG(info) << "Received " << fulNumMessages << " messages";
485 
487  uint32_t uPartIdx = 0;
490  /*
491  std::string msgStrTsMeta( static_cast< char * >( parts.At( uPartIdx )->GetData() ),
492  ( parts.At( uPartIdx ) )->GetSize() );
493  std::istringstream issTsMeta(msgStrTsMeta);
494  boost::archive::binary_iarchive inputArchiveTsMeta(issTsMeta);
495  inputArchiveTsMeta >> (*fTsMetaData);
496  ++uPartIdx;
497 */
498  Deserialize<RootSerializer>(*parts.At(uPartIdx), fTsMetaData);
500  new (
501  (*fTimeSliceMetaDataArray)
502  [fTimeSliceMetaDataArray->GetEntriesFast()
503  // ] ) TimesliceMetaData( *fTsMetaData ) ;
504  ]) TimesliceMetaData(std::move(*fTsMetaData));
505  ++uPartIdx;
506 
508  std::string msgStrT0(static_cast<char*>(parts.At(uPartIdx)->GetData()),
509  (parts.At(uPartIdx))->GetSize());
510  std::istringstream issT0(msgStrT0);
511  boost::archive::binary_iarchive inputArchiveT0(issT0);
512  inputArchiveT0 >> *fvDigiT0;
513  ++uPartIdx;
514 
516  std::string msgStrSts(static_cast<char*>(parts.At(uPartIdx)->GetData()),
517  (parts.At(uPartIdx))->GetSize());
518  std::istringstream issSts(msgStrSts);
519  boost::archive::binary_iarchive inputArchiveSts(issSts);
520  inputArchiveSts >> *fvDigiSts;
521  ++uPartIdx;
522 
524  std::string msgStrMuch(static_cast<char*>(parts.At(uPartIdx)->GetData()),
525  (parts.At(uPartIdx))->GetSize());
526  std::istringstream issMuch(msgStrMuch);
527  boost::archive::binary_iarchive inputArchiveMuch(issMuch);
528  inputArchiveMuch >> *fvDigiMuch;
529  ++uPartIdx;
530 
532  std::string msgStrTrd(static_cast<char*>(parts.At(uPartIdx)->GetData()),
533  (parts.At(uPartIdx))->GetSize());
534  std::istringstream issTrd(msgStrTrd);
535  boost::archive::binary_iarchive inputArchiveTrd(issTrd);
536  inputArchiveTrd >> *fvDigiTrd;
537  ++uPartIdx;
538 
540  std::string msgStrTof(static_cast<char*>(parts.At(uPartIdx)->GetData()),
541  (parts.At(uPartIdx))->GetSize());
542  std::istringstream issTof(msgStrTof);
543  boost::archive::binary_iarchive inputArchiveTof(issTof);
544  inputArchiveTof >> *fvDigiTof;
545  ++uPartIdx;
546 
548  std::string msgStrRich(static_cast<char*>(parts.At(uPartIdx)->GetData()),
549  (parts.At(uPartIdx))->GetSize());
550  std::istringstream issRich(msgStrRich);
551  boost::archive::binary_iarchive inputArchiveRich(issRich);
552  inputArchiveRich >> *fvDigiRich;
553  ++uPartIdx;
554 
556  std::string msgStrPsd(static_cast<char*>(parts.At(uPartIdx)->GetData()),
557  (parts.At(uPartIdx))->GetSize());
558  std::istringstream issPsd(msgStrPsd);
559  boost::archive::binary_iarchive inputArchivePsd(issPsd);
560  inputArchivePsd >> *fvDigiPsd;
561  ++uPartIdx;
562 
564  fpAlgo->ProcessTs();
565 
567  if (!SendEvents(parts)) return false;
568 
570  fTimeSliceMetaDataArray->Clear();
571  // delete fTsMetaData;
572 
574  fvDigiT0->clear();
575  fvDigiSts->clear();
576  fvDigiMuch->clear();
577  fvDigiTrd->clear();
578  fvDigiTof->clear();
579  fvDigiRich->clear();
580  fvDigiPsd->clear();
581 
583  fpAlgo->ClearEventVector();
584  fEvents->Clear("C");
585  // fEvents->Clear();
586 
588  if (kTRUE == fbFillHistos) {
592  std::chrono::system_clock::time_point currentTime =
593  std::chrono::system_clock::now();
594  std::chrono::duration<double_t> elapsedSeconds =
595  currentTime - fLastPublishTime;
596  if ((fdMaxPublishTime < elapsedSeconds.count())
597  || (0 == fulNumMessages % fuPublishFreqTs
598  && fdMinPublishTime < elapsedSeconds.count())) {
599  SendHistograms();
600  fLastPublishTime = std::chrono::system_clock::now();
601  } // if( ( fdMaxPublishTime < elapsedSeconds.count() ) || ( 0 == fulNumMessages % fuPublishFreqTs && fdMinPublishTime < elapsedSeconds.count() ) )
602  } // if( kTRUE == fbFillHistos )
603 
604  return true;
605 }
606 
607 bool CbmDeviceMcbmEventBuilderWin::SendEvents(FairMQParts& partsIn) {
609  fEvents->Delete();
610  // fEvents->Clear();
611 
613  std::vector<CbmEvent*> vEvents = fpAlgo->GetEventVector();
614 
616  for (CbmEvent* event : vEvents) {
617  LOG(debug) << "Vector: " << event->ToString();
618  new ((*fEvents)[fEvents->GetEntriesFast()]) CbmEvent(std::move(*event));
619  // new ( (*fEvents)[fEvents->GetEntriesFast()] ) CbmEvent( *event );
620  LOG(debug) << "TClonesArray: "
621  << static_cast<CbmEvent*>(
622  fEvents->At(fEvents->GetEntriesFast() - 1))
623  ->ToString();
624  } // for( CbmEvent* event: vEvents )
625 
627  FairMQMessagePtr message(NewMessage());
628  Serialize<RootSerializer>(*message, fEvents);
629 
632  FairMQParts partsOut(std::move(partsIn));
633  partsOut.AddPart(std::move(message));
634 
635  // /// Get vector from algo
636  // fEventVector = fpAlgo->GetEventVector();
637  //
638  // /// Prepare serialized versions of the events vector
639  // std::stringstream ossEvents;
640  // boost::archive::binary_oarchive oaEvents(ossEvents);
641  // oaEvents << fpAlgo->GetEventVector();
642  // std::string* strMsgEvents = new std::string(ossEvents.str());
643  //
644  // /// Create message
645  // FairMQMessagePtr msg( NewMessage( const_cast< char * >( strMsgEvents->c_str() ), // data
646  // strMsgEvents->length(), // size
647  // []( void * /*data*/, void* object ){ delete static_cast< std::string * >( object ); },
648  // strMsgEvents ) ); // object that manages the data
649 
651  // if( Send( message, fsChannelNameDataOutput ) < 0 )
652  if (Send(partsOut, fsChannelNameDataOutput) < 0) {
653  LOG(error) << "Problem sending data to " << fsChannelNameDataOutput;
654  return false;
655  }
656 
657  return true;
658 }
659 
662  FairMQMessagePtr message(NewMessage());
663  Serialize<RootSerializer>(*message, &fArrayHisto);
664 
666  if (Send(message, fsChannelNameHistosInput) < 0) {
667  LOG(error) << "Problem sending data";
668  return false;
669  } // if( Send( message, fsChannelNameHistosInput ) < 0 )
670 
672  fpAlgo->ResetHistograms(kFALSE);
673 
674  return true;
675 }
676 
679  fTimeSliceMetaDataArray->Clear();
680  delete fTsMetaData;
681 
683  fvDigiT0->clear();
684  fvDigiSts->clear();
685  fvDigiMuch->clear();
686  fvDigiTrd->clear();
687  fvDigiTof->clear();
688  fvDigiRich->clear();
689  fvDigiPsd->clear();
690 
692  fEvents->Delete();
693 
694  delete fpRun;
695 
696  delete fTimeSliceMetaDataArray;
697  delete fEvents;
698 
699  delete fpAlgo;
700 }
701 
CbmDeviceMcbmEventBuilderWin::CbmDeviceMcbmEventBuilderWin
CbmDeviceMcbmEventBuilderWin()
Definition: CbmDeviceMcbmEventBuilderWin.cxx:51
CbmDeviceMcbmEventBuilderWin::InitTask
virtual void InitTask()
Definition: CbmDeviceMcbmEventBuilderWin.cxx:55
kEventBuilderDetRich
static const EventBuilderDetector kEventBuilderDetRich
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:97
CbmMvdDigi.h
InitTaskError
CBM headers.
Definition: CbmDeviceEventBuilderEtofStar2019.cxx:36
kEventBuilderDetT0
static const EventBuilderDetector kEventBuilderDetT0
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:101
kEventBuilderDetMuch
static const EventBuilderDetector kEventBuilderDetMuch
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:91
ECbmModuleId::kT0
@ kT0
ToF start Detector.
CbmFlesCanvasTools.h
kEventBuilderDetTof
static const EventBuilderDetector kEventBuilderDetTof
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:95
TimesliceMetaData
Definition: TimesliceMetaData.h:11
ECbmModuleId
ECbmModuleId
Definition: CbmDefs.h:33
ECbmModuleId::kTof
@ kTof
Time-of-flight Detector.
CbmMatch.h
kEventBuilderDetTrd
static const EventBuilderDetector kEventBuilderDetTrd
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:93
cbm::mq::Transition::ErrorFound
@ ErrorFound
CbmEvent.h
CbmDeviceMcbmEventBuilderWin::SendHistograms
bool SendHistograms()
Definition: CbmDeviceMcbmEventBuilderWin.cxx:660
CbmDeviceMcbmEventBuilderWin::~CbmDeviceMcbmEventBuilderWin
virtual ~CbmDeviceMcbmEventBuilderWin()
Definition: CbmDeviceMcbmEventBuilderWin.cxx:677
CbmDeviceMcbmEventBuilderWin::SendEvents
bool SendEvents(FairMQParts &partsIn)
Definition: CbmDeviceMcbmEventBuilderWin.cxx:607
ECbmModuleId::kRich
@ kRich
Ring-Imaging Cherenkov Detector.
kEventBuilderDetUndef
static const EventBuilderDetector kEventBuilderDetUndef
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:103
EventBuilderDetector
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:37
first
bool first
Definition: LKFMinuit.cxx:143
kEventBuilderDetPsd
static const EventBuilderDetector kEventBuilderDetPsd
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:99
kEventBuilderDetSts
static const EventBuilderDetector kEventBuilderDetSts
Pre-defined detector types.
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:89
EOverlapMode::AllowOverlap
@ AllowOverlap
CbmDeviceMcbmEventBuilderWin::Finish
void Finish()
Definition: CbmDeviceMcbmEventBuilderWin.cxx:702
ECbmModuleId::kTrd
@ kTrd
Transition Radiation Detector.
GenerateCanvasConfigString
std::string GenerateCanvasConfigString(TCanvas *pCanv)
Definition: CbmFlesCanvasTools.cxx:296
CbmDeviceMcbmEventBuilderWin::IsChannelNameAllowed
bool IsChannelNameAllowed(std::string channelName)
Definition: CbmDeviceMcbmEventBuilderWin.cxx:392
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
pos
TVector3 pos
Definition: CbmMvdSensorDigiToHitTask.cxx:60
ECbmModuleId::kMuch
@ kMuch
Muon detection system.
ECbmModuleId::kPsd
@ kPsd
Projectile spectator detector.
CbmDeviceMcbmEventBuilderWin::HandleData
bool HandleData(FairMQParts &, int)
Definition: CbmDeviceMcbmEventBuilderWin.cxx:476
EOverlapMode
EOverlapMode
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:35
ECbmModuleId::kNotExist
@ kNotExist
If not found.
TimesliceMetaData.h
CbmMQDefs.h
cbm::mq::ChangeState
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)
Definition: CbmMQDefs.h:19
ECbmModuleId::kSts
@ kSts
Silicon Tracking System.
CbmDeviceMcbmEventBuilderWin.h
EOverlapMode::MergeOverlap
@ MergeOverlap
Cbm::ToString
std::string ToString(const T &value)
Definition: CbmUtils.h:16
EOverlapMode::NoOverlap
@ NoOverlap
CbmMcbm2019TimeWinEventBuilderAlgo
Definition: CbmMcbm2019TimeWinEventBuilderAlgo.h:106