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 
91  //used by ESProducer to create the proper Decorator based on the
92  // argument type passed. The default it to just 'pass through'
93  // the argument as the decorator itself
94  template <typename T, typename TRecord, typename TDecorator>
95  inline const TDecorator& createDecoratorFrom(T*, const TRecord*, const TDecorator& iDec) {
96  return iDec;
97  }
98  } // namespace eventsetup
100  public:
101  ESProducer();
102  ~ESProducer() noexcept(false) override;
103 
104  // ---------- const member functions ---------------------
105 
106  // ---------- static member functions --------------------
107 
108  // ---------- member functions ---------------------------
109  void updateLookup(eventsetup::ESRecordsToProxyIndices const&) final;
110  ESProxyIndex const* getTokenIndices(unsigned int iIndex) const {
111  if (itemsToGetFromRecords_.empty()) {
112  return nullptr;
113  }
114  return (itemsToGetFromRecords_[iIndex].empty()) ? static_cast<ESProxyIndex const*>(nullptr)
115  : &(itemsToGetFromRecords_[iIndex].front());
116  }
117 
118  protected:
123  template <typename T>
124  auto setWhatProduced(T* iThis, const es::Label& iLabel = {}) {
125  return setWhatProduced(iThis, &T::produce, iLabel);
126  }
127 
128  template <typename T>
129  auto setWhatProduced(T* iThis, const char* iLabel) {
130  return setWhatProduced(iThis, es::Label(iLabel));
131  }
132  template <typename T>
133  auto setWhatProduced(T* iThis, const std::string& iLabel) {
134  return setWhatProduced(iThis, es::Label(iLabel));
135  }
136 
137  template <typename T, typename TDecorator>
138  auto setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = {}) {
139  return setWhatProduced(iThis, &T::produce, iDec, iLabel);
140  }
146  template <typename T, typename TReturn, typename TRecord>
147  auto setWhatProduced(T* iThis, TReturn (T ::*iMethod)(const TRecord&), const es::Label& iLabel = {}) {
148  return setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(), iLabel);
149  }
156  template <typename T, typename TReturn, typename TRecord, typename TArg>
158  TReturn (T ::*iMethod)(const TRecord&),
159  const TArg& iDec,
160  const es::Label& iLabel = {}) {
161  const auto id = consumesInfos_.size();
162  auto callback = std::make_shared<
164  iThis, iMethod, id, createDecoratorFrom(iThis, static_cast<const TRecord*>(nullptr), iDec));
165  registerProducts(callback,
166  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type*>(nullptr),
167  static_cast<const TRecord*>(nullptr),
168  iLabel);
169  consumesInfos_.push_back(std::make_unique<ESConsumesInfo>());
170  return ESConsumesCollectorT<TRecord>(consumesInfos_.back().get(), id);
171  }
172 
173  ESProducer(const ESProducer&) = delete; // stop default
174  ESProducer const& operator=(const ESProducer&) = delete; // stop default
175 
176  private:
177  template <typename CallbackT, typename TList, typename TRecord>
178  void registerProducts(std::shared_ptr<CallbackT> iCallback,
179  const TList*,
180  const TRecord* iRecord,
181  const es::Label& iLabel) {
182  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
183  registerProducts(iCallback, static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
184  }
185 
186  template <typename T, typename TRecord>
187  void registerProducts(std::shared_ptr<T>, const eventsetup::produce::Null*, const TRecord*, const es::Label&) {
188  //do nothing
189  }
190 
191  template <typename T, typename TProduct, typename TRecord>
192  void registerProduct(std::shared_ptr<T> iCallback, const TProduct*, const TRecord*, const es::Label& iLabel) {
195  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.default_);
196  }
197 
198  template <typename T, typename TProduct, typename TRecord, int IIndex>
199  void registerProduct(std::shared_ptr<T> iCallback,
201  const TRecord*,
202  const es::Label& iLabel) {
203  if (iLabel.labels_.size() <= IIndex || iLabel.labels_[IIndex] == es::Label::def()) {
205  "Unnamed Label\nthe index ",
206  IIndex,
207  " was never assigned a name in the 'setWhatProduced' method");
208  }
211  registerFactory(std::make_unique<FactoryType>(iCallback), iLabel.labels_[IIndex]);
212  }
213 
214  std::vector<std::unique_ptr<ESConsumesInfo>> consumesInfos_;
215  std::vector<std::vector<ESProxyIndex>> itemsToGetFromRecords_;
216  //need another structure to say which record to get the data from in
217  // order to make prefetching work
218  std::vector<std::vector<ESRecordIndex>> recordsUsedDuringGet_;
219  };
220 } // namespace edm
221 #endif
auto setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:133
void registerProduct(std::shared_ptr< T > iCallback, const es::L< TProduct, IIndex > *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:199
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
static const std::string & def()
Definition: es_Label.h:82
std::vector< std::vector< ESRecordIndex > > recordsUsedDuringGet_
Definition: ESProducer.h:218
std::vector< std::unique_ptr< ESConsumesInfo > > consumesInfos_
Definition: ESProducer.h:214
auto setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
Definition: ESProducer.h:147
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
void registerProduct(std::shared_ptr< T > iCallback, const TProduct *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:192
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:95
ESConsumesCollectorT< TRecord > setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:157
void registerProducts(std::shared_ptr< T >, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
Definition: ESProducer.h:187
#define noexcept
ESProxyIndex const * getTokenIndices(unsigned int iIndex) const
Definition: ESProducer.h:110
HLT enums.
std::string default_
Definition: es_Label.h:88
auto setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:129
void registerProducts(std::shared_ptr< CallbackT > iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
Definition: ESProducer.h:178
auto setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:138
std::vector< std::string > labels_
Definition: es_Label.h:87
long double T
std::vector< std::vector< ESProxyIndex > > itemsToGetFromRecords_
Definition: ESProducer.h:215