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
78 
84 
85 // forward declarations
86 namespace edm {
87  namespace eventsetup {
88 
89  //used by ESProducer to create the proper Decorator based on the
90  // argument type passed. The default it to just 'pass through'
91  // the argument as the decorator itself
92  template< typename T, typename TRecord, typename TDecorator >
93  inline const TDecorator& createDecoratorFrom(T*, const TRecord*, const TDecorator& iDec) {
94  return iDec;
95  }
96  }
98  {
99 
100  public:
101  ESProducer();
102  ~ESProducer() noexcept(false) override;
103 
104  // ---------- const member functions ---------------------
105 
106  // ---------- static member functions --------------------
107 
108  // ---------- member functions ---------------------------
109  protected:
114  template<typename T>
115  void setWhatProduced(T* iThis, const es::Label& iLabel = es::Label()) {
116  setWhatProduced(iThis , &T::produce, iLabel);
117  }
118 
119  template<typename T>
120  void setWhatProduced(T* iThis, const char* iLabel) {
121  setWhatProduced(iThis , es::Label(iLabel));
122  }
123  template<typename T>
124  void setWhatProduced(T* iThis, const std::string& iLabel) {
125  setWhatProduced(iThis , es::Label(iLabel));
126  }
127 
128  template<typename T, typename TDecorator >
129  void setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = es::Label()) {
130  setWhatProduced(iThis , &T::produce, iDec, iLabel);
131  }
137  template<typename T, typename TReturn, typename TRecord>
138  void setWhatProduced(T* iThis,
139  TReturn (T ::* iMethod)(const TRecord&),
140  const es::Label& iLabel = es::Label()) {
141  setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(),iLabel);
142  }
149  template<typename T, typename TReturn, typename TRecord, typename TArg>
150  void setWhatProduced(T* iThis,
151  TReturn (T ::* iMethod)(const TRecord&),
152  const TArg& iDec,
153  const es::Label& iLabel = es::Label()) {
154  auto callback = std::make_shared<eventsetup::Callback<T,
155  TReturn,
156  TRecord,
158  iMethod,
159  createDecoratorFrom(iThis,
160  static_cast<const TRecord*>(nullptr),
161  iDec));
162  registerProducts(callback,
163  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type *>(nullptr),
164  static_cast<const TRecord*>(nullptr),
165  iLabel);
166  //static_assert((std::is_base_of<ED, T>::type));
167  }
168 
169  ESProducer(const ESProducer&) = delete; // stop default
170  ESProducer const& operator=(const ESProducer&) = delete; // stop default
171 
172  private:
173 
174  template<typename CallbackT, typename TList, typename TRecord>
175  void registerProducts(std::shared_ptr<CallbackT> iCallback, const TList*, const TRecord* iRecord,
176  const es::Label& iLabel) {
177  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
178  registerProducts(iCallback, static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
179  }
180  template<typename T, typename TRecord>
181  void registerProducts(std::shared_ptr<T>, const eventsetup::produce::Null*, const TRecord*,const es::Label&) {
182  //do nothing
183  }
184 
185 
186  template<typename T, typename TProduct, typename TRecord>
187  void registerProduct(std::shared_ptr<T> iCallback, const TProduct*, const TRecord*,const es::Label& iLabel) {
190  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.default_);
191  }
192 
193  template<typename T, typename TProduct, typename TRecord, int IIndex>
194  void registerProduct(std::shared_ptr<T> iCallback, const es::L<TProduct,IIndex>*, const TRecord*,const es::Label& iLabel) {
195  if(iLabel.labels_.size() <= IIndex ||
196  iLabel.labels_[IIndex] == es::Label::def()) {
198  "Unnamed Label\nthe index ",
199  IIndex,
200  " was never assigned a name in the 'setWhatProduced' method");
201  }
204  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.labels_[IIndex]);
205  }
206 
207  };
208 }
209 #endif
void registerProduct(std::shared_ptr< T > iCallback, const es::L< TProduct, IIndex > *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:194
static const std::string & def()
Definition: es_Label.h:88
#define noexcept
void setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:124
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
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:187
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:93
void setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel=es::Label())
Definition: ESProducer.h:138
void registerProducts(std::shared_ptr< T >, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
Definition: ESProducer.h:181
void setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:120
void setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:129
HLT enums.
std::string default_
Definition: es_Label.h:94
void setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:150
void registerProducts(std::shared_ptr< CallbackT > iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
Definition: ESProducer.h:175
std::vector< std::string > labels_
Definition: es_Label.h:93
long double T