ATLAS Offline Software
Loading...
Searching...
No Matches
BaseAccessor.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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(IAccessor::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 IAccessor::VariableType variableType([[maybe_unused]] const std::string &var_name) const override {
31 return m_variableType;
32 }
33
34 private:
36 };
37
41 public :
42 virtual IAccessor::VariableType variableType([[maybe_unused]] const std::string &var_name) const override { return IProxyLoader::VT_VECEMPTY; }
43 virtual int loadInt([[maybe_unused]] const EventContext& ctx,[[maybe_unused]] const std::string &var_name) const override
44 { throwEmptyVector(); return 0; }
45 virtual double loadDouble([[maybe_unused]] const EventContext& ctx,[[maybe_unused]] const std::string &var_name) const override
46 { throwEmptyVector(); return 0.;}
47 virtual std::vector<int> loadVecInt([[maybe_unused]] const EventContext& ctx,[[maybe_unused]] const std::string &var_name) const override
48 { return std::vector<int>(); }
49 virtual std::vector<double> loadVec([[maybe_unused]] const EventContext& ctx,[[maybe_unused]] const std::string &var_name) const override
50 { return std::vector<double>(); }
51 private:
52 void throwEmptyVector() const {
53 throw std::runtime_error("Attempt to convert empty vector into scalar.");
54 }
55 };
56
57}
58#endif
virtual IAccessor::VariableType variableType(const std::string &var_name) const override
IAccessor::VariableType m_variableType
static void throwVectorContainsNotOneElement(const std::string &key, std::size_t n_elements)
BaseAccessor(IAccessor::VariableType variable_type)
static void throwInvalidHandle(const std::string &key)
Special accessor to handle empty containers until the correct accessor can be created.
virtual std::vector< double > loadVec(const EventContext &ctx, const std::string &var_name) const override
virtual int loadInt(const EventContext &ctx, const std::string &var_name) const override
virtual std::vector< int > loadVecInt(const EventContext &ctx, const std::string &var_name) const override
virtual IAccessor::VariableType variableType(const std::string &var_name) const override
virtual double loadDouble(const EventContext &ctx, const std::string &var_name) const override
Interface of auxiliary classes to access xAOD object content.
Definition IAccessor.h:17
Namespace holding all the expression evaluation code.
MsgStream & msg
Definition testRead.cxx:32