FairRoot/PandaRoot
PndTopix4.cxx
Go to the documentation of this file.
1 /*
2  * PndTopix4.cxx
3  *
4  * Created on: 16.09.2015
5  * Author: Stockmanns
6  */
7 
9 
10 #include "mrftools.h"
11 
12 using namespace ToPix4;
13 
14 //ClassImp(PndTopix4)
15 
17  // TODO Auto-generated constructor stub
18 
19 }
20 
22  // TODO Auto-generated destructor stub
23 }
24 
25 std::vector<ULong64_t> PndTopix4::GetRawData(TMrfData_8b* data)
26 {
27  std::vector<ULong64_t> rawData;
28  for (UInt_t i = 0; i < data->getNumWords(); i += 5) {
29  ULong_t dataword = 0;
30  for (UInt_t j = 0; j < 5; j++) {
31  dataword = dataword << 8;
32  dataword += data->getWord(i + j);
33  }
34  rawData.push_back(dataword);
35 
36 // if (fVerbose > 2) {
37  ULong_t frameCount = -1;
38  ULong64_t header = GetType(dataword);
39  if (header == 1)
40  frameCount = GetFrameCount(dataword);
41 
42 // LOG(INFO) << std::dec << "dataword No " << i / 5 << "/" << data->getNumWords() / 5 << ": " << std::hex
43 // << dataword << " ";
44 // }
45  }
46  return rawData;
47 }
48 
49 int PndTopix4::GetType(ULong64_t data){
50  ULong_t header = data & 0xC000000000;
51  header = header >> 38;
52  return (int)header;
53 }
54 
55 int PndTopix4::GetFrameCount(ULong64_t data){
56  ULong_t frame = data & 0x3FC0000;
57  frame = frame >> 18;
58  return (int)frame;
59 }
60 
62 {
63  ToPix4::frameHeader tempHeader;
64  ULong_t temp = header;
65  tempHeader.fECC = temp & 0x3F;
66  temp = temp >> 18;
67  tempHeader.fFrameCount = temp & 0xFF;
68 
69  temp = temp >> 8;
70  tempHeader.fChipAddress = temp & 0xFFF;
71 
72  return tempHeader;
73 }
74 
76 {
77  ToPix4::frameTrailer tempTrailer;
78  ULong_t temp = trailer;
79  tempTrailer.fECC = temp & 0x3F;
80 
81  temp = temp >> 6;
82  tempTrailer.fFrameCRC = temp & 0xFFFF;
83 
84  temp = temp >> 16;
85  tempTrailer.fNEvents = temp & 0xFFFF;
86 
87  return tempTrailer;
88 
89 }
90 
92 {
93  //le_dataword = ((dataword & 0x0000000000fff000)>>12);¬
94  //te_dataword = (dataword & 0x0000000000000fff);¬
95  //pixeladdress = ((dataword & 0x0000003fff000000)>>24);¬
96 
97  ToPix4::pixel tempPixel;
98  ULong_t temp = data;
99  tempPixel.fTrailingEdge = mrftools::grayToBin(temp & 0X0000000000000FFF);
100 
101  temp = temp >> 12;
102  tempPixel.fLeadingEdge = mrftools::grayToBin(temp & 0X0000000000000FFF);
103 
104  temp = temp >> 12;
105  tempPixel.fPixelNumber = temp & 0X00000000000003FFF;
106 
107 // if (fVerbose > 1) std::cout << "BitAnalyzePixelData: " << std::hex << data << " pixel " << std::dec << tempPixel.fPixelAddress << " " << tempPixel.fLeadingEdge << " " << tempPixel.fTrailingEdge << std::endl;
108 
109  return tempPixel;
110 }
111 
113 {
114  ToPix4::pixelAddress address;
115 
116  UInt_t temp = pixelnumber;
117 
118  address.fRow= temp & 0x7f; //todo check if this conversion is correct!
119  temp = temp >> 7;
120  address.fSide= temp & 0x1;
121  temp = temp >> 1;
122  address.fCol = temp & 0x3f;
123 // temp = temp >> 6;
124 
125  return address;
126 }
127 
128 std::pair<UInt_t, UInt_t> PndTopix4::PixelNumberToMatrixAddress(UInt_t pixelnumber)
129 {
130  // Matrix: 32 columns x 20 rows
131 
132  ToPix4::pixelAddress address;
133 
134  address = PixelNumberToPixelAddress(pixelnumber);
135 // UInt_t matrix_column, matrix_row;
136 
137  return PixelAddressToMatrixAddress(address);
138 
139 
140 // UInt_t sel = (double_column_address<<1) | (double_column_side);
141 //
142 // if(sel == 0)
143 // {
144 // matrix_row = pixel_address;
145 // matrix_column = 1;
146 // }
147 // else if(sel ==1)
148 // {
149 // matrix_row = pixel_address;
150 // matrix_column = 0;
151 // }
152 // else if(sel == 6)
153 // {
154 // matrix_row = pixel_address;
155 // matrix_column = 19;
156 // }
157 // else if(sel == 7)
158 // {
159 // matrix_row = pixel_address;
160 // matrix_column = 18;
161 // }
162 // else if (sel==2)
163 // {
164 // if (pixel_address <32)
165 // {
166 // matrix_row = pixel_address;
167 // matrix_column = 3;
168 // }
169 // else if (pixel_address < 64)
170 // {
171 // matrix_row = 31 - (pixel_address-32);
172 // matrix_column = 4;
173 // }
174 // else if (pixel_address < 96)
175 // {
176 // matrix_row = (pixel_address-64);
177 // matrix_column = 7;
178 // }
179 // else if (pixel_address < 128)
180 // {
181 // matrix_row = 31 - (pixel_address-96);
182 // matrix_column = 8;
183 // }
184 // }
185 // else if (sel==3)
186 // {
187 // if (pixel_address <32)
188 // {
189 // matrix_row = pixel_address;
190 // matrix_column = 2;
191 // }
192 // else if (pixel_address < 64)
193 // {
194 // matrix_row = 31 - (pixel_address-32);
195 // matrix_column = 5;
196 // }
197 // else if (pixel_address < 96)
198 // {
199 // matrix_row = (pixel_address-64);
200 // matrix_column = 6;
201 // }
202 // else if (pixel_address < 128)
203 // {
204 // matrix_row = 31 - (pixel_address-96);
205 // matrix_column = 9;
206 // }
207 // }
208 // else if (sel==4)
209 // {
210 // if (pixel_address < 32)
211 // {
212 // matrix_row = pixel_address;
213 // matrix_column = 10;
214 // }
215 // else if (pixel_address < 64)
216 // {
217 // matrix_row = 31 - (pixel_address-32);
218 // matrix_column = 13;
219 // }
220 // else if (pixel_address < 96)
221 // {
222 // matrix_row = (pixel_address-64);
223 // matrix_column = 14;
224 // }
225 // else if (pixel_address < 128)
226 // {
227 // matrix_row = 31 - (pixel_address-96);
228 // matrix_column = 17;
229 // }
230 // }
231 // else if (sel==5)
232 // {
233 // if (pixel_address < 32)
234 // {
235 // matrix_row = pixel_address;
236 // matrix_column = 11;
237 // }
238 // else if (pixel_address < 64)
239 // {
240 // matrix_row = 31 - (pixel_address-32);
241 // matrix_column = 12;
242 // }
243 // else if (pixel_address < 96)
244 // {
245 // matrix_row = (pixel_address-64);
246 // matrix_column = 15;
247 // }
248 // else if (pixel_address < 128)
249 // {
250 // matrix_row = 31 - (pixel_address-96);
251 // matrix_column = 16;
252 // }
253 // }
254 
255 // return std::pair<UInt_t, UInt_t>(matrix_column, matrix_row);
256 }
257 
259 {
260  UInt_t matrix_row = 0;
261  UInt_t matrix_col = 0;
262 
263  if (address.fCol == 0 || address.fCol == 3){
264  matrix_row = address.fRow;
265  matrix_col = address.fCol * 6 + !(address.fSide);
266  }
267 
268  else {
269  matrix_col = (address.fRow / 32) * 2 + 2 + ((address.fCol - 1) * 8);
270  if ( (address.fRow/32) % 2 == 0 ){
271  matrix_row = address.fRow % 32;
272  matrix_col += !(address.fSide);
273  }
274  else {
275  matrix_row = 31 - address.fRow % 32;
276  matrix_col += address.fSide;
277  }
278  }
279  //std::cout << address.fRow << "/" << address.fCol << "/" << address.fSide << " --> " << matrix_row << "/" << matrix_col << std::endl;
280  return std::pair<UInt_t, UInt_t>(matrix_col, matrix_row);
281 }
282 
283 std::pair<UInt_t, UInt_t> PndTopix4::PixelAddressToMatrixAddress(UInt_t row, UInt_t col, Bool_t side){
284  ToPix4::pixelAddress address(row, col, side);
285  return PixelAddressToMatrixAddress(address);
286 }
287 
288 ToPix4::pixelAddress PndTopix4::MatrixAddressToPixelAddress(std::pair<UInt_t, UInt_t> matrixAddress)
289 {
290  UInt_t matrix_col = matrixAddress.first;
291  UInt_t matrix_row = matrixAddress.second;
292 
293  ToPix4::pixelAddress address;
294  if (matrix_col < 2 || matrix_col > 17){
295  address.fSide = !(matrix_col%2);
296  address.fCol = matrix_col/2;
297  address.fRow = matrix_row;
298  } else {
299  address.fCol = (matrix_col - 2) / 8 + 1;
300  if ( ((matrix_col - 2) / 2) % 2 == 0) {
301  address.fRow = (matrix_col - 2) / 2 * 32 + matrix_row;
302  address.fSide = !((matrix_col - 2) % 2);
303  } else {
304  address.fRow = ((((matrix_col - 2) % 8) / 2) + 1) * 32 - (matrix_row + 1);
305  address.fSide = ((matrix_col - 2) % 2);
306  }
307  }
308 
309  //std::cout << matrix_row << "/" << matrix_col << "-->" << address.fRow << "/" << address.fCol << "/" << address.fSide << std::endl;
310 
311  return address;
312 }
313 
314 ULong64_t PndTopix4::ConvertToPix4HammingToStandardHamming(ULong64_t topixhamming)
315 {
316  // The ToPix header and trailer data word consists of 34 data bits and 6 hamming bits.
317  // bit no: 39 38 37 36 35 9 8 7 6 5 4 3 2 1 0
318  // In a ToPix4 dataword the hamming bits are at the end of the word: (d34)(d33)(d32)(d31)(d30) ... (d04)(d03)(d02)(d01)(H 6)(H 5)(H 4)(H 3)(H 2)(H 1)
319  // At the standard hamming encoding the hamming bits are at the 2^i positions (d34)(d33)(d32)(d31)(d30) ... (d07)(d06)(d05)(d04)(H 3)(d03)(d02)(d01)(H 2)(H 1)
320  // This function expects a ToPix4 encoded dataword and moves the hamming bits at the end to the defined positions.
321 
322  ULong64_t standard_hamming = 0;
323 
324  standard_hamming = ( topixhamming & 0xff00000000);
325  standard_hamming += ((topixhamming & 0x00fffe0000) >> 1 );
326  standard_hamming += ((topixhamming & 0x000001fc00) >> 2 );
327  standard_hamming += ((topixhamming & 0x0000000380) >> 3 );
328  standard_hamming += ((topixhamming & 0x0000000040) >> 4 );
329 
330  standard_hamming += ((topixhamming & 0x0000000020) << 26 );
331  standard_hamming += ((topixhamming & 0x0000000010) << 11 );
332  standard_hamming += ((topixhamming & 0x0000000008) << 4 );
333  standard_hamming += ((topixhamming & 0x0000000004) << 1 );
334  standard_hamming += ( topixhamming & 0x0000000002);
335  standard_hamming += ( topixhamming & 0x0000000001);
336 
337  return standard_hamming;
338 }
int row
Definition: anaLmdDigi.C:67
Int_t i
Definition: run_full.C:25
ToPix4::frameTrailer BitAnalyzeTrailer(ULong64_t &trailer)
Definition: PndTopix4.cxx:75
ToPix4::frameHeader BitAnalyzeHeader(ULong64_t &header)
Definition: PndTopix4.cxx:61
std::pair< UInt_t, UInt_t > PixelAddressToMatrixAddress(ToPix4::pixelAddress address)
Definition: PndTopix4.cxx:258
int col
Definition: anaLmdDigi.C:67
ULong64_t ConvertToPix4HammingToStandardHamming(ULong64_t topixhamming)
Definition: PndTopix4.cxx:314
int GetFrameCount(ULong64_t data)
Definition: PndTopix4.cxx:55
ToPix4::pixel BitAnalyzePixelData(ULong64_t &data)
Definition: PndTopix4.cxx:91
UInt_t grayToBin(UInt_t gray)
Converts gray encoded values to bianry values.
std::vector< ULong64_t > GetRawData(TMrfData_8b *data)
Definition: PndTopix4.cxx:25
std::pair< UInt_t, UInt_t > PixelNumberToMatrixAddress(UInt_t pixelnumber)
Definition: PndTopix4.cxx:128
UInt_t fLeadingEdge
Definition: PndTopix4.h:36
Base interface class for data storage and manipulation. Compatible with IO classes from MRF Suite...
ToPix4::pixelAddress MatrixAddressToPixelAddress(std::pair< UInt_t, UInt_t > matrixAddress)
Definition: PndTopix4.cxx:288
ToPix4::pixelAddress PixelNumberToPixelAddress(UInt_t pixelnumber)
Definition: PndTopix4.cxx:112
const UChar_t & getWord(const UInt_t &position) const
Retrieves the word found at position.
UInt_t fPixelNumber
Definition: PndTopix4.h:33
UInt_t fTrailingEdge
Definition: PndTopix4.h:37
const UInt_t & getNumWords() const
Retrieves the length of the register in words.
int GetType(ULong64_t data)
returns if the data word is a header (0b01), trailer (0b10) or data (0b11)
Definition: PndTopix4.cxx:49
virtual ~PndTopix4()
Definition: PndTopix4.cxx:21