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 ---------------------
66 
67  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
68  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
69 
70  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const { return itemsToGetFromBranch_[iType]; }
71 
74 
76  bool registeredToConsumeMany(TypeID const&, BranchType) const;
77  // ---------- static member functions --------------------
78 
79  // ---------- member functions ---------------------------
80  void updateLookup(BranchType iBranchType,
82  bool iPrefetchMayGet);
83 
85  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
86 
87  void modulesWhoseProductsAreConsumed(std::vector<ModuleDescription const*>& modules,
88  ProductRegistry const& preg,
89  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
90  std::string const& processName) const;
91 
94 
95  std::vector<ConsumesInfo> consumesInfo() const;
96 
97  protected:
98  friend class ConsumesCollector;
99  template<typename T> friend class WillGetIfMatch;
102 
103  template <typename ProductType, BranchType B=InEvent>
105  TypeToGet tid=TypeToGet::make<ProductType>();
106  return EDGetTokenT<ProductType>{recordConsumes(B,tid, checkIfEmpty(tag),true)};
107  }
108 
110  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
111  }
112 
113  template <BranchType B>
115  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
116  }
117 
118  template <typename ProductType, BranchType B=InEvent>
120  TypeToGet tid=TypeToGet::make<ProductType>();
121  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
122  }
123 
125  return mayConsume<InEvent>(id,tag);
126  }
127 
128  template <BranchType B>
130  return EDGetToken{recordConsumes(B,id,checkIfEmpty(tag),false)};
131  }
132 
133  template <typename ProductType, BranchType B=InEvent>
134  void consumesMany() {
135  TypeToGet tid=TypeToGet::make<ProductType>();
136  consumesMany<B>(tid);
137  }
138 
139  void consumesMany(const TypeToGet& id) {
140  consumesMany<InEvent>(id);
141  }
142 
143  template <BranchType B>
144  void consumesMany(const TypeToGet& id) {
145  recordConsumes(B,id,edm::InputTag{},true);
146  }
147 
148  private:
149  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
150 
151  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
153  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
154  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
155 
157  // ---------- member data --------------------------------
158 
161  ProductResolverIndex iIndex,
162  bool skipCurrentProcess,
163  BranchType iBranch):
164  m_type(iID),m_index(iIndex, skipCurrentProcess), m_branchType(iBranch){}
168  };
169 
170  struct LabelPlacement {
171  LabelPlacement(unsigned int iStartOfModuleLabel,
172  unsigned short iDeltaToProductInstance,
173  unsigned short iDeltaToProcessName):
174  m_startOfModuleLabel(iStartOfModuleLabel),
175  m_deltaToProductInstance(iDeltaToProductInstance),
176  m_deltaToProcessName(iDeltaToProcessName) {}
177  unsigned int m_startOfModuleLabel;
178  unsigned short m_deltaToProductInstance;
179  unsigned short m_deltaToProcessName;
180  };
181 
182  //define the purpose of each 'column' in m_tokenInfo
185 
186  //m_tokenStartOfLabels holds the entries into this container
187  // for each of the 3 labels needed to id the data
188  std::vector<char> m_tokenLabels;
189 
190  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
191 
192  bool frozen_;
194  };
195 }
196 
197 #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
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)