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 <map>
23 #include <string>
24 #include <vector>
25 #include <array>
26 
27 // user include files
43 
44 
45 // forward declarations
46 
47 namespace edm {
48  class ModuleDescription;
49  class ProductResolverIndexHelper;
50  class ProductRegistry;
51  class ConsumesCollector;
52  template<typename T> class WillGetIfMatch;
53 
55  {
56 
57  public:
59  virtual ~EDConsumerBase() noexcept(false);
60 
61  // disallow copying
62  EDConsumerBase(EDConsumerBase const&) = delete;
63  EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
64 
65  // allow moving
66  EDConsumerBase(EDConsumerBase&&) = default;
68 
69  // ---------- const member functions ---------------------
72 
73  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
74  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
75 
76  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const { return itemsToGetFromBranch_[iType]; }
77 
80 
82  bool registeredToConsumeMany(TypeID const&, BranchType) const;
83  // ---------- static member functions --------------------
84 
85  // ---------- member functions ---------------------------
86  void updateLookup(BranchType iBranchType,
88  bool iPrefetchMayGet);
89 
91  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
92 
93  void modulesWhoseProductsAreConsumed(std::vector<ModuleDescription const*>& modules,
94  ProductRegistry const& preg,
95  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
96  std::string const& processName) const;
97 
100 
101  std::vector<ConsumesInfo> consumesInfo() const;
102 
103  protected:
104  friend class ConsumesCollector;
105  template<typename T> friend class WillGetIfMatch;
108 
109  template <typename ProductType, BranchType B=InEvent>
111  TypeToGet tid=TypeToGet::make<ProductType>();
112  return EDGetTokenT<ProductType>{recordConsumes(B,tid, checkIfEmpty(tag),true)};
113  }
114 
116  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
117  }
118 
119  template <BranchType B>
121  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
122  }
123 
124  template <typename ProductType, BranchType B=InEvent>
126  TypeToGet tid=TypeToGet::make<ProductType>();
127  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
128  }
129 
131  return mayConsume<InEvent>(id,tag);
132  }
133 
134  template <BranchType B>
136  return EDGetToken{recordConsumes(B,id,checkIfEmpty(tag),false)};
137  }
138 
139  template <typename ProductType, BranchType B=InEvent>
140  void consumesMany() {
141  TypeToGet tid=TypeToGet::make<ProductType>();
142  consumesMany<B>(tid);
143  }
144 
145  void consumesMany(const TypeToGet& id) {
146  consumesMany<InEvent>(id);
147  }
148 
149  template <BranchType B>
150  void consumesMany(const TypeToGet& id) {
151  recordConsumes(B,id,edm::InputTag{},true);
152  }
153 
154  // For consuming event-setup products
155  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
156  auto esConsumes()
157  {
158  return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
159  }
160 
161  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
162  auto esConsumes(ESInputTag const& tag)
163  {
164  return ESGetTokenT<ESProduct>{tag};
165  }
166 
167  template <typename ESProduct, Transition Tr = Transition::Event>
169  {
170  return ESGetTokenT<ESProduct>{tag};
171  }
172 
173  private:
174  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
175 
176  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
178  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
179  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
180 
182  // ---------- member data --------------------------------
183 
186  ProductResolverIndex iIndex,
187  bool skipCurrentProcess,
188  BranchType iBranch):
189  m_type(iID),m_index(iIndex, skipCurrentProcess), m_branchType(iBranch){}
193  };
194 
195  struct LabelPlacement {
196  LabelPlacement(unsigned int iStartOfModuleLabel,
197  unsigned short iDeltaToProductInstance,
198  unsigned short iDeltaToProcessName):
199  m_startOfModuleLabel(iStartOfModuleLabel),
200  m_deltaToProductInstance(iDeltaToProductInstance),
201  m_deltaToProcessName(iDeltaToProcessName) {}
202  unsigned int m_startOfModuleLabel;
203  unsigned short m_deltaToProductInstance;
204  unsigned short m_deltaToProcessName;
205  };
206 
207  //define the purpose of each 'column' in m_tokenInfo
210 
211  //m_tokenStartOfLabels holds the entries into this container
212  // for each of the 3 labels needed to id the data
213  std::vector<char> m_tokenLabels;
214 
215  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
216 
217  bool frozen_;
219  };
220 }
221 
222 #endif
std::vector< ConsumesInfo > consumesInfo() const
unsigned int ProductResolverIndex
void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
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
#define noexcept
void throwConsumesCallAfterFrozen(TypeToGet const &, InputTag const &) const
edm::SoATuple< TokenLookupInfo, bool, LabelPlacement, edm::KindOfType > m_tokenInfo
void modulesWhoseProductsAreConsumed(std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
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::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
auto esConsumes(eventsetup::EventSetupRecordKey const &, ESInputTag const &tag)
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
bool registeredToConsume(ProductResolverIndex, bool, BranchType) const
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void itemsToGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
ProductResolverIndexAndSkipBit m_index
void throwBranchMismatch(BranchType, EDGetToken) const
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
static const std::string B
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
void labelsForToken(EDGetToken iToken, Labels &oLabels) const
HLT enums.
auto esConsumes(ESInputTag const &tag)
TokenLookupInfo(edm::TypeID const &iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
virtual ~EDConsumerBase() noexcept(false)
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)
std::array< std::vector< ProductResolverIndexAndSkipBit >, edm::NumBranchTypes > itemsToGetFromBranch_
EDGetToken consumes(const TypeToGet &id, edm::InputTag const &tag)