ATLAS Offline Software
Loading...
Searching...
No Matches
EventTVirtualEvent.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2//
3// File holding the implementation of the xAOD::Event functions that implement
4// the TVirtualEvent interface.
5//
6
7// Local include(s).
9
14
15namespace xAOD {
16
27SG::sgkey_t Event::getHash(const std::string& key) const {
28
29 // For empty keys let's finish quickly.
30 if (key == "") {
31 return 0;
32 }
33
34 // If the key is used in the input file, let's use the same hash for
35 // the output file as well.
36 static constexpr bool QUIET = true;
37 if (const EventFormatElement* efe = m_inputEventFormat.get(key, QUIET)) {
38 return efe->hash();
39 }
40
41 // If it's a new key, make a new hash for it from scratch:
42 return Utils::hash(key);
43}
44
52SG::sgkey_t Event::getKey(const void* obj) const {
53
54 // Make use of the getName function.
55 return getHash(getName(obj));
56}
57
65const std::string& Event::getName(const void* obj) const {
66
67 // Check the active TStore first, its pointer lookup is cheap.
68 const TStore* store = TActiveStore::store();
69 if (store && store->contains(obj)) {
70 return store->getName(obj);
71 }
72
73 // Then look among the output objects.
74 for (const auto& [key, manager] : m_outputObjects) {
75 // Check if this is our object.
76 if (manager->object() == obj) {
77 // If it is, let's return right away.
78 return key;
79 }
80 }
81
82 // Now look among the input objects.
83 for (const auto& [key, manager] : m_inputObjects) {
84 // Check if this is our object.
85 if (manager->object() == obj) {
86 // If it is, let's return.
87 return key;
88 }
89 }
90
91 // We didn't find the object in the event...
92 ATH_MSG_WARNING("Didn't find object with pointer \"" << obj
93 << "\" in the event");
94 static const std::string dummy;
95 return dummy;
96}
97
105const std::string& Event::getName(SG::sgkey_t hash) const {
106
107 // If the branch is known from the input:
108 static constexpr bool QUIET = true;
109 if (const EventFormatElement* efe = m_inputEventFormat.get(hash, QUIET)) {
110 return efe->branchName();
111 }
112
113 // If the branch is known on the output:
114 if (const EventFormatElement* efe =
115 (m_outputEventFormat ? m_outputEventFormat->get(hash, QUIET)
116 : nullptr)) {
117 return efe->branchName();
118 }
119
120 // If this is an object in the active store:
121 const TStore* store = TActiveStore::store();
122 if (store && store->contains(hash)) {
123 return store->getName(hash);
124 }
125
126 // If it is unknown:
127 static const std::string dummy;
128 return dummy;
129}
130
141void* Event::getOutputObject(SG::sgkey_t key, const std::type_info& ti) {
142
143 // Get a string name for this key.
144 const std::string& name = getName(key);
145 if (name.empty()) {
146 return nullptr;
147 }
148
149 // Forward the call to the function using an std::string key.
150 static const bool METADATA = false;
151 return getOutputObject(name, ti, METADATA);
152}
153
165const void* Event::getInputObject(SG::sgkey_t key, const std::type_info& ti,
166 bool silent) {
167
168 // Get a string name for this key:
169 const std::string& name = getName(key);
170 if (name.empty() && (silent == false)) {
171 ATH_MSG_WARNING("Key 0x" << std::hex << key << " unknown");
172 return nullptr;
173 }
174
175 // Forward the call to the function using an std::string key:
176 static const bool METADATA = false;
177 return getInputObject(name, ti, silent, METADATA);
178}
179
180} // namespace xAOD
#define ATH_MSG_WARNING(x,...)
Class describing one branch of the ROOT file.
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.
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.
const std::string & getName(const void *obj) const override
Function returning the key describing a known object.
Object_t m_inputObjects
Collection of all the managed input objects.
Definition Event.h:344
SG::sgkey_t getKey(const void *obj) const override
Function returning the hash describing a known object.
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
SG::sgkey_t getHash(const std::string &key) const override
Function returning the hash describing an object name.
EventFormat * m_outputEventFormat
Format of the current output file.
Definition Event.h:359
Object_t m_outputObjects
Collection of all the managed output object.
Definition Event.h:349
static TStore * store()
Access the currently active TStore object.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:46
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
SG::sgkey_t hash(const std::string &name)
This function provides a hashed version of the key (branch) names used in the xAOD file,...
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.