11#include "EventStorage/pickDataReader.h"
12#include "EventStorage/DataReader.h"
14#include "Gaudi/Property.h"
22#include "eformat/HeaderMarker.h"
23#include "eformat/SourceIdentifier.h"
24#include "eformat/Issue.h"
25#include "eformat/Problem.h"
26#include "eformat/Version.h"
27#include "eformat/Status.h"
28#include "eformat/old/util.h"
39 const std::string& name, ISvcLocator* pSvcLocator)
40 : base_class(name, pSvcLocator)
50 assert(pSvcLocator !=
nullptr);
68 return StatusCode::SUCCESS;
77 return StatusCode::SUCCESS;
84 return StatusCode::SUCCESS;
102 auto bsmdc = std::make_unique<ByteStreamMetadataContainer>();
103 bsmdc->push_back(std::make_unique<ByteStreamMetadata>(*
m_reader));
106 return m_inputMetadata->record(std::move(bsmdc),
"ByteStreamMetadata");
115 const EventContext& context{Gaudi::Hive::currentContext()};
118 cache->releaseEvent();
121 unsigned int eventSize;
128 if (DRWAIT == ecode &&
m_wait > 0) {
132 int result = usleep(
static_cast<int>(
m_wait * 1e6));
138 }
else if (DROK != ecode) {
145 ATH_MSG_ERROR(
"DataReader not ready. Need to getBlockIterator first");
158 if (cache->rawEvent ==
nullptr) {
171 ATH_MSG_DEBUG(
"switched to previous event in slot " << context);
172 return cache->rawEvent.get();
182 const EventContext& context{ Gaudi::Hive::currentContext() };
186 cache->releaseEvent();
189 unsigned int eventSize;
199 ecode =
m_reader->getData(eventSize, &(cache->data));
207 if (DRWAIT == ecode &&
m_wait > 0) {
211 int result = usleep(
static_cast<int>(
m_wait * 1e6));
216 }
while(
m_reader->getData(eventSize, &(cache->data)) == DRWAIT);
217 }
else if (DROK != ecode) {
224 ATH_MSG_ERROR(
"DataReader not ready. Need to getBlockIterator first");
237 if (cache->rawEvent ==
nullptr) {
253 return cache->rawEvent.get();
261 const EventContext& context{Gaudi::Hive::currentContext()};
271 unsigned int status = 0;
274 std::vector<eformat::FragmentProblem> problems;
275 rawEvent->problems(problems);
277 if(!problems.empty()) {
278 status += 0x01000000;
282 for(
const auto& problem : problems)
283 ATH_MSG_WARNING(eformat::helper::FragmentProblemDictionary.
string(problem));
289 status += 0x02000000;
305 EventCache* cache, uint32_t eventSize,
bool validate)
const {
312 const DataType headWord = fragment[0];
313 ATH_MSG_DEBUG(
"First word of the fragment " << MSG::hex << headWord << MSG::dec);
315 const DataType formatVersion = eformat::helper::Version(fragment[3]).major_version();
316 ATH_MSG_DEBUG(
"Format version" << MSG::hex << formatVersion << MSG::dec);
318 if((formatVersion != eformat::MAJOR_DEFAULT_VERSION) &&
319 (formatVersion != eformat::MAJOR_V24_VERSION) &&
320 (formatVersion != eformat::MAJOR_V30_VERSION) &&
321 (formatVersion != eformat::MAJOR_V40_VERSION) &&
322 (formatVersion != eformat::MAJOR_V31_VERSION) ) {
324 << MSG::hex << formatVersion << MSG::dec);
327 if(eformat::FULL_EVENT == headWord || 0xcc1234cc == headWord) {
330 if(formatVersion != eformat::MAJOR_DEFAULT_VERSION) {
332 const uint32_t newEventSize = eventSize + 1000;
334 eformat::old::convert(fragment, newFragment, newEventSize);
337 delete [] fragment; fragment =
nullptr;
340 fragment = newFragment;
341 cache->data =
reinterpret_cast< char*
>(fragment);
343 }
catch (
const eformat::Issue& ex) {
351 ATH_MSG_FATAL(
"Unknown Header work in input fragment " << MSG::hex << headWord);
361 cache->eventStatus = 0;
362 if(fragment[5] > 0) {
363 cache->eventStatus += eformat::helper::Status(fragment[6]).specific();
364 cache->eventStatus += (eformat::helper::Status(fragment[6]).generic() & 0x000000ff) << 16;
369 cache->rawEvent = std::make_unique<RawEvent>(fragment);
370 ATH_MSG_DEBUG(
"Made an FullEventFragment from ES " << fragment);
388 const EventContext& context{Gaudi::Hive::currentContext()};
394 std::string key =
"ByteStreamDataHeader";
400 std::unique_ptr<DataHeader> dataHeader = std::make_unique<DataHeader>();
404 dataHeader->setProcessTag(dataHeaderElement->getKey());
406 dataHeader->insert(*std::move(dataHeaderElement));
412 auto bsaddr = std::make_unique<ByteStreamAddress>(
414 bsaddr->setEventContext(context);
419 if (ptmpx !=
nullptr) {
421 dataHeader->insert(element);
428 bsaddr = std::make_unique<ByteStreamAddress>(
430 bsaddr->setEventContext(context);
437 dataHeader->insert(element);
443 "ByteStreamDataHeader",
true,
false,
true));
445 return StatusCode::SUCCESS;
480 if (!status.isSuccess()) {
486 ATH_MSG_INFO(
"No more events in this run, high water mark for this file = "
513std::pair<long,std::string>
519 m_reader = std::unique_ptr<EventStorage::DataReader>(pickDataReader(fileName));
524 return std::make_pair(-1,
"END");
534 ATH_MSG_DEBUG(
"Recorded ByteStreamMetadata in InputMetaDataStore");
536 ATH_MSG_ERROR(
"Unable to record ByteStreamMetadata in InputMetaDataStore");
537 return std::make_pair(-1,
"FAIL");
545 if (!test)
return std::make_pair(-1,
"SEQ");
569 return (!eofFlag) && moreEvent;
578 uint32_t total =
re->nchildren();
580 std::vector<eformat::FragmentProblem> problems;
582 for (
size_t i = 0; i<total; ++i) {
587 lastId = f.source_id();
590 f.problems(problems);
591 if(!problems.empty()) {
593 for(
const auto& problem : problems) {
595 << eformat::helper::SourceIdentifier(lastId).human() <<
" : "
596 << eformat::helper::FragmentProblemDictionary.
string(problem));
609 const EventContext& context{Gaudi::Hive::currentContext()};
617 void*
data,
unsigned int eventStatus)
621 cache->releaseEvent();
624 cache->rawEvent = std::make_unique<RawEvent>(fragment);
625 cache->eventStatus = eventStatus;
633 if (rec_sg != StatusCode::SUCCESS) {
634 ATH_MSG_ERROR(
"Fail to record BS DataHeader in StoreGate. Skipping events?! "
644 const EventContext& context{Gaudi::Hive::currentContext()};
653 const EventContext& context{Gaudi::Hive::currentContext()};
659std::unique_ptr<DataHeaderElement>
668 "StreamRAW", std::move(token));
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
This file contains the class definition for the Token class (migrated from POOL).
static void dump(const RawEvent *re)
dump fragments from FullEventFragment
This class provides a token that identifies in a unique way objects on the persistent storage.
Token & setDb(const Guid &db)
Set database name.
Token & setOid(const OID_t &oid)
Set object identifier.
Token & setTechnology(int t)
Set technology type.
const DataType * PointerType
eformat::ROBFragment< PointerType > ROBFragment
static constexpr CLID ID()