#ifndef _fwk_VModule_h_ #define _fwk_VModule_h_ #include #include #include #include #include #include namespace evt { class Event; } namespace fwk { class VModule; typedef utl::ObjectFactory VModuleFactory; #define REGISTER_MODULE(_moduleName_, _ModuleType_) \ public: \ static std::string GetRegistrationId() \ { return _moduleName_; } \ \ static \ fwk::VModule* \ Create() \ { \ static _ModuleType_ module; \ return &module; \ } \ \ private: \ utl::ObjectRegistrar<_ModuleType_, fwk::VModuleFactory> fAutoModuleReg /** \class VModule VModule.h "fwk/VModule.h" \brief Module interface Module interface defining standard methods to be implemented in user module. User modules inherit from this class. RunController sequences the methods methods in modules via this interface. The include file VModule.h also contains the macro which registers user modules with the framework. The syntax for use is of this macro: \code REGISTER_MODULE("module", type); \endcode where
  • module = the name by which the module is known to the RunController
  • type = the class name of the module
This macro should be placed at the very end of your class definition. \author T. Paul \date Jan 30, 2003 \version $Id: VModule.h 22085 2012-10-24 20:48:03Z paul $ \ingroup modules */ class VModule { public: VModule() { } virtual ~VModule() { } /// Flag returned by module methods to the RunController enum ResultFlag { /// Report success to RunController. eSuccess, /// Report failure to RunController, causing RunController to terminate execution. eFailure, /// Break current loop. It works for nested loops too! eBreakLoop, /// Skip remaining modules in the current loop and continue with next iteration of the loop eContinueLoop }; static std::string GetResultFlagByName(const ResultFlag flag); /// Initialize: invoked at beginning of run (NOT beginning of event) /** This method is for things that should be done once at the beginning of a run (for example, booking histograms, performing calculations that need to be done only once, initializing parameters) {\em You must override this method in your concrete module} */ virtual ResultFlag Init() = 0; /// Run: invoked once per event /** This method is for things that should be done once per event {\em You must override this method in your concrete module} */ virtual ResultFlag Run(evt::Event& event) = 0; /// Finish: invoked at end of the run (NOT end of the event) /** This method is for things that should be done at the end of the run (for example, closing files or writing out histograms) {\em You must override this method in your concrete module} */ virtual ResultFlag Finish() = 0; void InitTiming() { fStopwatch.Reset(); } ResultFlag RunWithTiming(evt::Event& event) { fStopwatch.Start(); const ResultFlag flag = Run(event); fStopwatch.Stop(); return flag; } utl::Stopwatch& GetStopwatch() { return fStopwatch; } const utl::Stopwatch& GetStopwatch() const { return fStopwatch; } /// Different types of version info that can be retrieved from GetVersionInfo enum VersionInfoType { eFilename = 1, eRevisionNumber = 2, eDate = 3, eTime = 4, eLastEditor = 5 }; /// Retrieve different sorts of module version info std::string GetVersionInfo(VersionInfoType v) const { std::vector splitVersionInfo; const std::string svnIdString = GetSVNId(); boost::split(splitVersionInfo, svnIdString, boost::is_any_of(" ")); if (int(splitVersionInfo.size()) > v) return splitVersionInfo.at(v); else return "Unknown"; } protected: // Each module returns a version from SVN $Id: stamp // This should be replaced in each module by // std::string($Id: VModule.h 22085 2012-10-24 20:48:03Z paul $), or a macro should be created // which writes this function. virtual std::string GetSVNId() const { return std::string("noInfo noInfo noInfo noInfo noInfo noInfo"); } private: // prevent copying VModule(const VModule&); VModule& operator=(const VModule&); utl::Stopwatch fStopwatch; }; } // namespace fwk_VModule_h // Configure (x)emacs for this file ... // Local Variables: // mode: c++ // compile-command: "cd ../../cmt; make -k test check" // End: #endif