ATLAS Offline Software
Loading...
Searching...
No Matches
SGxAODProxyLoader.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// SGxAODProxyLoader.h, (c) ATLAS Detector software
8// Author: Thomas Gillam (thomas.gillam@cern.ch)
9// ExpressionParsing library
11
12#ifndef SG_XAOD_PROXY_LOADER_H
13#define SG_XAOD_PROXY_LOADER_H
14
16
17#include "GaudiKernel/ServiceHandle.h"
25
27
29#include <any>
30
31#include "IAccessor.h"
32
33class TMethodCall;
34class TVirtualCollectionProxy;
35
36namespace SG {
37 class AuxVectorBase;
38 class AuxElement;
39}
40#include <map>
41
42namespace ExpressionParsing {
43
44
48
49 public:
51 SGxAODProxyLoader(StoreGateSvc_t &evtStore, bool verbose=false);
52 virtual ~SGxAODProxyLoader();
53
54 virtual void reset() override;
55
56 virtual VariableType variableType(const std::string &var_name) const override;
57
58 virtual std::pair< IProxyLoader::VariableType, const IAccessor &>
59 getAccessorFromString(const EventContext &ctx, const std::string &varname) const override;
60
61 virtual int loadInt(const EventContext& ctx,const std::string &varname) const override;
62 virtual double loadDouble(const EventContext& ctx,const std::string &varname) const override;
63 virtual std::vector<int> loadVecInt(const EventContext& ctx,const std::string &varname) const override;
64 virtual std::vector<double> loadVec(const EventContext& ctx,const std::string &varname) const override;
65
69 public:
73 virtual StatusCode declare(SG::VarHandleKey &handle) = 0;
74 };
75
78 template <class T>
79 class ParentHelper : public IParentHelper {
80 public:
81 ParentHelper(T *parent) : m_parent(parent) {}
82 virtual StatusCode declare(SG::VarHandleKey &handle) override {
83 m_parent->declare(handle);
84 handle.setOwner(m_parent);
85 return handle.initialize();
86 }
87 private:
89 };
90
93 template <class T>
94 static ParentHelper<T> wrapParent(T *parent) {
95 return ParentHelper<T>(parent);
96 }
97
109 const std::vector<std::string> &var_names,
110 const std::vector<std::string> &renounce,
111 const std::vector<const DataObjID *> &input_data_in,
112 const std::vector<const DataObjID *> &output_data_in,
113 std::vector<Gaudi::DataHandle *> &new_input_handles,
114 std::vector<Gaudi::DataHandle *> &new_output_handles);
115
116 private:
117 void splitVarnameIntoContainerAndMethod(const std::string &varname, std::string &containerName, std::string &methodName) const;
118
124 IAccessor &computeClassForVarname(const EventContext& ctx,
125 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator accessor_iter,
126 const std::string &varname) const;
127
133 std::pair<RootUtils::TSMethodCall, TVirtualCollectionProxy *>
134 getMethodCallAccessor(const std::string &method_name, const std::type_info &info) const;
135
142 IAccessor &getAccessor(const EventContext& ctx, const std::string &varname) const {
143 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator
144 accessor_iter = m_accessor.find(varname);
145 if (accessor_iter == m_accessor.end()) {
146 std::stringstream msg;
147 msg << "No accessor stub was created for " << varname << " i.e. variable is unknown.";
148 throw std::runtime_error(msg.str());
149 }
150 if (accessor_iter->second) return *(accessor_iter->second);
151 return computeClassForVarname(ctx,accessor_iter, varname);
152 }
153
162 template <class T_Aux>
163 std::unique_ptr<IAccessor> createAccessor(const EventContext& ctx,
164 const SG::ReadHandleKey<T_Aux> &key,
165 const SG::ReadDecorHandleKey<T_Aux> *decor_key,
166 SG::auxid_t method_id,
167 const std::string &method_name) const;
168
170
173 template <class T_Element_Key, class T_Vector_Key>
174 class ReadHandleMapTmpl : public std::unordered_map<std::string, std::any > {
175 public:
179 template <class T>
180 static T &checkedRef(T *a) {
181 if (!a) {
182 std::stringstream msg; msg << "Conversion to " << typeid(T).name() << " failed.";
183 throw std::runtime_error(msg.str());
184 }
185 return *a;
186 }
187
189 static bool isVector(const std::any &anything) { return anything.type() == typeid(T_Vector_Key); }
191 static bool isElement(const std::any &anything) { return anything.type() == typeid(T_Element_Key); }
193 static T_Element_Key &elementKey(std::any &anything) { return checkedRef(std::any_cast<T_Element_Key>(&anything)); }
195 static T_Vector_Key &vectorKey(std::any &anything) { return checkedRef(std::any_cast<T_Vector_Key>(&anything)); }
197 static const T_Element_Key &elementKey(const std::any &anything) { return checkedRef(std::any_cast<T_Element_Key>(&anything)); }
199 static const T_Vector_Key &vectorKey(const std::any &anything) { return checkedRef(std::any_cast<T_Vector_Key>(&anything)); }
200 };
205 ReadHandleMap m_readKeys; //< Association of variable names and read handle keys to AuxElement or AuxVectorBase.
206 ReadDecorHandleMap m_decorKeys; //< Association of variable names and read decoration handle keys for AuxElement or AuxVectorBase.
207
212 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> > m_accessor;
213
220 std::unique_ptr<IAccessor> m_emptyVectorAccessor;
221 bool m_verbose = false;
222 };
223
224}
225
226#endif // SG_XAOD_PROXY_LOADER_H
Manage index tracking and synchronization of auxiliary data.
Cached unique_ptr with atomic update.
static Double_t a
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.
Helper for thread-safe TMethodCall. Extracted from Type.
Cached pointer with atomic update.
Interface of auxiliary classes to access xAOD object content.
Definition IAccessor.h:17
IAccessor::VariableType VariableType
Interface of an auxiliary class to pass the parent, e.g.
virtual StatusCode declare(SG::VarHandleKey &handle)=0
This method needs to be implement to declare the given data handle.
Template of an auxiliary class to declare the new handles in the parent AthAlgTool,...
virtual StatusCode declare(SG::VarHandleKey &handle) override
This method needs to be implement to declare the given data handle.
Particular map which is used to associate names to read handles of AuxElements or AuxVectorBase.
static const T_Element_Key & elementKey(const std::any &anything)
Get a reference to the element object referred to by any or throw an exception (read only).
static const T_Vector_Key & vectorKey(const std::any &anything)
Get a reference to the vector object referred to by any or throw an exception (read only).
static T_Vector_Key & vectorKey(std::any &anything)
Get a reference to the vector object referred to by any or throw an exception.
static bool isElement(const std::any &anything)
Check whether the given any is the "element" object.
static bool isVector(const std::any &anything)
Check whether the given any is the "vector" object.
static T_Element_Key & elementKey(std::any &anything)
Get a reference to the element object referred to by any or throw an exception.
static T & checkedRef(T *a)
Return a reference for the given pointer.
std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > > m_accessor
Association of variable names to accessors for corresponding xAOD object content.
void splitVarnameIntoContainerAndMethod(const std::string &varname, std::string &containerName, std::string &methodName) const
virtual std::vector< double > loadVec(const EventContext &ctx, const std::string &varname) const override
virtual int loadInt(const EventContext &ctx, const std::string &varname) const override
ServiceHandle< StoreGateSvc > StoreGateSvc_t
virtual double loadDouble(const EventContext &ctx, const std::string &varname) const override
static ParentHelper< T > wrapParent(T *parent)
auxiliary method to create the auxiliary class to declare new data handles with the calling AthAlgToo...
bool updateDataDependencies(SGxAODProxyLoader::IParentHelper &parent, const std::vector< std::string > &var_names, const std::vector< std::string > &renounce, const std::vector< const DataObjID * > &input_data_in, const std::vector< const DataObjID * > &output_data_in, std::vector< Gaudi::DataHandle * > &new_input_handles, std::vector< Gaudi::DataHandle * > &new_output_handles)
Create extra data dependencies arising eventually from the given variables.
IAccessor & getAccessor(const EventContext &ctx, const std::string &varname) const
Get an existing or create a new accessor for the given variable name.
virtual VariableType variableType(const std::string &var_name) const override
std::pair< RootUtils::TSMethodCall, TVirtualCollectionProxy * > getMethodCallAccessor(const std::string &method_name, const std::type_info &info) const
Auxiliary method to create a TMethodCall and eventually also a collection proxy to call the given met...
virtual std::vector< int > loadVecInt(const EventContext &ctx, const std::string &varname) const override
virtual std::pair< IProxyLoader::VariableType, const IAccessor & > getAccessorFromString(const EventContext &ctx, const std::string &varname) const override
IAccessor & computeClassForVarname(const EventContext &ctx, std::unordered_map< std::string, CxxUtils::CachedUniquePtrT< IAccessor > >::const_iterator accessor_iter, const std::string &varname) const
Auxiliary method to create an xAOD object content accessor for the given variable name.
SGxAODProxyLoader(StoreGateSvc_t &evtStore, bool verbose=false)
std::unique_ptr< IAccessor > createAccessor(const EventContext &ctx, const SG::ReadHandleKey< T_Aux > &key, const SG::ReadDecorHandleKey< T_Aux > *decor_key, SG::auxid_t method_id, const std::string &method_name) const
Auxiliary method to create an accessor for the given method_name.
ReadHandleMapTmpl< SG::ReadHandleKey< SG::AuxElement >, SG::ReadHandleKey< SG::AuxVectorBase > > ReadHandleMap
std::unique_ptr< IAccessor > m_emptyVectorAccessor
Special accessor to handle empty vectors Accessor are constructed at time of first evaluation.
ReadHandleMapTmpl< SG::ReadDecorHandleKey< SG::AuxElement >, SG::ReadDecorHandleKey< SG::AuxVectorBase > > ReadDecorHandleMap
Base class for elements of a container that can have aux data.
Definition AuxElement.h:484
Manage index tracking and synchronization of auxiliary data.
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Property holding a SG store/key/clid from which a ReadHandle is made.
A property holding a SG store/key/clid from which a VarHandle is made.
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
bool verbose
Definition hcg.cxx:73
Namespace holding all the expression evaluation code.
Forward declaration.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
MsgStream & msg
Definition testRead.cxx:32