CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripHashedDetId.h
Go to the documentation of this file.
1 #ifndef CalibFormats_SiStripObjects_SiStripHashedDetId_H
2 #define CalibFormats_SiStripObjects_SiStripHashedDetId_H
3 
6 #include <boost/cstdint.hpp>
7 #include <iomanip>
8 #include <vector>
9 #include <algorithm>
10 
11 class SiStripHashedDetId;
12 std::ostream& operator<< ( std::ostream& os, const SiStripHashedDetId& );
13 
20 
21  public:
22 
23  // ---------- constructors ----------
24 
26  SiStripHashedDetId( const std::vector<uint32_t>& );
27 
29  SiStripHashedDetId( const std::vector<DetId>& );
30 
33 
36 
39 
40  // ---------- typedefs ----------
41 
42  typedef std::vector<uint32_t>::const_iterator const_iterator;
43 
44  typedef std::vector<uint32_t>::iterator iterator;
45 
46  // ---------- public interface ----------
47 
49  inline uint32_t hashedIndex( uint32_t det_id );
50 
52  inline uint32_t unhashIndex( uint32_t hashed_index ) const;
53 
55  //inline DetId detId( uint32_t index ) const;
56 
57  inline const_iterator begin() const;
58 
59  inline const_iterator end() const;
60 
61  private:
62 
63  void init( const std::vector<uint32_t>& );
64 
66  std::vector<uint32_t> detIds_;
67 
68  uint32_t id_;
69 
71 
72 };
73 
74 uint32_t SiStripHashedDetId::hashedIndex( uint32_t det_id ) {
76  if ( det_id > id_ ) { iter = find( iter_, end(), det_id ); }
77  else { iter = find( begin(), iter_, det_id ); }
78  if ( iter != end() ) {
79  id_ = det_id;
80  iter_ = iter;
81  return iter-begin();
82  } else {
83  id_ = 0;
84  iter_ = begin();
85  return sistrip::invalid32_;
86  }
87 }
88 uint32_t SiStripHashedDetId::unhashIndex( uint32_t hashed_index ) const {
89  if ( hashed_index < static_cast<uint32_t>(end()-begin()) ) { return detIds_[hashed_index]; }
90  else { return sistrip::invalid32_; }
91 }
94 
95 #endif // CalibFormats_SiStripObjects_SiStripHashedDetId_H
96 
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
const_iterator iter_
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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 > &)