CMS 3D CMS Logo

branchIDToProductID.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 
6 namespace edm {
7  std::vector<ProcessIndex> makeBranchListIndexToProcessIndex(BranchListIndexes const& branchListIndexes) {
8  ProcessIndex pix = 0;
9  auto const nelem = 1 + *std::max_element(branchListIndexes.begin(), branchListIndexes.end());
10  std::vector<ProcessIndex> branchListIndexToProcessIndex(nelem, std::numeric_limits<BranchListIndex>::max());
11  for (auto const& blindex : branchListIndexes) {
12  branchListIndexToProcessIndex[blindex] = pix;
13  ++pix;
14  }
15  return branchListIndexToProcessIndex;
16  }
17 
19  BranchIDListHelper const& branchIDListHelper,
20  std::vector<ProcessIndex> const& branchListIndexToProcessIndex) {
21  if (not bid.isValid()) {
22  throw Exception(errors::NotFound, "InvalidID") << "branchIDToProductID: invalid BranchID supplied\n";
23  }
24 
25  auto range = branchIDListHelper.branchIDToIndexMap().equal_range(bid);
26  for (auto it = range.first; it != range.second; ++it) {
27  edm::BranchListIndex blix = it->second.first;
28  if (blix < branchListIndexToProcessIndex.size()) {
29  auto v = branchListIndexToProcessIndex[blix];
31  edm::ProductIndex productIndex = it->second.second;
32  edm::ProcessIndex processIndex = v;
33  return edm::ProductID(processIndex + 1, productIndex + 1);
34  }
35  }
36  }
37  // cannot throw, because some products may legitimately not have product ID's (e.g. pile-up).
38  return edm::ProductID();
39  }
40 
41 } // namespace edm
unsigned short BranchListIndex
ProductID branchIDToProductID(BranchID const &bid, BranchIDListHelper const &branchIDListHelper, std::vector< ProcessIndex > const &branchListIndexToProcessIndex)
bool isValid() const
Definition: BranchID.h:22
std::vector< BranchListIndex > BranchListIndexes
unsigned short ProcessIndex
Definition: ProductID.h:25
std::vector< ProcessIndex > makeBranchListIndexToProcessIndex(BranchListIndexes const &branchListIndexes)
HLT enums.
unsigned short ProductIndex
Definition: ProductID.h:26
BranchIDToIndexMap const & branchIDToIndexMap() const