]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerSTURawStream.cxx
Warnings
[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{
de39a0ff 36 const Int_t kPayLoadSize = 944;
37 const Int_t kPayLoadSizeWithRawData = 1772;
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),
de39a0ff 53fGetRawData(0)
916f1e76 54{
55 //
56}
57
58//_____________________________________________________________________________
59AliEMCALTriggerSTURawStream::AliEMCALTriggerSTURawStream(AliRawReader* rawReader) : TObject(),
60fRawReader(rawReader),
61fL1JetThreshold(0),
62fL1GammaThreshold(0),
de39a0ff 63fL0GammaPatchIndex(),
64fL1GammaPatchIndex(),
65fL1JetPatchIndex(),
916f1e76 66fNL0GammaPatch(0),
67fNL1JetPatch(0),
de39a0ff 68fNL1GammaPatch(0),
69fGetRawData(0)
916f1e76 70{
71 //
72 fRawReader->Reset();
73 fRawReader->Select("EMCAL",44);
74}
75
76//_____________________________________________________________________________
77AliEMCALTriggerSTURawStream::~AliEMCALTriggerSTURawStream()
78{
79 // destructor
80}
81
82//_____________________________________________________________________________
83void AliEMCALTriggerSTURawStream::Reset()
84{
c1147445 85 // Reset
86
916f1e76 87 if (fRawReader) fRawReader->Reset();
de39a0ff 88
fff39dd1 89 fNL0GammaPatch = 0;
90 fNL1GammaPatch = 0;
91 fNL1JetPatch = 0;
916f1e76 92}
93
94//_____________________________________________________________________________
95Bool_t AliEMCALTriggerSTURawStream::ReadPayLoad()
96{
97 // STU data decoder from Olivier Bourrion LPSC CNRS-IN2P3
4bd37bd4 98 // bourrion_at_lpsc_dot_in2p3_dot_fr
916f1e76 99
100 UInt_t word32[1772]; // 32b words
de39a0ff 101 for (Int_t i=0;i<1772;i++) word32[i] = 0;
102
916f1e76 103 Int_t iword = 0;
fff39dd1 104
105 fNL0GammaPatch = 0;
106 fNL1GammaPatch = 0;
107 fNL1JetPatch = 0;
108
de39a0ff 109 Int_t eqId = -1, eqSize = 0;
916f1e76 110
111 UInt_t w32;
de39a0ff 112 while (fRawReader->ReadNextInt(w32))
113 {
114 if (!iword)
115 {
116 eqId = fRawReader->GetEquipmentId();
117 eqSize = fRawReader->GetEquipmentSize();
118 }
119
120 word32[iword++] = w32;
121 }
916f1e76 122
de39a0ff 123 if (iword != kPayLoadSize && iword != kPayLoadSizeWithRawData)
916f1e76 124 {
de39a0ff 125 AliError(Form("ERROR: STU payload (eqId: %d, eqSize: %d) doesn't match expected size! %d word32",
126 eqId, eqSize, iword));
916f1e76 127 return kFALSE;
de39a0ff 128 }
129 else if (AliDebugLevel())
916f1e76 130 {
de39a0ff 131 AliInfo(Form("STU (eqId: %d, eqSize: %d) payload size: %d word32",
132 eqId, eqSize, iword));
916f1e76 133 }
916f1e76 134
135 fL1JetThreshold = ((word32[0]>>16) & 0xFFF);
136 fL1GammaThreshold = (word32[0] & 0xFFF);
137
138 for (Int_t jet_row=0; jet_row<11; jet_row++)
139 {
140 UInt_t currentrow = word32[1+jet_row];
141
142 for (Int_t jet_col=0; jet_col<15; jet_col++)
143 {
144 if (currentrow & (1 << jet_col))
145 {
146 fNL1JetPatch++;
916f1e76 147
148 fL1JetPatchIndex[fNL1JetPatch-1] = ((jet_row << 8) & 0xFF00) | (jet_col & 0xFF);
149 }
150 }
151 }
152
153 //////////////////////////////////////////////////////////
154 // index des L0 //
155 //////////////////////////////////////////////////////////
156 // FIXME: still not interpreted to be done with Jiri
157
c1147445 158 unsigned short truL0indexes[32][6];
916f1e76 159
160 // extraction from stream
161 for (Int_t index=0;index<6;index++)
162 {
163 for (Int_t tru_num=0;tru_num<16;tru_num++)
164 {
c1147445 165 truL0indexes[2*tru_num ][index] = ( word32[12+index*16+tru_num] & 0xFFFF);
166 truL0indexes[2*tru_num+1][index] = ((word32[12+index*16+tru_num]>>16) & 0xFFFF);
916f1e76 167 }
168 }
169
170 for (Int_t tru_num=0;tru_num<32;tru_num++)
171 {
172 for (Int_t index=0;index<6;index++)
173 {
174 for (Int_t bit_num=0;bit_num<12;bit_num++)
175 {
c1147445 176 if ((truL0indexes[tru_num][index] & (1 << bit_num)))
916f1e76 177 {
916f1e76 178 Int_t idx = 12 * index + bit_num;
de39a0ff 179
916f1e76 180 fNL0GammaPatch++;
916f1e76 181
de39a0ff 182 fL0GammaPatchIndex[fNL0GammaPatch-1] = (((idx << 5) & 0x7E0) | (tru_num & 0x1F));
916f1e76 183 }
184 }
185 }
186 }
187
188 //////////////////////////////////////////////////////////
189 // index des L1 gamma //
190 //////////////////////////////////////////////////////////
191
c1147445 192 unsigned short truL1indexes[32][8];
916f1e76 193
194 // extraction from stream
195 for (Int_t index=0;index<8;index++)
196 {
197 for (Int_t tru_num=0;tru_num<16;tru_num++)
198 {
c1147445 199 truL1indexes[2*tru_num ][index] = ( word32[108+index*16+tru_num] & 0xFFFF);
200 truL1indexes[2*tru_num+1][index] = ((word32[108+index*16+tru_num]>>16) & 0xFFFF);
916f1e76 201 }
202 }
203
204 // interpretation
205 int gammacolnum;
206 short indexcopy;
207
208 for (Int_t tru_num=0;tru_num<32;tru_num++)
209 {
210 for (Int_t index=0;index<8;index++)
211 {
212 for (Int_t bit_num=0; bit_num<12; bit_num++)
213 {
c1147445 214 if ((truL1indexes[tru_num][index] & (1<<bit_num)) != 0)
916f1e76 215 {
216 if (index<4) // Even
217 {
218 gammacolnum = (2*bit_num );
219 indexcopy = index;
220 }
221 else // Odd
222 {
223 gammacolnum = (2*bit_num+1);
224 indexcopy = index-4;
225 }
226
227 fNL1GammaPatch++;
916f1e76 228
229 fL1GammaPatchIndex[fNL1GammaPatch-1] = (((indexcopy << 10) & 0xC00) | ((gammacolnum << 5) & 0x3E0) | (tru_num & 0x1F));
230 }
231 }
232 }
233 }
234
235 //////////////////////////////////////////////////////////
236 // raw output //
237 //////////////////////////////////////////////////////////
238
39c05eac 239 if ( iword <= kPayLoadSize )
240 {
241 fGetRawData = 0;
de39a0ff 242 return kTRUE;
39c05eac 243 }
244
245 fGetRawData = 1;
916f1e76 246
247 // extraction from stream
248 for (Int_t index=0;index<96;index++)
249 {
250 for (Int_t tru_num=0;tru_num<16;tru_num++)
251 {
252 fADC[2*tru_num ][index] = ( word32[236+index*16+tru_num] & 0xFFFF);
253 fADC[2*tru_num+1][index] = ((word32[236+index*16+tru_num]>>16) & 0xFFFF);
254 }
255 }
256
257 for (Int_t tru_num=16;tru_num<32;tru_num++) // A side
258 {
de39a0ff 259 Int_t v[96];
260 for (Int_t index=0;index<96;index++) v[index] = fADC[tru_num][95-index];
261
262 for (Int_t index=0;index<96;index++) fADC[tru_num][index] = v[index];
916f1e76 263 }
264
de39a0ff 265 return kTRUE;
916f1e76 266}
267
268//_____________________________________________________________________________
de39a0ff 269Bool_t AliEMCALTriggerSTURawStream::GetL0GammaPatch(const Int_t i, Int_t& tru, Int_t& idx) const
916f1e76 270{
c1147445 271 // L0 gamma patches sent to STU (original access to L0 patch indexes)
272
916f1e76 273 if (i > fNL0GammaPatch) return kFALSE;
274
275 tru = fL0GammaPatchIndex[i] & 0x1F;
de39a0ff 276 idx = (fL0GammaPatchIndex[i] & 0x7E0) >> 5;
916f1e76 277
278 return kTRUE;
279}
280
281//_____________________________________________________________________________
282Bool_t AliEMCALTriggerSTURawStream::GetL1GammaPatch(const Int_t i, Int_t& tru, Int_t& col, Int_t& row) const
283{
c1147445 284 // L1 gamma patch indexes
285
916f1e76 286 if (i > fNL1GammaPatch) return kFALSE;
287
288 tru = fL1GammaPatchIndex[i] & 0x1F;
289 col = (fL1GammaPatchIndex[i] & 0x3E0) >> 5;
290 row = (fL1GammaPatchIndex[i] & 0xC00) >> 10;
291
292 return kTRUE;
293}
294
295//_____________________________________________________________________________
296Bool_t AliEMCALTriggerSTURawStream::GetL1JetPatch(const Int_t i, Int_t& col, Int_t& row) const
297{
c1147445 298 // L1 jet patch indexes
299
916f1e76 300 if (i > fNL1JetPatch) return kFALSE;
301
302 col = fL1JetPatchIndex[i] & 0xFF;
303 row = (fL1JetPatchIndex[i] & 0xFF00) >> 8;
304
305 return kTRUE;
306}
307
308//_____________________________________________________________________________
309void AliEMCALTriggerSTURawStream::GetADC(Int_t iTRU, UInt_t ADC[])
310{
c1147445 311 // Time sums
312
916f1e76 313 for (Int_t i=0; i<96; i++) ADC[i] = fADC[iTRU][i];
314}
315
316//_____________________________________________________________________________
80e5a1ae 317void AliEMCALTriggerSTURawStream::DumpPayLoad(const Option_t *option) const
916f1e76 318{
c1147445 319 // Dump STU payload
320
916f1e76 321 TString op = option;
322
323 cout << "Jet Threshold: " << fL1JetThreshold << " Gamma threshold: " << fL1GammaThreshold << endl;
de39a0ff 324 cout << "Number of L0: " << fNL0GammaPatch << endl;
325 cout << "Number of L1-g: " << fNL1GammaPatch << endl;
326 cout << "Number of L1-j: " << fNL1JetPatch << endl;
916f1e76 327
328 Int_t itru, col, row;
916f1e76 329
330 if (op.Contains("L0") || op.Contains("ALL"))
331 {
332 for (Int_t i=0;i<fNL0GammaPatch;i++)
333 {
de39a0ff 334
335 if (GetL0GammaPatch(i,itru,col))
336 cout << "> Found L0 gamma in TRU #" << setw(2) << itru << " at idx: " << setw(2) << col << endl;
916f1e76 337 }
338 }
339
340 if (op.Contains("L1") || op.Contains("ALL"))
341 {
342 for (Int_t i=0;i<fNL1GammaPatch;i++)
343 {
de39a0ff 344 if (GetL1GammaPatch(i,itru,col,row))
345 cout << "> Found L1 gamma in TRU #" << setw(2) << itru << " at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
916f1e76 346 }
347
348 for (Int_t i=0;i<fNL1JetPatch;i++)
349 {
de39a0ff 350 if (GetL1JetPatch(i,col,row)) cout << "> Found L1 jet at: ( col: " << setw(2) << col << " , row: " << setw(2) << row << " )" << endl;
916f1e76 351 }
352 }
353
39c05eac 354 cout << "> RawData: " << fGetRawData << endl;
355
356 if ( (op.Contains("ADC") || op.Contains("ALL")) && fGetRawData )
916f1e76 357 {
358 for (Int_t i=0;i<32;i++)
359 {
360 cout << "--------\n";
361 cout << "TRU #" << setw(2) << i << ":";
362 for (Int_t j=0;j<96;j++)
363 {
364 TBits xadc(12); xadc.Set(12,&fADC[i][j]);
365 if ((j%4)==0) cout << endl;
366 //cout << setw(2) << j << ": " << xadc << " ";
367 printf("%2d: %3x / ",j,fADC[i][j]);
368 }
369 cout << "\n";
370 }
371 }
372}