ATLAS Offline Software
StackElement.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 
3 /*
4  Copyright (C) 2002-2021 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):
19 
30 namespace ExpressionParsing {
31 
32  // Forward declaration(s):
33  class IProxyLoader;
34 
50  class StackElement {
51 
53  friend std::ostream& operator<<( std::ostream& os,
54  const StackElement& el );
55 
56  public:
58  enum ElementType {
59  SE_UNK = 0,
60  SE_INT = 1,
61  SE_DOUBLE = 2,
62  SE_VECINT = 3,
63  SE_VECDOUBLE = 4
64  };
65 
68 
72  StackElement( unsigned int val ) : m_type( SE_INT ), m_intVal(static_cast<unsigned int>(val)) {}
78  StackElement( const std::vector< int >& val ) : m_type( SE_VECINT ), m_vecIntVal(val) {}
80  StackElement( const std::vector< double >& val ) : m_type( SE_VECDOUBLE ), m_vecDoubleVal( val ) {}
82  StackElement( std::vector< int >&& val ) : m_type( SE_VECINT ), m_vecIntVal(std::move(val)) {}
84  StackElement( std::vector< double >&& val ) : m_type( SE_VECDOUBLE ), m_vecDoubleVal( std::move(val) ) {}
86  StackElement( const std::string& val, IProxyLoader* proxyLoader ) : /*m_type( SE_UNK ), */m_varName( val ), m_proxyLoader( proxyLoader ) {}
87 ;
91 
94 
96  StackElement& operator=( int rhs );
98  StackElement& operator=( double rhs );
100  StackElement& operator=( const std::vector< int >& rhs );
102  StackElement& operator=( const std::vector< double >& rhs );
104  StackElement& operator=( std::vector< int >&& rhs );
106  StackElement& operator=( std::vector< double >&& rhs );
107 
110 
113 
118 
120 
123 
126  template< typename T >
127  StackElement& operator-=( const T& rhs );
129  template< typename T >
130  StackElement& operator-=( const std::vector< T >& rhs );
133  template< typename T >
134  StackElement& operator+=( const T& rhs );
136  template< typename T >
137  StackElement& operator+=( const std::vector< T >& rhs );
140  template< typename T >
141  StackElement& operator*=( const T& rhs );
143  template< typename T >
144  StackElement& operator*=( const std::vector< T >& rhs );
147  template< typename T >
148  StackElement& operator/=( const T& rhs );
150  template< typename T >
151  StackElement& operator/=( const std::vector< T >& rhs );
152 
155  template< typename T >
156  StackElement operator-( const T& rhs );
159  template< typename T >
160  StackElement operator+( const T& rhs );
163  template< typename T >
164  StackElement operator*( const T& rhs );
167  template< typename T >
168  StackElement operator/( const T& rhs );
169 
171 
174 
176  ElementType getType() const;
178  bool isScalar() const;
180  bool isVector() const;
182  bool isProxy() const;
183 
184  const std::string proxyVarName() const { return m_varName; }
185 
187  int asInt() const;
189  bool asBool() const;
190 
192  template< typename T >
193  T scalarValue() const;
195  template< typename T >
196  std::vector< T > vectorValue( std::size_t sizeIfScalar = 0 );
197 
199 
202 
205  void makeInt();
208  void makeDouble();
210  void makeVector( std::size_t n );
211 
215 
218  private:
219  template <class T_CompHelper>
220  StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper);
221  public:
230 
232 
235 
237  template< typename T >
238  StackElement _pow( const T& n );
240  StackElement _sum();
244  StackElement _abs();
277 
279 
280  private:
283 
285  void makeVectorIfNecessary( const std::vector< int >& other );
286  void makeVectorIfNecessary( const std::vector< double >& other );
287 
289  void makeDoubleIfNecessary( int other );
290  void makeDoubleIfNecessary( double other );
291  void makeDoubleIfNecessary( const std::vector< int >& other );
292  void makeDoubleIfNecessary( const std::vector< double >& other );
293 
294  void ensureCompatible( const StackElement& other ) const;
295  template< typename T >
296  void ensureCompatibleVectors( const T& other ) const;
297  template< typename T >
298  void ensureCompatibleVectors( const std::vector< T >& other ) const;
299 
300  size_t size() const;
302 
305 
307  int m_intVal = 0;
309  double m_doubleVal = 0.;
311  std::vector< int > m_vecIntVal;
313  std::vector< double > m_vecDoubleVal;
314 
316  std::string m_varName;
320  mutable std::atomic<IProxyLoader::VariableType> m_variableType = IProxyLoader::VT_UNK;
323  mutable std::atomic<bool> m_determinedVariableType = false;
324  mutable std::atomic<bool> m_moved = false;
325 
326  }; // class StackElement
327 
329  std::ostream& operator<<( std::ostream& os, const StackElement& el );
330 
331 } // namespace ExpressionParsing
332 
335 
336 #endif // EXPRESSIONEVALUATION_STACKELEMENT_H
ExpressionParsing::StackElement::StackElement
StackElement(int val)
Constructor creating the object with a signed integer value.
Definition: StackElement.h:74
ExpressionParsing::StackElement::operator*=
StackElement & operator*=(StackElement &rhs)
Multiply the object by a scalar type.
ExpressionParsing::StackElement::_atan
StackElement _atan()
Function taking the arc tangent value of the object.
ExpressionParsing::StackElement::ElementType
ElementType
Type of the data held by this object.
Definition: StackElement.h:58
ExpressionParsing::StackElement::_sum
StackElement _sum()
Function calculating a sum value.
Definition: StackElement.cxx:525
ExpressionParsing::StackElement::operator+=
StackElement & operator+=(const T &rhs)
ExpressionParsing::StackElement::operator*=
StackElement & operator*=(const T &rhs)
ExpressionParsing::StackElement::_exp
StackElement _exp()
Function taking the natural exponent of the object.
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ExpressionParsing::StackElement::operator*
StackElement operator*(StackElement &rhs)
Operator multiplying the object by a value.
ExpressionParsing::StackElement::operator-
StackElement operator-(const T &rhs)
ExpressionParsing::StackElement::isProxy
bool isProxy() const
Check if the object takes its value from a StoreGate object.
Definition: StackElement.cxx:241
ExpressionParsing::StackElement::valueFromProxy
StackElement valueFromProxy() const
Set the internal variables of the object based on the objects in SG.
Definition: StackElement.cxx:382
ExpressionParsing::StackElement::_acosh
StackElement _acosh()
Function taking the arc cosine hyperbolic value of the object.
ExpressionParsing::StackElement::makeVectorIfNecessary
void makeVectorIfNecessary(const StackElement &other)
The macro is not needed anymore:
Definition: StackElement.cxx:680
ExpressionParsing::StackElement::getType
ElementType getType() const
Get the variable type of the object.
Definition: StackElement.cxx:226
ExpressionParsing::StackElement::m_vecIntVal
std::vector< int > m_vecIntVal
The value of the object represented as a vector of integers.
Definition: StackElement.h:311
ExpressionParsing::StackElement::operator<<
friend std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare the print operator as a friend of the class.
Definition: StackElement.cxx:775
ExpressionParsing::StackElement::ensureCompatibleVectors
void ensureCompatibleVectors(const T &other) const
ExpressionParsing::StackElement::SE_DOUBLE
@ SE_DOUBLE
The type is a double.
Definition: StackElement.h:61
ExpressionParsing::StackElement::proxyVarName
const std::string proxyVarName() const
Definition: StackElement.h:184
ExpressionParsing::StackElement::_pow
StackElement _pow(const T &n)
Function raising the object's value to the n'th power.
ExpressionParsing::StackElement::_log
StackElement _log()
Function taking the logarithm of the object.
ExpressionParsing::StackElement::_cos
StackElement _cos()
Function taking the cosine value of the object.
ExpressionParsing::StackElement::makeDoubleIfNecessary
void makeDoubleIfNecessary(const StackElement &other)
Definition: StackElement.cxx:713
ExpressionParsing::StackElement::_neq
StackElement _neq(StackElement &other)
Definition: StackElement.cxx:506
ExpressionParsing::StackElement::_acos
StackElement _acos()
Function taking the arc cosine value of the object.
ExpressionParsing::StackElement::operator*=
StackElement & operator*=(const std::vector< T > &rhs)
Multiply the object by a vector type.
ExpressionParsing::StackElement::scalarValue
T scalarValue() const
Evaluate the value of the object into the requested scalar type.
ExpressionParsing::StackElement::operator+
StackElement operator+(const T &rhs)
ExpressionParsing::StackElement::_asin
StackElement _asin()
Function taking the arc sinus value of the object.
ExpressionParsing::StackElement::operator-=
StackElement & operator-=(const T &rhs)
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
ExpressionParsing::StackElement::_and
StackElement _and(StackElement &other)
Definition: StackElement.cxx:507
ExpressionParsing::StackElement::StackElement
StackElement(const std::vector< int > &val)
Constructor creating the object with a vector of integers value.
Definition: StackElement.h:78
ExpressionParsing::StackElement::makeDouble
void makeDouble()
Function constructing internal double values in case integer values were given to the object initiall...
Definition: StackElement.cxx:347
ExpressionParsing::IProxyLoader
Definition: IProxyLoader.h:19
ExpressionParsing::StackElement::vectorValue
std::vector< T > vectorValue(std::size_t sizeIfScalar=0)
Evaluate the value of the object into the requested vector type.
ExpressionParsing::StackElement::_atanh
StackElement _atanh()
Function taking the arc tangent hyperbolic value of the object.
ExpressionParsing::StackElement::StackElement
StackElement(std::vector< int > &&val)
Constructor creating the object with a vector of integers value.
Definition: StackElement.h:82
ExpressionParsing::StackElement::makeInt
void makeInt()
Function constructing internal integer values in case double values were given to the object initiall...
Definition: StackElement.cxx:331
ExpressionParsing::StackElement::StackElement
StackElement(const std::vector< double > &val)
Constructor creating the object with a vector of doubles value.
Definition: StackElement.h:80
ExpressionParsing::StackElement::operator+=
StackElement & operator+=(const std::vector< T > &rhs)
Add a vector type to the object.
ExpressionParsing::StackElement::operator/
StackElement operator/(StackElement &rhs)
Operator dividing the object by a value.
ExpressionParsing::StackElement::_lt
StackElement _lt(StackElement &other)
Definition: StackElement.cxx:511
ExpressionParsing::StackElement::operator/=
StackElement & operator/=(const std::vector< T > &rhs)
Divide the object by a vector type.
ExpressionParsing::IProxyLoader::VT_UNK
@ VT_UNK
Definition: IProxyLoader.h:21
ExpressionParsing::StackElement::StackElement
StackElement(double val)
Constructor creating the object with a double value.
Definition: StackElement.h:76
ExpressionParsing::StackElement::operator-=
StackElement & operator-=(StackElement &rhs)
Subtract a scalar type from the object.
ExpressionParsing::StackElement::_sinh
StackElement _sinh()
Function taking the sinus hyperbolic value of the object.
ExpressionParsing::StackElement::_cbrt
StackElement _cbrt()
Function taking the cubic root of the object.
beamspotman.n
n
Definition: beamspotman.py:731
ExpressionParsing::StackElement::isVector
bool isVector() const
Check if the object describes a vector value.
Definition: StackElement.cxx:236
ExpressionParsing::StackElement::_or
StackElement _or(StackElement &other)
Definition: StackElement.cxx:508
ExpressionParsing::StackElement::m_determinedVariableType
std::atomic< bool > m_determinedVariableType
Internal flag showing whether the type of the variable was already determined.
Definition: StackElement.h:323
ExpressionParsing::StackElement::size
size_t size() const
ExpressionParsing
Namespace holding all the expression evaluation code.
Definition: ExpressionParser.h:26
ExpressionParsing::StackElement::operator=
StackElement & operator=(StackElement &&rhs)
ExpressionParsing::StackElement::asInt
int asInt() const
Get the internal value of the object as an integer.
Definition: StackElement.cxx:246
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
ExpressionParsing::StackElement::m_doubleVal
double m_doubleVal
The value of the object represented as a double.
Definition: StackElement.h:309
ExpressionParsing::StackElement::StackElement
StackElement(std::vector< double > &&val)
Constructor creating the object with a vector of doubles value.
Definition: StackElement.h:84
ExpressionParsing::StackElement::StackElement
StackElement(const StackElement &a)
ExpressionParsing::StackElement::m_variableType
std::atomic< IProxyLoader::VariableType > m_variableType
Type of the variable provided by the proxy loader.
Definition: StackElement.h:320
ExpressionParsing::StackElement::m_varName
std::string m_varName
The name/definition of the variable.
Definition: StackElement.h:316
ExpressionParsing::StackElement::operator-
StackElement operator-()
Inverse operator.
Definition: StackElement.cxx:152
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
ExpressionParsing::StackElement::_gt
StackElement _gt(StackElement &other)
Definition: StackElement.cxx:509
ExpressionParsing::StackElement::SE_VECINT
@ SE_VECINT
The type is a vector of integers.
Definition: StackElement.h:62
ExpressionParsing::operator<<
std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare an output operator for StackElement objects.
Definition: StackElement.cxx:775
ExpressionParsing::StackElement::operator!
StackElement operator!()
NOT operator.
Definition: StackElement.cxx:110
ExpressionParsing::StackElement::m_vecDoubleVal
std::vector< double > m_vecDoubleVal
The value of the object represented as a vector of doubles.
Definition: StackElement.h:313
ExpressionParsing::StackElement::operator*
StackElement operator*(const T &rhs)
ExpressionParsing::StackElement::_abs
StackElement _abs()
Function taking the absolute value of the object.
Definition: StackElement.cxx:601
ExpressionParsing::StackElement::m_proxyLoader
IProxyLoader * m_proxyLoader
Loader for the described variable.
Definition: StackElement.h:318
ExpressionParsing::StackElement::m_type
ElementType m_type
The type of the variable held by the object.
Definition: StackElement.h:304
ExpressionParsing::StackElement::_lte
StackElement _lte(StackElement &other)
Definition: StackElement.cxx:512
ExpressionParsing::StackElement::_sqrt
StackElement _sqrt()
Function taking the square root of the object.
ExpressionParsing::StackElement::asBool
bool asBool() const
Get the internal value of the object as a boolean.
Definition: StackElement.cxx:255
ExpressionParsing::StackElement::isScalar
bool isScalar() const
Check if the object describes a scalar value.
Definition: StackElement.cxx:231
ExpressionParsing::StackElement::operator/
StackElement operator/(const T &rhs)
ExpressionParsing::StackElement::StackElement
StackElement()
Default constructor.
Definition: StackElement.h:70
ExpressionParsing::StackElement::_eq
StackElement _eq(StackElement &other)
Definition: StackElement.cxx:505
ExpressionParsing::StackElement::operator=
StackElement & operator=(int rhs)
Operator assigning an integer value to the object.
Definition: StackElement.cxx:39
a
TList * a
Definition: liststreamerinfos.cxx:10
ExpressionParsing::StackElement::StackElement
StackElement(unsigned int val)
Constructor creating the object with an unsigned integer value.
Definition: StackElement.h:72
ExpressionParsing::StackElement::SE_VECDOUBLE
@ SE_VECDOUBLE
The type is a vector of doubles.
Definition: StackElement.h:63
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
StackElement.icc
ExpressionParsing::StackElement::_cosh
StackElement _cosh()
Function taking the cosine hyperbolic value of the object.
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ExpressionParsing::StackElement::_gte
StackElement _gte(StackElement &other)
Definition: StackElement.cxx:510
ExpressionParsing::StackElement::SE_UNK
@ SE_UNK
The type is not known, or not applicable.
Definition: StackElement.h:59
ExpressionParsing::StackElement::operator/=
StackElement & operator/=(const T &rhs)
ExpressionParsing::StackElement::_sin
StackElement _sin()
Function taking the sinus value of the object.
ExpressionParsing::StackElement::_tan
StackElement _tan()
Function taking the tangent value of the object.
ExpressionParsing::StackElement::StackElement
StackElement(const std::string &val, IProxyLoader *proxyLoader)
Constructor creating the object from a text expression.
Definition: StackElement.h:86
ExpressionParsing::StackElement
Class describing a single element in a text expression.
Definition: StackElement.h:50
ExpressionParsing::StackElement::_asinh
StackElement _asinh()
Function taking the arc sinus hyperbolic value of the object.
ExpressionParsing::StackElement::_count
StackElement _count()
Function counting elements.
Definition: StackElement.cxx:563
ExpressionParsing::StackElement::m_moved
std::atomic< bool > m_moved
Definition: StackElement.h:324
ExpressionParsing::StackElement::m_intVal
int m_intVal
The value of the object represented as an integer.
Definition: StackElement.h:307
ExpressionParsing::StackElement::StackElement
StackElement(StackElement &&a)
ExpressionParsing::StackElement::operator-=
StackElement & operator-=(const std::vector< T > &rhs)
Subtract a vector type from the object.
ExpressionParsing::StackElement::operator-
StackElement operator-(StackElement &rhs)
Operator subtracting a value from the object.
ExpressionParsing::StackElement::operator/=
StackElement & operator/=(StackElement &rhs)
Divide the object by a scalar type.
IProxyLoader.h
ExpressionParsing::StackElement::operator+
StackElement operator+(StackElement &rhs)
Operator adding a value to the object.
ExpressionParsing::StackElement::_comparisonOp
StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper)
Definition: StackElement.cxx:466
ExpressionParsing::StackElement::_tanh
StackElement _tanh()
Function taking the tangent hyperbolic value of the object.
ExpressionParsing::StackElement::ensureCompatibleVectors
void ensureCompatibleVectors(const std::vector< T > &other) const
ExpressionParsing::StackElement::ensureCompatible
void ensureCompatible(const StackElement &other) const
Definition: StackElement.cxx:752
ExpressionParsing::StackElement::SE_INT
@ SE_INT
The type is an integer.
Definition: StackElement.h:60
ExpressionParsing::StackElement::operator+=
StackElement & operator+=(StackElement &rhs)
Add a scalar type to the object.
ExpressionParsing::StackElement::makeVector
void makeVector(std::size_t n)
Function converting a possibly scalar value into a vector.
Definition: StackElement.cxx:363