Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:42

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   // ---------- Control structure ----------
0077 
0078   /** Returns VME crate. */
0079   inline const uint16_t& fecCrate() const;
0080 
0081   /** Returns FEC identifier (VME slot). */
0082   inline const uint16_t& fecSlot() const;
0083 
0084   /** Returns FEC control ring. */
0085   inline const uint16_t& fecRing() const;
0086 
0087   /** Returns CCU module. */
0088   inline const uint16_t& ccuAddr() const;
0089 
0090   /** Returns Front-End module. */
0091   inline const uint16_t& ccuChan() const;
0092 
0093   /** Returns LLD channel. */
0094   inline const uint16_t& lldChan() const;
0095 
0096   /** Returns I2C address ("invalid" if inconsistent with LLD chan. */
0097   inline const uint16_t& i2cAddr() const;
0098 
0099   // ---------- Hybrid APV/LLD numbering scheme ----------
0100 
0101   /** Returns hybrid position (1-6) for a given I2C addr (32-37). */
0102   static uint16_t hybridPos(const uint16_t& i2c_addr);
0103 
0104   /** Returns I2C addr (32-37) for a given hybrid position (1-6). */
0105   static uint16_t i2cAddr(const uint16_t& hybrid_pos);
0106 
0107   /** Returns LLD channel (1-3) for a given APV I2C addr (32-37). */
0108   static uint16_t lldChan(const uint16_t& i2c_addr);
0109 
0110   /** Identifies if first APV of pair for given I2C addr (32-37). */
0111   static bool firstApvOfPair(const uint16_t& i2c_addr);
0112 
0113   /** Returns I2C addr (32-37) for LLD chan (1-3) and APV pos. */
0114   static uint16_t i2cAddr(const uint16_t& lld_chan, const bool& first_apv_of_pair);
0115 
0116   // ---------- Utility methods ----------
0117 
0118   /** Identifies key objects with identical member data. */
0119   bool isEqual(const SiStripKey&) const override;
0120 
0121   /** "Consistent" means identical and/or null (ie, "all") data. */
0122   bool isConsistent(const SiStripKey&) const override;
0123 
0124   /** Identifies all member data as being "valid" or "all" (null). */
0125   bool isValid() const override;
0126 
0127   /** All member data to level of "Granularity" are "valid". If
0128       sistrip::Granularity is "undefined", returns false. */
0129   bool isValid(const sistrip::Granularity&) const override;
0130 
0131   /** Identifies all member data as being "invalid". */
0132   bool isInvalid() const override;
0133 
0134   /** All member data to level of "Granularity" are invalid. If
0135       sistrip::Granularity is "undefined", returns true.  */
0136   bool isInvalid(const sistrip::Granularity&) const override;
0137 
0138   // ---------- Print methods ----------
0139 
0140   /** A terse summary of the key  */
0141   void print(std::stringstream& ss) const override;
0142 
0143   /** A terse summary of the key  */
0144   void terse(std::stringstream& ss) const override;
0145 
0146 private:
0147   // ---------- Private methods ----------
0148 
0149   void initFromValue() override;
0150   void initFromKey() override;
0151   void initFromPath() override;
0152   void initGranularity() override;
0153 
0154   // ---------- Private member data ----------
0155 
0156   /** FEC crate [0,1-4,invalid]. */
0157   uint16_t fecCrate_;
0158 
0159   /** FEC slot [0,2-21,invalid]. */
0160   uint16_t fecSlot_;
0161 
0162   /** FEC ring [0,1-8,invalid]. */
0163   uint16_t fecRing_;
0164 
0165   /** CCU module [0,1-126,invalid]. */
0166   uint16_t ccuAddr_;
0167 
0168   /** FE module [0,16-31,invalid]. */
0169   uint16_t ccuChan_;
0170 
0171   /** LLD channel [0,1-3,invalid]. */
0172   uint16_t lldChan_;
0173 
0174   /** APV I2C address [0,32-37,invalid]. */
0175   uint16_t i2cAddr_;
0176 
0177   // Definition of bit field positions for 32-bit key
0178   static const uint16_t fecCrateOffset_ = 27;
0179   static const uint16_t fecSlotOffset_ = 22;
0180   static const uint16_t fecRingOffset_ = 18;
0181   static const uint16_t ccuAddrOffset_ = 10;
0182   static const uint16_t ccuChanOffset_ = 5;
0183   static const uint16_t lldChanOffset_ = 2;
0184   static const uint16_t i2cAddrOffset_ = 0;
0185 
0186   // Definition of bit field masks for 32-bit key
0187   static const uint16_t fecCrateMask_ = 0x07;  // (3 bits)
0188   static const uint16_t fecSlotMask_ = 0x1F;   // (5 bits)
0189   static const uint16_t fecRingMask_ = 0x0F;   // (4 bits)
0190   static const uint16_t ccuAddrMask_ = 0xFF;   // (8 bits)
0191   static const uint16_t ccuChanMask_ = 0x1F;   // (5 bits)
0192   static const uint16_t lldChanMask_ = 0x07;   // (3 bits)
0193   static const uint16_t i2cAddrMask_ = 0x03;   // (2 bits)
0194 };
0195 
0196 // ---------- Inline methods ----------
0197 
0198 const uint16_t& SiStripFecKey::fecCrate() const { return fecCrate_; }
0199 const uint16_t& SiStripFecKey::fecSlot() const { return fecSlot_; }
0200 const uint16_t& SiStripFecKey::fecRing() const { return fecRing_; }
0201 const uint16_t& SiStripFecKey::ccuAddr() const { return ccuAddr_; }
0202 const uint16_t& SiStripFecKey::ccuChan() const { return ccuChan_; }
0203 const uint16_t& SiStripFecKey::lldChan() const { return lldChan_; }
0204 const uint16_t& SiStripFecKey::i2cAddr() const { return i2cAddr_; }
0205 
0206 /* const uint16_t& SiStripFecKey::fecCrate() const {  */
0207 /*   return ( key()>>fecCrateOffset_ ) & fecCrateMask_ != fecCrateMask_ ? ( key()>>fecCrateOffset_ ) & fecCrateMask_ : sistrip::invalid_;  */
0208 /* } */
0209 /* const uint16_t& SiStripFecKey::fecSlot() const {  */
0210 /*   return ( key()>>fecSlotOffset_ ) & fecSlotMask_ != fecSlotMask_ ? ( key()>>fecSlotOffset_ ) & fecSlotMask_ : sistrip::invalid_;  */
0211 /* } */
0212 /* const uint16_t& SiStripFecKey::fecRing() const {  */
0213 /*   return ( key()>>fecRingOffset_ ) & fecRingMask_ != fecRingMask_ ? ( key()>>fecRingOffset_ ) & fecRingMask_ : sistrip::invalid_;  */
0214 /* } */
0215 /* const uint16_t& SiStripFecKey::ccuAddr() const {  */
0216 /*   return ( key()>>ccuAddrOffset_ ) & ccuAddrMask_ != ccuAddrMask_ ? ( key()>>ccuAddrOffset_ ) & ccuAddrMask_ : sistrip::invalid_;  */
0217 /* } */
0218 /* const uint16_t& SiStripFecKey::ccuChan() const {  */
0219 /*   return ( key()>>ccuChanOffset_ ) & ccuChanMask_ != ccuChanMask_ ? ( key()>>ccuChanOffset_ ) & ccuChanMask_ : sistrip::invalid_;  */
0220 /* } */
0221 /* const uint16_t& SiStripFecKey::lldChan() const {  */
0222 /*   return ( key()>>lldChanOffset_ ) & lldChanMask_ != lldChanMask_ ? ( key()>>lldChanOffset_ ) & lldChanMask_ : sistrip::invalid_;  */
0223 /* } */
0224 /* const uint16_t& SiStripFecKey::i2cAddr() const {  */
0225 /*   return ( key()>>i2cAddrOffset_ ) & i2cAddrMask_ != i2cAddrMask_ ? ( key()>>i2cAddrOffset_ ) & i2cAddrMask_ : sistrip::invalid_;  */
0226 /* } */
0227 
0228 std::ostream& operator<<(std::ostream&, const SiStripFecKey&);
0229 
0230 inline bool operator<(const SiStripFecKey& a, const SiStripFecKey& b) { return (a.key() < b.key()); }
0231 
0232 class ConsistentWithKey {
0233 public:
0234   explicit ConsistentWithKey(const SiStripFecKey& key);
0235   bool operator()(const uint32_t&, const uint32_t&) const;
0236 
0237 private:
0238   explicit ConsistentWithKey();
0239   SiStripFecKey mask_;
0240 };
0241 
0242 #endif  // DataFormats_SiStripCommon_SiStripFecKey_H