artdaq_mfextensions  v1_06_02
ma_action.h
1 #ifndef ERROR_HANDLER_MA_ACTION_H
2 #define ERROR_HANDLER_MA_ACTION_H
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 #include "ErrorHandler/MessageAnalyzer/ma_types.h"
9 
10 #include <fhiclcpp/ParameterSet.h>
11 
12 #include <boost/any.hpp>
13 #include <boost/function.hpp>
14 
15 namespace novadaq {
16 namespace errorhandler {
17 
18 class ma_condition;
19 class ma_rule;
20 
21 typedef std::vector<boost::any> anys_t;
22 typedef fhicl::ParameterSet pset_t;
23 
25 class ma_action
26 {
27 public:
28  ma_action(ma_rule const *rule, pset_t const &pset = pset_t())
29  : parent_rule(*rule), parameter(pset) {}
30  virtual ~ma_action() {}
31 
32  virtual bool exec() = 0;
33 
34 protected:
35  ma_rule const &parent_rule;
36  pset_t parameter;
37 
38 private:
39 };
40 
41 typedef std::vector<ma_action *> ma_actions;
42 
43 typedef boost::function<ma_action *(ma_rule const *, pset_t const &)> gen_act_t;
44 
46 {
47  typedef std::map<std::string, gen_act_t> gen_map_t;
48 
49 public:
50  static void
51  reg(std::string const &action_name, gen_act_t f);
52 
53  static ma_action *
54  create_instance(std::string const &act_name, ma_rule const *rule, pset_t const &pset);
55 
56 private:
58 
59  static gen_map_t &
60  get_map()
61  {
62  static gen_map_t map;
63  return map;
64  }
65 };
66 
68 {
69  ma_action_maker(std::string const &act_name, gen_act_t f)
70  {
71  ma_action_factory::reg(act_name, f);
72  }
73 };
74 
75 } // end of namespace errorhandler
76 } // end of namespace novadaq
77 
78 // -------------------------------------------------
79 // Macro for registering the custom function
80 
81 #define REG_MA_ACTION(act_name, class_name) \
82  ma_action * \
83  class_name##_maker_func(ma_rule const *r, fhicl::ParameterSet const &p) \
84  { \
85  return new class_name(r, p); \
86  } \
87  ma_action_maker \
88  class_name##_maker_func_global_var(#act_name, class_name##_maker_func);
89 
90 #endif
base class - all customized fucntions are inherited from it
Definition: ma_action.h:25