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