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 if (m_inputEventFormat.exists(key)) {
37 return m_inputEventFormat.get(key)->hash();
38 }
39
40 // If it's a new key, make a new hash for it from scratch:
41 return Utils::hash(key);
42}
43
51SG::sgkey_t Event::getKey(const void* obj) const {
52
53 // Make use of the getName function.
54 return getHash(getName(obj));
55}
56
64const std::string& Event::getName(const void* obj) const {
65
66 // First look among the output objects.
67 for (const auto& [key, manager] : m_outputObjects) {
68 // Check if this is our object.
69 if (manager->object() == obj) {
70 // If it is, let's return right away.
71 return key;
72 }
73 }
74
75 // Now look among the input objects.
76 for (const auto& [key, manager] : m_inputObjects) {
77 // Check if this is our object.
78 if (manager->object() == obj) {
79 // If it is, let's return.
80 return key;
81 }
82 }
83
84 // If it's not there either, check if it's in an active TStore object:
85 const TStore* store = TActiveStore::store();
86 if (store && store->contains(obj)) {
87 // Get the name from the store then:
88 return store->getName(obj);
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 if (m_inputEventFormat.exists(hash)) {
109 return m_inputEventFormat.get(hash)->branchName();
110 }
111
112 // If the branch is known on the output:
113 if (m_outputEventFormat && m_outputEventFormat->exists(hash)) {
114 return m_outputEventFormat->get(hash)->branchName();
115 }
116
117 // If this is an object in the active store:
118 const TStore* store = TActiveStore::store();
119 if (store && store->contains(hash)) {
120 return store->getName(hash);
121 }
122
123 // If it is unknown:
124 static const std::string dummy;
125 return dummy;
126}
127
138void* Event::getOutputObject(SG::sgkey_t key, const std::type_info& ti) {
139
140 // Get a string name for this key.
141 const std::string& name = getName(key);
142 if (name.empty()) {
143 return nullptr;
144 }
145
146 // Forward the call to the function using an std::string key.
147 static const bool METADATA = false;
148 return getOutputObject(name, ti, METADATA);
149}
150
162const void* Event::getInputObject(SG::sgkey_t key, const std::type_info& ti,
163 bool silent) {
164
165 // Get a string name for this key:
166 const std::string& name = getName(key);
167 if (name.empty() && (silent == false)) {
168 ATH_MSG_WARNING("Key 0x" << std::hex << key << " unknown");
169 return nullptr;
170 }
171
172 // Forward the call to the function using an std::string key:
173 static const bool METADATA = false;
174 return getInputObject(name, ti, silent, METADATA);
175}
176
177} // namespace xAOD
#define ATH_MSG_WARNING(x)
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.
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:308
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:323
Object_t m_outputObjects
Collection of all the managed output object.
Definition Event.h:313
static TStore * store()
Access the currently active TStore object.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
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.