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 // user include files
38 
39 
40 // forward declarations
41 
42 namespace edm {
43  class ModuleDescription;
44  class ProductResolverIndexHelper;
45  class ProductRegistry;
46  class ConsumesCollector;
47  template<typename T> class WillGetIfMatch;
48 
50  {
51 
52  public:
54  virtual ~EDConsumerBase() noexcept(false);
55 
56  // disallow copying
57  EDConsumerBase(EDConsumerBase const&) = delete;
58  EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
59 
60  // allow moving
61  EDConsumerBase(EDConsumerBase&&) = default;
63 
64  // ---------- const member functions ---------------------
67 
68  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
69  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
70 
71  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const { return itemsToGetFromBranch_[iType]; }
72 
75 
77  bool registeredToConsumeMany(TypeID const&, BranchType) const;
78  // ---------- static member functions --------------------
79 
80  // ---------- member functions ---------------------------
81  void updateLookup(BranchType iBranchType,
83  bool iPrefetchMayGet);
84 
86  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
87 
88  void modulesWhoseProductsAreConsumed(std::vector<ModuleDescription const*>& modules,
89  ProductRegistry const& preg,
90  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
91  std::string const& processName) const;
92 
95 
96  std::vector<ConsumesInfo> consumesInfo() const;
97 
98  protected:
99  friend class ConsumesCollector;
100  template<typename T> friend class WillGetIfMatch;
103 
104  template <typename ProductType, BranchType B=InEvent>
106  TypeToGet tid=TypeToGet::make<ProductType>();
107  return EDGetTokenT<ProductType>{recordConsumes(B,tid, checkIfEmpty(tag),true)};
108  }
109 
111  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
112  }
113 
114  template <BranchType B>
116  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
117  }
118 
119  template <typename ProductType, BranchType B=InEvent>
121  TypeToGet tid=TypeToGet::make<ProductType>();
122  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
123  }
124 
126  return mayConsume<InEvent>(id,tag);
127  }
128 
129  template <BranchType B>
131  return EDGetToken{recordConsumes(B,id,checkIfEmpty(tag),false)};
132  }
133 
134  template <typename ProductType, BranchType B=InEvent>
135  void consumesMany() {
136  TypeToGet tid=TypeToGet::make<ProductType>();
137  consumesMany<B>(tid);
138  }
139 
140  void consumesMany(const TypeToGet& id) {
141  consumesMany<InEvent>(id);
142  }
143 
144  template <BranchType B>
145  void consumesMany(const TypeToGet& id) {
146  recordConsumes(B,id,edm::InputTag{},true);
147  }
148 
149  private:
150  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
151 
152  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
154  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
155  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
156 
158  // ---------- member data --------------------------------
159 
162  ProductResolverIndex iIndex,
163  bool skipCurrentProcess,
164  BranchType iBranch):
165  m_type(iID),m_index(iIndex, skipCurrentProcess), m_branchType(iBranch){}
169  };
170 
171  struct LabelPlacement {
172  LabelPlacement(unsigned int iStartOfModuleLabel,
173  unsigned short iDeltaToProductInstance,
174  unsigned short iDeltaToProcessName):
175  m_startOfModuleLabel(iStartOfModuleLabel),
176  m_deltaToProductInstance(iDeltaToProductInstance),
177  m_deltaToProcessName(iDeltaToProcessName) {}
178  unsigned int m_startOfModuleLabel;
179  unsigned short m_deltaToProductInstance;
180  unsigned short m_deltaToProcessName;
181  };
182 
183  //define the purpose of each 'column' in m_tokenInfo
186 
187  //m_tokenStartOfLabels holds the entries into this container
188  // for each of the 3 labels needed to id the data
189  std::vector<char> m_tokenLabels;
190 
191  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
192 
193  bool frozen_;
195  };
196 }
197 
198 #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)
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.
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)