CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  }
52  void swap(ClusterTPAssociation& other) {
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) { 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 cbegin() const
uint16_t *__restrict__ id
ProductID id() const
Definition: HandleBase.cc:29
void checkMappedProductID(const TrackingParticleRef &tp) const
def unique
Definition: tier0.py:24
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:19
void swap(ProductID &other)
Definition: ProductID.cc:16
void emplace_back(Args &&...args)
Definition: VecArray.h:90
edm::ProductID mappedProductId_
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
const_iterator end() const
void addKeyID(edm::ProductID id)
const_iterator cend() const
tuple key
prepare the HTCondor submission files and eventually submit them
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
edm::ProductID id() const
std::pair< const_iterator, const_iterator > range
string end
Definition: dataset.py:937
const map_type & map() const
edm::VecArray< edm::ProductID, 2 > keyProductIDs_
std::pair< key_type, mapped_type > value_type
tuple last
Definition: dqmdumpme.py:56
edm::Ref< TrackingParticleCollection > TrackingParticleRef
void emplace_back(const OmniClusterRef &cluster, const TrackingParticleRef &tp)
ClusterTPAssociation(const edm::ProductID &mappedProductId)