ATLAS Offline Software
MakeEventStreamInfo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "MakeEventStreamInfo.h"
11 
12 #include "GaudiKernel/IAlgorithm.h"
13 
18 
19 //___________________________________________________________________________
21  const std::string& name,
22  const IInterface* parent) : base_class(type, name, parent)
23 {
24 }
25 //___________________________________________________________________________
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 }
44 //___________________________________________________________________________
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 }
54 //___________________________________________________________________________
56  return StatusCode::SUCCESS;
57 }
58 //___________________________________________________________________________
60  return StatusCode::SUCCESS;
61 }
62 //___________________________________________________________________________
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;
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 
105  m_eventCounter++;
106 
107  return StatusCode::SUCCESS;
108 }
109 //___________________________________________________________________________
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 }
138 //___________________________________________________________________________
140  ATH_MSG_DEBUG("in finalize()");
141  return StatusCode::SUCCESS;
142 }
MakeEventStreamInfo::m_eventStore
ServiceHandle< StoreGateSvc > m_eventStore
Definition: MakeEventStreamInfo.h:60
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
EventType
This class represents the "type of event" where the type is given by one or more "characteristics".
Definition: EventType.h:92
MakeEventStreamInfo::m_metaDataSvc
ServiceHandle< IAthMetaDataSvc > m_metaDataSvc
Pointer to the data stores.
Definition: MakeEventStreamInfo.h:59
EventStreamInfo::reset
void reset()
Definition: EventStreamInfo.cxx:132
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
EventStreamInfo.h
This file contains the class definition for the EventStreamInfo class.
EventInfoFromxAOD.h
EventStreamInfo::setNumberOfEvents
void setNumberOfEvents(unsigned int number)
Set number of events.
Definition: EventStreamInfo.cxx:58
DataHeaderElement
This class provides a persistent form for the TransientAddress.
Definition: DataHeader.h:37
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MakeEventStreamInfo::m_eventCounter
std::atomic< unsigned int > m_eventCounter
Counter of the events in the stream.
Definition: MakeEventStreamInfo.h:63
EventStreamInfo::insertRunNumber
void insertRunNumber(unsigned int run)
Insert new Run Number into a set.
Definition: EventStreamInfo.cxx:64
MakeEventStreamInfo::postInitialize
virtual StatusCode postInitialize() override
Called at the end of AthenaOutputStream::initialize().
Definition: MakeEventStreamInfo.cxx:45
MakeEventStreamInfo::m_dataHeaderKey
StringProperty m_dataHeaderKey
Name of DataHeader key.
Definition: MakeEventStreamInfo.h:51
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::ReadHandle::get
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MakeEventStreamInfo::MakeEventStreamInfo
MakeEventStreamInfo(const std::string &type, const std::string &name, const IInterface *parent)
Standard AlgTool Constructor.
Definition: MakeEventStreamInfo.cxx:20
EventStreamInfo::addEvent
void addEvent(unsigned int number=1)
Increase Event Counter.
Definition: EventStreamInfo.cxx:53
DataHeader.h
This file contains the class definition for the DataHeader and DataHeaderElement classes.
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
MakeEventStreamInfo::finalize
virtual StatusCode finalize() override
Called at the end of AthenaOutputStream::finalize() (via release()).
Definition: MakeEventStreamInfo.cxx:139
EventStreamInfo::insertProcessingTag
void insertProcessingTag(const std::string &process)
Insert new Processing Tag into a set.
Definition: EventStreamInfo.cxx:76
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
EventStreamInfo::getNumberOfEvents
unsigned int getNumberOfEvents() const
Definition: EventStreamInfo.cxx:17
MakeEventStreamInfo::postExecute
virtual StatusCode postExecute() override
Called at the end of AthenaOutputStream::execute().
Definition: MakeEventStreamInfo.cxx:63
MakeEventStreamInfo::preExecute
virtual StatusCode preExecute() override
Called at the beginning of AthenaOutputStream::execute().
Definition: MakeEventStreamInfo.cxx:55
EventInfo.h
MakeEventStreamInfo::m_eventInfoKey
StringProperty m_eventInfoKey
Key, the StoreGate key for the xAOD::EventInfo object.
Definition: MakeEventStreamInfo.h:56
EventStreamInfo
This class provides the summary information stored for data written as a Event Stream.
Definition: EventStreamInfo.h:28
DataHeader::getProcessTag
const std::string & getProcessTag() const
Definition: DataHeader.cxx:246
MakeEventStreamInfo::preFinalize
virtual StatusCode preFinalize() override
Called at the beginning of AthenaOutputStream::finalize().
Definition: MakeEventStreamInfo.cxx:110
MakeEventStreamInfo::preStream
virtual StatusCode preStream() override
Called before actually streaming objects.
Definition: MakeEventStreamInfo.cxx:59
EventStreamInfo::insertItemList
void insertItemList(CLID type, const std::string &key)
Insert new ItemList Entry into a set.
Definition: EventStreamInfo.cxx:82
MakeEventStreamInfo::initialize
virtual StatusCode initialize() override
Required of all IAthenaOutputTools: Called by AthenaOutputStream::initialize() (via ToolSvc retrieve(...
Definition: MakeEventStreamInfo.cxx:26
eventTypeFromxAOD
EventType eventTypeFromxAOD(const xAOD::EventInfo *xaod)
Create EventType object from xAOD::EventInfo.
Definition: EventInfoFromxAOD.cxx:34
MakeEventStreamInfo::m_key
StringProperty m_key
Key, the StoreGate key for the EventStreamInfo object.
Definition: MakeEventStreamInfo.h:53
EventStreamInfo::insertEventType
void insertEventType(const EventType &event)
Insert new Event Type into a set.
Definition: EventStreamInfo.cxx:88
EventStreamInfo::insertLumiBlockNumber
void insertLumiBlockNumber(unsigned int lumiBlock)
Insert new Luminosity Block Number into a set.
Definition: EventStreamInfo.cxx:70
MakeEventStreamInfo.h
This file contains the class definition for the MakeEventStreamInfo class.