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 
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& itemsToGetFromEvent() const { return itemsToGetFromEvent_; }
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 
92  std::vector<ConsumesInfo> consumesInfo() const;
93 
94  protected:
95  friend class ConsumesCollector;
96  template<typename T> friend class WillGetIfMatch;
99 
100  template <typename ProductType, BranchType B=InEvent>
102  TypeToGet tid=TypeToGet::make<ProductType>();
103  return EDGetTokenT<ProductType>{recordConsumes(B,tid, checkIfEmpty(tag),true)};
104  }
105 
107  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
108  }
109 
110  template <BranchType B>
112  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
113  }
114 
115  template <typename ProductType, BranchType B=InEvent>
117  TypeToGet tid=TypeToGet::make<ProductType>();
118  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
119  }
120 
122  return mayConsume<InEvent>(id,tag);
123  }
124 
125  template <BranchType B>
127  return EDGetToken{recordConsumes(B,id,checkIfEmpty(tag),false)};
128  }
129 
130  template <typename ProductType, BranchType B=InEvent>
131  void consumesMany() {
132  TypeToGet tid=TypeToGet::make<ProductType>();
133  consumesMany<B>(tid);
134  }
135 
136  void consumesMany(const TypeToGet& id) {
137  consumesMany<InEvent>(id);
138  }
139 
140  template <BranchType B>
141  void consumesMany(const TypeToGet& id) {
142  recordConsumes(B,id,edm::InputTag{},true);
143  }
144 
145  private:
146  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
147 
148  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
150  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
151  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
152 
154  // ---------- member data --------------------------------
155 
158  ProductResolverIndex iIndex,
159  bool skipCurrentProcess,
160  BranchType iBranch):
161  m_type(iID),m_index(iIndex, skipCurrentProcess), m_branchType(iBranch){}
165  };
166 
167  struct LabelPlacement {
168  LabelPlacement(unsigned int iStartOfModuleLabel,
169  unsigned short iDeltaToProductInstance,
170  unsigned short iDeltaToProcessName):
171  m_startOfModuleLabel(iStartOfModuleLabel),
172  m_deltaToProductInstance(iDeltaToProductInstance),
173  m_deltaToProcessName(iDeltaToProcessName) {}
174  unsigned int m_startOfModuleLabel;
175  unsigned short m_deltaToProductInstance;
176  unsigned short m_deltaToProcessName;
177  };
178 
179  //define the purpose of each 'column' in m_tokenInfo
182 
183  //m_tokenStartOfLabels holds the entries into this container
184  // for each of the 3 labels needed to id the data
185  std::vector<char> m_tokenLabels;
186 
187  std::vector<ProductResolverIndexAndSkipBit> itemsToGetFromEvent_;
188 
189  bool frozen_;
190  };
191 }
192 
193 #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)
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFromEvent() const
unsigned int recordConsumes(BranchType iBranch, TypeToGet const &iType, edm::InputTag const &iTag, bool iAlwaysGets)
void consumesMany(const TypeToGet &id)
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
std::vector< ProductResolverIndexAndSkipBit > itemsToGetFromEvent_
void throwBranchMismatch(BranchType, EDGetToken) const
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
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)
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
EDGetToken consumes(const TypeToGet &id, edm::InputTag const &tag)