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
15#endif // not XAOD_STANDALONE
16
17// ROOT include(s).
18#include <TClass.h>
19
20// System include(s).
21#include <iomanip>
22#include <sstream>
23
24namespace xAOD {
25
28Event::Event(std::string_view name,
29 [[maybe_unused]] const EventContext* ctx /* = nullptr*/)
30 : TVirtualEvent(),
31 Details::IProxyDictBase(),
33
34 // Make sure that the I/O monitoring is active.
36
37 if (ctx) {
38#ifndef XAOD_STANDALONE
39 m_ctx = *ctx;
40#endif
41 }
42 else {
43 // Make this the active event.
44 this->setActive();
45 }
46}
47
49
50 // If this is set up as the active event at the moment, notify
51 // the active event object that this object will no longer be
52 // available.
53 if (TActiveEvent::event() == this) {
55 }
56#ifndef XAOD_STANDALONE
59 }
60#endif // not XAOD_STANDALONE
61}
62
63void Event::setActive() const {
64
65 // The active event and current store are thread-local globals.
66 Event* nc_this ATLAS_THREAD_SAFE = const_cast<Event*>(this);
67 TActiveEvent::setEvent(static_cast<TVirtualEvent*>(nc_this));
68#ifndef XAOD_STANDALONE
70#endif // not XAOD_STANDALONE
71}
72
80void Event::setAuxItemList(const std::string& containerKey,
81 const std::string& itemList) {
82
83 // Decoded attributes.
84 std::set<std::string> attributes;
85
86 // Split up the received string using "." as the separator.
87 if (itemList.size()) {
88 std::istringstream ss(itemList);
89 std::string attr;
90 while (std::getline(ss, attr, '.')) {
91 attributes.insert(attr);
92 }
93 }
94
95 // Remember the setting.
96 m_auxItemList[containerKey] = std::move(attributes);
97}
98
107
108 // Check that we received a valid pointer:
109 if (listener == nullptr) {
110 ATH_MSG_ERROR("Received a null pointer for the listener");
111 return StatusCode::FAILURE;
112 }
113
114 // Check whether we already have this listener.
115 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
116 if (itr != m_listeners.end()) {
117 ATH_MSG_WARNING("Listener " << static_cast<void*>(listener)
118 << " is already registered");
119 return StatusCode::SUCCESS;
120 }
121
122 // Add the listener.
123 m_listeners.push_back(listener);
124
125 // Return gracefully:
126 return StatusCode::SUCCESS;
127}
128
136
137 // Remove the listener. Or at least try to...
138 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
139 if (itr == m_listeners.end()) {
140 ATH_MSG_ERROR("Listener " << static_cast<void*>(listener) << " not known");
141 return StatusCode::FAILURE;
142 }
143 m_listeners.erase(itr);
144
145 // Return gracefully:
146 return StatusCode::SUCCESS;
147}
148
153
154 m_listeners.clear();
155}
156
171StatusCode Event::addNameRemap(const std::string& onfile,
172 const std::string& newName) {
173
174 // Check if this name is known on the input or output already. As that's
175 // not good.
176 if (m_inputEventFormat.exists(newName)) {
177 ATH_MSG_ERROR("Can't use \"" << newName << "\" as the target name in the \""
178 << onfile << "\" -> \"" << newName
179 << "\" remapping");
180 return StatusCode::FAILURE;
181 }
182
183 // Check if this name was remapped to something already.
184 auto itr = m_nameRemapping.find(newName);
185 if (itr != m_nameRemapping.end()) {
186 ATH_MSG_WARNING("Overriding existing name remapping \""
187 << itr->second << "\" -> \"" << itr->first << "\" with: \""
188 << onfile << "\" -> \"" << newName << "\"");
189 }
190
192 m_nameRemapping[newName] = onfile;
193
194 // Return gracefully:
195 return StatusCode::SUCCESS;
196}
197
203
204 m_nameRemapping.clear();
205}
206
211
212 // Print a header.
213 ATH_MSG_INFO("Name remapping rules:");
214
215 // In case no remapping rules have been set.
216 if (m_nameRemapping.empty()) {
217 ATH_MSG_INFO(" NONE");
218 return;
219 }
220
221 // Otherwise.
222 for (const auto& [newName, onfile] : m_nameRemapping) {
223 ATH_MSG_INFO(" \"" << newName << "\" -> \"" << onfile << "\"");
224 }
225}
226
233
235}
236
238
239 if (hasInput()) {
240 return &m_inputEventFormat;
241 }
242 return nullptr;
243}
244
246
247 return m_outputEventFormat;
248}
249
259std::string Event::dump() {
260
261 // The internal stream object.
262 std::ostringstream ost;
263 ost << "<<<<<<<<<<<<<<<<<<<< xAOD::TEvent Dump >>>>>>>>>>>>>>>>>>>>\n";
264
265 // Loop over the input EventFormat object.
266 for (const auto& [key, element] : m_inputEventFormat) {
267
268 // Get the type.
269 ::TClass* cl = ::TClass::GetClass(element.className().c_str());
270 const std::type_info* ti = (cl ? cl->GetTypeInfo() : nullptr);
271 if ((cl == nullptr) || (cl->IsLoaded() == false) || (ti == nullptr)) {
272 ATH_MSG_WARNING("Unknown type (" << element.className()
273 << ") found in the event format");
274 continue;
275 }
276
277 // Skip containers that are not available anyway.
278 static const bool METADATA = false;
279 if (!contains(element.branchName(), *ti, METADATA)) {
280 continue;
281 }
282
283 // Do the printout.
284 ost << " Hash: 0x" << std::setw(8) << std::setfill('0') << std::hex
285 << element.hash() << " Key: \"" << element.branchName() << "\"\n";
286
287 ost << " type: " << element.className() << "\n";
288 const bool isNonConst =
289 transientContains(element.branchName(), *ti, METADATA);
290 ost << " isConst: " << (isNonConst ? "No" : "Yes") << "\n";
291 static const bool SILENT = false;
292 ost << " Data: "
293 << (isNonConst
294 ? getOutputObject(element.branchName(), *ti, METADATA)
295 : getInputObject(element.branchName(), *ti, SILENT, METADATA))
296 << "\n";
297 }
298
299 // Finish with the construction:
300 ost << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
301 return ost.str();
302}
303
308
309 // Simply do this via the xAODCore code:
310 IOStats::instance().stats().Print("Summary");
311}
312
313const EventContext& Event::currentContext() const {
314#ifdef XAOD_STANDALONE
315 return Gaudi::Hive::currentContext();
316#else
317 return m_ctx;
318#endif
319}
320
321} // namespace xAOD
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
static Double_t ss
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:361
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:414
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.
Event(std::string_view name, const EventContext *ctx=nullptr)
Constructor with a name.
Definition EventCore.cxx:28
void setAuxItemList(const std::string &containerKey, const std::string &itemList)
Configure which dynamic variables to write out for a given store.
Definition EventCore.cxx:80
virtual ~Event()
Virtual destructor.
Definition EventCore.cxx:48
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.
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition Event.h:375
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:63
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition Event.h:372
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:366
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:363
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:398
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:369
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.
void setProxyDictInEventContext(IProxyDict *sg)
Update the IProxyDict in the current EventContext.
IProxyDict * proxyDictFromEventContext()
Return the IProxyDict for this thread's current context.
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
Some out-of-line helpers for ExtendedEventContext.