CMS 3D CMS Logo

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