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
47 
48 // forward declarations
49 
50 namespace edm {
51  class ModuleDescription;
52  class ProductResolverIndexHelper;
53  class ProductRegistry;
54  class ConsumesCollector;
55  template <typename T>
57 
58  namespace eventsetup {
60  }
61 
63  public:
64  EDConsumerBase() : m_tokenLabels{'\0'}, frozen_(false), containsCurrentProcessAlias_(false) {}
65  virtual ~EDConsumerBase() noexcept(false);
66 
67  // disallow copying
68  EDConsumerBase(EDConsumerBase const&) = delete;
69  EDConsumerBase const& operator=(EDConsumerBase const&) = delete;
70 
71  // allow moving
72  EDConsumerBase(EDConsumerBase&&) = default;
73  EDConsumerBase& operator=(EDConsumerBase&&) = default;
74 
75  // ---------- const member functions ---------------------
77  ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const;
78 
79  void itemsToGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
80  void itemsMayGet(BranchType, std::vector<ProductResolverIndexAndSkipBit>&) const;
81 
82  std::vector<ProductResolverIndexAndSkipBit> const& itemsToGetFrom(BranchType iType) const {
83  return itemsToGetFromBranch_[iType];
84  }
85 
87  bool registeredToConsume(ProductResolverIndex, bool, BranchType) const;
88 
90  bool registeredToConsumeMany(TypeID const&, BranchType) const;
91  // ---------- static member functions --------------------
92 
93  // ---------- member functions ---------------------------
94  void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const&, bool iPrefetchMayGet);
95  void updateLookup(eventsetup::ESRecordsToProxyIndices const&);
96 
98  void labelsForToken(EDGetToken iToken, Labels& oLabels) const;
99 
100  void modulesWhoseProductsAreConsumed(std::vector<ModuleDescription const*>& modules,
101  ProductRegistry const& preg,
102  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
103  std::string const& processName) const;
104 
106  void convertCurrentProcessAlias(std::string const& processName);
107 
108  std::vector<ConsumesInfo> consumesInfo() const;
109 
111  auto const& v = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)];
112  if (v.empty()) {
113  return nullptr;
114  }
115  return &(esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].front());
116  }
117 
118  protected:
119  friend class ConsumesCollector;
120  template <typename T>
121  friend class WillGetIfMatch;
123  ConsumesCollector consumesCollector();
124 
125  template <typename ProductType, BranchType B = InEvent>
127  TypeToGet tid = TypeToGet::make<ProductType>();
128  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), true)};
129  }
130 
132  return EDGetToken{recordConsumes(InEvent, id, checkIfEmpty(tag), true)};
133  }
134 
135  template <BranchType B>
137  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), true)};
138  }
139 
140  template <typename ProductType, BranchType B = InEvent>
142  TypeToGet tid = TypeToGet::make<ProductType>();
143  return EDGetTokenT<ProductType>{recordConsumes(B, tid, checkIfEmpty(tag), false)};
144  }
145 
146  EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) { return mayConsume<InEvent>(id, tag); }
147 
148  template <BranchType B>
150  return EDGetToken{recordConsumes(B, id, checkIfEmpty(tag), false)};
151  }
152 
153  template <typename ProductType, BranchType B = InEvent>
154  void consumesMany() {
155  TypeToGet tid = TypeToGet::make<ProductType>();
156  consumesMany<B>(tid);
157  }
158 
159  void consumesMany(const TypeToGet& id) { consumesMany<InEvent>(id); }
160 
161  template <BranchType B>
162  void consumesMany(const TypeToGet& id) {
163  recordConsumes(B, id, edm::InputTag{}, true);
164  }
165 
166  // For consuming event-setup products
167  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
168  auto esConsumes() {
169  return esConsumes<ESProduct, ESRecord, Tr>(ESInputTag{});
170  }
171 
172  template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
173  auto esConsumes(ESInputTag const& tag) {
174  auto index = recordESConsumes(Tr,
176  std::conditional_t<std::is_same_v<ESRecord, edm::DefaultRecord>,
178  ESRecord>>(),
179  eventsetup::heterocontainer::HCTypeTag::make<ESProduct>(),
180  tag);
181  return ESGetToken<ESProduct, ESRecord>{static_cast<unsigned int>(Tr), index, labelFor(index)};
182  }
183 
184  private:
185  unsigned int recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets);
186  ESTokenIndex recordESConsumes(Transition,
189  edm::ESInputTag const& iTag);
190 
191  const char* labelFor(ESTokenIndex) const;
192 
193  void throwTypeMismatch(edm::TypeID const&, EDGetToken) const;
194  void throwBranchMismatch(BranchType, EDGetToken) const;
195  void throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const;
196  void throwConsumesCallAfterFrozen(TypeToGet const&, InputTag const&) const;
197 
198  edm::InputTag const& checkIfEmpty(edm::InputTag const& tag);
199  // ---------- member data --------------------------------
200 
202  TokenLookupInfo(edm::TypeID const& iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
203  : m_type(iID), m_index(iIndex, skipCurrentProcess), m_branchType(iBranch) {}
207  };
208 
209  struct LabelPlacement {
210  LabelPlacement(unsigned int iStartOfModuleLabel,
211  unsigned short iDeltaToProductInstance,
212  unsigned short iDeltaToProcessName)
213  : m_startOfModuleLabel(iStartOfModuleLabel),
214  m_deltaToProductInstance(iDeltaToProductInstance),
215  m_deltaToProcessName(iDeltaToProcessName) {}
216  unsigned int m_startOfModuleLabel;
217  unsigned short m_deltaToProductInstance;
218  unsigned short m_deltaToProcessName;
219  };
220 
221  //define the purpose of each 'column' in m_tokenInfo
222  enum { kLookupInfo, kAlwaysGets, kLabels, kKind };
224 
225  //m_tokenStartOfLabels holds the entries into this container
226  // for each of the 3 labels needed to id the data
227  std::vector<char> m_tokenLabels;
228 
229  std::array<std::vector<ProductResolverIndexAndSkipBit>, edm::NumBranchTypes> itemsToGetFromBranch_;
230 
235  };
236 
237  // TODO We would like to be able to access m_esTokenInfo from the
238  // index in the token, but this is currently not possible. One idea
239  // for this is to order the entries in m_esToken so that all the ones
240  // for transition 0 come first, then the ones for for transition 1
241  // and so on for all the transitions. Within a transition, the
242  // entries would be in the same order in m_esTokenInfo and
243  // esItemsToGetFromTransition_. This is something for future
244  // development and might require a change to SoATuple to support
245  // inserts in the middle of the data structure.
246  enum { kESLookupInfo, kESProxyIndex };
248  std::array<std::vector<ESProxyIndex>, static_cast<unsigned int>(edm::Transition::NumberOfTransitions)>
249  esItemsToGetFromTransition_;
250  bool frozen_;
252  };
253 } // namespace edm
254 
255 #endif
edm::SoATuple< TokenLookupInfo, bool, LabelPlacement, edm::KindOfType > m_tokenInfo
unsigned int ProductResolverIndex
eventsetup::EventSetupRecordKey m_record
void consumesMany(const TypeToGet &id)
LabelPlacement(unsigned int iStartOfModuleLabel, unsigned short iDeltaToProductInstance, unsigned short iDeltaToProcessName)
BranchType
Definition: BranchType.h:11
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void consumesMany(const TypeToGet &id)
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom(BranchType iType) const
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
typename default_record< T >::RecordT default_record_t
ProductResolverIndexAndSkipBit m_index
Transition
Definition: Transition.h:12
EDGetToken mayConsume(const TypeToGet &id, edm::InputTag const &tag)
static const std::string B
std::vector< char > m_tokenLabels
ProductLabels Labels
#define noexcept
EDGetToken consumes(TypeToGet const &id, edm::InputTag const &tag)
edm::SoATuple< ESTokenLookupInfo, ESProxyIndex > m_esTokenInfo
HLT enums.
static EventSetupRecordKey makeKey()
auto esConsumes(ESInputTag const &tag)
TokenLookupInfo(edm::TypeID const &iID, ProductResolverIndex iIndex, bool skipCurrentProcess, BranchType iBranch)
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
std::array< std::vector< ProductResolverIndexAndSkipBit >, edm::NumBranchTypes > itemsToGetFromBranch_
ESProxyIndex const * esGetTokenIndices(edm::Transition iTrans) const
EDGetToken consumes(const TypeToGet &id, edm::InputTag const &tag)