ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
ExpressionParsing::StackElement Class Reference

Class describing a single element in a text expression. More...

#include <StackElement.h>

Collaboration diagram for ExpressionParsing::StackElement:

Public Types

enum  ElementType {
  SE_UNK = 0, SE_INT = 1, SE_DOUBLE = 2, SE_VECINT = 3,
  SE_VECDOUBLE = 4
}
 Type of the data held by this object. More...
 

Public Member Functions

template<>
std::vector< int > vectorValue (std::size_t sizeIfScalar)
 
template<>
std::vector< double > vectorValue (size_t sizeIfScalar)
 
template<>
StackElement _pow (const StackElement &n)
 
template<>
void ensureCompatibleVectors (const StackElement &other) const
 
Constructor definitions
 StackElement ()
 Default constructor. More...
 
 StackElement (unsigned int val)
 Constructor creating the object with an unsigned integer value. More...
 
 StackElement (int val)
 Constructor creating the object with a signed integer value. More...
 
 StackElement (double val)
 Constructor creating the object with a double value. More...
 
 StackElement (const std::vector< int > &val)
 Constructor creating the object with a vector of integers value. More...
 
 StackElement (const std::vector< double > &val)
 Constructor creating the object with a vector of doubles value. More...
 
 StackElement (std::vector< int > &&val)
 Constructor creating the object with a vector of integers value. More...
 
 StackElement (std::vector< double > &&val)
 Constructor creating the object with a vector of doubles value. More...
 
 StackElement (const std::string &val, IProxyLoader *proxyLoader)
 Constructor creating the object from a text expression. More...
 
 StackElement (const StackElement &a)
 
 StackElement (StackElement &&a)
 
Assignment operators
StackElementoperator= (int rhs)
 Operator assigning an integer value to the object. More...
 
StackElementoperator= (double rhs)
 Operator assigning a double value to the object. More...
 
StackElementoperator= (const std::vector< int > &rhs)
 Operator assigning a vector of integers to the object. More...
 
StackElementoperator= (const std::vector< double > &rhs)
 Operator assigning a vector of doubles to the object. More...
 
StackElementoperator= (std::vector< int > &&rhs)
 Operator assigning a vector of integers to the object. More...
 
StackElementoperator= (std::vector< double > &&rhs)
 Operator assigning a vector of doubles to the object. More...
 
StackElementoperator= (StackElement &&rhs)
 
Comparison and logical operators
StackElement operator! ()
 NOT operator. More...
 
StackElement operator- ()
 Inverse operator. More...
 
Modifier operators
StackElementoperator-= (StackElement &rhs)
 Subtract a scalar type from the object. More...
 
template<typename T >
StackElementoperator-= (const T &rhs)
 
template<typename T >
StackElementoperator-= (const std::vector< T > &rhs)
 Subtract a vector type from the object. More...
 
StackElementoperator+= (StackElement &rhs)
 Add a scalar type to the object. More...
 
template<typename T >
StackElementoperator+= (const T &rhs)
 
template<typename T >
StackElementoperator+= (const std::vector< T > &rhs)
 Add a vector type to the object. More...
 
StackElementoperator*= (StackElement &rhs)
 Multiply the object by a scalar type. More...
 
template<typename T >
StackElementoperator*= (const T &rhs)
 
template<typename T >
StackElementoperator*= (const std::vector< T > &rhs)
 Multiply the object by a vector type. More...
 
StackElementoperator/= (StackElement &rhs)
 Divide the object by a scalar type. More...
 
template<typename T >
StackElementoperator/= (const T &rhs)
 
template<typename T >
StackElementoperator/= (const std::vector< T > &rhs)
 Divide the object by a vector type. More...
 
StackElement operator- (StackElement &rhs)
 Operator subtracting a value from the object. More...
 
template<typename T >
StackElement operator- (const T &rhs)
 
StackElement operator+ (StackElement &rhs)
 Operator adding a value to the object. More...
 
template<typename T >
StackElement operator+ (const T &rhs)
 
StackElement operator* (StackElement &rhs)
 Operator multiplying the object by a value. More...
 
template<typename T >
StackElement operator* (const T &rhs)
 
StackElement operator/ (StackElement &rhs)
 Operator dividing the object by a value. More...
 
template<typename T >
StackElement operator/ (const T &rhs)
 
Accessor functions
ElementType getType () const
 Get the variable type of the object. More...
 
bool isScalar () const
 Check if the object describes a scalar value. More...
 
bool isVector () const
 Check if the object describes a vector value. More...
 
bool isProxy () const
 Check if the object takes its value from a StoreGate object. More...
 
const std::string & proxyVarName () const
 
int asInt () const
 Get the internal value of the object as an integer. More...
 
bool asBool () const
 Get the internal value of the object as a boolean. More...
 
template<typename T >
scalarValue () const
 Evaluate the value of the object into the requested scalar type. More...
 
template<typename T >
std::vector< T > vectorValue (std::size_t sizeIfScalar=0)
 Evaluate the value of the object into the requested vector type. More...
 
Modifier functions
void makeInt ()
 Function constructing internal integer values in case double values were given to the object initially. More...
 
void makeDouble ()
 Function constructing internal double values in case integer values were given to the object initially. More...
 
void makeVector (std::size_t n)
 Function converting a possibly scalar value into a vector. More...
 
StackElement valueFromProxy () const
 Set the internal variables of the object based on the objects in SG. More...
 
Internal functions evaluating mathematical operations
template<typename T >
StackElement _pow (const T &n)
 Function raising the object's value to the n'th power. More...
 
StackElement _sum ()
 Function calculating a sum value. More...
 
StackElement _count ()
 Function counting elements. More...
 
StackElement _abs ()
 Function taking the absolute value of the object. More...
 
StackElement _sqrt ()
 Function taking the square root of the object. More...
 
StackElement _cbrt ()
 Function taking the cubic root of the object. More...
 
StackElement _sin ()
 Function taking the sinus value of the object. More...
 
StackElement _cos ()
 Function taking the cosine value of the object. More...
 
StackElement _tan ()
 Function taking the tangent value of the object. More...
 
StackElement _asin ()
 Function taking the arc sinus value of the object. More...
 
StackElement _acos ()
 Function taking the arc cosine value of the object. More...
 
StackElement _atan ()
 Function taking the arc tangent value of the object. More...
 
StackElement _sinh ()
 Function taking the sinus hyperbolic value of the object. More...
 
StackElement _cosh ()
 Function taking the cosine hyperbolic value of the object. More...
 
StackElement _tanh ()
 Function taking the tangent hyperbolic value of the object. More...
 
StackElement _asinh ()
 Function taking the arc sinus hyperbolic value of the object. More...
 
StackElement _acosh ()
 Function taking the arc cosine hyperbolic value of the object. More...
 
StackElement _atanh ()
 Function taking the arc tangent hyperbolic value of the object. More...
 
StackElement _log ()
 Function taking the logarithm of the object. More...
 
StackElement _exp ()
 Function taking the natural exponent of the object. More...
 

Private Member Functions

Internal operations on the object
void makeVectorIfNecessary (const StackElement &other)
 The macro is not needed anymore: More...
 
void makeVectorIfNecessary (const std::vector< int > &other)
 
void makeVectorIfNecessary (const std::vector< double > &other)
 
void makeDoubleIfNecessary (const StackElement &other)
 
void makeDoubleIfNecessary (int other)
 
void makeDoubleIfNecessary (double other)
 
void makeDoubleIfNecessary (const std::vector< int > &other)
 
void makeDoubleIfNecessary (const std::vector< double > &other)
 
void ensureCompatible (const StackElement &other) const
 
template<typename T >
void ensureCompatibleVectors (const T &other) const
 
template<typename T >
void ensureCompatibleVectors (const std::vector< T > &other) const
 
size_t size () const
 

Private Attributes

ElementType m_type = SE_UNK
 The type of the variable held by the object. More...
 
int m_intVal = 0
 The value of the object represented as an integer. More...
 
double m_doubleVal = 0.
 The value of the object represented as a double. More...
 
std::vector< int > m_vecIntVal
 The value of the object represented as a vector of integers. More...
 
std::vector< double > m_vecDoubleVal
 The value of the object represented as a vector of doubles. More...
 
std::string m_varName
 The name/definition of the variable. More...
 
IProxyLoaderm_proxyLoader = nullptr
 Loader for the described variable. More...
 
std::atomic< IProxyLoader::VariableTypem_variableType = IProxyLoader::VT_UNK
 Type of the variable provided by the proxy loader. More...
 
std::atomic< bool > m_determinedVariableType = false
 Internal flag showing whether the type of the variable was already determined. More...
 
std::atomic< bool > m_moved = false
 

Friends

std::ostream & operator<< (std::ostream &os, const StackElement &el)
 Declare the print operator as a friend of the class. More...
 

Internal functions evaluating binary comparisons

StackElement _eq (StackElement &other)
 
StackElement _neq (StackElement &other)
 
StackElement _and (StackElement &other)
 
StackElement _or (StackElement &other)
 
StackElement _gt (StackElement &other)
 
StackElement _gte (StackElement &other)
 
StackElement _lt (StackElement &other)
 
StackElement _lte (StackElement &other)
 
template<class T_CompHelper >
StackElement _comparisonOp (StackElement &other, T_CompHelper comp_helper)
 

Detailed Description

Class describing a single element in a text expression.

A vector of such objects is used to describe a full text expression. As such, it's able to perform all the operations that can be described in a text expression. Most operations are destructive i.e. vector content will be modified and moved on operations. This is to reduce the number of vector copy operations. Thus, if the content should be preserved, a copy needs to be created and the operation should be applied to the copy.

Author
Thomas Gillam (thoma.nosp@m.s.gi.nosp@m.llam@.nosp@m.cern.nosp@m..ch)

$Revision$ $Date$

Definition at line 50 of file StackElement.h.

Member Enumeration Documentation

◆ ElementType

enum ExpressionParsing::StackElement::ElementType

Type of the data held by this object.

Enumerator
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.

Definition at line 58 of file StackElement.h.

58  {
59  SE_UNK = 0,
60  SE_INT = 1,
61  SE_DOUBLE = 2,
62  SE_VECINT = 3,
63  SE_VECDOUBLE = 4
64  };

Constructor & Destructor Documentation

◆ StackElement() [1/11]

ExpressionParsing::StackElement::StackElement ( )
inline

Default constructor.

Definition at line 70 of file StackElement.h.

70 {};

◆ StackElement() [2/11]

ExpressionParsing::StackElement::StackElement ( unsigned int  val)
inline

Constructor creating the object with an unsigned integer value.

Definition at line 72 of file StackElement.h.

72 : m_type( SE_INT ), m_intVal(static_cast<unsigned int>(val)) {}

◆ StackElement() [3/11]

ExpressionParsing::StackElement::StackElement ( int  val)
inline

Constructor creating the object with a signed integer value.

Definition at line 74 of file StackElement.h.

74 : m_type( SE_INT ), m_intVal(val) {}

◆ StackElement() [4/11]

ExpressionParsing::StackElement::StackElement ( double  val)
inline

Constructor creating the object with a double value.

Definition at line 76 of file StackElement.h.

76 : m_type( SE_DOUBLE ), m_doubleVal( val ) {}

◆ StackElement() [5/11]

ExpressionParsing::StackElement::StackElement ( const std::vector< int > &  val)
inline

Constructor creating the object with a vector of integers value.

Definition at line 78 of file StackElement.h.

◆ StackElement() [6/11]

ExpressionParsing::StackElement::StackElement ( const std::vector< double > &  val)
inline

Constructor creating the object with a vector of doubles value.

Definition at line 80 of file StackElement.h.

◆ StackElement() [7/11]

ExpressionParsing::StackElement::StackElement ( std::vector< int > &&  val)
inline

Constructor creating the object with a vector of integers value.

Definition at line 82 of file StackElement.h.

82 : m_type( SE_VECINT ), m_vecIntVal(std::move(val)) {}

◆ StackElement() [8/11]

ExpressionParsing::StackElement::StackElement ( std::vector< double > &&  val)
inline

Constructor creating the object with a vector of doubles value.

Definition at line 84 of file StackElement.h.

84 : m_type( SE_VECDOUBLE ), m_vecDoubleVal( std::move(val) ) {}

◆ StackElement() [9/11]

ExpressionParsing::StackElement::StackElement ( const std::string &  val,
IProxyLoader proxyLoader 
)
inline

Constructor creating the object from a text expression.

Definition at line 86 of file StackElement.h.

86 : /*m_type( SE_UNK ), */m_varName( val ), m_proxyLoader( proxyLoader ) {}

◆ StackElement() [10/11]

ExpressionParsing::StackElement::StackElement ( const StackElement a)

◆ StackElement() [11/11]

ExpressionParsing::StackElement::StackElement ( StackElement &&  a)

Member Function Documentation

◆ _abs()

StackElement ExpressionParsing::StackElement::_abs ( )

Function taking the absolute value of the object.

Definition at line 601 of file StackElement.cxx.

601  {
602  if (this->m_moved) throw std::logic_error("Content already moved");
603 
604  StackElement temp(std::move(*this));
605  this->m_moved=true;
606  switch( m_type ) {
607 
608  case SE_INT:
609  m_intVal = std::abs( temp.m_intVal );
610  break;
611 
612  case SE_DOUBLE:
613  m_doubleVal = std::abs( temp.m_doubleVal );
614  break;
615 
616  case SE_VECINT:
617  {
618  for( int &value : temp.m_vecIntVal ) {
619  value = std::abs( value );
620  }
621  }
622  break;
623 
624  case SE_VECDOUBLE:
625  {
626  for( double &value : temp.m_vecDoubleVal ) {
627  value = std::abs( value );
628  }
629  }
630  break;
631 
632  default:
633  // @throw exception ?
634  break;
635  }
636  return temp;
637  }

◆ _acos()

StackElement ExpressionParsing::StackElement::_acos ( )

Function taking the arc cosine value of the object.

◆ _acosh()

StackElement ExpressionParsing::StackElement::_acosh ( )

Function taking the arc cosine hyperbolic value of the object.

◆ _and()

StackElement ExpressionParsing::StackElement::_and ( StackElement other)

Definition at line 507 of file StackElement.cxx.

507 { return _comparisonOp(b, Helper_and()); }

◆ _asin()

StackElement ExpressionParsing::StackElement::_asin ( )

Function taking the arc sinus value of the object.

◆ _asinh()

StackElement ExpressionParsing::StackElement::_asinh ( )

Function taking the arc sinus hyperbolic value of the object.

◆ _atan()

StackElement ExpressionParsing::StackElement::_atan ( )

Function taking the arc tangent value of the object.

◆ _atanh()

StackElement ExpressionParsing::StackElement::_atanh ( )

Function taking the arc tangent hyperbolic value of the object.

◆ _cbrt()

StackElement ExpressionParsing::StackElement::_cbrt ( )

Function taking the cubic root of the object.

◆ _comparisonOp()

template<class T_CompHelper >
StackElement ExpressionParsing::StackElement::_comparisonOp ( StackElement other,
T_CompHelper  comp_helper 
)
private

Definition at line 466 of file StackElement.cxx.

467  {
468  if (m_type ==SE_UNK || other.m_type==SE_UNK) {
469  throw std::runtime_error( "ERROR: Can't operate on SE_UNK "
470  "StackElements");
471  }
472  if( isScalar() && other.isScalar() ) {
473  if( m_type == SE_INT && other.m_type == SE_INT ) {
474  return comp_helper.compare(scalarValue< int >(),other.scalarValue< int >() );
475  } else {
476  return comp_helper.compare(scalarValue< double >(),other.scalarValue< double >() );
477  }
478  } else {
479  if (isVector() && other.isVector() && this->size() != other.size()) {
480  throw std::runtime_error( "Incompatible vectors - different length" );
481  }
482  std::size_t the_size = ( m_type == SE_VECINT || m_type==SE_VECDOUBLE) ? this->size() : other.size();
483  if( ( m_type == SE_VECINT)
484  && ( other.m_type == SE_VECINT || other.m_type == SE_INT )) {
485  return compareVector( this->vectorValue<int>(the_size) , other.vectorValue< int >(the_size), comp_helper );
486  }
487  else if( m_type == SE_INT && other.m_type == SE_VECINT) {
488  return compareVectorAlt( this->vectorValue<int>(the_size) , other.vectorValue< int >(the_size), comp_helper );
489  }
490  else {
491  return compareVector( this->vectorValue<double>(the_size) , other.vectorValue< double >(the_size), comp_helper );
492  }
493  }
494  }

◆ _cos()

StackElement ExpressionParsing::StackElement::_cos ( )

Function taking the cosine value of the object.

◆ _cosh()

StackElement ExpressionParsing::StackElement::_cosh ( )

Function taking the cosine hyperbolic value of the object.

◆ _count()

StackElement ExpressionParsing::StackElement::_count ( )

Function counting elements.

Definition at line 563 of file StackElement.cxx.

563  {
564 
565  switch( m_type ) {
566 
567  case SE_INT:
568  return !!( m_intVal );
569  break;
570 
571  case SE_DOUBLE:
572  return !!( m_doubleVal );
573  break;
574 
575  case SE_VECINT:
576  {
577  int total = 0;
578  for( int value : m_vecIntVal ) {
579  total += !!value;
580  }
581  return total;
582  }
583  break;
584 
585  case SE_VECDOUBLE:
586  {
587  int total = 0;
588  for( double value : m_vecDoubleVal ) {
589  total += !!value;
590  }
591  return total;
592  }
593  break;
594 
595  default:
596  return 0;
597  break;
598  }
599  }

◆ _eq()

StackElement ExpressionParsing::StackElement::_eq ( StackElement other)

Definition at line 505 of file StackElement.cxx.

505 { return _comparisonOp(b, Helper_eq()); }

◆ _exp()

StackElement ExpressionParsing::StackElement::_exp ( )

Function taking the natural exponent of the object.

◆ _gt()

StackElement ExpressionParsing::StackElement::_gt ( StackElement other)

Definition at line 509 of file StackElement.cxx.

509 { return _comparisonOp(b, Helper_gt()); }

◆ _gte()

StackElement ExpressionParsing::StackElement::_gte ( StackElement other)

Definition at line 510 of file StackElement.cxx.

510 { return _comparisonOp(b, Helper_gte()); }

◆ _log()

StackElement ExpressionParsing::StackElement::_log ( )

Function taking the logarithm of the object.

◆ _lt()

StackElement ExpressionParsing::StackElement::_lt ( StackElement other)

Definition at line 511 of file StackElement.cxx.

511 { return _comparisonOp(b, Helper_lt()); }

◆ _lte()

StackElement ExpressionParsing::StackElement::_lte ( StackElement other)

Definition at line 512 of file StackElement.cxx.

512 { return _comparisonOp(b, Helper_lte()); }

◆ _neq()

StackElement ExpressionParsing::StackElement::_neq ( StackElement other)

Definition at line 506 of file StackElement.cxx.

506 { return _comparisonOp(b, Helper_neq()); }

◆ _or()

StackElement ExpressionParsing::StackElement::_or ( StackElement other)

Definition at line 508 of file StackElement.cxx.

508 { return _comparisonOp(b, Helper_or()); }

◆ _pow() [1/2]

template<>
StackElement ExpressionParsing::StackElement::_pow ( const StackElement n)

Definition at line 516 of file StackElement.cxx.

516  {
517 
518  if( n.isVector() ) {
519  throw std::runtime_error( "Can't use vector as exponent" );
520  } else {
521  return _pow( n.scalarValue< double >() );
522  }
523  }

◆ _pow() [2/2]

template<typename T >
StackElement ExpressionParsing::StackElement::_pow ( const T &  n)

Function raising the object's value to the n'th power.

◆ _sin()

StackElement ExpressionParsing::StackElement::_sin ( )

Function taking the sinus value of the object.

◆ _sinh()

StackElement ExpressionParsing::StackElement::_sinh ( )

Function taking the sinus hyperbolic value of the object.

◆ _sqrt()

StackElement ExpressionParsing::StackElement::_sqrt ( )

Function taking the square root of the object.

◆ _sum()

StackElement ExpressionParsing::StackElement::_sum ( )

Function calculating a sum value.

Definition at line 525 of file StackElement.cxx.

525  {
526 
527  switch( m_type ) {
528 
529  case SE_INT:
530  return m_intVal;
531  break;
532 
533  case SE_DOUBLE:
534  return m_doubleVal;
535  break;
536 
537  case SE_VECINT:
538  {
539  int total = 0;
540  for( int value : m_vecIntVal ) {
541  total += value;
542  }
543  return total;
544  }
545  break;
546 
547  case SE_VECDOUBLE:
548  {
549  double total = 0.0;
550  for( double value : m_vecDoubleVal ) {
551  total += value;
552  }
553  return total;
554  }
555  break;
556 
557  default:
558  return 0;
559  break;
560  }
561  }

◆ _tan()

StackElement ExpressionParsing::StackElement::_tan ( )

Function taking the tangent value of the object.

◆ _tanh()

StackElement ExpressionParsing::StackElement::_tanh ( )

Function taking the tangent hyperbolic value of the object.

◆ asBool()

bool ExpressionParsing::StackElement::asBool ( ) const

Get the internal value of the object as a boolean.

Definition at line 255 of file StackElement.cxx.

255  {
256 
257  if( ! ( ( m_type == SE_INT ) || ( m_type == SE_DOUBLE ) ) ) {
258  throw std::runtime_error( "asBool() only valid for non-vector types" );
259  }
260 
261  return scalarValue< bool >();
262  }

◆ asInt()

int ExpressionParsing::StackElement::asInt ( ) const

Get the internal value of the object as an integer.

Definition at line 246 of file StackElement.cxx.

246  {
247 
248  if( m_type != SE_INT ) {
249  throw std::runtime_error( "asInt() only valid for SE_INT" );
250  }
251 
252  return scalarValue< int >();
253  }

◆ ensureCompatible()

void ExpressionParsing::StackElement::ensureCompatible ( const StackElement other) const
private

Definition at line 752 of file StackElement.cxx.

752  {
753 
754  if( this->m_type != other.m_type ) {
755  throw std::runtime_error( "Incompatible stack elements" );
756  }
757 
758  return;
759  }

◆ ensureCompatibleVectors() [1/3]

template<>
void ExpressionParsing::StackElement::ensureCompatibleVectors ( const StackElement other) const

Definition at line 763 of file StackElement.cxx.

763  {
764 
765  if( isScalar() ) {
766  return;
767  }
768 
769  const std::size_t ourlen = size();
770  if( ourlen != other.size() ) {
771  throw std::runtime_error( "Incompatible vectors - different length" );
772  }
773  }

◆ ensureCompatibleVectors() [2/3]

template<typename T >
void ExpressionParsing::StackElement::ensureCompatibleVectors ( const std::vector< T > &  other) const
private

◆ ensureCompatibleVectors() [3/3]

template<typename T >
void ExpressionParsing::StackElement::ensureCompatibleVectors ( const T &  other) const
private

◆ getType()

StackElement::ElementType ExpressionParsing::StackElement::getType ( ) const

Get the variable type of the object.

The macro is not needed anymore:

Definition at line 226 of file StackElement.cxx.

226  {
227 
228  return m_type;
229  }

◆ isProxy()

bool ExpressionParsing::StackElement::isProxy ( ) const

Check if the object takes its value from a StoreGate object.

Definition at line 241 of file StackElement.cxx.

241  {
242 
243  return ( m_varName.length() > 0 );
244  }

◆ isScalar()

bool ExpressionParsing::StackElement::isScalar ( ) const

Check if the object describes a scalar value.

Definition at line 231 of file StackElement.cxx.

231  {
232 
233  return ( ( m_type == SE_INT ) || ( m_type == SE_DOUBLE ) );
234  }

◆ isVector()

bool ExpressionParsing::StackElement::isVector ( ) const

Check if the object describes a vector value.

Definition at line 236 of file StackElement.cxx.

236  {
237 
238  return ( ( m_type == SE_VECINT ) || ( m_type == SE_VECDOUBLE ) );
239  }

◆ makeDouble()

void ExpressionParsing::StackElement::makeDouble ( )

Function constructing internal double values in case integer values were given to the object initially.

Definition at line 347 of file StackElement.cxx.

347  {
348 
349  if( m_type == SE_INT ) {
350  m_type = SE_DOUBLE;
352  } else if( m_type == SE_VECINT ) {
354  m_vecDoubleVal.clear();
355  for( auto& value : m_vecIntVal ) {
356  m_vecDoubleVal.push_back( static_cast< double >( value ) );
357  }
358  }
359 
360  return;
361  }

◆ makeDoubleIfNecessary() [1/5]

void ExpressionParsing::StackElement::makeDoubleIfNecessary ( const StackElement other)
private

Definition at line 713 of file StackElement.cxx.

713  {
714 
715  if( ( m_type == SE_INT ) && ( other.m_type == SE_DOUBLE ) ) {
716  makeDouble();
717  } else if( ( m_type == SE_VECINT ) && ( other.m_type == SE_VECDOUBLE ) ) {
718  makeDouble();
719  }
720 
721  return;
722  }

◆ makeDoubleIfNecessary() [2/5]

void ExpressionParsing::StackElement::makeDoubleIfNecessary ( const std::vector< double > &  other)
private

Definition at line 743 of file StackElement.cxx.

743  {
744 
745  if( m_type == SE_VECINT ) {
746  makeDouble();
747  }
748 
749  return;
750  }

◆ makeDoubleIfNecessary() [3/5]

void ExpressionParsing::StackElement::makeDoubleIfNecessary ( const std::vector< int > &  other)
private

Definition at line 738 of file StackElement.cxx.

738  {
739 
740  return;
741  }

◆ makeDoubleIfNecessary() [4/5]

void ExpressionParsing::StackElement::makeDoubleIfNecessary ( double  other)
private

Definition at line 729 of file StackElement.cxx.

729  {
730 
731  if( m_type == SE_INT ) {
732  makeDouble();
733  }
734 
735  return;
736  }

◆ makeDoubleIfNecessary() [5/5]

void ExpressionParsing::StackElement::makeDoubleIfNecessary ( int  other)
private

Definition at line 724 of file StackElement.cxx.

724  {
725 
726  return;
727  }

◆ makeInt()

void ExpressionParsing::StackElement::makeInt ( )

Function constructing internal integer values in case double values were given to the object initially.

Definition at line 331 of file StackElement.cxx.

331  {
332 
333  if( m_type == SE_DOUBLE ) {
334  m_type = SE_INT;
336  } else if( m_type == SE_VECDOUBLE ) {
337  m_type = SE_VECINT;
338  m_vecIntVal.clear();
339  for( auto& value : m_vecDoubleVal ) {
340  m_vecIntVal.push_back( static_cast< int >( value ) );
341  }
342  }
343 
344  return;
345  }

◆ makeVector()

void ExpressionParsing::StackElement::makeVector ( std::size_t  n)

Function converting a possibly scalar value into a vector.

Definition at line 363 of file StackElement.cxx.

363  {
364 
365  if( isVector() ) {
366  return;
367  }
368 
369  if( m_type == SE_INT ) {
370  m_type = SE_VECINT;
371  m_vecIntVal.clear();
372  m_vecIntVal.resize( n, m_intVal );
373  } else if( m_type == SE_DOUBLE ) {
375  m_vecDoubleVal.clear();
376  m_vecDoubleVal.resize( n, m_doubleVal );
377  }
378 
379  return;
380  }

◆ makeVectorIfNecessary() [1/3]

void ExpressionParsing::StackElement::makeVectorIfNecessary ( const StackElement other)
private

The macro is not needed anymore:

Definition at line 680 of file StackElement.cxx.

680  {
681 
682  if( isVector() ) {
683  return;
684  }
685  if( other.isVector() ) {
686  makeVector( other.size() );
687  }
688 
689  return;
690  }

◆ makeVectorIfNecessary() [2/3]

void ExpressionParsing::StackElement::makeVectorIfNecessary ( const std::vector< double > &  other)
private

Definition at line 703 of file StackElement.cxx.

703  {
704 
705  if( isVector() ) {
706  return;
707  }
708  makeVector( other.size() );
709 
710  return;
711  }

◆ makeVectorIfNecessary() [3/3]

void ExpressionParsing::StackElement::makeVectorIfNecessary ( const std::vector< int > &  other)
private

Definition at line 692 of file StackElement.cxx.

692  {
693 
694  if( isVector() ) {
695  return;
696  }
697  makeVector( other.size() );
698 
699  return;
700  }

◆ operator!()

StackElement ExpressionParsing::StackElement::operator! ( )

NOT operator.

Definition at line 110 of file StackElement.cxx.

110  {
111 
112  // Create a copy of the object:
113  if (this->m_moved) throw std::logic_error("Content already moved");
114  StackElement temp( std::move(*this) );
115  this->m_moved=true;
116  // ...and modify its payload appropriately:
117  switch( m_type ) {
118 
119  case SE_INT:
120  temp.m_intVal = !( temp.m_intVal );
121  break;
122 
123  case SE_DOUBLE:
124  // temp.makeInt();
125  temp.m_intVal = !( temp.m_doubleVal );
126  break;
127 
128  case SE_VECINT:
129  for( std::size_t i = 0; i < temp.m_vecIntVal.size(); ++i ) {
130  temp.m_vecIntVal[ i ] = !( temp.m_vecIntVal[ i ] );
131  }
132  break;
133 
134  case SE_VECDOUBLE:
135  // temp.makeInt();
136  temp.m_vecIntVal.resize(temp.m_vecDoubleVal.size());
137  for( std::size_t i = 0; i < temp.m_vecDoubleVal.size(); ++i ) {
138  temp.m_vecIntVal[ i ] = !( temp.m_vecDoubleVal[ i ] ); // @TODO use >0. ?
139  }
140  break;
141 
142  default:
143  throw std::runtime_error( "! operator called on unknown "
144  "variable type" );
145  break;
146  }
147 
148  // Return the negated object:
149  return temp;
150  }

◆ operator*() [1/2]

template<typename T >
StackElement ExpressionParsing::StackElement::operator* ( const T &  rhs)

◆ operator*() [2/2]

StackElement ExpressionParsing::StackElement::operator* ( StackElement rhs)

Operator multiplying the object by a value.

◆ operator*=() [1/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator*= ( const std::vector< T > &  rhs)

Multiply the object by a vector type.

◆ operator*=() [2/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator*= ( const T &  rhs)

◆ operator*=() [3/3]

StackElement& ExpressionParsing::StackElement::operator*= ( StackElement rhs)

Multiply the object by a scalar type.

◆ operator+() [1/2]

template<typename T >
StackElement ExpressionParsing::StackElement::operator+ ( const T &  rhs)

◆ operator+() [2/2]

StackElement ExpressionParsing::StackElement::operator+ ( StackElement rhs)

Operator adding a value to the object.

◆ operator+=() [1/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator+= ( const std::vector< T > &  rhs)

Add a vector type to the object.

◆ operator+=() [2/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator+= ( const T &  rhs)

◆ operator+=() [3/3]

StackElement& ExpressionParsing::StackElement::operator+= ( StackElement rhs)

Add a scalar type to the object.

◆ operator-() [1/3]

StackElement ExpressionParsing::StackElement::operator- ( )

Inverse operator.

Definition at line 152 of file StackElement.cxx.

152  {
153 
154  // Create a copy of the object:
155  if (this->m_moved) throw std::logic_error("Content already moved");
156  StackElement temp( std::move(*this) );
157  this->m_moved=true;
158 
159  // ...and modify its payload appropriately:
160  switch( m_type ) {
161 
162  case SE_INT:
163  temp.m_intVal = -( this->m_intVal );
164  break;
165 
166  case SE_DOUBLE:
167  temp.m_doubleVal = -( this->m_doubleVal );
168  break;
169 
170  case SE_VECINT:
171  for( std::size_t i = 0; i < temp.m_vecIntVal.size(); ++i ) {
172  temp.m_vecIntVal[ i ] = -( temp.m_vecIntVal[ i ] );
173  }
174  break;
175 
176  case SE_VECDOUBLE:
177  for( std::size_t i = 0; i < temp.m_vecDoubleVal.size(); ++i ) {
178  temp.m_vecDoubleVal[ i ] = -( temp.m_vecDoubleVal[ i ] );
179  }
180  break;
181 
182  default:
183  throw std::runtime_error( "- operator called on unknown "
184  "variable type" );
185  break;
186  }
187 
188  // Return the inverted object:
189  return temp;
190  }

◆ operator-() [2/3]

template<typename T >
StackElement ExpressionParsing::StackElement::operator- ( const T &  rhs)

◆ operator-() [3/3]

StackElement ExpressionParsing::StackElement::operator- ( StackElement rhs)

Operator subtracting a value from the object.

◆ operator-=() [1/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator-= ( const std::vector< T > &  rhs)

Subtract a vector type from the object.

◆ operator-=() [2/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator-= ( const T &  rhs)

◆ operator-=() [3/3]

StackElement& ExpressionParsing::StackElement::operator-= ( StackElement rhs)

Subtract a scalar type from the object.

◆ operator/() [1/2]

template<typename T >
StackElement ExpressionParsing::StackElement::operator/ ( const T &  rhs)

◆ operator/() [2/2]

StackElement ExpressionParsing::StackElement::operator/ ( StackElement rhs)

Operator dividing the object by a value.

◆ operator/=() [1/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator/= ( const std::vector< T > &  rhs)

Divide the object by a vector type.

◆ operator/=() [2/3]

template<typename T >
StackElement& ExpressionParsing::StackElement::operator/= ( const T &  rhs)

◆ operator/=() [3/3]

StackElement& ExpressionParsing::StackElement::operator/= ( StackElement rhs)

Divide the object by a scalar type.

◆ operator=() [1/7]

StackElement & ExpressionParsing::StackElement::operator= ( const std::vector< double > &  rhs)

Operator assigning a vector of doubles to the object.

Definition at line 86 of file StackElement.cxx.

86  {
87 
89  m_intVal = 0;
90  m_doubleVal = 0;
91  m_vecIntVal.clear();
92  m_vecDoubleVal = rhs;
93  m_moved = false;
94 
95  return *this;
96  }

◆ operator=() [2/7]

StackElement & ExpressionParsing::StackElement::operator= ( const std::vector< int > &  rhs)

Operator assigning a vector of integers to the object.

Definition at line 64 of file StackElement.cxx.

64  {
65 
66  m_type = SE_VECINT;
67  m_intVal = 0;
68  m_doubleVal = 0;
69  m_vecIntVal = rhs;
70  m_vecDoubleVal.clear();
71  m_moved = false;
72 
73  return *this;
74  }

◆ operator=() [3/7]

StackElement & ExpressionParsing::StackElement::operator= ( double  rhs)

Operator assigning a double value to the object.

Definition at line 51 of file StackElement.cxx.

51  {
52 
53  m_type = SE_DOUBLE;
54  m_intVal = 0;
55  m_doubleVal = rhs;
56  m_vecIntVal.clear();
57  m_vecDoubleVal.clear();
58  m_moved = false;
59 
60  return *this;
61  }

◆ operator=() [4/7]

StackElement & ExpressionParsing::StackElement::operator= ( int  rhs)

Operator assigning an integer value to the object.

Definition at line 39 of file StackElement.cxx.

39  {
40 
41  m_type = SE_INT;
42  m_intVal = rhs;
43  m_doubleVal = 0;
44  m_vecIntVal.clear();
45  m_vecDoubleVal.clear();
46  m_moved = false;
47 
48  return *this;
49  }

◆ operator=() [5/7]

StackElement& ExpressionParsing::StackElement::operator= ( StackElement &&  rhs)

◆ operator=() [6/7]

StackElement & ExpressionParsing::StackElement::operator= ( std::vector< double > &&  rhs)

Operator assigning a vector of doubles to the object.

Definition at line 98 of file StackElement.cxx.

98  {
99 
101  m_intVal = 0;
102  m_doubleVal = 0;
103  m_vecIntVal.clear();
104  m_vecDoubleVal = std::move(rhs);
105  m_moved = false;
106 
107  return *this;
108  }

◆ operator=() [7/7]

StackElement & ExpressionParsing::StackElement::operator= ( std::vector< int > &&  rhs)

Operator assigning a vector of integers to the object.

Definition at line 75 of file StackElement.cxx.

75  {
76 
77  m_type = SE_VECINT;
78  m_intVal = 0;
79  m_doubleVal = 0;
80  m_vecIntVal = std::move(rhs);
81  m_vecDoubleVal.clear();
82  m_moved = false;
83 
84  return *this;
85  }

◆ proxyVarName()

const std::string& ExpressionParsing::StackElement::proxyVarName ( ) const
inline

Definition at line 184 of file StackElement.h.

184 { return m_varName; }

◆ scalarValue()

template<typename T >
T ExpressionParsing::StackElement::scalarValue ( ) const

Evaluate the value of the object into the requested scalar type.

◆ size()

size_t ExpressionParsing::StackElement::size ( ) const
private

◆ valueFromProxy()

StackElement ExpressionParsing::StackElement::valueFromProxy ( ) const

Set the internal variables of the object based on the objects in SG.

Definition at line 382 of file StackElement.cxx.

382  {
383 
385  if( ! isProxy() ) {
386  return tmp;
387  }
388 
389  if( ! m_determinedVariableType ) {
393  }
394  }
395 
396  switch( m_variableType ) {
397 
400  break;
401 
404  break;
405 
408  break;
409 
412  break;
413 
415  tmp=std::vector<double>();
416  break;
418  default:
419  throw std::runtime_error( "Got VT_UNK - unknown identifier: " +
420  m_varName );
421  break;
422  }
423 
424  return tmp;
425  }

◆ vectorValue() [1/3]

template<>
std::vector< double > ExpressionParsing::StackElement::vectorValue ( size_t  sizeIfScalar)

Definition at line 299 of file StackElement.cxx.

299  {
300 
301  if (this->m_moved) throw std::logic_error("Content already moved");
302  switch( m_type ) {
303 
304  case SE_VECINT: {
305  std::vector<double> ret(m_vecIntVal.size());
306  std::transform (m_vecIntVal.begin(), m_vecIntVal.end(), ret.begin(), [](int a) -> double { return a;});
307  return ret;
308  break;
309  }
310  case SE_VECDOUBLE:
311  m_moved=true;
312  return std::move(m_vecDoubleVal);
313  break;
314 
315  case SE_INT: {
316  return std::vector<double>(sizeIfScalar,static_cast< double >( m_intVal ) );
317  break;
318  }
319  case SE_DOUBLE: {
320  return std::vector<double>(sizeIfScalar, m_doubleVal );
321  break;
322  }
323  default:
324  throw std::runtime_error( "(dbl) vectorValue(): Unsupported "
325  "StackElement" );
326  break;
327  }
328  return std::vector<double>();
329  }

◆ vectorValue() [2/3]

template<>
std::vector< int > ExpressionParsing::StackElement::vectorValue ( std::size_t  sizeIfScalar)

Definition at line 266 of file StackElement.cxx.

266  {
267 
268  if (this->m_moved) throw std::logic_error("Content already moved");
269  switch( m_type ) {
270 
271  case SE_VECINT:
272  this->m_moved=true;
273  return std::move(m_vecIntVal);
274  break;
275 
276  case SE_VECDOUBLE: {
277  std::vector<int> ret(m_vecDoubleVal.size());
278  std::transform (m_vecDoubleVal.begin(), m_vecDoubleVal.end(), ret.begin(), [](const double &a) -> int { return static_cast<int>(a);});
279  break;
280  }
281  case SE_INT: {
282  return std::vector<int>( sizeIfScalar, m_intVal );
283  break;
284  }
285  case SE_DOUBLE:{
286  return std::vector<int>( sizeIfScalar,static_cast< int >( m_doubleVal ) );
287  break;
288  }
289  default:
290  throw std::runtime_error( "(int) vectorValue(): Unsupported "
291  "StackElement" );
292  break;
293  }
294  return std::vector<int>();
295  }

◆ vectorValue() [3/3]

template<typename T >
std::vector< T > ExpressionParsing::StackElement::vectorValue ( std::size_t  sizeIfScalar = 0)

Evaluate the value of the object into the requested vector type.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const StackElement el 
)
friend

Declare the print operator as a friend of the class.

Definition at line 775 of file StackElement.cxx.

776  {
777 
778  switch( el.m_type ) {
779 
781  os << "(int)" << el.m_intVal;
782  break;
783 
785  os << "(double)" << el.m_doubleVal;
786  break;
787 
789  os << "(vec<int>)" << el.m_vecIntVal;
790  break;
791 
793  os << "(vec<double>)" << el.m_vecDoubleVal;
794  break;
795 
797  os << "SE_UNK";
798  break;
799 
800  default:
801  break;
802  }
803 
804  return os;
805  }

Member Data Documentation

◆ m_determinedVariableType

std::atomic<bool> ExpressionParsing::StackElement::m_determinedVariableType = false
mutableprivate

Internal flag showing whether the type of the variable was already determined.

Definition at line 323 of file StackElement.h.

◆ m_doubleVal

double ExpressionParsing::StackElement::m_doubleVal = 0.
private

The value of the object represented as a double.

Definition at line 309 of file StackElement.h.

◆ m_intVal

int ExpressionParsing::StackElement::m_intVal = 0
private

The value of the object represented as an integer.

Definition at line 307 of file StackElement.h.

◆ m_moved

std::atomic<bool> ExpressionParsing::StackElement::m_moved = false
mutableprivate

Definition at line 324 of file StackElement.h.

◆ m_proxyLoader

IProxyLoader* ExpressionParsing::StackElement::m_proxyLoader = nullptr
private

Loader for the described variable.

Definition at line 318 of file StackElement.h.

◆ m_type

ElementType ExpressionParsing::StackElement::m_type = SE_UNK
private

The type of the variable held by the object.

Definition at line 304 of file StackElement.h.

◆ m_variableType

std::atomic<IProxyLoader::VariableType> ExpressionParsing::StackElement::m_variableType = IProxyLoader::VT_UNK
mutableprivate

Type of the variable provided by the proxy loader.

Definition at line 320 of file StackElement.h.

◆ m_varName

std::string ExpressionParsing::StackElement::m_varName
private

The name/definition of the variable.

Definition at line 316 of file StackElement.h.

◆ m_vecDoubleVal

std::vector< double > ExpressionParsing::StackElement::m_vecDoubleVal
private

The value of the object represented as a vector of doubles.

Definition at line 313 of file StackElement.h.

◆ m_vecIntVal

std::vector< int > ExpressionParsing::StackElement::m_vecIntVal
private

The value of the object represented as a vector of integers.

Definition at line 311 of file StackElement.h.


The documentation for this class was generated from the following files:
ExpressionParsing::IProxyLoader::VT_VECEMPTY
@ VT_VECEMPTY
Definition: IProxyLoader.h:21
StackElement
void * StackElement
One element of a stack trace.
Definition: stackstash.h:74
ExpressionParsing::StackElement::isProxy
bool isProxy() const
Check if the object takes its value from a StoreGate object.
Definition: StackElement.cxx:241
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::IProxyLoader::VT_VECDOUBLE
@ VT_VECDOUBLE
Definition: IProxyLoader.h:21
ExpressionParsing::StackElement::SE_DOUBLE
@ SE_DOUBLE
The type is a double.
Definition: StackElement.h:61
ExpressionParsing::StackElement::_pow
StackElement _pow(const T &n)
Function raising the object's value to the n'th power.
athena.value
value
Definition: athena.py:124
ExpressionParsing::IProxyLoader::loadDoubleVariableFromString
virtual double loadDoubleVariableFromString(const std::string &varname) const =0
ExpressionParsing::IProxyLoader::variableTypeFromString
virtual VariableType variableTypeFromString(const std::string &varname) const =0
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::compareVectorAlt
std::vector< int > compareVectorAlt(const std::vector< T > &&a, std::vector< T > &&b, T_CompHelper helper)
Definition: StackElement.cxx:440
ExpressionParsing::IProxyLoader::VT_DOUBLE
@ VT_DOUBLE
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::VT_UNK
@ VT_UNK
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::loadVecIntVariableFromString
virtual std::vector< int > loadVecIntVariableFromString(const std::string &varname) const =0
lumiFormat.i
int i
Definition: lumiFormat.py:85
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::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
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
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::compareVector
std::vector< int > compareVector(std::vector< T > &&a, std::vector< T > &&b, T_CompHelper helper)
Definition: StackElement.cxx:429
ExpressionParsing::IProxyLoader::VT_VECINT
@ VT_VECINT
Definition: IProxyLoader.h:21
ExpressionParsing::StackElement::m_variableType
std::atomic< IProxyLoader::VariableType > m_variableType
Type of the variable provided by the proxy loader.
Definition: StackElement.h:320
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ExpressionParsing::StackElement::m_varName
std::string m_varName
The name/definition of the variable.
Definition: StackElement.h:316
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
ExpressionParsing::StackElement::SE_VECINT
@ SE_VECINT
The type is a vector of integers.
Definition: StackElement.h:62
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::m_proxyLoader
IProxyLoader * m_proxyLoader
Loader for the described variable.
Definition: StackElement.h:318
ExpressionParsing::IProxyLoader::VT_INT
@ VT_INT
Definition: IProxyLoader.h:21
ExpressionParsing::IProxyLoader::loadVecDoubleVariableFromString
virtual std::vector< double > loadVecDoubleVariableFromString(const std::string &varname) const =0
ExpressionParsing::StackElement::m_type
ElementType m_type
The type of the variable held by the object.
Definition: StackElement.h:304
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
ExpressionParsing::StackElement::isScalar
bool isScalar() const
Check if the object describes a scalar value.
Definition: StackElement.cxx:231
a
TList * a
Definition: liststreamerinfos.cxx:10
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
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ExpressionParsing::StackElement::SE_UNK
@ SE_UNK
The type is not known, or not applicable.
Definition: StackElement.h:59
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::_comparisonOp
StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper)
Definition: StackElement.cxx:466
ExpressionParsing::IProxyLoader::loadIntVariableFromString
virtual int loadIntVariableFromString(const std::string &varname) const =0
ExpressionParsing::StackElement::SE_INT
@ SE_INT
The type is an integer.
Definition: StackElement.h:60
ExpressionParsing::StackElement::makeVector
void makeVector(std::size_t n)
Function converting a possibly scalar value into a vector.
Definition: StackElement.cxx:363