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

Private Member Functions

Internal operations on the object
void makeVectorIfNecessary (const StackElement &other)
 The macro is not needed anymore:
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.
int m_intVal = 0
 The value of the object represented as an integer.
double m_doubleVal = 0.
 The value of the object represented as a double.
std::vector< int > m_vecIntVal
 The value of the object represented as a vector of integers.
std::vector< double > m_vecDoubleVal
 The value of the object represented as a vector of doubles.
std::string m_varName
 The name/definition of the variable.
IProxyLoaderm_proxyLoader = nullptr
 Loader for the described variable.
std::atomic< IAccessor::VariableTypem_variableType = IProxyLoader::VT_UNK
 Type of the variable provided by the proxy loader.
PointerCache< IAccessor, std::memory_order_seq_cst > m_accessor ATLAS_THREAD_SAFE
std::atomic< bool > m_moved = false
 Internal flag showing whether the type of the variable was already determined.

Friends

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

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 55 of file StackElement.h.

Member Enumeration Documentation

◆ 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 63 of file StackElement.h.

63 {
64 SE_UNK = 0,
65 SE_INT = 1,
66 SE_DOUBLE = 2,
67 SE_VECINT = 3,
68 SE_VECDOUBLE = 4
69 };
@ 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.

Constructor & Destructor Documentation

◆ StackElement() [1/11]

ExpressionParsing::StackElement::StackElement ( )
inline

Default constructor.

Definition at line 75 of file StackElement.h.

75{};

◆ StackElement() [2/11]

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

Constructor creating the object with an unsigned integer value.

Definition at line 77 of file StackElement.h.

77: m_type( SE_INT ), m_intVal(static_cast<unsigned int>(val)) {}
ElementType m_type
The type of the variable held by the object.
int m_intVal
The value of the object represented as an integer.

◆ StackElement() [3/11]

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

Constructor creating the object with a signed integer value.

Definition at line 79 of file StackElement.h.

79: 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 81 of file StackElement.h.

81: m_type( SE_DOUBLE ), m_doubleVal( val ) {}
double m_doubleVal
The value of the object represented as a double.

◆ 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 83 of file StackElement.h.

83: m_type( SE_VECINT ), m_vecIntVal(val) {}
std::vector< int > m_vecIntVal
The value of the object represented as a vector of integers.

◆ 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 85 of file StackElement.h.

std::vector< double > m_vecDoubleVal
The value of the object represented as a vector of doubles.

◆ StackElement() [7/11]

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

Constructor creating the object with a vector of integers value.

Definition at line 87 of file StackElement.h.

87: 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 89 of file StackElement.h.

89: 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 91 of file StackElement.h.

91: /*m_type( SE_UNK ), */m_varName( val ), m_proxyLoader( proxyLoader ) {}
std::string m_varName
The name/definition of the variable.
IProxyLoader * m_proxyLoader
Loader for the described variable.

◆ 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 611 of file StackElement.cxx.

611 {
612 if (this->m_moved) throw std::logic_error("Content already moved");
613
614 StackElement temp(std::move(*this));
615 this->m_moved=true;
616 switch( m_type ) {
617
618 case SE_INT:
619 m_intVal = std::abs( temp.m_intVal );
620 break;
621
622 case SE_DOUBLE:
623 m_doubleVal = std::abs( temp.m_doubleVal );
624 break;
625
626 case SE_VECINT:
627 {
628 for( int &value : temp.m_vecIntVal ) {
629 value = std::abs( value );
630 }
631 }
632 break;
633
634 case SE_VECDOUBLE:
635 {
636 for( double &value : temp.m_vecDoubleVal ) {
637 value = std::abs( value );
638 }
639 }
640 break;
641
642 default:
643 // @throw exception ?
644 break;
645 }
646 return temp;
647 }
std::atomic< bool > m_moved
Internal flag showing whether the type of the variable was already determined.
StackElement()
Default constructor.

◆ _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 517 of file StackElement.cxx.

517{ return _comparisonOp(b, Helper_and()); }
StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper)

◆ _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 476 of file StackElement.cxx.

477 {
478 if (m_type ==SE_UNK || other.m_type==SE_UNK) {
479 throw std::runtime_error( "ERROR: Can't operate on SE_UNK "
480 "StackElements");
481 }
482 if( isScalar() && other.isScalar() ) {
483 if( m_type == SE_INT && other.m_type == SE_INT ) {
484 return comp_helper.compare(scalarValue< int >(),other.scalarValue< int >() );
485 } else {
486 return comp_helper.compare(scalarValue< double >(),other.scalarValue< double >() );
487 }
488 } else {
489 if (isVector() && other.isVector() && this->size() != other.size()) {
490 throw std::runtime_error( "Incompatible vectors - different length" );
491 }
492 std::size_t the_size = ( m_type == SE_VECINT || m_type==SE_VECDOUBLE) ? this->size() : other.size();
493 if( ( m_type == SE_VECINT)
494 && ( other.m_type == SE_VECINT || other.m_type == SE_INT )) {
495 return compareVector( this->vectorValue<int>(the_size) , other.vectorValue< int >(the_size), comp_helper );
496 }
497 else if( m_type == SE_INT && other.m_type == SE_VECINT) {
498 return compareVectorAlt( this->vectorValue<int>(the_size) , other.vectorValue< int >(the_size), comp_helper );
499 }
500 else {
501 return compareVector( this->vectorValue<double>(the_size) , other.vectorValue< double >(the_size), comp_helper );
502 }
503 }
504 }
bool isVector() const
Check if the object describes a vector value.
std::vector< T > vectorValue(std::size_t sizeIfScalar=0)
Evaluate the value of the object into the requested vector type.
T scalarValue() const
Evaluate the value of the object into the requested scalar type.
bool isScalar() const
Check if the object describes a scalar value.
std::vector< int > compareVectorAlt(const std::vector< T > &&a, std::vector< T > &&b, T_CompHelper helper)
std::vector< int > compareVector(std::vector< T > &&a, std::vector< T > &&b, T_CompHelper helper)

◆ _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 573 of file StackElement.cxx.

573 {
574
575 switch( m_type ) {
576
577 case SE_INT:
578 return !!( m_intVal );
579 break;
580
581 case SE_DOUBLE:
582 return !!( m_doubleVal );
583 break;
584
585 case SE_VECINT:
586 {
587 int total = 0;
588 for( int value : m_vecIntVal ) {
589 total += !!value;
590 }
591 return total;
592 }
593 break;
594
595 case SE_VECDOUBLE:
596 {
597 int total = 0;
598 for( double value : m_vecDoubleVal ) {
599 total += !!value;
600 }
601 return total;
602 }
603 break;
604
605 default:
606 return 0;
607 break;
608 }
609 }

◆ _eq()

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

Definition at line 515 of file StackElement.cxx.

515{ 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 519 of file StackElement.cxx.

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

◆ _gte()

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

Definition at line 520 of file StackElement.cxx.

520{ 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 521 of file StackElement.cxx.

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

◆ _lte()

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

Definition at line 522 of file StackElement.cxx.

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

◆ _neq()

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

Definition at line 516 of file StackElement.cxx.

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

◆ _or()

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

Definition at line 518 of file StackElement.cxx.

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

◆ _pow() [1/2]

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

Definition at line 526 of file StackElement.cxx.

526 {
527
528 if( n.isVector() ) {
529 throw std::runtime_error( "Can't use vector as exponent" );
530 } else {
531 return _pow( n.scalarValue< double >() );
532 }
533 }
StackElement _pow(const T &n)
Function raising the object's value to the n'th power.

◆ _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 535 of file StackElement.cxx.

535 {
536
537 switch( m_type ) {
538
539 case SE_INT:
540 return m_intVal;
541 break;
542
543 case SE_DOUBLE:
544 return m_doubleVal;
545 break;
546
547 case SE_VECINT:
548 {
549 int total = 0;
550 for( int value : m_vecIntVal ) {
551 total += value;
552 }
553 return total;
554 }
555 break;
556
557 case SE_VECDOUBLE:
558 {
559 double total = 0.0;
560 for( double value : m_vecDoubleVal ) {
561 total += value;
562 }
563 return total;
564 }
565 break;
566
567 default:
568 return 0;
569 break;
570 }
571 }

◆ _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 762 of file StackElement.cxx.

762 {
763
764 if( this->m_type != other.m_type ) {
765 throw std::runtime_error( "Incompatible stack elements" );
766 }
767
768 return;
769 }

◆ ensureCompatibleVectors() [1/3]

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

Definition at line 773 of file StackElement.cxx.

773 {
774
775 if( isScalar() ) {
776 return;
777 }
778
779 const std::size_t ourlen = size();
780 if( ourlen != other.size() ) {
781 throw std::runtime_error( "Incompatible vectors - different length" );
782 }
783 }

◆ 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 344 of file StackElement.cxx.

344 {
345
346 if( m_type == SE_INT ) {
349 } else if( m_type == SE_VECINT ) {
351 m_vecDoubleVal.clear();
352 for( auto& value : m_vecIntVal ) {
353 m_vecDoubleVal.push_back( static_cast< double >( value ) );
354 }
355 }
356
357 return;
358 }

◆ makeDoubleIfNecessary() [1/5]

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

Definition at line 723 of file StackElement.cxx.

723 {
724
725 if( ( m_type == SE_INT ) && ( other.m_type == SE_DOUBLE ) ) {
726 makeDouble();
727 } else if( ( m_type == SE_VECINT ) && ( other.m_type == SE_VECDOUBLE ) ) {
728 makeDouble();
729 }
730
731 return;
732 }
void makeDouble()
Function constructing internal double values in case integer values were given to the object initiall...

◆ makeDoubleIfNecessary() [2/5]

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

Definition at line 753 of file StackElement.cxx.

753 {
754
755 if( m_type == SE_VECINT ) {
756 makeDouble();
757 }
758
759 return;
760 }

◆ makeDoubleIfNecessary() [3/5]

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

Definition at line 748 of file StackElement.cxx.

748 {
749
750 return;
751 }

◆ makeDoubleIfNecessary() [4/5]

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

Definition at line 739 of file StackElement.cxx.

739 {
740
741 if( m_type == SE_INT ) {
742 makeDouble();
743 }
744
745 return;
746 }

◆ makeDoubleIfNecessary() [5/5]

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

Definition at line 734 of file StackElement.cxx.

734 {
735
736 return;
737 }

◆ makeInt()

void ExpressionParsing::StackElement::makeInt ( )

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

Definition at line 328 of file StackElement.cxx.

328 {
329
330 if( m_type == SE_DOUBLE ) {
331 m_type = SE_INT;
333 } else if( m_type == SE_VECDOUBLE ) {
335 m_vecIntVal.clear();
336 for( auto& value : m_vecDoubleVal ) {
337 m_vecIntVal.push_back( static_cast< int >( value ) );
338 }
339 }
340
341 return;
342 }

◆ makeVector()

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

Function converting a possibly scalar value into a vector.

Definition at line 360 of file StackElement.cxx.

360 {
361
362 if( isVector() ) {
363 return;
364 }
365
366 if( m_type == SE_INT ) {
368 m_vecIntVal.clear();
369 m_vecIntVal.resize( n, m_intVal );
370 } else if( m_type == SE_DOUBLE ) {
372 m_vecDoubleVal.clear();
373 m_vecDoubleVal.resize( n, m_doubleVal );
374 }
375
376 return;
377 }

◆ makeVectorIfNecessary() [1/3]

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

The macro is not needed anymore:

Definition at line 690 of file StackElement.cxx.

690 {
691
692 if( isVector() ) {
693 return;
694 }
695 if( other.isVector() ) {
696 makeVector( other.size() );
697 }
698
699 return;
700 }
void makeVector(std::size_t n)
Function converting a possibly scalar value into a vector.

◆ makeVectorIfNecessary() [2/3]

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

Definition at line 713 of file StackElement.cxx.

713 {
714
715 if( isVector() ) {
716 return;
717 }
718 makeVector( other.size() );
719
720 return;
721 }

◆ makeVectorIfNecessary() [3/3]

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

Definition at line 702 of file StackElement.cxx.

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

◆ 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
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
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
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 189 of file StackElement.h.

189{ 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 EventContext & ctx) const

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

Definition at line 379 of file StackElement.cxx.

379 {
380
382 if( ! isProxy() ) {
383 return tmp;
384 }
385
386 IAccessor::VariableType the_variable_type=m_variableType.load(std::memory_order_seq_cst);
387 if( the_variable_type==IProxyLoader::VT_UNK) {
388 auto [variable_type, accessor] = m_proxyLoader->getAccessorFromString(ctx, m_varName);
389 // if ( m_variableType != IProxyLoader::VT_UNK) {
390 if (variable_type != IProxyLoader::VT_VECEMPTY) {
391 // do not cache the accessor and variable type if it was an empty vector because
392 // in such cases there is not enough information to decide the variable type.
393 // otherwise set the accessor if still unset and set the variable type.
394 // Other threads would come to the same conclusion in case the vector is not empty
395 // (or empty), so which thread sets the variable type and/or accessor does not matter.
396 m_accessor.setIfUnset(accessor);
397 m_variableType.store(variable_type, std::memory_order_seq_cst);
398 }
399 // for the current event what ever getAccessorFromString returned is a good choice
400 // independent of other threads which might have had more information for a final
401 // decision. So, for this evaluation what ever getAccessorFromString returned will
402 // be used.
403 the_variable_type = variable_type;
404 }
405 assert((the_variable_type == IProxyLoader::VT_UNK || the_variable_type == IProxyLoader::VT_VECEMPTY || m_accessor == true) );
406
407 switch( the_variable_type ) {
409 tmp = m_accessor->loadInt(ctx, m_varName );
410 break;
411
413 tmp = m_accessor->loadDouble(ctx, m_varName );
414 break;
415
417 tmp = m_accessor->loadVecInt(ctx, m_varName );
418 break;
419
421 tmp = m_accessor->loadVec(ctx, m_varName );
422 break;
423 }
425 tmp=std::vector<double>();
426 break;
428 default:
429 throw std::runtime_error( "Got VT_UNK - unknown identifier: " +
430 m_varName );
431 break;
432 }
433
434 return tmp;
435 }
bool isProxy() const
Check if the object takes its value from a StoreGate object.
std::atomic< IAccessor::VariableType > m_variableType
Type of the variable provided by the proxy loader.
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.

◆ 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 return std::vector<double>(m_vecIntVal.begin(), m_vecIntVal.end());
306 break;
307 }
308 case SE_VECDOUBLE:
309 m_moved=true;
310 return std::move(m_vecDoubleVal);
311 break;
312
313 case SE_INT: {
314 return std::vector<double>(sizeIfScalar,static_cast< double >( m_intVal ) );
315 break;
316 }
317 case SE_DOUBLE: {
318 return std::vector<double>(sizeIfScalar, m_doubleVal );
319 break;
320 }
321 default:
322 throw std::runtime_error( "(dbl) vectorValue(): Unsupported "
323 "StackElement" );
324 break;
325 }
326 }

◆ 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 }
static Double_t a

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

◆ operator<<

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

Declare the print operator as a friend of the class.

Definition at line 785 of file StackElement.cxx.

786 {
787
788 switch( el.m_type ) {
789
791 os << "(int)" << el.m_intVal;
792 break;
793
795 os << "(double)" << el.m_doubleVal;
796 break;
797
799 os << "(vec<int>)" << el.m_vecIntVal;
800 break;
801
803 os << "(vec<double>)" << el.m_vecDoubleVal;
804 break;
805
807 os << "SE_UNK";
808 break;
809
810 default:
811 break;
812 }
813
814 return os;
815 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

PointerCache<IAccessor, std::memory_order_seq_cst> m_accessor ExpressionParsing::StackElement::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 326 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 314 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 312 of file StackElement.h.

◆ m_moved

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

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

Definition at line 329 of file StackElement.h.

◆ m_proxyLoader

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

Loader for the described variable.

Definition at line 323 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 309 of file StackElement.h.

◆ m_variableType

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

Type of the variable provided by the proxy loader.

Definition at line 325 of file StackElement.h.

◆ m_varName

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

The name/definition of the variable.

Definition at line 321 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 318 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 316 of file StackElement.h.


The documentation for this class was generated from the following files: