18#include <FairLogger.h>
19#include <FairRootManager.h>
20#include <FairRunOnline.h>
26#include "ext_data_client.h"
29 const TString& NtupleOptions,
30 const TString& UcesbPath,
53 R3BLOG(debug1,
"R3BUcesbSource destructor.");
66 R3BLOG(debug,
"checking whether R3BEventHeader has been defined in FairRun");
67 auto run = FairRun::Instance();
68 auto eventHeader =
dynamic_cast<R3BEventHeader*
>(run->GetEventHeader());
71 R3BLOG(info,
"EventHeader. was defined properly");
76 run->SetEventHeader(std::unique_ptr<R3BEventHeader>());
79 run->SetEventHeader(eventHeader);
81 R3BLOG(warn,
"EventHeader. has been created from R3BEventHeader");
85 std::ostringstream command;
94 LOG(info) <<
"Calling ucesb with command: " << command.str();
97 fFd = popen(command.str().c_str(),
"r");
100 R3BLOG(fatal,
"popen() failed");
106 if (kFALSE == status)
108 R3BLOG(error,
"ext_data_clnt::connect() failed");
117 R3BLOG(warn,
"Input file for RunIds could not be open, it is Ok!");
132 FairRootManager* frm = FairRootManager::Instance();
133 R3BLOG_IF(fatal, !frm,
"FairRootManager no found");
135 R3BLOG(info,
"Checking the register of R3BEventHeader");
139 R3BLOG(info,
"EventHeader. was defined properly");
143 R3BLOG(error,
"EventHeader. was not defined properly!");
147 for (
int i = 0; i <
fReaders->GetEntriesFast(); ++i)
158 uint32_t struct_map_success = 0;
163 R3BLOG(error,
"ext_data_clnt::setup() failed");
173 uint32_t map_ok = EXT_DATA_ITEM_MAP_OK | EXT_DATA_ITEM_MAP_NO_DEST;
174 if (struct_map_success & ~(map_ok))
176 R3BLOG(warn,
"ext_data_clnt::setup() failed to map all items:");
177 ext_data_struct_info_print_map_success(
fStructInfo, stderr, map_ok);
184 "ext_data_clnt::setup() mapping failure may "
185 "cause unexpected analysis results due to missing "
186 "data members. Unpacker needs fixing.");
191 "ext_data_clnt::setup() mapping failure may "
192 "cause unexpected analysis results due to missing "
193 "data members. Unpacker needs fixing.");
204 for (
int i = 0; i <
fReaders->GetEntriesFast(); ++i)
213 for (
int i = 0; i <
fReaders->GetEntriesFast(); ++i)
217 R3BLOG(fatal,
"ReInit of a reader failed.");
227 std::string tempstr = wholestr;
228 tempstr.replace(0, tempstr.find(pattern) + pattern.length(),
"");
229 tempstr.replace(0, tempstr.find(
'=') + 1,
"");
230 return atoi(tempstr.c_str());
247 R3BLOG(info,
"ReadEvent()");
253 LOG(info) <<
"read from file: \"" << buffer <<
"\"";
254 if (buffer.find(
"EVENT BEGIN") == 0)
259 if (buffer.find(
"EVENT") == 0)
261 Int_t fInit = atoi(buffer.c_str());
262 buffer.erase(0, buffer.find(
' ') + 1);
265 }
while (
fInputFile && buffer.compare(
"EVENT END"));
278 LOG(info) <<
"End of input";
283 perror(
"ext_data_clnt::fetch_event()");
284 R3BLOG(error,
"ext_data_clnt::fetch_event() failed");
290 ret =
fClient.get_raw_data(&raw, &raw_words);
293 perror(
"ext_data_clnt::get_raw_data()");
294 R3BLOG(fatal,
"Failed to get raw data.");
299 for (
int r = 0; r <
fReaders->GetEntriesFast(); ++r)
303 LOG(debug1) <<
" Reading reader " << r <<
" (" << reader->GetName() <<
")";
311 const uint32_t* u =
reinterpret_cast<const uint32_t*
>(raw);
313 LOG(info) <<
" Raw data:";
314 for (w = 0; w < raw_words; w += 8)
316 printf(
" RAW%4x:", w);
317 for (j = 0; j < 8 && w + j < raw_words; j++)
318 printf(
" %08x", u[w + j]);
337 R3BLOG(fatal,
"ext_data_clnt::close() failed");
342 status = pclose(
fFd);
346 R3BLOG(fatal,
"pclose() failed");
357 for (
int i = 0; i <
fReaders->GetEntriesFast(); ++i)
376 feh->SetRunId(fRunId);
#define R3BLOG(severity, x)
#define R3BLOG_IF(severity, condition, x)
struct EXT_STR_h101_t EXT_STR_h101
virtual Bool_t R3BRead()=0
R3BUcesbSource(const TString &, const TString &, const TString &, EXT_STR_h101 *, size_t)
virtual Bool_t InitUnpackers()
virtual void SetParUnpackers()
R3BEventHeader * fEventHeader
virtual void FillEventHeader(FairEventHeader *feh)
bool fFullDataStructureValidation
virtual Bool_t ReInitUnpackers()
const TString fNtupleOptions
ext_data_struct_info fStructInfo
virtual ~R3BUcesbSource()
virtual Bool_t SpecifyRunId()
Int_t ReadIntFromString(const std::string &wholestr, const std::string &pattern)