CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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();
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  //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<ED, T>::type));
117  setWhatProduced(iThis , &T::produce, iLabel);
118  }
119 
120  template<typename T>
121  void setWhatProduced(T* iThis, const char* iLabel) {
122  //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<ED, T>::type));
123  setWhatProduced(iThis , es::Label(iLabel));
124  }
125  template<typename T>
126  void setWhatProduced(T* iThis, const std::string& iLabel) {
127  //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<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  //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<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()) {
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  std::shared_ptr<eventsetup::Callback<T,TReturn,TRecord, typename eventsetup::DecoratorFromArg<T, TRecord, TArg>::Decorator_t > >
160  TReturn,
161  TRecord,
163  iThis,
164  iMethod,
165  createDecoratorFrom(iThis,
166  static_cast<const TRecord*>(nullptr),
167  iDec)));
168  registerProducts(callback,
169  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type *>(nullptr),
170  static_cast<const TRecord*>(nullptr),
171  iLabel);
172  //BOOST_STATIC_ASSERT((boost::is_base_and_derived<ED, T>::type));
173  }
174 
175  /*
176  template<typename T, typename TReturn, typename TArg>
177  void setWhatProduced(T* iThis, TReturn (T ::* iMethod)(const TArg&)) {
178  registerProducts(iThis, static_cast<const typename produce::product_traits<TReturn>::type *>(nullptr));
179  registerGet(iThis, static_cast<const TArg*>(nullptr));
180  //BOOST_STATIC_ASSERT((boost::is_base_and_derived<ED, T>::type));
181  }
182  */
183  private:
184  ESProducer(const ESProducer&); // stop default
185 
186  ESProducer const& operator=(const ESProducer&); // stop default
187 
188  /*
189  template<typename T, typename TProduct>
190  void registerGet(T* i, const TProduct* iProd) {
191  std::cout <<"registered 'get' for product type "
192  << test::name(iProd) <<
193  std::endl;
194  };
195  */
196  template<typename CallbackT, typename TList, typename TRecord>
197  void registerProducts(std::shared_ptr<CallbackT> iCallback, const TList*, const TRecord* iRecord,
198  const es::Label& iLabel) {
199  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
200  registerProducts(iCallback, static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
201  }
202  template<typename T, typename TRecord>
203  void registerProducts(std::shared_ptr<T>, const eventsetup::produce::Null*, const TRecord*,const es::Label&) {
204  //do nothing
205  }
206 
207 
208  template<typename T, typename TProduct, typename TRecord>
209  void registerProduct(std::shared_ptr<T> iCallback, const TProduct*, const TRecord*,const es::Label& iLabel) {
212  registerFactory(std::auto_ptr<FactoryType>(new FactoryType(iCallback)), iLabel.default_);
213  }
214 
215  template<typename T, typename TProduct, typename TRecord, int IIndex>
216  void registerProduct(std::shared_ptr<T> iCallback, const es::L<TProduct,IIndex>*, const TRecord*,const es::Label& iLabel) {
217  if(iLabel.labels_.size() <= IIndex ||
218  iLabel.labels_[IIndex] == es::Label::def()) {
220  "Unnamed Label\nthe index ",
221  IIndex,
222  " was never assigned a name in the 'setWhatProduced' method");
223  }
226  registerFactory(std::auto_ptr<FactoryType>(new FactoryType(iCallback)), iLabel.labels_[IIndex]);
227  }
228 
229  // ---------- member data --------------------------------
230  // NOTE: the factories share ownership of the callback
231  //std::vector<std::shared_ptr<CallbackBase> > callbacks_;
232 
233 };
234 }
235 #endif
void registerProduct(std::shared_ptr< T > iCallback, const es::L< TProduct, IIndex > *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:216
static const std::string & def()
Definition: es_Label.h:81
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:209
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:93
ESProducer const & operator=(const ESProducer &)
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:203
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
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:197
virtual ~ESProducer()
Definition: ESProducer.cc:39
std::vector< std::string > labels_
Definition: es_Label.h:85
long double T
void registerFactory(std::auto_ptr< TFactory > iFactory, const std::string &iLabel=std::string())