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 <boost/cstdint.hpp>
8 #include <iomanip>
9 #include <vector>
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 
37 
38  // ---------- typedefs ----------
39 
40  typedef std::vector<uint32_t>::const_iterator const_iterator;
41 
42  typedef std::vector<uint32_t>::iterator iterator;
43 
44  // ---------- public interface ----------
45 
47  inline uint32_t hashedIndex(uint32_t det_id);
48 
50  inline uint32_t unhashIndex(uint32_t hashed_index) const;
51 
53  // inline DetId detId( uint32_t index ) const;
54 
55  inline const_iterator begin() const;
56 
57  inline const_iterator end() const;
58 
59 private:
60  void init(const std::vector<uint32_t> &);
61 
63  std::vector<uint32_t> detIds_;
64 
65  uint32_t id_;
66 
67  const_iterator iter_;
68 };
69 
70 uint32_t SiStripHashedDetId::hashedIndex(uint32_t det_id) {
71  const_iterator iter = end();
72  if (det_id > id_) {
73  iter = find(iter_, end(), det_id);
74  } else {
75  iter = find(begin(), iter_, det_id);
76  }
77  if (iter != end()) {
78  id_ = det_id;
79  iter_ = iter;
80  return iter - begin();
81  } else {
82  id_ = 0;
83  iter_ = begin();
84  return sistrip::invalid32_;
85  }
86 }
87 uint32_t SiStripHashedDetId::unhashIndex(uint32_t hashed_index) const {
88  if (hashed_index < static_cast<uint32_t>(end() - begin())) {
89  return detIds_[hashed_index];
90  } else {
91  return sistrip::invalid32_;
92  }
93 }
96 
97 #endif // CalibFormats_SiStripObjects_SiStripHashedDetId_H
uint32_t unhashIndex(uint32_t hashed_index) const
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:20
uint32_t hashedIndex(uint32_t det_id)
Provides dense hash map in place of DetId.
const_iterator begin() const
std::vector< uint32_t > detIds_
const_iterator end() const
void init(const std::vector< uint32_t > &)