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  virtual ~ESProducer() noexcept(false);
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  //static_assert((typename std::is_base_of<ED, T>::type));
117  setWhatProduced(iThis , &T::produce, iLabel);
118  }
119 
120  template<typename T>
121  void setWhatProduced(T* iThis, const char* iLabel) {
122  //static_assert((typename std::is_base_of<ED, T>::type));
123  setWhatProduced(iThis , es::Label(iLabel));
124  }
125  template<typename T>
126  void setWhatProduced(T* iThis, const std::string& iLabel) {
127  //static_assert((typename std::is_base_of<ED, T>::type));
128  setWhatProduced(iThis , es::Label(iLabel));
129  }
130 
131  template<typename T, typename TDecorator >
132  void setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = es::Label()) {
133  //static_assert((typename std::is_base_of<ED, T>::type));
134  setWhatProduced(iThis , &T::produce, iDec, iLabel);
135  }
141  template<typename T, typename TReturn, typename TRecord>
142  void setWhatProduced(T* iThis,
143  TReturn (T ::* iMethod)(const TRecord&),
144  const es::Label& iLabel = es::Label()) {
145  setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(),iLabel);
146  }
153  template<typename T, typename TReturn, typename TRecord, typename TArg>
154  void setWhatProduced(T* iThis,
155  TReturn (T ::* iMethod)(const TRecord&),
156  const TArg& iDec,
157  const es::Label& iLabel = es::Label()) {
158  auto callback = std::make_shared<eventsetup::Callback<T,
159  TReturn,
160  TRecord,
162  iThis,
163  iMethod,
164  createDecoratorFrom(iThis,
165  static_cast<const TRecord*>(nullptr),
166  iDec));
167  registerProducts(callback,
168  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type *>(nullptr),
169  static_cast<const TRecord*>(nullptr),
170  iLabel);
171  //static_assert((std::is_base_of<ED, T>::type));
172  }
173 
174  /*
175  template<typename T, typename TReturn, typename TArg>
176  void setWhatProduced(T* iThis, TReturn (T ::* iMethod)(const TArg&)) {
177  registerProducts(iThis, static_cast<const typename produce::product_traits<TReturn>::type *>(nullptr));
178  registerGet(iThis, static_cast<const TArg*>(nullptr));
179  //static_assert((std::is_base_of<ED, T>::type));
180  }
181  */
182  private:
183  ESProducer(const ESProducer&); // stop default
184 
185  ESProducer const& operator=(const ESProducer&); // stop default
186 
187  /*
188  template<typename T, typename TProduct>
189  void registerGet(T* i, const TProduct* iProd) {
190  std::cout <<"registered 'get' for product type "
191  << test::name(iProd) <<
192  std::endl;
193  };
194  */
195  template<typename CallbackT, typename TList, typename TRecord>
196  void registerProducts(std::shared_ptr<CallbackT> iCallback, const TList*, const TRecord* iRecord,
197  const es::Label& iLabel) {
198  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
199  registerProducts(iCallback, static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
200  }
201  template<typename T, typename TRecord>
202  void registerProducts(std::shared_ptr<T>, const eventsetup::produce::Null*, const TRecord*,const es::Label&) {
203  //do nothing
204  }
205 
206 
207  template<typename T, typename TProduct, typename TRecord>
208  void registerProduct(std::shared_ptr<T> iCallback, const TProduct*, const TRecord*,const es::Label& iLabel) {
211  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.default_);
212  }
213 
214  template<typename T, typename TProduct, typename TRecord, int IIndex>
215  void registerProduct(std::shared_ptr<T> iCallback, const es::L<TProduct,IIndex>*, const TRecord*,const es::Label& iLabel) {
216  if(iLabel.labels_.size() <= IIndex ||
217  iLabel.labels_[IIndex] == es::Label::def()) {
219  "Unnamed Label\nthe index ",
220  IIndex,
221  " was never assigned a name in the 'setWhatProduced' method");
222  }
225  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.labels_[IIndex]);
226  }
227 
228  // ---------- member data --------------------------------
229  // NOTE: the factories share ownership of the callback
230  //std::vector<std::shared_ptr<CallbackBase> > callbacks_;
231 
232 };
233 }
234 #endif
void registerProduct(std::shared_ptr< T > iCallback, const es::L< TProduct, IIndex > *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:215
static const std::string & def()
Definition: es_Label.h:81
#define noexcept
void setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:126
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:208
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:142
void registerProducts(std::shared_ptr< T >, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
Definition: ESProducer.h:202
void setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:121
void setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:132
HLT enums.
std::string default_
Definition: es_Label.h:86
void setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:154
void registerProducts(std::shared_ptr< CallbackT > iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
Definition: ESProducer.h:196
std::vector< std::string > labels_
Definition: es_Label.h:85
long double T