CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ComponentMaker.h
Go to the documentation of this file.
1 #ifndef Framework_ComponentMaker_h
2 #define Framework_ComponentMaker_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : ComponentMaker
7 //
16 //
17 // Author: Chris Jones
18 // Created: Wed May 25 16:56:05 EDT 2005
19 //
20 
21 // system include files
22 #include <memory>
23 #include <string>
24 
25 // user include files
29 
30 // forward declarations
31 
32 namespace edm {
33  namespace eventsetup {
34  class EventSetupProvider;
35  class EventSetupsController;
36  class DataProxyProvider;
37 
39  public:
41 
42  protected:
44  };
45 
46  template <class T>
48  public:
49  typedef typename T::base_type base_type;
50  virtual std::shared_ptr<base_type> addTo(EventSetupsController& esController,
51  EventSetupProvider& iProvider,
52  ParameterSet const& iConfiguration,
53  bool replaceExisting) const = 0;
54  };
55 
56  template <class T, class TComponent>
57  class ComponentMaker : public ComponentMakerBase<T> {
58  public:
60  ComponentMaker(const ComponentMaker&) = delete; // stop default
61  const ComponentMaker& operator=(const ComponentMaker&) = delete; // stop default
62  typedef typename T::base_type base_type;
63 
64  // ---------- const member functions ---------------------
65  std::shared_ptr<base_type> addTo(EventSetupsController& esController,
66  EventSetupProvider& iProvider,
67  ParameterSet const& iConfiguration,
68  bool replaceExisting) const override;
69 
70  // ---------- static member functions --------------------
71 
72  // ---------- member functions ---------------------------
73  private:
74  void setDescription(DataProxyProvider* iProv, const ComponentDescription& iDesc) const {
75  iProv->setDescription(iDesc);
76  }
78  iFinder->setDescriptionForFinder(iDesc);
79  }
80  void setPostConstruction(DataProxyProvider* iProv, const edm::ParameterSet& iPSet) const {
81  //The 'appendToDataLabel' parameter was added very late in the development cycle and since
82  // the ParameterSet is not sent to the base class we must set the value after construction
83  iProv->setAppendToDataLabel(iPSet);
84  }
85  void setDescription(void*, const ComponentDescription&) const {}
86  void setDescriptionForFinder(void*, const ComponentDescription&) const {}
87  void setPostConstruction(void*, const edm::ParameterSet&) const {}
88  // ---------- member data --------------------------------
89  };
90 
91  template <class T, class TComponent>
92  std::shared_ptr<typename ComponentMaker<T, TComponent>::base_type> ComponentMaker<T, TComponent>::addTo(
93  EventSetupsController& esController,
94  EventSetupProvider& iProvider,
95  ParameterSet const& iConfiguration,
96  bool replaceExisting) const {
97  // This adds components to the EventSetupProvider for the process. It might
98  // make a new component then add it or reuse a component from an earlier
99  // SubProcess or the top level process and add that.
100 
101  if (!replaceExisting) {
102  std::shared_ptr<typename T::base_type> alreadyMadeComponent =
103  T::getComponentAndRegisterProcess(esController, iConfiguration);
104 
105  if (alreadyMadeComponent) {
106  // This is for the case when a component is shared between
107  // a SubProcess and a previous SubProcess or the top level process
108  // because the component has an identical configuration to a component
109  // from the top level process or earlier SubProcess.
110  std::shared_ptr<TComponent> component(
111  std::static_pointer_cast<TComponent, typename T::base_type>(alreadyMadeComponent));
112  T::addTo(iProvider, component, iConfiguration, true);
113  return component;
114  }
115  }
116 
117  std::shared_ptr<TComponent> component = std::make_shared<TComponent>(iConfiguration);
118  ComponentDescription description = this->createComponentDescription(iConfiguration);
119 
120  this->setDescription(component.get(), description);
121  this->setDescriptionForFinder(component.get(), description);
122  this->setPostConstruction(component.get(), iConfiguration);
123 
124  if (replaceExisting) {
125  // This case is for ESProducers where in the first pass
126  // the algorithm thought the component could be shared
127  // across SubProcess's because there was an ESProducer
128  // from a previous process with an identical configuration.
129  // But in a later check it was determined that sharing was not
130  // possible because other components associated with the
131  // same record or records that record depends on had
132  // differing configurations.
133  T::replaceExisting(iProvider, component);
134  } else {
135  // This is for the case when a new component is being constructed.
136  // All components for the top level process fall in this category.
137  // Or it could be a SubProcess where neither the top level process
138  // nor any prior SubProcess had a component with exactly the same configuration.
139  T::addTo(iProvider, component, iConfiguration, false);
140  T::putComponent(esController, iConfiguration, component);
141  }
142  return component;
143  }
144  } // namespace eventsetup
145 } // namespace edm
146 #endif
void setDescription(const ComponentDescription &iDescription)
virtual std::shared_ptr< base_type > addTo(EventSetupsController &esController, EventSetupProvider &iProvider, ParameterSet const &iConfiguration, bool replaceExisting) const =0
void setPostConstruction(DataProxyProvider *iProv, const edm::ParameterSet &iPSet) const
void setDescriptionForFinder(const eventsetup::ComponentDescription &iDescription)
void setAppendToDataLabel(const edm::ParameterSet &)
void setPostConstruction(void *, const edm::ParameterSet &) const
void setDescription(DataProxyProvider *iProv, const ComponentDescription &iDesc) const
const ComponentMaker & operator=(const ComponentMaker &)=delete
void setDescription(void *, const ComponentDescription &) const
void setDescriptionForFinder(void *, const ComponentDescription &) const
std::shared_ptr< base_type > addTo(EventSetupsController &esController, EventSetupProvider &iProvider, ParameterSet const &iConfiguration, bool replaceExisting) const override
void setDescriptionForFinder(EventSetupRecordIntervalFinder *iFinder, const ComponentDescription &iDesc) const
ComponentDescription createComponentDescription(ParameterSet const &iConfiguration) const