CMS 3D CMS Logo

VIDCutFlowResult.cc
Go to the documentation of this file.
3 
4 namespace {
5  const std::string empty_str("");
6 }
7 
8 namespace vid {
9 
11  const std::string& hash,
12  const std::map<std::string, unsigned>& n2idx,
13  const std::vector<double>& values,
14  unsigned bitmap,
15  unsigned mask)
16  : name_(name), hash_(hash), bitmap_(bitmap), mask_(mask), values_(values) {
17  for (const auto& val : n2idx) {
18  names_.push_back(val.first);
19  indices_.push_back(val.second);
20  }
21  }
22 
23  const std::string& CutFlowResult::getNameAtIndex(const unsigned idx) const {
24  unsigned internal_idx = 0;
25  for (const auto& value : indices_) {
26  if (value == idx)
27  return names_[internal_idx];
28  ++internal_idx;
29  }
30  throw cms::Exception("IndexNotFound") << "index = " << idx << " has no corresponding cut name!";
31  return empty_str;
32  }
33 
34  bool CutFlowResult::getCutResultByIndex(const unsigned idx) const {
35  if (idx >= indices_.size()) {
36  throw cms::Exception("OutOfBounds") << idx << " is out of bounds for this cut flow!";
37  }
38  return getCutBit(idx);
39  }
40 
42  auto found_name = std::lower_bound(names_.begin(), names_.end(), name);
43  if (found_name == names_.end() || *found_name != name) {
44  throw cms::Exception("UnknownName") << "Cut name: " << name << " is not known for this cutflow!";
45  }
46  return getCutBit(indices_[std::distance(names_.begin(), found_name)]);
47  }
48 
49  bool CutFlowResult::isCutMasked(const unsigned idx) const {
50  if (idx >= indices_.size()) {
51  throw cms::Exception("OutOfBounds") << idx << " is out of bounds for this cut flow!";
52  }
53  return getMaskBit(idx);
54  }
55 
57  auto found_name = std::lower_bound(names_.begin(), names_.end(), name);
58  if (found_name == names_.end() || *found_name != name) {
59  throw cms::Exception("UnknownName") << "Cut name: " << name << " is not known for this cutflow!";
60  }
61  return getMaskBit(indices_[std::distance(names_.begin(), found_name)]);
62  }
63 
64  double CutFlowResult::getValueCutUpon(const unsigned idx) const {
65  if (idx >= indices_.size()) {
66  throw cms::Exception("OutOfBounds") << idx << " is out of bounds for this cut flow!";
67  }
68  return getCutValue(idx);
69  }
70 
72  auto found_name = std::lower_bound(names_.begin(), names_.end(), name);
73  if (found_name == names_.end() || *found_name != name) {
74  throw cms::Exception("UnknownName") << "Cut name: " << name << " is not known for this cutflow!";
75  }
76  return getCutValue(indices_[std::distance(names_.begin(), found_name)]);
77  }
78 
79  CutFlowResult CutFlowResult::getCutFlowResultMasking(const std::vector<unsigned>& idxs) const {
80  unsigned bitmap = bitmap_;
81  unsigned mask = mask_;
82  for (const unsigned idx : idxs) {
83  if (idx >= indices_.size()) {
84  throw cms::Exception("OutOfBounds") << idx << " is out of bounds for this cut flow!";
85  }
86  mask = mask | 1 << idx;
87  }
88  bitmap = bitmap | mask;
89  return CutFlowResult(name_, empty_str, names_, indices_, values_, bitmap, mask);
90  }
91 
92  CutFlowResult CutFlowResult::getCutFlowResultMasking(const std::vector<std::string>& names) const {
93  unsigned bitmap = bitmap_;
94  unsigned mask = mask_;
95  for (const std::string& name : names) {
96  auto found_name = std::lower_bound(names_.begin(), names_.end(), name);
97  if (found_name == names_.end() || *found_name != name) {
98  throw cms::Exception("UnknownName") << "Cut name: " << name << " is not known for this cutflow!";
99  }
100  mask = mask | 1 << indices_[std::distance(names_.begin(), found_name)];
101  }
102  bitmap = bitmap | mask;
103  return CutFlowResult(name_, empty_str, names_, indices_, values_, bitmap, mask);
104  }
105 
107  unsigned bitmap = bitmap_;
108  unsigned mask = mask_;
109  if (idx >= indices_.size()) {
110  throw cms::Exception("OutOfBounds") << idx << " is out of bounds for this cut flow!";
111  }
112  mask = mask | 1 << idx;
113  bitmap = bitmap | mask;
114  return CutFlowResult(name_, empty_str, names_, indices_, values_, bitmap, mask);
115  }
116 
118  unsigned bitmap = bitmap_;
119  unsigned mask = mask_;
120  auto found_name = std::lower_bound(names_.begin(), names_.end(), name);
121  if (found_name == names_.end() || *found_name != name) {
122  throw cms::Exception("UnknownName") << "Cut name: " << name << " is not known for this cutflow!";
123  }
124  mask = mask | 1 << indices_[std::distance(names_.begin(), found_name)];
125  bitmap = bitmap | mask;
126  return CutFlowResult(name_, empty_str, names_, indices_, values_, bitmap, mask);
127  }
128 } // namespace vid
bool isCutMasked(const unsigned idx) const
double getCutValue(const unsigned idx) const
bool getCutBit(const unsigned idx) const
std::vector< unsigned > indices_
std::vector< std::string > names_
const std::string names[nVars_]
bool getCutResultByIndex(const unsigned idx) const
constexpr uint32_t mask
Definition: gpuClustering.h:26
double getValueCutUpon(const unsigned idx) const
const std::string & getNameAtIndex(const unsigned idx) const
std::vector< double > values_
Definition: value.py:1
bool getCutResultByName(const std::string &name) const
CutFlowResult getCutFlowResultMasking(const unsigned idx) const
bool getMaskBit(const unsigned idx) const