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 [[maybe_unused]] const EventContext* ctx /* = nullptr*/)
31 : TVirtualEvent(),
32 Details::IProxyDictBase(),
34
35 // Make sure that the I/O monitoring is active.
37
38 if (ctx) {
39#ifndef XAOD_STANDALONE
40 m_ctx = *ctx;
41#endif
42 }
43 else {
44 // Make this the active event.
45 this->setActive();
46 }
47}
48
50
51 // If this is set up as the active event at the moment, notify
52 // the active event object that this object will no longer be
53 // available.
54 if (TActiveEvent::event() == this) {
56 }
57#ifndef XAOD_STANDALONE
59 SG::CurrentEventStore::setStore(nullptr);
61 }
62#endif // not XAOD_STANDALONE
63}
64
65void Event::setActive() const {
66
67 // The active event and current store are thread-local globals.
68 Event* nc_this ATLAS_THREAD_SAFE = const_cast<Event*>(this);
69 TActiveEvent::setEvent(static_cast<TVirtualEvent*>(nc_this));
70#ifndef XAOD_STANDALONE
71 SG::CurrentEventStore::setStore(nc_this);
73#endif // not XAOD_STANDALONE
74}
75
83void Event::setAuxItemList(const std::string& containerKey,
84 const std::string& itemList) {
85
86 // Decoded attributes.
87 std::set<std::string> attributes;
88
89 // Split up the received string using "." as the separator.
90 if (itemList.size()) {
91 std::istringstream ss(itemList);
92 std::string attr;
93 while (std::getline(ss, attr, '.')) {
94 attributes.insert(attr);
95 }
96 }
97
98 // Remember the setting.
99 m_auxItemList[containerKey] = std::move(attributes);
100}
101
110
111 // Check that we received a valid pointer:
112 if (listener == nullptr) {
113 ATH_MSG_ERROR("Received a null pointer for the listener");
114 return StatusCode::FAILURE;
115 }
116
117 // Check whether we already have this listener.
118 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
119 if (itr != m_listeners.end()) {
120 ATH_MSG_WARNING("Listener " << static_cast<void*>(listener)
121 << " is already registered");
122 return StatusCode::SUCCESS;
123 }
124
125 // Add the listener.
126 m_listeners.push_back(listener);
127
128 // Return gracefully:
129 return StatusCode::SUCCESS;
130}
131
139
140 // Remove the listener. Or at least try to...
141 auto itr = std::find(m_listeners.begin(), m_listeners.end(), listener);
142 if (itr == m_listeners.end()) {
143 ATH_MSG_ERROR("Listener " << static_cast<void*>(listener) << " not known");
144 return StatusCode::FAILURE;
145 }
146 m_listeners.erase(itr);
147
148 // Return gracefully:
149 return StatusCode::SUCCESS;
150}
151
156
157 m_listeners.clear();
158}
159
174StatusCode Event::addNameRemap(const std::string& onfile,
175 const std::string& newName) {
176
177 // Check if this name is known on the input or output already. As that's
178 // not good.
179 if (m_inputEventFormat.exists(newName)) {
180 ATH_MSG_ERROR("Can't use \"" << newName << "\" as the target name in the \""
181 << onfile << "\" -> \"" << newName
182 << "\" remapping");
183 return StatusCode::FAILURE;
184 }
185
186 // Check if this name was remapped to something already.
187 auto itr = m_nameRemapping.find(newName);
188 if (itr != m_nameRemapping.end()) {
189 ATH_MSG_WARNING("Overriding existing name remapping \""
190 << itr->second << "\" -> \"" << itr->first << "\" with: \""
191 << onfile << "\" -> \"" << newName << "\"");
192 }
193
195 m_nameRemapping[newName] = onfile;
196
197 // Return gracefully:
198 return StatusCode::SUCCESS;
199}
200
206
207 m_nameRemapping.clear();
208}
209
214
215 // Print a header.
216 ATH_MSG_INFO("Name remapping rules:");
217
218 // In case no remapping rules have been set.
219 if (m_nameRemapping.empty()) {
220 ATH_MSG_INFO(" NONE");
221 return;
222 }
223
224 // Otherwise.
225 for (const auto& [newName, onfile] : m_nameRemapping) {
226 ATH_MSG_INFO(" \"" << newName << "\" -> \"" << onfile << "\"");
227 }
228}
229
236
238}
239
241
242 if (hasInput()) {
243 return &m_inputEventFormat;
244 }
245 return nullptr;
246}
247
249
250 return m_outputEventFormat;
251}
252
262std::string Event::dump() {
263
264 // The internal stream object.
265 std::ostringstream ost;
266 ost << "<<<<<<<<<<<<<<<<<<<< xAOD::TEvent Dump >>>>>>>>>>>>>>>>>>>>\n";
267
268 // Loop over the input EventFormat object.
269 for (const auto& [key, element] : m_inputEventFormat) {
270
271 // Get the type.
272 ::TClass* cl = ::TClass::GetClass(element.className().c_str());
273 const std::type_info* ti = (cl ? cl->GetTypeInfo() : nullptr);
274 if ((cl == nullptr) || (cl->IsLoaded() == false) || (ti == nullptr)) {
275 ATH_MSG_WARNING("Unknown type (" << element.className()
276 << ") found in the event format");
277 continue;
278 }
279
280 // Skip containers that are not available anyway.
281 static const bool METADATA = false;
282 if (!contains(element.branchName(), *ti, METADATA)) {
283 continue;
284 }
285
286 // Do the printout.
287 ost << " Hash: 0x" << std::setw(8) << std::setfill('0') << std::hex
288 << element.hash() << " Key: \"" << element.branchName() << "\"\n";
289
290 ost << " type: " << element.className() << "\n";
291 const bool isNonConst =
292 transientContains(element.branchName(), *ti, METADATA);
293 ost << " isConst: " << (isNonConst ? "No" : "Yes") << "\n";
294 static const bool SILENT = false;
295 ost << " Data: "
296 << (isNonConst
297 ? getOutputObject(element.branchName(), *ti, METADATA)
298 : getInputObject(element.branchName(), *ti, SILENT, METADATA))
299 << "\n";
300 }
301
302 // Finish with the construction:
303 ost << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
304 return ost.str();
305}
306
311
312 // Simply do this via the xAODCore code:
313 IOStats::instance().stats().Print("Summary");
314}
315
316const EventContext& Event::currentContext() const {
317#ifdef XAOD_STANDALONE
318 return Gaudi::Hive::currentContext();
319#else
320 return m_ctx;
321#endif
322}
323
324} // namespace xAOD
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Hold a pointer to the current event store.
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:357
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:410
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:29
void setAuxItemList(const std::string &containerKey, const std::string &itemList)
Configure which dynamic variables to write out for a given store.
Definition EventCore.cxx:83
virtual ~Event()
Virtual destructor.
Definition EventCore.cxx:49
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:371
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:65
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition Event.h:368
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:362
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:359
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:394
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:365
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.