Go to the documentation of this file.00001 #ifndef FWCore_Framework_WorkerMaker_h
00002 #define FWCore_Framework_WorkerMaker_h
00003
00004 #include "FWCore/Framework/src/WorkerT.h"
00005 #include "FWCore/Framework/src/WorkerParams.h"
00006
00007 #include <memory>
00008 #include <string>
00009 #include "sigc++/signal.h"
00010
00011
00012 namespace edm {
00013 class ConfigurationDescriptions;
00014 class ModuleDescription;
00015 class ParameterSet;
00016
00017 class Maker {
00018 public:
00019 virtual ~Maker();
00020 std::auto_ptr<Worker> makeWorker(WorkerParams const&,
00021 sigc::signal<void, ModuleDescription const&>& iPre,
00022 sigc::signal<void, ModuleDescription const&>& iPost) const;
00023 void swapModule(Worker*, ParameterSet const&);
00024 protected:
00025 ModuleDescription createModuleDescription(WorkerParams const& p) const;
00026
00027 void throwConfigurationException(ModuleDescription const& md,
00028 sigc::signal<void, ModuleDescription const&>& post,
00029 cms::Exception const& iException) const;
00030
00031 void throwValidationException(WorkerParams const& p,
00032 cms::Exception const& iException) const;
00033
00034 void validateEDMType(std::string const& edmType, WorkerParams const& p) const;
00035
00036 private:
00037 virtual void fillDescriptions(ConfigurationDescriptions& iDesc) const = 0;
00038 virtual std::auto_ptr<Worker> makeWorker(WorkerParams const& p,
00039 ModuleDescription const& md) const = 0;
00040 virtual const std::string& baseType() const =0;
00041 virtual void implSwapModule(Worker*, ParameterSet const&)=0;
00042 };
00043
00044 template <class T>
00045 class WorkerMaker : public Maker {
00046 public:
00047
00048 explicit WorkerMaker();
00049 private:
00050 virtual void fillDescriptions(ConfigurationDescriptions& iDesc) const;
00051 virtual std::auto_ptr<Worker> makeWorker(WorkerParams const& p, ModuleDescription const& md) const;
00052 virtual const std::string& baseType() const;
00053 virtual void implSwapModule(Worker*, ParameterSet const&);
00054 };
00055
00056 template <class T>
00057 WorkerMaker<T>::WorkerMaker() {
00058 }
00059
00060 template <class T>
00061 void WorkerMaker<T>::fillDescriptions(ConfigurationDescriptions& iDesc) const {
00062 T::fillDescriptions(iDesc);
00063 }
00064
00065 template <class T>
00066 std::auto_ptr<Worker> WorkerMaker<T>::makeWorker(WorkerParams const& p, ModuleDescription const& md) const {
00067 typedef T UserType;
00068 typedef typename UserType::ModuleType ModuleType;
00069 typedef typename UserType::WorkerType WorkerType;
00070
00071 std::auto_ptr<ModuleType> module(WorkerType::template makeModule<UserType>(md, *p.pset_));
00072 return std::auto_ptr<Worker>(new WorkerType(module, md, p));
00073 }
00074
00075
00076 template <class T>
00077 void WorkerMaker<T>::implSwapModule(Worker* w, ParameterSet const& p) {
00078 typedef T UserType;
00079 typedef typename UserType::ModuleType ModuleType;
00080 typedef typename UserType::WorkerType WorkerType;
00081
00082 WorkerType* wt = dynamic_cast<WorkerType*>(w);
00083 assert(0!=wt);
00084
00085 std::auto_ptr<ModuleType> module(WorkerType::template makeModule<UserType>(w->description(), p));
00086
00087 wt->setModule(module);
00088 }
00089
00090 template<class T>
00091 const std::string& WorkerMaker<T>::baseType() const {
00092 return T::baseType();
00093 }
00094
00095 }
00096
00097 #endif