CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(void* iModule, Maker const* iMaker): m_mod(iModule),
40  m_maker(iMaker){}
41  virtual ~ModuleHolder() {}
42  std::unique_ptr<Worker> makeWorker(ExceptionToActionTable const* actions) const;
43 
44  virtual ModuleDescription const& moduleDescription() const = 0;
45  virtual void setModuleDescription(ModuleDescription const& iDesc) = 0;
46  virtual void preallocate(PreallocationConfiguration const& ) = 0;
48  virtual void replaceModuleFor(Worker*) const = 0;
49 
50  virtual std::unique_ptr<OutputModuleCommunicator> createOutputModuleCommunicator() = 0;
51  protected:
52  void * m_mod;
53  Maker const* m_maker;
54  };
55 
56  template<typename T>
57  class ModuleHolderT : public ModuleHolder {
58  public:
59  ModuleHolderT(T* iModule, Maker const* iMaker) :ModuleHolder(iModule,iMaker) {}
60  ~ModuleHolderT() { delete reinterpret_cast<T*>(m_mod); }
61  T* module() const { return reinterpret_cast<T*>(m_mod); }
62  void replaceModuleFor(Worker* iWorker) const override {
63  auto w = dynamic_cast<WorkerT<T>*>(iWorker);
64  assert(0!=w);
65  w->setModule(module());
66  }
67  ModuleDescription const& moduleDescription() const override {
68  return module()->moduleDescription();
69  }
70  void setModuleDescription(ModuleDescription const& iDesc) override {
71  module()->setModuleDescription(iDesc);
72  }
73  void preallocate(PreallocationConfiguration const& iPrealloc) override {
74  module()->doPreallocate(iPrealloc);
75  }
76 
78  module()->registerProductsAndCallbacks(module(),iReg);
79  }
80  T* release() {
81  T* m = module();
82  m_mod = nullptr;
83  return m;
84  }
85 
86  std::unique_ptr<OutputModuleCommunicator>
88  return std::move(OutputModuleCommunicatorT<T>::createIfNeeded(this->module()));
89  }
90 
91  };
92  }
93 }
94 
95 #endif
void registerProductsAndCallbacks(ProductRegistry *iReg) override
Definition: ModuleHolder.h:77
virtual void replaceModuleFor(Worker *) const =0
void replaceModuleFor(Worker *iWorker) const override
Definition: ModuleHolder.h:62
ModuleHolder(void *iModule, Maker const *iMaker)
Definition: ModuleHolder.h:39
virtual void setModuleDescription(ModuleDescription const &iDesc)=0
void preallocate(PreallocationConfiguration const &iPrealloc) override
Definition: ModuleHolder.h:73
std::unique_ptr< Worker > makeWorker(ExceptionToActionTable const *actions) const
Definition: ModuleHolder.cc:23
actions
Definition: Schedule.cc:362
virtual void preallocate(PreallocationConfiguration const &)=0
void setModuleDescription(ModuleDescription const &iDesc) override
Definition: ModuleHolder.h:70
virtual ModuleDescription const & moduleDescription() const =0
std::unique_ptr< OutputModuleCommunicator > createOutputModuleCommunicator()
Definition: ModuleHolder.h:87
virtual void registerProductsAndCallbacks(ProductRegistry *)=0
virtual std::unique_ptr< OutputModuleCommunicator > createOutputModuleCommunicator()=0
ModuleHolderT(T *iModule, Maker const *iMaker)
Definition: ModuleHolder.h:59
ModuleDescription const & moduleDescription() const override
Definition: ModuleHolder.h:67
T w() const
long double T