artdaq_mfextensions  v1_05_00
ma_rule_engine.h
1 #ifndef ERROR_HANDLER_MA_RULE_ENGINE_H
2 #define ERROR_HANDLER_MA_RULE_ENGINE_H
3 
4 #include "ErrorHandler/MessageAnalyzer/ma_types.h"
5 #include "ErrorHandler/MessageAnalyzer/ma_condition.h"
6 #include "ErrorHandler/MessageAnalyzer/ma_rule.h"
7 #include "ErrorHandler/MessageAnalyzer/ma_participants.h"
8 
9 #include "ErrorHandler/MessageAnalyzer/ma_timing_event.h"
10 #include <boost/thread.hpp>
11 
12 namespace fhicl
13 {
14  class ParameterSet;
15 }
16 
17 namespace novadaq {
18 namespace errorhandler {
19 
21 {
22 public:
23 
24  // c'tor
25  ma_rule_engine( fhicl::ParameterSet const & pset
26  , alarm_fn_t alarm
27  , cond_match_fn_t cond_match );
28 
29  // public method, call to run the rule engine
30  void feed( qt_mf_msg const & msg );
31 
32  // public accessor for cond map and rule map
33  size_t cond_size() const { return cmap.size(); }
34  size_t rule_size() const { return rmap.size(); }
35 
36  const std::vector<std::string> & cond_names() const { return cnames; }
37  const std::vector<std::string> & rule_names() const { return rnames; }
38 
39  bool is_EHS() const { return EHS; }
40 
41  // get the raw configuration ParameterSet object
42  fhicl::ParameterSet
43  get_configuration() const
44  { return pset; }
45 
46  // get condition fields
47  const std::string &
48  cond_description( std::string const & name ) const
49  { return find_cond_by_name(name).description(); }
50 
51  const std::string &
52  cond_sources ( std::string const & name ) const
53  { return find_cond_by_name(name).sources_str(); }
54 
55  const std::string &
56  cond_regex ( std::string const & name ) const
57  { return find_cond_by_name(name).regex(); }
58 
59  int
60  cond_msg_count ( std::string const & name ) const
61  { return find_cond_by_name(name).get_msg_count(); }
62 
63  // get rule fields
64  const std::string &
65  rule_description( std::string const & name ) const
66  { return find_rule_by_name(name).description(); }
67 
68  const std::string &
69  rule_expr ( std::string const & name ) const
70  { return find_rule_by_name(name).cond_expr(); }
71 
72  const std::vector<std::string> &
73  rule_cond_names( std::string const & name ) const
74  { return find_rule_by_name(name).cond_names(); }
75 
76  int
77  rule_alarm_count ( std::string const & name ) const
78  { return find_rule_by_name(name).get_alarm_count(); }
79 
80  // set rule enable/disable status
81  void enable_rule( std::string const & name, bool flag )
82  { find_rule_by_name(name).enable(flag); }
83 
84  // enable/disable EHS
85  void enable_EHS( bool flag )
86  { EHS = flag; }
87 
88  // reset a rule to its ground state (reset alarms and domains)
89  void reset_rule( std::string const & name )
90  { find_rule_by_name(name).reset(); }
91 
92  void reset_rules( )
93  { for(rule_map_t::iterator it=rmap.begin(); it!=rmap.end(); ++it)
94  it->second.reset(); }
95 
96  // reset conditions
97  void reset_cond( std::string const & name )
98  { find_cond_by_name(name).reset(); }
99 
100  void reset_conds( )
101  { for(cond_map_t::iterator it=cmap.begin(); it!=cmap.end(); ++it)
102  it->second.reset(); }
103 
104  // reset all
105  void reset( )
106  { reset_conds(); reset_rules(); }
107 
108  // participants
109  void add_participant_group( std::string const & group )
110  { ma_participants::instance().add_group( group ); }
111 
112  void add_participant_group( std::string const & group, size_t size )
113  { ma_participants::instance().add_group( group, size ); }
114 
115  void add_participant( std::string const & group, std::string const & app )
116  { ma_participants::instance().add_participant( group, app ); }
117 
118  void add_participant( std::string const & app )
119  { ma_participants::instance().add_participant( app ); }
120 
121  size_t get_group_participant_count( std::string const & group ) const
122  { return ma_participants::instance().get_group_participant_count(group); }
123 
124  size_t get_participant_count( ) const
125  { return ma_participants::instance().get_participant_count(); }
126 
127 
128 private:
129 
130  // initialize the rule engine with configuration file
131  void init_engine( );
132 
133  // event worker
134  void event_worker( );
135 
136  // merge notification list from conditions
137  void merge_notify_list( notify_list_t & n_list
138  , conds_t const & c_list
139  , notify_t type );
140 
141  // evaluates the domain / status of all rules in the notification list
142  void evaluate_rules_domain( notify_list_t & notify_domain );
143  void evaluate_rules( notify_list_t & notify_status );
144 
145  // find condition/rule with given name
146  const ma_condition & find_cond_by_name( std::string const & name ) const;
147  ma_condition & find_cond_by_name( std::string const & name );
148 
149  const ma_rule & find_rule_by_name( std::string const & name ) const;
150  ma_rule & find_rule_by_name( std::string const & name );
151 
152 private:
153 
154  // configuration
155  fhicl::ParameterSet pset;
156 
157  // map of conditions
158  cond_map_t cmap;
159  std::vector<std::string> cnames;
160 
161  // map of rules
162  rule_map_t rmap;
163  std::vector<std::string> rnames;
164 
165  // callbacks
166  alarm_fn_t alarm_fn;
167  cond_match_fn_t cond_match_fn;
168 
169  // a list of scheduled events
170  ma_timing_events events;
171 
172  // event thread
173  boost::thread event_worker_t;
174 
175  // whether this engine is an Error Handler Supervisor
176  bool EHS;
177 };
178 
179 
180 } // end of namespace errorhandler
181 } // end of namespace novadaq
182 
183 
184 #endif
Qt wrapper around MessageFacility message
Definition: qt_mf_msg.hh:37