ATLAS Offline Software
Loading...
Searching...
No Matches
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
12namespace 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
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
virtual IProxyLoader::VariableType variableType() const override
BaseAccessor(IProxyLoader::VariableType variable_type)
IProxyLoader::VariableType m_variableType
static void throwVectorContainsNotOneElement(const std::string &key, std::size_t n_elements)
static void throwInvalidHandle(const std::string &key)
Special accessor to handle empty containers until the correct accessor can be created.
virtual IProxyLoader::VariableType variableType() const override
virtual std::vector< int > loadVecInt(const EventContext &ctx) const override
virtual double loadDouble(const EventContext &ctx) const override
virtual std::vector< double > loadVec(const EventContext &ctx) const override
virtual int loadInt(const EventContext &ctx) const override
Interface of auxiliary classes to access xAOD object content.
Definition IAccessor.h:13
Namespace holding all the expression evaluation code.
MsgStream & msg
Definition testRead.cxx:32