Belle II Software development
ModuleCondition Class Reference

Wraps a condition set on a Module instance. More...

#include <ModuleCondition.h>

Public Types

enum  EConditionOperators {
  c_GT ,
  c_ST ,
  c_GE ,
  c_SE ,
  c_EQ ,
  c_NE
}
 The supported condition operators. More...
 
enum class  EAfterConditionPath {
  c_End ,
  c_Continue
}
 Different options for behaviour after a conditional path was executed. More...
 

Public Member Functions

 ModuleCondition (std::string expression, std::shared_ptr< Path > conditionPath, EAfterConditionPath afterConditionPath)
 initialize from string expression (see class doc).
 
 ~ModuleCondition ()=default
 Destructor, nothing to see here.
 
 ModuleCondition (const ModuleCondition &other)=default
 default copy constructor.
 
ModuleConditionoperator= (const ModuleCondition &other)=default
 and default assignment operator
 
bool evaluate (int value) const
 evaluate the condition using the given value.
 
const std::shared_ptr< Path > & getPath () const
 Returns the path of the condition.
 
int getConditionValue () const
 Returns the value of the condition.
 
EConditionOperators getConditionOperator () const
 Returns the value of the condition.
 
EAfterConditionPath getAfterConditionPath () const
 What to do after a conditional path is finished.
 
std::string getString () const
 A string representation of this condition.
 

Static Public Member Functions

static void exposePythonAPI ()
 Exposes methods of the ModuleCondition class to Python.
 

Private Member Functions

 ModuleCondition ()=delete
 no default constructed objects.
 

Private Attributes

std::shared_ptr< Pathm_conditionPath
 The path which which will be executed if the condition is evaluated to true.
 
EConditionOperators m_conditionOperator
 The operator of the condition (set by parsing the condition expression).
 
int m_conditionValue
 Numeric value used in the condition (set by parsing the condition expression).
 
EAfterConditionPath m_afterConditionPath
 What to do after a conditional path is finished.
 

Detailed Description

Wraps a condition set on a Module instance.

It supports conditions of the form [comparison operator][integer] e.g. ">5", "=7", "!= 0"

Additional spaces in front of the operator, between operator and integer number and after the integer number are allowed.

Supported operators are: "> , < , = , == , >= , <= , !="

Definition at line 29 of file ModuleCondition.h.

Member Enumeration Documentation

◆ EAfterConditionPath

enum class EAfterConditionPath
strong

Different options for behaviour after a conditional path was executed.

Enumerator
c_End 

End current event after the conditional path.

c_Continue 

After the conditional path, resume execution after this module.

Definition at line 42 of file ModuleCondition.h.

42 {
43 c_End,
45 };
@ c_End
End current event after the conditional path.
@ c_Continue
After the conditional path, resume execution after this module.

◆ EConditionOperators

The supported condition operators.

Enumerator
c_GT 

Greater than: ">"

c_ST 

Smaller than: "<"

c_GE 

Greater or equal than: ">=".

c_SE 

Smaller or equal than: "<=".

c_EQ 

Equal: "=" or "=="

c_NE 

Not equal: "!=".

Definition at line 32 of file ModuleCondition.h.

32 {
33 c_GT,
34 c_ST,
35 c_GE,
36 c_SE,
37 c_EQ,
38 c_NE
39 };
@ c_GE
Greater or equal than: ">=".
@ c_SE
Smaller or equal than: "<=".
@ c_GT
Greater than: ">"
@ c_NE
Not equal: "!=".
@ c_EQ
Equal: "=" or "=="
@ c_ST
Smaller than: "<"

Constructor & Destructor Documentation

◆ ModuleCondition()

ModuleCondition ( std::string  expression,
std::shared_ptr< Path conditionPath,
EAfterConditionPath  afterConditionPath 
)

initialize from string expression (see class doc).

Throws runtime_error if expression is invalid.

Member Function Documentation

◆ evaluate()

bool evaluate ( int  value) const

evaluate the condition using the given value.

E.g. for a condition ">5", this would return "value>5"

Definition at line 57 of file ModuleCondition.cc.

58{
59 switch (m_conditionOperator) {
60 case c_GT : return value > m_conditionValue;
61 case c_ST : return value < m_conditionValue;
62 case c_GE : return value >= m_conditionValue;
63 case c_SE : return value <= m_conditionValue;
64 case c_EQ : return value == m_conditionValue;
65 case c_NE : return value != m_conditionValue;
66 }
67 return false;
68}
EConditionOperators m_conditionOperator
The operator of the condition (set by parsing the condition expression).
int m_conditionValue
Numeric value used in the condition (set by parsing the condition expression).

◆ exposePythonAPI()

void exposePythonAPI ( )
static

Exposes methods of the ModuleCondition class to Python.

Definition at line 93 of file ModuleCondition.cc.

94{
95 docstring_options options(true, true, false); //userdef, py sigs, c++ sigs
96
97 //Python class definition
98 class_<ModuleCondition, boost::noncopyable>("ModuleCondition", no_init)
99 .def("__str__", &ModuleCondition::getString)
100 .def("get_value", &ModuleCondition::getConditionValue)
101 .def("get_operator", &ModuleCondition::getConditionOperator)
102 .def("get_after_path", &ModuleCondition::getAfterConditionPath)
103 .def("get_path", &_getPathPython)
104 ;
105}
std::string getString() const
A string representation of this condition.
EConditionOperators getConditionOperator() const
Returns the value of the condition.
int getConditionValue() const
Returns the value of the condition.
EAfterConditionPath getAfterConditionPath() const
What to do after a conditional path is finished.

◆ getAfterConditionPath()

EAfterConditionPath getAfterConditionPath ( ) const
inline

What to do after a conditional path is finished.

Definition at line 69 of file ModuleCondition.h.

69{ return m_afterConditionPath; }
EAfterConditionPath m_afterConditionPath
What to do after a conditional path is finished.

◆ getConditionOperator()

EConditionOperators getConditionOperator ( ) const
inline

Returns the value of the condition.


Definition at line 66 of file ModuleCondition.h.

66{return m_conditionOperator; }

◆ getConditionValue()

int getConditionValue ( ) const
inline

Returns the value of the condition.


Definition at line 63 of file ModuleCondition.h.

63{return m_conditionValue; }

◆ getPath()

const std::shared_ptr< Path > & getPath ( ) const
inline

Returns the path of the condition.


Definition at line 60 of file ModuleCondition.h.

60{return m_conditionPath; }
std::shared_ptr< Path > m_conditionPath
The path which which will be executed if the condition is evaluated to true.

◆ getString()

std::string getString ( ) const

A string representation of this condition.

Definition at line 70 of file ModuleCondition.cc.

71{
72 std::string output = "(? ";
73 switch (m_conditionOperator) {
74 case c_GT: output += ">"; break;
75 case c_ST: output += "<"; break;
76 case c_GE: output += ">="; break;
77 case c_SE: output += "<="; break;
78 case c_NE: output += "!="; break;
79 case c_EQ: output += "=="; break;
80 default: output += "???";
81 }
82 output += std::to_string(m_conditionValue);
83 output += m_conditionPath->getPathString();
84 output += " )";
85 return output;
86}

Member Data Documentation

◆ m_afterConditionPath

EAfterConditionPath m_afterConditionPath
private

What to do after a conditional path is finished.

Definition at line 86 of file ModuleCondition.h.

◆ m_conditionOperator

EConditionOperators m_conditionOperator
private

The operator of the condition (set by parsing the condition expression).

Definition at line 84 of file ModuleCondition.h.

◆ m_conditionPath

std::shared_ptr<Path> m_conditionPath
private

The path which which will be executed if the condition is evaluated to true.

Definition at line 83 of file ModuleCondition.h.

◆ m_conditionValue

int m_conditionValue
private

Numeric value used in the condition (set by parsing the condition expression).

Definition at line 85 of file ModuleCondition.h.


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