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 
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 
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
sistrip::invalid32_
static const uint32_t invalid32_
Definition: Constants.h:15
SiStripHashedDetId::hashedIndex
uint32_t hashedIndex(uint32_t det_id)
Definition: SiStripHashedDetId.h:70
SiStripHashedDetId::~SiStripHashedDetId
~SiStripHashedDetId()
Definition: SiStripHashedDetId.cc:52
SiStripHashedDetId::detIds_
std::vector< uint32_t > detIds_
Definition: SiStripHashedDetId.h:63
SiStripHashedDetId::const_iterator
std::vector< uint32_t >::const_iterator const_iterator
Definition: SiStripHashedDetId.h:40
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
SiStripHashedDetId::iter_
const_iterator iter_
Definition: SiStripHashedDetId.h:67
SiStripHashedDetId::begin
const_iterator begin() const
Definition: SiStripHashedDetId.h:94
SiStripHashedDetId
Provides dense hash map in place of DetId.
Definition: SiStripHashedDetId.h:19
SiStripHashedDetId::id_
uint32_t id_
Definition: SiStripHashedDetId.h:65
SiStripConstants.h
operator<<
std::ostream & operator<<(std::ostream &os, const SiStripHashedDetId &)
Definition: SiStripHashedDetId.cc:85
SiStripHashedDetId::iterator
std::vector< uint32_t >::iterator iterator
Definition: SiStripHashedDetId.h:42
SiStripHashedDetId::end
const_iterator end() const
Definition: SiStripHashedDetId.h:95
SiStripHashedDetId::init
void init(const std::vector< uint32_t > &)
Definition: SiStripHashedDetId.cc:60
SiStripHashedDetId::SiStripHashedDetId
SiStripHashedDetId()
Definition: SiStripHashedDetId.cc:45
DetId.h
SiStripHashedDetId::unhashIndex
uint32_t unhashIndex(uint32_t hashed_index) const
Definition: SiStripHashedDetId.h:87