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

614 {
615 if (this->m_moved) throw std::logic_error("Content already moved");
616
617 StackElement temp(std::move(*this));
618 this->m_moved=true;
619 switch( m_type ) {
620
621 case SE_INT:
622 m_intVal = std::abs( temp.m_intVal );
623 break;
624
625 case SE_DOUBLE:
626 m_doubleVal = std::abs( temp.m_doubleVal );
627 break;
628
629 case SE_VECINT:
630 {
631 for( int &value : temp.m_vecIntVal ) {
632 value = std::abs( value );
633 }
634 }
635 break;
636
637 case SE_VECDOUBLE:
638 {
639 for( double &value : temp.m_vecDoubleVal ) {
640 value = std::abs( value );
641 }
642 }
643 break;
644
645 default:
646 // @throw exception ?
647 break;
648 }
649 return temp;
650 }
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 520 of file StackElement.cxx.

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

480 {
481 if (m_type ==SE_UNK || other.m_type==SE_UNK) {
482 throw std::runtime_error( "ERROR: Can't operate on SE_UNK "
483 "StackElements");
484 }
485 if( isScalar() && other.isScalar() ) {
486 if( m_type == SE_INT && other.m_type == SE_INT ) {
487 return comp_helper.compare(scalarValue< int >(),other.scalarValue< int >() );
488 } else {
489 return comp_helper.compare(scalarValue< double >(),other.scalarValue< double >() );
490 }
491 } else {
492 if (isVector() && other.isVector() && this->size() != other.size()) {
493 throw std::runtime_error( "Incompatible vectors - different length" );
494 }
495 std::size_t the_size = ( m_type == SE_VECINT || m_type==SE_VECDOUBLE) ? this->size() : other.size();
496 if( ( m_type == SE_VECINT)
497 && ( other.m_type == SE_VECINT || other.m_type == SE_INT )) {
498 return compareVector( this->vectorValue<int>(the_size) , other.vectorValue< int >(the_size), comp_helper );
499 }
500 else if( m_type == SE_INT && other.m_type == SE_VECINT) {
501 return compareVectorAlt( this->vectorValue<int>(the_size) , other.vectorValue< int >(the_size), comp_helper );
502 }
503 else {
504 return compareVector( this->vectorValue<double>(the_size) , other.vectorValue< double >(the_size), comp_helper );
505 }
506 }
507 }
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 576 of file StackElement.cxx.

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

◆ _eq()

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

Definition at line 518 of file StackElement.cxx.

518{ 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 522 of file StackElement.cxx.

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

◆ _gte()

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

Definition at line 523 of file StackElement.cxx.

523{ 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 524 of file StackElement.cxx.

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

◆ _lte()

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

Definition at line 525 of file StackElement.cxx.

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

◆ _neq()

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

Definition at line 519 of file StackElement.cxx.

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

◆ _or()

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

Definition at line 521 of file StackElement.cxx.

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

◆ _pow() [1/2]

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

Definition at line 529 of file StackElement.cxx.

529 {
530
531 if( n.isVector() ) {
532 throw std::runtime_error( "Can't use vector as exponent" );
533 } else {
534 return _pow( n.scalarValue< double >() );
535 }
536 }
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 538 of file StackElement.cxx.

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

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

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

◆ ensureCompatibleVectors() [1/3]

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

Definition at line 776 of file StackElement.cxx.

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

◆ 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 ) {
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 726 of file StackElement.cxx.

726 {
727
728 if( ( m_type == SE_INT ) && ( other.m_type == SE_DOUBLE ) ) {
729 makeDouble();
730 } else if( ( m_type == SE_VECINT ) && ( other.m_type == SE_VECDOUBLE ) ) {
731 makeDouble();
732 }
733
734 return;
735 }
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 756 of file StackElement.cxx.

756 {
757
758 if( m_type == SE_VECINT ) {
759 makeDouble();
760 }
761
762 return;
763 }

◆ makeDoubleIfNecessary() [3/5]

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

Definition at line 751 of file StackElement.cxx.

751 {
752
753 return;
754 }

◆ makeDoubleIfNecessary() [4/5]

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

Definition at line 742 of file StackElement.cxx.

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

◆ makeDoubleIfNecessary() [5/5]

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

Definition at line 737 of file StackElement.cxx.

737 {
738
739 return;
740 }

◆ 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 ) {
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 ) {
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 693 of file StackElement.cxx.

693 {
694
695 if( isVector() ) {
696 return;
697 }
698 if( other.isVector() ) {
699 makeVector( other.size() );
700 }
701
702 return;
703 }
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 716 of file StackElement.cxx.

716 {
717
718 if( isVector() ) {
719 return;
720 }
721 makeVector( other.size() );
722
723 return;
724 }

◆ makeVectorIfNecessary() [3/3]

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

Definition at line 705 of file StackElement.cxx.

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

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

382 {
383
385 if( ! isProxy() ) {
386 return tmp;
387 }
388
389 IAccessor::VariableType the_variable_type=m_variableType.load(std::memory_order_seq_cst);
390 if( the_variable_type==IProxyLoader::VT_UNK) {
391 auto [variable_type, accessor] = m_proxyLoader->getAccessorFromString(ctx, m_varName);
392 // if ( m_variableType != IProxyLoader::VT_UNK) {
393 if (variable_type != IProxyLoader::VT_VECEMPTY) {
394 // do not cache the accessor and variable type if it was an empty vector because
395 // in such cases there is not enough information to decide the variable type.
396 // otherwise set the accessor if still unset and set the variable type.
397 // Other threads would come to the same conclusion in case the vector is not empty
398 // (or empty), so which thread sets the variable type and/or accessor does not matter.
399 m_accessor.setIfUnset(accessor);
400 m_variableType.store(variable_type, std::memory_order_seq_cst);
401 }
402 // for the current event what ever getAccessorFromString returned is a good choice
403 // independent of other threads which might have had more information for a final
404 // decision. So, for this evaluation what ever getAccessorFromString returned will
405 // be used.
406 the_variable_type = variable_type;
407 }
408 assert((the_variable_type == IProxyLoader::VT_UNK && m_accessor == true) );
409
410 switch( the_variable_type ) {
412 tmp = m_accessor->loadInt(ctx, m_varName );
413 break;
414
416 tmp = m_accessor->loadDouble(ctx, m_varName );
417 break;
418
420 tmp = m_accessor->loadVecInt(ctx, m_varName );
421 break;
422
424 tmp = m_accessor->loadVec(ctx, m_varName );
425 break;
426 }
428 tmp=std::vector<double>();
429 break;
431 default:
432 throw std::runtime_error( "Got VT_UNK - unknown identifier: " +
433 m_varName );
434 break;
435 }
436
437 return tmp;
438 }
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 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 }
static Double_t a

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

◆ operator<<

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

Declare the print operator as a friend of the class.

Definition at line 788 of file StackElement.cxx.

789 {
790
791 switch( el.m_type ) {
792
794 os << "(int)" << el.m_intVal;
795 break;
796
798 os << "(double)" << el.m_doubleVal;
799 break;
800
802 os << "(vec<int>)" << el.m_vecIntVal;
803 break;
804
806 os << "(vec<double>)" << el.m_vecDoubleVal;
807 break;
808
810 os << "SE_UNK";
811 break;
812
813 default:
814 break;
815 }
816
817 return os;
818 }

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: