ATLAS Offline Software
Loading...
Searching...
No Matches
SGxAODProxyLoader.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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
17
18#include "GaudiKernel/ServiceHandle.h"
26
28#include <any>
29
30#include "IAccessor.h"
31
32class TMethodCall;
33class TVirtualCollectionProxy;
34
35namespace SG {
36 class AuxVectorBase;
37 class AuxElement;
38}
39#include <map>
40
41namespace ExpressionParsing {
42
43
47
48 public:
50 SGxAODProxyLoader(StoreGateSvc_t &evtStore, bool verbose=false);
51 virtual ~SGxAODProxyLoader();
52
53 virtual void reset();
54
55 virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const;
56
57 virtual int loadIntVariableFromString(const std::string &varname) const;
58 virtual double loadDoubleVariableFromString(const std::string &varname) const;
59 virtual std::vector<int> loadVecIntVariableFromString(const std::string &varname) const;
60 virtual std::vector<double> loadVecDoubleVariableFromString(const std::string &varname) const;
61
65 public:
69 virtual StatusCode declare(SG::VarHandleKey &handle) = 0;
70 };
71
74 template <class T>
75 class ParentHelper : public IParentHelper {
76 public:
77 ParentHelper(T *parent) : m_parent(parent) {}
78 virtual StatusCode declare(SG::VarHandleKey &handle) override {
79 m_parent->declare(handle);
80 handle.setOwner(m_parent);
81 return handle.initialize();
82 }
83 private:
85 };
86
89 template <class T>
90 static ParentHelper<T> wrapParent(T *parent) {
91 return ParentHelper<T>(parent);
92 }
93
105 const std::vector<std::string> &var_names,
106 const std::vector<std::string> &renounce,
107 const std::vector<const DataObjID *> &input_data_in,
108 const std::vector<const DataObjID *> &output_data_in,
109 std::vector<Gaudi::DataHandle *> &new_input_handles,
110 std::vector<Gaudi::DataHandle *> &new_output_handles);
111
112 private:
113 void splitVarnameIntoContainerAndMethod(const std::string &varname, std::string &containerName, std::string &methodName) const;
114
120 IAccessor &computeClassForVarname(const EventContext& ctx,
121 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator accessor_iter,
122 const std::string &varname) const;
123
129 std::pair<RootUtils::TSMethodCall, TVirtualCollectionProxy *>
130 getMethodCallAccessor(const std::string &method_name, const std::type_info &info) const;
131
138 IAccessor &getAccessor(const EventContext& ctx, const std::string &varname) const {
139 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> >::const_iterator
140 accessor_iter = m_accessor.find(varname);
141 if (accessor_iter == m_accessor.end()) {
142 std::stringstream msg;
143 msg << "No accessor stub was created for " << varname << " i.e. variable is unknown.";
144 throw std::runtime_error(msg.str());
145 }
146 if (accessor_iter->second) return *(accessor_iter->second);
147 return computeClassForVarname(ctx,accessor_iter, varname);
148 }
149
158 template <class T_Aux>
159 std::unique_ptr<IAccessor> createAccessor(const EventContext& ctx,
160 const SG::ReadHandleKey<T_Aux> &key,
161 const SG::ReadDecorHandleKey<T_Aux> *decor_key,
162 SG::auxid_t method_id,
163 const std::string &method_name) const;
164
166
169 template <class T_Element_Key, class T_Vector_Key>
170 class ReadHandleMapTmpl : public std::unordered_map<std::string, std::any > {
171 public:
175 template <class T>
176 static T &checkedRef(T *a) {
177 if (!a) {
178 std::stringstream msg; msg << "Conversion to " << typeid(T).name() << " failed.";
179 throw std::runtime_error(msg.str());
180 }
181 return *a;
182 }
183
185 static bool isVector(const std::any &anything) { return anything.type() == typeid(T_Vector_Key); }
187 static bool isElement(const std::any &anything) { return anything.type() == typeid(T_Element_Key); }
189 static T_Element_Key &elementKey(std::any &anything) { return checkedRef(std::any_cast<T_Element_Key>(&anything)); }
191 static T_Vector_Key &vectorKey(std::any &anything) { return checkedRef(std::any_cast<T_Vector_Key>(&anything)); }
193 static const T_Element_Key &elementKey(const std::any &anything) { return checkedRef(std::any_cast<T_Element_Key>(&anything)); }
195 static const T_Vector_Key &vectorKey(const std::any &anything) { return checkedRef(std::any_cast<T_Vector_Key>(&anything)); }
196 };
201 ReadHandleMap m_readKeys; //< Association of variable names and read handle keys to AuxElement or AuxVectorBase.
202 ReadDecorHandleMap m_decorKeys; //< Association of variable names and read decoration handle keys for AuxElement or AuxVectorBase.
203
208 std::unordered_map<std::string, CxxUtils::CachedUniquePtrT<IAccessor> > m_accessor;
209
216 std::unique_ptr<IAccessor> m_emptyVectorAccessor;
217 bool m_verbose = false;
218 };
219
220}
221
222#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.
Cached pointer with atomic update.
Interface of auxiliary classes to access xAOD object content.
Definition IAccessor.h:13
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 > loadVecDoubleVariableFromString(const std::string &varname) const
ServiceHandle< StoreGateSvc > StoreGateSvc_t
virtual double loadDoubleVariableFromString(const std::string &varname) const
virtual std::vector< int > loadVecIntVariableFromString(const std::string &varname) const
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.
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...
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.
virtual int loadIntVariableFromString(const std::string &varname) const
virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const
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:483
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