CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/Framework/src/WorkerT.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_WorkerT_h
00002 #define FWCore_Framework_WorkerT_h
00003 
00004 /*----------------------------------------------------------------------
00005 
00006 WorkerT: Code common to all workers.
00007 
00008 ----------------------------------------------------------------------*/
00009 
00010 #include "FWCore/Framework/interface/Frameworkfwd.h"
00011 #include "FWCore/Framework/interface/EventPrincipal.h"
00012 #include "FWCore/Framework/interface/UnscheduledHandler.h"
00013 #include "FWCore/Framework/src/Worker.h"
00014 #include "FWCore/Framework/src/WorkerParams.h"
00015 
00016 #include <memory>
00017 
00018 namespace edm {
00019 
00020   template<typename T>
00021   class WorkerT : public Worker {
00022   public:
00023     typedef T ModuleType;
00024     typedef WorkerT<T> WorkerType;
00025     WorkerT(std::auto_ptr<T>,
00026             ModuleDescription const&,
00027             WorkerParams const&);
00028 
00029     virtual ~WorkerT();
00030 
00031   template<typename ModType>
00032   static std::auto_ptr<T> makeModule(ModuleDescription const&,
00033                                      ParameterSet const& pset) {
00034     std::auto_ptr<ModType> module = std::auto_ptr<ModType>(new ModType(pset));
00035     return std::auto_ptr<T>(module.release());
00036   }
00037 
00038   void setModule( std::auto_ptr<T>& iModule) {
00039      module_ = iModule;
00040      module_->setModuleDescription(description());
00041      
00042   }
00043 
00044   protected:
00045     T& module() {return *module_;}
00046     T const& module() const {return *module_;}
00047 
00048   private:
00049     virtual bool implDoBegin(EventPrincipal& ep, EventSetup const& c,
00050                             CurrentProcessingContext const* cpc);
00051     virtual bool implDoEnd(EventPrincipal& ep, EventSetup const& c,
00052                             CurrentProcessingContext const* cpc);
00053     virtual bool implDoBegin(RunPrincipal& rp, EventSetup const& c,
00054                             CurrentProcessingContext const* cpc);
00055     virtual bool implDoEnd(RunPrincipal& rp, EventSetup const& c,
00056                             CurrentProcessingContext const* cpc);
00057     virtual bool implDoBegin(LuminosityBlockPrincipal& lbp, EventSetup const& c,
00058                             CurrentProcessingContext const* cpc);
00059     virtual bool implDoEnd(LuminosityBlockPrincipal& lbp, EventSetup const& c,
00060                             CurrentProcessingContext const* cpc);
00061     virtual void implBeginJob() ;
00062     virtual void implEndJob() ;
00063     virtual void implRespondToOpenInputFile(FileBlock const& fb);
00064     virtual void implRespondToCloseInputFile(FileBlock const& fb);
00065     virtual void implRespondToOpenOutputFiles(FileBlock const& fb);
00066     virtual void implRespondToCloseOutputFiles(FileBlock const& fb);
00067     virtual void implPreForkReleaseResources();
00068     virtual void implPostForkReacquireResources(unsigned int iChildIndex, 
00069                                                unsigned int iNumberOfChildren);
00070      virtual std::string workerType() const;
00071 
00072     std::auto_ptr<T> module_;
00073   };
00074 
00075   template<typename T>
00076   inline
00077   WorkerT<T>::WorkerT(std::auto_ptr<T> ed, ModuleDescription const& md, WorkerParams const& wp) :
00078     Worker(md, wp),
00079     module_(ed) {
00080     assert(module_.get() != 0);
00081     module_->setModuleDescription(md);
00082     module_->registerAnyProducts(module_.get(), wp.reg_);
00083   }
00084 
00085   template<typename T>
00086   WorkerT<T>::~WorkerT() {
00087   }
00088 
00089   template<typename T>
00090   bool 
00091   WorkerT<T>::implDoBegin(EventPrincipal& ep, EventSetup const& c, CurrentProcessingContext const* cpc) {
00092     UnscheduledHandlerSentry s(ep.unscheduledHandler().get(), cpc);
00093     return module_->doEvent(ep, c, cpc);
00094   }
00095 
00096   template<typename T>
00097   bool 
00098   WorkerT<T>::implDoEnd(EventPrincipal&, EventSetup const&, CurrentProcessingContext const*) {
00099     return false;
00100   }
00101 
00102   template<typename T>
00103   bool
00104   WorkerT<T>::implDoBegin(RunPrincipal& rp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00105     return module_->doBeginRun(rp, c, cpc);
00106   }
00107 
00108   template<typename T>
00109   bool
00110   WorkerT<T>::implDoEnd(RunPrincipal& rp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00111     return module_->doEndRun(rp, c, cpc);
00112   }
00113 
00114   template<typename T>
00115   bool
00116   WorkerT<T>::implDoBegin(LuminosityBlockPrincipal& lbp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00117     return module_->doBeginLuminosityBlock(lbp, c, cpc);
00118   }
00119 
00120   template<typename T>
00121   bool
00122   WorkerT<T>::implDoEnd(LuminosityBlockPrincipal& lbp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00123     return module_->doEndLuminosityBlock(lbp, c, cpc);
00124   }
00125 
00126   template<typename T>
00127   std::string
00128   WorkerT<T>::workerType() const {
00129     return module_->workerType();
00130   }
00131 
00132   template<typename T>
00133   void
00134   WorkerT<T>::implBeginJob() {
00135     module_->doBeginJob();
00136   }
00137 
00138   template<typename T>
00139   void
00140   WorkerT<T>::implEndJob() {
00141     module_->doEndJob();
00142   }
00143 
00144   template<typename T>
00145   void
00146   WorkerT<T>::implRespondToOpenInputFile(FileBlock const& fb) {
00147     module_->doRespondToOpenInputFile(fb);
00148   }
00149 
00150   template<typename T>
00151   void
00152   WorkerT<T>::implRespondToCloseInputFile(FileBlock const& fb) {
00153     module_->doRespondToCloseInputFile(fb);
00154   }
00155 
00156   template<typename T>
00157   void
00158   WorkerT<T>::implRespondToOpenOutputFiles(FileBlock const& fb) {
00159     module_->doRespondToOpenOutputFiles(fb);
00160   }
00161 
00162   template<typename T>
00163   void
00164   WorkerT<T>::implRespondToCloseOutputFiles(FileBlock const& fb) {
00165     module_->doRespondToCloseOutputFiles(fb);
00166   }
00167 
00168   template<typename T>
00169   void 
00170   WorkerT<T>::implPreForkReleaseResources() {
00171     module_->doPreForkReleaseResources();
00172   }
00173 
00174   template<typename T>
00175   void 
00176   WorkerT<T>::implPostForkReacquireResources(unsigned int iChildIndex, 
00177                                             unsigned int iNumberOfChildren) {
00178     module_->doPostForkReacquireResources(iChildIndex, iNumberOfChildren);
00179   }  
00180 }
00181 
00182 #endif