Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:30

0001 #ifndef CalibFormats_SiStripObjects_SiStripHashedDetId_H
0002 #define CalibFormats_SiStripObjects_SiStripHashedDetId_H
0003 
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0006 #include <algorithm>
0007 #include <iomanip>
0008 #include <vector>
0009 #include <cstdint>
0010 
0011 class SiStripHashedDetId;
0012 std::ostream &operator<<(std::ostream &os, const SiStripHashedDetId &);
0013 
0014 /**
0015     @class SiStripHashedDetId
0016     @author R.Bainbridge
0017     @brief Provides dense hash map in place of DetId
0018 */
0019 class SiStripHashedDetId {
0020 public:
0021   // ---------- constructors ----------
0022 
0023   /** Constructor taking raw DetIds as input. */
0024   SiStripHashedDetId(const std::vector<uint32_t> &);
0025 
0026   /** Constructor taking DetIds as input. */
0027   SiStripHashedDetId(const std::vector<DetId> &);
0028 
0029   /** Copy constructor. */
0030   SiStripHashedDetId(const SiStripHashedDetId &);
0031 
0032   /** Public default constructor. */
0033   SiStripHashedDetId();
0034 
0035   /** Default destructor. */
0036   ~SiStripHashedDetId();
0037 
0038   // ---------- typedefs ----------
0039 
0040   typedef std::vector<uint32_t>::const_iterator const_iterator;
0041 
0042   typedef std::vector<uint32_t>::iterator iterator;
0043 
0044   // ---------- public interface ----------
0045 
0046   /** Returns hashed index for given DetId. */
0047   inline uint32_t hashedIndex(uint32_t det_id);
0048 
0049   /** Returns raw (32-bit) DetId for given hashed index. */
0050   inline uint32_t unhashIndex(uint32_t hashed_index) const;
0051 
0052   /** Returns DetId object for given hashed index. */
0053   // inline DetId detId( uint32_t index ) const;
0054 
0055   inline const_iterator begin() const;
0056 
0057   inline const_iterator end() const;
0058 
0059 private:
0060   void init(const std::vector<uint32_t> &);
0061 
0062   /** Sorted list of all silicon strip tracker DetIds. */
0063   std::vector<uint32_t> detIds_;
0064 
0065   uint32_t id_;
0066 
0067   const_iterator iter_;
0068 };
0069 
0070 uint32_t SiStripHashedDetId::hashedIndex(uint32_t det_id) {
0071   const_iterator iter = end();
0072   if (det_id > id_) {
0073     iter = find(iter_, end(), det_id);
0074   } else {
0075     iter = find(begin(), iter_, det_id);
0076   }
0077   if (iter != end()) {
0078     id_ = det_id;
0079     iter_ = iter;
0080     return iter - begin();
0081   } else {
0082     id_ = 0;
0083     iter_ = begin();
0084     return sistrip::invalid32_;
0085   }
0086 }
0087 uint32_t SiStripHashedDetId::unhashIndex(uint32_t hashed_index) const {
0088   if (hashed_index < static_cast<uint32_t>(end() - begin())) {
0089     return detIds_[hashed_index];
0090   } else {
0091     return sistrip::invalid32_;
0092   }
0093 }
0094 SiStripHashedDetId::const_iterator SiStripHashedDetId::begin() const { return detIds_.begin(); }
0095 SiStripHashedDetId::const_iterator SiStripHashedDetId::end() const { return detIds_.end(); }
0096 
0097 #endif  // CalibFormats_SiStripObjects_SiStripHashedDetId_H