24#include "FairMQLogger.h"
25#include "FairMQProgOptions.h"
26#include "FairParGenericSet.h"
27#include "FairRunOnline.h"
29#include "BoostSerializer.h"
31#include "RootSerializer.h"
40#include <boost/archive/binary_iarchive.hpp>
41#include <boost/serialization/utility.hpp>
49 using std::runtime_error::runtime_error;
59 LOG(info) <<
"Init options for CbmDeviceBuildRawEvents.";
63 fsEvtOverMode = fConfig->GetValue<std::string>(
"EvtOverMode");
64 fsRefDet = fConfig->GetValue<std::string>(
"RefDet");
65 fvsAddDet = fConfig->GetValue<std::vector<std::string>>(
"AddDet");
66 fvsDelDet = fConfig->GetValue<std::vector<std::string>>(
"DelDet");
67 fvsSetTrigWin = fConfig->GetValue<std::vector<std::string>>(
"SetTrigWin");
68 fvsSetTrigMinNb = fConfig->GetValue<std::vector<std::string>>(
"SetTrigMinNb");
90 int noChannel = fChannels.size();
91 LOG(info) <<
"Number of defined channels: " << noChannel;
92 for (
auto const& entry : fChannels) {
93 LOG(info) <<
"Channel name: " << entry.first;
126 LOG(info) <<
"CbmDeviceBuildRawEvents::InitTask => Trying to change "
127 "reference to unsupported detector, ignored! "
132 for (std::vector<std::string>::iterator itStrAdd =
fvsAddDet.begin();
147 LOG(info) <<
"CbmDeviceBuildRawEvents::InitTask => Trying to add "
148 "unsupported detector, ignored! "
155 for (std::vector<std::string>::iterator itStrRem =
fvsDelDet.begin();
170 LOG(info) <<
"CbmDeviceBuildRawEvents::InitTask => Trying to remove "
171 "unsupported detector, ignored! "
177 for (std::vector<std::string>::iterator itStrTrigWin =
fvsSetTrigWin.begin();
180 size_t charPosDel = (*itStrTrigWin).find(
',');
181 if (std::string::npos == charPosDel) {
183 <<
"CbmDeviceBuildRawEvents::InitTask => "
184 <<
"Trying to set trigger window with invalid option pattern, ignored! "
185 <<
" (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found "
186 << (*itStrTrigWin) <<
" )";
191 std::string sSelDet = (*itStrTrigWin).substr(0, charPosDel);
202 <<
"CbmDeviceBuildRawEvents::InitTask => "
203 <<
"Trying to set trigger window for unsupported detector, ignored! "
210 std::string sNext = (*itStrTrigWin).substr(charPosDel);
211 charPosDel = sNext.find(
',');
212 if (std::string::npos == charPosDel) {
214 <<
"CbmDeviceBuildRawEvents::InitTask => "
215 <<
"Trying to set trigger window with invalid option pattern, ignored! "
216 <<
" (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found "
217 << (*itStrTrigWin) <<
" )";
220 Double_t dWinBeg = std::stod(sNext.substr(0, charPosDel));
224 Double_t dWinEnd = std::stod(sNext.substr(charPosDel));
229 for (std::vector<std::string>::iterator itStrMinNb =
fvsSetTrigMinNb.begin();
232 size_t charPosDel = (*itStrMinNb).find(
',');
233 if (std::string::npos == charPosDel) {
235 <<
"CbmDeviceBuildRawEvents::InitTask => "
236 <<
"Trying to set trigger min Nb with invalid option pattern, ignored! "
237 <<
" (Should be ECbmModuleId,uMinNb but instead found " << (*itStrMinNb)
243 std::string sSelDet = (*itStrMinNb).substr(0, charPosDel);
254 <<
"CbmDeviceBuildRawEvents::InitTask => "
255 <<
"Trying to set trigger min Nb for unsupported detector, ignored! "
262 UInt_t uMinNb = std::stoul((*itStrMinNb).substr(charPosDel));
272 fvDigiSts =
new std::vector<CbmStsDigi>();
273 fvDigiMuch =
new std::vector<CbmMuchBeamTimeDigi>();
274 fvDigiTrd =
new std::vector<CbmTrdDigi>();
275 fvDigiTof =
new std::vector<CbmTofDigi>();
277 fvDigiPsd =
new std::vector<CbmPsdDigi>();
296 fEvents =
new TClonesArray(
"CbmEvent", 500);
312 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
317 std::pair<std::string, std::string> psHistoConfig(vHistos[uHisto].
first->GetName(), vHistos[uHisto].second);
321 FairMQMessagePtr messageHist(NewMessage());
323 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageHist, psHistoConfig);
327 LOG(info) <<
"Config of hist " << psHistoConfig.first.data() <<
" in folder " << psHistoConfig.second.data();
333 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
336 std::string sCanvName = (vCanvases[uCanv].first)->GetName();
339 std::pair<std::string, std::string> psCanvConfig(sCanvName, sCanvConf);
344 FairMQMessagePtr messageCan(NewMessage());
346 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageCan, psCanvConfig);
351 LOG(info) <<
"Config string of Canvas " << psCanvConfig.first.data() <<
" is " << psCanvConfig.second.data();
356 LOG(error) << e.what();
364 std::size_t pos1 = channelName.find(entry);
365 if (pos1 != std::string::npos) {
366 const vector<std::string>::const_iterator
pos =
369 LOG(info) <<
"Found " << entry <<
" in " << channelName;
370 LOG(info) <<
"Channel name " << channelName <<
" found in list of allowed channel names at position " << idx;
374 LOG(info) <<
"Channel name " << channelName <<
" not found in list of allowed channel names.";
375 LOG(error) <<
"Stop device.";
383 LOG(debug) <<
"Received message number " <<
fulNumMessages <<
" with " << parts.Size() <<
" parts"
384 <<
", size0: " << parts.At(0)->GetSize();
389 uint32_t uPartIdx = 0;
393 RootSerializer().Deserialize(*parts.At(uPartIdx),
fTsMetaData);
399 std::string msgStrBmon(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
400 std::istringstream issBmon(msgStrBmon);
401 boost::archive::binary_iarchive inputArchiveBmon(issBmon);
406 std::string msgStrSts(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
407 std::istringstream issSts(msgStrSts);
408 boost::archive::binary_iarchive inputArchiveSts(issSts);
413 std::string msgStrMuch(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
414 std::istringstream issMuch(msgStrMuch);
415 boost::archive::binary_iarchive inputArchiveMuch(issMuch);
420 std::string msgStrTrd(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
421 std::istringstream issTrd(msgStrTrd);
422 boost::archive::binary_iarchive inputArchiveTrd(issTrd);
427 std::string msgStrTof(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
428 std::istringstream issTof(msgStrTof);
429 boost::archive::binary_iarchive inputArchiveTof(issTof);
434 std::string msgStrRich(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
435 std::istringstream issRich(msgStrRich);
436 boost::archive::binary_iarchive inputArchiveRich(issRich);
441 std::string msgStrPsd(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
442 std::istringstream issPsd(msgStrPsd);
443 boost::archive::binary_iarchive inputArchivePsd(issPsd);
474 std::chrono::system_clock::time_point currentTime = std::chrono::system_clock::now();
475 std::chrono::duration<double_t> elapsedSeconds = currentTime -
fLastPublishTime;
496 LOG(debug) <<
"Vector: " <<
event->ToString();
497 new ((*fEvents)[
fEvents->GetEntriesFast()])
CbmEvent(std::move(*event));
502 FairMQMessagePtr message(NewMessage());
504 RootSerializer().Serialize(*message,
fEvents);
507 FairMQParts partsOut(std::move(partsIn));
508 partsOut.AddPart(std::move(message));
521 FairMQMessagePtr message(NewMessage());
523 RootSerializer().Serialize(*message, &
fArrayHisto);
527 LOG(error) <<
"Problem sending data";
static const RawEventBuilderDetector kRawEventBuilderDetSts
Pre-defined detector types.
static const RawEventBuilderDetector kRawEventBuilderDetBmon
static const RawEventBuilderDetector kRawEventBuilderDetTrd
static const RawEventBuilderDetector kRawEventBuilderDetPsd
static const RawEventBuilderDetector kRawEventBuilderDetRich
static const RawEventBuilderDetector kRawEventBuilderDetTof
static const RawEventBuilderDetector kRawEventBuilderDetMuch
static const RawEventBuilderDetector kRawEventBuilderDetUndef
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kMuch
Muon detection system.
@ kRich
Ring-Imaging Cherenkov Detector.
void SetFillHistos(Bool_t var)
void SetEventOverlapMode(EOverlapModeRaw mode)
Control flags.
void SetTimeSliceMetaDataArray(TClonesArray *TimeSliceMetaDataArray)
std::vector< std::pair< TNamed *, std::string > > GetHistoVector()
void SetIgnoreTsOverlap(Bool_t bFlagIn=kTRUE)
std::vector< std::pair< TCanvas *, std::string > > GetCanvasVector()
void RemoveDetector(RawEventBuilderDetector selDet)
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< CbmEvent * > & GetEventVector()
Data output access.
void ResetHistograms(Bool_t bResetTime=kTRUE)
void SetTriggerMinNumber(ECbmModuleId selDet, UInt_t uVal)
void SetDigis(std::vector< CbmBmonDigi > *BmonDigis)
Set digi containers.
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 SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
std::string fsEvtOverMode
Switch ON/OFF filling of histograms.
std::string fsChannelNameHistosInput
std::string fsChannelNameDataOutput
std::vector< CbmTofDigi > * fvDigiTof
double_t fdMinPublishTime
TClonesArray * fEvents
Data emission.
CbmDeviceBuildRawEvents()
bool HandleData(FairMQParts &, int)
std::vector< CbmMuchBeamTimeDigi > * fvDigiMuch
std::vector< std::string > fvsSetTrigMinNb
std::vector< CbmStsDigi > * fvDigiSts
std::string fsChannelNameDataInput
message queues
std::vector< std::string > fvsAddDet
std::vector< std::string > fsAllowedChannels
List of MQ channels names.
std::vector< std::string > fvsDelDet
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
Bool_t fbFillHistos
Ignore data in Overlap part of the TS.
uint32_t fuPublishFreqTs
Histograms management.
bool SendEvents(FairMQParts &partsIn)
TClonesArray * fTimeSliceMetaDataArray
Total size of all MS in a TS, [nanoseconds].
virtual ~CbmDeviceBuildRawEvents()
std::string fsChannelNameCanvasConfig
std::vector< CbmPsdDigi > * fvDigiPsd
std::vector< std::pair< std::string, std::string > > fvpsHistosFolder
Vector of string pairs with ( HistoName, FolderPath ) to send to the histogram server.
TimesliceMetaData * fTsMetaData
std::vector< CbmBmonDigi > * fvDigiBmon
Digis storage.
std::string fsChannelNameHistosConfig
std::vector< CbmRichDigi > * fvDigiRich
bool IsChannelNameAllowed(std::string channelName)
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
Bool_t fbIgnoreTsOverlap
Constants.
std::chrono::system_clock::time_point fLastPublishTime
double_t fdMaxPublishTime
FairRunOnline * fpRun
output container of CbmEvents
std::vector< std::string > fvsSetTrigWin
std::vector< CbmTrdDigi > * fvDigiTrd
CbmAlgoBuildRawEvents * fpAlgo
Processing algos.
uint64_t fulNumMessages
Statistics & first TS rejection.
Class characterising one event by a collection of links (indices) to data objects,...
std::string ToString() const
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)