Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:27:02

0001 #ifndef FWCore_Framework_WorkerMaker_h
0002 #define FWCore_Framework_WorkerMaker_h
0003 
0004 #include <cassert>
0005 #include <memory>
0006 #include <string>
0007 
0008 #include "FWCore/Framework/interface/maker/WorkerT.h"
0009 #include "FWCore/Framework/interface/maker/MakeModuleParams.h"
0010 #include "FWCore/Framework/interface/maker/ModuleHolder.h"
0011 #include "FWCore/Framework/interface/maker/MakeModuleHelper.h"
0012 
0013 #include "FWCore/Utilities/interface/Signal.h"
0014 
0015 namespace edm {
0016   class ConfigurationDescriptions;
0017   class ModuleDescription;
0018   class ParameterSet;
0019   class ExceptionToActionTable;
0020 
0021   class Maker {
0022   public:
0023     virtual ~Maker();
0024     std::shared_ptr<maker::ModuleHolder> makeModule(MakeModuleParams const&,
0025                                                     signalslot::Signal<void(ModuleDescription const&)>& iPre,
0026                                                     signalslot::Signal<void(ModuleDescription const&)>& iPost) const;
0027     std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const*, maker::ModuleHolder const*) const;
0028 
0029     std::shared_ptr<maker::ModuleHolder> makeReplacementModule(edm::ParameterSet const& p) const {
0030       return makeModule(p);
0031     }
0032 
0033   protected:
0034     ModuleDescription createModuleDescription(MakeModuleParams const& p) const;
0035 
0036     void throwConfigurationException(ModuleDescription const& md, cms::Exception& iException) const;
0037 
0038     void throwValidationException(MakeModuleParams const& p, cms::Exception& iException) const;
0039 
0040     void validateEDMType(std::string const& edmType, MakeModuleParams const& p) const;
0041 
0042   private:
0043     virtual void fillDescriptions(ConfigurationDescriptions& iDesc) const = 0;
0044     virtual std::shared_ptr<maker::ModuleHolder> makeModule(edm::ParameterSet const& p) const = 0;
0045     virtual std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions,
0046                                                ModuleDescription const& md,
0047                                                maker::ModuleHolder const* mod) const = 0;
0048     virtual const std::string& baseType() const = 0;
0049   };
0050 
0051   template <class T>
0052   class WorkerMaker : public Maker {
0053   public:
0054     //typedef T worker_type;
0055     explicit WorkerMaker();
0056 
0057   private:
0058     void fillDescriptions(ConfigurationDescriptions& iDesc) const override;
0059     std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions,
0060                                        ModuleDescription const& md,
0061                                        maker::ModuleHolder const* mod) const override;
0062     std::shared_ptr<maker::ModuleHolder> makeModule(edm::ParameterSet const& p) const override;
0063     const std::string& baseType() const override;
0064   };
0065 
0066   template <class T>
0067   WorkerMaker<T>::WorkerMaker() {}
0068 
0069   template <class T>
0070   void WorkerMaker<T>::fillDescriptions(ConfigurationDescriptions& iDesc) const {
0071     T::fillDescriptions(iDesc);
0072     T::prevalidate(iDesc);
0073   }
0074 
0075   template <class T>
0076   std::shared_ptr<maker::ModuleHolder> WorkerMaker<T>::makeModule(edm::ParameterSet const& p) const {
0077     typedef T UserType;
0078     typedef typename UserType::ModuleType ModuleType;
0079     typedef MakeModuleHelper<ModuleType> MakerHelperType;
0080 
0081     return std::shared_ptr<maker::ModuleHolder>(
0082         std::make_shared<maker::ModuleHolderT<ModuleType> >(MakerHelperType::template makeModule<UserType>(p), this));
0083   }
0084 
0085   template <class T>
0086   std::unique_ptr<Worker> WorkerMaker<T>::makeWorker(ExceptionToActionTable const* actions,
0087                                                      ModuleDescription const& md,
0088                                                      maker::ModuleHolder const* mod) const {
0089     typedef T UserType;
0090     typedef typename UserType::ModuleType ModuleType;
0091     typedef edm::WorkerT<ModuleType> WorkerType;
0092 
0093     maker::ModuleHolderT<ModuleType> const* h = dynamic_cast<maker::ModuleHolderT<ModuleType> const*>(mod);
0094     return std::make_unique<WorkerType>(h->module(), md, actions);
0095   }
0096 
0097   template <class T>
0098   const std::string& WorkerMaker<T>::baseType() const {
0099     return T::baseType();
0100   }
0101 
0102 }  // namespace edm
0103 
0104 #endif