CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 <map>
23 #include <string>
24 #include <vector>
25 #include <array>
26 #include <cassert>
27 
28 // user include files
51 
52 // forward declarations
53 
54 namespace edm {
55  class ModuleProcessName;
56  class ProductResolverIndexHelper;
57  class ConsumesCollector;
58  template <Transition Tr>
60  template <Transition Tr>
62  template <BranchType B>
64  template <typename T>
66 
67  namespace eventsetup {
69  }
70 
72  public:
74  virtual ~EDConsumerBase() noexcept(false);
75 
76  // disallow copying
77  EDConsumerBase(EDConsumerBase const&) = delete;
78  EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
79 
80  // allow moving
81  EDConsumerBase(EDConsumerBase&&) = default;
83 
84  // ---------- const member functions ---------------------
87 
88  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
89  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
90 
91  //used for prefetching
92  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const {
93  return itemsToGetFromBranch_[iType];
94  }
95 
98 
100  bool registeredToConsumeMany(TypeID const&, BranchType) const;
101  // ---------- static member functions --------------------
102 
103  // ---------- member functions ---------------------------
104  void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&, bool iPrefetchMayGet);
106  void selectInputProcessBlocks(ProductRegistry const& productRegistry,
107  ProcessBlockHelperBase const& processBlockHelperBase) {
108  doSelectInputProcessBlocks(productRegistry, processBlockHelperBase);
109  }
110 
112  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
113 
114  void modulesWhoseProductsAreConsumed(std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
115  std::vector<ModuleProcessName>& modulesInPreviousProcesses,
116  ProductRegistry const& preg,
117  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
118  std::string const& processName) const;
119 
122 
123  std::vector<ConsumesInfo> consumesInfo() const;
124 
127  auto const& v = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
128  if (v.empty()) {
129  return nullptr;
130  }
131  return &(esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].front());
132  }
133  return nullptr;
134  }
135 
136  std::vector<ESProxyIndex> const& esGetTokenIndicesVector(edm::Transition iTrans) const {
138  return esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
139  }
140 
141  std::vector<ESRecordIndex> const& esGetTokenRecordIndicesVector(edm::Transition iTrans) const {
143  return esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
144  }
145 
146  protected:
147  friend class ConsumesCollector;
148  template <Transition Tr>
150  template <Transition Tr>
152  template <BranchType B>
153  friend class EDConsumerBaseAdaptor;
154  template <typename T>
155  friend class WillGetIfMatch;
158 
159  template <typename ProductType, BranchType B = InEvent>
161  TypeToGet tid = TypeToGet::make<ProductType>();
162  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), true)};
163  }
164 
165  template <BranchType B = InEvent>
167  return EDConsumerBaseAdaptor<B>(this, std::move(tag));
168  }
169 
171  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
172  }
173 
174  template <BranchType B>
176  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
177  }
178 
179  template <typename ProductType, BranchType B = InEvent>
181  TypeToGet tid = TypeToGet::make<ProductType>();
182  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
183  }
184 
185  EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) { return mayConsume<InEvent>(id, tag); }
186 
187  template <BranchType B>
189  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), false)};
190  }
191 
192  template <typename ProductType, BranchType B = InEvent>
193  void consumesMany() {
194  TypeToGet tid = TypeToGet::make<ProductType>();
195  consumesMany<B>(tid);
196  }
197 
198  void consumesMany(const TypeToGet& id) { consumesMany<InEvent>(id); }
199 
200  template <BranchType B>
201  void consumesMany(const TypeToGet& id) {
202  recordConsumes(B, id, edm::InputTag{}, true);
203  }
204 
205  // For consuming event-setup products
206  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
207  auto esConsumes() {
208  return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
209  }
210 
211  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
212  auto esConsumes(ESInputTag const& tag) {
213  auto index = recordESConsumes(Tr,
215  std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
217  ESRecord>>(),
218  eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
219  tag);
220  return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, labelFor(index)};
221  }
222 
223  template <Transition Tr = Transition::Event>
224  [[nodiscard]] constexpr auto esConsumes() noexcept {
225  return EDConsumerBaseESAdaptor<Tr>(this);
226  }
227 
228  template <Transition Tr = Transition::Event>
229  [[nodiscard]] auto esConsumes(ESInputTag tag) noexcept {
231  }
232 
234  template <Transition Tr = Transition::Event>
236  return ESGetTokenGeneric(static_cast<unsigned int>(Tr),
237  recordESConsumes(Tr, iRecord, iKey.type(), ESInputTag("", iKey.name().value())),
238  iRecord.type());
239  }
240 
241  //used for FinalPath
242  void resetItemsToGetFrom(BranchType iType) { itemsToGetFromBranch_[iType].clear(); }
243 
244  private:
246  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
250  edm::ESInputTag const& iTag);
251 
252  const char* labelFor(ESTokenIndex) const;
253 
254  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
256  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
257  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
260  edm::ESInputTag const&) const;
261  void throwESConsumesInProcessBlock() const;
262 
264 
266 
267  // ---------- member data --------------------------------
268 
270  TokenLookupInfo(edm::TypeID const& iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
271  : m_type(iID), m_index(iIndex, skipCurrentProcess), m_branchType(iBranch) {}
275  };
276 
277  struct LabelPlacement {
278  LabelPlacement(unsigned int iStartOfModuleLabel,
279  unsigned short iDeltaToProductInstance,
280  unsigned short iDeltaToProcessName)
281  : m_startOfModuleLabel(iStartOfModuleLabel),
282  m_deltaToProductInstance(iDeltaToProductInstance),
283  m_deltaToProcessName(iDeltaToProcessName) {}
284  unsigned int m_startOfModuleLabel;
285  unsigned short m_deltaToProductInstance;
286  unsigned short m_deltaToProcessName;
287  };
288 
289  //define the purpose of each 'column' in m_tokenInfo
292 
293  //m_tokenStartOfLabels holds the entries into this container
294  // for each of the 3 labels needed to id the data
295  std::vector<char> m_tokenLabels;
296 
297  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
298 
303  };
304 
305  // TODO We would like to be able to access m_esTokenInfo from the
306  // index in the token, but this is currently not possible. One idea
307  // for this is to order the entries in m_esToken so that all the ones
308  // for transition 0 come first, then the ones for for transition 1
309  // and so on for all the transitions. Within a transition, the
310  // entries would be in the same order in m_esTokenInfo and
311  // esItemsToGetFromTransition_. This is something for future
312  // development and might require a change to SoATuple to support
313  // inserts in the middle of the data structure.
316  std::array<std::vector<ESProxyIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
318  std::array<std::vector<ESRecordIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
320  bool frozen_;
322  };
323 
324  template <Transition TR>
326  public:
327  template <typename TYPE, typename REC>
329  return m_consumer->template esConsumes<TYPE, REC, TR>();
330  }
331 
332  private:
333  //only EDConsumerBase is allowed to make an instance of this class
334  friend class EDConsumerBase;
336 
338  };
339 
340  template <Transition TR>
342  public:
343  template <typename TYPE, typename REC>
345  return m_consumer->template esConsumes<TYPE, REC, TR>(m_tag);
346  }
347 
348  private:
349  //only EDConsumerBase is allowed to make an instance of this class
350  friend class EDConsumerBase;
352  : m_consumer(iBase), m_tag(std::move(iTag)) {}
353 
356  };
357 
358  template <BranchType B>
359  class EDConsumerBaseAdaptor {
360  public:
361  template <typename TYPE>
363  return m_consumer->template consumes<TYPE, B>(m_tag);
364  }
365 
366  private:
367  //only EDConsumerBase is allowed to make an instance of this class
368  friend class EDConsumerBase;
370  : m_consumer(iBase), m_tag(std::move(iTag)) {}
371 
374  };
375 
376 } // namespace edm
377 
378 #endif
edm::SoATuple< TokenLookupInfo, bool, LabelPlacement, edm::KindOfType > m_tokenInfo
void throwESConsumesCallAfterFrozen(eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &) const
EDGetTokenT< TYPE > consumes()
tuple array
Definition: mps_check.py:216
std::vector< ConsumesInfo > consumesInfo() const
unsigned int ProductResolverIndex
uint16_t *__restrict__ id
virtual void doSelectInputProcessBlocks(ProductRegistry const &, ProcessBlockHelperBase const &)
eventsetup::EventSetupRecordKey m_record
void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
edm::InputTag const m_tag
void consumesMany(const TypeToGet &id)
void throwTypeMismatch(edm::TypeID const &, EDGetToken) const
LabelPlacement(unsigned int iStartOfModuleLabel, unsigned short iDeltaToProductInstance, unsigned short iDeltaToProcessName)
void throwBadToken(edm::TypeID const &iType, EDGetToken iToken) const
constexpr auto esConsumes() noexcept
std::vector< ESProxyIndex > const & esGetTokenIndicesVector(edm::Transition iTrans) const
void throwConsumesCallAfterFrozen(TypeToGet const &, InputTag const &) const
EDConsumerBaseESAdaptor(EDConsumerBase *iBase)
ESGetToken< TYPE, REC > consumes()
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_
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
const char * labelFor(ESTokenIndex) const
EDConsumerBaseWithTagESAdaptor(EDConsumerBase *iBase, ESInputTag iTag) noexcept
auto esConsumes(ESInputTag tag) noexcept
typename default_record< T >::RecordT default_record_t
ESGetTokenGeneric esConsumes(eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
Used with EventSetupRecord::doGet.
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
bool registeredToConsume(ProductResolverIndex, bool, BranchType) 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
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void itemsToGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
ProductResolverIndexAndSkipBit m_index
def move
Definition: eostools.py:511
ESGetToken< TYPE, REC > consumes()
Transition
Definition: Transition.h:12
void throwBranchMismatch(BranchType, EDGetToken) const
virtual void registerLateConsumes(eventsetup::ESRecordsToProxyIndices const &)
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
static const std::string B
std::array< std::vector< ESRecordIndex >, static_cast< unsigned int >edm::Transition::NumberOfEventSetupTransitions)> esRecordsToGetFromTransition_
void throwESConsumesInProcessBlock() const
std::vector< char > m_tokenLabels
edm::InputTag const & checkIfEmpty(edm::InputTag const &tag)
EDConsumerBase const & operator=(EDConsumerBase const &)=delete
ProductLabels Labels
EDGetToken consumes(TypeToGet const &id, edm::InputTag const &tag)
bool registeredToConsumeMany(TypeID const &, BranchType) const
void itemsMayGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
EDConsumerBaseAdaptor(EDConsumerBase *iBase, edm::InputTag iTag) noexcept
const TypeTag & type() const
Definition: DataKey.h:52
edm::SoATuple< ESTokenLookupInfo, ESProxyIndex > m_esTokenInfo
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector(edm::Transition iTrans) const
EDConsumerBase * m_consumer
const NameTag & name() const
Definition: DataKey.h:53
static EventSetupRecordKey makeKey()
auto esConsumes(ESInputTag const &tag)
ESTokenIndex recordESConsumes(Transition, eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &iTag)
const char * value() const
Definition: DataKeyTags.h:39
TokenLookupInfo(edm::TypeID const &iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
virtual ~EDConsumerBase() noexcept(false)
void resetItemsToGetFrom(BranchType iType)
preg
Definition: Schedule.cc:687
void convertCurrentProcessAlias(std::string const &processName)
Convert &quot;@currentProcess&quot; in InputTag process names to the actual current process name...
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
EDConsumerBaseAdaptor< B > consumes(edm::InputTag tag) noexcept
std::array< std::vector< ProductResolverIndexAndSkipBit >, edm::NumBranchTypes > itemsToGetFromBranch_
ESProxyIndex const * esGetTokenIndices(edm::Transition iTrans) const
EDGetToken consumes(const TypeToGet &id, edm::InputTag const &tag)