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< IAthMetaDataSvcm_metaDataSvc {this, "MetaDataSvc", "MetaDataSvc"}
 Pointer to the data stores.
ServiceHandle< StoreGateSvcm_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 27 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 20 of file MakeEventStreamInfo.cxx.

22 : base_class(type, name, parent)
23{
24}

◆ ~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 139 of file MakeEventStreamInfo.cxx.

139 {
140 ATH_MSG_DEBUG("in finalize()");
141 return StatusCode::SUCCESS;
142}
#define ATH_MSG_DEBUG(x)

◆ initialize()

StatusCode MakeEventStreamInfo::initialize ( )
overridevirtual

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

Definition at line 26 of file MakeEventStreamInfo.cxx.

26 {
27 ATH_MSG_DEBUG("Initializing " << name());
28 // Locate the MetaDataStore
29 ATH_CHECK(m_metaDataSvc.retrieve());
30 ATH_CHECK(m_eventStore.retrieve());
31
32 // Autoconfigure data header key
33 if (m_dataHeaderKey.empty()){
34 if (const auto* parentAlg = dynamic_cast<const IAlgorithm*>(this->parent()); parentAlg) {
35 m_dataHeaderKey.setValue(parentAlg->name());
36 } else {
37 ATH_MSG_ERROR("Unable to get parent Algorithm");
38 return StatusCode::FAILURE;
39 }
40 }
41
42 return StatusCode::SUCCESS;
43}
#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 63 of file MakeEventStreamInfo.cxx.

63 {
64 SG::ReadHandle<DataHeader> dataHeader(m_dataHeaderKey);
65 if (!dataHeader.isValid()) {
66 return StatusCode::SUCCESS;
67 }
68 // Retrieve the EventInfo object
69 EventType evtype;
70 unsigned long long runN = 0;
71 unsigned lumiN = 0;
72 SG::ReadHandle<xAOD::EventInfo> xEventInfo(m_eventInfoKey);
73 if (xEventInfo.isValid()) {
74 runN = xEventInfo->runNumber();
75 lumiN = xEventInfo->lumiBlock();
76 evtype = eventTypeFromxAOD(xEventInfo.get());
77 } else {
78 ATH_MSG_ERROR("Unable to retrieve xAOD::EventInfo object");
79 return StatusCode::FAILURE;
80 }
81
82 EventStreamInfo* pEventStream = m_metaDataSvc->tryRetrieve<EventStreamInfo>(m_key.value());
83 if( !pEventStream ) {
84 auto esinfo_up = std::make_unique<EventStreamInfo>();
85 pEventStream = esinfo_up.get();
86 if( m_metaDataSvc->record(std::move(esinfo_up), m_key.value()).isFailure() ) {
87 ATH_MSG_ERROR("Could not register EventStreamInfo object");
88 return StatusCode::FAILURE;
89 }
90 }
91 static std::once_flag resetNumberOfEventsFlag;
92 std::call_once(resetNumberOfEventsFlag, [this, pEventStream]() -> void {
93 ATH_MSG_DEBUG("Resetting the EventStreamInfo payload at the first event");
94 pEventStream->reset();
95 });
96 pEventStream->addEvent();
97 pEventStream->insertProcessingTag(dataHeader->getProcessTag());
98 pEventStream->insertLumiBlockNumber( lumiN );
99 pEventStream->insertRunNumber( runN );
100 for (const DataHeaderElement& dhe : *dataHeader) {
101 pEventStream->insertItemList(dhe.getPrimaryClassID(), dhe.getKey());
102 }
103 pEventStream->insertEventType( evtype );
104
106
107 return StatusCode::SUCCESS;
108}
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 45 of file MakeEventStreamInfo.cxx.

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

◆ preExecute()

StatusCode MakeEventStreamInfo::preExecute ( )
overridevirtual

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

Definition at line 55 of file MakeEventStreamInfo.cxx.

55 {
56 return StatusCode::SUCCESS;
57}

◆ preFinalize()

StatusCode MakeEventStreamInfo::preFinalize ( )
overridevirtual

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

Definition at line 110 of file MakeEventStreamInfo.cxx.

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

59 {
60 return StatusCode::SUCCESS;
61}

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 51 of file MakeEventStreamInfo.h.

51{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 63 of file MakeEventStreamInfo.h.

63{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 56 of file MakeEventStreamInfo.h.

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

◆ m_eventStore

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

Definition at line 60 of file MakeEventStreamInfo.h.

60{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 53 of file MakeEventStreamInfo.h.

53{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 59 of file MakeEventStreamInfo.h.

59{this, "MetaDataSvc", "MetaDataSvc"};

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