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");
314 return std::vector<double>(sizeIfScalar,
static_cast< double >(
m_intVal ) );
318 return std::vector<double>(sizeIfScalar,
m_doubleVal );
322 throw std::runtime_error(
"(dbl) vectorValue(): Unsupported "
337 m_vecIntVal.push_back(
static_cast< int >( value ) );
396 m_accessor.setIfUnset(accessor);
403 the_variable_type = variable_type;
407 switch( the_variable_type ) {
409 tmp = m_accessor->loadInt(ctx,
m_varName );
413 tmp = m_accessor->loadDouble(ctx,
m_varName );
417 tmp = m_accessor->loadVecInt(ctx,
m_varName );
421 tmp = m_accessor->loadVec(ctx,
m_varName );
425 tmp=std::vector<double>();
429 throw std::runtime_error(
"Got VT_UNK - unknown identifier: " +
438 template <
class T_CompHelper,
class T>
439 std::vector<int>
compareVector(std::vector<T> &&
a, std::vector<T> &&b,T_CompHelper helper)
441 std::vector<int> ret;
442 ret.resize(
a.size());
443 assert(
a.size() == b.size() );
444 for (std::size_t idx=0; idx <
a.size(); ++idx) {
445 ret[idx] = helper.compare(
a[idx],b[idx]);
449 template <
class T_CompHelper,
class T>
450 std::vector<int>
compareVectorAlt(
const std::vector<T> &&
a, std::vector<T> &&b,T_CompHelper helper)
455 template <
class T_CompHelper>
456 std::vector<int>
compareVector(std::vector<int> &&
a,
const std::vector<int> &&b,T_CompHelper helper)
458 assert(
a.size() == b.size() );
459 for (std::size_t idx=0; idx <
a.size(); ++idx) {
460 a[idx] = helper.compare(
a[idx],b[idx]);
462 return std::vector<int>(std::move(
a));
465 template <
class T_CompHelper>
466 std::vector<int>
compareVectorAlt(
const std::vector<int> &&
a, std::vector<int> &&b,T_CompHelper helper)
468 assert(
a.size() == b.size() );
469 for (std::size_t idx=0; idx <
a.size(); ++idx) {
470 b[idx] = helper.compare(
a[idx],b[idx]);
472 return std::vector<int>(std::move(b));
475 template <
class T_CompHelper>
479 throw std::runtime_error(
"ERROR: Can't operate on SE_UNK "
482 if(
isScalar() && other.isScalar() ) {
489 if (
isVector() && other.isVector() && this->size() != other.size()) {
490 throw std::runtime_error(
"Incompatible vectors - different length" );
506 class Helper_eq {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a == b; } };
509 class Helper_or {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a || b; } };
510 class Helper_gt {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a > b; } };
512 class Helper_lt {
public:
template <
class T>
int compare(
const T &
a,
const T &b) {
return a < b; } };
529 throw std::runtime_error(
"Can't use vector as exponent" );
531 return _pow( n.scalarValue<
double >() );
612 if (this->
m_moved)
throw std::logic_error(
"Content already moved");
619 m_intVal = std::abs( temp.m_intVal );
628 for(
int &value : temp.m_vecIntVal ) {
629 value = std::abs( value );
636 for(
double &value : temp.m_vecDoubleVal ) {
637 value = std::abs( value );
650#define UNARY_MATH_FUNCTION( FUNC, BASEFUNC ) \
651 StackElement StackElement::FUNC() { \
652 if (this->m_moved) throw std::logic_error("Content already moved");\
653 StackElement temp( std::move(*this) ); \
654 this->m_moved=true; \
656 if( temp.m_type == SE_DOUBLE ) { \
657 temp.m_doubleVal = BASEFUNC( temp.m_doubleVal ); \
659 } else if( temp.m_type == SE_VECDOUBLE ) { \
660 for( double& value : temp.m_vecDoubleVal ) { \
661 value = BASEFUNC( value ); \
688#undef UNARY_MATH_FUNCTION
695 if( other.isVector() ) {
764 if( this->
m_type != other.m_type ) {
765 throw std::runtime_error(
"Incompatible stack elements" );
779 const std::size_t ourlen =
size();
780 if( ourlen != other.size() ) {
781 throw std::runtime_error(
"Incompatible vectors - different length" );
788 switch( el.m_type ) {
791 os <<
"(int)" << el.m_intVal;
795 os <<
"(double)" << el.m_doubleVal;
799 os <<
"(vec<int>)" << el.m_vecIntVal;
803 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)