Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-06 03:10:50

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   SiStripBadStrip(const SiStripBadStrip& orig) {
0060     v_badstrips = orig.v_badstrips;
0061     indexes = orig.indexes;
0062   }
0063   virtual ~SiStripBadStrip(){};
0064 
0065   bool put(const uint32_t& detID, const InputVector& vect) { return put(detID, Range(vect.begin(), vect.end())); }
0066   bool put(const uint32_t& detID, Range input);
0067   const Range getRange(const uint32_t detID) const;
0068   Range getRangeByPos(unsigned short pos) const;
0069   void getDetIds(std::vector<uint32_t>& DetIds_) const;
0070   void printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0071   void printDebug(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
0072 
0073   ContainerIterator getDataVectorBegin() const { return v_badstrips.begin(); }
0074   ContainerIterator getDataVectorEnd() const { return v_badstrips.end(); }
0075   RegistryIterator getRegistryVectorBegin() const { return indexes.begin(); }
0076   RegistryIterator getRegistryVectorEnd() const { return indexes.end(); }
0077 
0078   inline data decode(const unsigned int& value) const {
0079     data a;
0080     a.firstStrip = ((value >> sistrip::FirstBadStripShift_) & sistrip::FirstBadStripMask_);
0081     a.range = ((value >> sistrip::RangeBadStripShift_) & sistrip::RangeBadStripMask_);
0082     a.flag = ((value >> sistrip::FlagBadStripShift_) & sistrip::FlagBadStripMask_);
0083     return a;
0084   }
0085 
0086   inline unsigned int encode(const unsigned short& first,
0087                              const unsigned short& NconsecutiveBadStrips,
0088                              const unsigned short& flag = 0) {
0089     return ((first & sistrip::FirstBadStripMask_) << sistrip::FirstBadStripShift_) |
0090            ((NconsecutiveBadStrips & sistrip::RangeBadStripMask_) << sistrip::RangeBadStripShift_) |
0091            ((flag & sistrip::FlagBadStripMask_) << sistrip::FlagBadStripShift_);
0092   }
0093 
0094   // additional methods need for Phase-2
0095   inline data decodePhase2(const unsigned int& value) const {
0096     data a;
0097     a.firstStrip = ((value >> siPhase2strip::FirstBadStripShift_) & siPhase2strip::FirstBadStripMask_);
0098     a.range = ((value >> siPhase2strip::RangeBadStripShift_) & siPhase2strip::RangeBadStripMask_);
0099     a.flag = ((value >> siPhase2strip::FlagBadStripShift_) & siPhase2strip::FlagBadStripMask_);
0100     return a;
0101   }
0102 
0103   inline unsigned int encodePhase2(const unsigned short& first,
0104                                    const unsigned short& NconsecutiveBadStrips,
0105                                    const unsigned short& flag = 0) {
0106     return ((first & siPhase2strip::FirstBadStripMask_) << siPhase2strip::FirstBadStripShift_) |
0107            ((NconsecutiveBadStrips & siPhase2strip::RangeBadStripMask_) << siPhase2strip::RangeBadStripShift_) |
0108            ((flag & siPhase2strip::FlagBadStripMask_) << siPhase2strip::FlagBadStripShift_);
0109   }
0110 
0111 protected:
0112   Container v_badstrips;
0113   Registry indexes;
0114 
0115   COND_SERIALIZABLE;
0116 };
0117 
0118 #endif