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_);
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 
66  checkKeyProductID(key);
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 
72  void checkKeyProductID(const OmniClusterRef& key) const { checkKeyProductID(key.id()); }
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) {
81  return i.first.rawIndex() > j.first.rawIndex();
82  }
83 
84  static bool compareSort(const value_type& i, const value_type& j) {
85  // For sorting compare also TrackingParticle keys in order to
86  // remove duplicate matches
87  return compare(i, j) || (i.first.rawIndex() == j.first.rawIndex() && i.second.key() > j.second.key());
88  }
89 
93 };
94 
95 #endif
const_iterator cbegin() const
ProductID id() const
Definition: HandleBase.cc:15
void checkMappedProductID(const TrackingParticleRef &tp) const
void checkKeyProductID(const OmniClusterRef &key) const
const_iterator begin() const
typename map_type::const_iterator const_iterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void swap(ProductID &other)
Definition: ProductID.cc:17
void emplace_back(Args &&...args)
Definition: VecArray.h:90
edm::ProductID mappedProductId_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
const_iterator end() const
void addKeyID(edm::ProductID id)
const_iterator cend() const
def unique(seq, keepstr=True)
Definition: tier0.py:25
static bool compareSort(const value_type &i, const value_type &j)
range equal_range(const OmniClusterRef &key) const
#define end
Definition: vmac.h:39
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
#define begin
Definition: vmac.h:32
edm::ProductID id() const
std::pair< const_iterator, const_iterator > range
const map_type & map() 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)