ATLAS Offline Software
Loading...
Searching...
No Matches
EventCore.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3// Local include(s).
7
8// Project include(s).
13#ifndef XAOD_STANDALONE
16#endif // not XAOD_STANDALONE
17
18// ROOT include(s).
19#include <TClass.h>
20
21// System include(s).
22#include <iomanip>
23#include <sstream>
24
25namespace xAOD {
26
29Event::Event(std::string_view name)
30 : TVirtualEvent(),
31 Details::IProxyDictBase(),
33
34 // Make sure that the I/O monitoring is active.
36
37 // Make this the active event.
38 setActive();
39
40#ifndef XAOD_STANDALONE
42 m_ctx.setExtension( Atlas::ExtendedEventContext( this ) );
43#endif
44}
45
47
48 // If this is set up as the active event at the moment, notify
49 // the active event object that this object will no longer be
50 // available.
51 if (TActiveEvent::event() == this) {
53 }
54#ifndef XAOD_STANDALONE
55 if (SG::CurrentEventStore::store() == this) {
56 SG::CurrentEventStore::setStore(nullptr);
57 }
58#endif // not XAOD_STANDALONE
59}
60
61void Event::setActive() const {
62
63 // The active event and current store are thread-local globals.
64 Event* nc_this ATLAS_THREAD_SAFE = const_cast<Event*>(this);
65 TActiveEvent::setEvent(static_cast<TVirtualEvent*>(nc_this));
66#ifndef XAOD_STANDALONE
67 SG::CurrentEventStore::setStore(nc_this);
68#endif // not XAOD_STANDALONE
69}
70
78void Event::setAuxItemList(const std::string& containerKey,
79 const std::string& itemList) {
80
81 // Decoded attributes.
82 std::set<std::string> attributes;
83
84 // Split up the received string using "." as the separator.
85 if (itemList.size()) {
86 std::istringstream ss(itemList);
87 std::string attr;
88 while (std::getline(ss, attr, '.')) {
89 attributes.insert(attr);
90 }
91 }
92
93 // Remember the setting.
94 m_auxItemList[containerKey] = std::move(attributes);
95}
96
105
106 // Check that we received a valid pointer:
107 if (listener == nullptr) {
108 ATH_MSG_ERROR("Received a null pointer for the listener");
109 return StatusCode::FAILURE;
110 }
111
112 // Check whether we already have this listener.
113 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
114 if (itr != m_listeners.end()) {
115 ATH_MSG_WARNING("Listener " << static_cast<void*>(listener)
116 << " is already registered");
117 return StatusCode::SUCCESS;
118 }
119
120 // Add the listener.
121 m_listeners.push_back(listener);
122
123 // Return gracefully:
124 return StatusCode::SUCCESS;
125}
126
134
135 // Remove the listener. Or at least try to...
136 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
137 if (itr == m_listeners.end()) {
138 ATH_MSG_ERROR("Listener " << static_cast<void*>(listener) << " not known");
139 return StatusCode::FAILURE;
140 }
141 m_listeners.erase(itr);
142
143 // Return gracefully:
144 return StatusCode::SUCCESS;
145}
146
151
152 m_listeners.clear();
153}
154
169StatusCode Event::addNameRemap(const std::string& onfile,
170 const std::string& newName) {
171
172 // Check if this name is known on the input or output already. As that's
173 // not good.
174 if (m_inputEventFormat.exists(newName)) {
175 ATH_MSG_ERROR("Can't use \"" << newName << "\" as the target name in the \""
176 << onfile << "\" -> \"" << newName
177 << "\" remapping");
178 return StatusCode::FAILURE;
179 }
180
181 // Check if this name was remapped to something already.
182 auto itr = m_nameRemapping.find(newName);
183 if (itr != m_nameRemapping.end()) {
184 ATH_MSG_WARNING("Overriding existing name remapping \""
185 << itr->second << "\" -> \"" << itr->first << "\" with: \""
186 << onfile << "\" -> \"" << newName << "\"");
187 }
188
190 m_nameRemapping[newName] = onfile;
191
192 // Return gracefully:
193 return StatusCode::SUCCESS;
194}
195
201
202 m_nameRemapping.clear();
203}
204
209
210 // Print a header.
211 ATH_MSG_INFO("Name remapping rules:");
212
213 // In case no remapping rules have been set.
214 if (m_nameRemapping.empty()) {
215 ATH_MSG_INFO(" NONE");
216 return;
217 }
218
219 // Otherwise.
220 for (const auto& [newName, onfile] : m_nameRemapping) {
221 ATH_MSG_INFO(" \"" << newName << "\" -> \"" << onfile << "\"");
222 }
223}
224
231
233}
234
236
237 if (hasInput()) {
238 return &m_inputEventFormat;
239 }
240 return nullptr;
241}
242
244
245 return m_outputEventFormat;
246}
247
257std::string Event::dump() {
258
259 // The internal stream object.
260 std::ostringstream ost;
261 ost << "<<<<<<<<<<<<<<<<<<<< xAOD::TEvent Dump >>>>>>>>>>>>>>>>>>>>\n";
262
263 // Loop over the input EventFormat object.
264 for (const auto& [key, element] : m_inputEventFormat) {
265
266 // Get the type.
267 ::TClass* cl = ::TClass::GetClass(element.className().c_str());
268 const std::type_info* ti = (cl ? cl->GetTypeInfo() : nullptr);
269 if ((cl == nullptr) || (cl->IsLoaded() == false) || (ti == nullptr)) {
270 ATH_MSG_WARNING("Unknown type (" << element.className()
271 << ") found in the event format");
272 continue;
273 }
274
275 // Skip containers that are not available anyway.
276 static const bool METADATA = false;
277 if (!contains(element.branchName(), *ti, METADATA)) {
278 continue;
279 }
280
281 // Do the printout.
282 ost << " Hash: 0x" << std::setw(8) << std::setfill('0') << std::hex
283 << element.hash() << " Key: \"" << element.branchName() << "\"\n";
284
285 ost << " type: " << element.className() << "\n";
286 const bool isNonConst =
287 transientContains(element.branchName(), *ti, METADATA);
288 ost << " isConst: " << (isNonConst ? "No" : "Yes") << "\n";
289 static const bool SILENT = false;
290 ost << " Data: "
291 << (isNonConst
292 ? getOutputObject(element.branchName(), *ti, METADATA)
293 : getInputObject(element.branchName(), *ti, SILENT, METADATA))
294 << "\n";
295 }
296
297 // Finish with the construction:
298 ost << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
299 return ost.str();
300}
301
306
307 // Simply do this via the xAODCore code:
308 IOStats::instance().stats().Print("Summary");
309}
310
311const EventContext& Event::currentContext() const {
312#ifdef XAOD_STANDALONE
313 return Gaudi::Hive::currentContext();
314#else
315 return m_ctx;
316#endif
317}
318
319} // namespace xAOD
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
static Double_t ss
Hold a pointer to the current event store.
AsgMessaging(const std::string &name)
Constructor with a name.
STL class.
StatusCode removeListener(TVirtualIncidentListener *listener)
Remove an incident listener object.
virtual bool hasInput() const =0
Check if an input file is connected to the object.
StatusCode addListener(TVirtualIncidentListener *listener)
Register an incident listener object.
EventFormat m_inputEventFormat
Format of the current input file.
Definition Event.h:355
const std::string & name() const override
Get the name of the instance.
bool transientContains(const std::string &key) const
Function checking if an object is already in memory.
const EventFormat * outputEventFormat() const
Get information about the output objects.
EventContext m_ctx
The event context associated with this event.
Definition Event.h:408
void clearListeners()
Remove all listeners from the object.
void clearNameRemap()
Clear the current name re-mapping.
const EventFormat * inputEventFormat() const
Get information about the input objects.
bool contains(const std::string &key)
Function checking if an object is available from the store.
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.
StatusCode addNameRemap(const std::string &onfile, const std::string &newName)
Add a name re-mapping rule.
void setAuxItemList(const std::string &containerKey, const std::string &itemList)
Configure which dynamic variables to write out for a given store.
Definition EventCore.cxx:78
virtual ~Event()
Virtual destructor.
Definition EventCore.cxx:46
std::string dump()
Function creating a user-readable dump of the current input.
void printProxyWarnings(bool value=true)
Enable warnings associated with broken element links.
Event(std::string_view name)
Constructor with a name.
Definition EventCore.cxx:29
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition Event.h:369
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
void printNameRemap() const
Print the current name re-mapping rules.
void setActive() const
Set this event object as the currently active one.
Definition EventCore.cxx:61
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition Event.h:366
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:360
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:357
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:392
void printIOStats() const
Function printing the I/O statistics of the current process.
const EventContext & currentContext() const
Return the event context corresponding to this event.
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Definition Event.h:363
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
static PerfStats & instance()
Function accessing the singleton instance.
void Print(::Option_t *option="") const
Print information about the collected statistics.
static void setEvent(TVirtualEvent *ptr)
Set the active event pointer.
static TVirtualEvent * event()
Access the currently active TVirtualEvent object.
Base interface for getting objects out of the input file.
Class providing an interface for classes listening to xAOD incidents.
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition EventFormat.h:16