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 #include <optional>
75 
76 // user include files
81 
87 
89 
90 // forward declarations
91 namespace edm {
92  namespace eventsetup {
93 
95  //used by ESProducer to create the proper Decorator based on the
96  // argument type passed. The default it to just 'pass through'
97  // the argument as the decorator itself
98  template <typename T, typename TRecord, typename TDecorator>
99  inline const TDecorator& createDecoratorFrom(T*, const TRecord*, const TDecorator& iDec) {
100  return iDec;
101  }
102  } // namespace eventsetup
103 
105  public:
106  ESProducer();
107  ~ESProducer() noexcept(false) override;
108  ESProducer(const ESProducer&) = delete; // stop default
109  ESProducer const& operator=(const ESProducer&) = delete; // stop default
110 
112  ESProxyIndex const* getTokenIndices(unsigned int iIndex) const {
113  if (itemsToGetFromRecords_.empty()) {
114  return nullptr;
115  }
116  return (itemsToGetFromRecords_[iIndex].empty()) ? static_cast<ESProxyIndex const*>(nullptr)
117  : &(itemsToGetFromRecords_[iIndex].front());
118  }
119  ESRecordIndex const* getTokenRecordIndices(unsigned int iIndex) const {
120  if (recordsUsedDuringGet_.empty()) {
121  return nullptr;
122  }
123  return (recordsUsedDuringGet_[iIndex].empty()) ? static_cast<ESRecordIndex const*>(nullptr)
124  : &(recordsUsedDuringGet_[iIndex].front());
125  }
126  size_t numberOfTokenIndices(unsigned int iIndex) const {
127  if (itemsToGetFromRecords_.empty()) {
128  return 0;
129  }
130  return itemsToGetFromRecords_[iIndex].size();
131  }
132 
133  bool hasMayConsumes() const noexcept { return hasMayConsumes_; }
134 
135  template <typename Record>
136  std::optional<std::vector<ESProxyIndex>> updateFromMayConsumes(unsigned int iIndex, const Record& iRecord) const {
137  if (not hasMayConsumes()) {
138  return {};
139  }
140  std::vector<ESProxyIndex> ret = itemsToGetFromRecords_[iIndex];
141  auto const info = consumesInfos_[iIndex].get();
142  for (size_t i = 0; i < info->size(); ++i) {
143  auto chooserBase = (*info)[i].chooser_.get();
144  if (chooserBase) {
145  auto chooser = static_cast<eventsetup::impl::MayConsumeChooserBase<Record>*>(chooserBase);
146  ret[i] = chooser->makeChoice(iRecord);
147  }
148  }
149  return ret;
150  }
151 
153 
154  protected:
156  void usesResources(std::vector<std::string> const&);
157 
162  template <typename T>
163  auto setWhatProduced(T* iThis, const es::Label& iLabel = {}) {
164  return setWhatProduced(iThis, &T::produce, iLabel);
165  }
166 
167  template <typename T>
168  auto setWhatProduced(T* iThis, const char* iLabel) {
169  return setWhatProduced(iThis, es::Label(iLabel));
170  }
171  template <typename T>
172  auto setWhatProduced(T* iThis, const std::string& iLabel) {
173  return setWhatProduced(iThis, es::Label(iLabel));
174  }
175 
176  template <typename T, typename TDecorator>
177  auto setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = {}) {
178  return setWhatProduced(iThis, &T::produce, iDec, iLabel);
179  }
185  template <typename T, typename TReturn, typename TRecord>
186  auto setWhatProduced(T* iThis, TReturn (T ::*iMethod)(const TRecord&), const es::Label& iLabel = {}) {
187  return setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(), iLabel);
188  }
195  template <typename T, typename TReturn, typename TRecord, typename TArg>
197  TReturn (T ::*iMethod)(const TRecord&),
198  const TArg& iDec,
199  const es::Label& iLabel = {}) {
200  const auto id = consumesInfos_.size();
203  unsigned int iovIndex = 0; // Start with 0, but later will cycle through all of them
204  auto temp = std::make_shared<CallbackType>(
205  iThis, iMethod, id, createDecoratorFrom(iThis, static_cast<const TRecord*>(nullptr), iDec));
206  auto callback =
207  std::make_shared<std::pair<unsigned int, std::shared_ptr<CallbackType>>>(iovIndex, std::move(temp));
209  static_cast<const typename eventsetup::produce::product_traits<TReturn>::type*>(nullptr),
210  static_cast<const TRecord*>(nullptr),
211  iLabel);
212  consumesInfos_.push_back(std::make_unique<ESConsumesInfo>());
213  return ESConsumesCollectorT<TRecord>(consumesInfos_.back().get(), id);
214  }
215 
216  private:
217  template <typename CallbackT, typename TList, typename TRecord>
218  void registerProducts(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>> iCallback,
219  const TList*,
220  const TRecord* iRecord,
221  const es::Label& iLabel) {
222  registerProduct(iCallback, static_cast<const typename TList::tail_type*>(nullptr), iRecord, iLabel);
223  registerProducts(std::move(iCallback), static_cast<const typename TList::head_type*>(nullptr), iRecord, iLabel);
224  }
225 
226  template <typename CallbackT, typename TRecord>
227  void registerProducts(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>>,
229  const TRecord*,
230  const es::Label&) {
231  //do nothing
232  }
233 
234  template <typename CallbackT, typename TProduct, typename TRecord>
235  void registerProduct(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>> iCallback,
236  const TProduct*,
237  const TRecord*,
238  const es::Label& iLabel) {
241  registerFactory(std::make_unique<FactoryType>(std::move(iCallback)), iLabel.default_);
242  }
243 
244  template <typename CallbackT, typename TProduct, typename TRecord, int IIndex>
245  void registerProduct(std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackT>>> iCallback,
247  const TRecord*,
248  const es::Label& iLabel) {
249  if (iLabel.labels_.size() <= IIndex || iLabel.labels_[IIndex] == es::Label::def()) {
251  "Unnamed Label\nthe index ",
252  IIndex,
253  " was never assigned a name in the 'setWhatProduced' method");
254  }
257  registerFactory(std::make_unique<FactoryType>(std::move(iCallback)), iLabel.labels_[IIndex]);
258  }
259 
260  std::vector<std::unique_ptr<ESConsumesInfo>> consumesInfos_;
261  std::vector<std::vector<ESProxyIndex>> itemsToGetFromRecords_;
262  //need another structure to say which record to get the data from in
263  // order to make prefetching work
264  std::vector<std::vector<ESRecordIndex>> recordsUsedDuringGet_;
265 
267  std::unique_ptr<std::vector<std::string>> sharedResourceNames_;
268  bool hasMayConsumes_ = false;
269  };
270 } // namespace edm
271 #endif
auto setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:172
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
static const std::string & def()
Definition: es_Label.h:84
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< std::vector< ESRecordIndex > > recordsUsedDuringGet_
Definition: ESProducer.h:264
ret
prodAgent to be discontinued
std::vector< std::unique_ptr< ESConsumesInfo > > consumesInfos_
Definition: ESProducer.h:260
std::optional< std::vector< ESProxyIndex > > updateFromMayConsumes(unsigned int iIndex, const Record &iRecord) const
Definition: ESProducer.h:136
ESConsumesCollectorT< TRecord > setWhatProduced(T *iThis, TReturn(T ::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:196
ESProducer const & operator=(const ESProducer &)=delete
ESProxyIndex const * getTokenIndices(unsigned int iIndex) const
Definition: ESProducer.h:112
bool hasMayConsumes() const noexcept
Definition: ESProducer.h:133
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:84
void usesResources(std::vector< std::string > const &)
Definition: ESProducer.cc:117
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:99
auto setWhatProduced(T *iThis, TReturn(T ::*iMethod)(const TRecord &), const es::Label &iLabel={})
Definition: ESProducer.h:186
SerialTaskQueueChain & serialQueueChain() const
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:235
size_t numberOfTokenIndices(unsigned int iIndex) const
Definition: ESProducer.h:126
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:227
ESRecordIndex const * getTokenRecordIndices(unsigned int iIndex) const
Definition: ESProducer.h:119
std::unique_ptr< std::vector< std::string > > sharedResourceNames_
Definition: ESProducer.h:267
bool hasMayConsumes_
Definition: ESProducer.h:268
void updateLookup(eventsetup::ESRecordsToProxyIndices const &) final
Definition: ESProducer.cc:54
SerialTaskQueueChain & queue()
Definition: ESProducer.h:152
void registerFactory(std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
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:218
SharedResourcesAcquirer acquirer_
Definition: ESProducer.h:266
HLT enums.
std::string default_
Definition: es_Label.h:90
auto setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:168
~ESProducer() noexcept(false) override
Definition: ESProducer.cc:37
auto setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:177
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:245
std::vector< std::string > labels_
Definition: es_Label.h:89
long double T
std::vector< std::vector< ESProxyIndex > > itemsToGetFromRecords_
Definition: ESProducer.h:261
def move(src, dest)
Definition: eostools.py:511