CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/CalibFormats/SiStripObjects/interface/SiStripHashedDetId.h

Go to the documentation of this file.
00001 #ifndef CalibFormats_SiStripObjects_SiStripHashedDetId_H
00002 #define CalibFormats_SiStripObjects_SiStripHashedDetId_H
00003 
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00006 #include <boost/cstdint.hpp>
00007 #include <iomanip>
00008 #include <vector>
00009 #include <algorithm>
00010 
00011 class SiStripHashedDetId;
00012 std::ostream& operator<< ( std::ostream& os, const SiStripHashedDetId& );
00013 
00019 class SiStripHashedDetId {
00020   
00021  public:
00022 
00023   // ---------- constructors ----------
00024   
00026   SiStripHashedDetId( const std::vector<uint32_t>& );
00027   
00029   SiStripHashedDetId( const std::vector<DetId>& );
00030 
00032   SiStripHashedDetId( const SiStripHashedDetId& );
00033   
00035   SiStripHashedDetId();
00036 
00038   ~SiStripHashedDetId();
00039 
00040   // ---------- typedefs ----------
00041 
00042   typedef std::vector<uint32_t>::const_iterator const_iterator;
00043 
00044   typedef std::vector<uint32_t>::iterator iterator;
00045 
00046   // ---------- public interface ----------
00047 
00049   inline uint32_t hashedIndex( uint32_t det_id ); 
00050   
00052   inline uint32_t unhashIndex( uint32_t hashed_index ) const;
00053 
00055   //inline DetId detId( uint32_t index ) const;
00056 
00057   inline const_iterator begin() const;
00058 
00059   inline const_iterator end() const;
00060 
00061  private:
00062 
00063   void init( const std::vector<uint32_t>& );
00064   
00066   std::vector<uint32_t> detIds_;
00067 
00068   uint32_t id_;
00069 
00070   const_iterator iter_;
00071 
00072 };
00073 
00074 uint32_t SiStripHashedDetId::hashedIndex( uint32_t det_id ) { 
00075   const_iterator iter = end();
00076   if ( det_id > id_ ) { iter = find( iter_, end(), det_id ); }
00077   else { iter = find( begin(), iter_, det_id ); }
00078   if ( iter != end() ) { 
00079     id_ = det_id;
00080     iter_ = iter;
00081     return iter-begin(); 
00082   } else { 
00083     id_ = 0;
00084     iter_ = begin();
00085     return sistrip::invalid32_; 
00086   }
00087 }
00088 uint32_t SiStripHashedDetId::unhashIndex( uint32_t hashed_index ) const { 
00089   if ( hashed_index < static_cast<uint32_t>(end()-begin()) ) { return detIds_[hashed_index]; }
00090   else { return sistrip::invalid32_; }
00091 }
00092 SiStripHashedDetId::const_iterator SiStripHashedDetId::begin() const { return detIds_.begin(); }
00093 SiStripHashedDetId::const_iterator SiStripHashedDetId::end() const { return detIds_.end(); }
00094 
00095 #endif // CalibFormats_SiStripObjects_SiStripHashedDetId_H
00096