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