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 #include <tuple>
29 
30 // user include files
53 
54 // forward declarations
55 
56 namespace edm {
57  class ModuleProcessName;
58  class ProductResolverIndexHelper;
59  class ConsumesCollector;
60  template <Transition Tr>
62  template <Transition Tr>
64  template <BranchType B>
66  template <typename T>
68 
69  namespace eventsetup {
71  }
72 
74  public:
76  virtual ~EDConsumerBase() noexcept(false);
77 
78  // disallow copying
79  EDConsumerBase(EDConsumerBase const&) = delete;
80  EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
81 
82  // allow moving
83  EDConsumerBase(EDConsumerBase&&) = default;
85 
86  // ---------- const member functions ---------------------
89 
90  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
91  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
92 
93  //used for prefetching
94  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const {
95  return itemsToGetFromBranch_[iType];
96  }
97 
100 
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<ESResolverIndex> 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>();
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>();
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  // For consuming event-setup products
193  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
194  auto esConsumes() {
195  return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
196  }
197 
198  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
199  auto esConsumes(ESInputTag const& tag) {
200  auto [index, productLabel] =
201  recordESConsumes(Tr,
203  std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
205  ESRecord>>(),
206  eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
207  tag);
208  return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, productLabel};
209  }
210 
211  template <Transition Tr = Transition::Event>
212  [[nodiscard]] constexpr auto esConsumes() {
213  return EDConsumerBaseESAdaptor<Tr>(this);
214  }
215 
216  template <Transition Tr = Transition::Event>
217  [[nodiscard]] auto esConsumes(ESInputTag tag) {
219  }
220 
222  template <Transition Tr = Transition::Event>
224  auto [index, productLabel] = recordESConsumes(Tr, iRecord, iKey.type(), ESInputTag("", iKey.name().value()));
225  return ESGetTokenGeneric(static_cast<unsigned int>(Tr), index, iRecord.type());
226  }
227 
228  //used for FinalPath
229  void resetItemsToGetFrom(BranchType iType) { itemsToGetFromBranch_[iType].clear(); }
230 
231  private:
232  virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const&);
234  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
235  std::tuple<ESTokenIndex, char const*> recordESConsumes(Transition,
238  edm::ESInputTag const& iTag);
239 
240  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
242  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
243  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
246  edm::ESInputTag const&) const;
247  void throwESConsumesInProcessBlock() const;
248 
250 
252 
253  // ---------- member data --------------------------------
254 
256  TokenLookupInfo(edm::TypeID const& iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
257  : m_type(iID), m_index(iIndex, skipCurrentProcess), m_branchType(iBranch) {}
261  };
262 
263  struct LabelPlacement {
264  LabelPlacement(unsigned int iStartOfModuleLabel,
265  unsigned short iDeltaToProductInstance,
266  unsigned short iDeltaToProcessName)
267  : m_startOfModuleLabel(iStartOfModuleLabel),
268  m_deltaToProductInstance(iDeltaToProductInstance),
269  m_deltaToProcessName(iDeltaToProcessName) {}
270  unsigned int m_startOfModuleLabel;
271  unsigned short m_deltaToProductInstance;
272  unsigned short m_deltaToProcessName;
273  };
274 
275  //define the purpose of each 'column' in m_tokenInfo
278 
279  //m_tokenStartOfLabels holds the entries into this container
280  // for each of the 3 labels needed to id the data
281  std::vector<char> m_tokenLabels;
282 
283  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
284 
289  };
290 
291  // TODO We would like to be able to access m_esTokenInfo from the
292  // index in the token, but this is currently not possible. One idea
293  // for this is to order the entries in m_esToken so that all the ones
294  // for transition 0 come first, then the ones for for transition 1
295  // and so on for all the transitions. Within a transition, the
296  // entries would be in the same order in m_esTokenInfo and
297  // esItemsToGetFromTransition_. This is something for future
298  // development and might require a change to SoATuple to support
299  // inserts in the middle of the data structure.
302  std::array<std::vector<ESResolverIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
304  std::array<std::vector<ESRecordIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
306  bool frozen_;
308  };
309 
310  template <Transition TR>
312  public:
313  template <typename TYPE, typename REC>
315  return m_consumer->template esConsumes<TYPE, REC, TR>();
316  }
317 
318  private:
319  //only EDConsumerBase is allowed to make an instance of this class
320  friend class EDConsumerBase;
322 
324  };
325 
326  template <Transition TR>
328  public:
329  template <typename TYPE, typename REC>
331  return m_consumer->template esConsumes<TYPE, REC, TR>(m_tag);
332  }
333 
334  private:
335  //only EDConsumerBase is allowed to make an instance of this class
336  friend class EDConsumerBase;
338  : m_consumer(iBase), m_tag(std::move(iTag)) {}
339 
342  };
343 
344  template <BranchType B>
345  class EDConsumerBaseAdaptor {
346  public:
347  template <typename TYPE>
349  return m_consumer->template consumes<TYPE, B>(m_tag);
350  }
351 
352  private:
353  //only EDConsumerBase is allowed to make an instance of this class
354  friend class EDConsumerBase;
356  : m_consumer(iBase), m_tag(std::move(iTag)) {}
357 
360  };
361 
362 } // namespace edm
363 
364 #endif
edm::SoATuple< TokenLookupInfo, bool, LabelPlacement, edm::KindOfType > m_tokenInfo
ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const
EDGetTokenT< TYPE > consumes()
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
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
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)
std::vector< ESResolverIndex > const & esGetTokenIndicesVector(edm::Transition iTrans) const
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.
ESResolverIndex const * esGetTokenIndices(edm::Transition iTrans) const
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
ProductResolverIndexAndSkipBit m_index
Transition
Definition: Transition.h:12
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< ESResolverIndex >, static_cast< unsigned int >edm::Transition::NumberOfEventSetupTransitions)> esItemsToGetFromTransition_
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::tuple< ESTokenIndex, char const * > recordESConsumes(Transition, eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &iTag)
void itemsMayGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
void throwConsumesCallAfterFrozen(TypeToGet const &, InputTag const &) const
HLT enums.
EDConsumerBase * m_consumer
static EventSetupRecordKey makeKey()
auto esConsumes(ESInputTag const &tag)
TokenLookupInfo(edm::TypeID const &iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
virtual void registerLateConsumes(eventsetup::ESRecordsToProductResolverIndices const &)
EDConsumerBaseESAdaptor(EDConsumerBase *iBase)
edm::InputTag const & checkIfEmpty(edm::InputTag const &tag)
virtual ~EDConsumerBase() noexcept(false)
void resetItemsToGetFrom(BranchType iType)
edm::SoATuple< ESTokenLookupInfo, ESResolverIndex > m_esTokenInfo
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)