]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDrawStreamOld.cxx
fix error in ternary operator
[u/mrichter/AliRoot.git] / TRD / AliTRDrawStreamOld.cxx
1 /**************************************************************************\r\r
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r\r
3 *                                                                        *\r\r
4 * Author: The ALICE Off-line Project.                                    *\r\r
5 * Contributors are mentioned in the code where appropriate.              *\r\r
6 *                                                                        *\r\r
7 * Permission to use, copy, modify and distribute this software and its   *\r\r
8 * documentation strictly for non-commercial purposes is hereby granted   *\r\r
9 * without fee, provided that the above copyright notice appears in all   *\r\r
10 * copies and that both the copyright notice and this permission notice   *\r\r
11 * appear in the supporting documentation. The authors make no claims     *\r\r
12 * about the suitability of this software for any purpose. It is          *\r\r
13 * provided "as is" without express or implied warranty.                  *\r\r
14 **************************************************************************/\r\r
15 \r\r
16 /* $Id: AliTRDrawStreamOld.cxx 27797 2008-08-05 14:37:22Z cblume $ */\r\r
17 \r\r
18 ///////////////////////////////////////////////////////////////////////////////\r\r
19 //                                                                           //\r\r
20 // This class provides access to TRD digits in raw data.                     //\r\r
21 //                                                                           //\r\r
22 // It loops over all TRD digits in the raw data given by the AliRawReader.   //\r\r
23 // The Next method goes to the next digit. If there are no digits left       //\r\r
24 // it returns kFALSE.                                                        //\r\r
25 // Several getters provide information about the current digit.              //\r\r
26 //                                                                           //\r\r
27 // Author: M. Ploskon (ploskon@ikf.uni-frankfurt.de)                         //\r\r
28 // Author: MinJung Kweon (minjung@physi.uni-heidelberg.de)                   //\r\r
29 //                                                                           //\r\r
30 ///////////////////////////////////////////////////////////////////////////////\r\r
31 \r\r
32 #include "TString.h"\r\r
33 #include "TFile.h"\r\r
34 //#include "TTreeStream.h"\r\r
35 \r\r
36 #include "AliTRDrawStreamOld.h"\r\r
37 #include "AliTRDgeometry.h"\r\r
38 #include "AliTRDfeeParam.h"\r\r
39 #include "AliTRDdigitsManager.h"\r\r
40 #include "AliTRDarrayDictionary.h"\r\r
41 #include "AliTRDarrayADC.h"\r\r
42 #include "AliTRDSignalIndex.h"\r\r
43 #include "AliTRDdigitsParam.h"\r\r
44 \r\r
45 //#include "AliLog.h"\r\r
46 #include "AliRawReader.h"\r\r
47 \r\r
48 #define END_OF_TRACKLET_MARKEROLD 0xaaaaaaaa\r\r
49 #define END_OF_TRACKLET_MARKERNEW 0x10001000\r\r
50 #define ENDOFRAWDATAMARKER 0x00000000\r\r
51 #define WORD_SIZE sizeof(UInt_t)             // size of a word in bytes\r\r
52 #define EXTRA_LEAD_WORDS 24\r\r
53 #define CDH_WORDS 8\r\r
54 \r\r
55 #define IS_BIT_SET(w,b) ( ((w) >> (b)) & 0x1 )     // 1 if bit b is set in word w\r\r
56 #define GET_VALUE_AT(w,m,s) (( (w) >> (s)) & (m) ) // get value of word w rshifted by s and mask with m\r\r
57 \r\r
58 // SM index word masks:\r\r
59 #define SM_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16) \r\r
60 #define TRACKLETS_ENABLED(w) IS_BIT_SET(w,5)\r\r
61 #define STACK_MASK(w) ((w) & 0x1f)\r\r
62 \r\r
63 // Stack word masks\r\r
64 #define STACK_HEADER_SIZE(w) GET_VALUE_AT(w,0xffff,16)\r\r
65 #define STACK_LINK_WORD(w) ((w) & 0xfff)\r\r
66 #define LINK0_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,4) == (0x0) ? 0 : 1)  // 0 if physics data\r\r
67 #define LINK1_DATA_TYPE_FLAG(w) (GET_VALUE_AT(w,0x3,20) == (0x0) ? 0 : 1) // 0 if physics data\r\r
68 #define LINK0_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,0) == (0x0) ? 0 : 1)    // 0 if OK\r\r
69 #define LINK1_MONITOR_FLAG(w) (GET_VALUE_AT(w,0xf,16) == (0x0) ? 0 : 1)   // 0 if OK\r\r
70 \r\r
71 // HC word masks\r\r
72 #define HC_HEADER_MASK_ERR(w) ( ((w) & (0x3)) == (0x1) ? 0 : 1) // 0 if OK\r\r
73 \r\r
74 // HC word 0\r\r
75 #define HC_SPECIAL_RAW_VERSION(w) IS_BIT_SET(w,31)\r\r
76 #define HC_MAJOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,24)\r\r
77 #define HC_MAJOR_RAW_VERSION_OPT(w) GET_VALUE_AT(w,0x7,24)\r\r
78 #define HC_MINOR_RAW_VERSION(w) GET_VALUE_AT(w,0x7f,17)\r\r
79 #define HC_EXTRA_WORDS(w) GET_VALUE_AT(w,0x7,14)\r\r
80 #define HC_DCS_BOARD(w) GET_VALUE_AT(w,0xfff<<20,20)\r\r
81 #define HC_SM_NUMBER(w) GET_VALUE_AT(w,0x1f,9)\r\r
82 #define HC_LAYER_NUMBER(w) GET_VALUE_AT(w,0x7,6)\r\r
83 #define HC_STACK_NUMBER(w) GET_VALUE_AT(w,0x7,3)\r\r
84 #define HC_SIDE_NUMBER(w) IS_BIT_SET(w,2)\r\r
85 \r\r
86 // HC word 1\r\r
87 #define HC_NTIMEBINS(w) GET_VALUE_AT(w,0x3f,26)\r\r
88 #define HC_BUNCH_CROSS_COUNTER(w) GET_VALUE_AT(w,0xffff,10)\r\r
89 #define HC_PRETRIGGER_COUNTER(w) GET_VALUE_AT(w,0xf,6)\r\r
90 #define HC_PRETRIGGER_PHASE(w) GET_VALUE_AT(w,0xf,2)\r\r
91 \r\r
92 // MCM word and ADC mask\r\r
93 #define MCM_HEADER_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1)  // 0 if OK\r\r
94 #define MCM_ADCMASK_MASK_ERR(w) ( ((w) & (0xf)) == (0xc) ? 0 : 1) // 0 if OK\r\r
95 #define MCM_MCM_NUMBER(w) GET_VALUE_AT(w,0x0f,24)\r\r
96 #define MCM_ROB_NUMBER(w) GET_VALUE_AT(w,0x7,28)\r\r
97 #define MCM_EVENT_COUNTER(w) GET_VALUE_AT(w,0x00fffff,4)\r\r
98 #define MCM_ADCMASK_VAL(w) GET_VALUE_AT(w,0x1fffff,4)\r\r
99 #define MCM_ADCMASK_NADC(w) GET_VALUE_AT(w,0x1f,25)\r\r
100 \r\r
101 #define MCM_DUMMY_ADCMASK_VAL 0x015fffffc  // updated \r\r
102 #define ADCDATA_VAL1 0x2                   // updated \r\r
103 #define ADCDATA_VAL2 0x3                   // updated \r\r
104 \r\r
105 #define ADC_WORD_MASK(w) ((w) & 0x3)\r\r
106 \r\r
107 //--------------------------------------------------------\r\r
108 ClassImp(AliTRDrawStreamOld)\r\r
109 \r\r
110 Bool_t AliTRDrawStreamOld::fgExtraSkip = kFALSE;\r\r
111 Bool_t AliTRDrawStreamOld::fgSkipCDH = kFALSE;\r\r
112 Bool_t AliTRDrawStreamOld::fgCleanDataOnly = kFALSE;\r\r
113 Bool_t AliTRDrawStreamOld::fgDebugFlag = kTRUE;\r\r
114 Bool_t AliTRDrawStreamOld::fgEnableMemoryReset = kTRUE;\r\r
115 Bool_t AliTRDrawStreamOld::fgStackNumberChecker = kTRUE;\r\r
116 Bool_t AliTRDrawStreamOld::fgStackLinkNumberChecker = kFALSE;\r\r
117 Bool_t AliTRDrawStreamOld::fgSkipData = kTRUE;\r\r
118 Bool_t AliTRDrawStreamOld::fgEnableDecodeConfigData = kFALSE;\r\r
119 Int_t AliTRDrawStreamOld::fgDumpHead = -1;\r\r
120 Int_t AliTRDrawStreamOld::fgEmptySignals[] = \r\r
121   {\r\r
122     -1, -1, -1, -1, -1,  -1, -1, -1, -1, -1,  -1, -1, -1, -1, -1\r\r
123     -1, -1, -1, -1, -1,  -1, -1, -1, -1, -1,  -1, -1, -1, -1, -1\r\r
124   };\r\r
125 Short_t AliTRDrawStreamOld::fgMCMordering[] =\r\r
126   {\r\r
127     12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3 \r\r
128   };\r\r
129 Short_t AliTRDrawStreamOld::fgROBordering[] =\r\r
130   {\r\r
131     0, 1, 2, 3\r\r
132   };\r\r
133 Int_t  AliTRDrawStreamOld::fgLastHC = -1;\r\r
134 Int_t  AliTRDrawStreamOld::fgLastROB = -1;\r\r
135 Int_t  AliTRDrawStreamOld::fgLastIndex = -1;\r\r
136 Int_t  AliTRDrawStreamOld::fgDumpingSM = -1;\r\r
137 Int_t  AliTRDrawStreamOld::fgDumpingStack = -1;\r\r
138 Int_t  AliTRDrawStreamOld::fgDumpingLayer = -1;\r\r
139 Int_t  AliTRDrawStreamOld::fgDumpingROB = -1;\r\r
140 Int_t  AliTRDrawStreamOld::fgDumpingMCM = -1;\r\r
141 Bool_t  AliTRDrawStreamOld::fgDumpingEnable = kFALSE;\r\r
142 \r\r
143 \r\r
144 AliTRDrawStreamOld::AliTRDrawStreamOld()\r\r
145   : AliTRDrawStreamBase()\r\r
146   , fSM()\r\r
147   , fStack(0)\r\r
148   , fHC(0)\r\r
149   , fLastHC(0)\r\r
150   , fMCM(0)\r\r
151   , fADC(0)\r\r
152   , fpPos(0)\r\r
153   , fpBegin(0)\r\r
154   , fpEnd(0)\r\r
155   , fWordLength(0)\r\r
156   , fStackNumber(-1)\r\r
157   , fStackLinkNumber(-1)\r\r
158   , fhcMCMcounter(0)\r\r
159   , fmcmADCcounter(0)\r\r
160   , fLinkTrackletCounter(-1)\r\r
161   , fEndOfTrackletCount(-1)\r\r
162   , fNWordsCounter(-1)\r\r
163   , fMaskADCword(0)\r\r
164   , fTbinADC(0)\r\r
165   , fDecodedADCs(-1)\r\r
166   , fEventCounter(0)\r\r
167   , fLastEventCounter(0)\r\r
168   , fSharedPadsOn(kTRUE)\r\r
169   , fMaxADCgeom(0)\r\r
170   , fBufferRead(0)\r\r
171   , fGeometry(0)\r\r
172   , fRawReader(0)\r\r
173   , fTRDfeeParam(0)\r\r
174   , fCommonAdditive(0)\r\r
175   , fWarnError(kTRUE)\r\r
176 {\r\r
177   //\r\r
178   // default constructor\r\r
179   //\r\r
180   if (Init() == kFALSE) {\r\r
181     AliWarning("Unable to Init.");    \r\r
182   }\r\r
183 }\r\r
184 \r\r
185 //--------------------------------------------------------\r\r
186 AliTRDrawStreamOld::AliTRDrawStreamOld(AliRawReader *rawReader)\r\r
187   : AliTRDrawStreamBase(rawReader)\r\r
188   , fSM()\r\r
189   , fStack(0)\r\r
190   , fHC(0)\r\r
191   , fLastHC(0)\r\r
192   , fMCM(0)\r\r
193   , fADC(0)\r\r
194   , fpPos(0)\r\r
195   , fpBegin(0)\r\r
196   , fpEnd(0)\r\r
197   , fWordLength(0)\r\r
198   , fStackNumber(-1)\r\r
199   , fStackLinkNumber(-1)\r\r
200   , fhcMCMcounter(0)\r\r
201   , fmcmADCcounter(0)\r\r
202   , fLinkTrackletCounter(-1)\r\r
203   , fEndOfTrackletCount(-1)\r\r
204   , fNWordsCounter(-1)\r\r
205   , fMaskADCword(0)\r\r
206   , fTbinADC(0)\r\r
207   , fDecodedADCs(-1)\r\r
208   , fEventCounter(0)\r\r
209   , fLastEventCounter(0)\r\r
210   , fSharedPadsOn(kTRUE)\r\r
211   , fMaxADCgeom(0)\r\r
212   , fBufferRead(0)\r\r
213   , fGeometry(0)\r\r
214   , fRawReader(rawReader)\r\r
215   , fTRDfeeParam(0)\r\r
216   , fCommonAdditive(0)\r\r
217   , fWarnError(kTRUE)\r\r
218 {\r\r
219   //\r\r
220   // default constructor\r\r
221   //\r\r
222   if (fRawReader) {\r\r
223     if (Init() == kFALSE) {\r\r
224       AliWarning("Unable to Init. Try setting up the reader with SetReader or buffer with Init(void *, UInt_t )");    \r\r
225     }\r\r
226   }\r\r
227   else {\r\r
228     AliWarning("Unable to setup reader. Use SetReader(AliRawReader*).");\r\r
229   }\r\r
230 }\r\r
231 \r\r
232 //------------------------------------------------------------\r\r
233 \r\r
234 AliTRDrawStreamOld::AliTRDrawStreamOld(const AliTRDrawStreamOld& /*st*/)\r\r
235   : AliTRDrawStreamBase()\r\r
236   , fSM()\r\r
237   , fStack(0)\r\r
238   , fHC(0)\r\r
239   , fLastHC(0)\r\r
240   , fMCM(0)\r\r
241   , fADC(0)\r\r
242   , fpPos(0)\r\r
243   , fpBegin(0)\r\r
244   , fpEnd(0)\r\r
245   , fWordLength(0)\r\r
246   , fStackNumber(-1)\r\r
247   , fStackLinkNumber(-1)\r\r
248   , fhcMCMcounter(0)\r\r
249   , fmcmADCcounter(0)\r\r
250   , fLinkTrackletCounter(-1)\r\r
251   , fEndOfTrackletCount(-1)\r\r
252   , fNWordsCounter(-1)\r\r
253   , fMaskADCword(0)\r\r
254   , fTbinADC(0)\r\r
255   , fDecodedADCs(-1)\r\r
256   , fEventCounter(0)\r\r
257   , fLastEventCounter(0)\r\r
258   , fSharedPadsOn(kTRUE)\r\r
259   , fMaxADCgeom(0)\r\r
260   , fBufferRead(0)\r\r
261   , fGeometry(0)\r\r
262   , fRawReader(0)\r\r
263   , fTRDfeeParam(0)\r\r
264   , fCommonAdditive(0)\r\r
265   , fWarnError(kTRUE)\r\r
266 {\r\r
267   //\r\r
268   // Copy constructor\r\r
269   // \r\r
270   AliError("Not implemeneted.");\r\r
271 }\r\r
272 \r\r
273 //------------------------------------------------------------\r\r
274 Bool_t AliTRDrawStreamOld::SetRawVersion(Int_t fraw)\r\r
275 {\r\r
276   //\r\r
277   // function provided for backward compatibility\r\r
278   //\r\r
279   AliWarning("Raw data version is read from raw data stream! No point of setting it in here.");\r\r
280   fraw = 0; // avoid warnings\r\r
281 \r\r
282   return kFALSE;\r\r
283 }\r\r
284 \r\r
285 //------------------------------------------------------------\r\r
286 AliTRDrawStreamOld::~AliTRDrawStreamOld()\r\r
287 {\r\r
288   //\r\r
289   // destructor\r\r
290   //\r\r
291   delete fGeometry;\r\r
292 }\r\r
293 \r\r
294 //------------------------------------------------------------\r\r
295 AliTRDrawStreamOld & AliTRDrawStreamOld::operator=(const AliTRDrawStreamOld &)\r\r
296 {\r\r
297   //\r\r
298   // we are not using this functionality\r\r
299   //\r\r
300   AliFatal("May not use.");\r\r
301 \r\r
302   return *this;\r\r
303 }\r\r
304 \r\r
305 //___________________________________________________________\r\r
306 void AliTRDrawStreamOld::SwapOnEndian()\r\r
307 {\r\r
308   //\r\r
309   // Check the endian and swap if needed\r\r
310   //\r\r
311   int itemp = 1;\r\r
312   char* ptemp = (char*) &itemp;\r\r
313   if (ptemp[0] != 1) {\r\r
314     if (fgDebugFlag) AliDebug(8, "Swapping.");\r\r
315 \r\r
316     fpPos = fpBegin;\r\r
317     UInt_t iutmp = 0;\r\r
318     while (fpPos < fpEnd) {\r\r
319       fpPos += 1;\r\r
320       iutmp = (((*fpPos & 0x000000ffU) << 24) | ((*fpPos & 0x0000ff00U) <<  8) |\r\r
321              ((*fpPos & 0x00ff0000U) >>  8) | ((*fpPos & 0xff000000U) >> 24));\r\r
322       // here we override the value in the buffer!\r\r
323       *fpPos = iutmp;   \r\r
324     }\r\r
325     fpPos = fpBegin;\r\r
326   }\r\r
327 }\r\r
328 \r\r
329 //------------------------------------------------------------\r\r
330 Bool_t AliTRDrawStreamOld::DumpWords(UInt_t *px, UInt_t iw, UInt_t marker)\r\r
331 {\r\r
332   //\r\r
333   // dump given number of words for debugging\r\r
334   //\r\r
335   TString tsreturn = Form("\n[ Dump Sequence at 0x%p ] : ", px);\r\r
336   for (UInt_t i = 0; i < iw; i++) {\r\r
337      if ( iw != 0 && px + iw > fpEnd) return kFALSE;\r\r
338 \r\r
339      if (i % 8 == 0) tsreturn += "\n                              ";\r\r
340      if (marker != 0 && marker == px[i]) tsreturn += Form(" *>0x%08x<* ", px[i]);\r\r
341      else tsreturn += Form("0x%08x ", px[i]);\r\r
342   }\r\r
343   tsreturn += "\n";\r\r
344 \r\r
345   AliInfo(tsreturn.Data());\r\r
346 \r\r
347   return kTRUE;\r\r
348 }\r\r
349 \r\r
350 //------------------------------------------------------------\r\r
351 Bool_t AliTRDrawStreamOld::SkipWords(UInt_t iw)\r\r
352 {\r\r
353   //\r\r
354   // Skip words corresponding to iw\r\r
355   //\r\r
356   if ( fpPos + iw < fpEnd ) {\r\r
357     fpPos += iw;\r\r
358     return kTRUE;\r\r
359   }\r\r
360   else {\r\r
361     if (fWarnError) AliWarning(Form("Skip %u words failed. %u available", iw, fpEnd - fpPos - 1));\r\r
362     return kFALSE;\r\r
363   }\r\r
364 \r\r
365   return kTRUE;\r\r
366 }\r\r
367 \r\r
368 //------------------------------------------------------------\r\r
369 Bool_t AliTRDrawStreamOld::SetReader(AliRawReader * reader)\r\r
370 {\r\r
371   //\r\r
372   // Set reader pointer\r\r
373   //\r\r
374   if (reader != 0) {\r\r
375     fRawReader = reader;\r\r
376     if (fRawReader) {\r\r
377       return Init();\r\r
378     }\r\r
379     else {\r\r
380       AliWarning("Unable to setup reader.");\r\r
381       return kFALSE;\r\r
382     }\r\r
383   }\r\r
384   else {\r\r
385     AliWarning("AliRawReader argument is 0.");\r\r
386     fRawReader = 0;\r\r
387   }\r\r
388 \r\r
389   return kFALSE;\r\r
390 }\r\r
391 \r\r
392 //------------------------------------------------------------\r\r
393 Int_t AliTRDrawStreamOld::NextBuffer()\r\r
394 {\r\r
395   //\r\r
396   // return -1 if no more buffers available\r\r
397   // return  0 DecodeSM failed (clean data required for example) but still maybe more data to come\r\r
398   // return  1 DecodeSM OK\r\r
399   // \r\r
400   if (fRawReader != 0) {\r\r
401     UChar_t *buffer = 0;\r\r
402     UInt_t length = 0;\r\r
403     Bool_t kBufferSet = fRawReader->ReadNextData(buffer);\r\r
404     if (kBufferSet == kTRUE) {\r\r
405       if (fgDebugFlag)  AliDebug(9, "Buffer is set.");\r\r
406       length = fRawReader->GetDataSize();\r\r
407       if (fgExtraSkip == kTRUE) {\r\r
408         buffer += EXTRA_LEAD_WORDS * WORD_SIZE;\r\r
409         length -= EXTRA_LEAD_WORDS * WORD_SIZE;\r\r
410       }\r\r
411 \r\r
412       if (fgSkipCDH == kTRUE) {\r\r
413         buffer += CDH_WORDS * WORD_SIZE;\r\r
414         length -= CDH_WORDS * WORD_SIZE;\r\r
415       }\r\r
416 \r\r
417       if (length > 0) {\r\r
418         if (fgDebugFlag)  AliDebug(9, Form("Buffer length : %d", length));\r\r
419         if (fgEnableMemoryReset) ResetMemory(); //[mj]\r\r
420         if (DecodeSM((void*)buffer, length) == kTRUE)\r\r
421           return 1;\r\r
422         else\r\r
423           return 0;\r\r
424       }\r\r
425     }\r\r
426     else {\r\r
427       return -1;\r\r
428     }\r\r
429   }\r\r
430 \r\r
431   return -1;\r\r
432 }\r\r
433 \r\r
434 //------------------------------------------------------------\r\r
435 void AliTRDrawStreamOld::ResetCounters()\r\r
436 {\r\r
437   //\r\r
438   // reset some global counters\r\r
439   //\r\r
440   fBufferRead = kFALSE; // read buffer if it is false (important to read buffer)\r\r
441 \r\r
442   fStackNumber = 0;\r\r
443   fStackLinkNumber = 0;\r\r
444   fDecodedADCs = 0;\r\r
445 \r\r
446   fSM.fActiveStacks = 0;\r\r
447   fSM.fNexpectedHalfChambers = 0;\r\r
448 \r\r
449   fLinkTrackletCounter = 0;\r\r
450   fLastEventCounter = 0;\r\r
451   fEventCounter = 0;\r\r
452 }\r\r
453 \r\r
454 //------------------------------------------------------------\r\r
455 void AliTRDrawStreamOld::ResetIterators()\r\r
456 {\r\r
457   //\r\r
458   // reset data which should be reset every sm\r\r
459   //\r\r
460   fStackNumber = 0;     // reset for Next() function \r\r
461   fStackLinkNumber = 0; // reset for Next() function\r\r
462   fhcMCMcounter = 0;  \r\r
463   fmcmADCcounter = 0;\r\r
464 }\r\r
465 \r\r
466 //------------------------------------------------------------\r\r
467 void AliTRDrawStreamOld::ResetPerSM()\r\r
468 {\r\r
469   //\r\r
470   // reset every SM\r\r
471   //\r\r
472   fSM.fHeaderSize = 0;\r\r
473   fSM.fTrackletEnable = kFALSE;\r\r
474   fSM.fCorrupted = 0;\r\r
475   fSM.fNexpectedHalfChambers = 0;\r\r
476   fSM.fNexpectedHalfChambers = 0;\r\r
477   fSM.fClean = kTRUE;\r\r
478   fSM.fPos = NULL;\r\r
479   for (Int_t i=0; i<5; i++){\r\r
480     fSM.fStackActive[i] = kFALSE;\r\r
481   }\r\r
482 }     \r\r
483 \r\r
484 //------------------------------------------------------------\r\r
485 void AliTRDrawStreamOld::ResetPerStack()\r\r
486 {\r\r
487   //\r\r
488   // reset every Stack\r\r
489   //\r\r
490   fStack->fHeaderSize = 0;\r\r
491   fStack->fActiveLinks = 0;\r\r
492   fStack->fPos = NULL;\r\r
493   for (Int_t i=0; i<12; i++){\r\r
494     fStack->fLinksActive[i] = kFALSE;\r\r
495     fStack->fLinksDataType[i] = 0;\r\r
496     fStack->fLinksMonitor[i] = 0;\r\r
497     fStack->fLinkMonitorError[i] = 0;\r\r
498   }\r\r
499 }\r\r
500 \r\r
501 //------------------------------------------------------------\r\r
502 void AliTRDrawStreamOld::ResetPerHC()\r\r
503 {\r\r
504   //\r\r
505   // reset every HC\r\r
506   //\r\r
507   fEventCounter = 0;\r\r
508   fHC->fTrackletError = 0;\r\r
509   fHC->fNTracklets = 0;\r\r
510   fHC->fSpecialRawV = 0;\r\r
511   fHC->fRawVMajor = 0;\r\r
512   fHC->fRawVMajorOpt = 0;\r\r
513   fHC->fRawVMinor = 0;\r\r
514   fHC->fNExtraWords = 0;\r\r
515   fHC->fDCSboard = 0;\r\r
516   fHC->fSM = 0;\r\r
517   fHC->fStack = 0;\r\r
518   fHC->fLayer = 0;\r\r
519   fHC->fSide = 0;\r\r
520   fHC->fTimeBins = 0;\r\r
521   fHC->fBunchCrossCounter = 0;\r\r
522   fHC->fPreTriggerCounter = 0;\r\r
523   fHC->fPreTriggerPhase = 0;\r\r
524   fHC->fDET = 0;\r\r
525   fHC->fROC = 0;\r\r
526   fHC->fRowMax = 0;\r\r
527   fHC->fColMax = 0;\r\r
528   fHC->fMCMmax = 0;\r\r
529   fHC->fH0Corrupted = 0;\r\r
530   fHC->fH1Corrupted = 0;\r\r
531   fHC->fCorrupted = 0;\r\r
532 }\r\r
533 \r\r
534 //------------------------------------------------------------\r\r
535 void AliTRDrawStreamOld::ResetPerMCM()\r\r
536 {\r\r
537   //\r\r
538   // reset every MCM \r\r
539   //\r\r
540   fMCM->fROB = 0;\r\r
541   fMCM->fMCM = 0;\r\r
542   fMCM->fROW = 0;\r\r
543   fMCM->fEvCounter = 0;\r\r
544   fMCM->fADCMask = 0;\r\r
545   fMCM->fADCMaskWord = 0;\r\r
546   fMCM->fADCmax = 0;\r\r
547   fMCM->fADCcount = 0;\r\r
548   fMCM->fSingleADCwords = 0;\r\r
549   fMCM->fMCMhdCorrupted = 0;\r\r
550   fMCM->fADCmaskCorrupted = 0;\r\r
551   fMCM->fCorrupted = 0;\r\r
552   fMCM->fPos = NULL;\r\r
553   fMCM->fAdcDataPos = NULL;\r\r
554   fMCM->fADCcounter = 0;\r\r
555 \r\r
556   memset(fMCM->fADCchannel, 0, TRDMAXADC*sizeof(UInt_t));\r\r
557 }\r\r
558 \r\r
559 //------------------------------------------------------------\r\r
560 void AliTRDrawStreamOld::ResetPerADC()\r\r
561 {\r\r
562   //\r\r
563   // reset every ADC \r\r
564   //\r\r
565   fADC->fPos = NULL;\r\r
566   fADC->fADCnumber = 0;\r\r
567   fADC->fExtendedCOL = 0;\r\r
568   fADC->fCOL = 0;\r\r
569   fADC->fIsShared = kTRUE;\r\r
570   fADC->fCorrupted = 0;\r\r
571 \r\r
572   //memset(fADC->fSignals, 0, GetNumberOfTimeBins()*sizeof(Int_t));\r\r
573   memset(fADC->fSignals, 0, TRDMAXTBINS*sizeof(Int_t)); \r\r
574 }\r\r
575 \r\r
576 //------------------------------------------------------------\r\r
577 void AliTRDrawStreamOld::ResetMemory()\r\r
578 {                 \r\r
579   //              \r\r
580   // initialize all the data members to prevent read data from memory for previous buffer \r\r
581   //              \r\r
582   ResetPerSM();\r\r
583   for (Int_t istack=0; istack<5; istack++){\r\r
584      fStack = &fSM.fStacks[istack];\r\r
585      ResetPerStack();\r\r
586      for (Int_t ilink=0; ilink<12; ilink++){\r\r
587         fHC = &fStack->fHalfChambers[ilink];\r\r
588         ResetPerHC();\r\r
589         for (Int_t imcm=0; imcm<TRDMAXMCM; imcm++){\r\r
590            fMCM = &fHC->fMCMs[imcm];\r\r
591            ResetPerMCM();\r\r
592            for (Int_t iadc=0; iadc<TRDMAXADC; iadc++){\r\r
593               fADC = &fMCM->fADCs[iadc];\r\r
594               ResetPerADC();\r\r
595            } // iadc\r\r
596         } // imcm\r\r
597      } // ilink     \r\r
598   } // istack\r\r
599 }         \r\r
600 \r\r
601 //------------------------------------------------------------\r\r
602 Bool_t AliTRDrawStreamOld::Next()\r\r
603 {\r\r
604   //\r\r
605   // returns with true on next adc read\r\r
606   // returns false on errors and end of buffer\r\r
607   // \r\r
608   if (fBufferRead) {\r\r
609     while (fStackNumber < 5 && fSM.fActiveStacks > 0) {\r\r
610       if (fSM.fStackActive[fStackNumber] == kTRUE) {\r\r
611         fStack = &fSM.fStacks[fStackNumber];\r\r
612         while (fStackLinkNumber < 12) {\r\r
613           if (fStack->fLinksActive[fStackLinkNumber] == kTRUE && fStack->fLinksMonitor[fStackLinkNumber] == 0) {\r\r
614             fHC = &fStack->fHalfChambers[fStackLinkNumber];\r\r
615             if (!fHC) {\r\r
616               AliError(Form("HC missing at stack %d link %d", fStackNumber, fStackLinkNumber));\r\r
617               return kFALSE;\r\r
618             }\r\r
619             if (fHC->fCorrupted == 0 && (fHC->fH0Corrupted == 0 && fHC->fH1Corrupted == 0) | !fgSkipData) { // if HC data corrupted(in any case), we don't read data at all from this HC \r\r
620               while (fhcMCMcounter < fHC->fMCMmax) {\r\r
621                 fMCM = &fHC->fMCMs[fhcMCMcounter];\r\r
622                 if (!fMCM) {\r\r
623                   AliError(Form("HC missing at stack %d link %d atMCMslot %d", \r\r
624                   fStackNumber, fStackLinkNumber, fhcMCMcounter));\r\r
625                   return kFALSE;\r\r
626                 }\r\r
627                 while(fmcmADCcounter < fMCM->fADCmax) {\r\r
628                   fADC = &fMCM->fADCs[fmcmADCcounter];\r\r
629                   if (!fADC) {\r\r
630                     AliError(Form("ADC missing at stack %d link %d MCMslot %d ADCslot %d", \r\r
631                             fStackNumber, fStackLinkNumber, fhcMCMcounter, fmcmADCcounter));\r\r
632                     return kFALSE;\r\r
633                   }\r\r
634                   fmcmADCcounter++;\r\r
635                   if (fSharedPadsOn) {\r\r
636                     return kTRUE;\r\r
637                   }\r\r
638                   else {\r\r
639                     if (fADC->fIsShared == kFALSE)\r\r
640                       return kTRUE;\r\r
641                   }\r\r
642                 } // while fmcmADCcounter\r\r
643                 fhcMCMcounter++;\r\r
644                 fmcmADCcounter = 0; // next MCM should go through all active ADCs - start from 0\r\r
645               } // while fhcMCMcounter\r\r
646             } // if HC OK\r\r
647           } // if link active\r\r
648           fStackLinkNumber++;\r\r
649           fhcMCMcounter = 0; // next stack link (HC) should go through all active MCMs - start from 0\r\r
650         } // while fStackLinkNumber\r\r
651       } // if stack active\r\r
652       fStackNumber++;\r\r
653       fStackLinkNumber = 0; // next stack should go through all links - start from 0\r\r
654     } // while fStackNumber\r\r
655   } // if fBufferRead\r\r
656 \r\r
657   // in case rawreader manages the mem buffers, go for the next buffer \r\r
658   if (fRawReader) {\r\r
659     Int_t nextBuff = NextBuffer();\r\r
660     while (nextBuff != -1) {\r\r
661       if (nextBuff > 0) {\r\r
662         fBufferRead = kTRUE;\r\r
663         return Next();        \r\r
664       }\r\r
665       nextBuff = NextBuffer();\r\r
666     }\r\r
667   }\r\r
668 \r\r
669   return kFALSE;\r\r
670 }\r\r
671 \r\r
672 //------------------------------------------------------------\r\r
673 Int_t AliTRDrawStreamOld::NextChamber(AliTRDdigitsManager *const digitsManager, UInt_t **trackletContainer, UShort_t **/*errorCodeContainer*/) \r\r
674 {\r\r
675   //\r\r
676   // Fills single chamber digit array \r\r
677   // Return value is the detector number\r\r
678   //\r\r
679   AliTRDarrayADC *digits = 0;\r\r
680   AliTRDarrayDictionary *track0 = 0;\r\r
681   AliTRDarrayDictionary *track1 = 0;\r\r
682   AliTRDarrayDictionary *track2 = 0; \r\r
683   AliTRDSignalIndex *indexes = 0;\r\r
684   AliTRDdigitsParam *digitsparam = 0;\r\r
685 \r\r
686   // Loop through the digits\r\r
687   Int_t lastdet = -1;\r\r
688   Int_t det     = -1;\r\r
689   Int_t lastside = -1; \r\r
690   Int_t side     = -1;\r\r
691   Int_t it = 0;\r\r
692   Int_t ntracklets = 0;\r\r
693 \r\r
694   if (trackletContainer) { \r\r
695     for (Int_t i = 0; i < 2; i++) \r\r
696       for (Int_t j = 0; j < MAXTRACKLETSPERHC; j++) \r\r
697          trackletContainer[i][j] = 0; \r\r
698   }\r\r
699 \r\r
700   while (Next()) {\r\r
701     det    = GetDet();\r\r
702     side   = GetSide();\r\r
703 \r\r
704     if (trackletContainer) {\r\r
705       if ((det + side*AliTRDgeometry::kNdet) != (lastdet + lastside*AliTRDgeometry::kNdet)) {\r\r
706         if (det != lastdet) {\r\r
707           if (lastdet != -1) {\r\r
708             fmcmADCcounter--; \r\r
709             return lastdet;\r\r
710           }\r\r
711         }\r\r
712         ntracklets = GetNTracklets();\r\r
713         if (ntracklets > 0) memcpy(trackletContainer[side], GetTrackletWords(), sizeof(UInt_t) * ntracklets); //copy tracklet words to trackletContainer array\r\r
714         lastside = side; \r\r
715       } \r\r
716     } \r\r
717 \r\r
718     if (det != lastdet) {\r\r
719       // If new detector found\r\r
720       if (lastdet == -1) {\r\r
721         lastdet = det;\r\r
722         fLastHC = fHC;\r\r
723       }\r\r
724       else {\r\r
725         fmcmADCcounter--; \r\r
726         fHC = fLastHC ;\r\r
727         return lastdet;\r\r
728       }\r\r
729 \r\r
730       if (det < 0 || det >= AliTRDgeometry::kNdet) {\r\r
731         if (fSM.fClean == kTRUE) {\r\r
732           AliError(Form("Strange Det Number %d BUT event buffer seems to be clean.", det));\r\r
733         }\r\r
734         else {\r\r
735           AliError(Form("Strange Det Number %d. Event buffer marked NOT clean!", det));\r\r
736         }\r\r
737         continue;\r\r
738       }\r\r
739 \r\r
740       // Add a container for the digits of this detector\r\r
741       digits = (AliTRDarrayADC *) digitsManager->GetDigits(det);\r\r
742 \r\r
743       if (digitsManager->UsesDictionaries()) {\r\r
744         track0 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,0);\r\r
745         track1 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,1);\r\r
746         track2 = (AliTRDarrayDictionary *) digitsManager->GetDictionary(det,2);\r\r
747       }\r\r
748 \r\r
749       if (!digits) {\r\r
750         if (fSM.fClean == kTRUE) {\r\r
751           AliError(Form("Unable to get digits for det %d BUT event buffer seems to be clean.", det));\r\r
752         }\r\r
753         else {\r\r
754           AliError(Form("Unable to get digits for det %d. Event buffer is NOT clean!", det));\r\r
755         }\r\r
756         return -1;\r\r
757       }\r\r
758 \r\r
759       //Int_t rowMax = GetRowMax();\r\r
760       Int_t rowMax = fGeometry->RowmaxC1(); // we use maximum row number among all detectors to reuse memory\r\r
761       Int_t colMax = GetColMax();\r\r
762       Int_t ntbins = GetNumberOfTimeBins();\r\r
763 \r\r
764       // Set digitparam variables\r\r
765       digitsparam = (AliTRDdigitsParam *) digitsManager->GetDigitsParam();\r\r
766       digitsparam->SetPretriggerPhase(det,GetPreTriggerPhase());\r\r
767       digitsparam->SetNTimeBins(det,ntbins);\r\r
768       fCommonAdditive=10;\r\r
769       digitsparam->SetADCbaseline(det,fCommonAdditive);\r\r
770 \r\r
771       // Allocate memory space for the digits buffer\r\r
772       //if (digits->GetNtime() == 0) {\r\r
773       if (ntbins != digits->GetNtime()) {\r\r
774         digits->Allocate(rowMax, colMax, ntbins);\r\r
775         if (digitsManager->UsesDictionaries()) {\r\r
776           track0->Allocate(rowMax, colMax, ntbins);\r\r
777           track1->Allocate(rowMax, colMax, ntbins);\r\r
778           track2->Allocate(rowMax, colMax, ntbins);\r\r
779         }\r\r
780       }\r\r
781 \r\r
782       indexes = digitsManager->GetIndexes(det);\r\r
783       indexes->SetSM(GetSM());\r\r
784       indexes->SetStack(GetStack());\r\r
785       indexes->SetLayer(GetLayer());\r\r
786       indexes->SetDetNumber(det);\r\r
787       if (indexes->GetNtime() != ntbins)\r\r
788         indexes->Allocate(rowMax, colMax, ntbins);\r\r
789     }\r\r
790 \r\r
791     // ntimebins data are ready to read\r\r
792     for (it = 0; it < GetNumberOfTimeBins(); it++) {\r\r
793        digits->SetDataByAdcCol(GetRow(), GetExtendedCol(), it, GetSignals()[it]);\r\r
794        if (!(GetCol()<0)) indexes->AddIndexRC(GetRow(), GetCol());\r\r
795        if (digitsManager->UsesDictionaries()) {\r\r
796          track0->SetData(GetRow(), GetCol(), it, 0);\r\r
797          track1->SetData(GetRow(), GetCol(), it, 0);\r\r
798          track2->SetData(GetRow(), GetCol(), it, 0);\r\r
799        }\r\r
800     } // it\r\r
801   } // while Next()\r\r
802 \r\r
803   return det;\r\r
804 }\r\r
805 \r\r
806 //------------------------------------------------------------\r\r
807 Bool_t AliTRDrawStreamOld::Init()\r\r
808 {\r\r
809   //\r\r
810   // Initialize geometry and fee parameters \r\r
811   //\r\r
812   TDirectory *saveDir = gDirectory; \r\r
813   \r\r
814   if (!fGeometry) {\r\r
815     fGeometry = new AliTRDgeometry();\r\r
816     if (!fGeometry) {\r\r
817       AliError("Geometry FAILED!");\r\r
818       return kFALSE;\r\r
819     }\r\r
820   }\r\r
821 \r\r
822   fTRDfeeParam = AliTRDfeeParam::Instance();\r\r
823   if (!fTRDfeeParam) {\r\r
824     AliError("AliTRDfeeParam FAILED!");\r\r
825     return kFALSE;\r\r
826   }\r\r
827 \r\r
828   fMaxADCgeom = (Int_t)fGeometry->ADCmax();\r\r
829 \r\r
830   ResetCounters(); // fBufferRead is set to kFALSE - important\r\r
831 \r\r
832   saveDir->cd();\r\r
833 \r\r
834   return kTRUE;\r\r
835 }\r\r
836 \r\r
837 //------------------------------------------------------------\r\r
838 Bool_t AliTRDrawStreamOld::InitBuffer(void * const buffer, UInt_t length)\r\r
839 {\r\r
840   // \r\r
841   // set initial information about the buffer\r\r
842   //\r\r
843   if (fgDebugFlag)  AliDebug(5, Form("Equipment ID: %d",fRawReader->GetEquipmentId()));\r\r
844   if (fRawReader->GetEquipmentId()<1024 || fRawReader->GetEquipmentId()>1041) // tmp protection\r\r
845     return kFALSE; \r\r
846 \r\r
847   if (WORD_SIZE == 0) {\r\r
848     AliFatal("Strange word size. size of UInt_t == 0");\r\r
849     return kFALSE;\r\r
850   }\r\r
851 \r\r
852   ResetCounters();\r\r
853 \r\r
854   fpBegin = (UInt_t *)buffer;\r\r
855   fWordLength = length/WORD_SIZE;\r\r
856   fpEnd = fpBegin + fWordLength;\r\r
857   fpPos = fpBegin;\r\r
858 \r\r
859   if (fpBegin == 0 || length <= 0) {\r\r
860     AliError(Form("Buffer size or pointer is strange. pointer to the buffer is 0x%p of size %u", fpBegin, length));\r\r
861     return kFALSE;\r\r
862   }\r\r
863 \r\r
864   SwapOnEndian();\r\r
865 \r\r
866   if (fgDumpHead >= 0) {\r\r
867     if ( fgDumpHead == 0 ) { // dump all words\r\r
868       AliInfo(Form("---------- Dumping all words from the beginnig of the buffer ----------"));\r\r
869       if (DumpWords(fpBegin, fWordLength) == kFALSE) AliError("Dump failed. Not enough data.");\r\r
870     } \r\r
871     else {\r\r
872       AliInfo(Form("---------- Dumping %u words from the beginnig of the buffer ----------",fgDumpHead));\r\r
873       if (DumpWords(fpBegin, fgDumpHead) == kFALSE) AliError("Dump failed. Not enough data.");\r\r
874     }\r\r
875     AliInfo(Form("---------- Dumping ended ----------------------------------------------"));\r\r
876   }\r\r
877 \r\r
878   return kTRUE;\r\r
879 }\r\r
880 \r\r
881 //------------------------------------------------------------\r\r
882 Bool_t AliTRDrawStreamOld::DecodeGTUheader()\r\r
883 {\r\r
884   // Decode Supermodule Index Word\r\r
885   DecodeSMInfo(fpPos, &fSM);\r\r
886 \r\r
887   if (fgDebugFlag)  AliDebug(5, DumpSMInfo(&fSM));\r\r
888 \r\r
889   fpPos++;\r\r
890   if (fpPos < fpEnd) {\r\r
891     // fSM.fHeaderSize represent additional Supermodule header size which contains additional information regarding hardware design.\r\r
892     // For the moment, we skip decoding these words \r\r
893     if (SkipWords(fSM.fHeaderSize) == kTRUE) {\r\r
894       for (Int_t istack = 0; istack < 5; istack++) {\r\r
895          if (fSM.fStackActive[istack] == kFALSE)\r\r
896            continue;\r\r
897 \r\r
898          fStack = &fSM.fStacks[istack];\r\r
899 \r\r
900          // Decode Stack Index Word of given stack\r\r
901          DecodeStackInfo(fpPos, fStack);\r\r
902          fpPos++;\r\r
903 \r\r
904          fSM.fNexpectedHalfChambers += fStack->fActiveLinks;\r\r
905         \r\r
906          if (fgDebugFlag)  AliDebug(5, DumpStackInfo(fStack));\r\r
907         \r\r
908          if (SkipWords(fStack->fHeaderSize-6) == kFALSE) { // 6 is the 6 stack header words for 12 links \r\r
909            if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack header words missing");\r\r
910            return kFALSE;\r\r
911          }\r\r
912          for (Int_t iword=0; iword<6; iword++) { // decode 6 stack header words\r\r
913             // Decode Stack Header Word of given stack\r\r
914             DecodeStackHeader(fpPos, fStack, iword); \r\r
915             fpPos++;\r\r
916          }\r\r
917       }\r\r
918     }\r\r
919     else {\r\r
920       return kFALSE;\r\r
921     }\r\r
922   }\r\r
923   else {\r\r
924     if (fWarnError) AliWarning("No additional sm headers and stack index words present.");\r\r
925     if (fRawReader) fRawReader->AddMajorErrorLog(kDecodeStackInfo, "Stack info missing");\r\r
926       return kFALSE;\r\r
927   }\r\r
928 \r\r
929   if (fpPos < fpEnd) {\r\r
930     if (fgDebugFlag)  AliDebug(5, "GTU headers are OK.");\r\r
931   }\r\r
932   else {\r\r
933     if (fWarnError) AliWarning("No data just after GTU headers.");\r\r
934     if (fRawReader) fRawReader->AddMajorErrorLog(kMissingData, "Missing sm data");\r\r
935       return kFALSE;\r\r
936   }\r\r
937 \r\r
938   if (fgDebugFlag)  AliDebug(5, Form("Expected half chambers from GTU header: %d", fSM.fNexpectedHalfChambers));\r\r
939 \r\r
940   return kTRUE;\r\r
941 }\r\r
942 \r\r
943 //------------------------------------------------------------\r\r
944 Bool_t AliTRDrawStreamOld::DecodeSM(void * const buffer, UInt_t length)\r\r
945 {\r\r
946   //\r\r
947   // decode one sm data in buffer\r\r
948   //\r\r
949   ResetIterators(); \r\r
950 \r\r
951   fSM.fClean = kTRUE;\r\r
952   if (InitBuffer(buffer, length) == kFALSE) {\r\r
953     if (fWarnError) AliError("InitBuffer failed.");      \r\r
954       fSM.fClean = kFALSE;\r\r
955       return kFALSE;\r\r
956   }\r\r
957 \r\r
958   if (DecodeGTUheader()== kFALSE)\r\r
959     return kFALSE;\r\r
960 \r\r
961   for (Int_t istack = 0; istack < 5; istack++) {\r\r
962      fStackNumber = istack; \r\r
963      if (fSM.fStackActive[istack] == kFALSE)\r\r
964        continue;\r\r
965       \r\r
966      fStack = &fSM.fStacks[istack];\r\r
967 \r\r
968      fgLastHC  = -1; // to check rob number odering \r\r
969      for (Int_t ilink = 0; ilink < 12; ilink++) {\r\r
970         fStackLinkNumber = ilink; \r\r
971         if (fStack->fLinksActive[ilink] == kFALSE)\r\r
972           continue;\r\r
973 \r\r
974         // check GTU link monitor \r\r
975         if (!(fStack->fLinksDataType[ilink] == 0 && fStack->fLinksMonitor[ilink] == 0)) {\r\r
976           fStack->fLinkMonitorError[ilink] = 1;\r\r
977           SeekEndOfData(); // skip this HC data if GTU link monitor report error\r\r
978           fStack->fLinkMonitorError[ilink] += fNWordsCounter; // counts words of given hc having link monitor error\r\r
979           continue; \r\r
980         }\r\r
981 \r\r
982         if (fpPos >= fpEnd) {\r\r
983           if (fRawReader) fRawReader->AddMajorErrorLog(kLinkDataMissing, "Link data missing");        \r\r
984           if (fWarnError) AliError("Link data missing.");      \r\r
985           fSM.fClean = kFALSE;\r\r
986           break;\r\r
987         }\r\r
988 \r\r
989         fHC = &fStack->fHalfChambers[ilink];\r\r
990         ResetPerHC();\r\r
991 \r\r
992         if (fSM.fTrackletEnable == kTRUE) {\r\r
993           if (DecodeTracklets() == kFALSE) {\r\r
994             fSM.fClean = kFALSE;\r\r
995             SeekEndOfData();\r\r
996 \r\r
997             if (fWarnError) {\r\r
998               AliError(Form("Tracklet decoding failed stack %d link %d", fStackNumber, fStackLinkNumber));\r\r
999             }\r\r
1000             continue;\r\r
1001           }\r\r
1002         }\r\r
1003 \r\r
1004         if (fpPos >= fpEnd) {\r\r
1005           if (fRawReader) fRawReader->AddMajorErrorLog(kHCdataMissing, "HC data missing");        \r\r
1006           if (fWarnError) AliError("HC data missing.");      \r\r
1007           fSM.fClean = kFALSE;\r\r
1008           break;\r\r
1009         }\r\r
1010     \r\r
1011         fgLastROB   = -1; // to check mcm number odering \r\r
1012         fgLastIndex = -1 ; // to check mcm number odering \r\r
1013         if (DecodeHC() == kFALSE) {\r\r
1014           fSM.fClean = kFALSE;\r\r
1015           if (fHC->fCorrupted < 16)  SeekEndOfData(); // In case that we meet END_OF_TRACKLET_MARKERNEW \r\r
1016                                                       // during ADC data decoding or MCM header decoding\r\r
1017                                                       // we don't seek ENDOFRAWDATAMARKER\r\r
1018           if (fWarnError) {\r\r
1019             AliError(Form("Failed HC : %s", DumpHCinfoH0(fHC)));\r\r
1020             AliError(Form("Failed HC : %s", DumpHCinfoH1(fHC)));\r\r
1021           }\r\r
1022                 \r\r
1023           continue;\r\r
1024         }\r\r
1025         else {\r\r
1026           SeekEndOfData(); // make sure that finish off with the end of data markers\r\r
1027         }\r\r
1028      } // ilink\r\r
1029   } // istack\r\r
1030 \r\r
1031   ResetIterators(); // need to do it again for Next() function \r\r
1032 \r\r
1033   if (fSM.fClean == kTRUE)\r\r
1034     return kTRUE;\r\r
1035   \r\r
1036   if (fgCleanDataOnly && (fSM.fClean == kFALSE)) {\r\r
1037     if (fWarnError) {\r\r
1038       AliWarning("Buffer with errors. Returning FALSE.");\r\r
1039       AliWarning(Form("--- Failed SM : %s ---", DumpSMInfo(&fSM)));\r\r
1040     }\r\r
1041     fSM.fActiveStacks = 0; // Next() will not give data\r\r
1042     return kFALSE;\r\r
1043   }\r\r
1044 \r\r
1045   return kTRUE;\r\r
1046 }\r\r
1047 \r\r
1048 //------------------------------------------------------------\r\r
1049 Int_t AliTRDrawStreamOld::DecodeSM()\r\r
1050 {\r\r
1051   //\r\r
1052   // decode SM data in case AliRawReader is in use\r\r
1053   //    \r\r
1054   if (fRawReader) {\r\r
1055     Int_t nextBuff = NextBuffer();\r\r
1056     while (nextBuff != -1) {\r\r
1057       if (nextBuff > 0)\r\r
1058         return nextBuff;        \r\r
1059       nextBuff = NextBuffer();\r\r
1060     }\r\r
1061     return -1;\r\r
1062   }\r\r
1063   else {\r\r
1064     AliWarning("AliRawReader not set.");\r\r
1065   }\r\r
1066 \r\r
1067   return kFALSE;\r\r
1068 }\r\r
1069 \r\r
1070 //------------------------------------------------------------\r\r
1071 Int_t AliTRDrawStreamOld::DecodeSM(AliRawReader *reader)\r\r
1072 {\r\r
1073   //\r\r
1074   // decode SM with the AliRawReader\r\r
1075   //\r\r
1076   if (reader != 0) {\r\r
1077     fRawReader = reader;\r\r
1078     return DecodeSM();\r\r
1079   }\r\r
1080   else {\r\r
1081     AliWarning("Argument AliRawReader is 0.");\r\r
1082   }\r\r
1083 \r\r
1084   return kFALSE;\r\r
1085 }\r\r
1086 \r\r
1087 //------------------------------------------------------------\r\r
1088 Bool_t AliTRDrawStreamOld::SeekEndOfData()\r\r
1089 {\r\r
1090   //\r\r
1091   // go to end of data marker\r\r
1092   //\r\r
1093   Int_t fEndOfDataCount = 0;\r\r
1094   fNWordsCounter = 0;\r\r
1095 \r\r
1096   while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r\r
1097     fpPos++;\r\r
1098     fNWordsCounter++;\r\r
1099   }\r\r
1100   while (*fpPos == ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r\r
1101     fEndOfDataCount++;\r\r
1102     fpPos++;      \r\r
1103   }\r\r
1104   \r\r
1105   return kTRUE;\r\r
1106 }\r\r
1107 \r\r
1108 //------------------------------------------------------------\r\r
1109 Bool_t AliTRDrawStreamOld::SkipMCMdata(UInt_t iw)\r\r
1110 {\r\r
1111   //\r\r
1112   // skip mcm data words due to corruption \r\r
1113   //\r\r
1114   if (fgDebugFlag) AliDebug(11,Form("Skip %d words due to MCM header corruption.",iw));\r\r
1115   UInt_t iwcounter = 0;  \r\r
1116   while ( *fpPos != ENDOFRAWDATAMARKER && iwcounter < iw) {\r\r
1117     if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {\r\r
1118       if (fgDebugFlag) AliDebug(11,"Met END_OF_TRACKLET_MARKERNEW");\r\r
1119       fMCM->fCorrupted += 16;\r\r
1120       fHC->fCorrupted += 16;\r\r
1121       return kFALSE;\r\r
1122     } \r\r
1123     fpPos++;\r\r
1124     iwcounter++; \r\r
1125   }\r\r
1126 \r\r
1127   if (iwcounter == iw) {\r\r
1128     fpPos++;\r\r
1129     return kTRUE;\r\r
1130   }\r\r
1131 \r\r
1132   if (fgDebugFlag) AliDebug(11,"Met ENDOFRAWDATAMARKER");\r\r
1133 \r\r
1134   return kFALSE;\r\r
1135 }\r\r
1136 \r\r
1137 //------------------------------------------------------------\r\r
1138 Bool_t AliTRDrawStreamOld::SeekNextMCMheader()\r\r
1139 {\r\r
1140   //\r\r
1141   // go to mcm marker\r\r
1142   //\r\r
1143   fpPos++;\r\r
1144 \r\r
1145   while ( *fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd ) {\r\r
1146     if (MCM_HEADER_MASK_ERR(*fpPos) == 0 && MCM_HEADER_MASK_ERR(*(fpPos+1)) == 0) {      \r\r
1147       if (fgDebugFlag) AliDebug(11,Form("^^^ Found : Pos 0x%p : Val 0x%08x", fpPos, *fpPos));\r\r
1148       return kTRUE;\r\r
1149     }\r\r
1150     if ( *fpPos == END_OF_TRACKLET_MARKERNEW) {\r\r
1151       fMCM->fCorrupted += 16;\r\r
1152       fHC->fCorrupted += 16;\r\r
1153       return kFALSE;\r\r
1154     } \r\r
1155     fpPos++;\r\r
1156   }\r\r
1157 \r\r
1158   SeekEndOfData();\r\r
1159 \r\r
1160   return kFALSE;\r\r
1161 }\r\r
1162 \r\r
1163 //------------------------------------------------------------\r\r
1164 Bool_t AliTRDrawStreamOld::DecodeTracklets()\r\r
1165 {\r\r
1166   //\r\r
1167   // decode tracklets\r\r
1168   //\r\r
1169   fLinkTrackletCounter = 0;\r\r
1170   fEndOfTrackletCount = 0;\r\r
1171   fHC->fNTracklets = 0;\r\r
1172 \r\r
1173   for (Int_t i = 0; i < MAXTRACKLETSPERHC; i++) \r\r
1174      fHC->fTrackletWords[i] = 0; \r\r
1175 \r\r
1176   if (fgDebugFlag)  AliDebug(10, Form("Decode tracklets at 0x%p : 0x%08x", fpPos, *fpPos));\r\r
1177 \r\r
1178   while ( *fpPos != END_OF_TRACKLET_MARKEROLD && *fpPos != END_OF_TRACKLET_MARKERNEW && fpPos < fpEnd ) {\r\r
1179     if (fgDebugFlag)  AliDebug(10, Form("Tracklet found at 0x%p : 0x%08x", fpPos, *fpPos));\r\r
1180 \r\r
1181     fLinkTrackletCounter++;\r\r
1182 \r\r
1183     if (fLinkTrackletCounter > MAXTRACKLETSPERHC) {\r\r
1184       if (fgDebugFlag) AliDebug(11,Form("Max number of tracklets exceeded %d > %d.", \r\r
1185                                         fLinkTrackletCounter, MAXTRACKLETSPERHC));\r\r
1186       if (fRawReader) fRawReader->AddMajorErrorLog(kTrackletOverflow,"Too many tracklets"); \r\r
1187       fHC->fTrackletError = 1;\r\r
1188       return kFALSE;\r\r
1189     }\r\r
1190 \r\r
1191     fHC->fTrackletWords[fLinkTrackletCounter-1] = UInt_t(*fpPos); //store tracklet words into array  \r\r
1192     fHC->fNTracklets = fLinkTrackletCounter;\r\r
1193     fpPos++;\r\r
1194   }\r\r
1195 \r\r
1196   while ( ( *fpPos == END_OF_TRACKLET_MARKEROLD || *fpPos == END_OF_TRACKLET_MARKERNEW ) && fpPos < fpEnd ) {\r\r
1197     if (fgDebugFlag)  AliDebug(10, Form("EoTracklets found at 0x%p : 0x%08x", fpPos, *fpPos));\r\r
1198 \r\r
1199     fEndOfTrackletCount++;\r\r
1200     fpPos++;\r\r
1201   }\r\r
1202 \r\r
1203   if ( fEndOfTrackletCount < 2 ) {\r\r
1204     if (fgDebugFlag) AliDebug(11,"End of tracklets word missing"); \r\r
1205     if (fRawReader) fRawReader->AddMajorErrorLog(kEOTrackeltsMissing, "End of tracklets word missing"); \r\r
1206     fHC->fTrackletError += 2;\r\r
1207     return kFALSE;\r\r
1208   }\r\r
1209 \r\r
1210   return kTRUE;\r\r
1211 }\r\r
1212 \r\r
1213 //------------------------------------------------------------\r\r
1214 Bool_t AliTRDrawStreamOld::IsRowValid()\r\r
1215 {\r\r
1216   //\r\r
1217   // check if the row number is in valid range\r\r
1218   //\r\r
1219   if ( (fHC->fStack == 2 && fMCM->fROW >= fGeometry->RowmaxC0()) ||\r\r
1220       (fHC->fStack != 2 && fMCM->fROW >= fGeometry->RowmaxC1()) || fMCM->fROW < 0 ) {\r\r
1221     if (fgDebugFlag) AliDebug(11,Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"\r\r
1222                                       , fHC->fSM, fHC->fLayer, fHC->fStack, fMCM->fROW, fMCM->fROB, fHC->fSide, fMCM->fMCM ));\r\r
1223     return kFALSE;\r\r
1224   }\r\r
1225 \r\r
1226   return kTRUE;\r\r
1227 }\r\r
1228 \r\r
1229 //------------------------------------------------------------\r\r
1230 Bool_t AliTRDrawStreamOld::IsMCMheaderOK()\r\r
1231 {\r\r
1232   //\r\r
1233   // check the mcm header\r\r
1234   //\r\r
1235   if (fgLastROB != fMCM->fROB) {\r\r
1236     fgLastIndex = 0;\r\r
1237     if (fgLastROB== -1) fgLastROB = fMCM->fROB;\r\r
1238   }\r\r
1239   else {\r\r
1240     Int_t matchingcounter = 0; \r\r
1241     for (Int_t i=fgLastIndex+1; i<16; i++) {\r\r
1242        if ( fMCM->fMCM == fgMCMordering[i] ) {\r\r
1243          fgLastIndex = i;\r\r
1244          matchingcounter++;\r\r
1245          break;\r\r
1246        }\r\r
1247     }\r\r
1248     if (matchingcounter == 0) {  \r\r
1249       fMCM->fMCMhdCorrupted += 2;\r\r
1250       AliDebug(11,Form("MCM number from last MCM is larger: MCM # from last MCM %d,  MCM # from current MCM %d \n",(fMCM-1)->fMCM, fMCM->fMCM));\r\r
1251     }\r\r
1252   }\r\r
1253 \r\r
1254   if ( fgLastHC == fHC->fLayer*2 + fHC->fSide ) {\r\r
1255     if ( fMCM->fROB < (fMCM-1)->fROB ) {\r\r
1256       fMCM->fMCMhdCorrupted += 2;\r\r
1257       AliDebug(11,Form("ROB number from last MCM is larger: ROB # from last MCM %d,  ROB # from current MCM %d \n",(fMCM-1)->fROB, fMCM->fROB));\r\r
1258     }\r\r
1259     else fgLastROB = fMCM->fROB; \r\r
1260   }\r\r
1261 \r\r
1262   fgLastHC = fHC->fLayer*2 + fHC->fSide; \r\r
1263 \r\r
1264   /*\r\r
1265   // this check will come back later again when we have "patched MCM map"\r\r
1266   int expectedROB = -1;\r\r
1267   if(!fHC->fSide) expectedROB = int(fHC->fMCMmax/16)*2;\r\r
1268   else expectedROB = int(fHC->fMCMmax/16)*2 + 1;\r\r
1269   int expectedMCM = 4*(3-int((fHC->fMCMmax%16)/4)) + fHC->fMCMmax%4;\r\r
1270 \r\r
1271   if ( expectedROB != fMCM->fROB || expectedMCM != fMCM->fMCM)\r\r
1272     {\r\r
1273       fMCM->fMCMhdCorrupted += 2;\r\r
1274       AliDebug(11,Form("ROB expected %d ROB read %d,  MCM expected %d MCM read %d\n",expectedROB, fMCM->fROB, expectedMCM, fMCM->fMCM));\r\r
1275     }\r\r
1276   */\r\r
1277 \r\r
1278   // below two conditions are redundant  \r\r
1279   /*\r\r
1280   if ( fMCM->fMCM < 0 || fMCM->fMCM > 15 || fMCM->fROB < 0 || fMCM->fROB > 7 ) \r\r
1281     {\r\r
1282       fMCM->fMCMhdCorrupted += 8;  // need to assign new number\r\r
1283       if (fgDebugFlag) AliDebug(11,Form("ROB or MCM number is out of range. %s\n", DumpMCMinfo(fMCM)));\r\r
1284     }\r\r
1285   if (IsRowValid() == kFALSE)\r\r
1286     {\r\r
1287       fMCM->fMCMhdCorrupted += 16; // need to assign new number\r\r
1288     }\r\r
1289   */  \r\r
1290     \r\r
1291   if (fEventCounter == 0) {\r\r
1292     fEventCounter = fMCM->fEvCounter;\r\r
1293   }\r\r
1294 \r\r
1295   if (fEventCounter != fMCM->fEvCounter) {\r\r
1296     fMCM->fMCMhdCorrupted += 4;      \r\r
1297     if (fgDebugFlag) AliDebug(11,Form("Event number(%d) of current MCM is different from that(%d) of reference MCM %s.\n"\r\r
1298                                       , fMCM->fEvCounter, fEventCounter, DumpMCMinfo(fMCM)));\r\r
1299   }\r\r
1300 \r\r
1301   if (fEventCounter < fLastEventCounter) {\r\r
1302     fMCM->fMCMhdCorrupted += 8;      \r\r
1303     if (fgDebugFlag) AliDebug(11,Form("Event from the past? Current %d Last %d %s.\n", fEventCounter, fLastEventCounter, DumpMCMinfo(fMCM)));\r\r
1304   }\r\r
1305 \r\r
1306   if ( fMCM->fADCmaskCorrupted > 0 ) {\r\r
1307     return kFALSE;\r\r
1308   }\r\r
1309 \r\r
1310   if ( fMCM->fMCMhdCorrupted > 0 ) {\r\r
1311     return kFALSE;\r\r
1312   }\r\r
1313 \r\r
1314   return kTRUE;\r\r
1315 }\r\r
1316 \r\r
1317 //------------------------------------------------------------\r\r
1318 Bool_t AliTRDrawStreamOld::DecodeMCMheader()\r\r
1319 {\r\r
1320   //\r\r
1321   // decode the mcm header\r\r
1322   //\r\r
1323   DecodeMCMheader(fpPos, fMCM); \r\r
1324 \r\r
1325   if (fgDumpingEnable) { \r\r
1326     if (fMCM->fMCM == fgDumpingMCM) {\r\r
1327       if (fMCM->fROB == fgDumpingROB && fHC->fLayer == fgDumpingLayer) {\r\r
1328         if (fHC->fSM == fgDumpingSM && fHC->fStack == fgDumpingStack) {\r\r
1329           if (fgDebugFlag) {\r\r
1330             AliDebug(5,DumpHCinfoH0(fHC));\r\r
1331             AliDebug(5,DumpMCMinfo(fMCM));\r\r
1332           }\r\r
1333           DumpWords(fpPos, 212);\r\r
1334         }  \r\r
1335       }\r\r
1336     }\r\r
1337   }\r\r
1338 \r\r
1339   if (fHC->fCorrupted >= 16) {\r\r
1340     fpPos--; \r\r
1341     return kFALSE;\r\r
1342   }\r\r
1343   fMCM->fROW = fTRDfeeParam->GetPadRowFromMCM(fMCM->fROB, fMCM->fMCM); \r\r
1344 \r\r
1345   if ((fHC->fRawVMajor > 2 && fHC->fRawVMajor <5) || ((fHC->fRawVMajor & 32) == 32)) { //cover old and new version definition of ZS data\r\r
1346     fpPos++;\r\r
1347     if ( fpPos < fpEnd ) {\r\r
1348       DecodeMask(fpPos, fMCM); \r\r
1349       if (fHC->fCorrupted >= 16) {\r\r
1350         fpPos--; \r\r
1351         return kFALSE;\r\r
1352       }\r\r
1353       MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);\r\r
1354       fMCM->fAdcDataPos = fpPos + 1;\r\r
1355     }\r\r
1356     else {\r\r
1357       if (fgDebugFlag) AliDebug(11,"Expected ADC mask word. Fail due to buffer END.");    \r\r
1358       if (fRawReader) fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing"); \r\r
1359       fHC->fCorrupted += 32;\r\r
1360       return kFALSE;\r\r
1361     }\r\r
1362   }\r\r
1363   else {\r\r
1364     UInt_t dummyMask = MCM_DUMMY_ADCMASK_VAL;\r\r
1365     DecodeMask(&dummyMask, fMCM); \r\r
1366     MCMADCwordsWithTbins(fHC->fTimeBins, fMCM);\r\r
1367     fMCM->fAdcDataPos = fpPos + 1;\r\r
1368   }\r\r
1369 \r\r
1370   if (fgDebugFlag) { \r\r
1371     AliDebug(6, DumpMCMinfo(fMCM));\r\r
1372     AliDebug(7, DumpMCMadcMask(fMCM));\r\r
1373   }\r\r
1374 \r\r
1375   if (IsMCMheaderOK() == kFALSE) {\r\r
1376     return kFALSE;\r\r
1377   }    \r\r
1378 \r\r
1379   return kTRUE;\r\r
1380 }\r\r
1381 \r\r
1382 //------------------------------------------------------------\r\r
1383 Bool_t AliTRDrawStreamOld::IsHCheaderOK()\r\r
1384 {\r\r
1385   //\r\r
1386   // check insanity of half chamber header\r\r
1387   //\r\r
1388   if (fHC->fStack < 0 || fHC->fStack > 4) {\r\r
1389     if (fgDebugFlag) AliDebug(11,Form("Wrong Stack %d", fHC->fStack));\r\r
1390       return kFALSE;\r\r
1391   }\r\r
1392 \r\r
1393   if (fHC->fLayer < 0 || fHC->fLayer >= AliTRDgeometry::kNlayer) {\r\r
1394     if (fgDebugFlag) AliDebug(11,Form("Wrong layer %d", fHC->fLayer));\r\r
1395       return kFALSE;\r\r
1396   }\r\r
1397 \r\r
1398   if (fHC->fSide < 0 || fHC->fSide > 1) {\r\r
1399     if (fgDebugFlag) AliDebug(11,Form("Wrong Side %d", fHC->fSide));\r\r
1400       return kFALSE;\r\r
1401   }\r\r
1402 \r\r
1403   if (fgStackNumberChecker) {\r\r
1404     if (fHC->fStack != fStackNumber) {\r\r
1405       if (fgDebugFlag) AliDebug(11,Form("Missmatch: Stack number between HC header %d and GTU link mask %d", \r\r
1406                                         fHC->fStack, fStackNumber));\r\r
1407       fStackNumber = -1;\r\r
1408       return kFALSE;\r\r
1409     }\r\r
1410   }\r\r
1411 \r\r
1412   if (fgStackLinkNumberChecker) {\r\r
1413     if (fHC->fLayer * 2 + fHC->fSide != fStackLinkNumber) {\r\r
1414     // let it make flexible to consider known fiber swapping\r\r
1415     //if ((fHC->fLayer * 2 != fStackLinkNumber) && (fHC->fLayer * 2 != fStackLinkNumber - 1)) { \r\r
1416       if (fgDebugFlag) AliDebug(11,Form("Missmatch: Layer number between HC header %d and GTU link mask %d | %s", \r\r
1417                                         fHC->fLayer, fStackLinkNumber, DumpStackInfo(fStack)));\r\r
1418       fStackLinkNumber = -1;\r\r
1419       return kFALSE;      \r\r
1420     }\r\r
1421   }\r\r
1422 \r\r
1423   // SLOW GEOM : consistancy check with geometry\r\r
1424   fHC->fDET = fGeometry->GetDetector(fHC->fLayer, fHC->fStack, fHC->fSM);\r\r
1425   if (fHC->fDET < 0 || fHC->fDET >= AliTRDgeometry::kNdet) {\r\r
1426     if (fgDebugFlag) AliDebug(11,Form("Wrong detector %d", fHC->fDET));      \r\r
1427     if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongDet, "Wrong Det");       \r\r
1428     return kFALSE;\r\r
1429   }\r\r
1430 \r\r
1431   if (fHC->fSM != fGeometry->GetSector(fHC->fDET) || fHC->fSM <0 || fHC->fSM >= AliTRDgeometry::kNsector) {\r\r
1432     if (fgDebugFlag) AliDebug(11,Form("Wrong SM(sector) %d (Geometry says: %d) Stack=%d Layer=%d Det=%d", \r\r
1433                                       fHC->fSM, fGeometry->GetSector(fHC->fDET), fHC->fStack, fHC->fLayer, fHC->fDET));\r\r
1434     if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongSM, "Wrong SM");       \r\r
1435     return kFALSE;\r\r
1436   }\r\r
1437 \r\r
1438   fHC->fROC    = fGeometry->GetDetectorSec(fHC->fLayer, fHC->fStack);\r\r
1439   if (fHC->fROC < 0) {\r\r
1440     if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC");       \r\r
1441     return kFALSE;\r\r
1442   }\r\r
1443 \r\r
1444   fHC->fRowMax = fGeometry->GetRowMax(fHC->fLayer, fHC->fStack, fHC->fSM);\r\r
1445   if (fHC->fRowMax < 1) {\r\r
1446     if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Row Max");       \r\r
1447     return kFALSE;\r\r
1448   }\r\r
1449 \r\r
1450   fHC->fColMax = fGeometry->GetColMax(fHC->fROC);\r\r
1451   if (fHC->fColMax < 1) {\r\r
1452     if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderWrongROC, "Wrong ROC Col Max");       \r\r
1453     return kFALSE;\r\r
1454   }\r\r
1455   \r\r
1456   return kTRUE;\r\r
1457 }\r\r
1458 \r\r
1459 //------------------------------------------------------------\r\r
1460 Bool_t AliTRDrawStreamOld::DecodeHCheader()\r\r
1461 {  \r\r
1462   //\r\r
1463   // decode the half chamber header\r\r
1464   //\r\r
1465   if (DecodeHCwordH0(fpPos, fHC) == kFALSE)\r\r
1466     return kFALSE;\r\r
1467     \r\r
1468   if (fHC->fNExtraWords > 0) {\r\r
1469     fpPos++;\r\r
1470     if (fpPos < fpEnd) {\r\r
1471       if (DecodeHCwordH1(fpPos, fHC) == kFALSE)\r\r
1472         return kFALSE;\r\r
1473     }\r\r
1474     else {\r\r
1475       if (fgDebugFlag) AliDebug(11,"Expected HC header word 1. Fail due to buffer END.");\r\r
1476       if (fRawReader) fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word 1 (count from 0) missing"); \r\r
1477       return kFALSE;\r\r
1478     }\r\r
1479   }\r\r
1480 \r\r
1481   if (fgDebugFlag)  AliDebug(5, DumpHCinfoH0(fHC));\r\r
1482   if (fgDebugFlag)  AliDebug(5, DumpHCinfoH1(fHC));\r\r
1483 \r\r
1484   fHC->fDET = -1;\r\r
1485   if (IsHCheaderOK() == kFALSE) {\r\r
1486     fHC->fH0Corrupted += 2;\r\r
1487     if (fgDebugFlag) AliDebug(11,Form("H0 Header Insane. Word 0x%p", *fHC->fPos));\r\r
1488       return kFALSE;\r\r
1489   }\r\r
1490   \r\r
1491   return kTRUE;\r\r
1492 }\r\r
1493 \r\r
1494 //------------------------------------------------------------\r\r
1495 Bool_t AliTRDrawStreamOld::DecodeHC()\r\r
1496 {\r\r
1497   //\r\r
1498   // decode hc header and data\r\r
1499   //\r\r
1500 \r\r
1501   if (DecodeHCheader() == kFALSE) {\r\r
1502     if (fWarnError) AliWarning(Form("HC Header decode failed. H0 Error: %d H1 Error: %d",fHC->fH0Corrupted,fHC->fH1Corrupted));\r\r
1503     if (fRawReader) fRawReader->AddMajorErrorLog(kHCHeaderCorrupt, "HC header corrupted"); \r\r
1504     return kFALSE;\r\r
1505   }\r\r
1506   else {\r\r
1507     fpPos++;\r\r
1508     if (fpPos >= fpEnd) {\r\r
1509       fHC->fCorrupted += 1;\r\r
1510       if (fgDebugFlag) AliDebug(11,"No MCM data? Not enough data in the buffer.");\r\r
1511       if (fRawReader) fRawReader->AddMajorErrorLog(kMCMdataMissing, "MCM data missing"); \r\r
1512       return kFALSE;\r\r
1513     }\r\r
1514   }\r\r
1515 \r\r
1516 //   if ((fHC->fRawVMajor & 64) == 64) { // test pattern data\r\r
1517 //     AliTRDrawTPStream *tpStream = new AliTRDrawTPStream(fHC->fRawVMajorOpt, fpPos);\r\r
1518 //     if (tpStream->DecodeTPdata() == kFALSE) {\r\r
1519 //       if (fWarnError) AliError("failed to decode test pattern data");\r\r
1520 //         return kFALSE; \r\r
1521 //     }\r\r
1522 //     return kTRUE;\r\r
1523 //   } \r\r
1524 \r\r
1525   fHC->fMCMmax = 0;\r\r
1526   while (*fpPos != ENDOFRAWDATAMARKER && fpPos < fpEnd) {\r\r
1527     if (fHC->fMCMmax > TRDMAXMCM) {\r\r
1528       fHC->fCorrupted += 2;\r\r
1529       if (fgDebugFlag) AliDebug(11,"More mcm data than expected!");\r\r
1530       if (fRawReader) fRawReader->AddMajorErrorLog(kMCMoverflow, "Too many mcms found!"); \r\r
1531       return kFALSE;\r\r
1532     }\r\r
1533 \r\r
1534     fMCM = &fHC->fMCMs[fHC->fMCMmax];\r\r
1535 \r\r
1536     if (DecodeMCMheader() == kFALSE) {\r\r
1537       if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r\r
1538     \r\r
1539       if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) { // stop HC data reading\r\r
1540         fHC->fMCMmax++;\r\r
1541         return kFALSE;\r\r
1542       } \r\r
1543           \r\r
1544       fHC->fMCMmax++; // increase mcm counter to match with expected rob/mcm number\r\r
1545 \r\r
1546       // in case we decide to keep reading data, skip this mcm data and find next mcm header \r\r
1547       if (fMCM->fADCmaskCorrupted < 2) {\r\r
1548         if (SkipMCMdata(fMCM->fADCcount*fMCM->fSingleADCwords) == kFALSE)\r\r
1549           return kFALSE;\r\r
1550         continue;\r\r
1551       }\r\r
1552       else {\r\r
1553         if (SeekNextMCMheader() == kFALSE)\r\r
1554           return kFALSE;\r\r
1555         continue;\r\r
1556       }\r\r
1557     }\r\r
1558 \r\r
1559     fHC->fMCMmax++;\r\r
1560 \r\r
1561     if (fMCM->fADCmax > 0) {\r\r
1562       fpPos++;\r\r
1563       if (fpPos >= fpEnd) {\r\r
1564         fMCM->fCorrupted += 1;\r\r
1565         if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r\r
1566         if (fgDebugFlag)  AliDebug(9, Form("Buffer short of data. ADC data expected."));    \r\r
1567         return kFALSE;\r\r
1568       }\r\r
1569 \r\r
1570       for (Int_t iadc = 0; iadc < fMCM->fADCmax; iadc++) {\r\r
1571          fADC = &fMCM->fADCs[iadc];\r\r
1572          fADC->fADCnumber = fMCM->fADCchannel[iadc];\r\r
1573          if (fgDebugFlag)  AliDebug(9, Form("This is ADC %d of %d. ADC number is %d.", \r\r
1574                                             iadc+1, fMCM->fADCmax, fMCM->fADCchannel[iadc]));\r\r
1575          if (fpPos + fMCM->fSingleADCwords >= fpEnd) {\r\r
1576            fMCM->fCorrupted += 2;\r\r
1577            if (fHC->fCorrupted < 4) fHC->fCorrupted += 4; // benchmark hc data corruption as 4\r\r
1578            if (fgDebugFlag) AliDebug(11,"ADC (10 words) expected. Not enough data in the buffer.");\r\r
1579            return kFALSE;\r\r
1580          }\r\r
1581 \r\r
1582          if (fHC->fRawVMajor < 64) { // normal(real) ADC data\r\r
1583            if (fHC->fTimeBins < 31) {\r\r
1584              if (DecodeADC() == kFALSE) {\r\r
1585                if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4\r\r
1586                if (fHC->fCorrupted < 4) fHC->fCorrupted += 4;   // benchmark hc data corruption as 4\r\r
1587                if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared\r\r
1588                  fADC->fExtendedCOL = -1;\r\r
1589                  fADC->fCOL = -1;\r\r
1590                  fpPos = fADC->fPos + fMCM->fSingleADCwords;\r\r
1591                }\r\r
1592                else {\r\r
1593                  if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));\r\r
1594                  if (fgSkipData == kTRUE || fHC->fCorrupted >= 16) \r\r
1595                    return kFALSE; // stop HC data reading\r\r
1596                }\r\r
1597              }\r\r
1598            }\r\r
1599            else if (fHC->fTimeBins > 32) {\r\r
1600              if (DecodeADCExtended() == kFALSE) { // decoding TRAP data with ZS and more than 32 samples\r\r
1601                if (fMCM->fCorrupted < 4) fMCM->fCorrupted += 4; // benchmark mcm data corruption as 4\r\r
1602                if (fHC->fCorrupted < 4) fHC->fCorrupted += 4;   // benchmark hc data corruption as 4\r\r
1603                if (fADC->fIsShared && fADC->fCorrupted == 32) { // check if we are out of the det when the pad is shared\r\r
1604                  fADC->fExtendedCOL = -1;\r\r
1605                  fADC->fCOL = -1;\r\r
1606                  fpPos = fADC->fPos + fMCM->fSingleADCwords;\r\r
1607                }\r\r
1608                else {\r\r
1609                  if (fgDebugFlag) AliDebug(11,Form("ADC decode failed."));\r\r
1610                  if (fgSkipData == kTRUE || fHC->fCorrupted >= 16)\r\r
1611                    return kFALSE; // stop HC data reading\r\r
1612                }\r\r
1613              }\r\r
1614            }\r\r
1615            else { // nsamples = 31, 32 are not implemented in the TRAP and should never happen  \r\r
1616              if (fWarnError) AliError("nsamples are 31 or 32. These are not implemented in the TRAP and should never happen!"); \r\r
1617            }\r\r
1618          } // if fHC->fRawVMajor\r\r
1619          else { // test pattern data\r\r
1620            if (fWarnError) AliError("These are test pattern data. You need other reader"); // will be served in other class\r\r
1621          }\r\r
1622       } // for iadc \r\r
1623     } // if fMCM->fADCmax\r\r
1624     else {\r\r
1625       fpPos++;\r\r
1626     }\r\r
1627   }//while eof data\r\r
1628 \r\r
1629   if (fpPos >= fpEnd) {\r\r
1630     if (fgDebugFlag) AliDebug(11,"We are at the end of buffer. There should be one more word left.");\r\r
1631     return kFALSE;\r\r
1632   }\r\r
1633 \r\r
1634   return kTRUE;\r\r
1635 }\r\r
1636 \r\r
1637 //------------------------------------------------------------\r\r
1638 Bool_t AliTRDrawStreamOld::DecodeADC()\r\r
1639 {\r\r
1640   //\r\r
1641   // decode single ADC channel\r\r
1642   //\r\r
1643 \r\r
1644   fADC->fCorrupted = 0;\r\r
1645   if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);\r\r
1646   if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);\r\r
1647 \r\r
1648   fADC->fPos = fpPos;\r\r
1649   fTbinADC = 0;\r\r
1650 \r\r
1651   for (Int_t i = 0; i < GetNumberOfTimeBins(); i++)\r\r
1652   //for (Int_t i = 0; i < TRDMAXTBINS; i++)\r\r
1653     fADC->fSignals[i] = 0;\r\r
1654 \r\r
1655   for (Int_t iw = 0; iw < fMCM->fSingleADCwords; iw++) {\r\r
1656      if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {\r\r
1657        if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));\r\r
1658        fADC->fCorrupted += 16;\r\r
1659        fHC->fCorrupted += 16; \r\r
1660        fpPos--;\r\r
1661        return kFALSE;\r\r
1662      }\r\r
1663      if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {\r\r
1664        fADC->fCorrupted += 1;\r\r
1665        if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x  Current mask: 0x%08x] MCM= %s Error : %d",\r\r
1666                                          fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));\r\r
1667        fpPos++;\r\r
1668        continue;\r\r
1669      }\r\r
1670 \r\r
1671      fADC->fSignals[fTbinADC + 0] = ((*fpPos & 0x00000ffc) >>  2);\r\r
1672      fADC->fSignals[fTbinADC + 1] = ((*fpPos & 0x003ff000) >> 12);\r\r
1673      fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0xffc00000) >> 22);\r\r
1674 \r\r
1675      fTbinADC += 3;\r\r
1676      fpPos++;\r\r
1677   } // iw\r\r
1678 \r\r
1679   if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {\r\r
1680     fADC->fIsShared = kTRUE;\r\r
1681   }\r\r
1682   else {\r\r
1683     fADC->fIsShared = kFALSE;\r\r
1684   }\r\r
1685 \r\r
1686     fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r\r
1687     fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r\r
1688 \r\r
1689   if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {\r\r
1690     if (fADC->fIsShared == kFALSE) {\r\r
1691       fADC->fCorrupted += 32;\r\r
1692       if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", \r\r
1693                                         fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));\r\r
1694     }\r\r
1695     //else {\r\r
1696     // we are out of the det when the pad is shared\r\r
1697     //if (fgDebugFlag) AliDebug(11, Form("Column out of the detector! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", \r\r
1698     //             fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));\r\r
1699     //fADC->fCorrupted += 32;\r\r
1700     //}\r\r
1701   }\r\r
1702 \r\r
1703   if (fADC->fCorrupted > 0) {\r\r
1704     return kFALSE;\r\r
1705   }\r\r
1706 \r\r
1707   fDecodedADCs++;\r\r
1708 \r\r
1709   return kTRUE;\r\r
1710 }\r\r
1711 \r\r
1712 //------------------------------------------------------------\r\r
1713 Bool_t AliTRDrawStreamOld::DecodeADCExtended()\r\r
1714 {\r\r
1715   //\r\r
1716   // decode single ADC channel\r\r
1717   //\r\r
1718 \r\r
1719   fADC->fCorrupted = 0;\r\r
1720   if(fADC->fADCnumber%2==1) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL1);\r\r
1721   if(fADC->fADCnumber%2==0) fMaskADCword = ADC_WORD_MASK(ADCDATA_VAL2);\r\r
1722 \r\r
1723   fADC->fPos = fpPos;\r\r
1724 \r\r
1725   fTbinADC = ((*fpPos & 0x000000fc) >>  2);\r\r
1726   fMCM->fSingleADCwords  = ((*fpPos & 0x00000f00) >>  8);\r\r
1727   fADC->fSignals[fTbinADC] = ((*fpPos & 0x003ff000) >> 12);\r\r
1728   fADC->fSignals[fTbinADC+1] = ((*fpPos & 0xffc00000) >> 22);\r\r
1729 \r\r
1730   fpPos++; \r\r
1731   for (Int_t iw = 0; iw < fMCM->fSingleADCwords-1; iw++) { // it goes up to fMCM->fSingleADCwords-1 since the first word was already decoded above\r\r
1732      if (HC_HEADER_MASK_ERR(*fpPos) == 0 || *fpPos == END_OF_TRACKLET_MARKERNEW) {\r\r
1733        if (fWarnError) AliError(Form("There should be ADC data. We meet HC header or END_OF_TRACKLET_MARKER 0x%08x",*fpPos));\r\r
1734        fADC->fCorrupted += 16;\r\r
1735        fHC->fCorrupted += 16; \r\r
1736        fpPos--;\r\r
1737        return kFALSE;\r\r
1738      }\r\r
1739      if (fMaskADCword != ADC_WORD_MASK(*fpPos)) {\r\r
1740        fADC->fCorrupted += 1;\r\r
1741        if (fgDebugFlag) AliDebug(11,Form("Wrong ADC data mask! ADC channel number: %02d [Expected mask: 0x%08x  Current mask: 0x%08x] MCM= %s Error : %d",\r\r
1742                                          fADC->fADCnumber, fMaskADCword, ADC_WORD_MASK(*fpPos),DumpMCMinfo(fMCM),fADC->fCorrupted));\r\r
1743        fpPos++;\r\r
1744        continue;\r\r
1745      }\r\r
1746 \r\r
1747      fADC->fSignals[fTbinADC + 2] = ((*fpPos & 0x00000ffc) >>  2);\r\r
1748      fADC->fSignals[fTbinADC + 3] = ((*fpPos & 0x003ff000) >> 12);\r\r
1749      fADC->fSignals[fTbinADC + 4] = ((*fpPos & 0xffc00000) >> 22);\r\r
1750 \r\r
1751      fTbinADC += 3;\r\r
1752      fpPos++;\r\r
1753   } // iw\r\r
1754 \r\r
1755 //  for(int i=0; i )\r\r
1756 //  printf();\r\r
1757 \r\r
1758 \r\r
1759   if (fADC->fADCnumber <= 1 || fADC->fADCnumber == fMaxADCgeom - 1) {\r\r
1760     fADC->fIsShared = kTRUE;\r\r
1761   }\r\r
1762   else {\r\r
1763     fADC->fIsShared = kFALSE;\r\r
1764   }\r\r
1765 \r\r
1766   fADC->fExtendedCOL = fTRDfeeParam->GetExtendedPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r\r
1767     fADC->fCOL = fTRDfeeParam->GetPadColFromADC(fMCM->fROB, fMCM->fMCM, fADC->fADCnumber);\r\r
1768 \r\r
1769   if (fADC->fCOL >= fHC->fColMax || fADC->fCOL < 0) {\r\r
1770     if (fADC->fIsShared == kFALSE) {\r\r
1771       fADC->fCorrupted += 32;\r\r
1772       if (fgDebugFlag) AliDebug(11,Form("Wrong column! ADCnumber %d MaxIs %d Col %d MaxIs %d MCM= %s", \r\r
1773                                         fADC->fADCnumber, fMaxADCgeom, fADC->fCOL, fHC->fColMax, DumpMCMinfo(fMCM)));\r\r
1774     }\r\r
1775   }\r\r
1776 \r\r
1777   if (fADC->fCorrupted > 0) {\r\r
1778     return kFALSE;\r\r
1779   }\r\r
1780 \r\r
1781   fDecodedADCs++;\r\r
1782 \r\r
1783   return kTRUE;\r\r
1784 }\r\r
1785 \r\r
1786 //--------------------------------------------------------\r\r
1787 void AliTRDrawStreamOld::DecodeSMInfo(const UInt_t *word, struct AliTRDrawSM *sm) const\r\r
1788 {\r\r
1789   //\r\r
1790   // Decode Supermodule Index Word\r\r
1791   // The Supermodule Index Word is a 32-Bit word wit following structure\r\r
1792   // ssssssss ssssssss vvvv rrrr r d t mmmm\r\r
1793   // s: Size of the Supermodule Header, v: Supermodule Header Version, r: Reserved for future use\r\r
1794   // d: Track Data Enabled Bit, t: Tracklet Data Enabled Bit, m: Stack Mask \r\r
1795   //\r\r
1796   sm->fPos = (UInt_t*)word; \r\r
1797 \r\r
1798   UInt_t vword = *word;\r\r
1799   sm->fHeaderSize = SM_HEADER_SIZE(vword);\r\r
1800     \r\r
1801   if (TRACKLETS_ENABLED(vword) > 0)\r\r
1802     sm->fTrackletEnable = kTRUE;\r\r
1803   else\r\r
1804     sm->fTrackletEnable = kFALSE;\r\r
1805     \r\r
1806   UInt_t stackMask = STACK_MASK(vword);\r\r
1807   sm->fActiveStacks = 0;\r\r
1808   for (Int_t i = 0; i < 5; i++) {\r\r
1809      if (IS_BIT_SET(stackMask,i) > 0) {\r\r
1810        sm->fStackActive[i] = kTRUE;\r\r
1811        sm->fActiveStacks++;\r\r
1812      }\r\r
1813      else {\r\r
1814        sm->fStackActive[i] = kFALSE;\r\r
1815      }\r\r
1816   }\r\r
1817 }\r\r
1818 \r\r
1819 //--------------------------------------------------------\r\r
1820 const char *AliTRDrawStreamOld::DumpSMInfo(const struct AliTRDrawSM *sm)\r\r
1821 {\r\r
1822   //\r\r
1823   // Get SM structure into a const char\r\r
1824   //\r\r
1825   return Form("[ SM Info 0x%08x] : Hsize %d TrackletEnable %d Stacks %d %d %d %d %d",\r\r
1826               *sm->fPos, sm->fHeaderSize, sm->fTrackletEnable,\r\r
1827               sm->fStackActive[0], sm->fStackActive[1], sm->fStackActive[2],\r\r
1828               sm->fStackActive[3], sm->fStackActive[4]);      \r\r
1829 }\r\r
1830 \r\r
1831 //--------------------------------------------------------\r\r
1832 void AliTRDrawStreamOld::DecodeStackInfo(const UInt_t *word, struct AliTRDrawStack *st) const\r\r
1833 {\r\r
1834   //\r\r
1835   // Decode Stack #i Index Word\r\r
1836   // The Stack #i Index Word is a 32-Bit word wit following structure\r\r
1837   // ssssssss ssssssss vvvv mmmm mmmmmmmm\r\r
1838   // s: Size of the Stack #i Header, v: Supermodule Header Version, m: Link Mask\r\r
1839   //\r\r
1840   st->fPos = (UInt_t*)word;\r\r
1841       \r\r
1842   UInt_t vword = *word;\r\r
1843   st->fHeaderSize = STACK_HEADER_SIZE(vword);\r\r
1844 \r\r
1845   UInt_t linkMask = STACK_LINK_WORD(vword);\r\r
1846   st->fActiveLinks = 0;\r\r
1847   for (Int_t i = 0; i < 12; i++) {\r\r
1848      if (IS_BIT_SET(linkMask,i) > 0) {\r\r
1849        st->fLinksActive[i] = kTRUE;\r\r
1850        st->fActiveLinks++;\r\r
1851      }\r\r
1852      else {\r\r
1853        st->fLinksActive[i] = kFALSE;\r\r
1854      }\r\r
1855   }\r\r
1856 }\r\r
1857   \r\r
1858 //--------------------------------------------------------\r\r
1859 void AliTRDrawStreamOld::DecodeStackHeader(const UInt_t *word, struct AliTRDrawStack *st, Int_t iword) const\r\r
1860 {\r\r
1861   //\r\r
1862   // decode gtu header for stack info\r\r
1863   //\r\r
1864   st->fPos = (UInt_t*)word;\r\r
1865      \r\r
1866   UInt_t vword = *word;\r\r
1867   st->fLinksDataType[2*iword]    = LINK0_DATA_TYPE_FLAG(vword);\r\r
1868   st->fLinksMonitor[2*iword]     = LINK0_MONITOR_FLAG(vword);\r\r
1869   st->fLinksDataType[2*iword+1]  = LINK1_DATA_TYPE_FLAG(vword);\r\r
1870   st->fLinksMonitor[2*iword+1]   = LINK1_MONITOR_FLAG(vword);\r\r
1871 }\r\r
1872 \r\r
1873 //--------------------------------------------------------\r\r
1874 const char *AliTRDrawStreamOld::DumpStackInfo(const struct AliTRDrawStack *st)\r\r
1875 {\r\r
1876   //\r\r
1877   // format the string with the stack info\r\r
1878   //\r\r
1879 \r\r
1880   return Form("[ Stack Info 0x%08x ] : Hsize %d Links Active %d %d %d %d %d %d %d %d %d %d %d %d",\r\r
1881               *st->fPos, st->fHeaderSize,\r\r
1882               st->fLinksActive[0], st->fLinksActive[1], st->fLinksActive[2], st->fLinksActive[3],\r\r
1883               st->fLinksActive[4], st->fLinksActive[5], st->fLinksActive[6], st->fLinksActive[7],\r\r
1884               st->fLinksActive[8], st->fLinksActive[9], st->fLinksActive[10], st->fLinksActive[11]);\r\r
1885 }\r\r
1886 \r\r
1887 //--------------------------------------------------------\r\r
1888 Bool_t AliTRDrawStreamOld::DecodeHCwordH0(const UInt_t *word, struct AliTRDrawHC *hc) const\r\r
1889 {\r\r
1890   //\r\r
1891   // decode the hc header word 0\r\r
1892   //\r\r
1893   UInt_t vword = *word;\r\r
1894   hc->fPos[0] = (UInt_t*)word;\r\r
1895 \r\r
1896   hc->fH0Corrupted = HC_HEADER_MASK_ERR(vword);\r\r
1897   if (hc->fH0Corrupted > 0) {\r\r
1898     if (fgDebugFlag) AliDebug(11,Form("H0 Header Mask Error. Word 0x%p", *fHC->fPos));\r\r
1899     return kFALSE;\r\r
1900   }\r\r
1901 \r\r
1902   hc->fSpecialRawV =  HC_SPECIAL_RAW_VERSION(vword);\r\r
1903   hc->fRawVMajor = HC_MAJOR_RAW_VERSION(vword);\r\r
1904   hc->fRawVMajorOpt = HC_MAJOR_RAW_VERSION_OPT(vword); \r\r
1905   hc->fRawVMinor = HC_MINOR_RAW_VERSION(vword);\r\r
1906   hc->fNExtraWords = HC_EXTRA_WORDS(vword);\r\r
1907   hc->fDCSboard = HC_DCS_BOARD(vword);\r\r
1908   hc->fSM = HC_SM_NUMBER(vword);\r\r
1909   hc->fStack = HC_STACK_NUMBER(vword);\r\r
1910   hc->fLayer = HC_LAYER_NUMBER(vword);\r\r
1911   hc->fSide = HC_SIDE_NUMBER(vword);\r\r
1912 \r\r
1913 \r\r
1914   return kTRUE;\r\r
1915 }\r\r
1916 \r\r
1917 //--------------------------------------------------------\r\r
1918 Bool_t AliTRDrawStreamOld::DecodeHCwordH1(const UInt_t *word, struct AliTRDrawHC *hc) const\r\r
1919 {\r\r
1920   //\r\r
1921   // decode the hc header word 1\r\r
1922   //\r\r
1923   UInt_t vword = *word;\r\r
1924 \r\r
1925   hc->fH1Corrupted = HC_HEADER_MASK_ERR(vword);\r\r
1926   if (hc->fH1Corrupted > 0) {\r\r
1927     if (fgDebugFlag) AliDebug(11,Form("H1 Header Mask Error. Word 0x%p", *fHC->fPos));\r\r
1928     return kFALSE;\r\r
1929   }\r\r
1930 \r\r
1931   hc->fTimeBins = HC_NTIMEBINS(vword);\r\r
1932   hc->fBunchCrossCounter = HC_BUNCH_CROSS_COUNTER(vword);\r\r
1933   hc->fPreTriggerCounter = HC_PRETRIGGER_COUNTER(vword);\r\r
1934   hc->fPreTriggerPhase = HC_PRETRIGGER_PHASE(vword);\r\r
1935 \r\r
1936   hc->fPos[1] = (UInt_t*)word;\r\r
1937 \r\r
1938   return kTRUE;\r\r
1939 }\r\r
1940   \r\r
1941 //--------------------------------------------------------\r\r
1942 const char *AliTRDrawStreamOld::DumpHCinfoH0(const struct AliTRDrawHC *hc)\r\r
1943 {\r\r
1944   //\r\r
1945   // dump the hc header word 0\r\r
1946   //\r\r
1947   if (!hc)\r\r
1948     return Form("Unable to dump. Null received as parameter!?!");\r\r
1949   else\r\r
1950     return Form("[ HC[0] at 0x%p ] : 0x%08x Info is : RawV %d SM %d Stack %d Layer %d Side %d DCSboard %d",\r\r
1951                 hc->fPos[0], (hc->fPos[0]) ? *(hc->fPos[0]) : 0, hc->fRawVMajor, \r\r
1952                 fRawReader->GetEquipmentId()-1024, hc->fStack, hc->fLayer, hc->fSide, hc->fDCSboard);\r\r
1953 }\r\r
1954 \r\r
1955 //--------------------------------------------------------\r\r
1956 const char *AliTRDrawStreamOld::DumpHCinfoH1(const struct AliTRDrawHC *hc)\r\r
1957 {\r\r
1958   //\r\r
1959   // dump the hc header word 1\r\r
1960   //\r\r
1961   if (!hc)\r\r
1962     return Form("Unable to dump. Null received as parameter!?!");\r\r
1963   else\r\r
1964     return Form("[ HC[1] at 0x%p ] : 0x%08x Info is : TBins %d BCcount %d PreTrigCount %d PreTrigPhase %d",\r\r
1965                 hc->fPos[1], (hc->fPos[1]) ? *(hc->fPos[1]) : 0, hc->fTimeBins, hc->fBunchCrossCounter, hc->fPreTriggerCounter, hc->fPreTriggerPhase);\r\r
1966 }\r\r
1967 \r\r
1968 //--------------------------------------------------------\r\r
1969 void AliTRDrawStreamOld::DecodeMCMheader(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r\r
1970 {\r\r
1971   //\r\r
1972   // decode the mcm header\r\r
1973   //\r\r
1974   UInt_t vword = *word;\r\r
1975 \r\r
1976   if (vword == END_OF_TRACKLET_MARKERNEW) {\r\r
1977     if (fWarnError) AliError(Form("There should be MCM header. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));\r\r
1978     mcm->fMCMhdCorrupted += 16;\r\r
1979     fHC->fCorrupted += 16; //to finish data reading of this HC\r\r
1980   }\r\r
1981 \r\r
1982   mcm->fMCMhdCorrupted = MCM_HEADER_MASK_ERR(vword); //if MCM header mask has error\r\r
1983   if (fgDebugFlag && mcm->fMCMhdCorrupted != 0) AliDebug(11,Form("Wrong MCM header mask 0x%08x.\n", *fpPos));\r\r
1984 \r\r
1985   mcm->fROB = MCM_ROB_NUMBER(vword);\r\r
1986   mcm->fMCM = MCM_MCM_NUMBER(vword);\r\r
1987   mcm->fEvCounter = MCM_EVENT_COUNTER(vword);\r\r
1988   mcm->fPos = (UInt_t*)word;\r\r
1989 }\r\r
1990 \r\r
1991 //--------------------------------------------------------\r\r
1992 UInt_t AliTRDrawStreamOld::GetMCMadcMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r\r
1993 {\r\r
1994   //\r\r
1995   // get the adc mask\r\r
1996   //\r\r
1997   UInt_t vword = *word;\r\r
1998 \r\r
1999   mcm->fADCmax    = 0;\r\r
2000   mcm->fADCMask   = 0;\r\r
2001   mcm->fADCcount  = 0;\r\r
2002   mcm->fADCMaskWord = vword;\r\r
2003 \r\r
2004   if (vword == END_OF_TRACKLET_MARKERNEW) {\r\r
2005     if (fWarnError) AliError(Form("There should be MCMadcMask. We meet END_OF_TRACKLET_MARKER 0x%08x",vword));\r\r
2006     mcm->fADCmaskCorrupted += 16;\r\r
2007     fHC->fCorrupted += 16; //to finish data reading of this HC\r\r
2008   }\r\r
2009 \r\r
2010   if ( MCM_ADCMASK_MASK_ERR(vword) == 0 ) {\r\r
2011     mcm->fADCMask  = MCM_ADCMASK_VAL(vword);\r\r
2012     mcm->fADCcount = MCM_ADCMASK_NADC(~vword);\r\r
2013   }\r\r
2014   else {\r\r
2015     mcm->fADCMask = 0xffffffff;\r\r
2016     mcm->fADCmaskCorrupted = 1; // mcm adc mask error\r\r
2017     if (fgDebugFlag) AliDebug(11,Form("Wrong ADC Mask word 0x%08x.\n", *fpPos));\r\r
2018   }\r\r
2019 \r\r
2020   return mcm->fADCMask;\r\r
2021 }\r\r
2022 \r\r
2023 //--------------------------------------------------------\r\r
2024 void AliTRDrawStreamOld::DecodeMask(const UInt_t *word, struct AliTRDrawMCM *mcm) const\r\r
2025 {\r\r
2026   //\r\r
2027   // decode the adc mask - adcs to be read out\r\r
2028   //\r\r
2029   mcm->fSingleADCwords = 0;\r\r
2030   mcm->fADCmax = 0;\r\r
2031   mcm->fADCMask = GetMCMadcMask(word, mcm);\r\r
2032 \r\r
2033   if (mcm->fADCMask > 0) {\r\r
2034     for (Int_t i = 0; i < TRDMAXADC; i++) {\r\r
2035        mcm->fADCchannel[mcm->fADCmax] = 0;\r\r
2036        if ( IS_BIT_SET(mcm->fADCMask,i) ) {\r\r
2037          mcm->fADCchannel[mcm->fADCmax] = i;\r\r
2038          mcm->fADCmax++;\r\r
2039        }\r\r
2040     }\r\r
2041   }\r\r
2042   if (mcm->fADCcount != mcm->fADCmax && fHC->fRawVMajor >= 32) { // backward compatibility\r\r
2043     mcm->fADCmaskCorrupted += 2; \r\r
2044     if (fgDebugFlag) AliDebug(11,Form("ADC counts from ADCMask are different %d %d : ADCMask word 0x%08x\n", mcm->fADCcount, mcm->fADCmax, *fMCM->fPos));\r\r
2045   }\r\r
2046 }\r\r
2047 \r\r
2048 //--------------------------------------------------------\r\r
2049 void AliTRDrawStreamOld::MCMADCwordsWithTbins(UInt_t fTbins, struct AliTRDrawMCM *mcm) const\r\r
2050 {\r\r
2051   //\r\r
2052   //  count the expected mcm words for a given tbins\r\r
2053   //\r\r
2054   mcm->fSingleADCwords = 0;\r\r
2055   mcm->fSingleADCwords = (fTbins-1)/3+1;\r\r
2056   if (fTbins > 32) mcm->fSingleADCwords = 10; // if the timebin is more than 30, then fix the number of adc words to 10\r\r
2057 }\r\r
2058   \r\r
2059 //--------------------------------------------------------\r\r
2060 const char *AliTRDrawStreamOld::DumpMCMinfo(const struct AliTRDrawMCM *mcm)\r\r
2061 {\r\r
2062   //\r\r
2063   // mcm info in a string\r\r
2064   //\r\r
2065   if (!mcm)\r\r
2066     return Form("Unable to dump. Null received as parameter!?!");\r\r
2067   else\r\r
2068     return Form("[ MCM 0x%08x ] : ROB %d MCM %d EvCounter %d", *(mcm->fPos), mcm->fROB, mcm->fMCM, mcm->fEvCounter);\r\r
2069 }\r\r
2070   \r\r
2071 //--------------------------------------------------------\r\r
2072 const char *AliTRDrawStreamOld::DumpMCMadcMask(const struct AliTRDrawMCM *mcm)\r\r
2073 {\r\r
2074   //\r\r
2075   // mcm adc mask in a string\r\r
2076   //\r\r
2077   if (!mcm)\r\r
2078     return Form("Unable to dump. Null received as parameter!?!");\r\r
2079 \r\r
2080   TString tsreturn = Form("[Word] : 0x%08x => [Mask] : 0x%08x : ", mcm->fADCMaskWord, mcm->fADCMask);\r\r
2081   for (Int_t i = 0; i < TRDMAXADC; i++) {\r\r
2082      tsreturn += Form("%d ", mcm->fADCchannel[i]);\r\r
2083   }\r\r
2084   tsreturn += "";\r\r
2085   return tsreturn.Data();\r\r
2086 }\r\r
2087 \r\r