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:
246  virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const&);
248  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
252  edm::ESInputTag const& iTag);
253 
254  const char* labelFor(ESTokenIndex) const;
255 
256  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
258  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
259  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
262  edm::ESInputTag const&) const;
263  void throwESConsumesInProcessBlock() const;
264 
266 
268 
269  // ---------- member data --------------------------------
270 
272  TokenLookupInfo(edm::TypeID const& iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
273  : m_type(iID), m_index(iIndex, skipCurrentProcess), m_branchType(iBranch) {}
277  };
278 
279  struct LabelPlacement {
280  LabelPlacement(unsigned int iStartOfModuleLabel,
281  unsigned short iDeltaToProductInstance,
282  unsigned short iDeltaToProcessName)
283  : m_startOfModuleLabel(iStartOfModuleLabel),
284  m_deltaToProductInstance(iDeltaToProductInstance),
285  m_deltaToProcessName(iDeltaToProcessName) {}
286  unsigned int m_startOfModuleLabel;
287  unsigned short m_deltaToProductInstance;
288  unsigned short m_deltaToProcessName;
289  };
290 
291  //define the purpose of each 'column' in m_tokenInfo
294 
295  //m_tokenStartOfLabels holds the entries into this container
296  // for each of the 3 labels needed to id the data
297  std::vector<char> m_tokenLabels;
298 
299  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
300 
305  };
306 
307  // TODO We would like to be able to access m_esTokenInfo from the
308  // index in the token, but this is currently not possible. One idea
309  // for this is to order the entries in m_esToken so that all the ones
310  // for transition 0 come first, then the ones for for transition 1
311  // and so on for all the transitions. Within a transition, the
312  // entries would be in the same order in m_esTokenInfo and
313  // esItemsToGetFromTransition_. This is something for future
314  // development and might require a change to SoATuple to support
315  // inserts in the middle of the data structure.
318  std::array<std::vector<ESProxyIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
320  std::array<std::vector<ESRecordIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
322  bool frozen_;
324  };
325 
326  template <Transition TR>
328  public:
329  template <typename TYPE, typename REC>
331  return m_consumer->template esConsumes<TYPE, REC, TR>();
332  }
333 
334  private:
335  //only EDConsumerBase is allowed to make an instance of this class
336  friend class EDConsumerBase;
338 
340  };
341 
342  template <Transition TR>
344  public:
345  template <typename TYPE, typename REC>
347  return m_consumer->template esConsumes<TYPE, REC, TR>(m_tag);
348  }
349 
350  private:
351  //only EDConsumerBase is allowed to make an instance of this class
352  friend class EDConsumerBase;
354  : m_consumer(iBase), m_tag(std::move(iTag)) {}
355 
358  };
359 
360  template <BranchType B>
361  class EDConsumerBaseAdaptor {
362  public:
363  template <typename TYPE>
365  return m_consumer->template consumes<TYPE, B>(m_tag);
366  }
367 
368  private:
369  //only EDConsumerBase is allowed to make an instance of this class
370  friend class EDConsumerBase;
372  : m_consumer(iBase), m_tag(std::move(iTag)) {}
373 
376  };
377 
378 } // namespace edm
379 
380 #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 &)
virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper 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)