2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 This class provides access to STU DDL raw data.
22 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
25 #include "AliEMCALTriggerSTURawStream.h"
26 #include "AliRawReader.h"
29 #include "Riostream.h"
36 const Int_t kPayLoadSizeV0 = 236;
37 const Int_t kPayLoadSizeV1 = 245;
38 const Int_t kPayLoadSizeV2 = 390;
41 ClassImp(AliEMCALTriggerSTURawStream)
43 //_____________________________________________________________________________
44 AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream() : TObject(),
64 for (int i = 0; i < 2; i++) {
66 fL1JetThreshold[i] = fL1GammaThreshold[i] = 0;
68 fNL1JetPatch[i] = fNL1GammaPatch[i] = 0;
71 for (int i = 0; i < 3; i++) {
72 for (int j = 0; j < 2; j++) {
74 fG[i][j] = fJ[i][j] = 0;
78 for (int i = 0; i < 3100; i++) {
80 fL0GammaPatchIndex[i] = 0;
82 for (int j = 0; j < 2; j++) {
84 fL1GammaPatchIndex[i][j] = 0;
88 for (int i = 0; i < 200; i++) {
89 for (int j = 0; j < 2; j++) {
91 fL1JetPatchIndex[i][j] = 0;
96 //_____________________________________________________________________________
97 AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
98 fRawReader(rawReader),
101 fL0GammaPatchIndex(),
102 fL1GammaPatchIndex(),
118 fRawReader->Select("EMCAL",44);
120 for (int i = 0; i < 2; i++) {
122 fL1JetThreshold[i] = fL1GammaThreshold[i] = 0;
124 fNL1JetPatch[i] = fNL1GammaPatch[i] = 0;
127 for (int i = 0; i < 3; i++) {
128 for (int j = 0; j < 2; j++) {
130 fG[i][j] = fJ[i][j] = 0;
134 for (int i = 0; i < 3100; i++) {
136 fL0GammaPatchIndex[i] = 0;
138 for (int j = 0; j < 2; j++) {
140 fL1GammaPatchIndex[i][j] = 0;
144 for (int i = 0; i < 200; i++) {
145 for (int j = 0; j < 2; j++) {
147 fL1JetPatchIndex[i][j] = 0;
152 //_____________________________________________________________________________
153 AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
158 //_____________________________________________________________________________
159 void AliEMCALTriggerSTURawStream::Reset()
163 if (fRawReader) fRawReader->Reset();
166 fNL1GammaPatch[0] = fNL1GammaPatch[1] = 0;
167 fNL1JetPatch[0] = fNL1JetPatch[1] = 0;
170 //_____________________________________________________________________________
171 Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
173 // STU data decoder from Olivier Bourrion LPSC CNRS-IN2P3
174 // bourrion_at_lpsc_dot_in2p3_dot_fr
176 UInt_t word32[kPayLoadSizeV2 + 1536]; // 32b words
177 for (Int_t i = 0;i < kPayLoadSizeV2 + 1536; i++) word32[i] = 0;
182 fNL1GammaPatch[0] = fNL1GammaPatch[1] = 0;
183 fNL1JetPatch[0] = fNL1JetPatch[1] = 0;
185 Int_t eqId = -1, eqSize = 0;
189 while (fRawReader->ReadNextInt(w32))
193 eqId = fRawReader->GetEquipmentId();
194 eqSize = fRawReader->GetEquipmentSize();
197 word32[iword++] = w32;
200 if (iword != kPayLoadSizeV0 && iword != kPayLoadSizeV1 && iword != kPayLoadSizeV2
202 iword != (kPayLoadSizeV0 + 1536) && iword != (kPayLoadSizeV1 + 1536) && iword != (kPayLoadSizeV2 + 1536))
204 AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32",
205 eqId, eqSize, iword));
209 AliDebug(1, Form("STU (eqId: %d, eqSize: %d) payload size: %d word32",
210 eqId, eqSize, iword));
212 int offset = 1;//, jetSize = 2;
219 case kPayLoadSizeV0 + 1536:
221 fL1JetThreshold[0] = ((word32[0]>>16) & 0xFFFF);
222 fL1GammaThreshold[0] = (word32[0] & 0xFFFF);
227 case kPayLoadSizeV1 + 1536:
229 fV0A = ((word32[0]>>16) & 0xFFFF);
230 fV0C = (word32[0] & 0xFFFF);
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];
238 fRegionEnable = word32[7];
239 fFrameReceived = word32[8];
240 fFwVersion = word32[9];
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);
250 case kPayLoadSizeV2 + 1536:
252 fV0A = ((word32[0]>>16) & 0xFFFF);
253 fV0C = (word32[0] & 0xFFFF);
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];
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];
269 fRegionEnable = word32[13];
270 fFrameReceived = word32[14];
271 fFwVersion = word32[15];
273 for (int i = 0; i < 2; i++) {
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);
286 AliError(Form("STU payload size not found! %d word32", iword));
289 // jetSize += (fFwVersion >> 16);
295 for (int i = 0; i < nthres; i++) {
296 DecodeL1JetPatchIndexes(i, word32, offset);
301 DecodeL0GammaPatchIndexes(word32, offset);
305 for (int i = 0; i < nthres; i++) {
306 DecodeL1GammaPatchIndexes(i, word32, offset);
311 if (iword == kPayLoadSizeV0 || iword == kPayLoadSizeV1 || iword == kPayLoadSizeV2) {
318 DecodeTRUADC(word32, offset);
323 //_____________________________________________________________________________
324 void AliEMCALTriggerSTURawStream::DecodeL0GammaPatchIndexes(UInt_t *word32, const int offset)
326 //////////////////////////////////////////////////////////
328 //////////////////////////////////////////////////////////
329 // FIXME: sounds like not valid data
331 unsigned short truL0indexes[32][6];
333 // extraction from stream
334 for (Int_t index=0;index<6;index++)
336 for (Int_t tru_num=0;tru_num<16;tru_num++)
338 truL0indexes[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
339 truL0indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
343 for (Int_t tru_num=0;tru_num<32;tru_num++)
345 for (Int_t index=0;index<6;index++)
347 for (Int_t bit_num=0;bit_num<12;bit_num++)
349 if ((truL0indexes[tru_num][index] & (1 << bit_num)))
351 Int_t idx = 12 * index + bit_num;
355 fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
362 //_____________________________________________________________________________
363 void AliEMCALTriggerSTURawStream::DecodeL1JetPatchIndexes(const int i, UInt_t *word32, const int offset)
365 //////////////////////////////////////////////////////////
366 // index des L1 jet //
367 //////////////////////////////////////////////////////////
369 int jetSize = 2 + (fFwVersion >> 16);
371 for (Int_t jet_row = 0; jet_row < 12 - (jetSize - 1); jet_row++)
373 UInt_t currentrow = word32[offset + jet_row];
375 for (Int_t jet_col = 0; jet_col < 15; jet_col++)
377 if (currentrow & (1 << jet_col))
379 fNL1JetPatch[i] = fNL1JetPatch[i] + 1;
381 fL1JetPatchIndex[fNL1JetPatch[i] - 1][i] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
387 //_____________________________________________________________________________
388 void AliEMCALTriggerSTURawStream::DecodeL1GammaPatchIndexes(const int i, UInt_t *word32, const int offset)
390 //////////////////////////////////////////////////////////
391 // index des L1 gamma //
392 //////////////////////////////////////////////////////////
394 unsigned short truL1indexes[32][8];
396 // extraction from stream
397 for (Int_t index=0;index<8;index++)
399 for (Int_t tru_num=0;tru_num<16;tru_num++)
401 truL1indexes[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
402 truL1indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
410 for (Int_t tru_num=0;tru_num<32;tru_num++)
412 for (Int_t index=0;index<8;index++)
414 for (Int_t bit_num=0; bit_num<12; bit_num++)
416 if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
420 gammacolnum = (2*bit_num );
425 gammacolnum = (2*bit_num+1);
429 fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
431 fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
438 //_____________________________________________________________________________
439 void AliEMCALTriggerSTURawStream::DecodeTRUADC(UInt_t *word32, const int offset)
441 // extraction from stream
442 for (Int_t index=0;index<96;index++)
444 for (Int_t tru_num=0;tru_num<16;tru_num++)
446 fADC[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
447 fADC[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
451 for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
454 for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
456 for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
461 //_____________________________________________________________________________
462 Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
464 // L0 gamma patches sent to STU (original access to L0 patch indexes)
466 if (i > fNL0GammaPatch) return kFALSE;
468 tru = fL0GammaPatchIndex[i] & 0x1F;
469 idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
474 //_____________________________________________________________________________
475 Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, const Int_t j, Int_t& tru, Int_t& col, Int_t& row) const
477 // L1 gamma patch indexes
479 if (j > 2 || i > fNL1GammaPatch[j]) return kFALSE;
481 tru = fL1GammaPatchIndex[i][j] & 0x1F;
482 col = (fL1GammaPatchIndex[i][j] & 0x3E0) >> 5;
483 row = (fL1GammaPatchIndex[i][j] & 0xC00) >> 10;
488 //_____________________________________________________________________________
489 Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, const Int_t j, Int_t& col, Int_t& row) const
491 // L1 jet patch indexes
493 if (j > 2 || i > fNL1JetPatch[j]) return kFALSE;
495 col = fL1JetPatchIndex[i][j] & 0xFF;
496 row = (fL1JetPatchIndex[i][j] & 0xFF00) >> 8;
501 //_____________________________________________________________________________
502 void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
506 for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
509 //_____________________________________________________________________________
510 void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
516 printf("V0A: %d\n", fV0A);
517 printf("V0C: %d\n", fV0C);
519 printf("RawData: %d\n", fGetRawData);
520 printf("RegionEnable: %8x\n", fRegionEnable);
521 printf("FrameReceived: %8x\n", fFrameReceived);
522 printf("FwVersion: %x\n", fFwVersion);
523 printf("Number of L0: %d\n", fNL0GammaPatch);
525 for (int i = 0; i < 2; i++) {
526 for (int j = 0; j < 3; j++) {
527 printf("G[%d][%d]: %d\n", j, i, fG[j][i]);
528 printf("J[%d][%d]: %d\n", j, i, fJ[j][i]);
531 printf("Gamma threshold[%d]: %d\n", i, fL1GammaThreshold[i]);
532 printf("Jet Threshold[%d]: %d\n", i, fL1JetThreshold[i]);
534 printf("Number of L1-g[%d]: %d\n", i, fNL1GammaPatch[i]);
535 printf("Number of L1-j[%d]: %d\n", i, fNL1JetPatch[i]);
538 Int_t itru, col, row;
540 if (op.Contains("L0") || op.Contains("ALL"))
542 for (Int_t i = 0;i < fNL0GammaPatch; i++) {
543 if (GetL0GammaPatch(i,itru,col))
544 cout << "> Found L0 gamma in TRU #" << setw(2) << itru << " at idx: " << setw(2) << col << endl;
548 if (op.Contains("L1") || op.Contains("ALL")) {
549 for (int j = 0; j < 2; j++) {
550 for (Int_t i = 0; i < fNL1GammaPatch[j]; i++) {
551 if (GetL1GammaPatch(i, j, itru, col, row))
552 cout << "> Found L1 gamma " << j << " in TRU #" << setw(2) << itru << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
555 for (Int_t i = 0; i < fNL1JetPatch[j]; i++) {
556 if (GetL1JetPatch(i, j, col, row)) cout << "> Found L1 jet " << j << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
561 if ((op.Contains("ADC") || op.Contains("ALL")) && fGetRawData) {
562 for (Int_t i = 0; i < 32; i++) {
563 cout << "--------\n";
564 cout << "TRU #" << setw(2) << i << ":";
565 for (Int_t j = 0;j < 96; j++) {
566 //TBits xadc(12); xadc.Set(12,&fADC[i][j]);
567 if ((j % 4) == 0) cout << endl;
568 //cout << setw(2) << j << ": " << xadc << " ";
569 printf("%2d: %3x / ",j,fADC[i][j]);
576 //_____________________________________________________________________________
577 UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
580 ULong64_t v0sum = V0A + V0C;
582 ULong64_t sqrV0 = v0sum * v0sum;
592 return (UShort_t)(sqrV0 + v0sum + C);