ATLAS Offline Software
Loading...
Searching...
No Matches
xAODAccessor.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef _ExpressionEvaluation_xAODAccessor_h_
5#define _ExpressionEvaluation_xAODAccessor_h_
6
7#include "GaudiKernel/DataHandle.h"
15
16#include <memory>
17#include <stdexcept>
18#include <sstream>
19
20#include "Utils.h"
21#include "GenAccessor.h"
22
23namespace ExpressionParsing {
26 template <class T_Cont,typename T_src>
28 public:
30 : m_accessor(SG::AuxTypeRegistry::instance().getName(auxid))
31 {}
32
33 std::size_t size(const T_Cont &cont) const {
34 return getContainerSize(cont);
35 }
36
38 T_src get(const T_Cont &cont) const {
39 return m_accessor( cont );
40 }
41
43 T_src get(const T_Cont &cont, std::size_t idx) const {
44 return m_accessor( cont,idx );
45 }
46
49 class Kit {
50 public:
51 Kit(Kit &&) = default;
52 Kit(SG::auxid_t auxid) : m_auxid(auxid) {}
53
54 AccessorHelper<T_Cont,T_src> create(const EventContext& ctx, SG::ReadHandle<T_Cont> &handle) const {
55 (void) ctx;
56 (void) handle;
58 }
59 private:
61 };
62
63 private:
65 };
66
69 template <class T_Cont,typename T_src>
71 public:
72 DecorHelper(const EventContext& ctx,const SG::ReadDecorHandleKey<T_Cont> &key,SG::ReadHandle<T_Cont> &handle)
73 : m_decorHandle(key, ctx),
74 m_data(getVectorData(*handle)->getDataArray(m_decorHandle.auxid()))
75 {
76 if (!m_decorHandle.isValid()) {
77 BaseAccessor::throwInvalidHandle(key.key());
78 }
79 }
80
81 std::size_t size(const T_Cont &cont) const {
82 return getContainerSize(cont);
83 }
84
86 T_src get(const T_Cont &cont) const {
87 return m_decorHandle( cont );
88 }
89
91 T_src get(const T_Cont &cont, std::size_t idx) const {
92 (void) cont;
94 }
95
98 class Kit {
99 public:
100 Kit(Kit &&) = default;
102
103 DecorHelper<T_Cont,T_src> create(const EventContext& ctx, SG::ReadHandle<T_Cont> &handle) const {
104 (void) handle;
105 try {
106 return DecorHelper<T_Cont,T_src>(ctx, *m_decorKey, handle);
107 }
108 catch (std::exception &err) {
109 dumpAux(*handle, 357);
110 throw err;
111 }
112 return DecorHelper<T_Cont,T_src>(ctx, *m_decorKey, handle);
113 }
114 private:
116 };
117
118 private:
120 const void *m_data;
121 };
122
123 class AccessorFactory;
124
128 friend class AccessorFactory;
129 public:
130 virtual ~IAccessorKit() {}
131 virtual std::unique_ptr<IAccessor> create( const SG::ReadHandleKey<SG::AuxVectorBase> &key,
132 SG::auxid_t auxid,
133 const SG::ReadDecorHandleKey<SG::AuxVectorBase> *decor_key=nullptr) const = 0;
134 virtual std::unique_ptr<IAccessor> create( const SG::ReadHandleKey<SG::AuxElement> &key,
135 SG::auxid_t auxid,
136 const SG::ReadDecorHandleKey<SG::AuxElement> *decor_key=nullptr) const = 0;
137 };
138
141 template <class T, IProxyLoader::VariableType T_variable_type>
142 class AccessorKit : public IAccessorKit {
143 virtual std::unique_ptr<IAccessor> create( const SG::ReadHandleKey<SG::AuxVectorBase> &key,
144 SG::auxid_t auxid,
145 const SG::ReadDecorHandleKey<SG::AuxVectorBase> *decor_key=nullptr) const override {
146 return createAccessor<SG::AuxVectorBase,VectorHelper>(key,auxid, decor_key);
147 }
148 virtual std::unique_ptr<IAccessor> create( const SG::ReadHandleKey<SG::AuxElement> &key,
149 SG::auxid_t auxid,
150 const SG::ReadDecorHandleKey<SG::AuxElement> *decor_key=nullptr) const override {
151 return createAccessor<SG::AuxElement,ScalarHelper>(key,auxid, decor_key);
152 }
153 private:
154 template <class T_Cont, class T_ScalarVectorHelper>
155 std::unique_ptr<IAccessor> createAccessor( const SG::ReadHandleKey<T_Cont> &key,
156 SG::auxid_t auxid,
157 const SG::ReadDecorHandleKey<T_Cont> *decor_key=nullptr) const {
158 if (decor_key) {
159 return std::make_unique<GenAccessor<T_Cont,
161 T_ScalarVectorHelper> >(key,
162 typename DecorHelper<T_Cont, T>::Kit(*decor_key),
163 T_variable_type);
164 }
165 else {
166 return std::make_unique<GenAccessor<T_Cont,
168 T_ScalarVectorHelper> >(key,
169 typename AccessorHelper<T_Cont,T>::Kit(auxid),
170 T_variable_type);
171 }
172 }
173 };
174
175
176
180 // class AccessorFactory;
181 class AccessorFactory : public Singleton<AccessorFactory> {
182 public:
184 m_kits.insert( std::make_pair(typeid(float).hash_code(), std::make_unique<AccessorKit<float,IProxyLoader::VT_VECDOUBLE> >()));
185 m_kits.insert( std::make_pair(typeid(double).hash_code(), std::make_unique<AccessorKit<double,IProxyLoader::VT_VECDOUBLE> >()));
186 m_kits.insert( std::make_pair(typeid(bool).hash_code(), std::make_unique<AccessorKit<bool,IProxyLoader::VT_VECINT> >()));
187 m_kits.insert( std::make_pair(typeid(unsigned char).hash_code(), std::make_unique<AccessorKit<unsigned char,IProxyLoader::VT_VECINT> >()));
188 m_kits.insert( std::make_pair(typeid(unsigned short).hash_code(), std::make_unique<AccessorKit<unsigned short,IProxyLoader::VT_VECINT> >()));
189 m_kits.insert( std::make_pair(typeid(unsigned int).hash_code(), std::make_unique<AccessorKit<unsigned int,IProxyLoader::VT_VECINT> >()));
190 m_kits.insert( std::make_pair(typeid(unsigned long).hash_code(), std::make_unique<AccessorKit<unsigned long,IProxyLoader::VT_VECINT> >())); // @TODO might get cropped if int interface is used
191 m_kits.insert( std::make_pair(typeid(char).hash_code(), std::make_unique<AccessorKit<char,IProxyLoader::VT_VECINT> >()));
192 m_kits.insert( std::make_pair(typeid(short).hash_code(), std::make_unique<AccessorKit<short,IProxyLoader::VT_VECINT> >()));
193 m_kits.insert( std::make_pair(typeid(int).hash_code(), std::make_unique<AccessorKit<int,IProxyLoader::VT_VECINT> >()));
194 m_kits.insert( std::make_pair(typeid(long).hash_code(), std::make_unique<AccessorKit<long,IProxyLoader::VT_VECINT> >())); // @TODO might get cropped if int interface is used
195 }
196
198 std::unique_ptr<IAccessor> create(const SG::ReadHandleKey<SG::AuxElement> &key,
199 SG::auxid_t auxid,
200 const SG::ReadDecorHandleKey<SG::AuxElement> *decor_key=nullptr) const {
201 return getKit(auxid).create(key,auxid, decor_key);
202 }
203
204 std::unique_ptr<IAccessor> create(const SG::ReadHandleKey<SG::AuxVectorBase> &key,
205 SG::auxid_t auxid,
206 const SG::ReadDecorHandleKey<SG::AuxVectorBase> *decor_key=nullptr) const {
207 return getKit(auxid).create(key,auxid, decor_key);
208 }
209
210 private:
211
214 const IAccessorKit &getKit(SG::auxid_t auxid) const {
215 const std::type_info* the_type_info = SG::AuxTypeRegistry::instance().getType (auxid);
216 if (!the_type_info) {
217 std::stringstream msg;
218 msg << "ExpressionParsing::AccessorFactory: no type information about " << auxid
219 << " (" << SG::AuxTypeRegistry::instance().getName(auxid) << ")";
220 throw std::runtime_error(msg.str());
221 }
222 std::map<std::size_t, std::unique_ptr<IAccessorKit> >::const_iterator
223 iter = m_kits.find(the_type_info->hash_code());
224 if (iter == m_kits.end()) {
225 std::stringstream msg;
226 msg << "ExpressionParsing::AccessorFactory: no type information about " << auxid
227 << " (" << SG::AuxTypeRegistry::instance().getName(auxid) << ")";
228 throw std::runtime_error(msg.str());
229 }
230 return *(iter->second);
231 }
232 std::map<std::size_t, std::unique_ptr<IAccessorKit> > m_kits;
233 };
234
235}
236#endif
Base class for elements of a container that can have aux data.
Manage index tracking and synchronization of auxiliary data.
std::map< std::string, double > instance
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for reading from StoreGate.
Class which creates accessors for the specified xAOD object content (singleton).
std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxVectorBase > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxVectorBase > *decor_key=nullptr) const
create an accessor for the specified content of an AuxVectorBase.
std::map< std::size_t, std::unique_ptr< IAccessorKit > > m_kits
std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxElement > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxElement > *decor_key=nullptr) const
create an accessor for the specified content of an AuxElement.
const IAccessorKit & getKit(SG::auxid_t auxid) const
Get an auxiliary class which creates an accessor for the specified content.
Auxiliary class to create the corresponding auxiliary helper object.
AccessorHelper< T_Cont, T_src > create(const EventContext &ctx, SG::ReadHandle< T_Cont > &handle) const
std::size_t size(const T_Cont &cont) const
T_src get(const T_Cont &cont, std::size_t idx) const
Get the specified element of the vector provided by the container.
SG::AuxElement::ConstAccessor< T_src > m_accessor
T_src get(const T_Cont &cont) const
Get the scalar provided by the container.
AccessorHelper(SG::auxid_t auxid)
Implementation of an accessor creator which provides accessors for xAOD accessor or decor handle acce...
std::unique_ptr< IAccessor > createAccessor(const SG::ReadHandleKey< T_Cont > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< T_Cont > *decor_key=nullptr) const
virtual std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxVectorBase > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxVectorBase > *decor_key=nullptr) const override
virtual std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxElement > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxElement > *decor_key=nullptr) const override
Auxiliary class to create the corresponding auxiliary helper object.
const SG::ReadDecorHandleKey< T_Cont > * m_decorKey
Kit(const SG::ReadDecorHandleKey< T_Cont > &key)
DecorHelper< T_Cont, T_src > create(const EventContext &ctx, SG::ReadHandle< T_Cont > &handle) const
T_src get(const T_Cont &cont) const
Get the scalar provided by the container.
T_src get(const T_Cont &cont, std::size_t idx) const
Get the specified element of the vector provided by the container.
std::size_t size(const T_Cont &cont) const
SG::ReadDecorHandle< T_Cont, T_src > m_decorHandle
DecorHelper(const EventContext &ctx, const SG::ReadDecorHandleKey< T_Cont > &key, SG::ReadHandle< T_Cont > &handle)
Generic accessor to access xAOD object content.
Definition GenAccessor.h:63
Interface of a class to create an xAOD object content accessor.
virtual std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxVectorBase > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxVectorBase > *decor_key=nullptr) const =0
virtual std::unique_ptr< IAccessor > create(const SG::ReadHandleKey< SG::AuxElement > &key, SG::auxid_t auxid, const SG::ReadDecorHandleKey< SG::AuxElement > *decor_key=nullptr) const =0
static reference_type index(void *ptr, size_t ndx)
Look up an element in the container by index.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
Property holding a SG store/key/clid from which a ReadHandle is made.
Namespace holding all the expression evaluation code.
const SG::AuxVectorData * getVectorData(const T &cont)
void dumpAux(const T &cont, SG::auxid_t method_id)
Method for debugging to dump information of all aux member of the given container and the specific au...
Definition DebugUtils.h:55
Forward declaration.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
MsgStream & msg
Definition testRead.cxx:32