Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:13

0001 
0002 #ifndef DataFormats_SiStripCommon_SiStripFecKey_H
0003 #define DataFormats_SiStripCommon_SiStripFecKey_H
0004 
0005 #include "DataFormats/SiStripCommon/interface/ConstantsForGranularity.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripKey.h"
0007 
0008 /**
0009    @class SiStripFecKey
0010    @author R.Bainbridge
0011    
0012    @brief Utility class that identifies a position within the strip
0013    tracker control structure, down to the level of an APV25.
0014    
0015    The class allows to encode the position within a 32-bit "key" and,
0016    conversely, unpack a 32-bit key to provide the position.
0017 
0018    The class provides the following member data: 
0019    - FEC key (32 bits),
0020    - VME crate,
0021    - FEC (using VME slot), 
0022    - FEC control ring,
0023    - CCU module,
0024    - Front-End module,
0025    - LLD channel,
0026    - APV25 chip,
0027    - directory path,
0028    - "granularity".
0029    
0030    Member data (integer in type only) with values of 0xFFFF signifies
0031    "invalid" (ie, FecSlot = 0xFFFF means "invalid FEC slot"). Data
0032    with null values signifies "all" (ie, FecSlot = 0 means "all FEC
0033    slots").
0034 
0035    The class generates a "directory path" string according to the
0036    member data. This can be used to organise histograms / other data
0037    types when using DQM / root. Conversely, the member data can also
0038    be built using the directory path when provided as a constructor
0039    argument.
0040 
0041    The class also provides the "granularity" to which the FEC key is
0042    unambiguous (ie, not "invalid" or "null") in defining a position
0043    within the control system.
0044 */
0045 class SiStripFecKey : public SiStripKey {
0046 public:
0047   // ---------- Constructors ----------
0048 
0049   /** Constructor using crate, FEC, ring, CCU, module and channel. */
0050   SiStripFecKey(const uint16_t& fec_crate,
0051                 const uint16_t& fec_slot = 0,
0052                 const uint16_t& fec_ring = 0,
0053                 const uint16_t& ccu_addr = 0,
0054                 const uint16_t& ccu_chan = 0,
0055                 const uint16_t& lld_chan = 0,
0056                 const uint16_t& i2c_addr = 0);
0057 
0058   /** Constructor using 32-bit "FEC key". */
0059   SiStripFecKey(const uint32_t& fec_key);
0060 
0061   /** Constructor using directory path. */
0062   SiStripFecKey(const std::string& directory_path);
0063 
0064   /** Copy constructor. */
0065   SiStripFecKey(const SiStripFecKey&);
0066 
0067   /** Copy constructor using base class. */
0068   SiStripFecKey(const SiStripKey&);
0069 
0070   /** Copy to level specified by granularity. */
0071   SiStripFecKey(const SiStripKey&, const sistrip::Granularity&);
0072 
0073   /** Default constructor */
0074   SiStripFecKey();
0075 
0076   /** Assignment operator */
0077   SiStripFecKey& operator=(const SiStripFecKey&) = default;
0078 
0079   // ---------- Control structure ----------
0080 
0081   /** Returns VME crate. */
0082   inline const uint16_t& fecCrate() const;
0083 
0084   /** Returns FEC identifier (VME slot). */
0085   inline const uint16_t& fecSlot() const;
0086 
0087   /** Returns FEC control ring. */
0088   inline const uint16_t& fecRing() const;
0089 
0090   /** Returns CCU module. */
0091   inline const uint16_t& ccuAddr() const;
0092 
0093   /** Returns Front-End module. */
0094   inline const uint16_t& ccuChan() const;
0095 
0096   /** Returns LLD channel. */
0097   inline const uint16_t& lldChan() const;
0098 
0099   /** Returns I2C address ("invalid" if inconsistent with LLD chan. */
0100   inline const uint16_t& i2cAddr() const;
0101 
0102   // ---------- Hybrid APV/LLD numbering scheme ----------
0103 
0104   /** Returns hybrid position (1-6) for a given I2C addr (32-37). */
0105   static uint16_t hybridPos(const uint16_t& i2c_addr);
0106 
0107   /** Returns I2C addr (32-37) for a given hybrid position (1-6). */
0108   static uint16_t i2cAddr(const uint16_t& hybrid_pos);
0109 
0110   /** Returns LLD channel (1-3) for a given APV I2C addr (32-37). */
0111   static uint16_t lldChan(const uint16_t& i2c_addr);
0112 
0113   /** Identifies if first APV of pair for given I2C addr (32-37). */
0114   static bool firstApvOfPair(const uint16_t& i2c_addr);
0115 
0116   /** Returns I2C addr (32-37) for LLD chan (1-3) and APV pos. */
0117   static uint16_t i2cAddr(const uint16_t& lld_chan, const bool& first_apv_of_pair);
0118 
0119   // ---------- Utility methods ----------
0120 
0121   /** Identifies key objects with identical member data. */
0122   bool isEqual(const SiStripKey&) const override;
0123 
0124   /** "Consistent" means identical and/or null (ie, "all") data. */
0125   bool isConsistent(const SiStripKey&) const override;
0126 
0127   /** Identifies all member data as being "valid" or "all" (null). */
0128   bool isValid() const override;
0129 
0130   /** All member data to level of "Granularity" are "valid". If
0131       sistrip::Granularity is "undefined", returns false. */
0132   bool isValid(const sistrip::Granularity&) const override;
0133 
0134   /** Identifies all member data as being "invalid". */
0135   bool isInvalid() const override;
0136 
0137   /** All member data to level of "Granularity" are invalid. If
0138       sistrip::Granularity is "undefined", returns true.  */
0139   bool isInvalid(const sistrip::Granularity&) const override;
0140 
0141   // ---------- Print methods ----------
0142 
0143   /** A terse summary of the key  */
0144   void print(std::stringstream& ss) const override;
0145 
0146   /** A terse summary of the key  */
0147   void terse(std::stringstream& ss) const override;
0148 
0149 private:
0150   // ---------- Private methods ----------
0151 
0152   void initFromValue() override;
0153   void initFromKey() override;
0154   void initFromPath() override;
0155   void initGranularity() override;
0156 
0157   // ---------- Private member data ----------
0158 
0159   /** FEC crate [0,1-4,invalid]. */
0160   uint16_t fecCrate_;
0161 
0162   /** FEC slot [0,2-21,invalid]. */
0163   uint16_t fecSlot_;
0164 
0165   /** FEC ring [0,1-8,invalid]. */
0166   uint16_t fecRing_;
0167 
0168   /** CCU module [0,1-126,invalid]. */
0169   uint16_t ccuAddr_;
0170 
0171   /** FE module [0,16-31,invalid]. */
0172   uint16_t ccuChan_;
0173 
0174   /** LLD channel [0,1-3,invalid]. */
0175   uint16_t lldChan_;
0176 
0177   /** APV I2C address [0,32-37,invalid]. */
0178   uint16_t i2cAddr_;
0179 
0180   // Definition of bit field positions for 32-bit key
0181   static const uint16_t fecCrateOffset_ = 27;
0182   static const uint16_t fecSlotOffset_ = 22;
0183   static const uint16_t fecRingOffset_ = 18;
0184   static const uint16_t ccuAddrOffset_ = 10;
0185   static const uint16_t ccuChanOffset_ = 5;
0186   static const uint16_t lldChanOffset_ = 2;
0187   static const uint16_t i2cAddrOffset_ = 0;
0188 
0189   // Definition of bit field masks for 32-bit key
0190   static const uint16_t fecCrateMask_ = 0x07;  // (3 bits)
0191   static const uint16_t fecSlotMask_ = 0x1F;   // (5 bits)
0192   static const uint16_t fecRingMask_ = 0x0F;   // (4 bits)
0193   static const uint16_t ccuAddrMask_ = 0xFF;   // (8 bits)
0194   static const uint16_t ccuChanMask_ = 0x1F;   // (5 bits)
0195   static const uint16_t lldChanMask_ = 0x07;   // (3 bits)
0196   static const uint16_t i2cAddrMask_ = 0x03;   // (2 bits)
0197 };
0198 
0199 // ---------- Inline methods ----------
0200 
0201 const uint16_t& SiStripFecKey::fecCrate() const { return fecCrate_; }
0202 const uint16_t& SiStripFecKey::fecSlot() const { return fecSlot_; }
0203 const uint16_t& SiStripFecKey::fecRing() const { return fecRing_; }
0204 const uint16_t& SiStripFecKey::ccuAddr() const { return ccuAddr_; }
0205 const uint16_t& SiStripFecKey::ccuChan() const { return ccuChan_; }
0206 const uint16_t& SiStripFecKey::lldChan() const { return lldChan_; }
0207 const uint16_t& SiStripFecKey::i2cAddr() const { return i2cAddr_; }
0208 
0209 /* const uint16_t& SiStripFecKey::fecCrate() const {  */
0210 /*   return ( key()>>fecCrateOffset_ ) & fecCrateMask_ != fecCrateMask_ ? ( key()>>fecCrateOffset_ ) & fecCrateMask_ : sistrip::invalid_;  */
0211 /* } */
0212 /* const uint16_t& SiStripFecKey::fecSlot() const {  */
0213 /*   return ( key()>>fecSlotOffset_ ) & fecSlotMask_ != fecSlotMask_ ? ( key()>>fecSlotOffset_ ) & fecSlotMask_ : sistrip::invalid_;  */
0214 /* } */
0215 /* const uint16_t& SiStripFecKey::fecRing() const {  */
0216 /*   return ( key()>>fecRingOffset_ ) & fecRingMask_ != fecRingMask_ ? ( key()>>fecRingOffset_ ) & fecRingMask_ : sistrip::invalid_;  */
0217 /* } */
0218 /* const uint16_t& SiStripFecKey::ccuAddr() const {  */
0219 /*   return ( key()>>ccuAddrOffset_ ) & ccuAddrMask_ != ccuAddrMask_ ? ( key()>>ccuAddrOffset_ ) & ccuAddrMask_ : sistrip::invalid_;  */
0220 /* } */
0221 /* const uint16_t& SiStripFecKey::ccuChan() const {  */
0222 /*   return ( key()>>ccuChanOffset_ ) & ccuChanMask_ != ccuChanMask_ ? ( key()>>ccuChanOffset_ ) & ccuChanMask_ : sistrip::invalid_;  */
0223 /* } */
0224 /* const uint16_t& SiStripFecKey::lldChan() const {  */
0225 /*   return ( key()>>lldChanOffset_ ) & lldChanMask_ != lldChanMask_ ? ( key()>>lldChanOffset_ ) & lldChanMask_ : sistrip::invalid_;  */
0226 /* } */
0227 /* const uint16_t& SiStripFecKey::i2cAddr() const {  */
0228 /*   return ( key()>>i2cAddrOffset_ ) & i2cAddrMask_ != i2cAddrMask_ ? ( key()>>i2cAddrOffset_ ) & i2cAddrMask_ : sistrip::invalid_;  */
0229 /* } */
0230 
0231 std::ostream& operator<<(std::ostream&, const SiStripFecKey&);
0232 
0233 inline bool operator<(const SiStripFecKey& a, const SiStripFecKey& b) { return (a.key() < b.key()); }
0234 
0235 class ConsistentWithKey {
0236 public:
0237   explicit ConsistentWithKey(const SiStripFecKey& key);
0238   bool operator()(const uint32_t&, const uint32_t&) const;
0239 
0240 private:
0241   explicit ConsistentWithKey();
0242   SiStripFecKey mask_;
0243 };
0244 
0245 #endif  // DataFormats_SiStripCommon_SiStripFecKey_H