CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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/UnscheduledHandler.h"
00012 #include "FWCore/Framework/src/Worker.h"
00013 #include "FWCore/Framework/src/WorkerParams.h"
00014 
00015 #include <memory>
00016 
00017 namespace edm {
00018   UnscheduledHandler* getUnscheduledHandler(EventPrincipal const& ep);
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     void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
00045                                bool anyProductProduced) {
00046       module_->setEventSelectionInfo(outputModulePathPositions, anyProductProduced);
00047     }
00048 
00049   protected:
00050     T& module() {return *module_;}
00051     T const& module() const {return *module_;}
00052 
00053   private:
00054     virtual bool implDoBegin(EventPrincipal& ep, EventSetup const& c,
00055                             CurrentProcessingContext const* cpc);
00056     virtual bool implDoEnd(EventPrincipal& ep, EventSetup const& c,
00057                             CurrentProcessingContext const* cpc);
00058     virtual bool implDoBegin(RunPrincipal& rp, EventSetup const& c,
00059                             CurrentProcessingContext const* cpc);
00060     virtual bool implDoEnd(RunPrincipal& rp, EventSetup const& c,
00061                             CurrentProcessingContext const* cpc);
00062     virtual bool implDoBegin(LuminosityBlockPrincipal& lbp, EventSetup const& c,
00063                             CurrentProcessingContext const* cpc);
00064     virtual bool implDoEnd(LuminosityBlockPrincipal& lbp, EventSetup const& c,
00065                             CurrentProcessingContext const* cpc);
00066     virtual void implBeginJob() ;
00067     virtual void implEndJob() ;
00068     virtual void implRespondToOpenInputFile(FileBlock const& fb);
00069     virtual void implRespondToCloseInputFile(FileBlock const& fb);
00070     virtual void implRespondToOpenOutputFiles(FileBlock const& fb);
00071     virtual void implRespondToCloseOutputFiles(FileBlock const& fb);
00072     virtual void implPreForkReleaseResources();
00073     virtual void implPostForkReacquireResources(unsigned int iChildIndex, 
00074                                                unsigned int iNumberOfChildren);
00075      virtual std::string workerType() const;
00076 
00077     std::auto_ptr<T> module_;
00078   };
00079 
00080   template<typename T>
00081   inline
00082   WorkerT<T>::WorkerT(std::auto_ptr<T> ed, ModuleDescription const& md, WorkerParams const& wp) :
00083     Worker(md, wp),
00084     module_(ed) {
00085     assert(module_.get() != 0);
00086     module_->setModuleDescription(md);
00087     module_->registerProductsAndCallbacks(module_.get(), wp.reg_);
00088   }
00089 
00090   template<typename T>
00091   WorkerT<T>::~WorkerT() {
00092   }
00093 
00094   template<typename T>
00095   inline
00096   bool 
00097   WorkerT<T>::implDoBegin(EventPrincipal& ep, EventSetup const& c, CurrentProcessingContext const* cpc) {
00098     UnscheduledHandlerSentry s(getUnscheduledHandler(ep), cpc);
00099     boost::shared_ptr<Worker> sentry(this,[&ep](Worker* obj) {obj->postDoEvent(ep);});
00100     return module_->doEvent(ep, c, cpc);
00101   }
00102 
00103   template<typename T>
00104   inline
00105   bool 
00106   WorkerT<T>::implDoEnd(EventPrincipal&, EventSetup const&, CurrentProcessingContext const*) {
00107     return false;
00108   }
00109 
00110   template<typename T>
00111   inline
00112   bool
00113   WorkerT<T>::implDoBegin(RunPrincipal& rp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00114     return module_->doBeginRun(rp, c, cpc);
00115   }
00116 
00117   template<typename T>
00118   inline
00119   bool
00120   WorkerT<T>::implDoEnd(RunPrincipal& rp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00121     return module_->doEndRun(rp, c, cpc);
00122   }
00123 
00124   template<typename T>
00125   inline
00126   bool
00127   WorkerT<T>::implDoBegin(LuminosityBlockPrincipal& lbp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00128     return module_->doBeginLuminosityBlock(lbp, c, cpc);
00129   }
00130 
00131   template<typename T>
00132   inline
00133   bool
00134   WorkerT<T>::implDoEnd(LuminosityBlockPrincipal& lbp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00135     return module_->doEndLuminosityBlock(lbp, c, cpc);
00136   }
00137 
00138   template<typename T>
00139   inline
00140   std::string
00141   WorkerT<T>::workerType() const {
00142     return module_->workerType();
00143   }
00144 
00145   template<typename T>
00146   inline
00147   void
00148   WorkerT<T>::implBeginJob() {
00149     module_->doBeginJob();
00150   }
00151 
00152   template<typename T>
00153   inline
00154   void
00155   WorkerT<T>::implEndJob() {
00156     module_->doEndJob();
00157   }
00158 
00159   template<typename T>
00160   inline
00161   void
00162   WorkerT<T>::implRespondToOpenInputFile(FileBlock const& fb) {
00163     module_->doRespondToOpenInputFile(fb);
00164   }
00165 
00166   template<typename T>
00167   inline
00168   void
00169   WorkerT<T>::implRespondToCloseInputFile(FileBlock const& fb) {
00170     module_->doRespondToCloseInputFile(fb);
00171   }
00172 
00173   template<typename T>
00174   inline
00175   void
00176   WorkerT<T>::implRespondToOpenOutputFiles(FileBlock const& fb) {
00177     module_->doRespondToOpenOutputFiles(fb);
00178   }
00179 
00180   template<typename T>
00181   inline
00182   void
00183   WorkerT<T>::implRespondToCloseOutputFiles(FileBlock const& fb) {
00184     module_->doRespondToCloseOutputFiles(fb);
00185   }
00186 
00187   template<typename T>
00188   inline
00189   void 
00190   WorkerT<T>::implPreForkReleaseResources() {
00191     module_->doPreForkReleaseResources();
00192   }
00193 
00194   template<typename T>
00195   inline
00196   void 
00197   WorkerT<T>::implPostForkReacquireResources(unsigned int iChildIndex, 
00198                                             unsigned int iNumberOfChildren) {
00199     module_->doPostForkReacquireResources(iChildIndex, iNumberOfChildren);
00200   }  
00201 }
00202 
00203 #endif