ATLAS Offline Software
Loading...
Searching...
No Matches
PhysicsAnalysis/CommonTools/ExpressionEvaluation/src/Utils.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef _ExpressionEvaluation_Utils_h_
5#define _ExpressionEvaluation_Utils_h_
6
7#include <stdexcept>
8#include "GaudiKernel/DataHandle.h"
12
13namespace ExpressionParsing {
16 template <class T_Key>
17 void initializeHandle(T_Key *key, std::vector<Gaudi::DataHandle *> &new_input_handles) {
18 if (key) {
19 if (key->initialize().isFailure()) {
20 std::stringstream msg;
21 msg << "Failed to initialize read handle " << key->key();
22 throw std::runtime_error( msg.str());
23 }
24 key->init();
25 new_input_handles.push_back( key);
26 }
27 }
28
29
30 // helper functions to provide a uniform interface for AuxElement and AuxVectorBase
31 template <class T_Aux>
32 bool isAvailable(const T_Aux &cont, SG::auxid_t auxid);
33
34 template <>
36 return cont.isAvailable(auxid);
37 }
38
39 template <>
41 return cont.container() && cont.container()->isAvailable(auxid);
42 }
43
44 // helper functions to provide a uniform interface for AuxElement and AuxVectorBase
45 template <class T>
46 class SizeHelper {
47 public:
48 static std::size_t getSize(const T &cont) {
49 (void) cont;
50 return 1;
51 }
52 };
53
54 template <typename T>
55 class SizeHelper<std::vector<T> > {
56 public:
57 static std::size_t getSize(const std::vector<T> &cont) { return cont.size(); }
58 };
59
60 template <>
61 class SizeHelper<SG::AuxVectorBase > {
62 public:
63 static std::size_t getSize(const SG::AuxVectorBase &cont) { return cont.size_v(); }
64 };
65
66 template <>
67 class SizeHelper<SG::AuxElement > {
68 public:
69 static std::size_t getSize(const SG::AuxElement &cont) { return cont.container() ? cont.container()->size_v() : 0; }
70 };
71
72 template <class T>
73 std::size_t getContainerSize(const T &cont) {
74 return SizeHelper<T>::getSize(cont);
75 }
76
77 template <class T>
78 const SG::AuxVectorData *getVectorData(const T &cont) {
79 return &cont;
80 }
81
82 template <>
84 return cont.container();
85 }
86
87 template <class T_Derived>
88 class Singleton {
89 public:
90 static T_Derived &instance() {
91 if (!s_instance) {
92 s_instance.set(std::make_unique<T_Derived>());
93 }
94 return *s_instance;
95 }
96 private:
98 };
99 template <class T_Derived>
101
102}
103#endif
Base class for elements of a container that can have aux data.
Manage index tracking and synchronization of auxiliary data.
Define macros for attributes used to control the static checker.
Cached pointer with atomic update.
static CxxUtils::CachedUniquePtrT< T_Derived > s_instance ATLAS_THREAD_SAFE
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
const SG::AuxVectorData * container() const
Return the container holding this element.
Manage index tracking and synchronization of auxiliary data.
bool isAvailable(const std::string &name, const std::string &clsname="") const
Test to see if a variable exists in the store.
Manage lookup of vectors of auxiliary data.
bool isAvailable(auxid_t id) const
Test to see if a variable exists in the store.
virtual size_t size_v() const =0
Return the size of the container.
Namespace holding all the expression evaluation code.
bool isAvailable(const T_Aux &cont, SG::auxid_t auxid)
const SG::AuxVectorData * getVectorData(const T &cont)
const SG::AuxVectorData * getVectorData< SG::AuxElement >(const SG::AuxElement &cont)
bool isAvailable< SG::AuxVectorBase >(const SG::AuxVectorBase &cont, SG::auxid_t auxid)
CxxUtils::CachedUniquePtrT< T_Derived > Singleton< T_Derived >::s_instance ATLAS_THREAD_SAFE
void initializeHandle(T_Key *key, std::vector< Gaudi::DataHandle * > &new_input_handles)
Auxiliary function to initialize newly create data handles.
bool isAvailable< SG::AuxElement >(const SG::AuxElement &cont, SG::auxid_t auxid)
Forward declaration.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
STL namespace.
MsgStream & msg
Definition testRead.cxx:32