]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerSTURawStream.cxx
updated
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerSTURawStream.cxx
CommitLineData
4bd37bd4 1
916f1e76 2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/*
18
19
20
21This class provides access to STU DDL raw data.
22Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
23*/
24
25#include "AliEMCALTriggerSTURawStream.h"
26#include "AliRawReader.h"
27#include "AliLog.h"
28
29#include "Riostream.h"
30#include "TBits.h"
31
c58cfdff 32#include <cstdlib>
33
916f1e76 34namespace
35{
63c22917 36 const Int_t kPayLoadSizeV0 = 236;
37 const Int_t kPayLoadSizeV1 = 245;
38 const Int_t kPayLoadSizeV2 = 390;
916f1e76 39}
40
41ClassImp(AliEMCALTriggerSTURawStream)
42
43//_____________________________________________________________________________
44AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream() : TObject(),
45fRawReader(0x0),
63c22917 46fL1JetThreshold(),
47fL1GammaThreshold(),
de39a0ff 48fL0GammaPatchIndex(),
49fL1GammaPatchIndex(),
50fL1JetPatchIndex(),
916f1e76 51fNL0GammaPatch(0),
63c22917 52fNL1JetPatch(),
53fNL1GammaPatch(),
648b8b91 54fGetRawData(0),
55fV0A(0),
56fV0C(0),
63c22917 57fG(),
58fJ(),
648b8b91 59fRegionEnable(0),
60fFrameReceived(0),
61fFwVersion(0)
916f1e76 62{
63 //
63c22917 64 for (int i = 0; i < 2; i++) {
65 //
66 fL1JetThreshold[i] = fL1GammaThreshold[i] = 0;
67
68 fNL1JetPatch[i] = fNL1GammaPatch[i] = 0;
69 }
70
71 for (int i = 0; i < 3; i++) {
72 for (int j = 0; j < 2; j++) {
73 //
74 fG[i][j] = fJ[i][j] = 0;
75 }
76 }
77
78 for (int i = 0; i < 3100; i++) {
79 //
80 fL0GammaPatchIndex[i] = 0;
81
82 for (int j = 0; j < 2; j++) {
83
84 fL1GammaPatchIndex[i][j] = 0;
85 }
86 }
87
88 for (int i = 0; i < 200; i++) {
89 for (int j = 0; j < 2; j++) {
90
91 fL1JetPatchIndex[i][j] = 0;
92 }
93 }
916f1e76 94}
95
96//_____________________________________________________________________________
97AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
98fRawReader(rawReader),
63c22917 99fL1JetThreshold(),
100fL1GammaThreshold(),
de39a0ff 101fL0GammaPatchIndex(),
102fL1GammaPatchIndex(),
103fL1JetPatchIndex(),
916f1e76 104fNL0GammaPatch(0),
63c22917 105fNL1JetPatch(),
106fNL1GammaPatch(),
648b8b91 107fGetRawData(0),
108fV0A(0),
109fV0C(0),
63c22917 110fG(),
111fJ(),
648b8b91 112fRegionEnable(0),
113fFrameReceived(0),
114fFwVersion(0)
916f1e76 115{
116 //
117 fRawReader->Reset();
118 fRawReader->Select("EMCAL",44);
63c22917 119 //
120 for (int i = 0; i < 2; i++) {
121 //
122 fL1JetThreshold[i] = fL1GammaThreshold[i] = 0;
123
124 fNL1JetPatch[i] = fNL1GammaPatch[i] = 0;
125 }
126
127 for (int i = 0; i < 3; i++) {
128 for (int j = 0; j < 2; j++) {
129 //
130 fG[i][j] = fJ[i][j] = 0;
131 }
132 }
133
134 for (int i = 0; i < 3100; i++) {
135 //
136 fL0GammaPatchIndex[i] = 0;
137
138 for (int j = 0; j < 2; j++) {
139
140 fL1GammaPatchIndex[i][j] = 0;
141 }
142 }
143
144 for (int i = 0; i < 200; i++) {
145 for (int j = 0; j < 2; j++) {
146
147 fL1JetPatchIndex[i][j] = 0;
148 }
149 }
916f1e76 150}
151
152//_____________________________________________________________________________
153AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
154{
155 // destructor
156}
157
158//_____________________________________________________________________________
159void AliEMCALTriggerSTURawStream::Reset()
160{
c1147445 161 // Reset
162
916f1e76 163 if (fRawReader) fRawReader->Reset();
de39a0ff 164
fff39dd1 165 fNL0GammaPatch = 0;
63c22917 166 fNL1GammaPatch[0] = fNL1GammaPatch[1] = 0;
167 fNL1JetPatch[0] = fNL1JetPatch[1] = 0;
916f1e76 168}
169
170//_____________________________________________________________________________
171Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
172{
173 // STU data decoder from Olivier Bourrion LPSC CNRS-IN2P3
4bd37bd4 174 // bourrion_at_lpsc_dot_in2p3_dot_fr
916f1e76 175
63c22917 176 UInt_t word32[kPayLoadSizeV2 + 1536]; // 32b words
177 for (Int_t i = 0;i < kPayLoadSizeV2 + 1536; i++) word32[i] = 0;
de39a0ff 178
916f1e76 179 Int_t iword = 0;
fff39dd1 180
181 fNL0GammaPatch = 0;
63c22917 182 fNL1GammaPatch[0] = fNL1GammaPatch[1] = 0;
183 fNL1JetPatch[0] = fNL1JetPatch[1] = 0;
fff39dd1 184
de39a0ff 185 Int_t eqId = -1, eqSize = 0;
916f1e76 186
187 UInt_t w32;
648b8b91 188
de39a0ff 189 while (fRawReader->ReadNextInt(w32))
190 {
191 if (!iword)
192 {
193 eqId = fRawReader->GetEquipmentId();
194 eqSize = fRawReader->GetEquipmentSize();
195 }
196
197 word32[iword++] = w32;
198 }
804b828a 199
63c22917 200 if (iword != kPayLoadSizeV0 && iword != kPayLoadSizeV1 && iword != kPayLoadSizeV2
201 &&
202 iword != (kPayLoadSizeV0 + 1536) && iword != (kPayLoadSizeV1 + 1536) && iword != (kPayLoadSizeV2 + 1536))
916f1e76 203 {
648b8b91 204 AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32",
de39a0ff 205 eqId, eqSize, iword));
916f1e76 206 return kFALSE;
de39a0ff 207 }
648b8b91 208
63c22917 209 AliDebug(1, Form("STU (eqId: %d, eqSize: %d) payload size: %d word32",
de39a0ff 210 eqId, eqSize, iword));
916f1e76 211
63c22917 212 int offset = 1;//, jetSize = 2;
213
214 int nthres = 1;
648b8b91 215
216 switch (iword)
217 {
63c22917 218 case kPayLoadSizeV0:
219 case kPayLoadSizeV0 + 1536:
648b8b91 220 {
63c22917 221 fL1JetThreshold[0] = ((word32[0]>>16) & 0xFFFF);
222 fL1GammaThreshold[0] = (word32[0] & 0xFFFF);
648b8b91 223
224 break;
225 }
63c22917 226 case kPayLoadSizeV1:
227 case kPayLoadSizeV1 + 1536:
648b8b91 228 {
46e461b8 229 fV0A = ((word32[0]>>16) & 0xFFFF);
230 fV0C = (word32[0] & 0xFFFF);
648b8b91 231
63c22917 232 fG[0][0] = word32[1];
233 fG[1][0] = word32[2];
234 fG[2][0] = word32[3];
235 fJ[0][0] = word32[4];
236 fJ[1][0] = word32[5];
237 fJ[2][0] = word32[6];
648b8b91 238 fRegionEnable = word32[7];
239 fFrameReceived = word32[8];
240 fFwVersion = word32[9];
241
63c22917 242 fL1JetThreshold[0] = GetThreshold(fJ[0][0], fJ[1][0], fJ[2][0], fV0A, fV0C);
243 fL1GammaThreshold[0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C);
244
245 offset = 10;
246
247 break;
248 }
249 case kPayLoadSizeV2:
250 case kPayLoadSizeV2 + 1536:
251 {
252 fV0A = ((word32[0]>>16) & 0xFFFF);
253 fV0C = (word32[0] & 0xFFFF);
ad9ab1c9 254
63c22917 255 fG[0][0] = word32[1];
256 fG[1][0] = word32[2];
257 fG[2][0] = word32[3];
258 fJ[0][0] = word32[4];
259 fJ[1][0] = word32[5];
260 fJ[2][0] = word32[6];
261
262 fG[0][1] = word32[7];
263 fG[1][1] = word32[8];
264 fG[2][1] = word32[9];
265 fJ[0][1] = word32[10];
266 fJ[1][1] = word32[11];
267 fJ[2][1] = word32[12];
268
269 fRegionEnable = word32[13];
270 fFrameReceived = word32[14];
271 fFwVersion = word32[15];
272
273 for (int i = 0; i < 2; i++) {
274 //
275 fL1JetThreshold[i] = GetThreshold(fJ[0][i], fJ[1][i], fJ[2][i], fV0A, fV0C);
276 fL1GammaThreshold[i] = GetThreshold(fG[0][i], fG[1][i], fG[2][i], fV0A, fV0C);
277 }
648b8b91 278
63c22917 279 offset = 16;
280
281 nthres = 2;
648b8b91 282
283 break;
284 }
648b8b91 285 }
286
63c22917 287// jetSize += (fFwVersion >> 16);
288
648b8b91 289 ///////////
290 // START DECODING
291 //////////
ad9ab1c9 292
63c22917 293 for (int i = 0; i < nthres; i++) {
294 DecodeL1JetPatchIndexes(i, word32, offset);
916f1e76 295
63c22917 296 offset += 11;
916f1e76 297 }
63c22917 298
299 DecodeL0GammaPatchIndexes(word32, offset);
300
301 offset += 96;
302
303 for (int i = 0; i < nthres; i++) {
304 DecodeL1GammaPatchIndexes(i, word32, offset);
648b8b91 305
63c22917 306 offset += 128;
307 }
916f1e76 308
63c22917 309 if (iword == kPayLoadSizeV0 || iword == kPayLoadSizeV1 || iword == kPayLoadSizeV2) {
310 fGetRawData = 0;
311 return kTRUE;
312 }
313
314 fGetRawData = 1;
315
316 DecodeTRUADC(word32, offset);
317
318 return kTRUE;
319}
320
321//_____________________________________________________________________________
322void AliEMCALTriggerSTURawStream::DecodeL0GammaPatchIndexes(UInt_t *word32, const int offset)
323{
916f1e76 324 //////////////////////////////////////////////////////////
325 // index des L0 //
326 //////////////////////////////////////////////////////////
648b8b91 327 // FIXME: sounds like not valid data
916f1e76 328
c1147445 329 unsigned short truL0indexes[32][6];
916f1e76 330
331 // extraction from stream
332 for (Int_t index=0;index<6;index++)
333 {
334 for (Int_t tru_num=0;tru_num<16;tru_num++)
335 {
63c22917 336 truL0indexes[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
337 truL0indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
916f1e76 338 }
339 }
63c22917 340
916f1e76 341 for (Int_t tru_num=0;tru_num<32;tru_num++)
342 {
343 for (Int_t index=0;index<6;index++)
344 {
345 for (Int_t bit_num=0;bit_num<12;bit_num++)
346 {
c1147445 347 if ((truL0indexes[tru_num][index] & (1 << bit_num)))
916f1e76 348 {
916f1e76 349 Int_t idx = 12 * index + bit_num;
63c22917 350
916f1e76 351 fNL0GammaPatch++;
916f1e76 352
de39a0ff 353 fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
916f1e76 354 }
355 }
356 }
357 }
63c22917 358}
359
360//_____________________________________________________________________________
361void AliEMCALTriggerSTURawStream::DecodeL1JetPatchIndexes(const int i, UInt_t *word32, const int offset)
362{
363 //////////////////////////////////////////////////////////
364 // index des L1 jet //
365 //////////////////////////////////////////////////////////
366
367 int jetSize = 2 + (fFwVersion >> 16);
368
369 for (Int_t jet_row = 0; jet_row < 12 - (jetSize - 1); jet_row++)
370 {
371 UInt_t currentrow = word32[offset + jet_row];
372
373 for (Int_t jet_col = 0; jet_col < 15; jet_col++)
374 {
375 if (currentrow & (1 << jet_col))
376 {
377 fNL1JetPatch[i] = fNL1JetPatch[i] + 1;
378
379 fL1JetPatchIndex[fNL1JetPatch[i] - 1][i] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
380 }
381 }
382 }
383}
916f1e76 384
63c22917 385//_____________________________________________________________________________
386void AliEMCALTriggerSTURawStream::DecodeL1GammaPatchIndexes(const int i, UInt_t *word32, const int offset)
387{
916f1e76 388 //////////////////////////////////////////////////////////
389 // index des L1 gamma //
390 //////////////////////////////////////////////////////////
391
c1147445 392 unsigned short truL1indexes[32][8];
916f1e76 393
394 // extraction from stream
395 for (Int_t index=0;index<8;index++)
396 {
397 for (Int_t tru_num=0;tru_num<16;tru_num++)
398 {
63c22917 399 truL1indexes[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
400 truL1indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
916f1e76 401 }
402 }
63c22917 403
916f1e76 404 // interpretation
405 int gammacolnum;
406 short indexcopy;
407
408 for (Int_t tru_num=0;tru_num<32;tru_num++)
409 {
410 for (Int_t index=0;index<8;index++)
411 {
412 for (Int_t bit_num=0; bit_num<12; bit_num++)
413 {
c1147445 414 if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
916f1e76 415 {
416 if (index<4) // Even
417 {
418 gammacolnum = (2*bit_num );
419 indexcopy = index;
420 }
421 else // Odd
422 {
423 gammacolnum = (2*bit_num+1);
424 indexcopy = index-4;
425 }
426
63c22917 427 fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
916f1e76 428
63c22917 429 fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
916f1e76 430 }
431 }
432 }
433 }
63c22917 434}
916f1e76 435
63c22917 436//_____________________________________________________________________________
437void AliEMCALTriggerSTURawStream::DecodeTRUADC(UInt_t *word32, const int offset)
438{
916f1e76 439 // extraction from stream
440 for (Int_t index=0;index<96;index++)
441 {
442 for (Int_t tru_num=0;tru_num<16;tru_num++)
443 {
63c22917 444 fADC[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
445 fADC[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
916f1e76 446 }
447 }
63c22917 448
916f1e76 449 for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
450 {
de39a0ff 451 Int_t v[96];
452 for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
453
454 for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
916f1e76 455 }
916f1e76 456}
457
63c22917 458
916f1e76 459//_____________________________________________________________________________
de39a0ff 460Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
916f1e76 461{
c1147445 462 // L0 gamma patches sent to STU (original access to L0 patch indexes)
463
916f1e76 464 if (i > fNL0GammaPatch) return kFALSE;
465
466 tru = fL0GammaPatchIndex[i] & 0x1F;
de39a0ff 467 idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
916f1e76 468
469 return kTRUE;
470}
471
472//_____________________________________________________________________________
63c22917 473Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, const Int_t j, Int_t& tru, Int_t& col, Int_t& row) const
916f1e76 474{
c1147445 475 // L1 gamma patch indexes
476
9c024499 477 if (j >= 2 || i > fNL1GammaPatch[j]) return kFALSE;
916f1e76 478
63c22917 479 tru = fL1GammaPatchIndex[i][j] & 0x1F;
480 col = (fL1GammaPatchIndex[i][j] & 0x3E0) >> 5;
481 row = (fL1GammaPatchIndex[i][j] & 0xC00) >> 10;
916f1e76 482
483 return kTRUE;
484}
485
486//_____________________________________________________________________________
63c22917 487Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, const Int_t j, Int_t& col, Int_t& row) const
916f1e76 488{
c1147445 489 // L1 jet patch indexes
490
9c024499 491 if (j >= 2 || i > fNL1JetPatch[j]) return kFALSE;
916f1e76 492
63c22917 493 col = fL1JetPatchIndex[i][j] & 0xFF;
494 row = (fL1JetPatchIndex[i][j] & 0xFF00) >> 8;
916f1e76 495
496 return kTRUE;
497}
498
499//_____________________________________________________________________________
500void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
501{
c1147445 502 // Time sums
503
916f1e76 504 for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
505}
506
507//_____________________________________________________________________________
80e5a1ae 508void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
916f1e76 509{
c1147445 510 // Dump STU payload
511
916f1e76 512 TString op = option;
513
648b8b91 514 printf("V0A: %d\n", fV0A);
515 printf("V0C: %d\n", fV0C);
63c22917 516
648b8b91 517 printf("RawData: %d\n", fGetRawData);
518 printf("RegionEnable: %8x\n", fRegionEnable);
519 printf("FrameReceived: %8x\n", fFrameReceived);
520 printf("FwVersion: %x\n", fFwVersion);
521 printf("Number of L0: %d\n", fNL0GammaPatch);
63c22917 522
523 for (int i = 0; i < 2; i++) {
524 for (int j = 0; j < 3; j++) {
525 printf("G[%d][%d]: %d\n", j, i, fG[j][i]);
526 printf("J[%d][%d]: %d\n", j, i, fJ[j][i]);
527 }
528
529 printf("Gamma threshold[%d]: %d\n", i, fL1GammaThreshold[i]);
530 printf("Jet Threshold[%d]: %d\n", i, fL1JetThreshold[i]);
531
532 printf("Number of L1-g[%d]: %d\n", i, fNL1GammaPatch[i]);
533 printf("Number of L1-j[%d]: %d\n", i, fNL1JetPatch[i]);
534 }
916f1e76 535
536 Int_t itru, col, row;
916f1e76 537
538 if (op.Contains("L0") || op.Contains("ALL"))
539 {
63c22917 540 for (Int_t i = 0;i < fNL0GammaPatch; i++) {
de39a0ff 541 if (GetL0GammaPatch(i,itru,col))
542 cout << "> Found L0 gamma in TRU #" << setw(2) << itru << " at idx: " << setw(2) << col << endl;
916f1e76 543 }
544 }
545
63c22917 546 if (op.Contains("L1") || op.Contains("ALL")) {
547 for (int j = 0; j < 2; j++) {
548 for (Int_t i = 0; i < fNL1GammaPatch[j]; i++) {
549 if (GetL1GammaPatch(i, j, itru, col, row))
550 cout << "> Found L1 gamma " << j << " in TRU #" << setw(2) << itru << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
551 }
552
553 for (Int_t i = 0; i < fNL1JetPatch[j]; i++) {
554 if (GetL1JetPatch(i, j, col, row)) cout << "> Found L1 jet " << j << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
555 }
916f1e76 556 }
557 }
558
63c22917 559 if ((op.Contains("ADC") || op.Contains("ALL")) && fGetRawData) {
560 for (Int_t i = 0; i < 32; i++) {
916f1e76 561 cout << "--------\n";
562 cout << "TRU #" << setw(2) << i << ":";
63c22917 563 for (Int_t j = 0;j < 96; j++) {
564 //TBits xadc(12); xadc.Set(12,&fADC[i][j]);
565 if ((j % 4) == 0) cout << endl;
916f1e76 566 //cout << setw(2) << j << ": " << xadc << " ";
567 printf("%2d: %3x / ",j,fADC[i][j]);
568 }
569 cout << "\n";
570 }
571 }
572}
222f9c45 573
574//_____________________________________________________________________________
79b05051 575UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
222f9c45 576{
79b05051 577 // Get threshold
578 ULong64_t v0sum = V0A + V0C;
222f9c45 579
79b05051 580 ULong64_t sqrV0 = v0sum * v0sum;
222f9c45 581
582 sqrV0 *= A;
583
584 sqrV0 >>= 32;
585
79b05051 586 v0sum *= B;
222f9c45 587
79b05051 588 v0sum >>= 16;
222f9c45 589
79b05051 590 return (UShort_t)(sqrV0 + v0sum + C);
222f9c45 591}