ATLAS Offline Software
SGNTUPProxyLoader.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // SGNTUPProxyLoader.cxx, (c) ATLAS Detector software
8 // Author: Thomas Gillam (thomas.gillam@cern.ch)
9 // ExpressionParsing library
11 
13 
14 #define SG_GET_SCALAR(RETTYPE, TRYTYPE) do { if (m_evtStore->contains<TRYTYPE>(varname)) { \
15  const TRYTYPE *val = nullptr; \
16  StatusCode sc = m_evtStore->retrieve<TRYTYPE>((const TRYTYPE*&)val, varname); \
17  if (sc.isFailure()) { \
18  throw std::runtime_error("Couldn't retrieve (" #TRYTYPE ") " + varname); \
19  } \
20  return (RETTYPE)(*val); \
21 } } while (0)
22 
23 #define SG_GET_VECTOR(RETTYPE, TRYTYPE) do { if (m_evtStore->contains<std::vector<TRYTYPE> >(varname)) { \
24  const std::vector<TRYTYPE> *val = nullptr; \
25  StatusCode sc = m_evtStore->retrieve<std::vector<TRYTYPE> >((const std::vector<TRYTYPE>*&)val, varname); \
26  if (sc.isFailure()) { \
27  throw std::runtime_error("Couldn't retrieve (std::vector<" #TRYTYPE ">) " + varname); \
28  } \
29  std::vector<RETTYPE> temp; \
30  for (std::vector<TRYTYPE>::const_iterator it = val->begin(); it != val->end(); ++it) { \
31  temp.push_back((RETTYPE)(*it)); \
32  } \
33  return temp; \
34 } } while (0)
35 
36 namespace ExpressionParsing {
38  {
39  }
40 
42  {
43  }
44 
46  {
47  if (m_evtStore->contains<int>(varname)) return VT_INT;
48  else if (m_evtStore->contains<bool>(varname)) return VT_INT;
49  else if (m_evtStore->contains<unsigned int>(varname)) return VT_INT;
50  else if (m_evtStore->contains<float>(varname)) return VT_DOUBLE;
51  else if (m_evtStore->contains<double>(varname)) return VT_DOUBLE;
52  else if (m_evtStore->contains<std::vector<int> >(varname)) return VT_VECINT;
53  else if (m_evtStore->contains<std::vector<bool> >(varname)) return VT_VECINT;
54  else if (m_evtStore->contains<std::vector<unsigned int> >(varname)) return VT_VECINT;
55  else if (m_evtStore->contains<std::vector<float> >(varname)) return VT_VECDOUBLE;
56  else if (m_evtStore->contains<std::vector<double> >(varname)) return VT_VECDOUBLE;
57  else return VT_UNK;
58  }
59 
61  {
62  SG_GET_SCALAR(int, int);
63  SG_GET_SCALAR(int, bool);
64  SG_GET_SCALAR(int, unsigned int);
65  throw std::runtime_error("Unknown int-like proxy: " + varname);
66  }
67 
69  {
70  SG_GET_SCALAR(double, float);
71  SG_GET_SCALAR(double, double);
72  throw std::runtime_error("Unknown double-like proxy: " + varname);
73  }
74 
75  std::vector<int> SGNTUPProxyLoader::loadVecIntVariableFromString(const std::string &varname) const
76  {
77  SG_GET_VECTOR(int, int);
78  SG_GET_VECTOR(int, bool);
79  SG_GET_VECTOR(int, unsigned int);
80  throw std::runtime_error("Unknown vector<int>-like proxy: " + varname);
81  }
82 
83  std::vector<double> SGNTUPProxyLoader::loadVecDoubleVariableFromString(const std::string &varname) const
84  {
85  SG_GET_VECTOR(double, float);
86  SG_GET_VECTOR(double, double);
87  throw std::runtime_error("Unknown vector<double>-like proxy: " + varname);
88  }
89 }
ExpressionParsing::SGNTUPProxyLoader::loadDoubleVariableFromString
virtual double loadDoubleVariableFromString(const std::string &varname) const
Definition: SGNTUPProxyLoader.cxx:68
ExpressionParsing::IProxyLoader::VT_VECDOUBLE
@ VT_VECDOUBLE
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::VariableType
VariableType
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::VT_DOUBLE
@ VT_DOUBLE
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::VT_UNK
@ VT_UNK
Definition: IProxyLoader.h:21
SGNTUPProxyLoader.h
ExpressionParsing
Namespace holding all the expression evaluation code.
Definition: ExpressionParser.h:26
ExpressionParsing::IProxyLoader::VT_VECINT
@ VT_VECINT
Definition: IProxyLoader.h:21
ExpressionParsing::SGNTUPProxyLoader::variableTypeFromString
virtual IProxyLoader::VariableType variableTypeFromString(const std::string &varname) const
Definition: SGNTUPProxyLoader.cxx:45
ExpressionParsing::SGNTUPProxyLoader::~SGNTUPProxyLoader
virtual ~SGNTUPProxyLoader()
Definition: SGNTUPProxyLoader.cxx:37
ExpressionParsing::SGNTUPProxyLoader::loadVecIntVariableFromString
virtual std::vector< int > loadVecIntVariableFromString(const std::string &varname) const
Definition: SGNTUPProxyLoader.cxx:75
ExpressionParsing::IProxyLoader::VT_INT
@ VT_INT
Definition: IProxyLoader.h:21
ExpressionParsing::SGNTUPProxyLoader::loadIntVariableFromString
virtual int loadIntVariableFromString(const std::string &varname) const
Definition: SGNTUPProxyLoader.cxx:60
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
ExpressionParsing::SGNTUPProxyLoader::m_evtStore
StoreGateSvc_t m_evtStore
Definition: SGNTUPProxyLoader.h:40
SG_GET_SCALAR
#define SG_GET_SCALAR(RETTYPE, TRYTYPE)
Definition: SGNTUPProxyLoader.cxx:14
ExpressionParsing::SGNTUPProxyLoader::reset
virtual void reset()
Definition: SGNTUPProxyLoader.cxx:41
SG_GET_VECTOR
#define SG_GET_VECTOR(RETTYPE, TRYTYPE)
Definition: SGNTUPProxyLoader.cxx:23
ExpressionParsing::SGNTUPProxyLoader::loadVecDoubleVariableFromString
virtual std::vector< double > loadVecDoubleVariableFromString(const std::string &varname) const
Definition: SGNTUPProxyLoader.cxx:83