QBaseModule.hh

Go to the documentation of this file.
00001 #ifndef _Q_BASE_MODULE_H_
00002 #define _Q_BASE_MODULE_H_
00003 
00019 #include <string>
00020 #include <stdarg.h>
00021 
00022 #include "QMessage.hh"
00023 #include "QCuore.hh"
00024 #include "QNamed.hh"
00025 #include "QSequence.hh"
00026 #include "QGeneralFactory.hh"
00027 #include "QBaseModuleFactory.hh"
00028 
00029 
00030 namespace Cuore {class QEvent;}
00031 
00032 class QBaseModule : public QNamed {
00033 
00034     public:
00036         QBaseModule(const std::string&, QSequence *s);
00037 
00039         virtual ~QBaseModule();
00040 
00043         void BeginBase();
00044         virtual void Begin() = 0;
00046         Cuore::QEvent* ProcessBase(Cuore::QEvent* ev);
00047         virtual Cuore::QEvent* Process(Cuore::QEvent* ev) = 0;
00048         
00050         void EndBase();
00051         virtual void End() = 0;
00052 
00054         unsigned int GetOccurrence() const {return fOccurrence;}
00055 
00057         inline bool isEnabled() const { return fEnabled;}
00058 
00059         std::string GetFullPath() const;
00060 
00061     protected:
00063         double GetDouble(const std::string&, double defVal, bool warnCfg = true) const;
00065         int GetInt(const std::string&, int defVal, bool warnCfg = true) const;
00067         const std::string& GetString(const std::string&, const std::string& defVal, bool warnCfg = true) const;
00069         bool GetBool(const std::string&, bool defVal, bool warnCfg = true) const;
00070 
00072         inline void Debug(const char* descr, ...) const; 
00074         inline void Info(const char* descr, ...) const; 
00076         inline void Warn(const char* descr, ...) const; 
00078         inline void Error(const char* descr, ...) const; 
00080         inline void Panic(const char* descr, ...) const; 
00081 
00083         bool GetRunAgain() { return GetSequence().GetRunAgain();}
00085         void SetRunAgain(bool b) { GetSequence().SetRunAgain(b);}
00087         unsigned int GetIteration() { return GetSequence().GetIteration(); }
00088         
00090         QGlobalDataManager& SeqAuxData() {return GetSequence().AuxData();}
00091 
00093         MsgLevel GetVerbosity() {return verbosity;}
00094 
00096         QSequence& GetSequence() {return *my_sequence;}
00097         const QSequence& GetSequence() const {return *my_sequence;}
00098         
00100         void UpdateEnableFlag() { fEnabled = GetBool("enable",false); }
00101 
00102     private:
00104         void SetOccurrence(unsigned int o);
00105 
00106         MsgLevel verbosity;
00107         bool fTimeProfilingOn;
00108         unsigned int fOccurrence;
00109         double fProcessTime;
00110         unsigned long long int fProcessCalls;
00111         bool fEnabled;
00112         QSequence *my_sequence;
00113 
00114         void SetVerbosity(MsgLevel l=WarnMsg) { verbosity=l; }
00115    
00116         template<class T> friend class QModFactory;
00117 
00118 
00119         friend class QModuleFactory;
00120         friend class QSequence;
00121 
00122 };
00123 
00124 inline void QBaseModule::Debug(const char* descr, ...) const {
00125     if (verbosity <= DebugMsg ){
00126         char buf[4096];  
00127         va_list args;
00128         va_start(args,descr);
00129         vsprintf(buf,descr,args);
00130         std::string msg(buf);
00131         QMessageHandler::Get()->Send(DebugMsg, GetName(), msg);
00132     }
00133 }
00134 
00135 inline void QBaseModule::Info(const char* descr, ...)const  {
00136     if (verbosity <= InfoMsg ){
00137         char buf[4096];  
00138         va_list args;
00139         va_start(args,descr);
00140         vsprintf(buf,descr,args);
00141         std::string msg(buf);
00142         QMessageHandler::Get()->Send(InfoMsg, GetName(), msg);
00143     }
00144 }
00145 
00146 inline void QBaseModule::Warn(const char* descr, ...)const  {
00147     if (verbosity <= WarnMsg ){
00148         char buf[4096];  
00149         va_list args;
00150         va_start(args,descr);
00151         vsprintf(buf,descr,args);
00152         std::string msg(buf);
00153         QMessageHandler::Get()->Send(WarnMsg, GetName(), msg);
00154     }
00155 }
00156 
00157 inline void QBaseModule::Error(const char* descr, ...)const  {
00158     if (verbosity <= ErrorMsg ){
00159         char buf[4096];  
00160         va_list args;
00161         va_start(args,descr);
00162         vsprintf(buf,descr,args);
00163         std::string msg(buf);
00164         QMessageHandler::Get()->Send(ErrorMsg, GetName(), msg);
00165     }
00166 }
00167 
00168 inline void QBaseModule::Panic(const char* descr, ...)const  {
00169     if (verbosity <= PanicMsg ){
00170         char buf[4096];  
00171         va_list args;
00172         va_start(args,descr);
00173         vsprintf(buf,descr,args);
00174         std::string msg(buf);
00175         QMessageHandler::Get()->Send(PanicMsg, GetName(), msg);
00176     }
00177 }
00178 
00179 #endif

Generated on Tue Nov 16 10:49:56 2010 for CUORE Software by  doxygen 1.5.6