CMS 3D CMS Logo

ESProducer.h
Go to the documentation of this file.
1 #ifndef Framework_ESProducer_h
2 #define Framework_ESProducer_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : ESProducer
7 //
66 //
67 // Author: Chris Jones
68 // Created: Thu Apr 7 17:08:14 CDT 2005
69 //
70 
71 // system include files
72 #include <memory>
73 #include <string>
74 
75 // user include files
79 
85 
86 // forward declarations
87 namespace edm {
88  namespace eventsetup {
89 
90  //used by ESProducer to create the proper Decorator based on the
91  // argument type passed. The default it to just 'pass through'
92  // the argument as the decorator itself
93  template< typename T, typename TRecord, typename TDecorator >
94  inline const TDecorator& createDecoratorFrom(T*, const TRecord*, const TDecorator& iDec) {
95  return iDec;
96  }
97  }
99  {
100 
101  public:
102  ESProducer();
103  ~ESProducer() noexcept(false) override;
104 
105  // ---------- const member functions ---------------------
106 
107  // ---------- static member functions --------------------
108 
109  // ---------- member functions ---------------------------
110  protected:
115  template<typename T>
116  auto setWhatProduced(T* iThis, const es::Label& iLabel = {}) {
117  return setWhatProduced(iThis , &T::produce, iLabel);
118  }
119 
120  template<typename T>
121  auto setWhatProduced(T* iThis, const char* iLabel) {
122  return setWhatProduced(iThis , es::Label(iLabel));
123  }
124  template<typename T>
125  auto setWhatProduced(T* iThis, const std::string& iLabel) {
126  return setWhatProduced(iThis , es::Label(iLabel));
127  }
128 
129  template<typename T, typename TDecorator >
130  auto setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = {}) {
131  return setWhatProduced(iThis , &T::produce, iDec, iLabel);
132  }
138  template<typename T, typename TReturn, typename TRecord>
139  auto setWhatProduced(T* iThis,
140  TReturn (T ::* iMethod)(const TRecord&),
141  const es::Label& iLabel = {}) {
142  return setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(),iLabel);
143  }
150  template<typename T, typename TReturn, typename TRecord, typename TArg>
152  TReturn (T ::* iMethod)(const TRecord&),
153  const TArg& iDec,
154  const es::Label& iLabel = {}) {
155  auto callback = std::make_shared<eventsetup::Callback<T,
156  TReturn,
157  TRecord,
159  iMethod,
160  createDecoratorFrom(iThis,
161  static_cast<const TRecord*>(nullptr),
162  iDec));
163  registerProducts(callback,
164  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type *>(nullptr),
165  static_cast<const TRecord*>(nullptr),
166  iLabel);
167  return ESConsumesCollector{iThis};
168  }
169 
170  ESProducer(const ESProducer&) = delete; // stop default
171  ESProducer const& operator=(const ESProducer&) = delete; // stop default
172 
173  private:
174 
175  template<typename CallbackT, typename TList, typename TRecord>
176  void registerProducts(std::shared_ptr<CallbackT> iCallback, const TList*, const TRecord* iRecord,
177  const es::Label& iLabel) {
178  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
179  registerProducts(iCallback, static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
180  }
181 
182  template<typename T, typename TRecord>
183  void registerProducts(std::shared_ptr<T>, const eventsetup::produce::Null*, const TRecord*,const es::Label&) {
184  //do nothing
185  }
186 
187  template<typename T, typename TProduct, typename TRecord>
188  void registerProduct(std::shared_ptr<T> iCallback, const TProduct*, const TRecord*,const es::Label& iLabel) {
191  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.default_);
192  }
193 
194  template<typename T, typename TProduct, typename TRecord, int IIndex>
195  void registerProduct(std::shared_ptr<T> iCallback, const es::L<TProduct,IIndex>*, const TRecord*,const es::Label& iLabel) {
196  if(iLabel.labels_.size() <= IIndex ||
197  iLabel.labels_[IIndex] == es::Label::def()) {
199  "Unnamed Label\nthe index ",
200  IIndex,
201  " was never assigned a name in the 'setWhatProduced' method");
202  }
205  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.labels_[IIndex]);
206  }
207 
208  };
209 }
210 #endif
auto setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:125
void registerProduct(std::shared_ptr< T > iCallback, const es::L< TProduct, IIndex > *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:195
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:116
static const std::string & def()
Definition: es_Label.h:88
#define noexcept
auto setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
Definition: ESProducer.h:139
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
void registerProduct(std::shared_ptr< T > iCallback, const TProduct *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:188
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:94
ESConsumesCollector setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:151
void registerProducts(std::shared_ptr< T >, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
Definition: ESProducer.h:183
HLT enums.
std::string default_
Definition: es_Label.h:94
auto setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:121
void registerProducts(std::shared_ptr< CallbackT > iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
Definition: ESProducer.h:176
auto setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:130
std::vector< std::string > labels_
Definition: es_Label.h:93
long double T