CMS 3D CMS Logo

EDConsumerBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWCore/Framework
4 // Class : EDConsumerBase
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Tue, 02 Apr 2013 21:36:06 GMT
11 //
12 
13 // system include files
14 #include <algorithm>
15 #include <cassert>
16 #include <cstring>
17 #include <set>
18 #include <utility>
19 
20 // user include files
32 
33 using namespace edm;
34 
35 namespace {
36  std::vector<char> makeEmptyTokenLabels() { return std::vector<char>{'\0'}; }
37 } // namespace
38 
40  : m_tokenLabels{makeEmptyTokenLabels()}, frozen_(false), containsCurrentProcessAlias_(false) {}
41 
43 
44 //
45 // member functions
46 //
48  ConsumesCollector c{this};
49  return c;
50 }
51 
52 static const edm::InputTag kWasEmpty("@EmptyLabel@");
53 
55  if (iTag.label().empty()) {
56  return kWasEmpty;
57  }
58  return iTag;
59 }
60 
62  TypeToGet const& iType,
63  edm::InputTag const& iTag,
64  bool iAlwaysGets) {
65  if (frozen_) {
66  throwConsumesCallAfterFrozen(iType, iTag);
67  }
68 
69  unsigned int index = m_tokenInfo.size();
70 
71  bool skipCurrentProcess = iTag.willSkipCurrentProcess();
72 
73  const size_t labelSize = iTag.label().size();
74  const size_t productInstanceSize = iTag.instance().size();
75  unsigned int labelStart = m_tokenLabels.size();
76  unsigned short delta1 = labelSize + 1;
77  unsigned short delta2 = labelSize + 2 + productInstanceSize;
78  m_tokenInfo.emplace_back(TokenLookupInfo{iType.type(), ProductResolverIndexInvalid, skipCurrentProcess, iBranch},
79  iAlwaysGets,
80  LabelPlacement{labelStart, delta1, delta2},
81  iType.kind());
82 
83  const size_t additionalSize = skipCurrentProcess ? labelSize + productInstanceSize + 3
84  : labelSize + productInstanceSize + iTag.process().size() + 3;
85 
86  m_tokenLabels.reserve(m_tokenLabels.size() + additionalSize);
87  {
88  const std::string& m = iTag.label();
89  m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
90  m_tokenLabels.push_back('\0');
91  }
92  {
93  const std::string& m = iTag.instance();
94  m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
95  m_tokenLabels.push_back('\0');
96  }
97  {
98  const std::string& m = iTag.process();
101  }
102  if (!skipCurrentProcess) {
103  m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
104  m_tokenLabels.push_back('\0');
105  } else {
106  m_tokenLabels.push_back('\0');
107  }
108  }
109  return index;
110 }
111 
113  ProductResolverIndexHelper const& iHelper,
114  bool iPrefetchMayGet) {
115  frozen_ = true;
117  {
118  auto itKind = m_tokenInfo.begin<kKind>();
119  auto itLabels = m_tokenInfo.begin<kLabels>();
120  for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
121  ++itInfo, ++itKind, ++itLabels) {
122  if (itInfo->m_branchType == iBranchType) {
123  const unsigned int labelStart = itLabels->m_startOfModuleLabel;
124  const char* moduleLabel = &(m_tokenLabels[labelStart]);
125  itInfo->m_index = ProductResolverIndexAndSkipBit(iHelper.index(*itKind,
126  itInfo->m_type,
127  moduleLabel,
128  moduleLabel + itLabels->m_deltaToProductInstance,
129  moduleLabel + itLabels->m_deltaToProcessName),
130  itInfo->m_index.skipCurrentProcess());
131  }
132  }
133  }
134 
135  //now add resolved requests to get many to the end of our list
136  // a get many will have an empty module label
137  for (size_t i = 0, iEnd = m_tokenInfo.size(); i != iEnd; ++i) {
138  //need to copy since pointer could be invalidated by emplace_back
139  auto const info = m_tokenInfo.get<kLookupInfo>(i);
140  if (info.m_branchType == iBranchType && info.m_index.productResolverIndex() == ProductResolverIndexInvalid &&
141  m_tokenLabels[m_tokenInfo.get<kLabels>(i).m_startOfModuleLabel] == '\0') {
142  //find all matching types
143  const auto kind = m_tokenInfo.get<kKind>(i);
144  auto matches = iHelper.relatedIndexes(kind, info.m_type);
145 
146  //NOTE: This could be changed to contain the true labels for what is being
147  // requested but for now I want to remember these are part of a get many
148  const LabelPlacement labels = m_tokenInfo.get<kLabels>(i);
149  bool alwaysGet = m_tokenInfo.get<kAlwaysGets>(i);
150  for (unsigned int j = 0; j != matches.numberOfMatches(); ++j) {
151  //only keep the ones that are for a specific data item and not a collection
152  if (matches.isFullyResolved(j)) {
153  auto index = matches.index(j);
154  m_tokenInfo.emplace_back(
155  TokenLookupInfo{info.m_type, index, info.m_index.skipCurrentProcess(), info.m_branchType},
156  alwaysGet,
157  labels,
158  kind);
159  }
160  }
161  }
162  }
163  m_tokenInfo.shrink_to_fit();
164 
165  itemsToGet(iBranchType, itemsToGetFromBranch_[iBranchType]);
166  if (iPrefetchMayGet) {
167  itemsMayGet(iBranchType, itemsToGetFromBranch_[iBranchType]);
168  }
169 }
170 
172  // temporarily unfreeze to allow late EventSetup consumes registration
173  frozen_ = false;
175  frozen_ = true;
176 
177  unsigned int index = 0;
178  for (auto it = m_esTokenInfo.begin<kESLookupInfo>(); it != m_esTokenInfo.end<kESLookupInfo>(); ++it, ++index) {
179  auto indexInRecord = iPI.indexInRecord(it->m_record, it->m_key);
181  const char* componentName = &(m_tokenLabels[it->m_startOfComponentName]);
182  if (*componentName) {
183  auto component = iPI.component(it->m_record, it->m_key);
184  if (component->label_.empty()) {
185  if (component->type_ != componentName) {
187  }
188  } else if (component->label_ != componentName) {
190  }
191  }
192  }
193  m_esTokenInfo.get<kESProxyIndex>(index) = indexInRecord;
194 
195  int negIndex = -1 * (index + 1);
196  for (auto& items : esItemsToGetFromTransition_) {
197  for (auto& itemIndex : items) {
198  if (itemIndex.value() == negIndex) {
199  itemIndex = indexInRecord;
200  esRecordsToGetFromTransition_[&items - &esItemsToGetFromTransition_.front()][&itemIndex - &items.front()] =
201  iPI.recordIndexFor(it->m_record);
202  negIndex = 1;
203  break;
204  }
205  }
206  if (negIndex > 0) {
207  break;
208  }
209  }
210  }
211 }
212 
214  eventsetup::EventSetupRecordKey const& iRecord,
216  edm::ESInputTag const& iTag) {
217  if (frozen_) {
218  throwESConsumesCallAfterFrozen(iRecord, iDataType, iTag);
219  }
220 
221  //m_tokenLabels first entry is a null. Since most ES data requests have
222  // empty labels we will assume we can reuse the first entry
223  unsigned int startOfComponentName = 0;
224  if (not iTag.module().empty()) {
225  startOfComponentName = m_tokenLabels.size();
226 
227  m_tokenLabels.reserve(m_tokenLabels.size() + iTag.module().size() + 1);
228  {
229  const std::string& m = iTag.module();
230  m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
231  m_tokenLabels.push_back('\0');
232  }
233  }
234 
235  auto index = static_cast<ESProxyIndex::Value_t>(m_esTokenInfo.size());
236  m_esTokenInfo.emplace_back(
237  ESTokenLookupInfo{iRecord, eventsetup::DataKey{iDataType, iTag.data().c_str()}, startOfComponentName},
238  ESProxyIndex{-1});
241  }
242  auto indexForToken = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].size();
243  esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back(-1 * (index + 1));
244  esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back();
245  return ESTokenIndex{static_cast<ESTokenIndex::Value_t>(indexForToken)};
246 }
247 
248 //
249 // const member functions
250 //
252  BranchType iBranch,
253  TypeID const& iType) const {
254  if (UNLIKELY(iToken.index() >= m_tokenInfo.size())) {
255  throwBadToken(iType, iToken);
256  }
257  const auto& info = m_tokenInfo.get<kLookupInfo>(iToken.index());
258  if (LIKELY(iBranch == info.m_branchType)) {
259  if (LIKELY(iType == info.m_type)) {
260  return info.m_index;
261  } else {
262  throwTypeMismatch(iType, iToken);
263  }
264  } else {
265  throwBranchMismatch(iBranch, iToken);
266  }
268 }
269 
271  return m_tokenInfo.get<kLookupInfo>(iToken.index()).m_index;
272 }
273 
274 void EDConsumerBase::itemsToGet(BranchType iBranch, std::vector<ProductResolverIndexAndSkipBit>& oIndices) const {
275  //how many are we adding?
276  unsigned int count = 0;
277  {
278  auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
279  for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
280  ++it, ++itAlwaysGet) {
281  if (iBranch == it->m_branchType) {
282  if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
283  if (*itAlwaysGet) {
284  ++count;
285  }
286  }
287  }
288  }
289  }
290  oIndices.reserve(oIndices.size() + count);
291  {
292  auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
293  for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
294  ++it, ++itAlwaysGet) {
295  if (iBranch == it->m_branchType) {
296  if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
297  if (*itAlwaysGet) {
298  oIndices.push_back(it->m_index);
299  }
300  }
301  }
302  }
303  }
304 }
305 
306 void EDConsumerBase::itemsMayGet(BranchType iBranch, std::vector<ProductResolverIndexAndSkipBit>& oIndices) const {
307  //how many are we adding?
308  unsigned int count = 0;
309  {
310  auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
311  for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
312  ++it, ++itAlwaysGet) {
313  if (iBranch == it->m_branchType) {
314  if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
315  if (not *itAlwaysGet) {
316  ++count;
317  }
318  }
319  }
320  }
321  }
322  oIndices.reserve(oIndices.size() + count);
323  {
324  auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
325  for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
326  ++it, ++itAlwaysGet) {
327  if (iBranch == it->m_branchType) {
328  if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
329  if (not *itAlwaysGet) {
330  oIndices.push_back(it->m_index);
331  }
332  }
333  }
334  }
335  }
336 }
337 
338 void EDConsumerBase::labelsForToken(EDGetToken iToken, Labels& oLabels) const {
339  unsigned int index = iToken.index();
340  auto labels = m_tokenInfo.get<kLabels>(index);
341  unsigned int start = labels.m_startOfModuleLabel;
342  oLabels.module = &(m_tokenLabels[start]);
343  oLabels.productInstance = oLabels.module + labels.m_deltaToProductInstance;
344  oLabels.process = oLabels.module + labels.m_deltaToProcessName;
345 }
346 
348  bool skipCurrentProcess,
349  BranchType iBranch) const {
350  for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd; ++it) {
351  if (it->m_index.productResolverIndex() == iIndex and it->m_index.skipCurrentProcess() == skipCurrentProcess and
352  it->m_branchType == iBranch) {
353  return true;
354  }
355  }
356  return false;
357 }
358 
359 bool EDConsumerBase::registeredToConsumeMany(TypeID const& iType, BranchType iBranch) const {
360  for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd; ++it) {
361  //consumesMany entries do not have their index resolved
362  if (it->m_index.productResolverIndex() == ProductResolverIndexInvalid and it->m_type == iType and
363  it->m_branchType == iBranch) {
364  return true;
365  }
366  }
367  return false;
368 }
369 
370 void EDConsumerBase::throwTypeMismatch(edm::TypeID const& iType, EDGetToken iToken) const {
371  throw cms::Exception("TypeMismatch") << "A get using a EDGetToken used the C++ type '" << iType.className()
372  << "' but the consumes call was for type '"
373  << m_tokenInfo.get<kLookupInfo>(iToken.index()).m_type.className()
374  << "'.\n Please modify either the consumes or get call so the types match.";
375 }
377  throw cms::Exception("BranchTypeMismatch")
378  << "A get using a EDGetToken was done in " << BranchTypeToString(iBranch) << " but the consumes call was for "
379  << BranchTypeToString(m_tokenInfo.get<kLookupInfo>(iToken.index()).m_branchType)
380  << ".\n Please modify the consumes call to use the correct branch type.";
381 }
382 
383 void EDConsumerBase::throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const {
384  if (iToken.isUninitialized()) {
385  throw cms::Exception("BadToken") << "A get using a EDGetToken with the C++ type '" << iType.className()
386  << "' was made using an uninitialized token.\n Please check that the variable is "
387  "being initialized from a 'consumes' call.";
388  }
389  throw cms::Exception("BadToken")
390  << "A get using a EDGetToken with the C++ type '" << iType.className() << "' was made using a token with a value "
391  << iToken.index()
392  << " which is beyond the range used by this module.\n Please check that the variable is being initialized from a "
393  "'consumes' call from this module.\n You can not share EDGetToken values between modules.";
394 }
395 
397  throw cms::Exception("LogicError") << "A module declared it consumes a product after its constructor.\n"
398  << "This must be done in the contructor\n"
399  << "The product type was: " << typeToGet.type() << "\n"
400  << "and " << inputTag << "\n";
401 }
402 
405  edm::ESInputTag const& iTag) const {
406  throw cms::Exception("LogicError") << "A module declared it consumes an EventSetup product after its constructor.\n"
407  << "This must be done in the contructor\n"
408  << "The product type was: " << iDataType.name() << " in record "
409  << iRecord.type().name() << "\n"
410  << "and ESInputTag was " << iTag << "\n";
411 }
412 
414  throw cms::Exception("LogicError")
415  << "A module declared it consumes an EventSetup product during a ProcessBlock transition.\n"
416  << "EventSetup products can only be consumed in Event, Lumi, or Run transitions.\n";
417 }
418 
420 
421 namespace {
422  struct CharStarComp {
423  bool operator()(const char* iLHS, const char* iRHS) const { return strcmp(iLHS, iRHS) < 0; }
424  };
425 } // namespace
426 
427 namespace {
428  void insertFoundModuleLabel(edm::KindOfType consumedTypeKind,
429  edm::TypeID consumedType,
430  const char* consumedModuleLabel,
431  const char* consumedProductInstance,
432  std::vector<ModuleDescription const*>& modules,
433  std::set<std::string>& alreadyFound,
434  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
435  ProductRegistry const& preg) {
436  // Convert from label string to module description, eliminate duplicates,
437  // then insert into the vector of modules
438  if (auto it = labelsToDesc.find(consumedModuleLabel); it != labelsToDesc.end()) {
439  if (alreadyFound.insert(consumedModuleLabel).second) {
440  modules.push_back(it->second);
441  }
442  return;
443  }
444  // Deal with EDAlias's by converting to the original module label first
445  if (auto aliasToModuleLabels =
446  preg.aliasToModules(consumedTypeKind, consumedType, consumedModuleLabel, consumedProductInstance);
447  not aliasToModuleLabels.empty()) {
448  bool foundInLabelsToDesc = false;
449  for (auto const& label : aliasToModuleLabels) {
450  if (auto it = labelsToDesc.find(label); it != labelsToDesc.end()) {
451  if (alreadyFound.insert(label).second) {
452  modules.push_back(it->second);
453  }
454  foundInLabelsToDesc = true;
455  } else {
456  if (label == "source") {
457  foundInLabelsToDesc = true;
458  }
459  }
460  }
461  if (foundInLabelsToDesc) {
462  return;
463  }
464  }
465  // Ignore the source products, we are only interested in module products.
466  // As far as I know, it should never be anything else so throw if something
467  // unknown gets passed in.
468  if (std::string_view(consumedModuleLabel) != "source") {
469  throw cms::Exception("EDConsumerBase", "insertFoundModuleLabel")
470  << "Couldn't find ModuleDescription for the consumed product type: '" << consumedType.className()
471  << "' module label: '" << consumedModuleLabel << "' product instance name: '" << consumedProductInstance
472  << "'";
473  }
474  }
475 } // namespace
476 
478  std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
479  std::vector<ModuleProcessName>& modulesInPreviousProcesses,
480  ProductRegistry const& preg,
481  std::map<std::string, ModuleDescription const*> const& labelsToDesc,
482  std::string const& processName) const {
483  std::set<std::string> alreadyFound;
484 
485  auto modulesInPreviousProcessesEmplace = [&modulesInPreviousProcesses](std::string_view module,
486  std::string_view process) {
487  auto it = std::lower_bound(
488  modulesInPreviousProcesses.begin(), modulesInPreviousProcesses.end(), ModuleProcessName(module, process));
489  modulesInPreviousProcesses.emplace(it, module, process);
490  };
491 
492  auto itKind = m_tokenInfo.begin<kKind>();
493  auto itLabels = m_tokenInfo.begin<kLabels>();
494  for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
495  ++itInfo, ++itKind, ++itLabels) {
496  ProductResolverIndexHelper const& helper = *preg.productLookup(itInfo->m_branchType);
497  std::vector<ModuleDescription const*>& modules = *modulesAll[itInfo->m_branchType];
498 
499  const unsigned int labelStart = itLabels->m_startOfModuleLabel;
500  const char* const consumedModuleLabel = &(m_tokenLabels[labelStart]);
501  const char* const consumedProductInstance = consumedModuleLabel + itLabels->m_deltaToProductInstance;
502  const char* const consumedProcessName = consumedModuleLabel + itLabels->m_deltaToProcessName;
503 
504  if (not itInfo->m_index.skipCurrentProcess()) {
505  if (*consumedModuleLabel != '\0') { // not a consumesMany
506  if (*consumedProcessName != '\0') { // process name is specified in consumes call
507  if (helper.index(
508  *itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance, consumedProcessName) !=
510  if (processName == consumedProcessName) {
511  insertFoundModuleLabel(*itKind,
512  itInfo->m_type,
513  consumedModuleLabel,
514  consumedProductInstance,
515  modules,
516  alreadyFound,
517  labelsToDesc,
518  preg);
519  } else {
520  // Product explicitly from different process than the current process, so must refer to an earlier process (unless it ends up "not found")
521  modulesInPreviousProcessesEmplace(consumedModuleLabel, consumedProcessName);
522  }
523  }
524  } else { // process name was empty
525  auto matches = helper.relatedIndexes(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance);
526  for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
527  if (processName == matches.processName(j)) {
528  insertFoundModuleLabel(*itKind,
529  itInfo->m_type,
530  consumedModuleLabel,
531  consumedProductInstance,
532  modules,
533  alreadyFound,
534  labelsToDesc,
535  preg);
536  } else {
537  // Product did not match to current process, so must refer to an earlier process (unless it ends up "not found")
538  // Recall that empty process name means "in the latest process" that can change event-by-event
539  modulesInPreviousProcessesEmplace(consumedModuleLabel, matches.processName(j));
540  }
541  }
542  }
543  // consumesMany case
544  } else if (itInfo->m_index.productResolverIndex() == ProductResolverIndexInvalid) {
545  auto matches = helper.relatedIndexes(*itKind, itInfo->m_type);
546  for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
547  if (processName == matches.processName(j)) {
548  insertFoundModuleLabel(*itKind,
549  itInfo->m_type,
550  matches.moduleLabel(j),
551  matches.productInstanceName(j),
552  modules,
553  alreadyFound,
554  labelsToDesc,
555  preg);
556  } else {
557  modulesInPreviousProcessesEmplace(matches.moduleLabel(j), matches.processName(j));
558  }
559  }
560  }
561  } else {
562  // The skipCurrentProcess means the same as empty process name,
563  // except the current process is skipped. Therefore need to do
564  // the same matching as above. There is no consumesMany branch
565  // in this case.
566  auto matches = helper.relatedIndexes(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance);
567  for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
568  if (processName != matches.processName(j)) {
569  modulesInPreviousProcessesEmplace(matches.moduleLabel(j), matches.processName(j));
570  }
571  }
572  }
573  }
574 }
575 
577  frozen_ = true;
578 
581 
582  auto newTokenLabels = makeEmptyTokenLabels();
583 
584  // first calculate the size of the new vector and reserve memory for it
585  std::vector<char>::size_type newSize = newTokenLabels.size();
586  std::string newProcessName;
587  for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
588  newProcessName = &m_tokenLabels[iter->m_startOfModuleLabel + iter->m_deltaToProcessName];
589  if (newProcessName == InputTag::kCurrentProcess) {
590  newProcessName = processName;
591  }
592  newSize += (iter->m_deltaToProcessName + newProcessName.size() + 1);
593  }
594  newTokenLabels.reserve(newSize);
595 
596  unsigned int newStartOfModuleLabel = newTokenLabels.size();
597  for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
598  unsigned int startOfModuleLabel = iter->m_startOfModuleLabel;
599  unsigned short deltaToProcessName = iter->m_deltaToProcessName;
600 
601  iter->m_startOfModuleLabel = newStartOfModuleLabel;
602 
603  newProcessName = &m_tokenLabels[startOfModuleLabel + deltaToProcessName];
604  if (newProcessName == InputTag::kCurrentProcess) {
605  newProcessName = processName;
606  }
607 
608  newStartOfModuleLabel += (deltaToProcessName + newProcessName.size() + 1);
609 
610  // Copy in both the module label and instance, they are the same
611  newTokenLabels.insert(newTokenLabels.end(),
612  m_tokenLabels.begin() + startOfModuleLabel,
613  m_tokenLabels.begin() + (startOfModuleLabel + deltaToProcessName));
614 
615  newTokenLabels.insert(newTokenLabels.end(), newProcessName.begin(), newProcessName.end());
616  newTokenLabels.push_back('\0');
617  }
618  m_tokenLabels = std::move(newTokenLabels);
619  }
620 }
621 
622 std::vector<ConsumesInfo> EDConsumerBase::consumesInfo() const {
623  // Use this to eliminate duplicate entries related
624  // to consumesMany items where only the type was specified
625  // and the there are multiple matches. In these cases the
626  // label, instance, and process will be empty.
627  std::set<edm::TypeID> alreadySeenTypes;
628 
629  std::vector<ConsumesInfo> result;
630  auto itAlways = m_tokenInfo.begin<kAlwaysGets>();
631  auto itKind = m_tokenInfo.begin<kKind>();
632  auto itLabels = m_tokenInfo.begin<kLabels>();
633  for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
634  ++itInfo, ++itKind, ++itLabels, ++itAlways) {
635  const unsigned int labelStart = itLabels->m_startOfModuleLabel;
636  const char* consumedModuleLabel = &(m_tokenLabels[labelStart]);
637  const char* consumedInstance = consumedModuleLabel + itLabels->m_deltaToProductInstance;
638  const char* consumedProcessName = consumedModuleLabel + itLabels->m_deltaToProcessName;
639 
640  // consumesMany case
641  if (*consumedModuleLabel == '\0') {
642  if (!alreadySeenTypes.insert(itInfo->m_type).second) {
643  continue;
644  }
645  }
646 
647  // Just copy the information into the ConsumesInfo data structure
648  result.emplace_back(itInfo->m_type,
649  consumedModuleLabel,
650  consumedInstance,
651  consumedProcessName,
652  itInfo->m_branchType,
653  *itKind,
654  *itAlways,
655  itInfo->m_index.skipCurrentProcess());
656  }
657  return result;
658 }
659 
660 const char* EDConsumerBase::labelFor(ESTokenIndex iIndex) const {
661  return m_esTokenInfo.get<kESLookupInfo>(iIndex.value()).m_key.name().value();
662 }
size
Write out results.
edm::SoATuple< TokenLookupInfo, bool, LabelPlacement, edm::KindOfType > m_tokenInfo
Definition: start.py:1
ProductResolverIndexAndSkipBit uncheckedIndexFrom(EDGetToken) const
TypeID const & type() const
Definition: TypeToGet.h:42
static const TGPicture * info(bool iBackgroundIsBlack)
const char * labelFor(ESTokenIndex) const
constexpr unsigned int index() const noexcept
Definition: EDGetToken.h:50
Definition: helper.py:1
unsigned int ProductResolverIndex
virtual void doSelectInputProcessBlocks(ProductRegistry const &, ProcessBlockHelperBase const &)
std::string const & instance() const
Definition: InputTag.h:37
void updateLookup(BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
void throwESConsumesInProcessBlock() const
std::vector< std::string > aliasToModules(KindOfType kindOfType, TypeID const &type, std::string_view moduleLabel, std::string_view productInstanceName) const
constexpr Value_t value() const noexcept
Definition: ESIndices.h:70
void throwTypeMismatch(edm::TypeID const &, EDGetToken) const
void itemsToGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
ProductResolverIndexAndSkipBit indexFrom(EDGetToken, BranchType, TypeID const &) const
#define LIKELY(x)
Definition: Likely.h:20
void modulesWhoseProductsAreConsumed(std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
std::string const & label() const
Definition: InputTag.h:36
KindOfType kind() const
Definition: TypeToGet.h:43
assert(be >=bs)
uint16_t size_type
Matches relatedIndexes(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance) const
const std::string & data() const
Definition: ESInputTag.h:104
BranchType
Definition: BranchType.h:11
char const * process
Definition: ProductLabels.h:7
unsigned int recordConsumes(BranchType iBranch, TypeToGet const &iType, edm::InputTag const &iTag, bool iAlwaysGets)
ESRecordIndex recordIndexFor(EventSetupRecordKey const &iRK) const noexcept
std::array< std::vector< ESProxyIndex >, static_cast< unsigned int >edm::Transition::NumberOfEventSetupTransitions)> esItemsToGetFromTransition_
char const * label
ESProxyIndex indexInRecord(EventSetupRecordKey const &iRK, DataKey const &iDK) const noexcept
If the index is not found, returns missingProxyIndex()
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
ProductResolverIndex index(KindOfType kindOfType, TypeID const &typeID, char const *moduleLabel, char const *instance, char const *process=nullptr) const
std::string const & BranchTypeToString(BranchType const &branchType)
Definition: BranchType.cc:93
Transition
Definition: Transition.h:12
static const std::string kCurrentProcess
Definition: InputTag.h:54
virtual void registerLateConsumes(eventsetup::ESRecordsToProxyIndices const &)
void throwESConsumesCallAfterFrozen(eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &) const
std::vector< ConsumesInfo > consumesInfo() const
char const * module
Definition: ProductLabels.h:5
std::array< std::vector< ESRecordIndex >, static_cast< unsigned int >edm::Transition::NumberOfEventSetupTransitions)> esRecordsToGetFromTransition_
static constexpr ESProxyIndex missingProxyIndex() noexcept
bool registeredToConsume(ProductResolverIndex, bool, BranchType) const
ComponentDescription const * component(EventSetupRecordKey const &iRK, DataKey const &iDK) const noexcept
std::vector< char > m_tokenLabels
std::string const & className() const
Definition: TypeID.cc:40
static const edm::InputTag kWasEmpty("@EmptyLabel@")
void throwBadToken(edm::TypeID const &iType, EDGetToken iToken) const
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
edm::SoATuple< ESTokenLookupInfo, ESProxyIndex > m_esTokenInfo
void itemsMayGet(BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
bool registeredToConsumeMany(TypeID const &, BranchType) const
void throwConsumesCallAfterFrozen(TypeToGet const &, InputTag const &) const
char const * productInstance
Definition: ProductLabels.h:6
HLT enums.
bool willSkipCurrentProcess() const
Definition: InputTag.h:42
ESTokenIndex recordESConsumes(Transition, eventsetup::EventSetupRecordKey const &, eventsetup::heterocontainer::HCTypeTag const &, edm::ESInputTag const &iTag)
edm::InputTag const & checkIfEmpty(edm::InputTag const &tag)
virtual ~EDConsumerBase() noexcept(false)
const std::string & module() const
Definition: ESInputTag.h:99
#define UNLIKELY(x)
Definition: Likely.h:21
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:51
std::string const & process() const
Definition: InputTag.h:40
void convertCurrentProcessAlias(std::string const &processName)
Convert "@currentProcess" in InputTag process names to the actual current process name...
void throwBranchMismatch(BranchType, EDGetToken) const
def move(src, dest)
Definition: eostools.py:511
std::array< std::vector< ProductResolverIndexAndSkipBit >, edm::NumBranchTypes > itemsToGetFromBranch_
void labelsForToken(EDGetToken iToken, Labels &oLabels) const