VModule.h
Go to the documentation of this file.
1 #ifndef _fwk_VModule_h_
2 #define _fwk_VModule_h_
3 
4 #include <utl/ObjectRegistrar.h>
5 #include <utl/ObjectFactory.h>
6 #include <utl/ErrorLogger.h>
7 #include <utl/Stopwatch.h>
8 
9 #include <boost/algorithm/string.hpp>
10 
11 #include <string>
12 
13 
14 namespace evt {
15  class Event;
16 }
17 
18 namespace fwk {
19 
20  class VModule;
21 
23 
24 
53  class VModule {
54 
55  public:
56  VModule() = default;
57  virtual ~VModule() = default;
58 
60  enum ResultFlag {
69  };
70 
71  static std::string GetResultFlagByName(const ResultFlag flag);
72 
74 
80  virtual ResultFlag Init() = 0;
81 
83 
86  virtual ResultFlag Run(evt::Event& event) = 0;
87 
89 
93  virtual ResultFlag Finish() = 0;
94 
95  void InitTiming() { fStopwatch.Reset(); }
96 
99  {
100  fStopwatch.Start();
101  const ResultFlag flag = this->Run(event);
102  fStopwatch.Stop();
103  return flag;
104  }
105 
107  const utl::Stopwatch& GetStopwatch() const { return fStopwatch; }
108 
113  eDate = 3,
114  eTime = 4,
116  };
117 
119  std::string GetVersionInfo(const VersionInfoType v) const;
120 
121  protected:
122  // Module specific verbosity level (used in Radio module)
123  int fInfoLevel = 0;
124 
125  enum InfoLevel {
130  };
131 
132  private:
133  // prevent copying
134  VModule(const VModule&);
135  VModule& operator=(const VModule&);
136 
138 
139  };
140 
141 
142 }
143 
144 
145 #define REGISTER_MODULE(_moduleName_, _ModuleType_) \
146 public: \
147  static std::string GetRegistrationId() \
148  { return _moduleName_; } \
149  \
150  static \
151  fwk::VModule* \
152  Create() \
153  { \
154  static _ModuleType_ module; \
155  return &module; \
156  } \
157  \
158 private: \
159  utl::ObjectRegistrar<_ModuleType_, fwk::VModuleFactory> fAutoModuleReg
160 
161 #define INFOFinal(y) if (InfoLevel::eInfoFinal <= fInfoLevel) INFO(y)
162 #define INFOIntermediate(y) if (InfoLevel::eInfoIntermediate <= fInfoLevel) INFO(y)
163 #define INFODebug(y) if (InfoLevel::eInfoDebug <= fInfoLevel) INFO(y)
164 
165 
166 #endif
const utl::Stopwatch & GetStopwatch() const
Definition: VModule.h:107
utl::Stopwatch fStopwatch
Definition: VModule.h:137
Report success to RunController.
Definition: VModule.h:62
virtual ResultFlag Finish()=0
Finish: invoked at end of the run (NOT end of the event)
Skip remaining modules in the current loop and continue with next iteration of the loop...
Definition: VModule.h:68
std::string GetVersionInfo(const VersionInfoType v) const
Retrieve different sorts of module version info.
Definition: VModule.cc:26
int fInfoLevel
Definition: VModule.h:123
ResultFlag RunWithTiming(evt::Event &event)
Definition: VModule.h:98
VersionInfoType
Different types of version info that can be retrieved from GetVersionInfo.
Definition: VModule.h:110
Break current loop. It works for nested loops too!
Definition: VModule.h:66
VModule & operator=(const VModule &)
void InitTiming()
Definition: VModule.h:95
utl::ObjectFactory< VModule *, std::string > VModuleFactory
Definition: VModule.h:20
void Reset()
Definition: Stopwatch.cc:21
static std::string GetResultFlagByName(const ResultFlag flag)
Definition: VModule.cc:8
virtual ResultFlag Run(evt::Event &event)=0
Run: invoked once per event.
Module interface.
Definition: VModule.h:53
Template for object factory.
Definition: ObjectFactory.h:71
void Start()
Definition: Stopwatch.cc:29
virtual ~VModule()=default
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
utl::Stopwatch & GetStopwatch()
Definition: VModule.h:106
Report failure to RunController, causing RunController to terminate execution.
Definition: VModule.h:64
VModule()=default
virtual ResultFlag Init()=0
Initialize: invoked at beginning of run (NOT beginning of event)

, generated on Tue Sep 26 2023.