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 
100  // ---------- static member functions --------------------
101 
102  // ---------- member functions ---------------------------
103  void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&, bool iPrefetchMayGet);
105  void selectInputProcessBlocks(ProductRegistry const& productRegistry,
106  ProcessBlockHelperBase const& processBlockHelperBase) {
107  doSelectInputProcessBlocks(productRegistry, processBlockHelperBase);
108  }
109 
111  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
112 
113  void modulesWhoseProductsAreConsumed(std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
114  std::vector<ModuleProcessName>& modulesInPreviousProcesses,
115  ProductRegistry const& preg,
116  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
117  std::string const& processName) const;
118 
121 
122  std::vector<ConsumesInfo> consumesInfo() const;
123 
126  auto const& v = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
127  if (v.empty()) {
128  return nullptr;
129  }
130  return &(esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].front());
131  }
132  return nullptr;
133  }
134 
135  std::vector<ESResolverIndex> const& esGetTokenIndicesVector(edm::Transition iTrans) const {
137  return esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
138  }
139 
140  std::vector<ESRecordIndex> const& esGetTokenRecordIndicesVector(edm::Transition iTrans) const {
142  return esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
143  }
144 
145  protected:
146  friend class ConsumesCollector;
147  template <Transition Tr>
149  template <Transition Tr>
151  template <BranchType B>
152  friend class EDConsumerBaseAdaptor;
153  template <typename T>
154  friend class WillGetIfMatch;
157 
158  template <typename ProductType, BranchType B = InEvent>
160  TypeToGet tid = TypeToGet::make<ProductType>();
162  }
163 
164  template <BranchType B = InEvent>
166  return EDConsumerBaseAdaptor<B>(this, std::move(tag));
167  }
168 
170  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
171  }
172 
173  template <BranchType B>
175  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
176  }
177 
178  template <typename ProductType, BranchType B = InEvent>
180  TypeToGet tid = TypeToGet::make<ProductType>();
182  }
183 
184  EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) { return mayConsume<InEvent>(id, tag); }
185 
186  template <BranchType B>
188  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), false)};
189  }
190 
191  // For consuming event-setup products
192  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
193  auto esConsumes() {
194  return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
195  }
196 
197  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
198  auto esConsumes(ESInputTag const& tag) {
199  auto index = recordESConsumes(Tr,
201  std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
203  ESRecord>>(),
204  eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
205  tag);
206  return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, labelFor(index)};
207  }
208 
209  template <Transition Tr = Transition::Event>
210  [[nodiscard]] constexpr auto esConsumes() {
211  return EDConsumerBaseESAdaptor<Tr>(this);
212  }
213 
214  template <Transition Tr = Transition::Event>
215  [[nodiscard]] auto esConsumes(ESInputTag tag) {
217  }
218 
220  template <Transition Tr = Transition::Event>
222  return ESGetTokenGeneric(static_cast<unsigned int>(Tr),
223  recordESConsumes(Tr, iRecord, iKey.type(), ESInputTag("", iKey.name().value())),
224  iRecord.type());
225  }
226 
227  //used for FinalPath
228  void resetItemsToGetFrom(BranchType iType) { itemsToGetFromBranch_[iType].clear(); }
229 
230  private:
231  virtual void extendUpdateLookup(BranchType iBranchType, ProductResolverIndexHelper const&);
233  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
237  edm::ESInputTag const& iTag);
238 
239  const char* labelFor(ESTokenIndex) const;
240 
241  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
243  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
244  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
247  edm::ESInputTag const&) const;
248  void throwESConsumesInProcessBlock() const;
249 
251 
253 
254  // ---------- member data --------------------------------
255 
257  TokenLookupInfo(edm::TypeID const& iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
258  : m_type(iID), m_index(iIndex, skipCurrentProcess), m_branchType(iBranch) {}
262  };
263 
264  struct LabelPlacement {
265  LabelPlacement(unsigned int iStartOfModuleLabel,
266  unsigned short iDeltaToProductInstance,
267  unsigned short iDeltaToProcessName)
268  : m_startOfModuleLabel(iStartOfModuleLabel),
269  m_deltaToProductInstance(iDeltaToProductInstance),
270  m_deltaToProcessName(iDeltaToProcessName) {}
271  unsigned int m_startOfModuleLabel;
272  unsigned short m_deltaToProductInstance;
273  unsigned short m_deltaToProcessName;
274  };
275 
276  //define the purpose of each 'column' in m_tokenInfo
279 
280  //m_tokenStartOfLabels holds the entries into this container
281  // for each of the 3 labels needed to id the data
282  std::vector<char> m_tokenLabels;
283 
284  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
285 
290  };
291 
292  // TODO We would like to be able to access m_esTokenInfo from the
293  // index in the token, but this is currently not possible. One idea
294  // for this is to order the entries in m_esToken so that all the ones
295  // for transition 0 come first, then the ones for for transition 1
296  // and so on for all the transitions. Within a transition, the
297  // entries would be in the same order in m_esTokenInfo and
298  // esItemsToGetFromTransition_. This is something for future
299  // development and might require a change to SoATuple to support
300  // inserts in the middle of the data structure.
303  std::array<std::vector<ESResolverIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
305  std::array<std::vector<ESRecordIndex>, static_cast<unsigned int>(edm::Transition::NumberOfEventSetupTransitions)>
307  bool frozen_;
309  };
310 
311  template <Transition TR>
313  public:
314  template <typename TYPE, typename REC>
316  return m_consumer->template esConsumes<TYPE, REC, TR>();
317  }
318 
319  private:
320  //only EDConsumerBase is allowed to make an instance of this class
321  friend class EDConsumerBase;
323 
325  };
326 
327  template <Transition TR>
329  public:
330  template <typename TYPE, typename REC>
332  return m_consumer->template esConsumes<TYPE, REC, TR>(m_tag);
333  }
334 
335  private:
336  //only EDConsumerBase is allowed to make an instance of this class
337  friend class EDConsumerBase;
339  : m_consumer(iBase), m_tag(std::move(iTag)) {}
340 
343  };
344 
345  template <BranchType B>
346  class EDConsumerBaseAdaptor {
347  public:
348  template <typename TYPE>
350  return m_consumer->template consumes<TYPE, B>(m_tag);
351  }
352 
353  private:
354  //only EDConsumerBase is allowed to make an instance of this class
355  friend class EDConsumerBase;
357  : m_consumer(iBase), m_tag(std::move(iTag)) {}
358 
361  };
362 
363 } // namespace edm
364 
365 #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
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
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)
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)
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)