15 #ifndef FAIRMQLMDSAMPLER_H
16 #define FAIRMQLMDSAMPLER_H
25 #include <FairMQDevice.h>
26 #include <FairMQLogger.h>
27 #include <FairMQMessage.h>
28 #include <boost/filesystem.hpp>
47 , fInfoHeader(nullptr)
70 const std::string& channelName)
72 SubEvtKey key(type, subType, procid, subCrate, control);
73 if (fSubEventChanMap.count(key)) {
74 LOG(warn) <<
"FairMQLmdSampler : subevent header key '(" << type <<
"," << subType <<
"," << procid <<
","
75 << subCrate <<
"," << control <<
")' has already been defined with channel name '"
76 << fSubEventChanMap.at(key)
77 <<
"'. it will be overwritten with new channel name = " << channelName;
79 fSubEventChanMap[key] = channelName;
84 boost::filesystem::path directory = dir;
86 if (boost::filesystem::exists(directory)) {
87 boost::filesystem::directory_iterator end_itr;
89 for (boost::filesystem::directory_iterator itr(directory); itr != end_itr; ++itr) {
90 if (boost::filesystem::is_regular_file(itr->path())) {
91 std::string currentFile = itr->path().string();
96 LOG(warn) <<
"FairMQLmdSampler: directory '" << directory.string() <<
"' not found";
101 boost::filesystem::path filepath = fileName;
102 if (boost::filesystem::exists(filepath)) {
103 fFileNames.push_back(fileName);
105 LOG(warn) <<
"FairMQLmdSampler: file '" << fileName <<
"' not found";
112 fFilename = fConfig->GetValue<std::string>(
"input-file-name");
113 fType = fConfig->GetValue<
short>(
"lmd-type");
114 fSubType = fConfig->GetValue<
short>(
"lmd-sub-type");
115 fProcId = fConfig->GetValue<
short>(
"lmd-proc-id");
116 fSubCrate = fConfig->GetValue<
short>(
"lmd-sub-crate");
117 fControl = fConfig->GetValue<
short>(
"lmd-control");
118 fChanName = fConfig->GetValue<std::string>(
"lmd-chan-name");
123 AddSubEvtKey(fType, fSubType, fProcId, fSubCrate, fControl, fChanName);
125 if (fFileNames.empty()) {
126 throw std::runtime_error(std::string(
"FairMQLmdSampler::InitTask: No files provided"));
129 std::string name = fFileNames.at(fCurrentFile);
131 throw std::runtime_error(std::string(
"FairMQLmdSampler::InitTask: cannot open file ") + name);
141 while (!NewStatePending())
147 LOG(info) <<
"Sent " << fMsgCounter <<
" messages.";
152 void* evtptr = &fEvent;
153 void* buffptr = &fBuffer;
161 int status =
f_evt_get_event(&fInputChannel, static_cast<INTS4**>(evtptr), static_cast<INTS4**>(buffptr));
171 CHARS* sErrorString = NULL;
179 if (fCurrentFile >= static_cast<int>(fFileNames.size())) {
184 std::string name = fFileNames.at(fCurrentFile);
214 for (
int i = 1; i <= nrSubEvts; i++) {
215 void* SubEvtptr = &fSubEvent;
216 void* EvtDataptr = &fEventData;
219 fEvent, i, static_cast<int**>(SubEvtptr), static_cast<int**>(EvtDataptr), &nrlongwords);
225 sebuflength = nrlongwords;
226 setype = fSubEvent->
i_type;
236 SubEvtKey key(setype, sesubtype, seprocid, sesubcrate, secontrol);
238 if (!fSubEventChanMap.count(key)) {
244 std::string chanName = fSubEventChanMap.at(key);
253 int* arraySize =
new int(sebuflength);
255 parts.AddPart(NewMessage(
258 [](
void* ,
void* hint) {
delete static_cast<int*
>(hint); },
260 parts.AddPart(NewMessage(
263 [](
void* ,
void* ) { },
265 Send(parts, chanName);
292 void* headptr = &fInfoHeader;
295 LOG(info) <<
"File " << fileName <<
" will be opened.";
298 inputMode, const_cast<char*>(fileName.c_str()), &fInputChannel, static_cast<char**>(headptr), 1, 1);
301 LOG(error) <<
"File " << fileName <<
" opening failed.";
305 LOG(info) <<
"File " << fileName <<
" opened.";
324 std::vector<std::string> fFileNames;
333 typedef std::tuple<short, short, short, short, short> SubEvtKey;
334 std::map<SubEvtKey, std::string> fSubEventChanMap;
336 std::string fFilename;
342 std::string fChanName;
INTS4 f_evt_get_subevent(s_ve10_1 *ps_ve10_1, INTS4 l_subevent, INTS4 **pl_se, INTS4 **pl_d, INTS4 *pl_lwords)
INTS4 f_evt_get_close(s_evt_channel *ps_chan)
INTS4 f_evt_get_open(INTS4 l_mode, CHARS *pc_server, s_evt_channel *ps_chan, CHARS **ps_info, INTS4 l_sample, INTS4 l_param)
INTS4 f_evt_error(INTS4 l_error, CHARS *pc_dest, INTS4 l_out)
void AddSubEvtKey(short type, short subType, short procid, short subCrate, short control, const std::string &channelName)
FairMQLmdSampler operator=(const FairMQLmdSampler &)=delete
bool OpenNextFile(const std::string &fileName)
void AddFile(const std::string &fileName)
virtual ~FairMQLmdSampler()
INTS4 f_evt_get_event(s_evt_channel *ps_chan, INTS4 **ppl_buffer, INTS4 **ppl_goobuf)
void AddDir(const std::string &dir)