ATLAS Offline Software
Loading...
Searching...
No Matches
GenAccessor.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 _ExpressionEvaluation_GenAccessor_h_
5#define _ExpressionEvaluation_GenAccessor_h_
6
10
11#include "BaseAccessor.h"
12
13#include <vector>
14
15namespace ExpressionParsing {
16
20 public:
21 template <class T_Dest, class T_Cont, class T_Helper>
22 static void fillVector(T_Helper &helper, SG::ReadHandle<T_Cont> &handle, std::vector<T_Dest> &result) {
23 result.reserve(1);
24 result.push_back( static_cast<T_Dest>( helper.get( *handle ) ));
25 }
26
27 template <class T_Dest, class T_Cont, class T_Helper>
28 static T_Dest getScalar(T_Helper &helper, SG::ReadHandle<T_Cont> &handle,const T_Dest &dummy) {
29 (void) dummy;
30 return static_cast<T_Dest>( helper.get( *handle ) );
31 }
32 };
33
37 public:
38 template <class T_Dest, class T_Cont, class T_Helper>
39 static void fillVector(T_Helper &helper, SG::ReadHandle<T_Cont> &handle, std::vector<T_Dest> &result) {
40 std::size_t n_elements=helper.size(*handle);
41 // helper.checkSize(n_elements);
42 result.reserve(n_elements);
43 for(std::size_t idx =0; idx <n_elements; ++idx) {
44 result.push_back( static_cast<T_Dest>( helper.get(*handle, idx)) );
45 }
46 }
47 template <class T_Dest, class T_Cont, class T_Helper>
48 static T_Dest getScalar(T_Helper &helper, SG::ReadHandle<T_Cont> &handle, const T_Dest &dummy) {
49 (void) dummy;
50 if (getContainerSize(*handle) != 1) {
52 }
53
54 return static_cast<T_Dest>( helper.get(*handle, 0));
55 }
56 };
57
62 template <class T_Cont, class T_HelperKit, class T_ScalarVectorHelper>
63 class GenAccessor : public BaseAccessor {
64 public:
65 GenAccessor(const SG::ReadHandleKey<T_Cont> &key, T_HelperKit &&helper_kit, IProxyLoader::VariableType variable_type)
66 : BaseAccessor(variable_type),
67 m_key(&key),
68 m_helperKit(std::move(helper_kit))
69 {}
70
71 virtual int loadInt(const EventContext& ctx) const override {
72 return this->loadScalar<int>(ctx);
73 }
74 virtual double loadDouble(const EventContext& ctx) const override {
75 return this->loadScalar<double>(ctx);
76 }
77 virtual std::vector<int> loadVecInt(const EventContext& ctx) const override {
78 return this->loadVector<int>(ctx);
79 }
80 virtual std::vector<double> loadVec(const EventContext& ctx) const override {
81 return this->loadVector<double>(ctx);
82 }
83 protected:
84 template <class T_Dest>
85 std::vector<T_Dest> loadVector(const EventContext& ctx) const {
86 SG::ReadHandle<T_Cont> handle(*this->m_key, ctx);
87 if (!handle.isValid()) {
88 this->throwInvalidHandle(this->m_key->key());
89 }
90 std::vector<T_Dest> result;
91 if (getContainerSize(*handle)>0) {
92 auto helper( m_helperKit.create(ctx, handle));
93 T_ScalarVectorHelper::fillVector(helper, handle,result);
94 }
95 return result;
96 }
97
98 template <class T_Dest>
99 T_Dest loadScalar(const EventContext& ctx) const {
100 SG::ReadHandle<T_Cont> handle(*this->m_key, ctx);
101 if (!handle.isValid()) {
102 this->throwInvalidHandle(this->m_key->key());
103 }
104 auto helper( m_helperKit.create(ctx, handle));
105 T_Dest dummy {};
106 return T_ScalarVectorHelper::getScalar(helper, handle, dummy);
107 }
108
109 const SG::ReadHandleKey<T_Cont> *m_key; //< key to access the xAOD container
110 T_HelperKit m_helperKit; //< auxiliary class to create an access helper
111 };
112}
113#endif
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for reading from StoreGate.
BaseAccessor(IProxyLoader::VariableType variable_type)
static void throwVectorContainsNotOneElement(const std::string &key, std::size_t n_elements)
static void throwInvalidHandle(const std::string &key)
virtual std::vector< double > loadVec(const EventContext &ctx) const override
Definition GenAccessor.h:80
virtual double loadDouble(const EventContext &ctx) const override
Definition GenAccessor.h:74
virtual std::vector< int > loadVecInt(const EventContext &ctx) const override
Definition GenAccessor.h:77
GenAccessor(const SG::ReadHandleKey< T_Cont > &key, T_HelperKit &&helper_kit, IProxyLoader::VariableType variable_type)
Definition GenAccessor.h:65
const SG::ReadHandleKey< T_Cont > * m_key
virtual int loadInt(const EventContext &ctx) const override
Definition GenAccessor.h:71
std::vector< T_Dest > loadVector(const EventContext &ctx) const
Definition GenAccessor.h:85
T_Dest loadScalar(const EventContext &ctx) const
Definition GenAccessor.h:99
Auxiliary class to handle scalar like containers (AuxElement).
Definition GenAccessor.h:19
static void fillVector(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, std::vector< T_Dest > &result)
Definition GenAccessor.h:22
static T_Dest getScalar(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, const T_Dest &dummy)
Definition GenAccessor.h:28
Auxiliary class to handle vector like containers (AuxVectorBase).
Definition GenAccessor.h:36
static void fillVector(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, std::vector< T_Dest > &result)
Definition GenAccessor.h:39
static T_Dest getScalar(T_Helper &helper, SG::ReadHandle< T_Cont > &handle, const T_Dest &dummy)
Definition GenAccessor.h:48
Property holding a SG store/key/clid from which a ReadHandle is made.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Namespace holding all the expression evaluation code.
STL namespace.