ATLAS Offline Software
MakeEventStreamInfo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "MakeEventStreamInfo.h"
11 
12 #include "GaudiKernel/IAlgorithm.h"
13 
16 #include "EventInfo/EventInfo.h"
17 #include "EventInfo/EventID.h"
18 #include "StoreGate/StoreGateSvc.h"
21 
22 //___________________________________________________________________________
24  const std::string& name,
25  const IInterface* parent) : base_class(type, name, parent)
26 {
27 }
28 //___________________________________________________________________________
30 }
31 //___________________________________________________________________________
33  ATH_MSG_DEBUG("Initializing " << name());
34  // Locate the MetaDataStore
35  if (!m_metaDataSvc.retrieve().isSuccess()) {
36  ATH_MSG_FATAL("Could not find MetaDataSvc");
37  return(StatusCode::FAILURE);
38  }
39  if (!m_eventStore.retrieve().isSuccess()) {
40  ATH_MSG_FATAL("Could not find EventStore");
41  return(StatusCode::FAILURE);
42  }
43 
44  // Autoconfigure data header key
45  if (m_dataHeaderKey.empty()){
46  const IAlgorithm* parentAlg = dynamic_cast<const IAlgorithm*>(this->parent());
47  if (parentAlg == nullptr) {
48  ATH_MSG_ERROR("Unable to get parent Algorithm");
49  return(StatusCode::FAILURE);
50  }
51  m_dataHeaderKey.setValue(parentAlg->name());
52  }
53 
54  return(StatusCode::SUCCESS);
55 }
56 //___________________________________________________________________________
58  // Remove EventStreamInfo with same key if it exists
59  bool ignoreIfAbsent = true;
60  if( !m_metaDataSvc->remove<EventStreamInfo>(m_key.value(), ignoreIfAbsent).isSuccess() ) {
61  ATH_MSG_ERROR("Unable to remove EventStreamInfo with key " << m_key.value());
62  return StatusCode::FAILURE;
63  }
64  return(StatusCode::SUCCESS);
65 }
66 //___________________________________________________________________________
68  return(StatusCode::SUCCESS);
69 }
70 //___________________________________________________________________________
72  return(StatusCode::SUCCESS);
73 }
74 //___________________________________________________________________________
77  if (!dataHeader.isValid()) {
78  return(StatusCode::SUCCESS);
79  }
80  // Retrieve the EventInfo object
81  EventType evtype;
82  unsigned long long runN = 0;
83  unsigned lumiN = 0;
85  if (xEventInfo.isValid()) {
86  runN = xEventInfo->runNumber();
87  lumiN = xEventInfo->lumiBlock();
88  evtype = eventTypeFromxAOD(xEventInfo.get());
89  } else {
91  if (oEventInfo.isValid()) {
92  runN = oEventInfo->event_ID()->run_number();
93  lumiN = oEventInfo->event_ID()->lumi_block();
94  evtype = *oEventInfo->event_type();
95  } else {
96  ATH_MSG_ERROR("Unable to retrieve EventInfo object");
97  return(StatusCode::FAILURE);
98  }
99  }
100 
101  EventStreamInfo* pEventStream = m_metaDataSvc->tryRetrieve<EventStreamInfo>(m_key.value());
102  if( !pEventStream ) {
103  auto esinfo_up = std::make_unique<EventStreamInfo>();
104  pEventStream = esinfo_up.get();
105  if( m_metaDataSvc->record(std::move(esinfo_up), m_key.value()).isFailure() ) {
106  ATH_MSG_ERROR("Could not register EventStreamInfo object");
107  return(StatusCode::FAILURE);
108  }
109  }
110  static std::once_flag resetNumberOfEventsFlag;
111  std::call_once(resetNumberOfEventsFlag, [this, pEventStream]() -> void {
112  ATH_MSG_DEBUG("Resetting the EventStreamInfo payload at the first event");
113  pEventStream->reset();
114  });
115  pEventStream->addEvent();
116  pEventStream->insertProcessingTag(dataHeader->getProcessTag());
117  pEventStream->insertLumiBlockNumber( lumiN );
118  pEventStream->insertRunNumber( runN );
119  for (const DataHeaderElement& dhe : *dataHeader) {
120  pEventStream->insertItemList(dhe.getPrimaryClassID(), dhe.getKey());
121  }
122  pEventStream->insertEventType( evtype );
123 
124  m_eventCounter++;
125 
126  return(StatusCode::SUCCESS);
127 }
128 //___________________________________________________________________________
130  EventStreamInfo* pEventStream = m_metaDataSvc->tryRetrieve<EventStreamInfo>(m_key.value());
131  if (!pEventStream) {
132  auto esinfo_up = std::make_unique<EventStreamInfo>();
133  pEventStream = esinfo_up.get();
134  ATH_CHECK(m_metaDataSvc->record(std::move(esinfo_up), m_key.value()));
135  }
136  if (m_eventCounter > 0 &&
137  m_eventCounter < pEventStream->getNumberOfEvents()) {
138  // The number of events that have been processed by MakeEventStreamInfo
139  // tool is less than the number of events in already existing
140  // EventStreamInfo object. This can happen if the EventStreamInfo object was
141  // updated by CopyEventStreamInfo, for example at beginning of reading the
142  // 2nd (or next) file.
144  "Event count mismatch in EventStreamInfo (likely due to "
145  "multi-file processing). MakeEventStreamInfo processed: "
146  << m_eventCounter << " events, existing EventStreamInfo object has "
147  << pEventStream->getNumberOfEvents()
148  << " events. Setting number of events to what "
149  "MakeEventStreamInfo processed.");
150  pEventStream->setNumberOfEvents(m_eventCounter);
151  } else {
152  // Insert processing tags when no events have been processed
153  pEventStream->insertProcessingTag(m_dataHeaderKey.value());
154  }
155  return (StatusCode::SUCCESS);
156 }
157 //___________________________________________________________________________
159  ATH_MSG_DEBUG("in finalize()");
160  // release the MetaDataStore
161  if (!m_metaDataSvc.release().isSuccess()) {
162  ATH_MSG_WARNING("Could not release MetaDataStore");
163  }
164  if (!m_eventStore.release().isSuccess()) {
165  ATH_MSG_WARNING("Could not release EventStore");
166  }
167  return(StatusCode::SUCCESS);
168 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MakeEventStreamInfo::m_eventStore
ServiceHandle< StoreGateSvc > m_eventStore
Definition: MakeEventStreamInfo.h:62
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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:61
EventStreamInfo::reset
void reset()
Definition: EventStreamInfo.cxx:132
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
MakeEventStreamInfo::m_oEventInfoKey
StringProperty m_oEventInfoKey
Key, the StoreGate key for the old EventInfo object, ix there is no xAOD::EventInfo.
Definition: MakeEventStreamInfo.h:58
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
EventID.h
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
DataHeaderElement
This class provides a persistent form for the TransientAddress.
Definition: DataHeader.h:36
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:65
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:57
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
EventInfo::event_ID
EventID * event_ID()
the unique identification of the event.
Definition: EventInfo/EventInfo/EventInfo.h:224
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:23
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:158
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:228
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:75
MakeEventStreamInfo::preExecute
virtual StatusCode preExecute() override
Called at the beginning of AthenaOutputStream::execute().
Definition: MakeEventStreamInfo.cxx:67
EventInfo.h
MakeEventStreamInfo::~MakeEventStreamInfo
virtual ~MakeEventStreamInfo()
Destructor.
Definition: MakeEventStreamInfo.cxx:29
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DataHeader::getProcessTag
const std::string & getProcessTag() const
Definition: DataHeader.cxx:247
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MakeEventStreamInfo::preFinalize
virtual StatusCode preFinalize() override
Called at the beginning of AthenaOutputStream::finalize().
Definition: MakeEventStreamInfo.cxx:129
MakeEventStreamInfo::preStream
virtual StatusCode preStream() override
Called before actually streaming objects.
Definition: MakeEventStreamInfo.cxx:71
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:32
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
StoreGateSvc.h
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
EventInfo::event_type
EventType * event_type()
the type of the event, e.g. simulation, testbeam, etc
Definition: EventInfo/EventInfo/EventInfo.h:234
MakeEventStreamInfo.h
This file contains the class definition for the MakeEventStreamInfo class.