Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-03 00:59:00

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/ESRecordsToProxyIndices.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::updateLookup(BranchType iBranchType,
0114                                   ProductResolverIndexHelper const& iHelper,
0115                                   bool iPrefetchMayGet) {
0116   frozen_ = true;
0117   assert(!containsCurrentProcessAlias_);
0118   {
0119     auto itKind = m_tokenInfo.begin<kKind>();
0120     auto itLabels = m_tokenInfo.begin<kLabels>();
0121     for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
0122          ++itInfo, ++itKind, ++itLabels) {
0123       if (itInfo->m_branchType == iBranchType) {
0124         const unsigned int labelStart = itLabels->m_startOfModuleLabel;
0125         const char* moduleLabel = &(m_tokenLabels[labelStart]);
0126         itInfo->m_index = ProductResolverIndexAndSkipBit(iHelper.index(*itKind,
0127                                                                        itInfo->m_type,
0128                                                                        moduleLabel,
0129                                                                        moduleLabel + itLabels->m_deltaToProductInstance,
0130                                                                        moduleLabel + itLabels->m_deltaToProcessName),
0131                                                          itInfo->m_index.skipCurrentProcess());
0132       }
0133     }
0134   }
0135 
0136   //now add resolved requests to get many to the end of our list
0137   // a get many will have an empty module label
0138   for (size_t i = 0, iEnd = m_tokenInfo.size(); i != iEnd; ++i) {
0139     //need to copy since pointer could be invalidated by emplace_back
0140     auto const info = m_tokenInfo.get<kLookupInfo>(i);
0141     if (info.m_branchType == iBranchType && info.m_index.productResolverIndex() == ProductResolverIndexInvalid &&
0142         m_tokenLabels[m_tokenInfo.get<kLabels>(i).m_startOfModuleLabel] == '\0') {
0143       //find all matching types
0144       const auto kind = m_tokenInfo.get<kKind>(i);
0145       auto matches = iHelper.relatedIndexes(kind, info.m_type);
0146 
0147       //NOTE: This could be changed to contain the true labels for what is being
0148       // requested but for now I want to remember these are part of a get many
0149       const LabelPlacement labels = m_tokenInfo.get<kLabels>(i);
0150       bool alwaysGet = m_tokenInfo.get<kAlwaysGets>(i);
0151       for (unsigned int j = 0; j != matches.numberOfMatches(); ++j) {
0152         //only keep the ones that are for a specific data item and not a collection
0153         if (matches.isFullyResolved(j)) {
0154           auto index = matches.index(j);
0155           m_tokenInfo.emplace_back(
0156               TokenLookupInfo{info.m_type, index, info.m_index.skipCurrentProcess(), info.m_branchType},
0157               alwaysGet,
0158               labels,
0159               kind);
0160         }
0161       }
0162     }
0163   }
0164   m_tokenInfo.shrink_to_fit();
0165 
0166   itemsToGet(iBranchType, itemsToGetFromBranch_[iBranchType]);
0167   if (iPrefetchMayGet) {
0168     itemsMayGet(iBranchType, itemsToGetFromBranch_[iBranchType]);
0169   }
0170 }
0171 
0172 void EDConsumerBase::updateLookup(eventsetup::ESRecordsToProxyIndices const& iPI) {
0173   // temporarily unfreeze to allow late EventSetup consumes registration
0174   frozen_ = false;
0175   registerLateConsumes(iPI);
0176   frozen_ = true;
0177 
0178   unsigned int index = 0;
0179   for (auto it = m_esTokenInfo.begin<kESLookupInfo>(); it != m_esTokenInfo.end<kESLookupInfo>(); ++it, ++index) {
0180     auto indexInRecord = iPI.indexInRecord(it->m_record, it->m_key);
0181     if (indexInRecord != eventsetup::ESRecordsToProxyIndices::missingProxyIndex()) {
0182       const char* componentName = &(m_tokenLabels[it->m_startOfComponentName]);
0183       if (*componentName) {
0184         auto component = iPI.component(it->m_record, it->m_key);
0185         if (component->label_.empty()) {
0186           if (component->type_ != componentName) {
0187             indexInRecord = eventsetup::ESRecordsToProxyIndices::missingProxyIndex();
0188           }
0189         } else if (component->label_ != componentName) {
0190           indexInRecord = eventsetup::ESRecordsToProxyIndices::missingProxyIndex();
0191         }
0192       }
0193     }
0194     m_esTokenInfo.get<kESProxyIndex>(index) = indexInRecord;
0195 
0196     int negIndex = -1 * (index + 1);
0197     for (auto& items : esItemsToGetFromTransition_) {
0198       for (auto& itemIndex : items) {
0199         if (itemIndex.value() == negIndex) {
0200           itemIndex = indexInRecord;
0201           esRecordsToGetFromTransition_[&items - &esItemsToGetFromTransition_.front()][&itemIndex - &items.front()] =
0202               iPI.recordIndexFor(it->m_record);
0203           negIndex = 1;
0204           break;
0205         }
0206       }
0207       if (negIndex > 0) {
0208         break;
0209       }
0210     }
0211   }
0212 }
0213 
0214 ESTokenIndex EDConsumerBase::recordESConsumes(Transition iTrans,
0215                                               eventsetup::EventSetupRecordKey const& iRecord,
0216                                               eventsetup::heterocontainer::HCTypeTag const& iDataType,
0217                                               edm::ESInputTag const& iTag) {
0218   if (frozen_) {
0219     throwESConsumesCallAfterFrozen(iRecord, iDataType, iTag);
0220   }
0221 
0222   //m_tokenLabels first entry is a null. Since most ES data requests have
0223   // empty labels we will assume we can reuse the first entry
0224   unsigned int startOfComponentName = 0;
0225   if (not iTag.module().empty()) {
0226     startOfComponentName = m_tokenLabels.size();
0227 
0228     m_tokenLabels.reserve(m_tokenLabels.size() + iTag.module().size() + 1);
0229     {
0230       const std::string& m = iTag.module();
0231       m_tokenLabels.insert(m_tokenLabels.end(), m.begin(), m.end());
0232       m_tokenLabels.push_back('\0');
0233     }
0234   }
0235 
0236   auto index = static_cast<ESProxyIndex::Value_t>(m_esTokenInfo.size());
0237   m_esTokenInfo.emplace_back(
0238       ESTokenLookupInfo{iRecord, eventsetup::DataKey{iDataType, iTag.data().c_str()}, startOfComponentName},
0239       ESProxyIndex{-1});
0240   if (iTrans >= edm::Transition::NumberOfEventSetupTransitions) {
0241     throwESConsumesInProcessBlock();
0242   }
0243   auto indexForToken = esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].size();
0244   esItemsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back(-1 * (index + 1));
0245   esRecordsToGetFromTransition_[static_cast<unsigned int>(iTrans)].emplace_back();
0246   return ESTokenIndex{static_cast<ESTokenIndex::Value_t>(indexForToken)};
0247 }
0248 
0249 //
0250 // const member functions
0251 //
0252 ProductResolverIndexAndSkipBit EDConsumerBase::indexFrom(EDGetToken iToken,
0253                                                          BranchType iBranch,
0254                                                          TypeID const& iType) const {
0255   if (UNLIKELY(iToken.index() >= m_tokenInfo.size())) {
0256     throwBadToken(iType, iToken);
0257   }
0258   const auto& info = m_tokenInfo.get<kLookupInfo>(iToken.index());
0259   if (LIKELY(iBranch == info.m_branchType)) {
0260     if (LIKELY(iType == info.m_type)) {
0261       return info.m_index;
0262     } else {
0263       throwTypeMismatch(iType, iToken);
0264     }
0265   } else {
0266     throwBranchMismatch(iBranch, iToken);
0267   }
0268   return ProductResolverIndexAndSkipBit(edm::ProductResolverIndexInvalid, false);
0269 }
0270 
0271 ProductResolverIndexAndSkipBit EDConsumerBase::uncheckedIndexFrom(EDGetToken iToken) const {
0272   return m_tokenInfo.get<kLookupInfo>(iToken.index()).m_index;
0273 }
0274 
0275 void EDConsumerBase::itemsToGet(BranchType iBranch, std::vector<ProductResolverIndexAndSkipBit>& oIndices) const {
0276   //how many are we adding?
0277   unsigned int count = 0;
0278   {
0279     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0280     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0281          ++it, ++itAlwaysGet) {
0282       if (iBranch == it->m_branchType) {
0283         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0284           if (*itAlwaysGet) {
0285             ++count;
0286           }
0287         }
0288       }
0289     }
0290   }
0291   oIndices.reserve(oIndices.size() + count);
0292   {
0293     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0294     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0295          ++it, ++itAlwaysGet) {
0296       if (iBranch == it->m_branchType) {
0297         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0298           if (*itAlwaysGet) {
0299             oIndices.push_back(it->m_index);
0300           }
0301         }
0302       }
0303     }
0304   }
0305 }
0306 
0307 void EDConsumerBase::itemsMayGet(BranchType iBranch, std::vector<ProductResolverIndexAndSkipBit>& oIndices) const {
0308   //how many are we adding?
0309   unsigned int count = 0;
0310   {
0311     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0312     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0313          ++it, ++itAlwaysGet) {
0314       if (iBranch == it->m_branchType) {
0315         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0316           if (not *itAlwaysGet) {
0317             ++count;
0318           }
0319         }
0320       }
0321     }
0322   }
0323   oIndices.reserve(oIndices.size() + count);
0324   {
0325     auto itAlwaysGet = m_tokenInfo.begin<kAlwaysGets>();
0326     for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd;
0327          ++it, ++itAlwaysGet) {
0328       if (iBranch == it->m_branchType) {
0329         if (it->m_index.productResolverIndex() != ProductResolverIndexInvalid) {
0330           if (not *itAlwaysGet) {
0331             oIndices.push_back(it->m_index);
0332           }
0333         }
0334       }
0335     }
0336   }
0337 }
0338 
0339 void EDConsumerBase::labelsForToken(EDGetToken iToken, Labels& oLabels) const {
0340   unsigned int index = iToken.index();
0341   auto labels = m_tokenInfo.get<kLabels>(index);
0342   unsigned int start = labels.m_startOfModuleLabel;
0343   oLabels.module = &(m_tokenLabels[start]);
0344   oLabels.productInstance = oLabels.module + labels.m_deltaToProductInstance;
0345   oLabels.process = oLabels.module + labels.m_deltaToProcessName;
0346 }
0347 
0348 bool EDConsumerBase::registeredToConsume(ProductResolverIndex iIndex,
0349                                          bool skipCurrentProcess,
0350                                          BranchType iBranch) const {
0351   for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd; ++it) {
0352     if (it->m_index.productResolverIndex() == iIndex and it->m_index.skipCurrentProcess() == skipCurrentProcess and
0353         it->m_branchType == iBranch) {
0354       return true;
0355     }
0356   }
0357   return false;
0358 }
0359 
0360 bool EDConsumerBase::registeredToConsumeMany(TypeID const& iType, BranchType iBranch) const {
0361   for (auto it = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); it != itEnd; ++it) {
0362     //consumesMany entries do not have their index resolved
0363     if (it->m_index.productResolverIndex() == ProductResolverIndexInvalid and it->m_type == iType and
0364         it->m_branchType == iBranch) {
0365       return true;
0366     }
0367   }
0368   return false;
0369 }
0370 
0371 void EDConsumerBase::throwTypeMismatch(edm::TypeID const& iType, EDGetToken iToken) const {
0372   throw cms::Exception("TypeMismatch") << "A get using a EDGetToken used the C++ type '" << iType.className()
0373                                        << "' but the consumes call was for type '"
0374                                        << m_tokenInfo.get<kLookupInfo>(iToken.index()).m_type.className()
0375                                        << "'.\n Please modify either the consumes or get call so the types match.";
0376 }
0377 void EDConsumerBase::throwBranchMismatch(BranchType iBranch, EDGetToken iToken) const {
0378   throw cms::Exception("BranchTypeMismatch")
0379       << "A get using a EDGetToken was done in " << BranchTypeToString(iBranch) << " but the consumes call was for "
0380       << BranchTypeToString(m_tokenInfo.get<kLookupInfo>(iToken.index()).m_branchType)
0381       << ".\n Please modify the consumes call to use the correct branch type.";
0382 }
0383 
0384 void EDConsumerBase::throwBadToken(edm::TypeID const& iType, EDGetToken iToken) const {
0385   if (iToken.isUninitialized()) {
0386     throw cms::Exception("BadToken") << "A get using a EDGetToken with the C++ type '" << iType.className()
0387                                      << "' was made using an uninitialized token.\n Please check that the variable is "
0388                                         "being initialized from a 'consumes' call.";
0389   }
0390   throw cms::Exception("BadToken")
0391       << "A get using a EDGetToken with the C++ type '" << iType.className() << "' was made using a token with a value "
0392       << iToken.index()
0393       << " which is beyond the range used by this module.\n Please check that the variable is being initialized from a "
0394          "'consumes' call from this module.\n You can not share EDGetToken values between modules.";
0395 }
0396 
0397 void EDConsumerBase::throwConsumesCallAfterFrozen(TypeToGet const& typeToGet, InputTag const& inputTag) const {
0398   throw cms::Exception("LogicError") << "A module declared it consumes a product after its constructor.\n"
0399                                      << "This must be done in the contructor\n"
0400                                      << "The product type was: " << typeToGet.type() << "\n"
0401                                      << "and " << inputTag << "\n";
0402 }
0403 
0404 void EDConsumerBase::throwESConsumesCallAfterFrozen(eventsetup::EventSetupRecordKey const& iRecord,
0405                                                     eventsetup::heterocontainer::HCTypeTag const& iDataType,
0406                                                     edm::ESInputTag const& iTag) const {
0407   throw cms::Exception("LogicError") << "A module declared it consumes an EventSetup product after its constructor.\n"
0408                                      << "This must be done in the contructor\n"
0409                                      << "The product type was: " << iDataType.name() << " in record "
0410                                      << iRecord.type().name() << "\n"
0411                                      << "and ESInputTag was " << iTag << "\n";
0412 }
0413 
0414 void EDConsumerBase::throwESConsumesInProcessBlock() const {
0415   throw cms::Exception("LogicError")
0416       << "A module declared it consumes an EventSetup product during a ProcessBlock transition.\n"
0417       << "EventSetup products can only be consumed in Event, Lumi, or Run transitions.\n";
0418 }
0419 
0420 void EDConsumerBase::doSelectInputProcessBlocks(ProductRegistry const&, ProcessBlockHelperBase const&) {}
0421 
0422 namespace {
0423   struct CharStarComp {
0424     bool operator()(const char* iLHS, const char* iRHS) const { return strcmp(iLHS, iRHS) < 0; }
0425   };
0426 }  // namespace
0427 
0428 namespace {
0429   void insertFoundModuleLabel(edm::KindOfType consumedTypeKind,
0430                               edm::TypeID consumedType,
0431                               const char* consumedModuleLabel,
0432                               const char* consumedProductInstance,
0433                               std::vector<ModuleDescription const*>& modules,
0434                               std::set<std::string>& alreadyFound,
0435                               std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0436                               ProductRegistry const& preg) {
0437     // Convert from label string to module description, eliminate duplicates,
0438     // then insert into the vector of modules
0439     if (auto it = labelsToDesc.find(consumedModuleLabel); it != labelsToDesc.end()) {
0440       if (alreadyFound.insert(consumedModuleLabel).second) {
0441         modules.push_back(it->second);
0442       }
0443       return;
0444     }
0445     // Deal with EDAlias's by converting to the original module label first
0446     if (auto aliasToModuleLabels =
0447             preg.aliasToModules(consumedTypeKind, consumedType, consumedModuleLabel, consumedProductInstance);
0448         not aliasToModuleLabels.empty()) {
0449       bool foundInLabelsToDesc = false;
0450       for (auto const& label : aliasToModuleLabels) {
0451         if (auto it = labelsToDesc.find(label); it != labelsToDesc.end()) {
0452           if (alreadyFound.insert(label).second) {
0453             modules.push_back(it->second);
0454           }
0455           foundInLabelsToDesc = true;
0456         } else {
0457           if (label == "source") {
0458             foundInLabelsToDesc = true;
0459           }
0460         }
0461       }
0462       if (foundInLabelsToDesc) {
0463         return;
0464       }
0465     }
0466     // Ignore the source products, we are only interested in module products.
0467     // As far as I know, it should never be anything else so throw if something
0468     // unknown gets passed in.
0469     if (std::string_view(consumedModuleLabel) != "source") {
0470       throw cms::Exception("EDConsumerBase", "insertFoundModuleLabel")
0471           << "Couldn't find ModuleDescription for the consumed product type: '" << consumedType.className()
0472           << "' module label: '" << consumedModuleLabel << "' product instance name: '" << consumedProductInstance
0473           << "'";
0474     }
0475   }
0476 }  // namespace
0477 
0478 void EDConsumerBase::modulesWhoseProductsAreConsumed(
0479     std::array<std::vector<ModuleDescription const*>*, NumBranchTypes>& modulesAll,
0480     std::vector<ModuleProcessName>& modulesInPreviousProcesses,
0481     ProductRegistry const& preg,
0482     std::map<std::string, ModuleDescription const*> const& labelsToDesc,
0483     std::string const& processName) const {
0484   std::set<std::string> alreadyFound;
0485 
0486   auto modulesInPreviousProcessesEmplace = [&modulesInPreviousProcesses](std::string_view module,
0487                                                                          std::string_view process) {
0488     auto it = std::lower_bound(
0489         modulesInPreviousProcesses.begin(), modulesInPreviousProcesses.end(), ModuleProcessName(module, process));
0490     modulesInPreviousProcesses.emplace(it, module, process);
0491   };
0492 
0493   auto itKind = m_tokenInfo.begin<kKind>();
0494   auto itLabels = m_tokenInfo.begin<kLabels>();
0495   for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
0496        ++itInfo, ++itKind, ++itLabels) {
0497     ProductResolverIndexHelper const& helper = *preg.productLookup(itInfo->m_branchType);
0498     std::vector<ModuleDescription const*>& modules = *modulesAll[itInfo->m_branchType];
0499 
0500     const unsigned int labelStart = itLabels->m_startOfModuleLabel;
0501     const char* const consumedModuleLabel = &(m_tokenLabels[labelStart]);
0502     const char* const consumedProductInstance = consumedModuleLabel + itLabels->m_deltaToProductInstance;
0503     const char* const consumedProcessName = consumedModuleLabel + itLabels->m_deltaToProcessName;
0504 
0505     if (not itInfo->m_index.skipCurrentProcess()) {
0506       if (*consumedModuleLabel != '\0') {    // not a consumesMany
0507         if (*consumedProcessName != '\0') {  // process name is specified in consumes call
0508           if (helper.index(
0509                   *itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance, consumedProcessName) !=
0510               ProductResolverIndexInvalid) {
0511             if (processName == consumedProcessName) {
0512               insertFoundModuleLabel(*itKind,
0513                                      itInfo->m_type,
0514                                      consumedModuleLabel,
0515                                      consumedProductInstance,
0516                                      modules,
0517                                      alreadyFound,
0518                                      labelsToDesc,
0519                                      preg);
0520             } else {
0521               // Product explicitly from different process than the current process, so must refer to an earlier process (unless it ends up "not found")
0522               modulesInPreviousProcessesEmplace(consumedModuleLabel, consumedProcessName);
0523             }
0524           }
0525         } else {  // process name was empty
0526           auto matches = helper.relatedIndexes(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance);
0527           for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
0528             if (processName == matches.processName(j)) {
0529               insertFoundModuleLabel(*itKind,
0530                                      itInfo->m_type,
0531                                      consumedModuleLabel,
0532                                      consumedProductInstance,
0533                                      modules,
0534                                      alreadyFound,
0535                                      labelsToDesc,
0536                                      preg);
0537             } else {
0538               // Product did not match to current process, so must refer to an earlier process (unless it ends up "not found")
0539               // Recall that empty process name means "in the latest process" that can change event-by-event
0540               modulesInPreviousProcessesEmplace(consumedModuleLabel, matches.processName(j));
0541             }
0542           }
0543         }
0544         // consumesMany case
0545       } else if (itInfo->m_index.productResolverIndex() == ProductResolverIndexInvalid) {
0546         auto matches = helper.relatedIndexes(*itKind, itInfo->m_type);
0547         for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
0548           if (processName == matches.processName(j)) {
0549             insertFoundModuleLabel(*itKind,
0550                                    itInfo->m_type,
0551                                    matches.moduleLabel(j),
0552                                    matches.productInstanceName(j),
0553                                    modules,
0554                                    alreadyFound,
0555                                    labelsToDesc,
0556                                    preg);
0557           } else {
0558             modulesInPreviousProcessesEmplace(matches.moduleLabel(j), matches.processName(j));
0559           }
0560         }
0561       }
0562     } else {
0563       // The skipCurrentProcess means the same as empty process name,
0564       // except the current process is skipped. Therefore need to do
0565       // the same matching as above. There is no consumesMany branch
0566       // in this case.
0567       auto matches = helper.relatedIndexes(*itKind, itInfo->m_type, consumedModuleLabel, consumedProductInstance);
0568       for (unsigned int j = 0; j < matches.numberOfMatches(); ++j) {
0569         if (processName != matches.processName(j)) {
0570           modulesInPreviousProcessesEmplace(matches.moduleLabel(j), matches.processName(j));
0571         }
0572       }
0573     }
0574   }
0575 }
0576 
0577 void EDConsumerBase::convertCurrentProcessAlias(std::string const& processName) {
0578   frozen_ = true;
0579 
0580   if (containsCurrentProcessAlias_) {
0581     containsCurrentProcessAlias_ = false;
0582 
0583     auto newTokenLabels = makeEmptyTokenLabels();
0584 
0585     // first calculate the size of the new vector and reserve memory for it
0586     std::vector<char>::size_type newSize = newTokenLabels.size();
0587     std::string newProcessName;
0588     for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
0589       newProcessName = &m_tokenLabels[iter->m_startOfModuleLabel + iter->m_deltaToProcessName];
0590       if (newProcessName == InputTag::kCurrentProcess) {
0591         newProcessName = processName;
0592       }
0593       newSize += (iter->m_deltaToProcessName + newProcessName.size() + 1);
0594     }
0595     newTokenLabels.reserve(newSize);
0596 
0597     unsigned int newStartOfModuleLabel = newTokenLabels.size();
0598     for (auto iter = m_tokenInfo.begin<kLabels>(), itEnd = m_tokenInfo.end<kLabels>(); iter != itEnd; ++iter) {
0599       unsigned int startOfModuleLabel = iter->m_startOfModuleLabel;
0600       unsigned short deltaToProcessName = iter->m_deltaToProcessName;
0601 
0602       iter->m_startOfModuleLabel = newStartOfModuleLabel;
0603 
0604       newProcessName = &m_tokenLabels[startOfModuleLabel + deltaToProcessName];
0605       if (newProcessName == InputTag::kCurrentProcess) {
0606         newProcessName = processName;
0607       }
0608 
0609       newStartOfModuleLabel += (deltaToProcessName + newProcessName.size() + 1);
0610 
0611       // Copy in both the module label and instance, they are the same
0612       newTokenLabels.insert(newTokenLabels.end(),
0613                             m_tokenLabels.begin() + startOfModuleLabel,
0614                             m_tokenLabels.begin() + (startOfModuleLabel + deltaToProcessName));
0615 
0616       newTokenLabels.insert(newTokenLabels.end(), newProcessName.begin(), newProcessName.end());
0617       newTokenLabels.push_back('\0');
0618     }
0619     m_tokenLabels = std::move(newTokenLabels);
0620   }
0621 }
0622 
0623 std::vector<ConsumesInfo> EDConsumerBase::consumesInfo() const {
0624   // Use this to eliminate duplicate entries related
0625   // to consumesMany items where only the type was specified
0626   // and the there are multiple matches. In these cases the
0627   // label, instance, and process will be empty.
0628   std::set<edm::TypeID> alreadySeenTypes;
0629 
0630   std::vector<ConsumesInfo> result;
0631   auto itAlways = m_tokenInfo.begin<kAlwaysGets>();
0632   auto itKind = m_tokenInfo.begin<kKind>();
0633   auto itLabels = m_tokenInfo.begin<kLabels>();
0634   for (auto itInfo = m_tokenInfo.begin<kLookupInfo>(), itEnd = m_tokenInfo.end<kLookupInfo>(); itInfo != itEnd;
0635        ++itInfo, ++itKind, ++itLabels, ++itAlways) {
0636     const unsigned int labelStart = itLabels->m_startOfModuleLabel;
0637     const char* consumedModuleLabel = &(m_tokenLabels[labelStart]);
0638     const char* consumedInstance = consumedModuleLabel + itLabels->m_deltaToProductInstance;
0639     const char* consumedProcessName = consumedModuleLabel + itLabels->m_deltaToProcessName;
0640 
0641     // consumesMany case
0642     if (*consumedModuleLabel == '\0') {
0643       if (!alreadySeenTypes.insert(itInfo->m_type).second) {
0644         continue;
0645       }
0646     }
0647 
0648     // Just copy the information into the ConsumesInfo data structure
0649     result.emplace_back(itInfo->m_type,
0650                         consumedModuleLabel,
0651                         consumedInstance,
0652                         consumedProcessName,
0653                         itInfo->m_branchType,
0654                         *itKind,
0655                         *itAlways,
0656                         itInfo->m_index.skipCurrentProcess());
0657   }
0658   return result;
0659 }
0660 
0661 const char* EDConsumerBase::labelFor(ESTokenIndex iIndex) const {
0662   return m_esTokenInfo.get<kESLookupInfo>(iIndex.value()).m_key.name().value();
0663 }