25#include "FairMQLogger.h"
26#include "FairMQProgOptions.h"
27#include "FairParGenericSet.h"
28#include "FairRunOnline.h"
30#include "BoostSerializer.h"
32#include "RootSerializer.h"
41#include <boost/archive/binary_iarchive.hpp>
42#include <boost/serialization/utility.hpp>
50 using std::runtime_error::runtime_error;
62 LOG(info) <<
"Init options for CbmDeviceMcbmEventBuilderWin.";
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");
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;
131 LOG(info) <<
"CbmDeviceMcbmEventBuilderWin::InitTask => Trying to change "
132 "reference to unsupported detector, ignored! "
137 for (std::vector<std::string>::iterator itStrAdd =
fvsAddDet.begin();
152 LOG(info) <<
"CbmDeviceMcbmEventBuilderWin::InitTask => Trying to add "
153 "unsupported detector, ignored! "
160 for (std::vector<std::string>::iterator itStrRem =
fvsDelDet.begin();
175 LOG(info) <<
"CbmDeviceMcbmEventBuilderWin::InitTask => Trying to remove "
176 "unsupported detector, ignored! "
182 for (std::vector<std::string>::iterator itStrTrigWin =
fvsSetTrigWin.begin();
185 size_t charPosDel = (*itStrTrigWin).find(
',');
186 if (std::string::npos == charPosDel) {
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) <<
" )";
196 std::string sSelDet = (*itStrTrigWin).substr(0, charPosDel);
207 <<
"CbmDeviceMcbmEventBuilderWin::InitTask => "
208 <<
"Trying to set trigger window for unsupported detector, ignored! "
215 std::string sNext = (*itStrTrigWin).substr(charPosDel);
216 charPosDel = sNext.find(
',');
217 if (std::string::npos == charPosDel) {
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) <<
" )";
225 Double_t dWinBeg = std::stod(sNext.substr(0, charPosDel));
229 Double_t dWinEnd = std::stod(sNext.substr(charPosDel));
234 for (std::vector<std::string>::iterator itStrMinNb =
fvsSetTrigMinNb.begin();
237 size_t charPosDel = (*itStrMinNb).find(
',');
238 if (std::string::npos == charPosDel) {
240 <<
"CbmDeviceMcbmEventBuilderWin::InitTask => "
241 <<
"Trying to set trigger min Nb with invalid option pattern, ignored! "
242 <<
" (Should be ECbmModuleId,uMinNb but instead found " << (*itStrMinNb)
248 std::string sSelDet = (*itStrMinNb).substr(0, charPosDel);
259 <<
"CbmDeviceMcbmEventBuilderWin::InitTask => "
260 <<
"Trying to set trigger min Nb for unsupported detector, ignored! "
267 UInt_t uMinNb = std::stoul((*itStrMinNb).substr(charPosDel));
277 fvDigiSts =
new std::vector<CbmStsDigi>();
278 fvDigiMuch =
new std::vector<CbmMuchBeamTimeDigi>();
279 fvDigiTrd =
new std::vector<CbmTrdDigi>();
280 fvDigiTof =
new std::vector<CbmTofDigi>();
282 fvDigiPsd =
new std::vector<CbmPsdDigi>();
285 fpRun =
new FairRunOnline(0);
286 FairRootManager* ioman =
nullptr;
287 ioman = FairRootManager::Instance();
288 if (NULL == ioman) {
throw InitTaskError(
"No FairRootManager instance"); }
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);
315 fEvents =
new TClonesArray(
"CbmEvent", 500);
319 throw InitTaskError(
"Failed to initilize the algorithm class.");
333 for (UInt_t uHisto = 0; uHisto < vHistos.size(); ++uHisto) {
338 std::pair<std::string, std::string> psHistoConfig(vHistos[uHisto].
first->GetName(), vHistos[uHisto].second);
342 FairMQMessagePtr messageHist(NewMessage());
344 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageHist, psHistoConfig);
351 LOG(info) <<
"Config of hist " << psHistoConfig.first.data() <<
" in folder " << psHistoConfig.second.data();
357 for (UInt_t uCanv = 0; uCanv < vCanvases.size(); ++uCanv) {
360 std::string sCanvName = (vCanvases[uCanv].first)->GetName();
363 std::pair<std::string, std::string> psCanvConfig(sCanvName, sCanvConf);
368 FairMQMessagePtr messageCan(NewMessage());
370 BoostSerializer<std::pair<std::string, std::string>>().Serialize(*messageCan, psCanvConfig);
377 LOG(info) <<
"Config string of Canvas " << psCanvConfig.first.data() <<
" is " << psCanvConfig.second.data();
382 LOG(error) << e.what();
390 std::size_t pos1 = channelName.find(entry);
391 if (pos1 != std::string::npos) {
392 const vector<std::string>::const_iterator
pos =
395 LOG(info) <<
"Found " << entry <<
" in " << channelName;
396 LOG(info) <<
"Channel name " << channelName <<
" found in list of allowed channel names at position " << idx;
400 LOG(info) <<
"Channel name " << channelName <<
" not found in list of allowed channel names.";
401 LOG(error) <<
"Stop device.";
413 fpAlgo ->SetIgnoreOverlapMs( fbIgnoreOverlapMs );
415 Bool_t initOK = fpAlgo->InitContainers();
417// Bool_t initOK = fMonitorAlgo->ReInitContainers();
422Bool_t CbmDeviceMcbmEventBuilderWin::InitParameters( TList* fParCList )
424 for( int iparC = 0; iparC < fParCList->GetEntries(); iparC++ )
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
432 // Her must come the proper Runid
433 std::string message = paramName + ",111";
434 LOG(info) << "Requesting parameter container " << paramName << ", sending message: " << message;
436 FairMQMessagePtr req( NewSimpleMessage(message) );
437 FairMQMessagePtr rep( NewMessage() );
439 FairParGenericSet* newObj = nullptr;
441 if( Send(req, "parameters") > 0 )
443 if( Receive( rep, "parameters" ) >= 0)
445 if( 0 != rep->GetSize() )
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:";
451 } // if( 0 != rep->GetSize() )
454 LOG( error ) << "Received empty reply. Parameter not available";
456 } // else of if( 0 != rep->GetSize() )
457 } // if( Receive( rep, "parameters" ) >= 0)
458 } // if( Send(req, "parameters") > 0 )
459 fParCList->AddAt( newObj, iparC );
461 } // for( int iparC = 0; iparC < fParCList->GetEntries(); iparC++ )
470 LOG(debug) <<
"Received message number " <<
fulNumMessages <<
" with " << parts.Size() <<
" parts"
471 <<
", size0: " << parts.At(0)->GetSize();
476 uint32_t uPartIdx = 0;
488 RootSerializer().Deserialize(*parts.At(uPartIdx),
fTsMetaData);
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);
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);
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);
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);
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);
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);
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);
573 std::chrono::system_clock::time_point currentTime = std::chrono::system_clock::now();
574 std::chrono::duration<double_t> elapsedSeconds = currentTime -
fLastPublishTime;
596 LOG(debug) <<
"Vector: " <<
event->ToString();
597 new ((*fEvents)[
fEvents->GetEntriesFast()])
CbmEvent(std::move(*event));
603 FairMQMessagePtr message(NewMessage());
605 RootSerializer().Serialize(*message,
fEvents);
609 FairMQParts partsOut(std::move(partsIn));
610 partsOut.AddPart(std::move(message));
640 FairMQMessagePtr message(NewMessage());
642 RootSerializer().Serialize(*message, &
fArrayHisto);
646 LOG(error) <<
"Problem sending data";
@ 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.
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
CbmMcbm2019TimeWinEventBuilderAlgo * fpAlgo
Processing algos.
std::vector< CbmStsDigi > * fvDigiSts
std::vector< CbmPsdDigi > * fvDigiPsd
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.
std::string fsChannelNameHistosConfig
TObjArray fArrayHisto
Array of histograms to send to the histogram server.
std::chrono::system_clock::time_point fLastPublishTime
std::vector< std::string > fvsSetTrigWin
Bool_t fbIgnoreTsOverlap
Constants.
std::vector< std::string > fvsSetTrigMinNb
virtual ~CbmDeviceMcbmEventBuilderWin()
TClonesArray * fTimeSliceMetaDataArray
Total size of all MS in a TS, [nanoseconds].
std::vector< CbmMuchBeamTimeDigi > * fvDigiMuch
std::vector< CbmTrdDigi > * fvDigiTrd
TClonesArray * fEvents
Data emission.
uint64_t fulNumMessages
Parameters management.
std::vector< CbmTofDigi > * fvDigiTof
std::string fsChannelNameHistosInput
std::vector< std::string > fsAllowedChannels
List of MQ channels names.
std::string fsChannelNameDataInput
message queues
std::vector< std::string > fvsAddDet
std::vector< CbmTofDigi > * fvDigiBmon
Digis storage.
Bool_t fbFillHistos
Ignore data in Overlap part of the TS.
std::vector< std::string > fvsDelDet
bool HandleData(FairMQParts &, int)
uint32_t fuPublishFreqTs
Histograms management.
TimesliceMetaData * fTsMetaData
double_t fdMinPublishTime
CbmDeviceMcbmEventBuilderWin()
bool SendEvents(FairMQParts &partsIn)
std::vector< CbmRichDigi > * fvDigiRich
std::string fsChannelNameCanvasConfig
std::string fsEvtOverMode
Switch ON/OFF filling of histograms.
std::string fsChannelNameDataOutput
FairRunOnline * fpRun
output container of CbmEvents
std::vector< std::pair< std::string, std::string > > fvpsCanvasConfig
double_t fdMaxPublishTime
Class characterising one event by a collection of links (indices) to data objects,...
std::string ToString() const
void SetIgnoreTsOverlap(Bool_t bFlagIn=kTRUE)
void ResetHistograms(Bool_t bResetTime=kTRUE)
void SetTriggerWindow(ECbmModuleId selDet, Double_t dWinBeg, Double_t dWinEnd)
void SetFillHistos(Bool_t var)
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 RemoveDetector(EventBuilderDetector selDet)
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)