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