Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-12 04:16:28

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Framework
0004 // Class  :     EDConsumerBase
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue, 02 Apr 2013 21:36:06 GMT
0011 //
0012 
0013 // system include files
0014 #include <array>
0015 #include <algorithm>
0016 #include <cassert>
0017 #include <cstring>
0018 #include <set>
0019 #include <utility>
0020 
0021 // user include files
0022 #include "FWCore/Framework/interface/EDConsumerBase.h"
0023 #include "FWCore/Framework/interface/ConsumesCollector.h"
0024 #include "FWCore/Framework/interface/ESRecordsToProductResolverIndices.h"
0025 #include "FWCore/Framework/interface/ComponentDescription.h"
0026 #include "FWCore/Framework/interface/ModuleProcessName.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 #include "FWCore/Utilities/interface/BranchType.h"
0029 #include "FWCore/Utilities/interface/Likely.h"
0030 #include "FWCore/Utilities/interface/Exception.h"
0031 #include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
0032 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0033 
0034 using namespace edm;
0035 
0036 namespace {
0037   std::vector<char> makeEmptyTokenLabels() { return std::vector<char>{'\0'}; }
0038 }  // namespace
0039 
0040 EDConsumerBase::EDConsumerBase()
0041     : m_tokenLabels{makeEmptyTokenLabels()}, frozen_(false), containsCurrentProcessAlias_(false) {}
0042 
0043 EDConsumerBase::~EDConsumerBase() noexcept(false) {}
0044 
0045 //
0046 // member functions
0047 //
0048 ConsumesCollector EDConsumerBase::consumesCollector() {
0049   ConsumesCollector c{this};
0050   return c;
0051 }
0052 
0053 static const edm::InputTag kWasEmpty("@EmptyLabel@");
0054 
0055 edm::InputTag const& EDConsumerBase::checkIfEmpty(edm::InputTag const& iTag) {
0056   if (iTag.label().empty()) {
0057     return kWasEmpty;
0058   }
0059   return iTag;
0060 }
0061 
0062 unsigned int EDConsumerBase::recordConsumes(BranchType iBranch,
0063                                             TypeToGet const& iType,
0064                                             edm::InputTag const& iTag,
0065                                             bool iAlwaysGets) {
0066   if (frozen_) {
0067     throwConsumesCallAfterFrozen(iType, iTag);
0068   }
0069 
0070   unsigned int index = m_tokenInfo.size();
0071 
0072   bool skipCurrentProcess = iTag.willSkipCurrentProcess();
0073 
0074   const size_t labelSize = iTag.label().size();
0075   const size_t productInstanceSize = iTag.instance().size();
0076   unsigned int labelStart = m_tokenLabels.size();
0077   unsigned short delta1 = labelSize + 1;
0078   unsigned short delta2 = labelSize + 2 + productInstanceSize;
0079   m_tokenInfo.emplace_back(TokenLookupInfo{iType.type(), ProductResolverIndexInvalid, skipCurrentProcess, iBranch},
0080                            iAlwaysGets,
0081                            LabelPlacement{labelStart, delta1, delta2},
0082                            iType.kind());
0083 
0084   const size_t additionalSize = skipCurrentProcess ? labelSize + productInstanceSize + 3
0085                                                    : labelSize + productInstanceSize + iTag.process().size() + 3;
0086 
0087   m_tokenLabels.reserve(m_tokenLabels.size() + additionalSize);
0088   {
0089     const std::string& m = iTag.label();
0090     m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
0091     m_tokenLabels.push_back('\0');
0092   }
0093   {
0094     const std::string& m = iTag.instance();
0095     m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
0096     m_tokenLabels.push_back('\0');
0097   }
0098   {
0099     const std::string& m = iTag.process();
0100     if (m == InputTag::kCurrentProcess) {
0101       containsCurrentProcessAlias_ = true;
0102     }
0103     if (!skipCurrentProcess) {
0104       m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
0105       m_tokenLabels.push_back('\0');
0106     } else {
0107       m_tokenLabels.push_back('\0');
0108     }
0109   }
0110   return index;
0111 }
0112 
0113 void EDConsumerBase::extendUpdateLookup(BranchType, ProductResolverIndexHelper const&) {}
0114 
0115 void EDConsumerBase::updateLookup(BranchType iBranchType,
0116                                   ProductResolverIndexHelper const& iHelper,
0117                                   bool iPrefetchMayGet) {
0118   frozen_ = true;
0119   assert(!containsCurrentProcessAlias_);
0120   extendUpdateLookup(iBranchType, iHelper);
0121   {
0122     auto itKind = m_tokenInfo.begin<kKind>();
0123     auto itLabels = m_tokenInfo.begin<kLabels>();
0124     for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
0125          ++itInfo, ++itKind, ++itLabels) {
0126       if (itInfo->m_branchType == iBranchType) {
0127         const unsigned int labelStart = itLabels->m_startOfModuleLabel;
0128         const char* moduleLabel = &(m_tokenLabels[labelStart]);
0129         itInfo->m_index = ProductResolverIndexAndSkipBit(iHelper.index(*itKind,
0130                                                                        itInfo->m_type,
0131                                                                        moduleLabel,
0132                                                                        moduleLabel + itLabels->m_deltaToProductInstance,
0133                                                                        moduleLabel + itLabels->m_deltaToProcessName),
0134                                                          itInfo->m_index.skipCurrentProcess());
0135       }
0136     }
0137   }
0138 
0139   m_tokenInfo.shrink_to_fit();
0140 
0141   itemsToGet(iBranchType, itemsToGetFromBranch_[iBranchType]);
0142   if (iPrefetchMayGet) {
0143     itemsMayGet(iBranchType, itemsToGetFromBranch_[iBranchType]);
0144   }
0145 }
0146 
0147 void EDConsumerBase::updateLookup(eventsetup::ESRecordsToProductResolverIndices const& iPI) {
0148   // temporarily unfreeze to allow late EventSetup consumes registration
0149   frozen_ = false;
0150   registerLateConsumes(iPI);
0151   frozen_ = true;
0152 
0153   unsigned int index = 0;
0154   for (auto it = m_esTokenInfo.begin<kESLookupInfo>(); it != m_esTokenInfo.end<kESLookupInfo>(); ++it, ++index) {
0155     auto indexInRecord = iPI.indexInRecord(it->m_record, it->m_key);
0156     if (indexInRecord != ESResolverIndex::noResolverConfigured()) {
0157       const char* componentName = &(m_tokenLabels[it->m_startOfComponentName]);
0158       if (*componentName) {
0159         auto component = iPI.component(it->m_record, it->m_key);
0160         if (component->label_.empty()) {
0161           if (component->type_ != componentName) {
0162             indexInRecord = ESResolverIndex::moduleLabelDoesNotMatch();
0163           }
0164         } else if (component->label_ != componentName) {
0165           indexInRecord = ESResolverIndex::moduleLabelDoesNotMatch();
0166         }
0167       }
0168     }
0169     m_esTokenInfo.get<kESResolverIndex>(index) = indexInRecord;
0170 
0171     int negIndex = -1 * (index + 1);
0172     for (auto& items : esItemsToGetFromTransition_) {
0173       for (auto& itemIndex : items) {
0174         if (itemIndex.value() == negIndex) {
0175           itemIndex = indexInRecord;
0176           esRecordsToGetFromTransition_[&items - &esItemsToGetFromTransition_.front()][&itemIndex - &items.front()] =
0177               iPI.recordIndexFor(it->m_record);
0178           negIndex = 1;
0179           break;
0180         }
0181       }
0182       if (negIndex > 0) {
0183         break;
0184       }
0185     }
0186   }
0187 }
0188 
0189 std::tuple<ESTokenIndex, char const*> EDConsumerBase::recordESConsumes(
0190     Transition iTrans,
0191     eventsetup::EventSetupRecordKey const& iRecord,
0192     eventsetup::heterocontainer::HCTypeTag const& iDataType,
0193     edm::ESInputTag const& iTag) {
0194   if (frozen_) {
0195     throwESConsumesCallAfterFrozen(iRecord, iDataType, iTag);
0196   }
0197 
0198   //m_tokenLabels first entry is a null. Since most ES data requests have
0199   // empty labels we will assume we can reuse the first entry
0200   unsigned int startOfComponentName = 0;
0201   if (not iTag.module().empty()) {
0202     startOfComponentName = m_tokenLabels.size();
0203 
0204     m_tokenLabels.reserve(m_tokenLabels.size() + iTag.module().size() + 1);
0205     {
0206       const std::string& m = iTag.module();
0207       m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
0208       m_tokenLabels.push_back('\0');
0209     }
0210   }
0211 
0212   auto index = static_cast<ESResolverIndex::Value_t>(m_esTokenInfo.size());
0213   m_esTokenInfo.emplace_back(
0214       ESTokenLookupInfo{iRecord, eventsetup::DataKey{iDataType, iTag.data().c_str()}, startOfComponentName},
0215       ESResolverIndex{-1});
0216   if (iTrans >= edm::Transition::NumberOfEventSetupTransitions) {
0217     throwESConsumesInProcessBlock();
0218   }
0219   auto indexForToken = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].size();
0220   esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back(-1 * (index + 1));
0221   esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back();
0222   return {ESTokenIndex{static_cast<ESTokenIndex::Value_t>(indexForToken)},
0223           m_esTokenInfo.get<kESLookupInfo>(index).m_key.name().value()};
0224 }
0225 
0226 //
0227 // const member functions
0228 //
0229 ProductResolverIndexAndSkipBit EDConsumerBase::indexFrom(EDGetToken iToken,
0230                                                          BranchType iBranch,
0231                                                          TypeID const& iType) const {
0232   if (UNLIKELY(iToken.index() >= m_tokenInfo.size())) {
0233     throwBadToken(iType, iToken);
0234   }
0235   const auto& info = m_tokenInfo.get<kLookupInfo>(iToken.index());
0236   if (LIKELY(iBranch == info.m_branchType)) {
0237     if (LIKELY(iType == info.m_type)) {
0238       return info.m_index;
0239     } else {
0240       throwTypeMismatch(iType, iToken);
0241     }
0242   } else {
0243     throwBranchMismatch(iBranch, iToken);
0244   }
0245   return ProductResolverIndexAndSkipBit(edm::ProductResolverIndexInvalid, false);
0246 }
0247 
0248 ProductResolverIndexAndSkipBit EDConsumerBase::uncheckedIndexFrom(EDGetToken iToken) const {
0249   return m_tokenInfo.get<kLookupInfo>(iToken.index()).m_index;
0250 }
0251 
0252 void EDConsumerBase::itemsToGet(BranchType iBranch, std::vector<ProductResolverIndexAndSkipBit>& oIndices) const {
0253   //how many are we adding?
0254   unsigned int count = 0;
0255   {
0256     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0257     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0258          ++it, ++itAlwaysGet) {
0259       if (iBranch == it->m_branchType) {
0260         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0261           if (*itAlwaysGet) {
0262             ++count;
0263           }
0264         }
0265       }
0266     }
0267   }
0268   oIndices.reserve(oIndices.size() + count);
0269   {
0270     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0271     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0272          ++it, ++itAlwaysGet) {
0273       if (iBranch == it->m_branchType) {
0274         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0275           if (*itAlwaysGet) {
0276             oIndices.push_back(it->m_index);
0277           }
0278         }
0279       }
0280     }
0281   }
0282 }
0283 
0284 void EDConsumerBase::itemsMayGet(BranchType iBranch, std::vector<ProductResolverIndexAndSkipBit>& oIndices) const {
0285   //how many are we adding?
0286   unsigned int count = 0;
0287   {
0288     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0289     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0290          ++it, ++itAlwaysGet) {
0291       if (iBranch == it->m_branchType) {
0292         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0293           if (not *itAlwaysGet) {
0294             ++count;
0295           }
0296         }
0297       }
0298     }
0299   }
0300   oIndices.reserve(oIndices.size() + count);
0301   {
0302     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0303     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0304          ++it, ++itAlwaysGet) {
0305       if (iBranch == it->m_branchType) {
0306         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0307           if (not *itAlwaysGet) {
0308             oIndices.push_back(it->m_index);
0309           }
0310         }
0311       }
0312     }
0313   }
0314 }
0315 
0316 void EDConsumerBase::labelsForToken(EDGetToken iToken, Labels& oLabels) const {
0317   unsigned int index = iToken.index();
0318   auto labels = m_tokenInfo.get<kLabels>(index);
0319   unsigned int start = labels.m_startOfModuleLabel;
0320   oLabels.module = &(m_tokenLabels[start]);
0321   oLabels.productInstance = oLabels.module + labels.m_deltaToProductInstance;
0322   oLabels.process = oLabels.module + labels.m_deltaToProcessName;
0323 }
0324 
0325 bool EDConsumerBase::registeredToConsume(ProductResolverIndex iIndex,
0326                                          bool skipCurrentProcess,
0327                                          BranchType iBranch) const {
0328   for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd; ++it) {
0329     if (it->m_index.productResolverIndex() == iIndex and it->m_index.skipCurrentProcess() == skipCurrentProcess and
0330         it->m_branchType == iBranch) {
0331       return true;
0332     }
0333   }
0334   return false;
0335 }
0336 
0337 void EDConsumerBase::throwTypeMismatch(edm::TypeID const& iType, EDGetToken iToken) const {
0338   throw cms::Exception("TypeMismatch") << "A get using a EDGetToken used the C++ type '" << iType.className()
0339                                        << "' but the consumes call was for type '"
0340                                        << m_tokenInfo.get<kLookupInfo>(iToken.index()).m_type.className()
0341                                        << "'.\n Please modify either the consumes or get call so the types match.";
0342 }
0343 void EDConsumerBase::throwBranchMismatch(BranchType iBranch, EDGetToken iToken) const {
0344   throw cms::Exception("BranchTypeMismatch")
0345       << "A get using a EDGetToken was done in " << BranchTypeToString(iBranch) << " but the consumes call was for "
0346       << BranchTypeToString(m_tokenInfo.get<kLookupInfo>(iToken.index()).m_branchType)
0347       << ".\n Please modify the consumes call to use the correct branch type.";
0348 }
0349 
0350 void EDConsumerBase::throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const {
0351   if (iToken.isUninitialized()) {
0352     throw cms::Exception("BadToken") << "A get using a EDGetToken with the C++ type '" << iType.className()
0353                                      << "' was made using an uninitialized token.\n Please check that the variable is "
0354                                         "being initialized from a 'consumes' call.";
0355   }
0356   throw cms::Exception("BadToken")
0357       << "A get using a EDGetToken with the C++ type '" << iType.className() << "' was made using a token with a value "
0358       << iToken.index()
0359       << " which is beyond the range used by this module.\n Please check that the variable is being initialized from a "
0360          "'consumes' call from this module.\n You can not share EDGetToken values between modules.";
0361 }
0362 
0363 void EDConsumerBase::throwConsumesCallAfterFrozen(TypeToGet const& typeToGet, InputTag const& inputTag) const {
0364   throw cms::Exception("LogicError") << "A module declared it consumes a product after its constructor.\n"
0365                                      << "This must be done in the contructor\n"
0366                                      << "The product type was: " << typeToGet.type() << "\n"
0367                                      << "and " << inputTag << "\n";
0368 }
0369 
0370 void EDConsumerBase::throwESConsumesCallAfterFrozen(eventsetup::EventSetupRecordKey const& iRecord,
0371                                                     eventsetup::heterocontainer::HCTypeTag const& iDataType,
0372                                                     edm::ESInputTag const& iTag) const {
0373   throw cms::Exception("LogicError") << "A module declared it consumes an EventSetup product after its constructor.\n"
0374                                      << "This must be done in the contructor\n"
0375                                      << "The product type was: " << iDataType.name() << " in record "
0376                                      << iRecord.type().name() << "\n"
0377                                      << "and ESInputTag was " << iTag << "\n";
0378 }
0379 
0380 void EDConsumerBase::throwESConsumesInProcessBlock() const {
0381   throw cms::Exception("LogicError")
0382       << "A module declared it consumes an EventSetup product during a ProcessBlock transition.\n"
0383       << "EventSetup products can only be consumed in Event, Lumi, or Run transitions.\n";
0384 }
0385 
0386 void EDConsumerBase::doSelectInputProcessBlocks(ProductRegistry const&, ProcessBlockHelperBase const&) {}
0387 
0388 namespace {
0389   struct CharStarComp {
0390     bool operator()(const char* iLHS, const char* iRHS) const { return strcmp(iLHS, iRHS) < 0; }
0391   };
0392 }  // namespace
0393 
0394 namespace {
0395   void insertFoundModuleLabel(edm::KindOfType consumedTypeKind,
0396                               edm::TypeID consumedType,
0397                               const char* consumedModuleLabel,
0398                               const char* consumedProductInstance,
0399                               std::vector<ModuleDescription const*>& modules,
0400                               std::set<std::string>& alreadyFound,
0401                               std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0402                               ProductRegistry const& preg) {
0403     // Convert from label string to module description, eliminate duplicates,
0404     // then insert into the vector of modules
0405     if (auto it = labelsToDesc.find(consumedModuleLabel); it != labelsToDesc.end()) {
0406       if (alreadyFound.insert(consumedModuleLabel).second) {
0407         modules.push_back(it->second);
0408       }
0409       return;
0410     }
0411     // Deal with EDAlias's by converting to the original module label first
0412     if (auto aliasToModuleLabels =
0413             preg.aliasToModules(consumedTypeKind, consumedType, consumedModuleLabel, consumedProductInstance);
0414         not aliasToModuleLabels.empty()) {
0415       bool foundInLabelsToDesc = false;
0416       for (auto const& label : aliasToModuleLabels) {
0417         if (auto it = labelsToDesc.find(label); it != labelsToDesc.end()) {
0418           if (alreadyFound.insert(label).second) {
0419             modules.push_back(it->second);
0420           }
0421           foundInLabelsToDesc = true;
0422         } else {
0423           if (label == "source") {
0424             foundInLabelsToDesc = true;
0425           }
0426         }
0427       }
0428       if (foundInLabelsToDesc) {
0429         return;
0430       }
0431     }
0432     // Ignore the source products, we are only interested in module products.
0433     // As far as I know, it should never be anything else so throw if something
0434     // unknown gets passed in.
0435     if (std::string_view(consumedModuleLabel) != "source") {
0436       throw cms::Exception("EDConsumerBase", "insertFoundModuleLabel")
0437           << "Couldn't find ModuleDescription for the consumed product type: '" << consumedType.className()
0438           << "' module label: '" << consumedModuleLabel << "' product instance name: '" << consumedProductInstance
0439           << "'";
0440     }
0441   }
0442 }  // namespace
0443 
0444 void EDConsumerBase::modulesWhoseProductsAreConsumed(
0445     std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
0446     std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0447     ProductRegistry const& preg,
0448     std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0449     std::string const& processName) const {
0450   std::set<std::string> alreadyFound;
0451 
0452   auto modulesInPreviousProcessesEmplace = [&modulesInPreviousProcesses](std::string_view module,
0453                                                                          std::string_view process) {
0454     auto it = std::lower_bound(
0455         modulesInPreviousProcesses.begin(), modulesInPreviousProcesses.end(), ModuleProcessName(module, process));
0456     modulesInPreviousProcesses.emplace(it, module, process);
0457   };
0458 
0459   auto itKind = m_tokenInfo.begin<kKind>();
0460   auto itLabels = m_tokenInfo.begin<kLabels>();
0461   for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
0462        ++itInfo, ++itKind, ++itLabels) {
0463     ProductResolverIndexHelper const& helper = *preg.productLookup(itInfo->m_branchType);
0464     std::vector<ModuleDescription const*>& modules = *modulesAll[itInfo->m_branchType];
0465 
0466     const unsigned int labelStart = itLabels->m_startOfModuleLabel;
0467     const char* const consumedModuleLabel = &(m_tokenLabels[labelStart]);
0468     const char* const consumedProductInstance = consumedModuleLabel + itLabels->m_deltaToProductInstance;
0469     const char* const consumedProcessName = consumedModuleLabel + itLabels->m_deltaToProcessName;
0470 
0471     if (not itInfo->m_index.skipCurrentProcess()) {
0472       assert(*consumedModuleLabel != '\0');  // consumesMany used to create empty labels before we removed consumesMany
0473       if (*consumedProcessName != '\0') {    // process name is specified in consumes call
0474         if (helper.index(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance, consumedProcessName) !=
0475             ProductResolverIndexInvalid) {
0476           if (processName == consumedProcessName) {
0477             insertFoundModuleLabel(*itKind,
0478                                    itInfo->m_type,
0479                                    consumedModuleLabel,
0480                                    consumedProductInstance,
0481                                    modules,
0482                                    alreadyFound,
0483                                    labelsToDesc,
0484                                    preg);
0485           } else {
0486             // Product explicitly from different process than the current process, so must refer to an earlier process (unless it ends up "not found")
0487             modulesInPreviousProcessesEmplace(consumedModuleLabel, consumedProcessName);
0488           }
0489         }
0490       } else {  // process name was empty
0491         auto matches = helper.relatedIndexes(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance);
0492         for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
0493           if (processName == matches.processName(j)) {
0494             insertFoundModuleLabel(*itKind,
0495                                    itInfo->m_type,
0496                                    consumedModuleLabel,
0497                                    consumedProductInstance,
0498                                    modules,
0499                                    alreadyFound,
0500                                    labelsToDesc,
0501                                    preg);
0502           } else {
0503             // Product did not match to current process, so must refer to an earlier process (unless it ends up "not found")
0504             // Recall that empty process name means "in the latest process" that can change event-by-event
0505             modulesInPreviousProcessesEmplace(consumedModuleLabel, matches.processName(j));
0506           }
0507         }
0508       }
0509     } else {
0510       // The skipCurrentProcess means the same as empty process name,
0511       // except the current process is skipped. Therefore need to do
0512       // the same matching as above.
0513       auto matches = helper.relatedIndexes(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance);
0514       for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
0515         if (processName != matches.processName(j)) {
0516           modulesInPreviousProcessesEmplace(matches.moduleLabel(j), matches.processName(j));
0517         }
0518       }
0519     }
0520   }
0521 }
0522 
0523 void EDConsumerBase::convertCurrentProcessAlias(std::string const& processName) {
0524   frozen_ = true;
0525 
0526   if (containsCurrentProcessAlias_) {
0527     containsCurrentProcessAlias_ = false;
0528 
0529     auto newTokenLabels = makeEmptyTokenLabels();
0530 
0531     // first calculate the size of the new vector and reserve memory for it
0532     std::vector<char>::size_type newSize = newTokenLabels.size();
0533     std::string newProcessName;
0534     for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
0535       newProcessName = &m_tokenLabels[iter->m_startOfModuleLabel + iter->m_deltaToProcessName];
0536       if (newProcessName == InputTag::kCurrentProcess) {
0537         newProcessName = processName;
0538       }
0539       newSize += (iter->m_deltaToProcessName + newProcessName.size() + 1);
0540     }
0541     newTokenLabels.reserve(newSize);
0542 
0543     unsigned int newStartOfModuleLabel = newTokenLabels.size();
0544     for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
0545       unsigned int startOfModuleLabel = iter->m_startOfModuleLabel;
0546       unsigned short deltaToProcessName = iter->m_deltaToProcessName;
0547 
0548       iter->m_startOfModuleLabel = newStartOfModuleLabel;
0549 
0550       newProcessName = &m_tokenLabels[startOfModuleLabel + deltaToProcessName];
0551       if (newProcessName == InputTag::kCurrentProcess) {
0552         newProcessName = processName;
0553       }
0554 
0555       newStartOfModuleLabel += (deltaToProcessName + newProcessName.size() + 1);
0556 
0557       // Copy in both the module label and instance, they are the same
0558       newTokenLabels.insert(newTokenLabels.end(),
0559                             m_tokenLabels.begin() + startOfModuleLabel,
0560                             m_tokenLabels.begin() + (startOfModuleLabel + deltaToProcessName));
0561 
0562       newTokenLabels.insert(newTokenLabels.end(), newProcessName.begin(), newProcessName.end());
0563       newTokenLabels.push_back('\0');
0564     }
0565     m_tokenLabels = std::move(newTokenLabels);
0566   }
0567 }
0568 
0569 std::vector<ConsumesInfo> EDConsumerBase::consumesInfo() const {
0570   std::vector<ConsumesInfo> result;
0571   auto itAlways = m_tokenInfo.begin<kAlwaysGets>();
0572   auto itKind = m_tokenInfo.begin<kKind>();
0573   auto itLabels = m_tokenInfo.begin<kLabels>();
0574   for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
0575        ++itInfo, ++itKind, ++itLabels, ++itAlways) {
0576     const unsigned int labelStart = itLabels->m_startOfModuleLabel;
0577     const char* consumedModuleLabel = &(m_tokenLabels[labelStart]);
0578     const char* consumedInstance = consumedModuleLabel + itLabels->m_deltaToProductInstance;
0579     const char* consumedProcessName = consumedModuleLabel + itLabels->m_deltaToProcessName;
0580 
0581     assert(*consumedModuleLabel != '\0');
0582 
0583     // Just copy the information into the ConsumesInfo data structure
0584     result.emplace_back(itInfo->m_type,
0585                         consumedModuleLabel,
0586                         consumedInstance,
0587                         consumedProcessName,
0588                         itInfo->m_branchType,
0589                         *itKind,
0590                         *itAlways,
0591                         itInfo->m_index.skipCurrentProcess());
0592   }
0593   return result;
0594 }