Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:58

0001 #ifndef FWCore_Framework_ModuleHolder_h
0002 #define FWCore_Framework_ModuleHolder_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     ModuleHolder
0007 //
0008 /**\class edm::maker::ModuleHolder ModuleHolder.h "FWCore/Framework/interface/maker/ModuleHolder.h"
0009 
0010  Description: Base class used to own a module for the framework
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Fri, 23 Aug 2013 17:47:04 GMT
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/maker/WorkerT.h"
0026 #include "FWCore/Framework/interface/OutputModuleCommunicatorT.h"
0027 
0028 // forward declarations
0029 namespace edm {
0030   class Maker;
0031   class ModuleDescription;
0032   class ProductRegistry;
0033   class ExceptionToActionTable;
0034   class PreallocationConfiguration;
0035 
0036   namespace maker {
0037     class ModuleHolder {
0038     public:
0039       ModuleHolder(Maker const* iMaker) : m_maker(iMaker) {}
0040       virtual ~ModuleHolder() {}
0041       std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions) const;
0042 
0043       virtual ModuleDescription const& moduleDescription() const = 0;
0044       virtual void setModuleDescription(ModuleDescription const& iDesc) = 0;
0045       virtual void preallocate(PreallocationConfiguration const&) = 0;
0046       virtual void registerProductsAndCallbacks(ProductRegistry*) = 0;
0047       virtual void replaceModuleFor(Worker*) const = 0;
0048 
0049       virtual std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() = 0;
0050 
0051     protected:
0052       Maker const* m_maker;
0053     };
0054 
0055     template <typename T>
0056     class ModuleHolderT : public ModuleHolder {
0057     public:
0058       ModuleHolderT(std::shared_ptr<T> iModule, Maker const* iMaker) : ModuleHolder(iMaker), m_mod(iModule) {}
0059       ~ModuleHolderT() override {}
0060       std::shared_ptr<T> module() const { return m_mod; }
0061       void replaceModuleFor(Worker* iWorker) const override {
0062         auto w = dynamic_cast<WorkerT<T>*>(iWorker);
0063         assert(nullptr != w);
0064         w->setModule(m_mod);
0065       }
0066       ModuleDescription const& moduleDescription() const override { return m_mod->moduleDescription(); }
0067       void setModuleDescription(ModuleDescription const& iDesc) override { m_mod->setModuleDescription(iDesc); }
0068       void preallocate(PreallocationConfiguration const& iPrealloc) override { m_mod->doPreallocate(iPrealloc); }
0069 
0070       void registerProductsAndCallbacks(ProductRegistry* iReg) override {
0071         m_mod->registerProductsAndCallbacks(module().get(), iReg);
0072       }
0073 
0074       std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() override {
0075         return OutputModuleCommunicatorT<T>::createIfNeeded(m_mod.get());
0076       }
0077 
0078     private:
0079       std::shared_ptr<T> m_mod;
0080     };
0081   }  // namespace maker
0082 }  // namespace edm
0083 
0084 #endif