19 template<
typename T >
20 std::ostream&
operator <<( std::ostream& os,
const std::vector< T >&
vec ) {
23 for( std::size_t i = 0;
i <
vec.size(); ++
i ) {
25 if( ( i + 1 ) <
vec.size() ) {
113 if (this->
m_moved)
throw std::logic_error(
"Content already moved");
120 temp.m_intVal = !( temp.m_intVal );
125 temp.m_intVal = !( temp.m_doubleVal );
129 for( std::size_t i = 0; i < temp.m_vecIntVal.size(); ++i ) {
130 temp.m_vecIntVal[ i ] = !( temp.m_vecIntVal[ i ] );
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 ] );
143 throw std::runtime_error(
"! operator called on unknown "
155 if (this->
m_moved)
throw std::logic_error(
"Content already moved");
163 temp.m_intVal = -( this->
m_intVal );
171 for( std::size_t i = 0; i < temp.m_vecIntVal.size(); ++i ) {
172 temp.m_vecIntVal[ i ] = -( temp.m_vecIntVal[ i ] );
177 for( std::size_t i = 0; i < temp.m_vecDoubleVal.size(); ++i ) {
178 temp.m_vecDoubleVal[ i ] = -( temp.m_vecDoubleVal[ i ] );
183 throw std::runtime_error(
"- operator called on unknown "
193#define IMPL_ASSIGN_OP( OP ) \
194 StackElement& StackElement::operator OP( StackElement& rhs ) { \
195 makeVectorIfNecessary( rhs ); \
196 makeDoubleIfNecessary( rhs ); \
199 m_intVal OP rhs.scalarValue< int >(); \
202 m_doubleVal OP rhs.scalarValue< double >(); \
205 *this OP rhs.vectorValue< int >( m_vecIntVal.size() ); \
208 *this OP rhs.vectorValue< double >( m_vecDoubleVal.size() ); \
211 throw std::runtime_error( "StackElement ill-defined in " \
249 throw std::runtime_error(
"asInt() only valid for SE_INT" );
258 throw std::runtime_error(
"asBool() only valid for non-vector types" );
268 if (this->
m_moved)
throw std::logic_error(
"Content already moved");
282 return std::vector<int>( sizeIfScalar,
m_intVal );
286 return std::vector<int>( sizeIfScalar,
static_cast< int >(
m_doubleVal ) );
290 throw std::runtime_error(
"(int) vectorValue(): Unsupported "
294 return std::vector<int>();
298 std::vector< double >
301 if (this->
m_moved)
throw std::logic_error(
"Content already moved");
316 return std::vector<double>(sizeIfScalar,
static_cast< double >(
m_intVal ) );
320 return std::vector<double>(sizeIfScalar,
m_doubleVal );
324 throw std::runtime_error(
"(dbl) vectorValue(): Unsupported "
328 return std::vector<double>();
340 m_vecIntVal.push_back(
static_cast< int >( value ) );
399 m_accessor.setIfUnset(accessor);
406 the_variable_type = variable_type;
410 switch( the_variable_type ) {
412 tmp = m_accessor->loadInt(ctx,
m_varName );
416 tmp = m_accessor->loadDouble(ctx,
m_varName );
420 tmp = m_accessor->loadVecInt(ctx,
m_varName );
424 tmp = m_accessor->loadVec(ctx,
m_varName );
428 tmp=std::vector<double>();
432 throw std::runtime_error(
"Got VT_UNK - unknown identifier: " +
441 template <
class T_CompHelper,
class T>
442 std::vector<int>
compareVector(std::vector<T> &&
a, std::vector<T> &&b,T_CompHelper helper)
444 std::vector<int> ret;
445 ret.resize(
a.size());
446 assert(
a.size() == b.size() );
447 for (std::size_t idx=0; idx <
a.size(); ++idx) {
448 ret[idx] = helper.compare(
a[idx],b[idx]);
452 template <
class T_CompHelper,
class T>
453 std::vector<int>
compareVectorAlt(
const std::vector<T> &&
a, std::vector<T> &&b,T_CompHelper helper)
458 template <
class T_CompHelper>
459 std::vector<int>
compareVector(std::vector<int> &&
a,
const std::vector<int> &&b,T_CompHelper helper)
461 assert(
a.size() == b.size() );
462 for (std::size_t idx=0; idx <
a.size(); ++idx) {
463 a[idx] = helper.compare(
a[idx],b[idx]);
465 return std::vector<int>(std::move(
a));
468 template <
class T_CompHelper>
469 std::vector<int>
compareVectorAlt(
const std::vector<int> &&
a, std::vector<int> &&b,T_CompHelper helper)
471 assert(
a.size() == b.size() );
472 for (std::size_t idx=0; idx <
a.size(); ++idx) {
473 b[idx] = helper.compare(
a[idx],b[idx]);
475 return std::vector<int>(std::move(b));
478 template <
class T_CompHelper>
482 throw std::runtime_error(
"ERROR: Can't operate on SE_UNK "
485 if(
isScalar() && other.isScalar() ) {
492 if (
isVector() && other.isVector() && this->size() != other.size()) {
493 throw std::runtime_error(
"Incompatible vectors - different length" );
509 class Helper_eq {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a == b; } };
512 class Helper_or {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a || b; } };
513 class Helper_gt {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a > b; } };
515 class Helper_lt {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a < b; } };
532 throw std::runtime_error(
"Can't use vector as exponent" );
534 return _pow( n.scalarValue<
double >() );
615 if (this->
m_moved)
throw std::logic_error(
"Content already moved");
622 m_intVal = std::abs( temp.m_intVal );
631 for(
int &value : temp.m_vecIntVal ) {
632 value = std::abs( value );
639 for(
double &value : temp.m_vecDoubleVal ) {
640 value = std::abs( value );
653#define UNARY_MATH_FUNCTION( FUNC, BASEFUNC ) \
654 StackElement StackElement::FUNC() { \
655 if (this->m_moved) throw std::logic_error("Content already moved");\
656 StackElement temp( std::move(*this) ); \
657 this->m_moved=true; \
659 if( temp.m_type == SE_DOUBLE ) { \
660 temp.m_doubleVal = BASEFUNC( temp.m_doubleVal ); \
662 } else if( temp.m_type == SE_VECDOUBLE ) { \
663 for( double& value : temp.m_vecDoubleVal ) { \
664 value = BASEFUNC( value ); \
691#undef UNARY_MATH_FUNCTION
698 if( other.isVector() ) {
767 if( this->
m_type != other.m_type ) {
768 throw std::runtime_error(
"Incompatible stack elements" );
782 const std::size_t ourlen =
size();
783 if( ourlen != other.size() ) {
784 throw std::runtime_error(
"Incompatible vectors - different length" );
791 switch( el.m_type ) {
794 os <<
"(int)" << el.m_intVal;
798 os <<
"(double)" << el.m_doubleVal;
802 os <<
"(vec<int>)" << el.m_vecIntVal;
806 os <<
"(vec<double>)" << el.m_vecDoubleVal;
std::vector< size_t > vec
#define IMPL_ASSIGN_OP(OP)
Helper macro implementing the assignment operator specialisations.
#define UNARY_MATH_FUNCTION(FUNC, BASEFUNC)
Helper macro for implementing many of the mathematical functions.
std::ostream & operator<<(std::ostream &lhs, const TestGaudiProperty &rhs)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
int compare(const T &a, const T &b)
std::string m_varName
The name/definition of the variable.
int asInt() const
Get the internal value of the object as an integer.
bool isVector() const
Check if the object describes a vector value.
IProxyLoader * m_proxyLoader
Loader for the described variable.
std::vector< double > m_vecDoubleVal
The value of the object represented as a vector of doubles.
std::vector< T > vectorValue(std::size_t sizeIfScalar=0)
Evaluate the value of the object into the requested vector type.
StackElement _gt(StackElement &other)
void makeDouble()
Function constructing internal double values in case integer values were given to the object initiall...
StackElement _comparisonOp(StackElement &other, T_CompHelper comp_helper)
StackElement operator!()
NOT operator.
bool isProxy() const
Check if the object takes its value from a StoreGate object.
StackElement _lt(StackElement &other)
std::atomic< bool > m_moved
Internal flag showing whether the type of the variable was already determined.
StackElement & operator=(int rhs)
Operator assigning an integer value to the object.
StackElement _pow(const T &n)
Function raising the object's value to the n'th power.
bool asBool() const
Get the internal value of the object as a boolean.
T scalarValue() const
Evaluate the value of the object into the requested scalar type.
StackElement _eq(StackElement &other)
bool isScalar() const
Check if the object describes a scalar value.
ElementType
Type of the data held by this object.
@ SE_UNK
The type is not known, or not applicable.
@ SE_INT
The type is an integer.
@ SE_DOUBLE
The type is a double.
@ SE_VECINT
The type is a vector of integers.
@ SE_VECDOUBLE
The type is a vector of doubles.
void makeVectorIfNecessary(const StackElement &other)
The macro is not needed anymore:
StackElement _neq(StackElement &other)
StackElement _abs()
Function taking the absolute value of the object.
StackElement valueFromProxy(const EventContext &ctx) const
Set the internal variables of the object based on the objects in SG.
StackElement _or(StackElement &other)
StackElement _and(StackElement &other)
StackElement _sum()
Function calculating a sum value.
void ensureCompatibleVectors(const T &other) const
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 operator-()
Inverse operator.
void makeVector(std::size_t n)
Function converting a possibly scalar value into a vector.
StackElement _count()
Function counting elements.
ElementType getType() const
Get the variable type of the object.
StackElement()
Default constructor.
void ensureCompatible(const StackElement &other) const
std::vector< int > m_vecIntVal
The value of the object represented as a vector of integers.
StackElement _gte(StackElement &other)
std::atomic< IAccessor::VariableType > m_variableType
Type of the variable provided by the proxy loader.
void makeInt()
Function constructing internal integer values in case double values were given to the object initiall...
double m_doubleVal
The value of the object represented as a double.
void makeDoubleIfNecessary(const StackElement &other)
StackElement _lte(StackElement &other)
Namespace holding all the expression evaluation code.
std::ostream & operator<<(std::ostream &os, const StackElement &el)
Declare an output operator for StackElement objects.
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)