artdaq_mfextensions  v1_05_00
ma_function.h
1 #ifndef ERROR_HANDLER_MA_FUNCTION_H
2 #define ERROR_HANDLER_MA_FUNCTION_H
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 
8 #include "ErrorHandler/MessageAnalyzer/ma_types.h"
9 
10 #include <boost/any.hpp>
11 #include <boost/function.hpp>
12 
13 namespace novadaq {
14 namespace errorhandler {
15 
16 class ma_condition;
17 
18 typedef std::vector<boost::any> anys_t;
19 
20 // base class - all customized fucntions are inherited from it
22 {
23 public:
24 
25  ma_function() {}
26  virtual ~ma_function() {}
27 
28  // evaluate() function gets called when the boolean expression
29  // of the rule is being evaluated.
30  //
31  // param 'cond':
32  // 'cond' is the reference to the basic condition to which
33  // this user defined function is related. Though this object
34  // the function can have access to the most recent message
35  // that triggeres the condition, as well as other historical
36  // information
37  //
38  // param 'dom':
39  // when using complex conditions and domain selection clauses
40  // in the rule expression, a user define function might get
41  // evaluated multiple times each for a possible source/targets
42  // domain when a new message comes in. 'dom' contains the domain
43  // of possible source/target combinations in this evaluation.
44  // an example would be, cond.get_alarm_count(dom, cond_type)
45  // returns with the number of triggered source/target pairs
46  // WITHIN the given domain of a condition.
47  //
48  // return value:
49  // the return value could be a boolean, an integer, a double,
50  // or a string object. all of them need to be wrapped in a
51  // boost::any object before returning to the caller
52  virtual boost::any
53  evaluate( ma_condition const & cond
54  , ma_cond_domain dom ) = 0;
55 
56  // a user function is internally implemented by a class, which allows
57  // the function to have states. not surprisingly would the funciton
58  // writers also like to implement a reset method for the purpose of
59  // resetting the state of the user-defined function into its ground
60  // state
61  virtual void
62  reset( ) { }
63 
64  // a user function is allowed to take multiple arguments
65  // other than the condition name that it applies on
66  virtual bool
67  parse_arguments( anys_t const & /*args*/ ) { return true; }
68 
69  // whether the funciton triggers a grouped alarm or
70  // individual alarms with respect to the condition's
71  // source / targets.
72  //
73  // e.g.: a user function COUNT() usually triggers a grouped
74  // alarm, as we dont necessary need to make distinguish
75  // between whether it was source 1,2,5, or source 3,7,8
76  // who trigger the alarm
77  //
78  // an example of non-grouped alarm is the function of
79  // OUT_OF_SYNC(). we are interested in who was out of
80  // sync, and raises alarms for each source
81  virtual bool
82  grouped_alarm( ) { return true; }
83 
84 protected:
85 
86 private:
87 
88 };
89 
90 typedef boost::function<ma_function * ()> gen_func_t;
91 
93 {
94  typedef std::map<std::string, gen_func_t> gen_map_t;
95 
96 public:
97 
98  static void
99  reg( std::string const & func_name, gen_func_t f );
100 
101  static ma_function *
102  create_instance( std::string const & func_name );
103 
104 private:
105 
106  ma_function_factory() {};
107 
108  static gen_map_t &
109  get_map() { static gen_map_t map; return map; }
110 
111 };
112 
114 {
115  ma_function_maker( std::string const & func_name, gen_func_t f )
116  { ma_function_factory::reg( func_name, f ); }
117 };
118 
119 
120 } // end of namespace errorhandler
121 } // end of namespace novadaq
122 
123 
124 // -------------------------------------------------
125 // Macro for registering the custom function
126 
127 #define REG_MA_FUNCTION(func_name, class_name) \
128 ma_function * \
129  class_name ## _maker_func( ) { return new class_name( ); } \
130 ma_function_maker \
131  class_name ## _maker_func_global_var ( #func_name, class_name ## _maker_func );
132 
133 
134 #endif
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146