Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:41

0001 #ifndef SiStripBadStrip_h
0002 #define SiStripBadStrip_h
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <vector>
0007 #include <map>
0008 #include <iostream>
0009 #include "DataFormats/SiStripCommon/interface/ConstantsForCondObjects.h"
0010 #include <cstdint>
0011 
0012 class TrackerTopology;
0013 
0014 /**
0015  * Holds the list of bad components. <br>
0016  * The bad components can be filled with two put methods, that receive a DetId and
0017  * either a range of bad strips or a vector of bad strips. <br>
0018  * The information is stored in two vectors: <br>
0019  * - a vector<unsigned int> holding the bad strips <br>
0020  * - a vector<DetRegistry> associating a DetId to the corresponding range of
0021  * bad strips in the vector described above <br>
0022  * A DetRegistry contains the DetId and the index of the first and last position
0023  * in the bad strips vector correspoding to this DetId. <br>
0024  * The printSummary method prints the number of modules with at least a bad strip
0025  * divided by subdetector and layer/disk. It also prints the number of bad strips
0026  * divided in the same way. <br>
0027  * The printDebug method prints the full information of all the bad strips.
0028  */
0029 
0030 class SiStripBadStrip {
0031 public:
0032   struct data {
0033     unsigned short firstStrip;
0034     unsigned short range;
0035     unsigned short flag;
0036   };
0037 
0038   struct DetRegistry {
0039     uint32_t detid;
0040     uint32_t ibegin;
0041     uint32_t iend;
0042 
0043     COND_SERIALIZABLE;
0044   };
0045 
0046   class StrictWeakOrdering {
0047   public:
0048     bool operator()(const DetRegistry& p, const uint32_t& i) const { return p.detid < i; }
0049   };
0050 
0051   typedef std::vector<unsigned int> Container;
0052   typedef std::vector<unsigned int>::const_iterator ContainerIterator;
0053   typedef std::pair<ContainerIterator, ContainerIterator> Range;
0054   typedef std::vector<DetRegistry> Registry;
0055   typedef Registry::const_iterator RegistryIterator;
0056   typedef Container InputVector;
0057 
0058   SiStripBadStrip() {}
0059   virtual ~SiStripBadStrip() {}
0060 
0061   bool put(const uint32_t& detID, const InputVector& vect) { return put(detID, Range(vect.begin(), vect.end())); }
0062   bool put(const uint32_t& detID, Range input);
0063   const Range getRange(const uint32_t detID) const;
0064   Range getRangeByPos(unsigned short pos) const;
0065   void getDetIds(std::vector<uint32_t>& DetIds_) const;
0066   void printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0067   void printDebug(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0068 
0069   ContainerIterator getDataVectorBegin() const { return v_badstrips.begin(); }
0070   ContainerIterator getDataVectorEnd() const { return v_badstrips.end(); }
0071   RegistryIterator getRegistryVectorBegin() const { return indexes.begin(); }
0072   RegistryIterator getRegistryVectorEnd() const { return indexes.end(); }
0073 
0074   inline data decode(const unsigned int& value) const {
0075     data a;
0076     a.firstStrip = ((value >> sistrip::FirstBadStripShift_) & sistrip::FirstBadStripMask_);
0077     a.range = ((value >> sistrip::RangeBadStripShift_) & sistrip::RangeBadStripMask_);
0078     a.flag = ((value >> sistrip::FlagBadStripShift_) & sistrip::FlagBadStripMask_);
0079     return a;
0080   }
0081 
0082   inline unsigned int encode(const unsigned short& first,
0083                              const unsigned short& NconsecutiveBadStrips,
0084                              const unsigned short& flag = 0) {
0085     return ((first & sistrip::FirstBadStripMask_) << sistrip::FirstBadStripShift_) |
0086            ((NconsecutiveBadStrips & sistrip::RangeBadStripMask_) << sistrip::RangeBadStripShift_) |
0087            ((flag & sistrip::FlagBadStripMask_) << sistrip::FlagBadStripShift_);
0088   }
0089 
0090   // additional methods need for Phase-2
0091   inline data decodePhase2(const unsigned int& value) const {
0092     data a;
0093     a.firstStrip = ((value >> siPhase2strip::FirstBadStripShift_) & siPhase2strip::FirstBadStripMask_);
0094     a.range = ((value >> siPhase2strip::RangeBadStripShift_) & siPhase2strip::RangeBadStripMask_);
0095     a.flag = ((value >> siPhase2strip::FlagBadStripShift_) & siPhase2strip::FlagBadStripMask_);
0096     return a;
0097   }
0098 
0099   inline unsigned int encodePhase2(const unsigned short& first,
0100                                    const unsigned short& NconsecutiveBadStrips,
0101                                    const unsigned short& flag = 0) {
0102     return ((first & siPhase2strip::FirstBadStripMask_) << siPhase2strip::FirstBadStripShift_) |
0103            ((NconsecutiveBadStrips & siPhase2strip::RangeBadStripMask_) << siPhase2strip::RangeBadStripShift_) |
0104            ((flag & siPhase2strip::FlagBadStripMask_) << siPhase2strip::FlagBadStripShift_);
0105   }
0106 
0107 protected:
0108   Container v_badstrips;
0109   Registry indexes;
0110 
0111   COND_SERIALIZABLE;
0112 };
0113 
0114 #endif