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
0008 union VFATfirst {
0009 uint64_t word;
0010
0011 struct {
0012 uint64_t msData1 : 16;
0013 uint64_t bc : 16;
0014 uint64_t ec : 8;
0015 uint64_t header : 8;
0016
0017 uint64_t vc : 1;
0018 uint64_t : 7;
0019 uint64_t pos : 5;
0020 uint64_t : 3;
0021 };
0022
0023 struct {
0024 uint64_t msData1v2 : 16;
0025 uint64_t chipID : 12;
0026 uint64_t b1110 : 4;
0027 uint64_t flag : 4;
0028 uint64_t ecV2 : 8;
0029 uint64_t b1100 : 4;
0030 uint64_t bcV2 : 12;
0031 uint64_t b1010 : 4;
0032 };
0033 };
0034 union VFATsecond {
0035 uint64_t word;
0036 struct {
0037 uint64_t lsData1 : 16;
0038 uint64_t msData2 : 48;
0039 };
0040 };
0041 union VFATthird {
0042 uint64_t word;
0043 struct {
0044 uint64_t crc : 16;
0045 uint64_t lsData2 : 48;
0046 };
0047 };
0048
0049 GEMVFAT();
0050
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
0060 void read_fw(uint64_t word) { fw_ = word; }
0061 uint64_t get_fw() const { return fw_; }
0062
0063
0064 void read_sw(uint64_t word) { sw_ = word; }
0065 uint64_t get_sw() const { return sw_; }
0066
0067
0068 void read_tw(uint64_t word) { tw_ = word; }
0069 uint64_t get_tw() const { return tw_; }
0070
0071
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
0098 uint8_t quality();
0099
0100
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; }
0105
0106
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_;
0122 int phiPos_;
0123
0124 uint64_t fw_;
0125 uint64_t sw_;
0126 uint64_t tw_;
0127 };
0128
0129 #endif