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;
44 ClassImp(AliEMCALTriggerSTURawStream)
46 //_____________________________________________________________________________
47 AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream() : TObject(),
67 for (int i = 0; i < 2; i++) {
69 fL1JetThreshold[i] = fL1GammaThreshold[i] = 0;
71 fNL1JetPatch[i] = fNL1GammaPatch[i] = 0;
74 for (int i = 0; i < 3; i++) {
75 for (int j = 0; j < 2; j++) {
77 fG[i][j] = fJ[i][j] = 0;
81 for (int i = 0; i < 3100; i++) {
83 fL0GammaPatchIndex[i] = 0;
85 for (int j = 0; j < 2; j++) {
87 fL1GammaPatchIndex[i][j] = 0;
91 for (int i = 0; i < 200; i++) {
92 for (int j = 0; j < 2; j++) {
94 fL1JetPatchIndex[i][j] = 0;
99 //_____________________________________________________________________________
100 AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
101 fRawReader(rawReader),
104 fL0GammaPatchIndex(),
105 fL1GammaPatchIndex(),
121 fRawReader->Select("EMCAL",44);
123 for (int i = 0; i < 2; i++) {
125 fL1JetThreshold[i] = fL1GammaThreshold[i] = 0;
127 fNL1JetPatch[i] = fNL1GammaPatch[i] = 0;
130 for (int i = 0; i < 3; i++) {
131 for (int j = 0; j < 2; j++) {
133 fG[i][j] = fJ[i][j] = 0;
137 for (int i = 0; i < 3100; i++) {
139 fL0GammaPatchIndex[i] = 0;
141 for (int j = 0; j < 2; j++) {
143 fL1GammaPatchIndex[i][j] = 0;
147 for (int i = 0; i < 200; i++) {
148 for (int j = 0; j < 2; j++) {
150 fL1JetPatchIndex[i][j] = 0;
155 //_____________________________________________________________________________
156 AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
161 //_____________________________________________________________________________
162 void AliEMCALTriggerSTURawStream::Reset()
166 if (fRawReader) fRawReader->Reset();
169 fNL1GammaPatch[0] = fNL1GammaPatch[1] = 0;
170 fNL1JetPatch[0] = fNL1JetPatch[1] = 0;
173 //_____________________________________________________________________________
174 Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
176 // STU data decoder from Olivier Bourrion LPSC CNRS-IN2P3
177 // bourrion_at_lpsc_dot_in2p3_dot_fr
179 UInt_t word32[kPayLoadSizeV2 + 1536]; // 32b words
180 for (Int_t i = 0;i < kPayLoadSizeV2 + 1536; i++) word32[i] = 0;
185 fNL1GammaPatch[0] = fNL1GammaPatch[1] = 0;
186 fNL1JetPatch[0] = fNL1JetPatch[1] = 0;
188 Int_t eqId = -1, eqSize = 0;
192 while (fRawReader->ReadNextInt(w32))
196 eqId = fRawReader->GetEquipmentId();
197 eqSize = fRawReader->GetEquipmentSize();
200 word32[iword++] = w32;
203 if (iword != kPayLoadSizeV0 && iword != kPayLoadSizeV1 && iword != kPayLoadSizeV2
205 iword != (kPayLoadSizeV0 + 1536) && iword != (kPayLoadSizeV1 + 1536) && iword != (kPayLoadSizeV2 + 1536))
207 AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32",
208 eqId, eqSize, iword));
212 AliDebug(1, Form("STU (eqId: %d, eqSize: %d) payload size: %d word32",
213 eqId, eqSize, iword));
215 int offset = 1;//, jetSize = 2;
222 case kPayLoadSizeV0 + 1536:
224 fL1JetThreshold[0] = ((word32[0]>>16) & 0xFFFF);
225 fL1GammaThreshold[0] = (word32[0] & 0xFFFF);
230 case kPayLoadSizeV1 + 1536:
232 fV0A = ((word32[0]>>16) & 0xFFFF);
233 fV0C = (word32[0] & 0xFFFF);
235 fG[0][0] = word32[1];
236 fG[1][0] = word32[2];
237 fG[2][0] = word32[3];
238 fJ[0][0] = word32[4];
239 fJ[1][0] = word32[5];
240 fJ[2][0] = word32[6];
241 fRegionEnable = word32[7];
242 fFrameReceived = word32[8];
243 fFwVersion = word32[9];
245 fL1JetThreshold[0] = GetThreshold(fJ[0][0], fJ[1][0], fJ[2][0], fV0A, fV0C);
246 fL1GammaThreshold[0] = GetThreshold(fG[0][0], fG[1][0], fG[2][0], fV0A, fV0C);
253 case kPayLoadSizeV2 + 1536:
255 fV0A = ((word32[0]>>16) & 0xFFFF);
256 fV0C = (word32[0] & 0xFFFF);
258 fG[0][0] = word32[1];
259 fG[1][0] = word32[2];
260 fG[2][0] = word32[3];
261 fJ[0][0] = word32[4];
262 fJ[1][0] = word32[5];
263 fJ[2][0] = word32[6];
265 fG[0][1] = word32[7];
266 fG[1][1] = word32[8];
267 fG[2][1] = word32[9];
268 fJ[0][1] = word32[10];
269 fJ[1][1] = word32[11];
270 fJ[2][1] = word32[12];
272 fRegionEnable = word32[13];
273 fFrameReceived = word32[14];
274 fFwVersion = word32[15];
276 for (int i = 0; i < 2; i++) {
278 fL1JetThreshold[i] = GetThreshold(fJ[0][i], fJ[1][i], fJ[2][i], fV0A, fV0C);
279 fL1GammaThreshold[i] = GetThreshold(fG[0][i], fG[1][i], fG[2][i], fV0A, fV0C);
290 // jetSize += (fFwVersion >> 16);
296 for (int i = 0; i < nthres; i++) {
297 DecodeL1JetPatchIndexes(i, word32, offset);
302 DecodeL0GammaPatchIndexes(word32, offset);
306 for (int i = 0; i < nthres; i++) {
307 DecodeL1GammaPatchIndexes(i, word32, offset);
312 if (iword == kPayLoadSizeV0 || iword == kPayLoadSizeV1 || iword == kPayLoadSizeV2) {
319 DecodeTRUADC(word32, offset);
324 //_____________________________________________________________________________
325 void AliEMCALTriggerSTURawStream::DecodeL0GammaPatchIndexes(UInt_t *word32, const int offset)
327 //////////////////////////////////////////////////////////
329 //////////////////////////////////////////////////////////
330 // FIXME: sounds like not valid data
332 unsigned short truL0indexes[32][6];
334 // extraction from stream
335 for (Int_t index=0;index<6;index++)
337 for (Int_t tru_num=0;tru_num<16;tru_num++)
339 truL0indexes[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
340 truL0indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
344 for (Int_t tru_num=0;tru_num<32;tru_num++)
346 for (Int_t index=0;index<6;index++)
348 for (Int_t bit_num=0;bit_num<12;bit_num++)
350 if ((truL0indexes[tru_num][index] & (1 << bit_num)))
352 Int_t idx = 12 * index + bit_num;
356 fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
363 //_____________________________________________________________________________
364 void AliEMCALTriggerSTURawStream::DecodeL1JetPatchIndexes(const int i, UInt_t *word32, const int offset)
366 //////////////////////////////////////////////////////////
367 // index des L1 jet //
368 //////////////////////////////////////////////////////////
370 int jetSize = 2 + (fFwVersion >> 16);
372 for (Int_t jet_row = 0; jet_row < 12 - (jetSize - 1); jet_row++)
374 UInt_t currentrow = word32[offset + jet_row];
376 for (Int_t jet_col = 0; jet_col < 15; jet_col++)
378 if (currentrow & (1 << jet_col))
380 fNL1JetPatch[i] = fNL1JetPatch[i] + 1;
382 fL1JetPatchIndex[fNL1JetPatch[i] - 1][i] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
388 //_____________________________________________________________________________
389 void AliEMCALTriggerSTURawStream::DecodeL1GammaPatchIndexes(const int i, UInt_t *word32, const int offset)
391 //////////////////////////////////////////////////////////
392 // index des L1 gamma //
393 //////////////////////////////////////////////////////////
395 unsigned short truL1indexes[32][8];
397 // extraction from stream
398 for (Int_t index=0;index<8;index++)
400 for (Int_t tru_num=0;tru_num<16;tru_num++)
402 truL1indexes[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
403 truL1indexes[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
411 for (Int_t tru_num=0;tru_num<32;tru_num++)
413 for (Int_t index=0;index<8;index++)
415 for (Int_t bit_num=0; bit_num<12; bit_num++)
417 if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
421 gammacolnum = (2*bit_num );
426 gammacolnum = (2*bit_num+1);
430 fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
432 fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
439 //_____________________________________________________________________________
440 void AliEMCALTriggerSTURawStream::DecodeTRUADC(UInt_t *word32, const int offset)
442 // extraction from stream
443 for (Int_t index=0;index<96;index++)
445 for (Int_t tru_num=0;tru_num<16;tru_num++)
447 fADC[2*tru_num ][index] = ( word32[offset + index * 16 + tru_num] & 0xFFFF);
448 fADC[2*tru_num+1][index] = ((word32[offset + index * 16 + tru_num] >> 16) & 0xFFFF);
452 for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
455 for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
457 for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
462 //_____________________________________________________________________________
463 Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
465 // L0 gamma patches sent to STU (original access to L0 patch indexes)
467 if (i > fNL0GammaPatch) return kFALSE;
469 tru = fL0GammaPatchIndex[i] & 0x1F;
470 idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
475 //_____________________________________________________________________________
476 Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, const Int_t j, Int_t& tru, Int_t& col, Int_t& row) const
478 // L1 gamma patch indexes
480 if (j >= 2 || i > fNL1GammaPatch[j]) return kFALSE;
482 tru = fL1GammaPatchIndex[i][j] & 0x1F;
483 col = (fL1GammaPatchIndex[i][j] & 0x3E0) >> 5;
484 row = (fL1GammaPatchIndex[i][j] & 0xC00) >> 10;
489 //_____________________________________________________________________________
490 Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, const Int_t j, Int_t& col, Int_t& row) const
492 // L1 jet patch indexes
494 if (j >= 2 || i > fNL1JetPatch[j]) return kFALSE;
496 col = fL1JetPatchIndex[i][j] & 0xFF;
497 row = (fL1JetPatchIndex[i][j] & 0xFF00) >> 8;
502 //_____________________________________________________________________________
503 void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
507 for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
510 //_____________________________________________________________________________
511 void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
517 printf("V0A: %d\n", fV0A);
518 printf("V0C: %d\n", fV0C);
520 printf("RawData: %d\n", fGetRawData);
521 printf("RegionEnable: %8x\n", fRegionEnable);
522 printf("FrameReceived: %8x\n", fFrameReceived);
523 printf("FwVersion: %x\n", fFwVersion);
524 printf("Number of L0: %d\n", fNL0GammaPatch);
526 for (int i = 0; i < 2; i++) {
527 for (int j = 0; j < 3; j++) {
528 printf("G[%d][%d]: %d\n", j, i, fG[j][i]);
529 printf("J[%d][%d]: %d\n", j, i, fJ[j][i]);
532 printf("Gamma threshold[%d]: %d\n", i, fL1GammaThreshold[i]);
533 printf("Jet Threshold[%d]: %d\n", i, fL1JetThreshold[i]);
535 printf("Number of L1-g[%d]: %d\n", i, fNL1GammaPatch[i]);
536 printf("Number of L1-j[%d]: %d\n", i, fNL1JetPatch[i]);
539 Int_t itru, col, row;
541 if (op.Contains("L0") || op.Contains("ALL"))
543 for (Int_t i = 0;i < fNL0GammaPatch; i++) {
544 if (GetL0GammaPatch(i,itru,col))
545 cout << "> Found L0 gamma in TRU #" << setw(2) << itru << " at idx: " << setw(2) << col << endl;
549 if (op.Contains("L1") || op.Contains("ALL")) {
550 for (int j = 0; j < 2; j++) {
551 for (Int_t i = 0; i < fNL1GammaPatch[j]; i++) {
552 if (GetL1GammaPatch(i, j, itru, col, row))
553 cout << "> Found L1 gamma " << j << " in TRU #" << setw(2) << itru << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
556 for (Int_t i = 0; i < fNL1JetPatch[j]; i++) {
557 if (GetL1JetPatch(i, j, col, row)) cout << "> Found L1 jet " << j << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
562 if ((op.Contains("ADC") || op.Contains("ALL")) && fGetRawData) {
563 for (Int_t i = 0; i < 32; i++) {
564 cout << "--------\n";
565 cout << "TRU #" << setw(2) << i << ":";
566 for (Int_t j = 0;j < 96; j++) {
567 //TBits xadc(12); xadc.Set(12,&fADC[i][j]);
568 if ((j % 4) == 0) cout << endl;
569 //cout << setw(2) << j << ": " << xadc << " ";
570 printf("%2d: %3x / ",j,fADC[i][j]);
577 //_____________________________________________________________________________
578 UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
581 ULong64_t v0sum = V0A + V0C;
583 ULong64_t sqrV0 = v0sum * v0sum;
593 return (UShort_t)(sqrV0 + v0sum + C);