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