ATLAS Offline Software
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).
8 #include "xAODRootAccess/Event.h"
9 
11 #include "xAODRootAccess/TStore.h"
14 
15 namespace xAOD {
16 
27 SG::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.
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 
51 SG::sgkey_t Event::getKey(const void* obj) const {
52 
53  // Make use of the getName function.
54  return getHash(getName(obj));
55 }
56 
64 const 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 
105 const std::string& Event::getName(SG::sgkey_t hash) const {
106 
107  // If the branch is known from the input:
110  }
111 
112  // If the branch is known on the output:
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 
138 void* 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 
162 const 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
SGTest::store
TestStore store
Definition: TestStore.cxx:23
xAOD::EventFormat_v1::get
const EventFormatElement * get(const std::string &key, bool quiet=false) const
Get the description of a given branch.
Definition: EventFormat_v1.cxx:91
xAOD::Event::name
const std::string & name() const override
Get the name of the instance.
Definition: EventIProxyDict.cxx:313
xAOD::Event::m_inputObjects
Object_t m_inputObjects
Collection of all the managed input objects.
Definition: Event.h:308
xAOD::Event::m_inputEventFormat
EventFormat m_inputEventFormat
Format of the current input file.
Definition: Event.h:321
xAOD::TActiveStore::store
static TStore * store()
Access the currently active TStore object.
Definition: TActiveStore.cxx:16
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
Utils.h
xAOD::EventFormatElement::branchName
const std::string & branchName() const
Get the branch/key name.
Definition: EventFormatElement.cxx:30
xAOD::EventFormatElement::hash
sgkey_t hash() const
Get the hash belonging to this branch/key.
Definition: EventFormatElement.cxx:48
xAOD::Event::getName
const std::string & getName(const void *obj) const override
Function returning the key describing a known object.
Definition: EventTVirtualEvent.cxx:64
xAOD::Event::getOutputObject
void * getOutputObject(SG::sgkey_t key, const std::type_info &ti) override
Function for retrieving an output object in a non-template way.
Definition: EventTVirtualEvent.cxx:138
CalibDbCompareRT.dummy
dummy
Definition: CalibDbCompareRT.py:59
Event.h
xAOD::Event::getInputObject
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.
Definition: EventTVirtualEvent.cxx:162
xAOD::Event::m_outputObjects
Object_t m_outputObjects
Collection of all the managed output object.
Definition: Event.h:313
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
TVirtualManager.h
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:45
xAOD::Event::getKey
SG::sgkey_t getKey(const void *obj) const override
Function returning the hash describing a known object.
Definition: EventTVirtualEvent.cxx:51
xAOD::Event::m_outputEventFormat
EventFormat * m_outputEventFormat
Format of the current output file.
Definition: Event.h:323
python.trfDecorators.silent
def silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity...
Definition: trfDecorators.py:24
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::Event::getHash
SG::sgkey_t getHash(const std::string &key) const override
Function returning the hash describing an object name.
Definition: EventTVirtualEvent.cxx:27
python.Logging.manager
manager
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/Logging.py:92
python.PyAthena.obj
obj
Definition: PyAthena.py:132
xAOD::Utils::hash
SG::sgkey_t hash(const std::string &name)
This function provides a hashed version of the key (branch) names used in the xAOD file,...
Definition: Control/xAODRootAccess/Root/Utils.cxx:125
TActiveStore.h
TStore.h
xAOD::EventFormat_v1::exists
bool exists(const std::string &key) const
Check if a description exists about a given branch.
Definition: EventFormat_v1.cxx:65
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37