CMS 3D CMS Logo

ClusterTPAssociation.h
Go to the documentation of this file.
1 #ifndef SimTracker_TrackerHitAssociation_ClusterTPAssociation_h
2 #define SimTracker_TrackerHitAssociation_ClusterTPAssociation_h
3 
9 
10 #include <vector>
11 #include <utility>
12 #include <algorithm>
13 
21 public:
24  using value_type = std::pair<key_type, mapped_type>;
25  using map_type = std::vector<value_type>;
26  using const_iterator = typename map_type::const_iterator;
27  using range = std::pair<const_iterator, const_iterator>;
28 
30  explicit ClusterTPAssociation(const edm::HandleBase& mappedHandle): ClusterTPAssociation(mappedHandle.id()) {}
31  explicit ClusterTPAssociation(const edm::ProductID& mappedProductId): mappedProductId_(mappedProductId) {}
32 
33  void emplace_back(const OmniClusterRef& cluster, const TrackingParticleRef& tp) {
35  map_.emplace_back(cluster, tp);
36  }
37  void sortAndUnique() {
38  std::sort(map_.begin(), map_.end(), compareSort);
39  auto last = std::unique(map_.begin(), map_.end());
40  map_.erase(last, map_.end());
41  map_.shrink_to_fit();
42  }
44  map_.swap(other.map_);
46  }
47 
48  bool empty() const { return map_.empty(); }
49  size_t size() const { return map_.size(); }
50 
51  const_iterator begin() const { return map_.begin(); }
52  const_iterator cbegin() const { return map_.cbegin(); }
53  const_iterator end() const { return map_.end(); }
54  const_iterator cend() const { return map_.end(); }
55 
57  return std::equal_range(map_.begin(), map_.end(), value_type(key, TrackingParticleRef()), compare);
58  }
59 
60  const map_type& map() const { return map_; }
61 
62  void checkMappedProductID(const edm::HandleBase& mappedHandle) const { checkMappedProductID(mappedHandle.id()); }
64  void checkMappedProductID(const edm::ProductID& id) const;
65 
66 private:
67  static bool compare(const value_type& i, const value_type& j) {
68  return i.first.rawIndex() > j.first.rawIndex();
69  }
70 
71  static bool compareSort(const value_type& i, const value_type& j) {
72  // For sorting compare also TrackingParticle keys in order to
73  // remove duplicate matches
74  return compare(i, j) || (i.first.rawIndex() == j.first.rawIndex() && i.second.key() > j.second.key());
75  }
76 
79 };
80 
81 #endif
const_iterator cbegin() const
ProductID id() const
Definition: HandleBase.cc:15
void checkMappedProductID(const TrackingParticleRef &tp) const
const_iterator begin() const
typename map_type::const_iterator const_iterator
void swap(ProductID &other)
Definition: ProductID.cc:17
edm::ProductID mappedProductId_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
const_iterator end() const
const_iterator cend() const
def unique(seq, keepstr=True)
Definition: tier0.py:24
static bool compareSort(const value_type &i, const value_type &j)
range equal_range(const OmniClusterRef &key) const
static bool compare(const value_type &i, const value_type &j)
std::vector< value_type > map_type
ClusterTPAssociation(const edm::HandleBase &mappedHandle)
void swap(ClusterTPAssociation &other)
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
std::pair< const_iterator, const_iterator > range
const map_type & map() const
std::pair< key_type, mapped_type > value_type
edm::Ref< TrackingParticleCollection > TrackingParticleRef
void emplace_back(const OmniClusterRef &cluster, const TrackingParticleRef &tp)
ClusterTPAssociation(const edm::ProductID &mappedProductId)