ATLAS Offline Software
Loading...
Searching...
No Matches
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).
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
23namespace xAOD {
24
27Event::Event(std::string_view name)
28 : TVirtualEvent(),
29 Details::IProxyDictBase(),
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) {
46 }
47#ifndef XAOD_STANDALONE
48 if (SG::CurrentEventStore::store() == this) {
50 }
51#endif // not XAOD_STANDALONE
52}
53
54void 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
71void 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
162StatusCode 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.
167 if (m_inputEventFormat.exists(newName)) {
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
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
250std::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
299
300 // Simply do this via the xAODCore code:
301 IOStats::instance().stats().Print("Summary");
302}
303
304} // 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.
static IProxyDict * store()
Fetch the current store.
static IProxyDict * setStore(IProxyDict *store)
Set the current 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.
Definition EventCore.cxx:97
EventFormat m_inputEventFormat
Format of the current input file.
Definition Event.h:321
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.
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:71
virtual ~Event()
Virtual destructor.
Definition EventCore.cxx:39
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:27
bool m_printEventProxyWarnings
Option to silence common warnings that seem to be harmless.
Definition Event.h:335
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:54
std::unordered_map< std::string, std::string > m_nameRemapping
Container name re-mapping rules.
Definition Event.h:332
std::unordered_map< std::string, std::set< std::string > > m_auxItemList
Rules for selecting which auxiliary branches to write.
Definition Event.h:326
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:323
SG::SGKeyMap< BranchInfo > m_branches ATLAS_THREAD_SAFE
Map from hashed sgkey to BranchInfo.
Definition Event.h:358
void printIOStats() const
Function printing the I/O statistics of the current process.
std::vector< TVirtualIncidentListener * > m_listeners
Listeners who should be notified when certain incidents happen.
Definition Event.h:329
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