File indexing completed on 2025-01-31 02:19:18
0001 #include "FWCore/Common/interface/ProcessBlockHelperBase.h"
0002
0003 #include "DataFormats/Provenance/interface/ProductDescription.h"
0004 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0005 #include "FWCore/Utilities/interface/BranchType.h"
0006 #include "FWCore/Utilities/interface/ProductLabels.h"
0007 #include "FWCore/Utilities/interface/TypeID.h"
0008
0009 #include <algorithm>
0010 #include <iterator>
0011
0012 namespace edm {
0013
0014 ProcessBlockHelperBase::~ProcessBlockHelperBase() = default;
0015
0016 void ProcessBlockHelperBase::updateForNewProcess(ProductRegistry const& productRegistry,
0017 std::string const& processName) {
0018
0019
0020 for (auto const& product : productRegistry.productList()) {
0021 auto const& desc = product.second;
0022 if (desc.branchType() == InProcess && desc.produced() && !desc.transient()) {
0023 processesWithProcessBlockProducts_.emplace_back(processName);
0024 addedProcesses_.emplace_back(processName);
0025 return;
0026 }
0027 }
0028 }
0029
0030 std::string ProcessBlockHelperBase::selectProcess(ProductRegistry const& productRegistry,
0031 ProductLabels const& productLabels,
0032 TypeID const& typeID) const {
0033 std::string processName(productLabels.process);
0034 std::string selectedProcess;
0035
0036 unsigned int bestPosition = 0;
0037 for (auto const& prod : productRegistry.productList()) {
0038 ProductDescription const& desc = prod.second;
0039 if (desc.branchType() == InProcess && !desc.produced() && desc.present() &&
0040 desc.moduleLabel() == productLabels.module && desc.productInstanceName() == productLabels.productInstance &&
0041 desc.unwrappedTypeID() == typeID && (processName.empty() || processName == desc.processName())) {
0042
0043 auto found =
0044 std::find_if(processesWithProcessBlockProducts_.begin(),
0045 processesWithProcessBlockProducts_.end(),
0046 [&desc](auto const& processFromHelper) { return processFromHelper == desc.processName(); });
0047 if (found != processesWithProcessBlockProducts_.end()) {
0048 const unsigned int position = std::distance(processesWithProcessBlockProducts_.begin(), found);
0049 if (position >= bestPosition) {
0050 bestPosition = position;
0051 selectedProcess = desc.processName();
0052 }
0053 }
0054 }
0055 }
0056 return selectedProcess;
0057 }
0058
0059 }