CMS 3D CMS Logo

Utils.h
Go to the documentation of this file.
1 #ifndef Utils_h
2 #define Utils_h
3 
4 #include <map>
5 #include <utility>
6 #include <vector>
7 
9 template <typename Reference, typename Association>
10 std::pair<typename Association::data_type::first_type, double> match(Reference key,
11  Association association,
12  bool bestMatchByMaxValue) {
13  typename Association::data_type::first_type value;
14 
15  typename Association::const_iterator pos = association.find(key);
16 
17  if (pos == association.end())
18  return std::pair<typename Association::data_type::first_type, double>(value, 0);
19 
20  const std::vector<typename Association::data_type> &matches = pos->val;
21 
22  double q = bestMatchByMaxValue ? -1e30 : 1e30;
23 
24  for (std::size_t i = 0; i < matches.size(); ++i)
25  if (bestMatchByMaxValue ? (matches[i].second > q) : (matches[i].second < q)) {
26  value = matches[i].first;
27  q = matches[i].second;
28  }
29 
30  return std::pair<typename Association::data_type::first_type, double>(value, q);
31 }
32 
36 public:
37  typedef std::map<unsigned int, unsigned int> MapType;
38 
40 
41  const unsigned int processId(unsigned int g4ProcessId) const;
42 
43 private:
44  MapType m_map;
45 };
46 
47 #endif
U second(std::pair< T, U > const &p)
std::map< unsigned int, unsigned int > MapType
Definition: Utils.h:37
const unsigned int processId(unsigned int g4ProcessId) const
Definition: Utils.cc:59
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10