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