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 
10 
11 #include <vector>
12 #include <utility>
13 #include <algorithm>
14 
22 public:
25  using value_type = std::pair<key_type, mapped_type>;
26  using map_type = std::vector<value_type>;
27  using const_iterator = typename map_type::const_iterator;
28  using range = std::pair<const_iterator, const_iterator>;
29 
31  explicit ClusterTPAssociation(const edm::HandleBase& mappedHandle) : ClusterTPAssociation(mappedHandle.id()) {}
32  explicit ClusterTPAssociation(const edm::ProductID& mappedProductId) : mappedProductId_(mappedProductId) {}
33 
35  auto foundKeyID = std::find(std::begin(keyProductIDs_), std::end(keyProductIDs_), id);
36  if (foundKeyID == std::end(keyProductIDs_)) {
38  }
39  }
40 
41  void emplace_back(const OmniClusterRef& cluster, const TrackingParticleRef& tp) {
43  checkKeyProductID(cluster.id());
44  map_.emplace_back(cluster, tp);
45  }
46  void sortAndUnique() {
47  std::sort(map_.begin(), map_.end(), compareSort);
48  auto last = std::unique(map_.begin(), map_.end());
49  map_.erase(last, map_.end());
50  map_.shrink_to_fit();
51  }
53  map_.swap(other.map_);
54  mappedProductId_.swap(other.mappedProductId_);
55  }
56 
57  bool empty() const { return map_.empty(); }
58  size_t size() const { return map_.size(); }
59 
60  const_iterator begin() const { return map_.begin(); }
61  const_iterator cbegin() const { return map_.cbegin(); }
62  const_iterator end() const { return map_.end(); }
63  const_iterator cend() const { return map_.end(); }
64 
67  return std::equal_range(map_.begin(), map_.end(), value_type(key, TrackingParticleRef()), compare);
68  }
69 
70  const map_type& map() const { return map_; }
71 
73  void checkKeyProductID(const edm::ProductID& id) const;
74 
75  void checkMappedProductID(const edm::HandleBase& mappedHandle) const { checkMappedProductID(mappedHandle.id()); }
77  void checkMappedProductID(const edm::ProductID& id) const;
78 
79 private:
80  static bool compare(const value_type& i, const value_type& j) { return i.first.rawIndex() > j.first.rawIndex(); }
81 
82  static bool compareSort(const value_type& i, const value_type& j) {
83  // For sorting compare also TrackingParticle keys in order to
84  // remove duplicate matches
85  return compare(i, j) || (i.first.rawIndex() == j.first.rawIndex() && i.second.key() > j.second.key());
86  }
87 
91 };
92 
93 #endif
const_iterator end() const
void checkKeyProductID(const OmniClusterRef &key) const
ProductID id() const
Definition: HandleBase.cc:29
range equal_range(const OmniClusterRef &key) const
typename map_type::const_iterator const_iterator
const_iterator begin() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void swap(ProductID &other)
Definition: ProductID.cc:16
void checkMappedProductID(const TrackingParticleRef &tp) const
edm::ProductID mappedProductId_
const_iterator cend() const
edm::ProductID id() const
void addKeyID(edm::ProductID id)
def unique(seq, keepstr=True)
Definition: tier0.py:24
const_iterator cbegin() const
static bool compareSort(const value_type &i, const value_type &j)
static bool compare(const value_type &i, const value_type &j)
std::vector< value_type > map_type
const map_type & map() const
ClusterTPAssociation(const edm::HandleBase &mappedHandle)
void swap(ClusterTPAssociation &other)
void emplace_back(Args &&... args)
Definition: VecArray.h:90
std::pair< const_iterator, const_iterator > range
void checkMappedProductID(const edm::HandleBase &mappedHandle) const
edm::VecArray< edm::ProductID, 2 > keyProductIDs_
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)