artdaq_mfextensions  v1_06_02
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_condition.h"
5 #include "ErrorHandler/MessageAnalyzer/ma_function.h"
6 #include "ErrorHandler/MessageAnalyzer/ma_types.h"
7 
8 #include <boost/any.hpp>
9 #include <boost/shared_ptr.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  // c'tor
33  : cond_type(COND)
34  , cond_arg(cond_arg_t(cond_idx_t(NULL, 0), NONE))
35  , op(CO_L)
36  , rhv_b(false)
37  , rhv_d(0.0)
38  , rhv_s()
39  , ext_func()
40  , expr()
41  {}
42 
43  // reset boolean cond
44  void reset();
45 
46  // evaluation
47  bool evaluate(ma_domain& value, ma_domain& alarm, ma_domain const& domain) const;
48 
49  // insert a boolean expression
50  void insert_expr(ma_boolean_expr const& expr);
51 
52  // insert a primitive condition
53  void insert_cond(cond_idx_t ci)
54  {
55  cond_arg.first = ci;
56  cond_arg.second = NONE;
57  }
58 
59  void insert_ext_func(cond_idx_t ci, arg_t arg, std::vector<boost::any> const& func_args, std::string const& function);
60 
61  void insert_compare_op_bool(compare_op_t cop, bool v)
62  {
63  op = cop;
64  rhv_b = v;
65  cond_type = FUNCTION_BOOL;
66  }
67 
68  void insert_compare_op_double(compare_op_t cop, double v)
69  {
70  op = cop;
71  rhv_d = v;
72  cond_type = FUNCTION_DOUBLE;
73  }
74 
75  void insert_compare_op_string(compare_op_t cop, std::string const& v)
76  {
77  op = cop;
78  rhv_s = v;
79  cond_type = FUNCTION_STRING;
80  }
81 
82 private:
83  // type of this element condition
84  cond_type_t cond_type;
85 
86  // case COND: this boolean cond is the boolean value of a ma_condition
87  // a pointer to the condition in the one big condition container
88  // DOES NOT own the condition
89  cond_arg_t cond_arg;
90 
91  // case EXT_FUNCTION:
92  // op: compare operator, <, <=, ==, !=, >=, >
93  // rhv: righ-hand value
94  // ext_func: ptr to a customized evaluation function. use ext_func->evaluate()
95  // to evaluate
96  compare_op_t op;
97  bool rhv_b;
98  double rhv_d;
99  std::string rhv_s;
100  boost::shared_ptr<ma_function> ext_func;
101 
102  // shared_ptr to an boolean expression
103  // a smart pointer to an boolean expression object
104  // DOES own the expression object
105  boost::shared_ptr<ma_boolean_expr> expr;
106 };
107 
108 typedef std::list<ma_boolean_cond> boolean_conds_t;
109 
110 } // end of namespace errorhandler
111 } // end of namespace novadaq
112 
113 #endif