artdaq_mfextensions  v1_05_00
ma_action.h
1 #ifndef ERROR_HANDLER_MA_ACTION_H
2 #define ERROR_HANDLER_MA_ACTION_H
3 
4 #include <string>
5 #include <vector>
6 #include <map>
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 
24 // base class - all customized fucntions are inherited from it
25 class ma_action
26 {
27 public:
28 
29  ma_action(ma_rule const * rule, pset_t const & pset = pset_t())
30  : parent_rule(*rule), parameter(pset) {}
31  virtual ~ma_action() {}
32 
33  virtual bool exec( ) = 0;
34 
35 protected:
36 
37  ma_rule const & parent_rule;
38  pset_t parameter;
39 
40 private:
41 
42 };
43 
44 typedef std::vector<ma_action *> ma_actions;
45 
46 typedef boost::function<ma_action * (ma_rule const *, pset_t const &)> gen_act_t;
47 
49 {
50  typedef std::map<std::string, gen_act_t> gen_map_t;
51 
52 public:
53 
54  static void
55  reg( std::string const & action_name, gen_act_t f );
56 
57  static ma_action *
58  create_instance( std::string const & act_name, ma_rule const * rule, pset_t const & pset );
59 
60 private:
61 
62  ma_action_factory() {};
63 
64  static gen_map_t &
65  get_map() { static gen_map_t map; return map; }
66 
67 };
68 
70 {
71  ma_action_maker( std::string const & act_name, gen_act_t f )
72  { ma_action_factory::reg( act_name, f ); }
73 };
74 
75 
76 } // end of namespace errorhandler
77 } // end of namespace novadaq
78 
79 
80 // -------------------------------------------------
81 // Macro for registering the custom function
82 
83 #define REG_MA_ACTION(act_name, class_name) \
84 ma_action * \
85  class_name ## _maker_func( ma_rule const * r, fhicl::ParameterSet const & p ) \
86  { return new class_name( r, p ); } \
87 ma_action_maker \
88  class_name ## _maker_func_global_var ( #act_name, class_name ## _maker_func );
89 
90 
91 #endif
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103