ATLAS Offline Software
Loading...
Searching...
No Matches
StackElement.h
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// $Id$
8#ifndef EXPRESSIONEVALUATION_STACKELEMENT_H
9#define EXPRESSIONEVALUATION_STACKELEMENT_H
10
11// System include(s):
12#include <iosfwd>
13#include <vector>
14#include <string>
15#include <atomic>
16
17// Local include(s):
22
23class EventContext;
24
35namespace ExpressionParsing {
36
37 // Forward declaration(s):
38 class IProxyLoader;
39
56
58 friend std::ostream& operator<<( std::ostream& os,
59 const StackElement& el );
60
61 public:
70
73
77 StackElement( unsigned int val ) : m_type( SE_INT ), m_intVal(static_cast<unsigned int>(val)) {}
79 StackElement( int val ) : m_type( SE_INT ), m_intVal(val) {}
81 StackElement( double val ) : m_type( SE_DOUBLE ), m_doubleVal( val ) {}
83 StackElement( const std::vector< int >& val ) : m_type( SE_VECINT ), m_vecIntVal(val) {}
85 StackElement( const std::vector< double >& val ) : m_type( SE_VECDOUBLE ), m_vecDoubleVal( val ) {}
87 StackElement( std::vector< int >&& val ) : m_type( SE_VECINT ), m_vecIntVal(std::move(val)) {}
89 StackElement( std::vector< double >&& val ) : m_type( SE_VECDOUBLE ), m_vecDoubleVal( std::move(val) ) {}
91 StackElement( const std::string& val, IProxyLoader* proxyLoader ) : /*m_type( SE_UNK ), */m_varName( val ), m_proxyLoader( proxyLoader ) {}
92;
96
99
101 StackElement& operator=( int rhs );
103 StackElement& operator=( double rhs );
105 StackElement& operator=( const std::vector< int >& rhs );
107 StackElement& operator=( const std::vector< double >& rhs );
109 StackElement& operator=( std::vector< int >&& rhs );
111 StackElement& operator=( std::vector< double >&& rhs );
112
115
118
123
125
128
131 template< typename T >
132 StackElement& operator-=( const T& rhs );
134 template< typename T >
135 StackElement& operator-=( const std::vector< T >& rhs );
138 template< typename T >
139 StackElement& operator+=( const T& rhs );
141 template< typename T >
142 StackElement& operator+=( const std::vector< T >& rhs );
145 template< typename T >
146 StackElement& operator*=( const T& rhs );
148 template< typename T >
149 StackElement& operator*=( const std::vector< T >& rhs );
152 template< typename T >
153 StackElement& operator/=( const T& rhs );
155 template< typename T >
156 StackElement& operator/=( const std::vector< T >& rhs );
157
160 template< typename T >
161 StackElement operator-( const T& rhs );
164 template< typename T >
165 StackElement operator+( const T& rhs );
168 template< typename T >
169 StackElement operator*( const T& rhs );
172 template< typename T >
173 StackElement operator/( const T& rhs );
174
176
179
181 ElementType getType() const;
183 bool isScalar() const;
185 bool isVector() const;
187 bool isProxy() const;
188
189 const std::string& proxyVarName() const { return m_varName; }
190
192 int asInt() const;
194 bool asBool() const;
195
197 template< typename T >
198 T scalarValue() const;
200 template< typename T >
201 std::vector< T > vectorValue( std::size_t sizeIfScalar = 0 );
202
204
207
210 void makeInt();
213 void makeDouble();
215 void makeVector( std::size_t n );
216
218 StackElement valueFromProxy(const EventContext& ctx) const;
220
223 private:
224 template <class T_CompHelper>
225 StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper);
226 public:
235
237
240
242 template< typename T >
243 StackElement _pow( const T& n );
282
284
285 private:
288
289 void makeVectorIfNecessary( const StackElement& other );
290 void makeVectorIfNecessary( const std::vector< int >& other );
291 void makeVectorIfNecessary( const std::vector< double >& other );
292
293 void makeDoubleIfNecessary( const StackElement& other );
294 void makeDoubleIfNecessary( int other );
295 void makeDoubleIfNecessary( double other );
296 void makeDoubleIfNecessary( const std::vector< int >& other );
297 void makeDoubleIfNecessary( const std::vector< double >& other );
298
299 void ensureCompatible( const StackElement& other ) const;
300 template< typename T >
301 void ensureCompatibleVectors( const T& other ) const;
302 template< typename T >
303 void ensureCompatibleVectors( const std::vector< T >& other ) const;
304
305 size_t size() const;
307
310
312 int m_intVal = 0;
314 double m_doubleVal = 0.;
316 std::vector< int > m_vecIntVal;
318 std::vector< double > m_vecDoubleVal;
319
321 std::string m_varName;
325 mutable std::atomic<IAccessor::VariableType> m_variableType = IProxyLoader::VT_UNK;
329 mutable std::atomic<bool> m_moved = false;
330
331 }; // class StackElement
332
334 std::ostream& operator<<( std::ostream& os, const StackElement& el );
335
336} // namespace ExpressionParsing
337
340
341#endif // EXPRESSIONEVALUATION_STACKELEMENT_H
static Double_t a
Define macros for attributes used to control the static checker.
Helper class to cache a non owning or owning pointer in an atomic way.
Class describing a single element in a text expression.
std::string m_varName
The name/definition of the variable.
int asInt() const
Get the internal value of the object as an integer.
bool isVector() const
Check if the object describes a vector value.
IProxyLoader * m_proxyLoader
Loader for the described variable.
StackElement operator+(StackElement &rhs)
Operator adding a value to the object.
StackElement _atanh()
Function taking the arc tangent hyperbolic value of the object.
std::vector< double > m_vecDoubleVal
The value of the object represented as a vector of doubles.
std::vector< T > vectorValue(std::size_t sizeIfScalar=0)
Evaluate the value of the object into the requested vector type.
StackElement & operator-=(const T &rhs)
StackElement _cos()
Function taking the cosine value of the object.
StackElement _gt(StackElement &other)
StackElement _acosh()
Function taking the arc cosine hyperbolic value of the object.
void makeDouble()
Function constructing internal double values in case integer values were given to the object initiall...
StackElement(double val)
Constructor creating the object with a double value.
StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper)
StackElement operator!()
NOT operator.
StackElement(const StackElement &a)
bool isProxy() const
Check if the object takes its value from a StoreGate object.
StackElement _tan()
Function taking the tangent value of the object.
StackElement _lt(StackElement &other)
std::atomic< bool > m_moved
Internal flag showing whether the type of the variable was already determined.
StackElement operator*(const T &rhs)
StackElement & operator=(int rhs)
Operator assigning an integer value to the object.
StackElement _asin()
Function taking the arc sinus value of the object.
StackElement operator-(const T &rhs)
StackElement _pow(const T &n)
Function raising the object's value to the n'th power.
bool asBool() const
Get the internal value of the object as a boolean.
StackElement & operator*=(StackElement &rhs)
Multiply the object by a scalar type.
StackElement & operator-=(const std::vector< T > &rhs)
Subtract a vector type from the object.
StackElement & operator+=(StackElement &rhs)
Add a scalar type to the object.
StackElement operator/(StackElement &rhs)
Operator dividing the object by a value.
StackElement & operator*=(const std::vector< T > &rhs)
Multiply the object by a vector type.
StackElement operator-(StackElement &rhs)
Operator subtracting a value from the object.
T scalarValue() const
Evaluate the value of the object into the requested scalar type.
PointerCache< IAccessor, std::memory_order_seq_cst > m_accessor ATLAS_THREAD_SAFE
StackElement _eq(StackElement &other)
bool isScalar() const
Check if the object describes a scalar value.
ElementType
Type of the data held by this object.
@ SE_UNK
The type is not known, or not applicable.
@ SE_INT
The type is an integer.
@ SE_DOUBLE
The type is a double.
@ SE_VECINT
The type is a vector of integers.
@ SE_VECDOUBLE
The type is a vector of doubles.
friend std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare the print operator as a friend of the class.
StackElement _asinh()
Function taking the arc sinus hyperbolic value of the object.
StackElement & operator-=(StackElement &rhs)
Subtract a scalar type from the object.
StackElement(unsigned int val)
Constructor creating the object with an unsigned integer value.
StackElement operator/(const T &rhs)
void makeVectorIfNecessary(const StackElement &other)
The macro is not needed anymore:
StackElement _neq(StackElement &other)
StackElement _abs()
Function taking the absolute value of the object.
StackElement valueFromProxy(const EventContext &ctx) const
Set the internal variables of the object based on the objects in SG.
StackElement _or(StackElement &other)
StackElement(int val)
Constructor creating the object with a signed integer value.
StackElement _and(StackElement &other)
StackElement & operator=(StackElement &&rhs)
StackElement & operator+=(const std::vector< T > &rhs)
Add a vector type to the object.
StackElement(const std::vector< int > &val)
Constructor creating the object with a vector of integers value.
StackElement(const std::vector< double > &val)
Constructor creating the object with a vector of doubles value.
StackElement _tanh()
Function taking the tangent hyperbolic value of the object.
StackElement _sqrt()
Function taking the square root of the object.
StackElement _sum()
Function calculating a sum value.
StackElement operator*(StackElement &rhs)
Operator multiplying the object by a value.
void ensureCompatibleVectors(const T &other) const
StackElement _cosh()
Function taking the cosine hyperbolic value of the object.
StackElement _atan()
Function taking the arc tangent value of the object.
ElementType m_type
The type of the variable held by the object.
StackElement & operator*=(const T &rhs)
StackElement _sin()
Function taking the sinus value of the object.
StackElement(StackElement &&a)
StackElement _acos()
Function taking the arc cosine value of the object.
StackElement _cbrt()
Function taking the cubic root of the object.
int m_intVal
The value of the object represented as an integer.
StackElement(std::vector< int > &&val)
Constructor creating the object with a vector of integers value.
StackElement _exp()
Function taking the natural exponent of the object.
StackElement operator-()
Inverse operator.
void makeVector(std::size_t n)
Function converting a possibly scalar value into a vector.
StackElement _count()
Function counting elements.
ElementType getType() const
Get the variable type of the object.
StackElement(const std::string &val, IProxyLoader *proxyLoader)
Constructor creating the object from a text expression.
StackElement _log()
Function taking the logarithm of the object.
StackElement & operator/=(StackElement &rhs)
Divide the object by a scalar type.
StackElement()
Default constructor.
StackElement _sinh()
Function taking the sinus hyperbolic value of the object.
void ensureCompatibleVectors(const std::vector< T > &other) const
void ensureCompatible(const StackElement &other) const
StackElement & operator/=(const std::vector< T > &rhs)
Divide the object by a vector type.
const std::string & proxyVarName() const
std::vector< int > m_vecIntVal
The value of the object represented as a vector of integers.
StackElement & operator+=(const T &rhs)
StackElement _gte(StackElement &other)
StackElement(std::vector< double > &&val)
Constructor creating the object with a vector of doubles value.
std::atomic< IAccessor::VariableType > m_variableType
Type of the variable provided by the proxy loader.
StackElement & operator/=(const T &rhs)
void makeInt()
Function constructing internal integer values in case double values were given to the object initiall...
double m_doubleVal
The value of the object represented as a double.
void makeDoubleIfNecessary(const StackElement &other)
StackElement _lte(StackElement &other)
StackElement operator+(const T &rhs)
Namespace holding all the expression evaluation code.
std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare an output operator for StackElement objects.
STL namespace.