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);
287 // jetSize += (fFwVersion >> 16);
293 for (int i = 0; i < nthres; i++) {
294 DecodeL1JetPatchIndexes(i, word32, offset);
299 DecodeL0GammaPatchIndexes(word32, offset);
303 for (int i = 0; i < nthres; i++) {
304 DecodeL1GammaPatchIndexes(i, word32, offset);
309 if (iword == kPayLoadSizeV0 || iword == kPayLoadSizeV1 || iword == kPayLoadSizeV2) {
316 DecodeTRUADC(word32, offset);
321 //_____________________________________________________________________________
322 void AliEMCALTriggerSTURawStream::DecodeL0GammaPatchIndexes(UInt_t *word32, const int offset)
324 //////////////////////////////////////////////////////////
326 //////////////////////////////////////////////////////////
327 // FIXME: sounds like not valid data
329 unsigned short truL0indexes[32][6];
331 // extraction from stream
332 for (Int_t index=0;index<6;index++)
334 for (Int_t tru_num=0;tru_num<16;tru_num++)
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);
341 for (Int_t tru_num=0;tru_num<32;tru_num++)
343 for (Int_t index=0;index<6;index++)
345 for (Int_t bit_num=0;bit_num<12;bit_num++)
347 if ((truL0indexes[tru_num][index] & (1 << bit_num)))
349 Int_t idx = 12 * index + bit_num;
353 fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
360 //_____________________________________________________________________________
361 void AliEMCALTriggerSTURawStream::DecodeL1JetPatchIndexes(const int i, UInt_t *word32, const int offset)
363 //////////////////////////////////////////////////////////
364 // index des L1 jet //
365 //////////////////////////////////////////////////////////
367 int jetSize = 2 + (fFwVersion >> 16);
369 for (Int_t jet_row = 0; jet_row < 12 - (jetSize - 1); jet_row++)
371 UInt_t currentrow = word32[offset + jet_row];
373 for (Int_t jet_col = 0; jet_col < 15; jet_col++)
375 if (currentrow & (1 << jet_col))
377 fNL1JetPatch[i] = fNL1JetPatch[i] + 1;
379 fL1JetPatchIndex[fNL1JetPatch[i] - 1][i] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
385 //_____________________________________________________________________________
386 void AliEMCALTriggerSTURawStream::DecodeL1GammaPatchIndexes(const int i, UInt_t *word32, const int offset)
388 //////////////////////////////////////////////////////////
389 // index des L1 gamma //
390 //////////////////////////////////////////////////////////
392 unsigned short truL1indexes[32][8];
394 // extraction from stream
395 for (Int_t index=0;index<8;index++)
397 for (Int_t tru_num=0;tru_num<16;tru_num++)
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);
408 for (Int_t tru_num=0;tru_num<32;tru_num++)
410 for (Int_t index=0;index<8;index++)
412 for (Int_t bit_num=0; bit_num<12; bit_num++)
414 if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
418 gammacolnum = (2*bit_num );
423 gammacolnum = (2*bit_num+1);
427 fNL1GammaPatch[i] = fNL1GammaPatch[i] + 1;
429 fL1GammaPatchIndex[fNL1GammaPatch[i] - 1][i] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
436 //_____________________________________________________________________________
437 void AliEMCALTriggerSTURawStream::DecodeTRUADC(UInt_t *word32, const int offset)
439 // extraction from stream
440 for (Int_t index=0;index<96;index++)
442 for (Int_t tru_num=0;tru_num<16;tru_num++)
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);
449 for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
452 for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
454 for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
459 //_____________________________________________________________________________
460 Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
462 // L0 gamma patches sent to STU (original access to L0 patch indexes)
464 if (i > fNL0GammaPatch) return kFALSE;
466 tru = fL0GammaPatchIndex[i] & 0x1F;
467 idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
472 //_____________________________________________________________________________
473 Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, const Int_t j, Int_t& tru, Int_t& col, Int_t& row) const
475 // L1 gamma patch indexes
477 if (j > 2 || i > fNL1GammaPatch[j]) return kFALSE;
479 tru = fL1GammaPatchIndex[i][j] & 0x1F;
480 col = (fL1GammaPatchIndex[i][j] & 0x3E0) >> 5;
481 row = (fL1GammaPatchIndex[i][j] & 0xC00) >> 10;
486 //_____________________________________________________________________________
487 Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, const Int_t j, Int_t& col, Int_t& row) const
489 // L1 jet patch indexes
491 if (j > 2 || i > fNL1JetPatch[j]) return kFALSE;
493 col = fL1JetPatchIndex[i][j] & 0xFF;
494 row = (fL1JetPatchIndex[i][j] & 0xFF00) >> 8;
499 //_____________________________________________________________________________
500 void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
504 for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
507 //_____________________________________________________________________________
508 void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
514 printf("V0A: %d\n", fV0A);
515 printf("V0C: %d\n", fV0C);
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);
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]);
529 printf("Gamma threshold[%d]: %d\n", i, fL1GammaThreshold[i]);
530 printf("Jet Threshold[%d]: %d\n", i, fL1JetThreshold[i]);
532 printf("Number of L1-g[%d]: %d\n", i, fNL1GammaPatch[i]);
533 printf("Number of L1-j[%d]: %d\n", i, fNL1JetPatch[i]);
536 Int_t itru, col, row;
538 if (op.Contains("L0") || op.Contains("ALL"))
540 for (Int_t i = 0;i < fNL0GammaPatch; i++) {
541 if (GetL0GammaPatch(i,itru,col))
542 cout << "> Found L0 gamma in TRU #" << setw(2) << itru << " at idx: " << setw(2) << col << endl;
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;
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;
559 if ((op.Contains("ADC") || op.Contains("ALL")) && fGetRawData) {
560 for (Int_t i = 0; i < 32; i++) {
561 cout << "--------\n";
562 cout << "TRU #" << setw(2) << i << ":";
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;
566 //cout << setw(2) << j << ": " << xadc << " ";
567 printf("%2d: %3x / ",j,fADC[i][j]);
574 //_____________________________________________________________________________
575 UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
578 ULong64_t v0sum = V0A + V0C;
580 ULong64_t sqrV0 = v0sum * v0sum;
590 return (UShort_t)(sqrV0 + v0sum + C);