ATLAS Offline Software
xAODVariableProxyLoaders.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 // xAODVariableProxyLoaders.h, (c) ATLAS Detector software
8 // Author: Thomas Gillam (thomas.gillam@cern.ch)
9 // ExpressionParsing library
11 
12 #ifndef XAOD_VARIABLE_PROXY_LOADERS_H
13 #define XAOD_VARIABLE_PROXY_LOADERS_H
14 
16 
18 #include "RootUtils/TSMethodCall.h"
19 #include "TMethodCall.h"
20 #include "TVirtualCollectionProxy.h"
23 #include "CxxUtils/SimpleUpdater.h"
24 
25 #include <unordered_map>
26 #include <string>
27 #include <typeinfo>
28 
29 namespace ExpressionParsing {
30 
32  public:
33  virtual ~BaseAccessorWrapper() { }
34  virtual bool isValid(const SG::AuxElement *auxElement) const = 0;
35  virtual bool isValid(const SG::AuxVectorData *auxVectorData) const = 0;
36 
37  virtual int getIntValue(const SG::AuxElement *auxElement) const = 0;
38  virtual double getDoubleValue(const SG::AuxElement *auxElement) const = 0;
39  virtual std::vector<int> getVecIntValue(const SG::AuxVectorData *auxVectorData) = 0;
40  virtual std::vector<double> getVecDoubleValue(const SG::AuxVectorData *auxVectorData) = 0;
41  };
42 
43 
44  template <typename T> class AccessorWrapper : public BaseAccessorWrapper {
45  public:
46  AccessorWrapper(const std::string &elementName) :
47  m_elementName(elementName), m_acc(elementName)
48  {
49  }
50 
51  virtual ~AccessorWrapper() { }
52 
53  virtual bool isValid(const SG::AuxElement *auxElement) const {
54  return m_acc.isAvailable(*auxElement);
55  }
56 
57  virtual bool isValid(const SG::AuxVectorData *auxVectorData) const {
58  // TPSG: A bit hacky - implementation copied from AuxElement.icc
60  SG::auxid_t auxid = r.findAuxID(m_elementName);
61  if (!auxVectorData || !auxVectorData->getConstStore()) return false;
62 
63  // At this point we just have to cross our fingers and hope...
64  if (auxVectorData->size_v() == 0) return true;
65 
66  const SG::auxid_set_t& ids = auxVectorData->getConstStore()->getAuxIDs();
67  if( ids.find (auxid) != ids.end() ) return true;
68  return auxVectorData->getConstStore()->getData( auxid ) != 0;
69  }
70 
71  virtual int getIntValue(const SG::AuxElement *auxElement) const {
72  return (int) m_acc(*auxElement);
73  }
74 
75  virtual double getDoubleValue(const SG::AuxElement *auxElement) const {
76  return (double) m_acc(*auxElement);
77  }
78 
79  virtual std::vector<int> getVecIntValue(const SG::AuxVectorData *auxVectorData) {
80  size_t N = auxVectorData->size_v();
81  std::vector<int> result(N);
82  for (size_t i = 0; i < N; ++i) {
83  result[i] = (int) m_acc(*auxVectorData, i);
84  }
85  return result;
86  }
87 
88  virtual std::vector<double> getVecDoubleValue(const SG::AuxVectorData *auxVectorData) {
89  size_t N = auxVectorData->size_v();
90  std::vector<double> result(N);
91  for (size_t i = 0; i < N; ++i) {
92  result[i] = (double) m_acc(*auxVectorData, i);
93  }
94  return result;
95  }
96 
97  private:
98  std::string m_elementName;
100  };
101 
102 
104  public:
105  TMethodWrapper(const std::type_info &elementTypeinfo, const std::string &methodName);
106  TMethodWrapper(const TMethodWrapper&) = delete;
108  virtual ~TMethodWrapper();
110  virtual bool isValid(const SG::AuxElement *auxElement) const;
111  virtual bool isValid(const SG::AuxVectorData *auxVectorData) const;
112 
113  virtual int getIntValue(const SG::AuxElement *auxElement) const;
114  virtual double getDoubleValue(const SG::AuxElement *auxElement) const;
115  virtual std::vector<int> getVecIntValue(const SG::AuxVectorData *auxVectorData);
116  virtual std::vector<double> getVecDoubleValue(const SG::AuxVectorData *auxVectorData);
117 
118  private:
120  bool m_valid;
121  };
122 
123 
125  public:
126  TMethodCollectionWrapper(const std::type_info &containerTypeinfo, const std::string &methodName);
129  virtual ~TMethodCollectionWrapper();
131  virtual bool isValid(const SG::AuxElement *auxElement) const;
132  virtual bool isValid(const SG::AuxVectorData *auxVectorData) const;
133 
134  virtual int getIntValue(const SG::AuxElement *auxElement) const;
135  virtual double getDoubleValue(const SG::AuxElement *auxElement) const;
136  virtual std::vector<int> getVecIntValue(const SG::AuxVectorData *auxVectorData);
137  virtual std::vector<double> getVecDoubleValue(const SG::AuxVectorData *auxVectorData);
138 
139  private:
140  TVirtualCollectionProxy *m_collectionProxy;
142  bool m_valid;
143  };
144 
145 
146  class xAODProxyLoader : public IProxyLoader {
147  public:
148  xAODProxyLoader();
149  virtual ~xAODProxyLoader();
150 
154 
155  virtual void reset();
156 
157  protected:
158  template<class TYPE, class AUX>
159  bool try_type(const std::string& varname, const std::type_info* ti, const AUX* data) const;
160 
161  template<class AUX>
162  IProxyLoader::VariableType try_all_known_types(const std::string& varname, const AUX* data, bool isVector) const;
163 
164  using accessorCache_t = CxxUtils::ConcurrentStrMap<BaseAccessorWrapper*, CxxUtils::SimpleUpdater>;
165  mutable accessorCache_t m_accessorCache ATLAS_THREAD_SAFE;
166  };
167 
168 
170  public:
172  xAODElementProxyLoader(const SG::AuxElement *auxElement);
173 
174  void setData(const SG::AuxElement *auxElement);
175 
176  virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const;
177  virtual int loadIntVariableFromString(const std::string &varname) const;
178  virtual double loadDoubleVariableFromString(const std::string &varname) const;
179  virtual std::vector<int> loadVecIntVariableFromString(const std::string &varname) const;
180  virtual std::vector<double> loadVecDoubleVariableFromString(const std::string &varname) const;
181 
182  private:
183  const SG::AuxElement *m_auxElement{nullptr};
184  };
185 
186 
188  public:
190  xAODVectorProxyLoader(const SG::AuxVectorData *auxVectorData);
191 
192  void setData(const SG::AuxVectorData *auxElement);
193 
194  virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const;
195  virtual int loadIntVariableFromString(const std::string &varname) const;
196  virtual double loadDoubleVariableFromString(const std::string &varname) const;
197  virtual std::vector<int> loadVecIntVariableFromString(const std::string &varname) const;
198  virtual std::vector<double> loadVecDoubleVariableFromString(const std::string &varname) const;
199 
200  private:
202  };
203 
204 }
205 
206 #endif // XAOD_VARIABLE_PROXY_LOADERS_H
ExpressionParsing::TMethodCollectionWrapper::~TMethodCollectionWrapper
virtual ~TMethodCollectionWrapper()
Definition: xAODVariableProxyLoaders.cxx:111
TSMethodCall.h
Helper for thread-safe TMethodCall. Extracted from Type.
ExpressionParsing::AccessorWrapper::isValid
virtual bool isValid(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.h:53
SG::AuxVectorData::getConstStore
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
beamspotman.r
def r
Definition: beamspotman.py:676
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
ExpressionParsing::TMethodCollectionWrapper::getDoubleValue
virtual double getDoubleValue(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.cxx:146
SG::IConstAuxStore::getData
virtual const void * getData(SG::auxid_t auxid) const =0
Return the data vector for one aux data item.
get_generator_info.result
result
Definition: get_generator_info.py:21
ExpressionParsing::xAODElementProxyLoader::loadVecIntVariableFromString
virtual std::vector< int > loadVecIntVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:299
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
ExpressionParsing::TMethodCollectionWrapper::m_valid
bool m_valid
Definition: xAODVariableProxyLoaders.h:142
ExpressionParsing::xAODProxyLoader
Definition: xAODVariableProxyLoaders.h:146
ExpressionParsing::TMethodCollectionWrapper::ATLAS_THREAD_SAFE
RootUtils::TSMethodCall m_methodCall ATLAS_THREAD_SAFE
Definition: xAODVariableProxyLoaders.h:141
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:472
ExpressionParsing::BaseAccessorWrapper::~BaseAccessorWrapper
virtual ~BaseAccessorWrapper()
Definition: xAODVariableProxyLoaders.h:33
ExpressionParsing::AccessorWrapper::getDoubleValue
virtual double getDoubleValue(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.h:75
ExpressionParsing::TMethodCollectionWrapper::TMethodCollectionWrapper
TMethodCollectionWrapper(const std::type_info &containerTypeinfo, const std::string &methodName)
Definition: xAODVariableProxyLoaders.cxx:89
ExpressionParsing::xAODProxyLoader::try_type
bool try_type(const std::string &varname, const std::type_info *ti, const AUX *data) const
Definition: xAODVariableProxyLoaders.cxx:203
ExpressionParsing::TMethodWrapper::variableType
IProxyLoader::VariableType variableType()
Definition: xAODVariableProxyLoaders.cxx:34
ExpressionParsing::BaseAccessorWrapper::isValid
virtual bool isValid(const SG::AuxVectorData *auxVectorData) const =0
ConcurrentStrMap.h
Hash map from strings allowing concurrent, lockless reads.
ExpressionParsing::TMethodCollectionWrapper::getVecIntValue
virtual std::vector< int > getVecIntValue(const SG::AuxVectorData *auxVectorData)
Definition: xAODVariableProxyLoaders.cxx:151
ExpressionParsing::BaseAccessorWrapper::getDoubleValue
virtual double getDoubleValue(const SG::AuxElement *auxElement) const =0
ExpressionParsing::TMethodCollectionWrapper::getVecDoubleValue
virtual std::vector< double > getVecDoubleValue(const SG::AuxVectorData *auxVectorData)
Definition: xAODVariableProxyLoaders.cxx:167
ExpressionParsing::xAODVectorProxyLoader::variableTypeFromString
virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:322
ExpressionParsing::xAODElementProxyLoader::setData
void setData(const SG::AuxElement *auxElement)
Definition: xAODVariableProxyLoaders.cxx:254
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
ExpressionParsing::BaseAccessorWrapper
Definition: xAODVariableProxyLoaders.h:31
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
ExpressionParsing::xAODProxyLoader::ATLAS_THREAD_SAFE
accessorCache_t m_accessorCache ATLAS_THREAD_SAFE
Definition: xAODVariableProxyLoaders.h:165
ExpressionParsing::xAODVectorProxyLoader::m_auxVectorData
const SG::AuxVectorData * m_auxVectorData
Definition: xAODVariableProxyLoaders.h:201
ExpressionParsing::TMethodCollectionWrapper::variableType
IProxyLoader::VariableType variableType()
Definition: xAODVariableProxyLoaders.cxx:115
ExpressionParsing::TMethodWrapper::isValid
virtual bool isValid(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.cxx:50
ExpressionParsing::xAODVectorProxyLoader::xAODVectorProxyLoader
xAODVectorProxyLoader()=default
ExpressionParsing::TMethodWrapper::getVecDoubleValue
virtual std::vector< double > getVecDoubleValue(const SG::AuxVectorData *auxVectorData)
Definition: xAODVariableProxyLoaders.cxx:81
ExpressionParsing::TMethodWrapper
Definition: xAODVariableProxyLoaders.h:103
ExpressionParsing::IProxyLoader
Definition: IProxyLoader.h:19
ExpressionParsing::TMethodCollectionWrapper::operator=
TMethodCollectionWrapper & operator=(const TMethodCollectionWrapper &)=delete
ExpressionParsing::TMethodWrapper::ATLAS_THREAD_SAFE
RootUtils::TSMethodCall m_methodCall ATLAS_THREAD_SAFE
Definition: xAODVariableProxyLoaders.h:119
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
RootUtils::TSMethodCall
Helper for making a thread-safe function call.
Definition: TSMethodCall.h:33
ExpressionParsing::AccessorWrapper::isValid
virtual bool isValid(const SG::AuxVectorData *auxVectorData) const
Definition: xAODVariableProxyLoaders.h:57
ExpressionParsing::AccessorWrapper::getIntValue
virtual int getIntValue(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.h:71
ExpressionParsing::IProxyLoader::VariableType
VariableType
Definition: IProxyLoader.h:21
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
ExpressionParsing::TMethodCollectionWrapper::isValid
virtual bool isValid(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.cxx:131
ExpressionParsing::TMethodCollectionWrapper::TMethodCollectionWrapper
TMethodCollectionWrapper(const TMethodCollectionWrapper &)=delete
lumiFormat.i
int i
Definition: lumiFormat.py:85
ExpressionParsing::AccessorWrapper::AccessorWrapper
AccessorWrapper(const std::string &elementName)
Definition: xAODVariableProxyLoaders.h:46
ExpressionParsing::xAODElementProxyLoader::m_auxElement
const SG::AuxElement * m_auxElement
Definition: xAODVariableProxyLoaders.h:183
ExpressionParsing::TMethodWrapper::~TMethodWrapper
virtual ~TMethodWrapper()
Definition: xAODVariableProxyLoaders.cxx:30
ExpressionParsing::xAODProxyLoader::try_all_known_types
IProxyLoader::VariableType try_all_known_types(const std::string &varname, const AUX *data, bool isVector) const
Definition: xAODVariableProxyLoaders.cxx:220
ExpressionParsing::xAODVectorProxyLoader::loadVecIntVariableFromString
virtual std::vector< int > loadVecIntVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:356
ExpressionParsing::AccessorWrapper::getVecIntValue
virtual std::vector< int > getVecIntValue(const SG::AuxVectorData *auxVectorData)
Definition: xAODVariableProxyLoaders.h:79
ExpressionParsing
Namespace holding all the expression evaluation code.
Definition: ExpressionParser.h:26
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
ExpressionParsing::xAODVectorProxyLoader::loadDoubleVariableFromString
virtual double loadDoubleVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:351
ExpressionParsing::TMethodWrapper::TMethodWrapper
TMethodWrapper(const TMethodWrapper &)=delete
ExpressionParsing::AccessorWrapper
Definition: xAODVariableProxyLoaders.h:44
ExpressionParsing::xAODElementProxyLoader::loadIntVariableFromString
virtual int loadIntVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:289
ExpressionParsing::xAODElementProxyLoader
Definition: xAODVariableProxyLoaders.h:169
ExpressionParsing::xAODVectorProxyLoader::loadIntVariableFromString
virtual int loadIntVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:346
ExpressionParsing::BaseAccessorWrapper::getVecIntValue
virtual std::vector< int > getVecIntValue(const SG::AuxVectorData *auxVectorData)=0
ExpressionParsing::TMethodCollectionWrapper
Definition: xAODVariableProxyLoaders.h:124
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
ExpressionParsing::TMethodWrapper::operator=
TMethodWrapper & operator=(const TMethodWrapper &)=delete
ExpressionParsing::AccessorWrapper::getVecDoubleValue
virtual std::vector< double > getVecDoubleValue(const SG::AuxVectorData *auxVectorData)
Definition: xAODVariableProxyLoaders.h:88
ExpressionParsing::xAODProxyLoader::accessorCache_t
CxxUtils::ConcurrentStrMap< BaseAccessorWrapper *, CxxUtils::SimpleUpdater > accessorCache_t
Definition: xAODVariableProxyLoaders.h:164
ExpressionParsing::TMethodCollectionWrapper::m_collectionProxy
TVirtualCollectionProxy * m_collectionProxy
Definition: xAODVariableProxyLoaders.h:140
ExpressionParsing::xAODProxyLoader::xAODProxyLoader
xAODProxyLoader()
Definition: xAODVariableProxyLoaders.cxx:186
ExpressionParsing::xAODElementProxyLoader::xAODElementProxyLoader
xAODElementProxyLoader()=default
ExpressionParsing::AccessorWrapper::m_acc
SG::AuxElement::ConstAccessor< T > m_acc
Definition: xAODVariableProxyLoaders.h:99
ExpressionParsing::AccessorWrapper::~AccessorWrapper
virtual ~AccessorWrapper()
Definition: xAODVariableProxyLoaders.h:51
ExpressionParsing::TMethodWrapper::m_valid
bool m_valid
Definition: xAODVariableProxyLoaders.h:120
ExpressionParsing::TMethodWrapper::getVecIntValue
virtual std::vector< int > getVecIntValue(const SG::AuxVectorData *auxVectorData)
Definition: xAODVariableProxyLoaders.cxx:76
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
ExpressionParsing::xAODElementProxyLoader::loadDoubleVariableFromString
virtual double loadDoubleVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:294
ExpressionParsing::xAODVectorProxyLoader
Definition: xAODVariableProxyLoaders.h:187
SimpleUpdater.h
Simple (non-deleting) Updater implementation.
ExpressionParsing::xAODProxyLoader::operator=
xAODProxyLoader & operator=(const xAODProxyLoader &)=delete
ExpressionParsing::xAODElementProxyLoader::loadVecDoubleVariableFromString
virtual std::vector< double > loadVecDoubleVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:304
ExpressionParsing::TMethodWrapper::getIntValue
virtual int getIntValue(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.cxx:60
ExpressionParsing::xAODVectorProxyLoader::setData
void setData(const SG::AuxVectorData *auxElement)
Definition: xAODVariableProxyLoaders.cxx:317
ExpressionParsing::xAODElementProxyLoader::variableTypeFromString
virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:259
ExpressionParsing::BaseAccessorWrapper::getIntValue
virtual int getIntValue(const SG::AuxElement *auxElement) const =0
ExpressionParsing::TMethodWrapper::getDoubleValue
virtual double getDoubleValue(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.cxx:68
runLayerRecalibration.isVector
string isVector
Definition: runLayerRecalibration.py:125
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:168
ExpressionParsing::BaseAccessorWrapper::getVecDoubleValue
virtual std::vector< double > getVecDoubleValue(const SG::AuxVectorData *auxVectorData)=0
checker_macros.h
Define macros for attributes used to control the static checker.
ExpressionParsing::xAODProxyLoader::reset
virtual void reset()
Definition: xAODVariableProxyLoaders.cxx:196
ExpressionParsing::xAODVectorProxyLoader::loadVecDoubleVariableFromString
virtual std::vector< double > loadVecDoubleVariableFromString(const std::string &varname) const
Definition: xAODVariableProxyLoaders.cxx:361
IProxyLoader.h
ExpressionParsing::TMethodWrapper::TMethodWrapper
TMethodWrapper(const std::type_info &elementTypeinfo, const std::string &methodName)
Definition: xAODVariableProxyLoaders.cxx:15
ExpressionParsing::BaseAccessorWrapper::isValid
virtual bool isValid(const SG::AuxElement *auxElement) const =0
ExpressionParsing::xAODProxyLoader::~xAODProxyLoader
virtual ~xAODProxyLoader()
Definition: xAODVariableProxyLoaders.cxx:191
ExpressionParsing::TMethodCollectionWrapper::getIntValue
virtual int getIntValue(const SG::AuxElement *auxElement) const
Definition: xAODVariableProxyLoaders.cxx:141
SG::IConstAuxStore::getAuxIDs
virtual const SG::auxid_set_t & getAuxIDs() const =0
Return a set of identifiers for existing data items in this store.
SG::AuxVectorData::size_v
virtual size_t size_v() const =0
Return the size of the container.
AuxElement.h
Base class for elements of a container that can have aux data.
ExpressionParsing::xAODProxyLoader::xAODProxyLoader
xAODProxyLoader(const xAODProxyLoader &)=delete
Disallow copy construction and assignment.
ExpressionParsing::AccessorWrapper::m_elementName
std::string m_elementName
Definition: xAODVariableProxyLoaders.h:98