CMS 3D CMS Logo

GEMVFAT.cc
Go to the documentation of this file.
2 #include <iostream>
3 
4 GEMVFAT::GEMVFAT() : ver_(0), phiPos_(0), fw_(0), sw_(0), tw_(0) {}
5 
6 GEMVFAT::GEMVFAT(const int vfatVer,
7  const uint16_t BC,
8  const uint32_t EC,
9  const uint16_t chipID,
10  const uint64_t lsDatas,
11  const uint64_t msDatas) {
12  // this constructor only used for packing sim digis
13  VFATfirst fw{0};
14  VFATsecond sw{0};
15  VFATthird tw{0};
16 
17  fw.header = 0x1E;
18 
19  if (vfatVer == 3) {
20  fw.bc = BC;
21  fw.ec = EC;
22  fw.pos = chipID;
23  } else {
24  fw.chipID = chipID;
25  fw.b1110 = 14;
26  fw.b1100 = 12;
27  fw.b1010 = 10;
28  fw.ecV2 = EC;
29  fw.bcV2 = BC;
30  }
31 
32  sw.lsData1 = lsDatas >> 48;
33  tw.lsData2 = lsDatas & 0x0000ffffffffffff;
34 
35  fw.msData1 = msDatas >> 48;
36  sw.msData2 = msDatas & 0x0000ffffffffffff;
37  ver_ = vfatVer;
38 
39  fw_ = fw.word;
40  sw_ = sw.word;
41  tw_ = tw.word;
42  // checkCRC only works after words are set
43  // checkCRC not yet implemented for v3
44  tw.crc = checkCRC();
45  // once crc is found, save new third word
46  tw_ = tw.word;
47 }
48 
49 uint8_t GEMVFAT::quality() {
50  uint8_t q = 0;
51  if (ver_ == 2) {
52  if (VFATthird{tw_}.crc != checkCRC())
53  q = 1;
54  if (VFATfirst{fw_}.b1010 != 10)
55  q |= 1UL << 1;
56  if (VFATfirst{fw_}.b1100 != 12)
57  q |= 1UL << 2;
58  if (VFATfirst{fw_}.b1110 != 14)
59  q |= 1UL << 3;
60  }
61  // quality test not yet implemented in v3
62  return q;
63 }
64 
65 uint16_t GEMVFAT::crc_cal(uint16_t crc_in, uint16_t dato) {
66  uint16_t v = 0x0001;
67  uint16_t mask = 0x0001;
68  uint16_t d = 0x0000;
69  uint16_t crc_temp = crc_in;
70  unsigned char datalen = 16;
71  for (int i = 0; i < datalen; i++) {
72  if (dato & v)
73  d = 0x0001;
74  else
75  d = 0x0000;
76  if ((crc_temp & mask) ^ d)
77  crc_temp = crc_temp >> 1 ^ 0x8408;
78  else
79  crc_temp = crc_temp >> 1;
80  v <<= 1;
81  }
82  return crc_temp;
83 }
84 
85 uint16_t GEMVFAT::checkCRC() {
86  uint16_t vfatBlockWords[12];
87  vfatBlockWords[11] = ((0x000f & VFATfirst{fw_}.b1010) << 12) | VFATfirst{fw_}.bcV2;
88  vfatBlockWords[10] =
89  ((0x000f & VFATfirst{fw_}.b1100) << 12) | ((0x00ff & VFATfirst{fw_}.ecV2) << 4) | (0x000f & VFATfirst{fw_}.flag);
90  vfatBlockWords[9] = ((0x000f & VFATfirst{fw_}.b1110) << 12) | VFATfirst{fw_}.chipID;
91  vfatBlockWords[8] = (0xffff000000000000 & msData()) >> 48;
92  vfatBlockWords[7] = (0x0000ffff00000000 & msData()) >> 32;
93  vfatBlockWords[6] = (0x00000000ffff0000 & msData()) >> 16;
94  vfatBlockWords[5] = (0x000000000000ffff & msData());
95  vfatBlockWords[4] = (0xffff000000000000 & lsData()) >> 48;
96  vfatBlockWords[3] = (0x0000ffff00000000 & lsData()) >> 32;
97  vfatBlockWords[2] = (0x00000000ffff0000 & lsData()) >> 16;
98  vfatBlockWords[1] = (0x000000000000ffff & lsData());
99 
100  uint16_t crc_fin = 0xffff;
101  for (int i = 11; i >= 1; i--) {
102  crc_fin = crc_cal(crc_fin, vfatBlockWords[i]);
103  }
104  return crc_fin;
105 }
uint64_t fw_
phi position of vfat in chamber
Definition: GEMVFAT.h:123
uint16_t crc_cal(uint16_t crc_in, uint16_t dato)
Definition: GEMVFAT.cc:65
uint8_t quality()
quality flag - bit: 0 good, 1 crc fail, 2 b1010 fail, 3 b1100 fail, 4 b1110
Definition: GEMVFAT.cc:49
constexpr uint32_t mask
Definition: gpuClustering.h:24
GEMVFAT()
Definition: GEMVFAT.cc:4
uint64_t sw_
Definition: GEMVFAT.h:124
int ver_
Definition: GEMVFAT.h:120
d
Definition: ztail.py:151
uint64_t lsData() const
Definition: GEMVFAT.h:74
unsigned long long uint64_t
Definition: Time.h:13
uint16_t chipID() const
Definition: GEMVFAT.h:110
uint16_t checkCRC()
Definition: GEMVFAT.cc:85
uint64_t tw_
Definition: GEMVFAT.h:125
uint64_t msData() const
Definition: GEMVFAT.h:75
VFAT data structure - 3 words of 64 bits each.
Definition: GEMVFAT.h:8