Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-28 22:45:30

0001 #include "DataFormats/Provenance/interface/branchIDToProductID.h"
0002 #include "FWCore/Utilities/interface/EDMException.h"
0003 
0004 #include <algorithm>
0005 
0006 namespace edm {
0007   std::vector<ProcessIndex> makeBranchListIndexToProcessIndex(BranchListIndexes const& branchListIndexes) {
0008     ProcessIndex pix = 0;
0009     auto const nelem = 1 + *std::max_element(branchListIndexes.begin(), branchListIndexes.end());
0010     std::vector<ProcessIndex> branchListIndexToProcessIndex(nelem, std::numeric_limits<BranchListIndex>::max());
0011     for (auto const& blindex : branchListIndexes) {
0012       branchListIndexToProcessIndex[blindex] = pix;
0013       ++pix;
0014     }
0015     return branchListIndexToProcessIndex;
0016   }
0017 
0018   ProductID branchIDToProductID(BranchID const& bid,
0019                                 BranchIDListHelper const& branchIDListHelper,
0020                                 std::vector<ProcessIndex> const& branchListIndexToProcessIndex) {
0021     if (not bid.isValid()) {
0022       throw Exception(errors::NotFound, "InvalidID") << "branchIDToProductID: invalid BranchID supplied\n";
0023     }
0024 
0025     auto range = branchIDListHelper.branchIDToIndexMap().equal_range(bid);
0026     for (auto it = range.first; it != range.second; ++it) {
0027       edm::BranchListIndex blix = it->second.first;
0028       if (blix < branchListIndexToProcessIndex.size()) {
0029         auto v = branchListIndexToProcessIndex[blix];
0030         if (v != std::numeric_limits<edm::BranchListIndex>::max()) {
0031           edm::ProductIndex productIndex = it->second.second;
0032           edm::ProcessIndex processIndex = v;
0033           return edm::ProductID(processIndex + 1, productIndex + 1);
0034         }
0035       }
0036     }
0037     // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
0038     return edm::ProductID();
0039   }
0040 
0041 }  // namespace edm