CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/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     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_->registerAnyProducts(module_.get(), wp.reg_);
00088   }
00089 
00090   template<typename T>
00091   WorkerT<T>::~WorkerT() {
00092   }
00093 
00094   template<typename T>
00095   bool 
00096   WorkerT<T>::implDoBegin(EventPrincipal& ep, EventSetup const& c, CurrentProcessingContext const* cpc) {
00097     UnscheduledHandlerSentry s(ep.unscheduledHandler().get(), cpc);
00098     boost::shared_ptr<Worker> sentry(this,[&ep](Worker* obj) {obj->postDoEvent(ep);});
00099     return module_->doEvent(ep, c, cpc);
00100   }
00101 
00102   template<typename T>
00103   bool 
00104   WorkerT<T>::implDoEnd(EventPrincipal&, EventSetup const&, CurrentProcessingContext const*) {
00105     return false;
00106   }
00107 
00108   template<typename T>
00109   bool
00110   WorkerT<T>::implDoBegin(RunPrincipal& rp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00111     return module_->doBeginRun(rp, c, cpc);
00112   }
00113 
00114   template<typename T>
00115   bool
00116   WorkerT<T>::implDoEnd(RunPrincipal& rp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00117     return module_->doEndRun(rp, c, cpc);
00118   }
00119 
00120   template<typename T>
00121   bool
00122   WorkerT<T>::implDoBegin(LuminosityBlockPrincipal& lbp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00123     return module_->doBeginLuminosityBlock(lbp, c, cpc);
00124   }
00125 
00126   template<typename T>
00127   bool
00128   WorkerT<T>::implDoEnd(LuminosityBlockPrincipal& lbp, EventSetup const& c, CurrentProcessingContext const* cpc) {
00129     return module_->doEndLuminosityBlock(lbp, c, cpc);
00130   }
00131 
00132   template<typename T>
00133   std::string
00134   WorkerT<T>::workerType() const {
00135     return module_->workerType();
00136   }
00137 
00138   template<typename T>
00139   void
00140   WorkerT<T>::implBeginJob() {
00141     module_->doBeginJob();
00142   }
00143 
00144   template<typename T>
00145   void
00146   WorkerT<T>::implEndJob() {
00147     module_->doEndJob();
00148   }
00149 
00150   template<typename T>
00151   void
00152   WorkerT<T>::implRespondToOpenInputFile(FileBlock const& fb) {
00153     module_->doRespondToOpenInputFile(fb);
00154   }
00155 
00156   template<typename T>
00157   void
00158   WorkerT<T>::implRespondToCloseInputFile(FileBlock const& fb) {
00159     module_->doRespondToCloseInputFile(fb);
00160   }
00161 
00162   template<typename T>
00163   void
00164   WorkerT<T>::implRespondToOpenOutputFiles(FileBlock const& fb) {
00165     module_->doRespondToOpenOutputFiles(fb);
00166   }
00167 
00168   template<typename T>
00169   void
00170   WorkerT<T>::implRespondToCloseOutputFiles(FileBlock const& fb) {
00171     module_->doRespondToCloseOutputFiles(fb);
00172   }
00173 
00174   template<typename T>
00175   void 
00176   WorkerT<T>::implPreForkReleaseResources() {
00177     module_->doPreForkReleaseResources();
00178   }
00179 
00180   template<typename T>
00181   void 
00182   WorkerT<T>::implPostForkReacquireResources(unsigned int iChildIndex, 
00183                                             unsigned int iNumberOfChildren) {
00184     module_->doPostForkReacquireResources(iChildIndex, iNumberOfChildren);
00185   }  
00186 }
00187 
00188 #endif