CMS 3D CMS Logo

ESProducer.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ESProducer_h
2 #define FWCore_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
80 
86 
87 // forward declarations
88 namespace edm {
89  namespace eventsetup {
90 
92  //used by ESProducer to create the proper Decorator based on the
93  // argument type passed. The default it to just 'pass through'
94  // the argument as the decorator itself
95  template <typename T, typename TRecord, typename TDecorator>
96  inline const TDecorator& createDecoratorFrom(T*, const TRecord*, const TDecorator& iDec) {
97  return iDec;
98  }
99  } // namespace eventsetup
100 
102  public:
103  ESProducer();
104  ~ESProducer() noexcept(false) override;
105  ESProducer(const ESProducer&) = delete; // stop default
106  ESProducer const& operator=(const ESProducer&) = delete; // stop default
107 
108  void updateLookup(eventsetup::ESRecordsToProxyIndices const&) final;
109  ESProxyIndex const* getTokenIndices(unsigned int iIndex) const {
110  if (itemsToGetFromRecords_.empty()) {
111  return nullptr;
112  }
113  return (itemsToGetFromRecords_[iIndex].empty()) ? static_cast<ESProxyIndex const*>(nullptr)
114  : &(itemsToGetFromRecords_[iIndex].front());
115  }
116 
117  template <typename Record>
118  void updateFromMayConsumes(unsigned int iIndex, const Record& iRecord) {
119  if (itemsToGetFromRecords_.empty() or itemsToGetFromRecords_[iIndex].empty()) {
120  return;
121  }
122  auto const info = consumesInfos_[iIndex].get();
123  for (size_t i = 0; i < info->size(); ++i) {
124  auto chooserBase = (*info)[i].chooser_.get();
125  if (chooserBase) {
126  auto chooser = static_cast<eventsetup::impl::MayConsumeChooserBase<Record>*>(chooserBase);
127  itemsToGetFromRecords_[iIndex][i] = chooser->makeChoice(iRecord);
128  }
129  }
130  }
131 
132  protected:
137  template <typename T>
138  auto setWhatProduced(T* iThis, const es::Label& iLabel = {}) {
139  return setWhatProduced(iThis, &T::produce, iLabel);
140  }
141 
142  template <typename T>
143  auto setWhatProduced(T* iThis, const char* iLabel) {
144  return setWhatProduced(iThis, es::Label(iLabel));
145  }
146  template <typename T>
147  auto setWhatProduced(T* iThis, const std::string& iLabel) {
148  return setWhatProduced(iThis, es::Label(iLabel));
149  }
150 
151  template <typename T, typename TDecorator>
152  auto setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = {}) {
153  return setWhatProduced(iThis, &T::produce, iDec, iLabel);
154  }
160  template <typename T, typename TReturn, typename TRecord>
161  auto setWhatProduced(T* iThis, TReturn (T ::*iMethod)(const TRecord&), const es::Label& iLabel = {}) {
162  return setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(), iLabel);
163  }
170  template <typename T, typename TReturn, typename TRecord, typename TArg>
172  TReturn (T ::*iMethod)(const TRecord&),
173  const TArg& iDec,
174  const es::Label& iLabel = {}) {
175  const auto id = consumesInfos_.size();
178  unsigned int iovIndex = 0; // Start with 0, but later will cycle through all of them
179  auto temp = std::make_shared<CallbackType>(
180  iThis, iMethod, id, createDecoratorFrom(iThis, static_cast<const TRecord*>(nullptr), iDec));
181  auto callback =
182  std::make_shared<std::pair<unsigned int, std::shared_ptr<CallbackType>>>(iovIndex, std::move(temp));
183  registerProducts(std::move(callback),
184  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type*>(nullptr),
185  static_cast<const TRecord*>(nullptr),
186  iLabel);
187  consumesInfos_.push_back(std::make_unique<ESConsumesInfo>());
188  return ESConsumesCollectorT<TRecord>(consumesInfos_.back().get(), id);
189  }
190 
191  private:
192  template <typename CallbackT, typename TList, typename TRecord>
193  void registerProducts(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>> iCallback,
194  const TList*,
195  const TRecord* iRecord,
196  const es::Label& iLabel) {
197  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
198  registerProducts(std::move(iCallback), static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
199  }
200 
201  template <typename CallbackT, typename TRecord>
202  void registerProducts(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>>,
204  const TRecord*,
205  const es::Label&) {
206  //do nothing
207  }
208 
209  template <typename CallbackT, typename TProduct, typename TRecord>
210  void registerProduct(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>> iCallback,
211  const TProduct*,
212  const TRecord*,
213  const es::Label& iLabel) {
216  registerFactory(std::make_unique<FactoryType>(std::move(iCallback)), iLabel.default_);
217  }
218 
219  template <typename CallbackT, typename TProduct, typename TRecord, int IIndex>
220  void registerProduct(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>> iCallback,
222  const TRecord*,
223  const es::Label& iLabel) {
224  if (iLabel.labels_.size() <= IIndex || iLabel.labels_[IIndex] == es::Label::def()) {
226  "Unnamed Label\nthe index ",
227  IIndex,
228  " was never assigned a name in the 'setWhatProduced' method");
229  }
232  registerFactory(std::make_unique<FactoryType>(std::move(iCallback)), iLabel.labels_[IIndex]);
233  }
234 
235  std::vector<std::unique_ptr<ESConsumesInfo>> consumesInfos_;
236  std::vector<std::vector<ESProxyIndex>> itemsToGetFromRecords_;
237  //need another structure to say which record to get the data from in
238  // order to make prefetching work
239  std::vector<std::vector<ESRecordIndex>> recordsUsedDuringGet_;
240  };
241 } // namespace edm
242 #endif
auto setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:147
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
static const std::string & def()
Definition: es_Label.h:82
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< std::vector< ESRecordIndex > > recordsUsedDuringGet_
Definition: ESProducer.h:239
std::vector< std::unique_ptr< ESConsumesInfo > > consumesInfos_
Definition: ESProducer.h:235
auto setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const es::Label &iLabel={})
Definition: ESProducer.h:161
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:96
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void updateFromMayConsumes(unsigned int iIndex, const Record &iRecord)
Definition: ESProducer.h:118
void registerProduct(std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const TProduct *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:210
void registerProducts(std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>>, const eventsetup::produce::Null *, const TRecord *, const es::Label &)
Definition: ESProducer.h:202
ESConsumesCollectorT< TRecord > setWhatProduced(T *iThis, TReturn(T::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:171
#define noexcept
ESProxyIndex const * getTokenIndices(unsigned int iIndex) const
Definition: ESProducer.h:109
void registerProducts(std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const TList *, const TRecord *iRecord, const es::Label &iLabel)
Definition: ESProducer.h:193
HLT enums.
std::string default_
Definition: es_Label.h:88
auto setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:143
auto setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:152
void registerProduct(std::shared_ptr< std::pair< unsigned int, std::shared_ptr< CallbackT >>> iCallback, const es::L< TProduct, IIndex > *, const TRecord *, const es::Label &iLabel)
Definition: ESProducer.h:220
std::vector< std::string > labels_
Definition: es_Label.h:87
long double T
std::vector< std::vector< ESProxyIndex > > itemsToGetFromRecords_
Definition: ESProducer.h:236
def move(src, dest)
Definition: eostools.py:511
virtual ESProxyIndex makeChoice(RCD const &iRecord) const =0