CMS 3D CMS Logo

VFATdata.h
Go to the documentation of this file.
1 #ifndef EventFilter_GEMRawToDigi_VFATdata_h
2 #define EventFilter_GEMRawToDigi_VFATdata_h
3 
4 #include <stdint.h>
5 
6 namespace gem {
7  class VFATdata
8  {
9  public:
12  VFATdata(const uint8_t b1010_,
13  const uint16_t BC_,
14  const uint8_t b1100_,
15  const uint8_t EC_,
16  const uint8_t Flag_,
17  const uint8_t b1110_,
18  const uint16_t ChipID_,
19  const uint64_t lsData_,
20  const uint64_t msData_,
21  const uint16_t crc_,
22  const uint16_t crc_calc_,
23  const int SlotNumber_,
24  const bool isBlockGood_) :
25  m_b1010(b1010_),
26  m_BC(BC_),
27  m_b1100(b1100_),
28  m_EC(EC_),
29  m_Flag(Flag_),
30  m_b1110(b1110_),
31  m_ChipID(ChipID_),
32  m_lsData(lsData_),
33  m_msData(msData_),
34  m_crc(crc_),
35  m_crc_calc(crc_calc_),
36  m_SlotNumber(SlotNumber_),
37  m_isBlockGood(isBlockGood_){
38  if (m_crc == 0)
39  m_crc = this->checkCRC();
40  }
41 
43  void read_fw(uint64_t word)
44  {
45  m_b1010 = 0x0f & (word >> 60);
46  m_BC = 0x0fff & (word >> 48);
47  m_b1100 = 0x0f & (word >> 44);
48  m_EC = word >> 36;
49  m_Flag = 0x0f & (word >> 32);
50  m_b1110 = 0x0f & (word >> 28);
51  m_ChipID = 0x0fff & (word >> 16);
52  m_msData = 0xffff000000000000 & (word << 48);
53  }
54  uint64_t get_fw() const
55  {
56  return
57  (static_cast<uint64_t>(m_b1010 & 0x0f) << 60) |
58  (static_cast<uint64_t>(m_BC & 0x0fff) << 48) |
59  (static_cast<uint64_t>(m_b1100 & 0x0f) << 44) |
60  (static_cast<uint64_t>(m_EC) << 36) |
61  (static_cast<uint64_t>(m_Flag & 0x0f) << 32) |
62  (static_cast<uint64_t>(m_b1110 & 0x0f) << 28) |
63  (static_cast<uint64_t>(m_ChipID & 0x0fff) << 16) |
64  (static_cast<uint64_t>(m_msData & 0xffff000000000000) >> 48);
65  }
66 
68  void read_sw(uint64_t word)
69  {
70  m_msData = m_msData | (0x0000ffffffffffff & word >> 16);
71  m_lsData = 0xffff000000000000 & (word << 48);
72  }
73  uint64_t get_sw() const
74  {
75  return
76  (static_cast<uint64_t>(m_msData & 0x0000ffffffffffff) << 16) |
77  (static_cast<uint64_t>(m_lsData & 0xffff000000000000) >> 48);
78  }
79 
81  void read_tw(uint64_t word)
82  {
83  m_lsData = m_lsData | (0x0000ffffffffffff & word >> 16);
84  m_crc = word;
85  }
86  // make write_word function
87  uint64_t get_tw() const
88  {
89  return
90  (static_cast<uint64_t>(m_lsData & 0x0000ffffffffffff) << 16) |
91  (static_cast<uint64_t>(m_crc));
92  }
93 
94  uint8_t b1010 () const { return m_b1010; }
95  uint16_t bc () const { return m_BC; }
96  uint8_t b1100 () const { return m_b1100; }
97  uint8_t ec () const { return m_EC; }
98  uint8_t flag () const { return m_Flag; }
99  uint8_t b1110 () const { return m_b1110; }
100  uint16_t chipID () const { return m_ChipID; }
101  uint64_t lsData () const { return m_lsData; }
102  uint64_t msData () const { return m_msData; }
103  uint16_t crc () const { return m_crc; }
104  uint16_t crc_calc () const { return m_crc_calc; }
105  int slotNumber () const { return m_SlotNumber; }
106  bool isBlockGood() const { return m_isBlockGood;}
107 
108  uint16_t crc_cal(uint16_t crc_in, uint16_t dato)
109  {
110  uint16_t v = 0x0001;
111  uint16_t mask = 0x0001;
112  uint16_t d=0x0000;
113  uint16_t crc_temp = crc_in;
114  unsigned char datalen = 16;
115  for (int i=0; i<datalen; i++){
116  if (dato & v) d = 0x0001;
117  else d = 0x0000;
118  if ((crc_temp & mask)^d) crc_temp = crc_temp>>1 ^ 0x8408;
119  else crc_temp = crc_temp>>1;
120  v<<=1;
121  }
122  return(crc_temp);
123  }
124 
125  uint16_t checkCRC()
126  {
127  uint16_t vfatBlockWords[12];
128  vfatBlockWords[11] = ((0x000f & m_b1010)<<12) | m_BC;
129  vfatBlockWords[10] = ((0x000f & m_b1100)<<12) | ((0x00ff & m_EC) <<4) | (0x000f & m_Flag);
130  vfatBlockWords[9] = ((0x000f & m_b1110)<<12) | m_ChipID;
131  vfatBlockWords[8] = (0xffff000000000000 & m_msData) >> 48;
132  vfatBlockWords[7] = (0x0000ffff00000000 & m_msData) >> 32;
133  vfatBlockWords[6] = (0x00000000ffff0000 & m_msData) >> 16;
134  vfatBlockWords[5] = (0x000000000000ffff & m_msData);
135  vfatBlockWords[4] = (0xffff000000000000 & m_lsData) >> 48;
136  vfatBlockWords[3] = (0x0000ffff00000000 & m_lsData) >> 32;
137  vfatBlockWords[2] = (0x00000000ffff0000 & m_lsData) >> 16;
138  vfatBlockWords[1] = (0x000000000000ffff & m_lsData);
139 
140  uint16_t crc_fin = 0xffff;
141  for (int i = 11; i >= 1; i--){
142  crc_fin = this->crc_cal(crc_fin, vfatBlockWords[i]);
143  }
144  return(crc_fin);
145  }
146 
147  uint16_t checkCRC(uint8_t b1010, uint16_t BC, uint8_t b1100,
148  uint8_t EC, uint8_t Flag, uint8_t b1110,
149  uint16_t ChipID, uint64_t msData, uint64_t lsData)
150  {
151  uint16_t vfatBlockWords[12];
152  vfatBlockWords[11] = ((0x000f & b1010)<<12) | BC;
153  vfatBlockWords[10] = ((0x000f & b1100)<<12) | ((0x00ff & EC) <<4) | (0x000f & Flag);
154  vfatBlockWords[9] = ((0x000f & b1110)<<12) | ChipID;
155  vfatBlockWords[8] = (0xffff000000000000 & msData) >> 48;
156  vfatBlockWords[7] = (0x0000ffff00000000 & msData) >> 32;
157  vfatBlockWords[6] = (0x00000000ffff0000 & msData) >> 16;
158  vfatBlockWords[5] = (0x000000000000ffff & msData);
159  vfatBlockWords[4] = (0xffff000000000000 & lsData) >> 48;
160  vfatBlockWords[3] = (0x0000ffff00000000 & lsData) >> 32;
161  vfatBlockWords[2] = (0x00000000ffff0000 & lsData) >> 16;
162  vfatBlockWords[1] = (0x000000000000ffff & lsData);
163 
164  uint16_t crc_fin = 0xffff;
165  for (int i = 11; i >= 1; i--){
166  crc_fin = this->crc_cal(crc_fin, vfatBlockWords[i]);
167  }
168  return(crc_fin);
169  }
170 
171  uint16_t checkCRC(const VFATdata * vfatData)
172  {
173  uint16_t vfatBlockWords[12];
174  vfatBlockWords[11] = ((0x000f & vfatData->b1010())<<12) | vfatData->bc();
175  vfatBlockWords[10] = ((0x000f & vfatData->b1100())<<12) | ((0x00ff & vfatData->ec()) <<4) | (0x000f & vfatData->flag());
176  vfatBlockWords[9] = ((0x000f & vfatData->b1110())<<12) | vfatData->chipID();
177  vfatBlockWords[8] = (0xffff000000000000 & vfatData->msData()) >> 48;
178  vfatBlockWords[7] = (0x0000ffff00000000 & vfatData->msData()) >> 32;
179  vfatBlockWords[6] = (0x00000000ffff0000 & vfatData->msData()) >> 16;
180  vfatBlockWords[5] = (0x000000000000ffff & vfatData->msData());
181  vfatBlockWords[4] = (0xffff000000000000 & vfatData->lsData()) >> 48;
182  vfatBlockWords[3] = (0x0000ffff00000000 & vfatData->lsData()) >> 32;
183  vfatBlockWords[2] = (0x00000000ffff0000 & vfatData->lsData()) >> 16;
184  vfatBlockWords[1] = (0x000000000000ffff & vfatData->lsData());
185 
186  uint16_t crc_fin = 0xffff;
187  for (int i = 11; i >= 1; i--){
188  crc_fin = this->crc_cal(crc_fin, vfatBlockWords[i]);
189  }
190  return(crc_fin);
191  }
192 
193  static const int nChannels = 128;
194  static const int sizeChipID = 12;
195 
196  private:
197 
198  uint8_t m_b1010;
199  uint16_t m_BC;
200  uint8_t m_b1100;
201  uint8_t m_EC;
202  uint8_t m_Flag;
203  uint8_t m_b1110;
204  uint16_t m_ChipID;
207  uint16_t m_crc;
208  uint16_t m_crc_calc;
211 
212  };
213 }
214 
215 #endif
uint16_t checkCRC(const VFATdata *vfatData)
Definition: VFATdata.h:171
uint8_t b1010() const
Definition: VFATdata.h:94
uint16_t m_crc_calc
Check Sum value recalculated, 16 bits.
Definition: VFATdata.h:208
VFATdata(const uint8_t b1010_, const uint16_t BC_, const uint8_t b1100_, const uint8_t EC_, const uint8_t Flag_, const uint8_t b1110_, const uint16_t ChipID_, const uint64_t lsData_, const uint64_t msData_, const uint16_t crc_, const uint16_t crc_calc_, const int SlotNumber_, const bool isBlockGood_)
Definition: VFATdata.h:12
uint8_t m_b1100
1100:4, Control bits, shoud be 1100
Definition: VFATdata.h:200
bool m_isBlockGood
Shows if block is good (control bits, chip ID and CRC checks)
Definition: VFATdata.h:210
void read_sw(uint64_t word)
Read second word from the block.
Definition: VFATdata.h:68
int slotNumber() const
Definition: VFATdata.h:105
uint16_t bc() const
Definition: VFATdata.h:95
uint16_t checkCRC()
Definition: VFATdata.h:125
uint16_t m_crc
Check Sum value, 16 bits.
Definition: VFATdata.h:207
A class for AMC data.
Definition: AMC13Event.h:6
uint64_t get_tw() const
Definition: VFATdata.h:87
uint8_t m_Flag
Control Flags: 4 bits, Hamming Error/AFULL/SEUlogic/SUEI2C.
Definition: VFATdata.h:202
static const int nChannels
Definition: VFATdata.h:193
uint8_t ec() const
Definition: VFATdata.h:97
bool isBlockGood() const
Definition: VFATdata.h:106
uint8_t m_b1010
1010:4 Control bits, shoud be 1010
Definition: VFATdata.h:198
uint64_t m_lsData
channels from 1to64
Definition: VFATdata.h:205
uint64_t m_msData
channels from 65to128
Definition: VFATdata.h:206
uint64_t lsData() const
Definition: VFATdata.h:101
uint16_t crc_cal(uint16_t crc_in, uint16_t dato)
Definition: VFATdata.h:108
uint16_t crc_calc() const
Definition: VFATdata.h:104
uint16_t chipID() const
Definition: VFATdata.h:100
void read_fw(uint64_t word)
Read first word from the block.
Definition: VFATdata.h:43
uint16_t m_BC
Bunch Crossing number, 12 bits.
Definition: VFATdata.h:199
unsigned long long uint64_t
Definition: Time.h:15
uint8_t b1110() const
Definition: VFATdata.h:99
uint64_t msData() const
Definition: VFATdata.h:102
uint16_t m_ChipID
Chip ID, 12 bits.
Definition: VFATdata.h:204
uint8_t m_EC
Event Counter, 8 bits.
Definition: VFATdata.h:201
uint8_t m_b1110
1110:4 Control bits, shoud be 1110
Definition: VFATdata.h:203
uint16_t checkCRC(uint8_t b1010, uint16_t BC, uint8_t b1100, uint8_t EC, uint8_t Flag, uint8_t b1110, uint16_t ChipID, uint64_t msData, uint64_t lsData)
Definition: VFATdata.h:147
static const int sizeChipID
Definition: VFATdata.h:194
int m_SlotNumber
Calculated chip position.
Definition: VFATdata.h:209
uint64_t get_sw() const
Definition: VFATdata.h:73
uint8_t b1100() const
Definition: VFATdata.h:96
uint8_t flag() const
Definition: VFATdata.h:98
void read_tw(uint64_t word)
Read third word from the block.
Definition: VFATdata.h:81
uint64_t get_fw() const
Definition: VFATdata.h:54
uint16_t crc() const
Definition: VFATdata.h:103