CMS 3D CMS Logo

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