CMS 3D CMS Logo

EDConsumerBase.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_EDConsumerBase_h
2 #define FWCore_Framework_EDConsumerBase_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : EDConsumerBase
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Tue, 02 Apr 2013 21:35:53 GMT
19 //
20 
21 // system include files
22 #include <array>
23 #include <map>
24 #include <string>
25 #include <vector>
26 #include <array>
27 #include <cassert>
28 
29 // user include files
52 
53 // forward declarations
54 
55 namespace edm {
56  class ModuleProcessName;
57  class ProductResolverIndexHelper;
58  class ConsumesCollector;
59  template <Transition Tr>
61  template <Transition Tr>
63  template <BranchType B>
65  template <typename T>
67 
68  namespace eventsetup {
70  }
71 
73  public:
75  virtual ~EDConsumerBase() noexcept(false);
76 
77  // disallow copying
78  EDConsumerBase(EDConsumerBase const&) = delete;
79  EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
80 
81  // allow moving
82  EDConsumerBase(EDConsumerBase&&) = default;
84 
85  // ---------- const member functions ---------------------
88 
89  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
90  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
91 
92  //used for prefetching
93  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const {
94  return itemsToGetFromBranch_[iType];
95  }
96 
99 
101  bool registeredToConsumeMany(TypeID const&, BranchType) const;
102  // ---------- static member functions --------------------
103 
104  // ---------- member functions ---------------------------
105  void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&, bool iPrefetchMayGet);
107  void selectInputProcessBlocks(ProductRegistry const& productRegistry,
108  ProcessBlockHelperBase const& processBlockHelperBase) {
109  doSelectInputProcessBlocks(productRegistry, processBlockHelperBase);
110  }
111 
113  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
114 
115  void modulesWhoseProductsAreConsumed(std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
116  std::vector<ModuleProcessName>& modulesInPreviousProcesses,
117  ProductRegistry const& preg,
118  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
119  std::string const& processName) const;
120 
123 
124  std::vector<ConsumesInfo> consumesInfo() const;
125 
128  auto const& v = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
129  if (v.empty()) {
130  return nullptr;
131  }
132  return &(esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].front());
133  }
134  return nullptr;
135  }
136 
137  std::vector<ESProxyIndex> const& esGetTokenIndicesVector(edm::Transition iTrans) const {
139  return esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
140  }
141 
142  std::vector<ESRecordIndex> const& esGetTokenRecordIndicesVector(edm::Transition iTrans) const {
144  return esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
145  }
146 
147  protected:
148  friend class ConsumesCollector;
149  template <Transition Tr>
151  template <Transition Tr>
153  template <BranchType B>
154  friend class EDConsumerBaseAdaptor;
155  template <typename T>
156  friend class WillGetIfMatch;
159 
160  template <typename ProductType, BranchType B = InEvent>
162  TypeToGet tid = TypeToGet::make<ProductType>();
164  }
165 
166  template <BranchType B = InEvent>
168  return EDConsumerBaseAdaptor<B>(this, std::move(tag));
169  }
170 
172  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
173  }
174 
175  template <BranchType B>
177  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
178  }
179 
180  template <typename ProductType, BranchType B = InEvent>
182  TypeToGet tid = TypeToGet::make<ProductType>();
184  }
185 
186  EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) { return mayConsume<InEvent>(id, tag); }
187 
188  template <BranchType B>
190  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), false)};
191  }
192 
193  template <typename ProductType, BranchType B = InEvent>
194  void consumesMany() {
195  TypeToGet tid = TypeToGet::make<ProductType>();
196  consumesMany<B>(tid);
197  }
198 
199  void consumesMany(const TypeToGet& id) { consumesMany<InEvent>(id); }
200 
201  template <BranchType B>
202  void consumesMany(const TypeToGet& id) {
203  recordConsumes(B, id, edm::InputTag{}, true);
204  }
205 
206  // For consuming event-setup products
207  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
208  auto esConsumes() {
209  return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
210  }
211 
212  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
213  auto esConsumes(ESInputTag const& tag) {
214  auto index = recordESConsumes(Tr,
216  std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
218  ESRecord>>(),
219  eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
220  tag);
221  return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, labelFor(index)};
222  }
223 
224  template <Transition Tr = Transition::Event>
225  [[nodiscard]] constexpr auto esConsumes() {
226  return EDConsumerBaseESAdaptor<Tr>(this);
227  }
228 
229  template <Transition Tr = Transition::Event>
230  [[nodiscard]] auto esConsumes(ESInputTag tag) {
232  }
233 
235  template <Transition Tr = Transition::Event>
237  return ESGetTokenGeneric(static_cast<unsigned int>(Tr),
238  recordESConsumes(Tr, iRecord, iKey.type(), ESInputTag("", iKey.name().value())),
239  iRecord.type());
240  }
241 
242  //used for FinalPath
243  void resetItemsToGetFrom(BranchType iType) { itemsToGetFromBranch_[iType].clear(); }
244 
245  private:
247  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
251  edm::ESInputTag const& iTag);
252 
253  const char* labelFor(ESTokenIndex) const;
254 
255  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
257  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
258  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
261  edm::ESInputTag const&) const;
262  void throwESConsumesInProcessBlock() const;
263 
265 
267 
268  // ---------- member data --------------------------------
269 
271  TokenLookupInfo(edm::TypeID const& iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
272  : m_type(iID), m_index(iIndex, skipCurrentProcess), m_branchType(iBranch) {}
276  };
277 
278  struct LabelPlacement {
279  LabelPlacement(unsigned int iStartOfModuleLabel,
280  unsigned short iDeltaToProductInstance,
281  unsigned short iDeltaToProcessName)
282  : m_startOfModuleLabel(iStartOfModuleLabel),
283  m_deltaToProductInstance(iDeltaToProductInstance),
284  m_deltaToProcessName(iDeltaToProcessName) {}
285  unsigned int m_startOfModuleLabel;
286  unsigned short m_deltaToProductInstance;
287  unsigned short m_deltaToProcessName;
288  };
289 
290  //define the purpose of each 'column' in m_tokenInfo
293 
294  //m_tokenStartOfLabels holds the entries into this container
295  // for each of the 3 labels needed to id the data
296  std::vector<char> m_tokenLabels;
297 
298  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
299 
304  };
305 
306  // TODO We would like to be able to access m_esTokenInfo from the
307  // index in the token, but this is currently not possible. One idea
308  // for this is to order the entries in m_esToken so that all the ones
309  // for transition 0 come first, then the ones for for transition 1
310  // and so on for all the transitions. Within a transition, the
311  // entries would be in the same order in m_esTokenInfo and
312  // esItemsToGetFromTransition_. This is something for future
313  // development and might require a change to SoATuple to support
314  // inserts in the middle of the data structure.
317  std::array<std::vector<ESProxyIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
319  std::array<std::vector<ESRecordIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
321  bool frozen_;
323  };
324 
325  template <Transition TR>
327  public:
328  template <typename TYPE, typename REC>
330  return m_consumer->template esConsumes<TYPE, REC, TR>();
331  }
332 
333  private:
334  //only EDConsumerBase is allowed to make an instance of this class
335  friend class EDConsumerBase;
337 
339  };
340 
341  template <Transition TR>
343  public:
344  template <typename TYPE, typename REC>
346  return m_consumer->template esConsumes<TYPE, REC, TR>(m_tag);
347  }
348 
349  private:
350  //only EDConsumerBase is allowed to make an instance of this class
351  friend class EDConsumerBase;
353  : m_consumer(iBase), m_tag(std::move(iTag)) {}
354 
357  };
358 
359  template <BranchType B>
360  class EDConsumerBaseAdaptor {
361  public:
362  template <typename TYPE>
364  return m_consumer->template consumes<TYPE, B>(m_tag);
365  }
366 
367  private:
368  //only EDConsumerBase is allowed to make an instance of this class
369  friend class EDConsumerBase;
371  : m_consumer(iBase), m_tag(std::move(iTag)) {}
372 
375  };
376 
377 } // namespace edm
378 
379 #endif
edm::SoATuple< TokenLookupInfo, bool, LabelPlacement, edm::KindOfType > m_tokenInfo
ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const
EDGetTokenT< TYPE > consumes()
const char * labelFor(ESTokenIndex) const
unsigned int ProductResolverIndex
Definition: APVGainStruct.h:7
virtual void doSelectInputProcessBlocks(ProductRegistry const &, ProcessBlockHelperBase const &)
eventsetup::EventSetupRecordKey m_record
void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
void throwESConsumesInProcessBlock() const
edm::InputTag const m_tag
void consumesMany(const TypeToGet &id)
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
void throwTypeMismatch(edm::TypeID const &, EDGetToken) const
void itemsToGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
LabelPlacement(unsigned int iStartOfModuleLabel, unsigned short iDeltaToProductInstance, unsigned short iDeltaToProcessName)
ESGetToken< TYPE, REC > consumes()
ESGetToken< TYPE, REC > consumes()
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
ESProxyIndex const * esGetTokenIndices(edm::Transition iTrans) const
void modulesWhoseProductsAreConsumed(std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
assert(be >=bs)
void selectInputProcessBlocks(ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
BranchType
Definition: BranchType.h:11
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
unsigned int recordConsumes(BranchType iBranch, TypeToGet const &iType, edm::InputTag const &iTag, bool iAlwaysGets)
void consumesMany(const TypeToGet &id)
std::array< std::vector< ESProxyIndex >, static_cast< unsigned int >edm::Transition::NumberOfEventSetupTransitions)> esItemsToGetFromTransition_
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
typename default_record< T >::RecordT default_record_t
ESGetTokenGeneric esConsumes(eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
Used with EventSetupRecord::doGet.
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
ProductResolverIndexAndSkipBit m_index
Transition
Definition: Transition.h:12
virtual void registerLateConsumes(eventsetup::ESRecordsToProxyIndices const &)
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
void throwESConsumesCallAfterFrozen(eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &) const
std::vector< ConsumesInfo > consumesInfo() const
std::array< std::vector< ESRecordIndex >, static_cast< unsigned int >edm::Transition::NumberOfEventSetupTransitions)> esRecordsToGetFromTransition_
constexpr auto esConsumes()
bool registeredToConsume(ProductResolverIndex, bool, BranchType) const
const TypeTag & type() const
Definition: DataKey.h:52
std::vector< char > m_tokenLabels
EDConsumerBase const & operator=(EDConsumerBase const &)=delete
ProductLabels Labels
EDGetToken consumes(TypeToGet const &id, edm::InputTag const &tag)
void throwBadToken(edm::TypeID const &iType, EDGetToken iToken) const
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector(edm::Transition iTrans) const
EDConsumerBaseAdaptor(EDConsumerBase *iBase, edm::InputTag iTag) noexcept
std::vector< ESProxyIndex > const & esGetTokenIndicesVector(edm::Transition iTrans) const
edm::SoATuple< ESTokenLookupInfo, ESProxyIndex > m_esTokenInfo
void itemsMayGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
bool registeredToConsumeMany(TypeID const &, BranchType) const
void throwConsumesCallAfterFrozen(TypeToGet const &, InputTag const &) const
HLT enums.
EDConsumerBase * m_consumer
static EventSetupRecordKey makeKey()
auto esConsumes(ESInputTag const &tag)
ESTokenIndex recordESConsumes(Transition, eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &iTag)
TokenLookupInfo(edm::TypeID const &iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
EDConsumerBaseESAdaptor(EDConsumerBase *iBase)
edm::InputTag const & checkIfEmpty(edm::InputTag const &tag)
virtual ~EDConsumerBase() noexcept(false)
void resetItemsToGetFrom(BranchType iType)
void convertCurrentProcessAlias(std::string const &processName)
Convert "@currentProcess" in InputTag process names to the actual current process name...
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
EDConsumerBaseAdaptor< B > consumes(edm::InputTag tag) noexcept
void throwBranchMismatch(BranchType, EDGetToken) const
const NameTag & name() const
Definition: DataKey.h:53
auto esConsumes(ESInputTag tag)
def move(src, dest)
Definition: eostools.py:511
std::array< std::vector< ProductResolverIndexAndSkipBit >, edm::NumBranchTypes > itemsToGetFromBranch_
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
EDConsumerBaseWithTagESAdaptor(EDConsumerBase *iBase, ESInputTag iTag) noexcept
const char * value() const
Definition: DataKeyTags.h:39
EDGetToken consumes(const TypeToGet &id, edm::InputTag const &tag)