Diana Software
QBaseModule.hh
Go to the documentation of this file.
1 #ifndef _Q_BASE_MODULE_H_
2 #define _Q_BASE_MODULE_H_
39 #include <string>
40 #include <sstream>
41 #include <stdarg.h>
42 
43 #include "QMessage.hh"
44 #include "QDiana.hh"
45 #include "QSequence.hh"
46 #include "QGeneralFactory.hh"
47 #include "QBaseModuleFactory.hh"
48 #include "QModuleConfig.hh"
49 #include "QEventLabel.hh"
50 #include "QModuleTimeProfiling.hh"
51 
53 
54 class QEventAssembler;
55 class QEventList;
56 
57 class QBaseModule : protected QModuleTimeProfiling {
58 
59  public:
60  enum Type {
66  };
67 
68 
70  QBaseModule(Type type);
71 
73  virtual ~QBaseModule();
80  double GetDouble(const std::string& parname, double defVal, bool warnCfg = true) const;
87  std::vector<double> GetVectorDouble(const std::string& parname, std::vector<double> defVal, bool warnCfg = true) const;
88 
90  int GetInt(const std::string& parname, int defVal, bool warnCfg = true) const;
92  std::vector<int> GetVectorInt(const std::string& parname, std::vector<int> defVal, bool warnCfg = true) const;
93 
95  bool GetBool(const std::string& parname, bool defVal, bool warnCfg = true) const;
97  std::vector<bool> GetVectorBool(const std::string& parname, std::vector<bool> defVal, bool warnCfg = true) const;
98 
100  const std::string& GetString(const std::string& parname, const std::string& defVal, bool warnCfg = true) const;
102  std::vector<std::string> GetVectorString(const std::string& parname, std::vector<std::string> defVal, bool warnCfg = true) const;
103 
105  inline void Debug(const char* descr, ...) const;
107  inline void Info(const char* descr, ...) const;
109  inline void Warn(const char* descr, ...) const;
111  inline void Error(const char* descr, ...) const;
113  inline void Panic(const char* descr, ...) const;
114 
118  bool GetRunAgain() const { return my_sequence->GetRunAgain();}
122  unsigned int GetIteration() const { return my_sequence->GetIteration(); }
123 
125  unsigned int GetOccurrence() const {return fOccurrence;}
127  inline bool isEnabled() const { return fEnabled;}
129  std::string GetFullPath() const;
131  const std::string& GetName() const { return fName; }
133  const std::string& GetLabel() const { return fLabel; }
137  const QSequence& GetSequence() const {return *my_sequence;}
139  void Update(QSequence* s, unsigned int occurrence);
141  bool NeedNeighbours() { return fNeedNeighbours;}
142 
144  void BeginBase(QEventAssembler& ev);
146  virtual void Begin(QEventAssembler& ev) = 0;
147 
149  bool ProcessBase(QEventAssembler& ev, QEventList& evl, const bool exec, QEventList& ovl);
151  virtual bool Process(QEventAssembler& ev, QEventList& evl, const bool exec,QEventList& ovl) = 0;
152 
154  void EndBase();
156  virtual void End() = 0;
157 
159  const std::vector<QEventLabel>& GetRequiredLabels() const { return fRequiredLabels; }
160 
161 
162  protected:
163  bool fExecuted;
164 
167 
169  void SetNeedNeighbours(bool need) {fNeedNeighbours = need;}
170 
171  private:
173  void UpdateEnableFlag() { fEnabled = GetBool("enable",false); }
174 
176  void Disable() { fEnabled = false; }
177 
179  void UpdateConfigParameters(const std::string& p) const;
180 
181 
183  unsigned int fOccurrence;
184  bool fEnabled;
185  std::string fLabel;
186  std::string fName;
187  std::string fMessageName;
193  std::vector<QEventLabel> fRequiredLabels;
194 
196 
197  template<class T> friend class QModFactory;
198 
199  friend class QModuleFactory;
200  friend class QSequence;
201  friend class QModule;
202  friend class QWriter;
203  friend class QDriver;
204  friend class QFilter;
205 
206 };
207 
208 inline void QBaseModule::Debug(const char* descr, ...) const {
209  if (verbosity <= DebugMsg ){
210  char buf[4096];
211  va_list args;
212  va_start(args,descr);
213  vsnprintf(buf,4096,descr,args);
215  }
216 }
217 
218 inline void QBaseModule::Info(const char* descr, ...)const {
219  if (verbosity <= InfoMsg ){
220  char buf[4096];
221  va_list args;
222  va_start(args,descr);
223  vsnprintf(buf,4096, descr,args);
225  }
226 }
227 
228 inline void QBaseModule::Warn(const char* descr, ...)const {
229  if (verbosity <= WarnMsg ){
230  char buf[4096];
231  va_list args;
232  va_start(args,descr);
233  vsnprintf(buf,4096,descr,args);
235  }
236 }
237 
238 inline void QBaseModule::Error(const char* descr, ...)const {
239  if (verbosity <= ErrorMsg ){
240  char buf[4096];
241  va_list args;
242  va_start(args,descr);
243  vsnprintf(buf,4096,descr,args);
245  }
246 }
247 
248 inline void QBaseModule::Panic(const char* descr, ...)const {
249  if (verbosity <= PanicMsg ){
250  char buf[4096];
251  va_list args;
252  va_start(args,descr);
253  vsnprintf(buf,4096,descr,args);
255  }
256 }
257 
259 
260 #endif
QVector b
Definition: CheckOF.C:21
#define Q_END_NAMESPACE
Definition: QDiana.hh:22
#define Q_BEGIN_NAMESPACE
Definition: QDiana.hh:20
MsgLevel
Definition: QMessageDefs.hh:4
@ ErrorMsg
Definition: QMessageDefs.hh:9
@ DebugMsg
Definition: QMessageDefs.hh:6
@ WarnMsg
Definition: QMessageDefs.hh:8
@ PanicMsg
Definition: QMessageDefs.hh:10
@ InfoMsg
Definition: QMessageDefs.hh:7
Base class for modules.
Definition: QBaseModule.hh:57
std::string GetFullPath() const
Get Full Path of module "GetName() + "." + GetOccurrence".
Definition: QBaseModule.cc:177
const std::string & GetString(const std::string &parname, const std::string &defVal, bool warnCfg=true) const
Get a string parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:297
std::string fMessageName
Definition: QBaseModule.hh:187
bool ProcessBase(QEventAssembler &ev, QEventList &evl, const bool exec, QEventList &ovl)
ProcessBase method is called for each event, getting the event and as argument.
Definition: QBaseModule.cc:128
MsgLevel verbosity
Definition: QBaseModule.hh:182
std::string fName
Definition: QBaseModule.hh:186
void Debug(const char *descr,...) const
Send a debug message (used to debug the module) with printf syntax.
Definition: QBaseModule.hh:208
void Warn(const char *descr,...) const
Send a warning message (an error that the framework can recover) with printf syntax.
Definition: QBaseModule.hh:228
QModuleConfig & GetConfig()
Get module config.
Definition: QBaseModule.hh:166
virtual ~QBaseModule()
constructor
Definition: QBaseModule.cc:30
void EndBase()
EndBase method is called after event loop.
Definition: QBaseModule.cc:162
unsigned int GetIteration() const
Get Current sequence iteration.
Definition: QBaseModule.hh:122
virtual bool Process(QEventAssembler &ev, QEventList &evl, const bool exec, QEventList &ovl)=0
Process method is called for each event, getting the event and as argument and must be implemented by...
unsigned int fOccurrence
Definition: QBaseModule.hh:183
void SetVerbosity(MsgLevel l=WarnMsg)
Definition: QBaseModule.hh:195
QSequence * my_sequence
Definition: QBaseModule.hh:190
std::vector< QEventLabel > fRequiredLabels
Definition: QBaseModule.hh:193
void Info(const char *descr,...) const
Send an info message (information) with printf syntax.
Definition: QBaseModule.hh:218
bool fNeedNeighbours
Definition: QBaseModule.hh:189
void UpdateConfigParameters(const std::string &p) const
update module config
Definition: QBaseModule.cc:333
void Error(const char *descr,...) const
Send an error message (an error that the framework cannot recover) with printf syntax.
Definition: QBaseModule.hh:238
double GetDouble(const std::string &parname, double defVal, bool warnCfg=true) const
Get a double parameter from config file.
Definition: QBaseModule.cc:184
bool GetRunAgain() const
Check if the sequence will be reiterated.
Definition: QBaseModule.hh:118
const std::string & GetLabel() const
Get Module name + the optional ExtraLabel ("name_extralabel")
Definition: QBaseModule.hh:133
QModuleConfig fConfig
Definition: QBaseModule.hh:191
void Panic(const char *descr,...) const
Send a panic message (stops the framework) with printf syntax.
Definition: QBaseModule.hh:248
const QSequence & GetSequence() const
get reference to this sequence
Definition: QBaseModule.hh:137
virtual void End()=0
End method is called after event loop and must be implemented by inheriting classes.
std::string fLabel
Definition: QBaseModule.hh:185
int GetInt(const std::string &parname, int defVal, bool warnCfg=true) const
Get an int parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:219
void UpdateEnableFlag()
update enable flag
Definition: QBaseModule.hh:173
std::vector< std::string > GetVectorString(const std::string &parname, std::vector< std::string > defVal, bool warnCfg=true) const
Get a vector<string> parameter from config file ( see GetVectorDouble() )
Definition: QBaseModule.cc:313
bool NeedNeighbours()
check wheter this module needs neighbours (available after the first event is processed)
Definition: QBaseModule.hh:141
bool GetBool(const std::string &parname, bool defVal, bool warnCfg=true) const
Get a bool parameter from config file ( see GetDouble() )
Definition: QBaseModule.cc:256
std::vector< bool > GetVectorBool(const std::string &parname, std::vector< bool > defVal, bool warnCfg=true) const
Get a vector<bool> parameter from config file ( see GetVectorDouble() )
Definition: QBaseModule.cc:270
std::vector< int > GetVectorInt(const std::string &parname, std::vector< int > defVal, bool warnCfg=true) const
Get an vector<int> parameter from config file ( see GetVectorDouble() )
Definition: QBaseModule.cc:234
void Disable()
disable
Definition: QBaseModule.hh:176
void Update(QSequence *s, unsigned int occurrence)
set the occurrence in the same sequence. MV FIXME: should not be public
Definition: QBaseModule.cc:34
const std::vector< QEventLabel > & GetRequiredLabels() const
Get labels of objects required by this module.
Definition: QBaseModule.hh:159
void SetRunAgain(bool b)
Set that the sequence will be reiterated.
Definition: QBaseModule.hh:120
const QGlobalDataManager & GlobalData() const
interface for saving and loading global QObjects
Definition: QBaseModule.hh:116
MsgLevel GetVerbosity()
get verbosity level set from config file
Definition: QBaseModule.hh:135
virtual void Begin(QEventAssembler &ev)=0
Begin method is called before event loop and must be implemented by inheriting classes.
void BeginBase(QEventAssembler &ev)
Begin Base method is called before event loop.
Definition: QBaseModule.cc:74
bool isEnabled() const
check if module is enabled
Definition: QBaseModule.hh:127
void SetNeedNeighbours(bool need)
set wheter this module needs neighbours
Definition: QBaseModule.hh:169
unsigned int GetOccurrence() const
get the number of times the same module is loaded inside a QSequence
Definition: QBaseModule.hh:125
std::vector< double > GetVectorDouble(const std::string &parname, std::vector< double > defVal, bool warnCfg=true) const
Get a std::vector<double> parameter from config file with syntax "{x,y,z}".
Definition: QBaseModule.cc:199
QBaseModule(Type type)
constructor
Definition: QBaseModule.cc:18
const std::string & GetName() const
Get Module name.
Definition: QBaseModule.hh:131
Base class for diana drivers.
Definition: QDriver.hh:32
Visitor class of QEvent that provides full handling of QEvent.
list of references to const QEvent (s)
Definition: QEventList.hh:21
Base class for diana filters.
Definition: QFilter.hh:57
Object to manage I/O (DB, file, or memory) of diana global quantities.
static QMessageHandler * Get()
Definition: QMessage.cc:24
void Send(MsgLevel l, const std::string &sender, const std::string &msg)
Definition: QMessage.cc:31
abstract module factory and definition of macros that builds modulefactories and register function.
QObject to store a QBaseModule configuration.
module instantiation class
Simple base class for time profiling a module.
Base class for diana modules.
Definition: QModule.hh:54
Diana Reconstruction program.
Definition: QSequence.hh:40
void SetRunAgain(bool b)
Run the sequence again.
Definition: QSequence.hh:79
bool GetRunAgain() const
Check if this sequence is going to be rerun.
Definition: QSequence.hh:81
unsigned int GetIteration() const
Definition: QSequence.hh:83
const QGlobalDataManager & GlobalData() const
Access to the global data manager for the sequence.
Definition: QSequence.hh:65
Abstract class for diana writers.
Definition: QWriter.hh:30