CMS 3D CMS Logo

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 
49 bool VFATFrame::checkFootprint() const {
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 }
VFATFrame::VFATFrame
VFATFrame(const word *_data=nullptr)
Definition: VFATFrame.cc:15
mps_fire.i
i
Definition: mps_fire.py:428
VFATFrame::checkCRC
virtual bool checkCRC() const
Definition: VFATFrame.cc:61
VFATFrame::checkFootprint
bool checkFootprint() const
Definition: VFATFrame.cc:48
VFATFrame::Print
void Print(bool binary=false) const
Definition: VFATFrame.cc:103
VFATFrame::isCRCPresent
bool isCRCPresent() const
Returns true if the CRC word is present in the frame.
Definition: VFATFrame.h:74
findQualityFiles.v
v
Definition: findQualityFiles.py:179
VFATFrame::getActiveChannels
virtual std::vector< unsigned char > getActiveChannels() const
Definition: VFATFrame.cc:28
VFATFrame::getFlags
VFATFrame::word getFlags() const
Returns flags.
Definition: VFATFrame.h:53
VFATFrame::getBC
VFATFrame::word getBC() const
Returns Bunch Crossing number (BC<11:0>).
Definition: VFATFrame.h:47
w
const double w
Definition: UKUtility.cc:23
VFATFrame::data
word data[12]
Definition: VFATFrame.h:127
VFATFrame::isBCPresent
bool isBCPresent() const
Returns true if the BC word is present in the frame.
Definition: VFATFrame.h:65
VFATFrame.h
VFATFrame::getChipID
VFATFrame::word getChipID() const
Returns ChipID (ChipID<11:0>).
Definition: VFATFrame.h:56
VFATFrame::getCRC
VFATFrame::word getCRC() const
Returns the CRC.
Definition: VFATFrame.h:59
VFATFrame::word
uint16_t word
Definition: VFATFrame.h:25
VFATFrame::isECPresent
bool isECPresent() const
Returns true if the EC word is present in the frame.
Definition: VFATFrame.h:68
VFATFrame::getEC
VFATFrame::word getEC() const
Returns Event Counter (EV<7:0>).
Definition: VFATFrame.h:50
VFATFrame::isIDPresent
bool isIDPresent() const
Returns true if the ID word is present in the frame.
Definition: VFATFrame.h:71
VFATFrame::calculateCRC
static word calculateCRC(word crc_in, word dato)
internaly used to check CRC
Definition: VFATFrame.cc:79
ewkTauDQM_cfi.channels
channels
Definition: ewkTauDQM_cfi.py:14
VFATFrame::daqErrorFlags
uint8_t daqErrorFlags
Error flag as given by certain versions of DAQ.
Definition: VFATFrame.h:139
ztail.d
d
Definition: ztail.py:151
VFATFrame::presenceFlags
uint8_t presenceFlags
Definition: VFATFrame.h:136
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
VFATFrame::setData
void setData(const word *_data)
Copies a memory block to data buffer.
Definition: VFATFrame.cc:26