CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VFATFrame.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of the TOTEM testbeam/monitoring software.
4 * This is a part of the TOTEM offline software.
5 * Authors:
6 * Jan Kašpar (jan.kaspar@gmail.com)
7 * Leszek Grzanka
8 *
9 ****************************************************************************/
10 
12 
13 #include <cstdio>
14 #include <cstring>
15 
17  : presenceFlags(15), // by default BC, EC, ID and CRC are present
18  daqErrorFlags(0), // by default, no DAQ error
19  numberOfClusters(0) // no clusters by default
20 {
21  if (_data)
22  setData(_data);
23  else
24  memset(data, 0, 12 * sizeof(word));
25 }
26 
27 void VFATFrame::setData(const VFATFrame::word *_data) { memcpy(data, _data, 24); }
28 
29 std::vector<unsigned char> VFATFrame::getActiveChannels() const {
30  std::vector<unsigned char> channels;
31 
32  for (int i = 0; i < 8; i++) {
33  // quick check
34  if (!data[1 + i])
35  continue;
36 
37  // go throug bits
38  word mask;
39  char offset;
40  for (mask = 1 << 15, offset = 15; mask; mask >>= 1, offset--) {
41  if (data[1 + i] & mask)
42  channels.push_back(i * 16 + offset);
43  }
44  }
45 
46  return channels;
47 }
48 
50  if (isIDPresent() && (data[9] & 0xF000) != 0xE000)
51  return false;
52 
53  if (isECPresent() && (data[10] & 0xF000) != 0xC000)
54  return false;
55 
56  if (isBCPresent() && (data[11] & 0xF000) != 0xA000)
57  return false;
58 
59  return true;
60 }
61 
62 bool VFATFrame::checkCRC() const {
63  // check DAQ error flags
64  if (daqErrorFlags != 0)
65  return false;
66 
67  // return true if CRC not present
68  if (!isCRCPresent())
69  return true;
70 
71  // compare CRC
72  word crc_fin = 0xffff;
73 
74  for (int i = 11; i >= 1; i--)
75  crc_fin = calculateCRC(crc_fin, data[i]);
76 
77  return (crc_fin == data[0]);
78 }
79 
81  word v = 0x0001;
82  word mask = 0x0001;
83  bool d = false;
84  word crc_temp = crc_in;
85  unsigned char datalen = 16;
86 
87  for (int i = 0; i < datalen; i++) {
88  if (dato & v)
89  d = true;
90  else
91  d = false;
92 
93  if ((crc_temp & mask) ^ d)
94  crc_temp = crc_temp >> 1 ^ 0x8408;
95  else
96  crc_temp = crc_temp >> 1;
97 
98  v <<= 1;
99  }
100 
101  return crc_temp;
102 }
103 
104 void VFATFrame::Print(bool binary) const {
105  if (binary) {
106  for (int i = 0; i < 12; i++) {
107  const word &w = data[11 - i];
108  word mask = (1 << 15);
109  for (int j = 0; j < 16; j++) {
110  if (w & mask)
111  printf("1");
112  else
113  printf("0");
114  mask = (mask >> 1);
115  if ((j + 1) % 4 == 0)
116  printf("|");
117  }
118  printf("\n");
119  }
120  } else {
121  printf("ID = %03x, BC = %04u, EC = %03u, flags = %2u, CRC = %04x ",
122  getChipID(),
123  getBC(),
124  getEC(),
125  getFlags(),
126  getCRC());
127 
128  if (checkCRC())
129  printf("( OK), footprint ");
130  else
131  printf("(FAIL), footprint ");
132 
133  if (checkFootprint())
134  printf(" OK");
135  else
136  printf("FAIL");
137 
138  printf(", frame = %04x|%04x|%04x|", data[11], data[10], data[9]);
139  for (int i = 8; i > 0; i--)
140  printf("%04x", data[i]);
141  printf("|%04x", data[0]);
142 
143  printf(", presFl=%x", presenceFlags);
144  printf(", daqErrFl=%x", daqErrorFlags);
145 
146  printf("\n");
147  }
148 }
word data[12]
Definition: VFATFrame.h:123
VFATFrame::word getFlags() const
Returns flags.
Definition: VFATFrame.h:49
const double w
Definition: UKUtility.cc:23
VFATFrame::word getBC() const
Returns Bunch Crossing number (BC&lt;11:0&gt;).
Definition: VFATFrame.h:43
uint16_t word
Definition: VFATFrame.h:21
bool checkFootprint() const
Definition: VFATFrame.cc:49
virtual bool checkCRC() const
Definition: VFATFrame.cc:62
tuple d
Definition: ztail.py:151
bool isECPresent() const
Returns true if the EC word is present in the frame.
Definition: VFATFrame.h:64
uint8_t daqErrorFlags
Error flag as given by certain versions of DAQ.
Definition: VFATFrame.h:135
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
void Print(bool binary=false) const
Definition: VFATFrame.cc:104
uint8_t presenceFlags
Definition: VFATFrame.h:132
VFATFrame::word getCRC() const
Returns the CRC.
Definition: VFATFrame.h:55
VFATFrame::word getEC() const
Returns Event Counter (EV&lt;7:0&gt;).
Definition: VFATFrame.h:46
bool isBCPresent() const
Returns true if the BC word is present in the frame.
Definition: VFATFrame.h:61
static word calculateCRC(word crc_in, word dato)
internaly used to check CRC
Definition: VFATFrame.cc:80
bool isIDPresent() const
Returns true if the ID word is present in the frame.
Definition: VFATFrame.h:67
VFATFrame::word getChipID() const
Returns ChipID (ChipID&lt;11:0&gt;).
Definition: VFATFrame.h:52
virtual std::vector< unsigned char > getActiveChannels() const
Definition: VFATFrame.cc:29
void setData(const word *_data)
Copies a memory block to data buffer.
Definition: VFATFrame.cc:27
VFATFrame(const word *_data=nullptr)
Definition: VFATFrame.cc:16
bool isCRCPresent() const
Returns true if the CRC word is present in the frame.
Definition: VFATFrame.h:70