Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-20 02:14:42

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