artdaq_mfextensions  v1_05_00
ma_boolean_cond.h
1 #ifndef ERROR_HANDLER_MA_BOOLEAN_COND_H
2 #define ERROR_HANDLER_MA_BOOLEAN_COND_H
3 
4 #include "ErrorHandler/MessageAnalyzer/ma_types.h"
5 #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
6 #include "ErrorHandler/MessageAnalyzer/ma_function.h"
7 
8 #include <boost/shared_ptr.hpp>
9 #include <boost/any.hpp>
10 
11 #include <list>
12 
13 namespace novadaq {
14 namespace errorhandler {
15 
16 class ma_rule;
17 class ma_boolean_expr;
18 
19 //-------------------------------------------------------------------
20 //
21 // elementary boolean condition has three possible cases:
22 // 1. '(' + boolean_expr + ')'
23 // 2. primitive elementary boolean condition Cn
24 // 3. non-primitive boolean condition ( COUNT(Cn.$s|t) )
25 //
26 //-------------------------------------------------------------------
27 
29 {
30 public:
31 
32  // c'tor
33  ma_boolean_cond( )
34  : cond_type ( COND )
35  , cond_arg ( cond_arg_t(cond_idx_t(NULL, 0), NONE) )
36  , op ( CO_L )
37  , rhv_b ( false )
38  , rhv_d ( 0.0 )
39  , rhv_s ( )
40  , ext_func ( )
41  , expr ( )
42  { }
43 
44  // reset boolean cond
45  void reset( );
46 
47  // evaluation
48  bool evaluate( ma_domain & value
49  , ma_domain & alarm
50  , ma_domain const & domain ) const;
51 
52  // insert a boolean expression
53  void insert_expr( ma_boolean_expr const & expr );
54 
55  // insert a primitive condition
56  void insert_cond( cond_idx_t ci )
57  { cond_arg.first = ci; cond_arg.second = NONE; }
58 
59  void insert_ext_func( cond_idx_t ci
60  , arg_t arg
61  , std::vector<boost::any> const & func_args
62  , std::string const & function );
63 
64  void insert_compare_op_bool ( compare_op_t cop, bool v )
65  { op = cop; rhv_b = v; cond_type = FUNCTION_BOOL; }
66 
67  void insert_compare_op_double( compare_op_t cop, double v )
68  { op = cop; rhv_d = v; cond_type = FUNCTION_DOUBLE; }
69 
70  void insert_compare_op_string( compare_op_t cop, std::string const & v )
71  { op = cop; rhv_s = v; cond_type = FUNCTION_STRING; }
72 
73 
74 private:
75 
76  // type of this element condition
77  cond_type_t cond_type;
78 
79  // case COND: this boolean cond is the boolean value of a ma_condition
80  // a pointer to the condition in the one big condition container
81  // DOES NOT own the condition
82  cond_arg_t cond_arg;
83 
84  // case EXT_FUNCTION:
85  // op: compare operator, <, <=, ==, !=, >=, >
86  // rhv: righ-hand value
87  // ext_func: ptr to a customized evaluation function. use ext_func->evaluate()
88  // to evaluate
89  compare_op_t op;
90  bool rhv_b;
91  double rhv_d;
92  std::string rhv_s;
93  boost::shared_ptr<ma_function> ext_func;
94 
95  // shared_ptr to an boolean expression
96  // a smart pointer to an boolean expression object
97  // DOES own the expression object
98  boost::shared_ptr<ma_boolean_expr> expr;
99 
100 };
101 
102 typedef std::list<ma_boolean_cond> boolean_conds_t;
103 
104 } // end of namespace errorhandler
105 } // end of namespace novadaq
106 
107 #endif