ATLAS Offline Software
EventCore.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 // Local include(s).
4 #include "xAODRootAccess/Event.h"
7 
8 // Project include(s).
12 #ifndef XAOD_STANDALONE
14 #endif // not XAOD_STANDALONE
15 
16 // ROOT include(s).
17 #include <TClass.h>
18 
19 // System include(s).
20 #include <iomanip>
21 #include <sstream>
22 
23 namespace xAOD {
24 
27 Event::Event(std::string_view name)
28  : TVirtualEvent(),
29  Details::IProxyDictBase(),
30  asg::AsgMessaging(std::string{name}) {
31 
32  // Make sure that the I/O monitoring is active.
34 
35  // Make this the active event.
36  setActive();
37 }
38 
40 
41  // If this is set up as the active event at the moment, notify
42  // the active event object that this object will no longer be
43  // available.
44  if (TActiveEvent::event() == this) {
45  TActiveEvent::setEvent(nullptr);
46  }
47 #ifndef XAOD_STANDALONE
48  if (SG::CurrentEventStore::store() == this) {
50  }
51 #endif // not XAOD_STANDALONE
52 }
53 
54 void Event::setActive() const {
55 
56  // The active event and current store are thread-local globals.
57  Event* nc_this ATLAS_THREAD_SAFE = const_cast<Event*>(this);
58  TActiveEvent::setEvent(static_cast<TVirtualEvent*>(nc_this));
59 #ifndef XAOD_STANDALONE
61 #endif // not XAOD_STANDALONE
62 }
63 
71 void Event::setAuxItemList(const std::string& containerKey,
72  const std::string& itemList) {
73 
74  // Decoded attributes.
75  std::set<std::string> attributes;
76 
77  // Split up the received string using "." as the separator.
78  if (itemList.size()) {
79  std::istringstream ss(itemList);
80  std::string attr;
81  while (std::getline(ss, attr, '.')) {
82  attributes.insert(attr);
83  }
84  }
85 
86  // Remember the setting.
87  m_auxItemList[containerKey] = std::move(attributes);
88 }
89 
98 
99  // Check that we received a valid pointer:
100  if (listener == nullptr) {
101  ATH_MSG_ERROR("Received a null pointer for the listener");
102  return StatusCode::FAILURE;
103  }
104 
105  // Check whether we already have this listener.
106  auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
107  if (itr != m_listeners.end()) {
108  ATH_MSG_WARNING("Listener " << static_cast<void*>(listener)
109  << " is already registered");
110  return StatusCode::SUCCESS;
111  }
112 
113  // Add the listener.
114  m_listeners.push_back(listener);
115 
116  // Return gracefully:
117  return StatusCode::SUCCESS;
118 }
119 
127 
128  // Remove the listener. Or at least try to...
129  auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
130  if (itr == m_listeners.end()) {
131  ATH_MSG_ERROR("Listener " << static_cast<void*>(listener) << " not known");
132  return StatusCode::FAILURE;
133  }
134  m_listeners.erase(itr);
135 
136  // Return gracefully:
137  return StatusCode::SUCCESS;
138 }
139 
144 
145  m_listeners.clear();
146 }
147 
162 StatusCode Event::addNameRemap(const std::string& onfile,
163  const std::string& newName) {
164 
165  // Check if this name is known on the input or output already. As that's
166  // not good.
168  ATH_MSG_ERROR("Can't use \"" << newName << "\" as the target name in the \""
169  << onfile << "\" -> \"" << newName
170  << "\" remapping");
171  return StatusCode::FAILURE;
172  }
173 
174  // Check if this name was remapped to something already.
175  auto itr = m_nameRemapping.find(newName);
176  if (itr != m_nameRemapping.end()) {
177  ATH_MSG_WARNING("Overriding existing name remapping \""
178  << itr->second << "\" -> \"" << itr->first << "\" with: \""
179  << onfile << "\" -> \"" << newName << "\"");
180  }
181 
183  m_nameRemapping[newName] = onfile;
184 
185  // Return gracefully:
186  return StatusCode::SUCCESS;
187 }
188 
194 
195  m_nameRemapping.clear();
196 }
197 
201 void Event::printNameRemap() const {
202 
203  // Print a header.
204  ATH_MSG_INFO("Name remapping rules:");
205 
206  // In case no remapping rules have been set.
207  if (m_nameRemapping.empty()) {
208  ATH_MSG_INFO(" NONE");
209  return;
210  }
211 
212  // Otherwise.
213  for (const auto& [newName, onfile] : m_nameRemapping) {
214  ATH_MSG_INFO(" \"" << newName << "\" -> \"" << onfile << "\"");
215  }
216 }
217 
224 
226 }
227 
229 
230  if (hasInput()) {
231  return &m_inputEventFormat;
232  }
233  return nullptr;
234 }
235 
237 
238  return m_outputEventFormat;
239 }
240 
250 std::string Event::dump() {
251 
252  // The internal stream object.
253  std::ostringstream ost;
254  ost << "<<<<<<<<<<<<<<<<<<<< xAOD::TEvent Dump >>>>>>>>>>>>>>>>>>>>\n";
255 
256  // Loop over the input EventFormat object.
257  for (const auto& [key, element] : m_inputEventFormat) {
258 
259  // Get the type.
260  ::TClass* cl = ::TClass::GetClass(element.className().c_str());
261  const std::type_info* ti = (cl ? cl->GetTypeInfo() : nullptr);
262  if ((cl == nullptr) || (cl->IsLoaded() == false) || (ti == nullptr)) {
263  ATH_MSG_WARNING("Unknown type (" << element.className()
264  << ") found in the event format");
265  continue;
266  }
267 
268  // Skip containers that are not available anyway.
269  static const bool METADATA = false;
270  if (!contains(element.branchName(), *ti, METADATA)) {
271  continue;
272  }
273 
274  // Do the printout.
275  ost << " Hash: 0x" << std::setw(8) << std::setfill('0') << std::hex
276  << element.hash() << " Key: \"" << element.branchName() << "\"\n";
277 
278  ost << " type: " << element.className() << "\n";
279  const bool isNonConst =
280  transientContains(element.branchName(), *ti, METADATA);
281  ost << " isConst: " << (isNonConst ? "No" : "Yes") << "\n";
282  static const bool SILENT = false;
283  ost << " Data: "
284  << (isNonConst
285  ? getOutputObject(element.branchName(), *ti, METADATA)
286  : getInputObject(element.branchName(), *ti, SILENT, METADATA))
287  << "\n";
288  }
289 
290  // Finish with the construction:
291  ost << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
292  return ost.str();
293 }
294 
298 void Event::printIOStats() const {
299 
300  // Simply do this via the xAODCore code:
301  IOStats::instance().stats().Print("Summary");
302 }
303 
304 } // namespace xAOD
xAOD::TVirtualEvent
Base interface for getting objects out of the input file.
Definition: TVirtualEvent.h:26
CurrentEventStore.h
Hold a pointer to the current event store.
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
xAOD::Event::clearListeners
void clearListeners()
Remove all listeners from the object.
Definition: EventCore.cxx:143
xAOD::Event::ATLAS_THREAD_SAFE
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition: Event.h:358
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
xAOD::Event::name
const std::string & name() const override
Get the name of the instance.
Definition: EventIProxyDict.cxx:313
xAOD::TActiveEvent::setEvent
static void setEvent(TVirtualEvent *ptr)
Set the active event pointer.
Definition: TActiveEvent.cxx:21
xAOD::Event::m_inputEventFormat
EventFormat m_inputEventFormat
Format of the current input file.
Definition: Event.h:321
xAOD::Event::setActive
void setActive() const
Set this event object as the currently active one.
Definition: EventCore.cxx:54
xAOD::Event::Event
Event(std::string_view name)
Constructor with a name.
Definition: EventCore.cxx:27
xAOD::ReadStats::Print
void Print(::Option_t *option="") const
Print information about the collected statistics.
asg
Definition: DataHandleTestTool.h:28
SG::CurrentEventStore::setStore
static IProxyDict * setStore(IProxyDict *store)
Set the current store.
Definition: CurrentEventStore.cxx:36
athena.value
value
Definition: athena.py:124
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
SG::CurrentEventStore::store
static IProxyDict * store()
Fetch the current store.
xAOD::TVirtualIncidentListener
Class providing an interface for classes listening to xAOD incidents.
Definition: TVirtualIncidentListener.h:25
xAOD::Event::m_nameRemapping
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition: Event.h:332
IOStats.h
TVirtualIncidentListener.h
xAOD::Event::removeListener
StatusCode removeListener(TVirtualIncidentListener *listener)
Remove an incident listener object.
Definition: EventCore.cxx:126
xAOD::Event::m_listeners
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Definition: Event.h:329
PerfStats.h
xAOD::TActiveEvent::event
static TVirtualEvent * event()
Access the currently active TVirtualEvent object.
Definition: TActiveEvent.cxx:16
xAOD::Event::m_printEventProxyWarnings
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition: Event.h:335
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::Event::m_auxItemList
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition: Event.h:326
xAOD::Event::inputEventFormat
const EventFormat * inputEventFormat() const
Get information about the input objects.
Definition: EventCore.cxx:228
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
vertexingJO_ITK_init.itemList
list itemList
Definition: vertexingJO_ITK_init.py:95
xAOD::Event::getOutputObject
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
Definition: EventTVirtualEvent.cxx:138
xAOD::Event::printIOStats
void printIOStats() const
Function printing the I/O statistics of the current process.
Definition: EventCore.cxx:298
xAOD::Event::printProxyWarnings
void printProxyWarnings(bool value=true)
Enable warnings associated with broken element links.
Definition: EventCore.cxx:223
xAOD::Event::addNameRemap
StatusCode addNameRemap(const std::string &onfile, const std::string &newName)
Add a name re-mapping rule.
Definition: EventCore.cxx:162
Event.h
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
xAOD::Details::IProxyDictBase
implements< IProxyDict > IProxyDictBase
IProxyDict base class to use in a specific build environment
Definition: Event.h:39
xAOD::Event::getInputObject
const void * getInputObject(SG::sgkey_t key, const std::type_info &ti, bool silent) override
Function for retrieving an input object in a non-template way.
Definition: EventTVirtualEvent.cxx:162
xAOD::Event::hasInput
virtual bool hasInput() const =0
Check if an input file is connected to the object.
xAOD::Event::clearNameRemap
void clearNameRemap()
Clear the current name re-mapping.
Definition: EventCore.cxx:193
TActiveEvent.h
xAOD::EventFormat_v1
Event format metadata for xAOD files.
Definition: EventFormat_v1.h:38
xAOD::Event::printNameRemap
void printNameRemap() const
Print the current name re-mapping rules.
Definition: EventCore.cxx:201
MakeNewFileFromOldAndSubstitution.newName
dictionary newName
Definition: ICHEP2016/MakeNewFileFromOldAndSubstitution.py:95
TVirtualManager.h
xAOD::PerfStats::instance
static PerfStats & instance()
Function accessing the singleton instance.
xAOD::Event::contains
bool contains(const std::string &key)
Function checking if an object is available from the store.
xAOD::Event::~Event
virtual ~Event()
Virtual destructor.
Definition: EventCore.cxx:39
xAOD::Event::addListener
StatusCode addListener(TVirtualIncidentListener *listener)
Register an incident listener object.
Definition: EventCore.cxx:97
xAOD::Event::m_outputEventFormat
EventFormat * m_outputEventFormat
Format of the current output file.
Definition: Event.h:323
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::Event::dump
std::string dump()
Function creating a user-readable dump of the current input.
Definition: EventCore.cxx:250
xAOD::Event::setAuxItemList
void setAuxItemList(const std::string &containerKey, const std::string &itemList)
Configure which dynamic variables to write out for a given store.
Definition: EventCore.cxx:71
xAOD::Event
Base class for the event (xAOD::TEvent and xAOD::REvent) classes.
Definition: Event.h:59
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:25
python.TransformConfig.attributes
def attributes(self)
Definition: TransformConfig.py:383
xAOD::Event::outputEventFormat
const EventFormat * outputEventFormat() const
Get information about the output objects.
Definition: EventCore.cxx:236
xAOD::Event::transientContains
bool transientContains(const std::string &key) const
Function checking if an object is already in memory.
xAOD::EventFormat_v1::exists
bool exists(const std::string &key) const
Check if a description exists about a given branch.
Definition: EventFormat_v1.cxx:65
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37