11#include "BoostSerializer.h"
13#include "FairMQLogger.h"
14#include "FairMQProgOptions.h"
15#include "FairRootFileSink.h"
16#include "FairRootManager.h"
17#include "FairRunOnline.h"
18#include "RootSerializer.h"
23#include <boost/archive/binary_iarchive.hpp>
24#include <boost/serialization/utility.hpp>
32 using std::runtime_error::runtime_error;
42 LOG(info) <<
"Init options for CbmDevBuildEvents.";
47 const std::vector<std::string> vsSetEvbuildWin = fConfig->GetValue<std::vector<std::string>>(
"SetEvbuildWin");
55 fpRun =
new FairRunOnline();
83 int noChannel = fChannels.size();
84 LOG(info) <<
"Number of defined channels: " << noChannel;
85 for (
auto const& entry : fChannels) {
86 LOG(info) <<
"Channel name: " << entry.first;
94 for (std::vector<std::string>::const_iterator itStrEvbuildWin = vsSetEvbuildWin.begin();
95 itStrEvbuildWin != vsSetEvbuildWin.end(); ++itStrEvbuildWin) {
96 size_t charPosDel = (*itStrEvbuildWin).find(
',');
97 if (std::string::npos == charPosDel) {
98 LOG(info) <<
"CbmDevBuildEvents::InitTask => "
99 <<
"Trying to set event builder window with invalid option pattern, ignored! "
100 <<
" (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found " << (*itStrEvbuildWin) <<
" )";
105 std::string sSelDet = (*itStrEvbuildWin).substr(0, charPosDel);
109 LOG(info) <<
"CbmDevBuildEvents::InitTask => "
110 <<
"Trying to set trigger window for unsupported detector, ignored! " << sSelDet;
116 std::string sNext = (*itStrEvbuildWin).substr(charPosDel);
117 charPosDel = sNext.find(
',');
118 if (std::string::npos == charPosDel) {
119 LOG(info) <<
"CbmDevBuildEvents::InitTask => "
120 <<
"Trying to set event builder window with invalid option pattern, ignored! "
121 <<
" (Should be ECbmModuleId,dWinBeg,dWinEnd but instead found " << (*itStrEvbuildWin) <<
" )";
124 double dWinBeg = std::stod(sNext.substr(0, charPosDel));
128 double dWinEnd = std::stod(sNext.substr(charPosDel));
130 fEvbuildAlgo = std::make_unique<cbm::algo::evbuild::EventBuilder>(config);
134 LOG(error) << e.what();
161 std::size_t pos1 = channelName.find(entry);
162 if (pos1 != std::string::npos) {
163 const vector<std::string>::const_iterator
pos =
166 LOG(info) <<
"Found " << entry <<
" in " << channelName;
167 LOG(info) <<
"Channel name " << channelName <<
" found in list of allowed channel names at position " << idx;
171 LOG(info) <<
"Channel name " << channelName <<
" not found in list of allowed channel names.";
172 LOG(error) <<
"Stop device.";
180 LOG(info) <<
"Received message number " <<
fulNumMessages <<
" with " << parts.Size() <<
" parts"
181 <<
", size0: " << parts.At(0)->GetSize();
186 uint32_t uPartIdx = 0;
190 std::string msgStrTS(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
191 std::istringstream issTS(msgStrTS);
192 boost::archive::binary_iarchive inputArchiveTS(issTS);
193 inputArchiveTS >> ts;
198 RootSerializer().Deserialize(*parts.At(uPartIdx), tsMetaData);
202 std::vector<double> triggers;
203 std::string msgStrTrig(
static_cast<char*
>(parts.At(uPartIdx)->GetData()), (parts.At(uPartIdx))->GetSize());
204 std::istringstream issTrig(msgStrTrig);
205 boost::archive::binary_iarchive inputArchiveTrig(issTrig);
206 inputArchiveTrig >> triggers;
222 LOG(debug) <<
"triggers: " << triggers.size();
225 std::vector<CbmDigiEvent> vEvents = (*fEvbuildAlgo)(ts, triggers).
first;
226 LOG(debug) <<
"vEvents size: " << vEvents.size();
238 (*fEventsSelOut) = std::move(vEvents);
265 LOG(debug) <<
"Vector size: " << vEvents.size();
267 FairMQParts partsOut;
270 FairMQMessagePtr messTsMeta(NewMessage());
271 RootSerializer().Serialize(*messTsMeta, tsMetaData);
272 partsOut.AddPart(std::move(messTsMeta));
275 std::stringstream ossEvt;
276 boost::archive::binary_oarchive oaEvt(ossEvt);
278 std::string* strMsgEvt =
new std::string(ossEvt.str());
280 partsOut.AddPart(NewMessage(
281 const_cast<char*
>(strMsgEvt->c_str()),
283 [](
void*,
void*
object) { delete static_cast<std::string*>(object); },
@ kTrd
Transition Radiation Detector.
@ kTof
Time-of-flight Detector.
@ kPsd
Projectile spectator detector.
@ kSts
Silicon Tracking System.
@ kTrd2d
TRD-FASP Detector (FIXME)
@ kMuch
Muon detection system.
@ kFsd
Forward spectator detector.
@ kRich
Ring-Imaging Cherenkov Detector.
std::vector< CbmBmonDigi > fDigis
Data vector.
std::string fsChannelNameDataInput
Keep track of whether the Finish was already called.
std::vector< CbmDigiEvent > * fEventsSelOut
ECbmModuleId GetDetectorId(std::string detName)
std::string fsChannelNameDataOutput
uint64_t fulNumMessages
Statistics & first TS rejection.
bool SendEvents(const std::vector< CbmDigiEvent > &vEvents, const TimesliceMetaData *tsMetaData)
FairRootManager * fpFairRootMgr
bool HandleData(FairMQParts &, int)
bool IsChannelNameAllowed(std::string channelName)
std::unique_ptr< cbm::algo::evbuild::EventBuilder > fEvbuildAlgo
Processing algos.
virtual ~CbmDevBuildEvents()
TClonesArray * fTimeSliceMetaDataArrayOut
std::string fsOutputFileName
Data storage.
std::vector< std::string > fsAllowedChannels
List of MQ channels names.
CbmPsdDigiData fPsd
PSD data.
CbmTrdDigiData fTrd
TRD data.
CbmTofDigiData fTof
TOF data.
CbmStsDigiData fSts
STS data.
CbmFsdDigiData fFsd
FSD data.
CbmRichDigiData fRich
RICH data.
CbmMuchDigiData fMuch
MUCH data.
CbmBmonDigiData fBmon
Beam monitor data.
Collection of digis from all detector systems within one timeslice.
CbmDigiData fData
Timeslice data.
std::vector< CbmFsdDigi > fDigis
Data vector.
std::vector< CbmMuchDigi > fDigis
Data vector.
std::vector< CbmPsdDigi > fDigis
Data vector.
std::vector< CbmRichDigi > fDigis
Data vector.
std::vector< CbmStsDigi > fDigis
Data vector.
std::vector< CbmTofDigi > fDigis
Data vector.
std::vector< CbmTrdDigi > fDigis
Data vector.
Configuration of the EventBuilder class.
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)