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
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
edm::SharedResourcesAcquirer::serialQueueChain
SerialTaskQueueChain & serialQueueChain() const
Definition: SharedResourcesAcquirer.h:54
edm::ESProducer::~ESProducer
~ESProducer() noexcept(false) override
Definition: ESProducer.cc:37
edm::SharedResourcesAcquirer
Definition: SharedResourcesAcquirer.h:34
edm::ESProxyFactoryProducer
Definition: ESProxyFactoryProducer.h:76
edm::es::Label::default_
std::string default_
Definition: es_Label.h:90
edm::eventsetup::produce::product_traits::type
T type
Definition: produce_helpers.h:58
mps_fire.i
i
Definition: mps_fire.py:428
edm::eventsetup::ESRecordsToProxyIndices
Definition: ESRecordsToProxyIndices.h:35
edm::ESProducer::itemsToGetFromRecords_
std::vector< std::vector< ESProxyIndex > > itemsToGetFromRecords_
Definition: ESProducer.h:261
ESProxyFactoryProducer.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ESProducer::updateFromMayConsumes
std::optional< std::vector< ESProxyIndex > > updateFromMayConsumes(unsigned int iIndex, const Record &iRecord) const
Definition: ESProducer.h:136
edm::eventsetup::impl::MayConsumeChooserBase
Definition: MayConsumeChooserBase.h:50
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const std::string &iLabel)
Definition: ESProducer.h:172
edm::ESProducer::recordsUsedDuringGet_
std::vector< std::vector< ESRecordIndex > > recordsUsedDuringGet_
Definition: ESProducer.h:264
ESConsumesCollector.h
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
edm::eventsetup::CallbackSimpleDecorator
Definition: Callback.h:44
edm::ESRecordIndex
Definition: ESIndices.h:80
edm::ESProducer::getTokenIndices
ESProxyIndex const * getTokenIndices(unsigned int iIndex) const
Definition: ESProducer.h:112
watchdog.const
const
Definition: watchdog.py:83
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::ESProducer::hasMayConsumes
bool hasMayConsumes() const noexcept
Definition: ESProducer.h:133
edm::eventsetup::Callback
Definition: Callback.h:54
edm::ESProxyIndex
Definition: ESIndices.h:30
edm::ESProducer::setWhatProduced
ESConsumesCollectorT< TRecord > setWhatProduced(T *iThis, TReturn(T ::*iMethod)(const TRecord &), const TArg &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:196
edm::ESConsumesCollectorT
Definition: ESConsumesCollector.h:125
edm::ESProducer::consumesInfos_
std::vector< std::unique_ptr< ESConsumesInfo > > consumesInfos_
Definition: ESProducer.h:260
SharedResourcesAcquirer.h
es_Label.h
eventsetup_dependsOn.h
edm::eventsetup::produce::Null
Definition: produce_helpers.h:47
edm::ESProducer::registerProducts
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
Callback.h
edm::eventsetup::createDecoratorFrom
const TDecorator & createDecoratorFrom(T *, const TRecord *, const TDecorator &iDec)
Definition: ESProducer.h:99
edm::ESProducer::ESProducer
ESProducer()
Definition: ESProducer.cc:30
edm::ESProducer::usesResources
void usesResources(std::vector< std::string > const &)
Definition: ESProducer.cc:117
edm::es::Label
Definition: es_Label.h:56
edm::es::Label::def
static const std::string & def()
Definition: es_Label.h:84
edm::ESProxyFactoryProducer::registerFactory
void registerFactory(std::unique_ptr< TFactory > iFactory, const std::string &iLabel=std::string())
Definition: ESProxyFactoryProducer.h:97
edm::ESProducer::operator=
ESProducer const & operator=(const ESProducer &)=delete
edm::ESProducer::numberOfTokenIndices
size_t numberOfTokenIndices(unsigned int iIndex) const
Definition: ESProducer.h:126
edm::eventsetup::ProxyArgumentFactoryTemplate
Definition: ProxyArgumentFactoryTemplate.h:37
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::es::L
Definition: es_Label.h:36
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, TReturn(T ::*iMethod)(const TRecord &), const es::Label &iLabel={})
Definition: ESProducer.h:186
edm::ESProducer::registerProducts
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
ESRecordsToProxyIndices
edm::ESProducer::getTokenRecordIndices
ESRecordIndex const * getTokenRecordIndices(unsigned int iIndex) const
Definition: ESProducer.h:119
edm::ESProducer::queue
SerialTaskQueueChain & queue()
Definition: ESProducer.h:152
edm::ESProducer::sharedResourceNames_
std::unique_ptr< std::vector< std::string > > sharedResourceNames_
Definition: ESProducer.h:267
edm::eventsetup::DecoratorFromArg::Decorator_t
TArg Decorator_t
Definition: eventsetup_dependsOn.h:156
edm::ESProducer::hasMayConsumes_
bool hasMayConsumes_
Definition: ESProducer.h:268
edm::ESProducer::registerProduct
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
edm::es::Label::labels_
std::vector< std::string > labels_
Definition: es_Label.h:89
edm::ESProducer::updateLookup
void updateLookup(eventsetup::ESRecordsToProxyIndices const &) final
Definition: ESProducer.cc:54
edm::ESProducer::acquirer_
SharedResourcesAcquirer acquirer_
Definition: ESProducer.h:266
produce_helpers.h
edmIntegrityCheck.callback
callback
Definition: edmIntegrityCheck.py:75
eostools.move
def move(src, dest)
Definition: eostools.py:511
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
T
long double T
Definition: Basic3DVectorLD.h:48
Record
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
CallbackProxy.h
edm::ESProducer
Definition: ESProducer.h:104
edm::eventsetup::CallbackProxy
Definition: CallbackProxy.h:39
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const char *iLabel)
Definition: ESProducer.h:168
edm::SerialTaskQueueChain
Definition: SerialTaskQueueChain.h:32
ProxyArgumentFactoryTemplate.h
MayConsumeChooserBase.h
edm::errors::Configuration
Definition: EDMException.h:36
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const TDecorator &iDec, const es::Label &iLabel={})
Definition: ESProducer.h:177
edm::ESProducer::registerProduct
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