CMS 3D CMS Logo

VFATdata.cc
Go to the documentation of this file.
2 #include <iostream>
3 using namespace gem;
4 
6  ver_ = 1;
7 }
8 
9 VFATdata::VFATdata(const int vfatVer,
10  const uint16_t BC,
11  const uint8_t EC,
12  const uint16_t chipID,
13  const uint64_t lsDatas,
14  const uint64_t msDatas)
15 {
16  // this constructor only used for packing sim digis
17  VFATfirst fw;
18  VFATsecond sw;
19  VFATthird tw;
20 
21  fw.word = 0;
22  sw.word = 0;
23  tw.word = 0;
24  fw.header = 0x1E;
25 
26  if (vfatVer == 3) {
27  fw.bc = BC;
28  fw.ec = EC;
29  fw.pos = chipID;
30  }
31  else {
32  fw.chipID = chipID;
33  fw.b1110 = 14;
34  fw.b1100 = 12;
35  fw.b1010 = 10;
36  fw.ecV2 = EC;
37  fw.bcV2 = BC;
38  }
39 
40  sw.lsData1 = lsDatas >> 48;
41  tw.lsData2 = lsDatas & 0x0000ffffffffffff;
42 
43  fw.msData1 = msDatas >> 48;
44  sw.msData2 = msDatas & 0x0000ffffffffffff;
45  ver_ = vfatVer;
46 
47  fw_ = fw.word;
48  sw_ = sw.word;
49  tw_ = tw.word;
50  // checkCRC only works after words are set
51  // checkCRC not yet implemented for v3
52  tw.crc = checkCRC();
53  // once crc is found, save new third word
54  tw_ = tw.word;
55 }
56 
57 uint8_t VFATdata::quality() {
58  uint8_t q = 0;
59  if (ver_ == 2) {
60  if (VFATthird{tw_}.crc != checkCRC()) q = 1;
61  if (VFATfirst{fw_}.b1010 != 10) q |= 1UL << 1;
62  if (VFATfirst{fw_}.b1100 != 12) q |= 1UL << 2;
63  if (VFATfirst{fw_}.b1110 != 14) q |= 1UL << 3;
64  }
65  // quality test not yet implemented in v3
66  return q;
67 }
68 
69 uint16_t VFATdata::crc_cal(uint16_t crc_in, uint16_t dato)
70 {
71  uint16_t v = 0x0001;
72  uint16_t mask = 0x0001;
73  uint16_t d=0x0000;
74  uint16_t crc_temp = crc_in;
75  unsigned char datalen = 16;
76  for (int i=0; i<datalen; i++) {
77  if (dato & v) d = 0x0001;
78  else d = 0x0000;
79  if ((crc_temp & mask)^d) crc_temp = crc_temp>>1 ^ 0x8408;
80  else crc_temp = crc_temp>>1;
81  v<<=1;
82  }
83  return crc_temp;
84 }
85 
87 {
88  uint16_t vfatBlockWords[12];
89  vfatBlockWords[11] = ((0x000f & VFATfirst{fw_}.b1010)<<12) | VFATfirst{fw_}.bcV2;
90  vfatBlockWords[10] = ((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 }
uint64_t ec
Event Counter, 8 bits.
Definition: VFATdata.h:14
uint64_t bcV2
Bunch Crossing number, 12 bits.
Definition: VFATdata.h:27
uint64_t ecV2
Event Counter, 8 bits.
Definition: VFATdata.h:25
uint64_t tw_
Definition: VFATdata.h:127
uint64_t msData2
channels from 65to128
Definition: VFATdata.h:35
Definition: AMC13Event.h:6
uint64_t crc
Check Sum value, 16 bits.
Definition: VFATdata.h:41
uint64_t word
Definition: VFATdata.h:9
uint64_t word
Definition: VFATdata.h:39
uint64_t lsData2
channels from 1to64
Definition: VFATdata.h:42
uint64_t sw_
Definition: VFATdata.h:126
uint64_t msData1
channels from 65to128
Definition: VFATdata.h:12
uint64_t word
Definition: VFATdata.h:32
uint64_t b1110
1110:4 Control bits, shoud be 1110
Definition: VFATdata.h:23
uint64_t lsData() const
Definition: VFATdata.h:76
uint16_t chipID() const
Definition: VFATdata.h:112
uint64_t lsData1
channels from 1to64
Definition: VFATdata.h:34
unsigned long long uint64_t
Definition: Time.h:15
uint64_t msData() const
Definition: VFATdata.h:79
uint64_t bc
Bunch Crossing number, 16 bits.
Definition: VFATdata.h:13
uint64_t pos
an 8bit value indicating the VFAT position on this GEB (it can be 0 to 23)
Definition: VFATdata.h:17
uint16_t checkCRC()
Definition: VFATdata.cc:86
uint64_t b1010
1010:4 Control bits, shoud be 1010
Definition: VFATdata.h:28
uint64_t chipID
Chip ID, 12 bits.
Definition: VFATdata.h:22
uint64_t header
normally 0x1E. 0x5E indicates that the VFAT3 internal buffer is half-full, so it&#39;s like a warning ...
Definition: VFATdata.h:15
VFAT data structure - 3 words of 64 bits each.
Definition: VFATdata.h:8
uint8_t quality()
quality flag - bit: 0 good, 1 crc fail, 2 b1010 fail, 3 b1100 fail, 4 b1110
Definition: VFATdata.cc:57
uint64_t b1100
1100:4, Control bits, shoud be 1100
Definition: VFATdata.h:26
uint16_t crc_cal(uint16_t crc_in, uint16_t dato)
Definition: VFATdata.cc:69
uint64_t fw_
phi position of vfat in chamber
Definition: VFATdata.h:125