ATLAS Offline Software
Loading...
Searching...
No Matches
MakeEventStreamInfo Class Reference

This class provides an algorithm to make the EventStreamInfo object and update it. More...

#include <MakeEventStreamInfo.h>

Inheritance diagram for MakeEventStreamInfo:
Collaboration diagram for MakeEventStreamInfo:

Public Member Functions

 MakeEventStreamInfo (const std::string &type, const std::string &name, const IInterface *parent)
 Standard AlgTool Constructor.
virtual ~MakeEventStreamInfo ()=default
 Destructor.
virtual StatusCode initialize () override
 Required of all IAthenaOutputTools: Called by AthenaOutputStream::initialize() (via ToolSvc retrieve()).
virtual StatusCode postInitialize () override
 Called at the end of AthenaOutputStream::initialize().
virtual StatusCode preExecute () override
 Called at the beginning of AthenaOutputStream::execute().
virtual StatusCode preStream () override
 Called before actually streaming objects.
virtual StatusCode postExecute () override
 Called at the end of AthenaOutputStream::execute().
virtual StatusCode preFinalize () override
 Called at the beginning of AthenaOutputStream::finalize().
virtual StatusCode finalize () override
 Called at the end of AthenaOutputStream::finalize() (via release()).

Private Attributes

Gaudi::Property< std::string > m_dataHeaderKey {this, "DataHeaderKey", "", "name of the data header key"}
 Name of DataHeader key.
Gaudi::Property< std::string > m_key {this, "Key", "", "name of the EventStreamInfo object"}
 Key, the StoreGate key for the EventStreamInfo object.
Gaudi::Property< std::string > m_eventInfoKey {this, "EventInfoKey", "EventInfo", "name of the xAOD::EventInfo"}
 Key, the StoreGate key for the xAOD::EventInfo object.
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc {this, "MetaDataSvc", "MetaDataSvc"}
 Pointer to the data stores.
ServiceHandle< StoreGateSvc > m_eventStore {this, "StoreGateSvc", "StoreGateSvc"}
std::atomic< unsigned int > m_eventCounter {0}
 Counter of the events in the stream.

Detailed Description

This class provides an algorithm to make the EventStreamInfo object and update it.

Definition at line 26 of file MakeEventStreamInfo.h.

Constructor & Destructor Documentation

◆ MakeEventStreamInfo()

MakeEventStreamInfo::MakeEventStreamInfo ( const std::string & type,
const std::string & name,
const IInterface * parent )

Standard AlgTool Constructor.

Definition at line 19 of file MakeEventStreamInfo.cxx.

20 : base_class(type, name, parent) {}

◆ ~MakeEventStreamInfo()

virtual MakeEventStreamInfo::~MakeEventStreamInfo ( )
virtualdefault

Destructor.

Member Function Documentation

◆ finalize()

StatusCode MakeEventStreamInfo::finalize ( )
overridevirtual

Called at the end of AthenaOutputStream::finalize() (via release()).

Definition at line 133 of file MakeEventStreamInfo.cxx.

133 {
134 ATH_MSG_DEBUG("in finalize()");
135 return StatusCode::SUCCESS;
136}
#define ATH_MSG_DEBUG(x,...)

◆ initialize()

StatusCode MakeEventStreamInfo::initialize ( )
overridevirtual

Required of all IAthenaOutputTools: Called by AthenaOutputStream::initialize() (via ToolSvc retrieve()).

Definition at line 22 of file MakeEventStreamInfo.cxx.

22 {
23 ATH_MSG_DEBUG("Initializing " << name());
24 // Locate the MetaDataStore
25 ATH_CHECK(m_metaDataSvc.retrieve());
26 ATH_CHECK(m_eventStore.retrieve());
27
28 // Autoconfigure data header key
29 if (m_dataHeaderKey.empty()) {
30 if (const auto* parentAlg = dynamic_cast<const IAlgorithm*>(this->parent()); parentAlg) {
31 m_dataHeaderKey.setValue(parentAlg->name());
32 } else {
33 ATH_MSG_ERROR("Unable to get parent Algorithm");
34 return StatusCode::FAILURE;
35 }
36 }
37
38 return StatusCode::SUCCESS;
39}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
ServiceHandle< StoreGateSvc > m_eventStore
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Pointer to the data stores.
Gaudi::Property< std::string > m_dataHeaderKey
Name of DataHeader key.

◆ postExecute()

StatusCode MakeEventStreamInfo::postExecute ( )
overridevirtual

Called at the end of AthenaOutputStream::execute().

Definition at line 59 of file MakeEventStreamInfo.cxx.

59 {
60 SG::ReadHandle<DataHeader> dataHeader(m_dataHeaderKey);
61 if (!dataHeader.isValid()) {
62 return StatusCode::SUCCESS;
63 }
64 // Retrieve the EventInfo object
65 EventType evtype;
66 unsigned long long runN = 0;
67 unsigned lumiN = 0;
68 SG::ReadHandle<xAOD::EventInfo> xEventInfo(m_eventInfoKey);
69 if (xEventInfo.isValid()) {
70 runN = xEventInfo->runNumber();
71 lumiN = xEventInfo->lumiBlock();
72 evtype = eventTypeFromxAOD(xEventInfo.get());
73 } else {
74 ATH_MSG_ERROR("Unable to retrieve xAOD::EventInfo object");
75 return StatusCode::FAILURE;
76 }
77
78 EventStreamInfo* pEventStream = m_metaDataSvc->tryRetrieve<EventStreamInfo>(m_key.value());
79 if (!pEventStream) {
80 auto esinfo_up = std::make_unique<EventStreamInfo>();
81 pEventStream = esinfo_up.get();
82 if (m_metaDataSvc->record(std::move(esinfo_up), m_key.value()).isFailure()) {
83 ATH_MSG_ERROR("Could not register EventStreamInfo object");
84 return StatusCode::FAILURE;
85 }
86 }
87 static std::once_flag resetNumberOfEventsFlag;
88 std::call_once(resetNumberOfEventsFlag, [this, pEventStream]() -> void {
89 ATH_MSG_DEBUG("Resetting the EventStreamInfo payload at the first event");
90 pEventStream->reset();
91 });
92 pEventStream->addEvent();
93 pEventStream->insertProcessingTag(dataHeader->getProcessTag());
94 pEventStream->insertLumiBlockNumber(lumiN);
95 pEventStream->insertRunNumber(runN);
96 for (const DataHeaderElement& dhe : *dataHeader) {
97 pEventStream->insertItemList(dhe.getPrimaryClassID(), dhe.getKey());
98 }
99 pEventStream->insertEventType(evtype);
100
102
103 return StatusCode::SUCCESS;
104}
EventType eventTypeFromxAOD(const xAOD::EventInfo *xaod)
Create EventType object from xAOD::EventInfo.
Athena::TPCnvVers::Old Athena::TPCnvVers::Current EventStreamInfo
void insertEventType(const EventType &event)
Insert new Event Type into a set.
void insertLumiBlockNumber(unsigned int lumiBlock)
Insert new Luminosity Block Number into a set.
void insertRunNumber(unsigned int run)
Insert new Run Number into a set.
void addEvent(unsigned int number=1)
Increase Event Counter.
void insertProcessingTag(const std::string &process)
Insert new Processing Tag into a set.
void insertItemList(CLID type, const std::string &key)
Insert new ItemList Entry into a set.
Gaudi::Property< std::string > m_key
Key, the StoreGate key for the EventStreamInfo object.
Gaudi::Property< std::string > m_eventInfoKey
Key, the StoreGate key for the xAOD::EventInfo object.
std::atomic< unsigned int > m_eventCounter
Counter of the events in the stream.

◆ postInitialize()

StatusCode MakeEventStreamInfo::postInitialize ( )
overridevirtual

Called at the end of AthenaOutputStream::initialize().

Definition at line 41 of file MakeEventStreamInfo.cxx.

41 {
42 // Remove EventStreamInfo with same key if it exists
43 bool ignoreIfAbsent = true;
44 if (!m_metaDataSvc->remove<EventStreamInfo>(m_key.value(), ignoreIfAbsent).isSuccess()) {
45 ATH_MSG_ERROR("Unable to remove EventStreamInfo with key " << m_key.value());
46 return StatusCode::FAILURE;
47 }
48 return StatusCode::SUCCESS;
49}

◆ preExecute()

StatusCode MakeEventStreamInfo::preExecute ( )
overridevirtual

Called at the beginning of AthenaOutputStream::execute().

Definition at line 51 of file MakeEventStreamInfo.cxx.

51 {
52 return StatusCode::SUCCESS;
53}

◆ preFinalize()

StatusCode MakeEventStreamInfo::preFinalize ( )
overridevirtual

Called at the beginning of AthenaOutputStream::finalize().

Definition at line 106 of file MakeEventStreamInfo.cxx.

106 {
107 EventStreamInfo* pEventStream = m_metaDataSvc->tryRetrieve<EventStreamInfo>(m_key.value());
108 if (!pEventStream) {
109 auto esinfo_up = std::make_unique<EventStreamInfo>();
110 pEventStream = esinfo_up.get();
111 ATH_CHECK(m_metaDataSvc->record(std::move(esinfo_up), m_key.value()));
112 }
113 if (m_eventCounter > 0 && m_eventCounter < pEventStream->getNumberOfEvents()) {
114 // The number of events that have been processed by MakeEventStreamInfo
115 // tool is less than the number of events in already existing
116 // EventStreamInfo object. This can happen if the EventStreamInfo object was
117 // updated by CopyEventStreamInfo, for example at beginning of reading the
118 // 2nd (or next) file.
120 "Event count mismatch in EventStreamInfo (likely due to "
121 "multi-file processing). MakeEventStreamInfo processed: "
122 << m_eventCounter << " events, existing EventStreamInfo object has " << pEventStream->getNumberOfEvents()
123 << " events. Setting number of events to what "
124 "MakeEventStreamInfo processed.");
125 pEventStream->setNumberOfEvents(m_eventCounter);
126 } else {
127 // Insert processing tags when no events have been processed
128 pEventStream->insertProcessingTag(m_dataHeaderKey.value());
129 }
130 return (StatusCode::SUCCESS);
131}
unsigned int getNumberOfEvents() const
void setNumberOfEvents(unsigned int number)
Set number of events.

◆ preStream()

StatusCode MakeEventStreamInfo::preStream ( )
overridevirtual

Called before actually streaming objects.

Definition at line 55 of file MakeEventStreamInfo.cxx.

55 {
56 return StatusCode::SUCCESS;
57}

Member Data Documentation

◆ m_dataHeaderKey

Gaudi::Property<std::string> MakeEventStreamInfo::m_dataHeaderKey {this, "DataHeaderKey", "", "name of the data header key"}
private

Name of DataHeader key.

Definition at line 50 of file MakeEventStreamInfo.h.

50{this, "DataHeaderKey", "", "name of the data header key"};

◆ m_eventCounter

std::atomic<unsigned int> MakeEventStreamInfo::m_eventCounter {0}
private

Counter of the events in the stream.

Definition at line 62 of file MakeEventStreamInfo.h.

62{0};

◆ m_eventInfoKey

Gaudi::Property<std::string> MakeEventStreamInfo::m_eventInfoKey {this, "EventInfoKey", "EventInfo", "name of the xAOD::EventInfo"}
private

Key, the StoreGate key for the xAOD::EventInfo object.

Definition at line 55 of file MakeEventStreamInfo.h.

55{this, "EventInfoKey", "EventInfo", "name of the xAOD::EventInfo"};

◆ m_eventStore

ServiceHandle<StoreGateSvc> MakeEventStreamInfo::m_eventStore {this, "StoreGateSvc", "StoreGateSvc"}
private

Definition at line 59 of file MakeEventStreamInfo.h.

59{this, "StoreGateSvc", "StoreGateSvc"};

◆ m_key

Gaudi::Property<std::string> MakeEventStreamInfo::m_key {this, "Key", "", "name of the EventStreamInfo object"}
private

Key, the StoreGate key for the EventStreamInfo object.

Definition at line 52 of file MakeEventStreamInfo.h.

52{this, "Key", "", "name of the EventStreamInfo object"};

◆ m_metaDataSvc

ServiceHandle<IAthMetaDataSvc> MakeEventStreamInfo::m_metaDataSvc {this, "MetaDataSvc", "MetaDataSvc"}
private

Pointer to the data stores.

Definition at line 58 of file MakeEventStreamInfo.h.

58{this, "MetaDataSvc", "MetaDataSvc"};

The documentation for this class was generated from the following files: