Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_GEMDigi_GEMVFAT_h
0002 #define DataFormats_GEMDigi_GEMVFAT_h
0003 #include <cstdint>
0004 
0005 class GEMVFAT {
0006 public:
0007   /// VFAT data structure - 3 words of 64 bits each
0008   union VFATfirst {
0009     uint64_t word;
0010     // v3 dataformat
0011     struct {
0012       uint64_t msData1 : 16;  ///<channels from 65to128
0013       uint64_t bc : 16;       ///<Bunch Crossing number, 16 bits
0014       uint64_t ec : 8;        ///<Event Counter, 8 bits
0015       uint64_t header : 8;    ///<normally 0x1E. 0x5E indicates that the VFAT3 internal buffer
0016       // is half-full, so it's like a warning
0017       uint64_t vc : 1;   /// VFAT CRC Error
0018       uint64_t : 7;      // unused
0019       uint64_t pos : 5;  // VFAT position on chamber, 5 used in GE11 but more is needed for phase2
0020       uint64_t : 3;      // unused
0021     };
0022     // v2 dataformat
0023     struct {
0024       uint64_t msData1v2 : 16;  ///<channels from 65to128 - placeholder since msData1 reads same info
0025       uint64_t chipID : 12;     ///<Chip ID, 12 bits
0026       uint64_t b1110 : 4;       ///<1110:4 Control bits, shoud be 1110
0027       uint64_t flag : 4;        ///<Control Flags: 4 bits, Hamming Error/AFULL/SEUlogic/SUEI2C
0028       uint64_t ecV2 : 8;        ///<Event Counter, 8 bits
0029       uint64_t b1100 : 4;       ///<1100:4, Control bits, shoud be 1100
0030       uint64_t bcV2 : 12;       ///<Bunch Crossing number, 12 bits
0031       uint64_t b1010 : 4;       ///<1010:4 Control bits, shoud be 1010
0032     };
0033   };
0034   union VFATsecond {
0035     uint64_t word;
0036     struct {
0037       uint64_t lsData1 : 16;  ///<channels from 1to64
0038       uint64_t msData2 : 48;  ///<channels from 65to128
0039     };
0040   };
0041   union VFATthird {
0042     uint64_t word;
0043     struct {
0044       uint64_t crc : 16;      ///<Check Sum value, 16 bits
0045       uint64_t lsData2 : 48;  ///<channels from 1to64
0046     };
0047   };
0048 
0049   GEMVFAT();
0050   // this constructor only used for packing sim digis
0051   GEMVFAT(const int vfatVer,
0052           const uint16_t BC,
0053           const uint32_t EC,
0054           const uint16_t chipID,
0055           const uint64_t lsDatas,
0056           const uint64_t msDatas);
0057   ~GEMVFAT() {}
0058 
0059   //!Read first word from the block.
0060   void read_fw(uint64_t word) { fw_ = word; }
0061   uint64_t get_fw() const { return fw_; }
0062 
0063   //!Read second word from the block.
0064   void read_sw(uint64_t word) { sw_ = word; }
0065   uint64_t get_sw() const { return sw_; }
0066 
0067   //!Read third word from the block.
0068   void read_tw(uint64_t word) { tw_ = word; }
0069   uint64_t get_tw() const { return tw_; }
0070 
0071   // local phi in chamber
0072   void setPhi(int i) { phiPos_ = i; }
0073   int phi() const { return phiPos_; }
0074 
0075   uint64_t lsData() const { return uint64_t(VFATsecond{sw_}.lsData1) << 48 | VFATthird{tw_}.lsData2; }
0076   uint64_t msData() const { return uint64_t(VFATfirst{fw_}.msData1) << 48 | VFATsecond{sw_}.msData2; }
0077 
0078   uint16_t bc() const {
0079     if (ver_ == 2)
0080       return VFATfirst{fw_}.bcV2;
0081     return VFATfirst{fw_}.bc;
0082   }
0083   uint8_t ec() const {
0084     if (ver_ == 2)
0085       return VFATfirst{fw_}.ecV2;
0086     return VFATfirst{fw_}.ec;
0087   }
0088   uint16_t vfatId() const {
0089     if (ver_ == 2)
0090       return VFATfirst{fw_}.chipID;
0091     return VFATfirst{fw_}.pos;
0092   }
0093 
0094   void setVersion(int i) { ver_ = i; }
0095   int version() const { return ver_; }
0096 
0097   /// quality flag - bit: 0 good, 1 crc fail, 2 b1010 fail, 3 b1100 fail, 4 b1110
0098   uint8_t quality();
0099 
0100   /// v3
0101   uint8_t header() const { return VFATfirst{fw_}.header; }
0102   bool vc() const { return VFATfirst{fw_}.vc; }
0103   uint8_t position() const { return VFATfirst{fw_}.pos; }
0104   uint8_t crcCheck() const { return VFATfirst{fw_}.vc; }  // to be removed
0105 
0106   /// v2
0107   uint8_t b1010() const { return VFATfirst{fw_}.b1010; }
0108   uint8_t b1100() const { return VFATfirst{fw_}.b1100; }
0109   uint8_t b1110() const { return VFATfirst{fw_}.b1110; }
0110   uint8_t flag() const { return VFATfirst{fw_}.flag; }
0111   uint16_t chipID() const { return VFATfirst{fw_}.chipID; }
0112   uint16_t crc() const { return VFATthird{tw_}.crc; }
0113 
0114   uint16_t crc_cal(uint16_t crc_in, uint16_t dato);
0115   uint16_t checkCRC();
0116 
0117   static const int nChannels = 128;
0118   static const int sizeChipID = 12;
0119 
0120 private:
0121   int ver_;     /// vfat version
0122   int phiPos_;  /// phi position of vfat in chamber
0123 
0124   uint64_t fw_;  // VFAT first word
0125   uint64_t sw_;  // VFAT second word
0126   uint64_t tw_;  // VFAT third word
0127 };
0128 
0129 #endif