ATLAS Offline Software
BaseAccessor.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 ExpressionParsing_BaseAccessor_h_
5 #define ExpressionParsing_BaseAccessor_h_
6 
7 #include <stdexcept>
8 #include <sstream>
11 
12 namespace ExpressionParsing {
13 
16  class BaseAccessor : public IAccessor {
17  public:
18  BaseAccessor(IProxyLoader::VariableType variable_type) : m_variableType(variable_type) {}
19 
20  static void throwInvalidHandle(const std::string &key) {
21  std::stringstream msg;
22  msg << "Failed to create read handle for " << key;
23  throw std::runtime_error(key);
24  }
25  static void throwVectorContainsNotOneElement(const std::string &key, std::size_t n_elements) {
26  std::stringstream msg;
27  msg << "Cannot convert to scalar since the aux vector data container " << key << " does not contain exactly one element but " << n_elements;
28  throw std::runtime_error(key);
29  }
30  virtual IProxyLoader::VariableType variableType() const override {
31  return m_variableType;
32  }
33 
34  private:
36  };
37 
40  class EmptyVectorAccessor : public IAccessor {
41  public :
43  virtual int loadInt(const EventContext& ctx) const override { (void) ctx; throwEmptyVector(); return 0; }
44  virtual double loadDouble(const EventContext& ctx) const override { (void) ctx; throwEmptyVector(); return 0.;}
45  virtual std::vector<int> loadVecInt(const EventContext& ctx) const override { (void) ctx; return std::vector<int>(); }
46  virtual std::vector<double> loadVec(const EventContext& ctx) const override { (void) ctx; return std::vector<double>(); }
47  private:
48  void throwEmptyVector() const {
49  throw std::runtime_error("Attempt to convert empty vector into scalar.");
50  }
51  };
52 
53 }
54 #endif
ExpressionParsing::EmptyVectorAccessor::loadDouble
virtual double loadDouble(const EventContext &ctx) const override
Definition: BaseAccessor.h:44
ExpressionParsing::IProxyLoader::VT_VECEMPTY
@ VT_VECEMPTY
Definition: IProxyLoader.h:21
ExpressionParsing::BaseAccessor::m_variableType
IProxyLoader::VariableType m_variableType
Definition: BaseAccessor.h:35
ExpressionParsing::EmptyVectorAccessor::loadVec
virtual std::vector< double > loadVec(const EventContext &ctx) const override
Definition: BaseAccessor.h:46
ExpressionParsing::BaseAccessor::variableType
virtual IProxyLoader::VariableType variableType() const override
Definition: BaseAccessor.h:30
ExpressionParsing::EmptyVectorAccessor::loadInt
virtual int loadInt(const EventContext &ctx) const override
Definition: BaseAccessor.h:43
ExpressionParsing::IProxyLoader::VariableType
VariableType
Definition: IProxyLoader.h:21
IAccessor.h
ExpressionParsing
Namespace holding all the expression evaluation code.
Definition: ExpressionParser.h:26
ExpressionParsing::EmptyVectorAccessor::loadVecInt
virtual std::vector< int > loadVecInt(const EventContext &ctx) const override
Definition: BaseAccessor.h:45
ExpressionParsing::BaseAccessor::throwInvalidHandle
static void throwInvalidHandle(const std::string &key)
Definition: BaseAccessor.h:20
ExpressionParsing::EmptyVectorAccessor::variableType
virtual IProxyLoader::VariableType variableType() const override
Definition: BaseAccessor.h:42
ExpressionParsing::IAccessor
Interface of auxiliary classes to access xAOD object content.
Definition: IAccessor.h:13
ExpressionParsing::BaseAccessor::throwVectorContainsNotOneElement
static void throwVectorContainsNotOneElement(const std::string &key, std::size_t n_elements)
Definition: BaseAccessor.h:25
ExpressionParsing::BaseAccessor
Base class of xAOD object content accessors.
Definition: BaseAccessor.h:16
ExpressionParsing::EmptyVectorAccessor::throwEmptyVector
void throwEmptyVector() const
Definition: BaseAccessor.h:48
IProxyLoader.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ExpressionParsing::EmptyVectorAccessor
Special accessor to handle empty containers until the correct accessor can be created.
Definition: BaseAccessor.h:40
ExpressionParsing::BaseAccessor::BaseAccessor
BaseAccessor(IProxyLoader::VariableType variable_type)
Definition: BaseAccessor.h:18
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37