CMS 3D CMS Logo

SiStripHashedDetId.h
Go to the documentation of this file.
1 #ifndef CalibFormats_SiStripObjects_SiStripHashedDetId_H
2 #define CalibFormats_SiStripObjects_SiStripHashedDetId_H
3 
6 #include <algorithm>
7 #include <iomanip>
8 #include <vector>
9 #include <cstdint>
10 
11 class SiStripHashedDetId;
12 std::ostream &operator<<(std::ostream &os, const SiStripHashedDetId &);
13 
20 public:
21  // ---------- constructors ----------
22 
24  SiStripHashedDetId(const std::vector<uint32_t> &);
25 
27  SiStripHashedDetId(const std::vector<DetId> &);
28 
31 
34  if (this != &other) { // Self-assignment check
35  this->id_ = 0;
36  this->iter_ = other.begin();
37  // auxilliary vector to store the list of raw IDs
38  std::vector<uint32_t> raw_ids;
39  raw_ids.reserve(other.size());
40 
41  // Copy elements from input vector to detIds_ vector
42  std::copy(other.begin(), other.end(), std::back_inserter(raw_ids));
43 
44  this->init(raw_ids);
45  }
46  return *this;
47  }
48 
51 
54 
55  // ---------- typedefs ----------
56 
57  typedef std::vector<uint32_t>::const_iterator const_iterator;
58 
59  typedef std::vector<uint32_t>::iterator iterator;
60 
61  // ---------- public interface ----------
62 
64  inline uint32_t hashedIndex(uint32_t det_id);
65 
67  inline uint32_t unhashIndex(uint32_t hashed_index) const;
68 
70  // inline DetId detId( uint32_t index ) const;
71 
72  inline const_iterator begin() const;
73 
74  inline const_iterator end() const;
75 
76  inline const size_t size() const { return detIds_.size(); }
77 
78 private:
79  void init(const std::vector<uint32_t> &);
80 
82  std::vector<uint32_t> detIds_;
83 
84  uint32_t id_;
85 
87 };
88 
89 uint32_t SiStripHashedDetId::hashedIndex(uint32_t det_id) {
90  const_iterator iter = end();
91  if (det_id > id_) {
92  iter = find(iter_, end(), det_id);
93  } else {
94  iter = find(begin(), iter_, det_id);
95  }
96  if (iter != end()) {
97  id_ = det_id;
98  iter_ = iter;
99  return iter - begin();
100  } else {
101  id_ = 0;
102  iter_ = begin();
103  return sistrip::invalid32_;
104  }
105 }
106 uint32_t SiStripHashedDetId::unhashIndex(uint32_t hashed_index) const {
107  if (hashed_index < static_cast<uint32_t>(end() - begin())) {
108  return detIds_[hashed_index];
109  } else {
110  return sistrip::invalid32_;
111  }
112 }
115 
116 #endif // CalibFormats_SiStripObjects_SiStripHashedDetId_H
std::vector< uint32_t >::const_iterator const_iterator
std::vector< uint32_t >::iterator iterator
static const uint32_t invalid32_
Definition: Constants.h:15
std::ostream & operator<<(std::ostream &os, const SiStripHashedDetId &)
const_iterator iter_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
uint32_t hashedIndex(uint32_t det_id)
Provides dense hash map in place of DetId.
uint32_t unhashIndex(uint32_t hashed_index) const
const size_t size() const
std::vector< uint32_t > detIds_
const_iterator end() const
void init(const std::vector< uint32_t > &)
const_iterator begin() const
SiStripHashedDetId & operator=(const SiStripHashedDetId &other)