CMS 3D CMS Logo

ModuleHolder.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ModuleHolder_h
2 #define FWCore_Framework_ModuleHolder_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : ModuleHolder
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Fri, 23 Aug 2013 17:47:04 GMT
19 //
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
28 // forward declarations
29 namespace edm {
30  class Maker;
31  class ModuleDescription;
32  class ProductRegistry;
33  class ExceptionToActionTable;
34  class PreallocationConfiguration;
35 
36  namespace maker {
37  class ModuleHolder {
38  public:
39  ModuleHolder(Maker const* iMaker) : m_maker(iMaker) {}
40  virtual ~ModuleHolder() {}
41  std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions) const;
42 
43  virtual ModuleDescription const& moduleDescription() const = 0;
44  virtual void setModuleDescription(ModuleDescription const& iDesc) = 0;
45  virtual void preallocate(PreallocationConfiguration const&) = 0;
47  virtual void replaceModuleFor(Worker*) const = 0;
48 
49  virtual std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() = 0;
50 
51  protected:
52  Maker const* m_maker;
53  };
54 
55  template <typename T>
56  class ModuleHolderT : public ModuleHolder {
57  public:
58  ModuleHolderT(std::shared_ptr<T> iModule, Maker const* iMaker) : ModuleHolder(iMaker), m_mod(iModule) {}
59  ~ModuleHolderT() override {}
60  std::shared_ptr<T> module() const { return m_mod; }
61  void replaceModuleFor(Worker* iWorker) const override {
62  auto w = dynamic_cast<WorkerT<T>*>(iWorker);
63  assert(nullptr != w);
64  w->setModule(m_mod);
65  }
66  ModuleDescription const& moduleDescription() const override { return m_mod->moduleDescription(); }
67  void setModuleDescription(ModuleDescription const& iDesc) override { m_mod->setModuleDescription(iDesc); }
68  void preallocate(PreallocationConfiguration const& iPrealloc) override { m_mod->doPreallocate(iPrealloc); }
69 
71  m_mod->registerProductsAndCallbacks(module().get(), iReg);
72  }
73 
74  std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() override {
76  }
77 
78  private:
79  std::shared_ptr<T> m_mod;
80  };
81  } // namespace maker
82 } // namespace edm
83 
84 #endif
ModuleHolderT(std::shared_ptr< T > iModule, Maker const *iMaker)
Definition: ModuleHolder.h:58
void registerProductsAndCallbacks(ProductRegistry *iReg) override
Definition: ModuleHolder.h:70
roAction_t actions[nactions]
Definition: GenABIO.cc:181
std::shared_ptr< T > module() const
Definition: ModuleHolder.h:60
virtual void replaceModuleFor(Worker *) const =0
void replaceModuleFor(Worker *iWorker) const override
Definition: ModuleHolder.h:61
T w() const
virtual void setModuleDescription(ModuleDescription const &iDesc)=0
void preallocate(PreallocationConfiguration const &iPrealloc) override
Definition: ModuleHolder.h:68
assert(be >=bs)
virtual void preallocate(PreallocationConfiguration const &)=0
void setModuleDescription(ModuleDescription const &iDesc) override
Definition: ModuleHolder.h:67
virtual ModuleDescription const & moduleDescription() const =0
virtual void registerProductsAndCallbacks(ProductRegistry *)=0
std::unique_ptr< Worker > makeWorker(ExceptionToActionTable const *actions) const
Definition: ModuleHolder.cc:21
std::shared_ptr< T > m_mod
Definition: ModuleHolder.h:79
virtual std::unique_ptr< OutputModuleCommunicator > createOutputModuleCommunicator()=0
std::unique_ptr< OutputModuleCommunicator > createOutputModuleCommunicator() override
Definition: ModuleHolder.h:74
HLT enums.
ModuleDescription const & moduleDescription() const override
Definition: ModuleHolder.h:66
ModuleHolder(Maker const *iMaker)
Definition: ModuleHolder.h:39
static std::unique_ptr< edm::OutputModuleCommunicator > createIfNeeded(T *iMod)