LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CMatchBookKeeper.cxx
Go to the documentation of this file.
2 
3 namespace cmtool {
4 
6  {
7  Reset();
8  }
9 
11  {
12  _register.clear();
13  }
14 
15  void CMatchBookKeeper::Match(const std::vector<unsigned int>& matched_indexes, const float& score)
16  {
17  _register.insert(std::make_pair(score, matched_indexes));
18  }
19 
20  std::vector<std::vector<unsigned int>> CMatchBookKeeper::GetResult() const
21  {
22  std::vector<std::vector<unsigned int>> res;
23 
24  PassResult(res);
25 
26  return res;
27  }
28 
30  void CMatchBookKeeper::PassResult(std::vector<std::vector<unsigned int>>& result) const
31  {
32  result.clear();
33 
34  // Rough guess: assume half of registered pairs are good
35  result.reserve((unsigned int)(_register.size() / 2));
36 
37  std::vector<bool> used_index;
38 
39  for (auto riter = _register.rbegin(); riter != _register.rend(); ++riter) {
40 
41  bool valid_set = true;
42 
43  for (auto const& index : (*riter).second) {
44 
45  if (index >= used_index.size())
46 
47  used_index.resize(index + 1, false);
48 
49  else if (used_index.at(index))
50  valid_set = false;
51  }
52 
53  if (valid_set) {
54 
55  result.push_back((*riter).second);
56 
57  for (auto& index : (*riter).second)
58 
59  used_index.at(index) = true;
60  }
61  }
62  }
63 
64 }
Class def header for a class CMatchBookKeeper.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
CMatchBookKeeper()
Default constructor.
void Match(const std::vector< unsigned int > &matched_indexes, const float &score)
Method to register matched clusters.
void PassResult(std::vector< std::vector< unsigned int >> &result) const
Method to pass result.
std::multimap< float, std::vector< unsigned int > > _register
void Reset()
Reset method.
std::vector< std::vector< unsigned int > > GetResult() const
Method to get result.