Add more user oriented options to costumize the tender - Jiri
[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{
648b8b91 36 const Int_t kPayLoadSizeOld = 236;
222f9c45 37 const Int_t kPayLoadSizeNew = 245;
916f1e76 38}
39
40ClassImp(AliEMCALTriggerSTURawStream)
41
42//_____________________________________________________________________________
43AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream() : TObject(),
44fRawReader(0x0),
45fL1JetThreshold(0),
46fL1GammaThreshold(0),
de39a0ff 47fL0GammaPatchIndex(),
48fL1GammaPatchIndex(),
49fL1JetPatchIndex(),
916f1e76 50fNL0GammaPatch(0),
51fNL1JetPatch(0),
52fNL1GammaPatch(0),
648b8b91 53fGetRawData(0),
54fV0A(0),
55fV0C(0),
56fGA(0),
57fGB(0),
58fGC(0),
59fJA(0),
60fJB(0),
61fJC(0),
62fRegionEnable(0),
63fFrameReceived(0),
64fFwVersion(0)
916f1e76 65{
66 //
67}
68
69//_____________________________________________________________________________
70AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
71fRawReader(rawReader),
72fL1JetThreshold(0),
73fL1GammaThreshold(0),
de39a0ff 74fL0GammaPatchIndex(),
75fL1GammaPatchIndex(),
76fL1JetPatchIndex(),
916f1e76 77fNL0GammaPatch(0),
78fNL1JetPatch(0),
de39a0ff 79fNL1GammaPatch(0),
648b8b91 80fGetRawData(0),
81fV0A(0),
82fV0C(0),
83fGA(0),
84fGB(0),
85fGC(0),
86fJA(0),
87fJB(0),
88fJC(0),
89fRegionEnable(0),
90fFrameReceived(0),
91fFwVersion(0)
916f1e76 92{
93 //
94 fRawReader->Reset();
95 fRawReader->Select("EMCAL",44);
96}
97
98//_____________________________________________________________________________
99AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
100{
101 // destructor
102}
103
104//_____________________________________________________________________________
105void AliEMCALTriggerSTURawStream::Reset()
106{
c1147445 107 // Reset
108
916f1e76 109 if (fRawReader) fRawReader->Reset();
de39a0ff 110
fff39dd1 111 fNL0GammaPatch = 0;
112 fNL1GammaPatch = 0;
113 fNL1JetPatch = 0;
916f1e76 114}
115
116//_____________________________________________________________________________
117Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
118{
119 // STU data decoder from Olivier Bourrion LPSC CNRS-IN2P3
4bd37bd4 120 // bourrion_at_lpsc_dot_in2p3_dot_fr
916f1e76 121
648b8b91 122 UInt_t word32[kPayLoadSizeNew + 1536]; // 32b words
123 for (Int_t i = 0;i < kPayLoadSizeNew + 1536; i++) word32[i] = 0;
de39a0ff 124
916f1e76 125 Int_t iword = 0;
fff39dd1 126
127 fNL0GammaPatch = 0;
128 fNL1GammaPatch = 0;
129 fNL1JetPatch = 0;
130
de39a0ff 131 Int_t eqId = -1, eqSize = 0;
916f1e76 132
133 UInt_t w32;
648b8b91 134
de39a0ff 135 while (fRawReader->ReadNextInt(w32))
136 {
137 if (!iword)
138 {
139 eqId = fRawReader->GetEquipmentId();
140 eqSize = fRawReader->GetEquipmentSize();
141 }
142
143 word32[iword++] = w32;
144 }
804b828a 145
648b8b91 146 if (iword != kPayLoadSizeOld && iword != kPayLoadSizeNew && iword != (kPayLoadSizeOld + 1536) && iword != (kPayLoadSizeNew + 1536))
916f1e76 147 {
648b8b91 148 AliError(Form("STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32",
de39a0ff 149 eqId, eqSize, iword));
916f1e76 150 return kFALSE;
de39a0ff 151 }
648b8b91 152
153 if (AliDebugLevel())
916f1e76 154 {
de39a0ff 155 AliInfo(Form("STU (eqId: %d, eqSize: %d) payload size: %d word32",
156 eqId, eqSize, iword));
916f1e76 157 }
916f1e76 158
ad9ab1c9 159 int offset = 0, jetSize = 2;
648b8b91 160
161 switch (iword)
162 {
163 case kPayLoadSizeOld:
164 case kPayLoadSizeOld + 1536:
165 {
46e461b8 166 fL1JetThreshold = ((word32[0]>>16) & 0xFFFF);
167 fL1GammaThreshold = (word32[0] & 0xFFFF);
648b8b91 168
169 break;
170 }
171 case kPayLoadSizeNew:
172 case kPayLoadSizeNew + 1536:
173 {
46e461b8 174 fV0A = ((word32[0]>>16) & 0xFFFF);
175 fV0C = (word32[0] & 0xFFFF);
648b8b91 176
648b8b91 177 fGA = word32[1];
178 fGB = word32[2];
179 fGC = word32[3];
180 fJA = word32[4];
181 fJB = word32[5];
182 fJC = word32[6];
183 fRegionEnable = word32[7];
184 fFrameReceived = word32[8];
185 fFwVersion = word32[9];
186
ad9ab1c9 187 jetSize += (fFwVersion >> 16);
188
222f9c45 189 fL1JetThreshold = GetThreshold(fJA, fJB, fJC, fV0A, fV0C);
190 fL1GammaThreshold = GetThreshold(fGA, fGB, fGC, fV0A, fV0C);
648b8b91 191
192 offset = 9;
193
194 break;
195 }
648b8b91 196 }
197
198 ///////////
199 // START DECODING
200 //////////
ad9ab1c9 201
202 for (Int_t jet_row = 0; jet_row < 12 - (jetSize - 1); jet_row++)
916f1e76 203 {
648b8b91 204 UInt_t currentrow = word32[offset + 1 + jet_row];
916f1e76 205
648b8b91 206 for (Int_t jet_col = 0; jet_col < 15; jet_col++)
916f1e76 207 {
208 if (currentrow & (1 << jet_col))
209 {
210 fNL1JetPatch++;
916f1e76 211
212 fL1JetPatchIndex[fNL1JetPatch-1] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
213 }
214 }
215 }
648b8b91 216
916f1e76 217
218 //////////////////////////////////////////////////////////
219 // index des L0 //
220 //////////////////////////////////////////////////////////
648b8b91 221 // FIXME: sounds like not valid data
916f1e76 222
c1147445 223 unsigned short truL0indexes[32][6];
916f1e76 224
225 // extraction from stream
226 for (Int_t index=0;index<6;index++)
227 {
228 for (Int_t tru_num=0;tru_num<16;tru_num++)
229 {
648b8b91 230 truL0indexes[2*tru_num ][index] = ( word32[offset + 12 + index * 16 + tru_num] & 0xFFFF);
231 truL0indexes[2*tru_num+1][index] = ((word32[offset + 12 + index * 16 + tru_num] >> 16) & 0xFFFF);
916f1e76 232 }
233 }
234
235 for (Int_t tru_num=0;tru_num<32;tru_num++)
236 {
237 for (Int_t index=0;index<6;index++)
238 {
239 for (Int_t bit_num=0;bit_num<12;bit_num++)
240 {
c1147445 241 if ((truL0indexes[tru_num][index] & (1 << bit_num)))
916f1e76 242 {
916f1e76 243 Int_t idx = 12 * index + bit_num;
de39a0ff 244
916f1e76 245 fNL0GammaPatch++;
916f1e76 246
de39a0ff 247 fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
916f1e76 248 }
249 }
250 }
251 }
252
253 //////////////////////////////////////////////////////////
254 // index des L1 gamma //
255 //////////////////////////////////////////////////////////
256
c1147445 257 unsigned short truL1indexes[32][8];
916f1e76 258
259 // extraction from stream
260 for (Int_t index=0;index<8;index++)
261 {
262 for (Int_t tru_num=0;tru_num<16;tru_num++)
263 {
648b8b91 264 truL1indexes[2*tru_num ][index] = ( word32[offset + 108 + index * 16 + tru_num] & 0xFFFF);
265 truL1indexes[2*tru_num+1][index] = ((word32[offset + 108 + index * 16 + tru_num] >> 16) & 0xFFFF);
916f1e76 266 }
267 }
268
269 // interpretation
270 int gammacolnum;
271 short indexcopy;
272
273 for (Int_t tru_num=0;tru_num<32;tru_num++)
274 {
275 for (Int_t index=0;index<8;index++)
276 {
277 for (Int_t bit_num=0; bit_num<12; bit_num++)
278 {
c1147445 279 if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
916f1e76 280 {
281 if (index<4) // Even
282 {
283 gammacolnum = (2*bit_num );
284 indexcopy = index;
285 }
286 else // Odd
287 {
288 gammacolnum = (2*bit_num+1);
289 indexcopy = index-4;
290 }
291
292 fNL1GammaPatch++;
916f1e76 293
294 fL1GammaPatchIndex[fNL1GammaPatch-1] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
295 }
296 }
297 }
298 }
299
300 //////////////////////////////////////////////////////////
301 // raw output //
302 //////////////////////////////////////////////////////////
303
648b8b91 304 if (iword == kPayLoadSizeOld || iword == kPayLoadSizeNew)
39c05eac 305 {
306 fGetRawData = 0;
de39a0ff 307 return kTRUE;
39c05eac 308 }
309
310 fGetRawData = 1;
916f1e76 311
312 // extraction from stream
313 for (Int_t index=0;index<96;index++)
314 {
315 for (Int_t tru_num=0;tru_num<16;tru_num++)
316 {
648b8b91 317 fADC[2*tru_num ][index] = ( word32[offset + 236 + index * 16 + tru_num] & 0xFFFF);
318 fADC[2*tru_num+1][index] = ((word32[offset + 236 + index * 16 + tru_num] >> 16) & 0xFFFF);
916f1e76 319 }
320 }
321
322 for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
323 {
de39a0ff 324 Int_t v[96];
325 for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
326
327 for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
916f1e76 328 }
329
de39a0ff 330 return kTRUE;
916f1e76 331}
332
333//_____________________________________________________________________________
de39a0ff 334Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
916f1e76 335{
c1147445 336 // L0 gamma patches sent to STU (original access to L0 patch indexes)
337
916f1e76 338 if (i > fNL0GammaPatch) return kFALSE;
339
340 tru = fL0GammaPatchIndex[i] & 0x1F;
de39a0ff 341 idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
916f1e76 342
343 return kTRUE;
344}
345
346//_____________________________________________________________________________
347Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, Int_t& tru, Int_t& col, Int_t& row) const
348{
c1147445 349 // L1 gamma patch indexes
350
916f1e76 351 if (i > fNL1GammaPatch) return kFALSE;
352
353 tru = fL1GammaPatchIndex[i] & 0x1F;
354 col = (fL1GammaPatchIndex[i] & 0x3E0) >> 5;
355 row = (fL1GammaPatchIndex[i] & 0xC00) >> 10;
356
357 return kTRUE;
358}
359
360//_____________________________________________________________________________
361Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, Int_t& col, Int_t& row) const
362{
c1147445 363 // L1 jet patch indexes
364
916f1e76 365 if (i > fNL1JetPatch) return kFALSE;
366
367 col = fL1JetPatchIndex[i] & 0xFF;
368 row = (fL1JetPatchIndex[i] & 0xFF00) >> 8;
369
370 return kTRUE;
371}
372
373//_____________________________________________________________________________
374void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
375{
c1147445 376 // Time sums
377
916f1e76 378 for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
379}
380
381//_____________________________________________________________________________
80e5a1ae 382void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
916f1e76 383{
c1147445 384 // Dump STU payload
385
916f1e76 386 TString op = option;
387
648b8b91 388 printf("V0A: %d\n", fV0A);
389 printf("V0C: %d\n", fV0C);
390 printf("G_A: %d\n", fGA);
391 printf("G_B: %d\n", fGB);
392 printf("G_C: %d\n", fGC);
393 printf("Gamma threshold: %d\n", fL1GammaThreshold);
394 printf("J_A: %d\n", fJA);
395 printf("J_B: %d\n", fJB);
396 printf("J_C: %d\n", fJC);
397 printf("Jet Threshold: %d\n", fL1JetThreshold);
398 printf("RawData: %d\n", fGetRawData);
399 printf("RegionEnable: %8x\n", fRegionEnable);
400 printf("FrameReceived: %8x\n", fFrameReceived);
401 printf("FwVersion: %x\n", fFwVersion);
402 printf("Number of L0: %d\n", fNL0GammaPatch);
403 printf("Number of L1-g: %d\n", fNL1GammaPatch);
404 printf("Number of L1-j: %d\n", fNL1JetPatch);
916f1e76 405
406 Int_t itru, col, row;
916f1e76 407
408 if (op.Contains("L0") || op.Contains("ALL"))
409 {
410 for (Int_t i=0;i<fNL0GammaPatch;i++)
411 {
de39a0ff 412
413 if (GetL0GammaPatch(i,itru,col))
414 cout << "> Found L0 gamma in TRU #" << setw(2) << itru << " at idx: " << setw(2) << col << endl;
916f1e76 415 }
416 }
417
418 if (op.Contains("L1") || op.Contains("ALL"))
419 {
420 for (Int_t i=0;i<fNL1GammaPatch;i++)
421 {
de39a0ff 422 if (GetL1GammaPatch(i,itru,col,row))
423 cout << "> Found L1 gamma in TRU #" << setw(2) << itru << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
916f1e76 424 }
425
426 for (Int_t i=0;i<fNL1JetPatch;i++)
427 {
de39a0ff 428 if (GetL1JetPatch(i,col,row)) cout << "> Found L1 jet at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
916f1e76 429 }
430 }
431
648b8b91 432
39c05eac 433
434 if ( (op.Contains("ADC") || op.Contains("ALL")) && fGetRawData )
916f1e76 435 {
436 for (Int_t i=0;i<32;i++)
437 {
438 cout << "--------\n";
439 cout << "TRU #" << setw(2) << i << ":";
440 for (Int_t j=0;j<96;j++)
441 {
442 TBits xadc(12); xadc.Set(12,&fADC[i][j]);
443 if ((j%4)==0) cout << endl;
444 //cout << setw(2) << j << ": " << xadc << " ";
445 printf("%2d: %3x / ",j,fADC[i][j]);
446 }
447 cout << "\n";
448 }
449 }
450}
222f9c45 451
452//_____________________________________________________________________________
79b05051 453UShort_t AliEMCALTriggerSTURawStream::GetThreshold(Short_t A, Short_t B, Short_t C, UShort_t V0A, UShort_t V0C) const
222f9c45 454{
79b05051 455 // Get threshold
456 ULong64_t v0sum = V0A + V0C;
222f9c45 457
79b05051 458 ULong64_t sqrV0 = v0sum * v0sum;
222f9c45 459
460 sqrV0 *= A;
461
462 sqrV0 >>= 32;
463
79b05051 464 v0sum *= B;
222f9c45 465
79b05051 466 v0sum >>= 16;
222f9c45 467
79b05051 468 return (UShort_t)(sqrV0 + v0sum + C);
222f9c45 469}