]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDRawStreamV2.cxx
fix for 64bit architectures after last commit
[u/mrichter/AliRoot.git] / TRD / AliTRDRawStreamV2.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 // This class provides access to TRD digits in raw data.                     //
21 //                                                                           //
22 // It loops over all TRD digits in the raw data given by the AliRawReader.   //
23 // The Next method goes to the next digit. If there are no digits left       //
24 // it returns kFALSE.                                                        //
25 // Several getters provide information about the current digit.              //
26 //                                                                           //
27 // Author: C. Lippmann (C.Lippmann@gsi.de)                                   //
28 //                                                                           //
29 ///////////////////////////////////////////////////////////////////////////////
30
31 #include "AliLog.h"
32 #include "AliRawReader.h"
33
34 #include "AliTRDRawStreamV2.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDcalibDB.h"
37 #include "AliTRDfeeParam.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDdataArrayI.h"
40 #include "AliTRDSignalIndex.h"
41
42 ClassImp(AliTRDRawStreamV2)
43
44 //_____________________________________________________________________________
45 AliTRDRawStreamV2::AliTRDRawStreamV2() 
46   :TObject()
47   ,fGeo(NULL) 
48   ,fSig()
49   ,fADC(0)
50   ,fTB(0)
51   ,fEv(0)
52   ,fROB(0)
53   ,fMCM(0)
54   ,fSM(0)
55   ,fLAYER(0)
56   ,fSTACK(0)
57   ,fROC(0)
58   ,fSIDE(0)
59   ,fDCS(0)
60   ,fROW(0)
61   ,fCOL(0)
62   ,fDET(0)
63   ,fLastDET(-1)
64   ,fBCctr(0)
65   ,fPTctr(0)
66   ,fPTphase(0)
67   ,fRVmajor(0)
68   ,fRVminor(0)
69   ,fHCHWords(0)
70   ,fTBins(0)
71   ,fTCon(0)
72   ,fPEDon(0)
73   ,fGAINon(0)
74   ,fXTon(0)
75   ,fNonLinOn(0)
76   ,fBypass(0)
77   ,fCommonAdditive(0)
78   ,fZeroSuppressed(0)
79   ,fHCHctr1(0)
80   ,fHCHctr2(0)
81   ,fMCMHctr1(0)
82   ,fMCMHctr2(0)
83   ,fGTUctr1(0)
84   ,fGTUctr2(0)
85   ,fHCdataCtr(0)
86   ,fTracklPID(0.)
87   ,fTracklDefL(0.)
88   ,fTracklPadPos(0.)
89   ,fTracklPadRow(0)
90   ,fGTUlinkMask()
91   ,fMCMWordCrt(0)
92   ,fMCMWordsExpected(0)
93   ,fRawReader(NULL)
94   ,fRawVersion(2)
95   ,fRawDigitThreshold(0)
96   ,fNextStatus(0)
97   ,fLastStatus(0)
98   ,fTbSwitch(0)
99   ,fTbSwitchCtr(0)
100   ,fTimeWords(0)
101   ,fWordCtr(0)
102   ,fRowMax(0)
103   ,fColMax(0)
104   ,fADCmask()
105   ,fLastADCmask(0)
106   ,fChamberDone()
107   ,fRetVal(0)
108   ,fEqID(0)
109   ,fDataSize(0)
110   ,fSizeOK(kFALSE)
111   ,fCountBytes(0)
112   ,fBufSize(0)
113   ,fkBufferSet(kFALSE)
114   ,fPos(NULL)
115   ,fDataWord(NULL)
116   ,fTimeBinsCalib(0)
117   ,fADClookup()
118   ,fNActiveADCs(0)
119   ,fEndOfDataFlag(kFALSE)
120 {
121   //
122   // Default constructor
123   //
124
125   for (Int_t i = 0; i < 540; i++) {
126     fChamberDone[i] = 0;
127   }
128
129 }
130
131 //_____________________________________________________________________________
132 AliTRDRawStreamV2::AliTRDRawStreamV2(AliRawReader *rawReader) 
133   :TObject()
134   ,fGeo(NULL) 
135   ,fADC(0)
136   ,fTB(0)
137   ,fEv(0)
138   ,fROB(0)
139   ,fMCM(0)
140   ,fSM(0)
141   ,fLAYER(0)
142   ,fSTACK(0)
143   ,fROC(0)
144   ,fSIDE(0)
145   ,fDCS(0)
146   ,fROW(0)
147   ,fCOL(0)
148   ,fDET(0)
149   ,fLastDET(-1)
150   ,fBCctr(0)
151   ,fPTctr(0)
152   ,fPTphase(0)
153   ,fRVmajor(0)
154   ,fRVminor(0)
155   ,fHCHWords(0)
156   ,fTBins(0)
157   ,fTCon(0)
158   ,fPEDon(0)
159   ,fGAINon(0)
160   ,fXTon(0)
161   ,fNonLinOn(0)
162   ,fBypass(0)
163   ,fCommonAdditive(0)
164   ,fZeroSuppressed(0)
165   ,fHCHctr1(0)
166   ,fHCHctr2(0)
167   ,fMCMHctr1(0)
168   ,fMCMHctr2(0)
169   ,fGTUctr1(0)
170   ,fGTUctr2(0)
171   ,fHCdataCtr(0)
172   ,fTracklPID(0.)
173   ,fTracklDefL(0.)
174   ,fTracklPadPos(0.)
175   ,fTracklPadRow(0)
176   ,fGTUlinkMask()
177   ,fMCMWordCrt(0)
178   ,fMCMWordsExpected(0)
179   ,fRawReader(rawReader)
180   ,fRawVersion(2)
181   ,fRawDigitThreshold(0)
182   ,fNextStatus(0)
183   ,fLastStatus(0)
184   ,fTbSwitch(0)
185   ,fTbSwitchCtr(0)
186   ,fTimeWords(0)
187   ,fWordCtr(0)
188   ,fRowMax(0)
189   ,fColMax(0)
190   ,fADCmask()
191   ,fLastADCmask(0)
192   ,fChamberDone()
193   ,fRetVal(0)
194   ,fEqID(0)
195   ,fDataSize(0)
196   ,fSizeOK(kFALSE)
197   ,fCountBytes(0)
198   ,fBufSize(0)
199   ,fkBufferSet(kFALSE)
200   ,fPos(NULL)
201   ,fDataWord(NULL)
202   ,fTimeBinsCalib(0)
203   ,fADClookup()
204   ,fNActiveADCs(0)
205   ,fEndOfDataFlag(kFALSE)
206 {
207   //
208   // Create an object to read TRD raw digits
209   //
210
211   fRawReader->Select("TRD");
212
213   for (Int_t i = 0; i < 540; i++) {
214     fChamberDone[i] = 0;
215   }
216
217 }
218
219 //_____________________________________________________________________________
220 AliTRDRawStreamV2::AliTRDRawStreamV2(const AliTRDRawStreamV2& stream)
221   :TObject(stream)
222   ,fGeo(NULL)
223   ,fSig()
224   ,fADC(-1)
225   ,fTB(-1)
226   ,fEv(-1)
227   ,fROB(-1)
228   ,fMCM(-1)
229   ,fSM(-1)
230   ,fLAYER(-1)
231   ,fSTACK(-1)
232   ,fROC(-1)
233   ,fSIDE(-1)
234   ,fDCS(-1)
235   ,fROW(-1)
236   ,fCOL(-1)
237   ,fDET(0)
238   ,fLastDET(-1)
239   ,fBCctr(-1)
240   ,fPTctr(-1)
241   ,fPTphase(-1)
242   ,fRVmajor(-1)
243   ,fRVminor(-1)
244   ,fHCHWords(-1)
245   ,fTBins(-1)
246   ,fTCon(0)
247   ,fPEDon(0)
248   ,fGAINon(0)
249   ,fXTon(0)
250   ,fNonLinOn(-1)
251   ,fBypass(-1)
252   ,fCommonAdditive(-1)
253   ,fZeroSuppressed(0)
254   ,fHCHctr1(-1)
255   ,fHCHctr2(-1)
256   ,fMCMHctr1(-1)
257   ,fMCMHctr2(-1)
258   ,fGTUctr1(-1)
259   ,fGTUctr2(-1)
260   ,fHCdataCtr(-1)
261   ,fTracklPID(-1.)
262   ,fTracklDefL(-1.)
263   ,fTracklPadPos(-1.)
264   ,fTracklPadRow(-1)
265   ,fGTUlinkMask()
266   ,fMCMWordCrt(0)
267   ,fMCMWordsExpected(0)
268   ,fRawReader(NULL)
269   ,fRawVersion(-1)
270   ,fRawDigitThreshold(0)
271   ,fNextStatus(0)
272   ,fLastStatus(0)
273   ,fTbSwitch(0)
274   ,fTbSwitchCtr(0)
275   ,fTimeWords(0)
276   ,fWordCtr(0)
277   ,fRowMax(-1)
278   ,fColMax(-1)
279   ,fADCmask()
280   ,fLastADCmask(0)
281   ,fChamberDone()
282   ,fRetVal(0)
283   ,fEqID(0)
284   ,fDataSize(0)
285   ,fSizeOK(kFALSE)
286   ,fCountBytes(0)
287   ,fBufSize(0)
288   ,fkBufferSet(kFALSE)
289   ,fPos(NULL)
290   ,fDataWord(NULL)
291   ,fTimeBinsCalib(0)
292   ,fADClookup()
293   ,fNActiveADCs(0)
294   ,fEndOfDataFlag(kFALSE)
295 {
296   //
297   // Copy constructor
298   //
299
300   AliFatal("Copy constructor not implemented");
301
302 }
303
304 //_____________________________________________________________________________
305 AliTRDRawStreamV2& AliTRDRawStreamV2::operator = (const AliTRDRawStreamV2& 
306                                               /* stream */)
307 {
308   //
309   // Assigment operator
310   //
311
312   Fatal("operator =", "assignment operator not implemented");
313   return *this;
314
315 }
316
317 //_____________________________________________________________________________
318 AliTRDRawStreamV2::~AliTRDRawStreamV2()
319 {
320   //
321   // Destructor
322   //
323
324   if (fGeo) {  
325     delete fGeo;
326   }
327
328 }
329
330 //_____________________________________________________________________________
331 void AliTRDRawStreamV2::SetRawReader(AliRawReader *rawReader) 
332 {
333   //
334   // Set the rawreader
335   //
336
337   if (rawReader)
338     {
339       fRawReader = rawReader;
340     }
341 }
342
343 //_____________________________________________________________________________
344 Bool_t AliTRDRawStreamV2::SetRawVersion(Int_t rv)
345 {
346   //
347   // Set the raw data version
348   //
349
350   if ( rv >= 0 && rv <= 3 ) {
351     fRawVersion = rv;
352     return kTRUE;
353   }
354
355   return kFALSE;
356
357 }
358
359 //____________________________________________________________________________
360 Int_t AliTRDRawStreamV2::Init()
361 {
362   //
363   // Initialization
364   //
365
366   if (!AliTRDcalibDB::Instance()) {
367     AliError("Could not get calibration object");
368     return 0;
369   }
370
371   if (!fGeo) {
372     fGeo = new AliTRDgeometry();
373   }
374   
375   fTimeBinsCalib = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
376   //AliDebug(2, Form("Number of Timebins read from CDB: %d", fTimeBinsCalib));
377
378   // The number of data words needed for this number of time bins (there
379   // are 3 time bins in one word)
380   fTimeWords = (fTimeBinsCalib-1)/3 + 1;
381
382   fTbSwitch    = 3;
383   fTbSwitchCtr = 0;
384
385   fHCHctr1 = fHCHctr2 =  0;
386   fGTUctr1 = fGTUctr2 = -1;
387
388   fHCdataCtr = 0;
389   fWordCtr   = 0;  
390
391   fDET     = 0;
392   fLastDET     = -1;
393   fRetVal = 0;
394   fEqID     = 0;
395   fDataSize = 0;
396   fSizeOK = kFALSE;
397   
398   fLastStatus = kStart;
399   fNextStatus = kStart;
400
401   fCountBytes = 0;
402   fBufSize = 0;
403   fDataWord = NULL;
404   fPos = NULL;
405   fWordCtr = 0;
406   fkBufferSet = kFALSE;
407
408   fMCMWordCrt = 0;
409   fMCMWordsExpected = 0;
410
411   fEndOfDataFlag = kFALSE;
412   // set all ADC active
413   // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
414   fNActiveADCs = ChannelsToRead(0x1fffff); 
415
416   fLastADCmask = 0;
417
418   return kTRUE;
419 }
420
421 //____________________________________________________________________________
422 Int_t AliTRDRawStreamV2::NextData()
423 {
424   //
425   // Updates the next data word pointer
426   //
427
428   if (fCountBytes + fgkSizeWord >= fBufSize)
429     {
430       fkBufferSet = fRawReader->ReadNextData(fPos);
431       if (fkBufferSet == kTRUE)
432         {
433           fBufSize = fRawReader->GetDataSize();
434           fCountBytes = 0;        
435           fDataWord = (UInt_t*)fPos;
436           ChangeStatus(kNextSM);
437           fWordCtr = 0;
438           return kNextSM;
439         }
440       else
441         {
442           ChangeStatus(kStop);
443           return kNoMoreData;
444         }
445     }
446   else
447     {
448       fPos += fgkSizeWord;
449       fCountBytes += fgkSizeWord;         
450       fDataWord = (UInt_t*)fPos;
451       fWordCtr++;
452       return kWordOK;
453     }
454 }
455
456 //============================================================================
457 // Decoding functions
458 //============================================================================
459
460 //____________________________________________________________________________
461 void AliTRDRawStreamV2::DecodeHCheader(Int_t timeBins)
462 {
463   //
464   // Decode the HC header (fRawVersion == 2, 3, 4, ???)
465   //
466
467   fRVmajor = (*fDataWord >> 24) & 0x7f;
468   fRVminor = (*fDataWord >> 17) & 0x7f;
469
470   if (fRVmajor < 2 || fRVmajor > 4)
471     AliError(Form(" Unsupported raw version: %d", fRawVersion))
472   
473   if ( fRawVersion != fRVmajor ) {
474     
475     AliWarning("===============================================================================");
476     AliWarning(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header (%d)"
477                     ,fRawVersion,fRVmajor));
478     AliWarning(Form("Setting fRawVersion to %d", fRVmajor));
479     AliWarning("===============================================================================");
480     fRawVersion = fRVmajor;
481
482   }
483
484   //
485   // check for zero suppression
486   if ( fRawVersion >= 3 || fRawVersion <= 4 ) fZeroSuppressed = kTRUE;
487   else                                        fZeroSuppressed = kFALSE;
488   
489   // 1st word (h[0])
490   if ( (*fDataWord & 0x3) == 1 ) {
491
492     fHCHWords = (*fDataWord >> 14) & 0x7;
493     fSM       = (*fDataWord >>  9) & 0x1f;
494     fLAYER    = (*fDataWord >>  6) & 0x7;
495     fSTACK    = (*fDataWord >>  3) & 0x7;
496     fSIDE     = (*fDataWord >>  2) & 0x1;
497
498     fROC      = fGeo->GetDetectorSec(fLAYER, fSTACK);
499
500     //AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", *fDataWord, fSM, fROC, fSIDE+10));
501     //AliDebug(5, Form("0x%08x: HC header: expecting %d HC words", *fDataWord, fHCHWords));
502
503     if ((fSM    <  0) || 
504         (fSM    > 17) || 
505         (fLAYER <  0) || 
506         (fLAYER >  5) || 
507         (fSTACK <  0) || 
508         (fSTACK >  4) || 
509         (fSIDE  <  0) || 
510         (fSIDE  >  1)) 
511       {
512         AliWarning(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.",
513                         *fDataWord, fDCS, fSM, fLAYER, fSTACK));
514         fRawReader->AddMajorErrorLog(kHCHeaderCorrupt,Form("0x%08x:dcs=%d; sm=%d; layer=%d; stack=%d.",
515                                                            *fDataWord, fDCS, fSM, fLAYER, fSTACK));
516       } 
517     else 
518       {
519         fHCHctr1++;
520         fHCHctr2++;
521       }
522   } 
523   else 
524     { 
525       AliWarning(Form("0x%08x: No HC header when it was expected.", *fDataWord)); 
526       fRawReader->AddMajorErrorLog(kHCHeaderMissing,Form("0x%08x", *fDataWord));
527     }
528
529   // 2nd word (h[1])
530   if ( fHCHWords >= 1 ) 
531     {
532       // read one more word
533       if (NextData() != kWordOK)
534         {
535           AliWarning("Next HC word missing");
536           fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing"); 
537           fNextStatus = kNextHC;
538           return;
539         }
540
541       if ( (*fDataWord & 0x3) == 1 ) 
542         {
543           
544           fBCctr   =  (*fDataWord >> 16);
545           fPTctr   =  (*fDataWord >> 12) & 0xf;
546           fPTphase =  (*fDataWord >>  8) & 0xf;
547           fTBins   = ((*fDataWord >>  2) & 0x3f) + 1;
548           fTimeWords = (fTBins - 1)/3 + 1;      
549           
550 //        AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d"
551 //                         , *fDataWord, fBCctr, fPTctr, fPTphase, fTBins));
552
553           if( fTBins != timeBins ) 
554             {         
555               AliWarning("===============================================================================");
556               AliError(Form("Mismatch between nNTB from CDB (%d) and from HC header (%d)"
557                             , timeBins, fTBins));
558               AliWarning(Form("We will use the value from the raw data (HC header): %d", fTBins));
559               AliWarning("===============================================================================");          
560
561               fTimeWords = (fTBins - 1)/3 + 1;  
562             }
563         }      
564     }
565
566   // 3nd word (h[2])
567   if ( fHCHWords >= 2 ) {
568     // read one more word
569     if (NextData() != kWordOK)
570       {
571         AliWarning("Next HC word missing");
572         fRawReader->AddMajorErrorLog(kHCWordMissing,"Next HC word missing"); 
573         fNextStatus = kNextHC;
574         return;
575       }
576     if ( (*fDataWord & 0x3) == 1 ) {
577        
578       fTCon     = (*fDataWord >> 29) & 0x1;
579       fPEDon    = (*fDataWord >> 31) & 0x1;
580       fGAINon   = (*fDataWord >> 30) & 0x1;
581       fXTon     = (*fDataWord >> 28) & 0x1;
582       fNonLinOn = (*fDataWord >> 27) & 0x1;
583       fBypass   = (*fDataWord >> 26) & 0x1;
584
585       fCommonAdditive = (*fDataWord >> 20) & 0x3f;
586
587 //       AliDebug(3, Form("0x%08x: HC header 3: TC=%d, PED=%d, GAIN=%d, XT=%d, NonLin=%d, Bypass=%d, Add=%d"
588 //                    , fTCon, fPEDon, fGAINon, fXTon, fNonLinOn, fBypass, fCommonAdditive));
589     }
590   }
591
592 }  
593
594 //____________________________________________________________________________
595 Int_t AliTRDRawStreamV2::ChannelsToRead(Int_t ADCmask)
596 {
597   //
598   // Return the channels to read
599   //
600
601   memset(fADClookup, -1, 32 * sizeof(Int_t));
602   fADClookup[0] = 0; // count entries
603   fADClookup[1] = 2; // index - data start at 2
604   UInt_t mask = 0;
605   for (Int_t i = 0; i < 30; i++)
606     {
607       mask = 1 << i;
608       if ((ADCmask & mask))
609         {
610           //AliDebug(9, Form("fDataWord=0x%08x mask=0x%08x i=%d", *fDataWord, mask, i));
611           fADClookup[fADClookup[1]] = i;
612           ++fADClookup[0];
613           ++fADClookup[1];
614         }
615     }
616
617   // test the iteration - comment out for production
618   // begin of comment out section
619   char schannels[512];
620   sprintf(schannels, "ADC Channels to read: ");
621   fADClookup[1] = 2;
622   while(fADClookup[1] - 2 < fADClookup[0])
623     {
624       //AliDebug(9, Form("max=%d index=%d adc=%d", fADClookup[0], fADClookup[1], fADClookup[fADClookup[1]]));
625       strcat(schannels, Form("%d ", fADClookup[fADClookup[1]]));
626       fADClookup[1]++;
627     }
628   //AliDebug(9, Form("%s", schannels));
629   //AliDebug(9, Form("ADC channels = %d", fADClookup[0]));
630   // end of comment out section
631
632   fADClookup[1] = 2;
633   return fADClookup[0];
634 }
635
636 //____________________________________________________________________________
637 void AliTRDRawStreamV2::DecodeTracklet()
638 {
639   //
640   // Decode the Tracklet
641   //
642   // this function is not tested yet on real tracklets
643   //
644
645   if ( fRawVersion < 1 || fRawVersion > 3 ) 
646     {
647       AliError(Form(" Unsupported raw version: %d", fRawVersion));      
648     }
649
650   fTracklPID    = (*fDataWord >> 24) & 0xff;
651   fTracklPadRow = (*fDataWord >> 20) & 0xf;    // 0:15
652   fTracklDefL   = (*fDataWord >> 13) & 0x7f;
653   fTracklPadPos = (*fDataWord)       & 0x1fff;
654
655   fTracklPID    /= (Float_t)((1<<8) - 1);                      // 0:1 (steps of 0.39%)
656   fTracklDefL    = (fTracklDefL  - ((1<< 7)-1)/2.) * 140.e-4;  // -0.889:0.889cm 
657   fTracklPadPos  = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm
658
659   //AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f"
660   //              , *fDataWord, fSM, fLAYER, fSTACK, fSIDE+10
661   //                , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID));
662
663   if( (fSTACK == 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC0()) ||
664       (fSTACK != 2) && (fTracklPadRow >= (Int_t) fGeo->RowmaxC1()) ) {
665     AliWarning(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow));
666     fRawReader->AddMajorErrorLog(kTrackletRowMismatch,Form("Word: %d", fTracklPadRow));
667   }
668
669 }
670
671 //____________________________________________________________________________
672 void AliTRDRawStreamV2::DecodeMCMheader()
673 {
674   //
675   // Decode the MCM header
676   //
677
678   if ( fRawVersion < 1 || fRawVersion > 3 ) 
679     {
680       AliError(Form(" Unsupported raw version: %d", fRawVersion));      
681     }
682
683   fMCM  = (*fDataWord & 0xff000000) >> 24;
684   fEv   = (*fDataWord & 0x00fffff0) >> 4;
685
686   fROB  = fMCM / 16;
687   fMCM  = fMCM % 16;
688
689   fROW  = AliTRDfeeParam::Instance()->GetPadRowFromMCM(fROB, fMCM);
690
691 //   AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d"
692 //                , *fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv));
693
694   if ( fROB % 2 == 0 && fSIDE == 1 ) {
695     AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
696                    , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
697     fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
698                                                        , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
699   }
700   if ( fROB % 2 != 0 && fSIDE == 0 ) {
701     AliWarning(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d"
702                    , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
703     fRawReader->AddMajorErrorLog(kROBSideMismatch,Form("SM%d L%dS%d: fROB (%d) fSIDE (%d): fMCM=%02d"
704                                                        , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM ));
705   }
706   if ( (fSTACK == 2 && fROW >= fGeo->RowmaxC0()) ||
707        (fSTACK != 2 && fROW >= fGeo->RowmaxC1()) || fROW < 0 ) {
708     AliWarning(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
709                    , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
710     fRawReader->AddMajorErrorLog(kWrongPadrow,Form("SM%d L%dS%d: Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d"
711                                                   , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM ));
712   }
713   
714   fMCMHctr1++;
715   fMCMHctr2++;
716
717   fMCMWordCrt = 1; // MCM header
718
719   // AdcMask for Zero supressed data
720   if ( fRawVersion == 3 ) 
721     {
722       // read one more word
723       if (NextData() != kWordOK)
724         {
725           AliWarning("MCM ADC mask missing");
726           fRawReader->AddMajorErrorLog(kMCMADCMaskMissing,"Missing"); 
727           fNextStatus = kNextHC;
728           return;
729         }
730       else
731         {
732           ++fMCMWordCrt;
733
734           for ( Int_t ctr = 0; ctr < fGeo->ADCmax(); ctr++ ) {
735             if ( (*fDataWord >> (11+ctr)) == 0x1 ) fADCmask[ctr] = kTRUE;
736             else                                  fADCmask[ctr] = kFALSE;
737           }
738           
739           //AliDebug(4, Form("0x%08x: ADC mask", *fDataWord));
740           fNActiveADCs = ChannelsToRead(*fDataWord);      
741         }
742     }
743
744   if (fRawVersion <= 2)
745     {
746       // no zero suppression
747       // raw version 2:
748       // 1 MCM header + 21 * ( Ntimebin/3)
749       // If NTimebin = 30, it is 211 words. 
750       //fMCMWordsExpected = 1 + 21 * (fTBins / 3);
751       //fNActiveADCs = 21;
752       fNActiveADCs = ChannelsToRead(0x1fffff); // should be 1111 1111 1111 1111 1111 1 = 21 bits active (0-20)
753       //fMCMWordsExpected = 1 + fNActiveADCs * ((fTBins-1) / 3. + 1.);      
754       //directly get it like that:
755       fMCMWordsExpected = 1 + fNActiveADCs * fTBins / 3;      
756     }
757
758   if (fRawVersion >= 3)
759     {
760       // raw version 3:
761       // 1 MCM header + 1 ADC mask + NofActiveADCs * ( Ntimebin/3 )
762       //directly get it like that:
763       fMCMWordsExpected = 1 + 1 + (fTBins * fNActiveADCs) / 3;
764     }
765   
766   //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
767 }
768 //____________________________________________________________________________
769 Bool_t AliTRDRawStreamV2::DecodeNextRawWord()
770 {
771   //
772   // Decode the next raw data word
773   //
774
775   //AliDebug(8, Form("-----------------------------------------"));
776   //AliDebug(8, Form("DATA IS 0x%x", *fDataWord));
777
778   if (fADClookup[1] - 2 > fADClookup[0])
779     {
780 //       AliDebug(8, Form("Overflow Index ADC = %d Max Index = %d Value = %d. Done with ADCs in this MCM. Is this already MCM header 0x%x?", 
781 //                     fADClookup[1] - 2, fADClookup[0], fADClookup[fADClookup[1]], *fDataWord));
782       fTbSwitchCtr = 0;
783       fMCMWordsExpected = 0;
784       AliWarning("Trying to recover. Fall back to DecodeMCM.");
785       DecodeMCM();
786       //ChangeStatus(kNextMCM);
787       return kFALSE;
788     }
789
790   if ( (*fDataWord & 0x00000003) != 0x2 && (*fDataWord & 0x00000003) != 0x3) {
791     AliWarning(Form("Data %08x : Data Word ends neither with b11 nor b10", (Int_t)*fDataWord));
792     fRawReader->AddMinorErrorLog(kDataMaskError,Form("Data %08x", (Int_t)*fDataWord));
793     fMCMWordsExpected = 0;
794     AliWarning("Trying to recover. Fall back to DecodeMCM.");
795     DecodeMCM();
796     //ChangeStatus(kNextMCM);
797     return kFALSE;
798   }
799
800   if ( (*fDataWord & 0x3) != fLastADCmask || fTbSwitchCtr > fTimeWords) 
801     {    
802       fADC = fADClookup[fADClookup[1]];
803 //       AliDebug(8, Form("Next fADC = %d at index = %d MCM Word Number: %d Max MCM Words is %d", 
804 //                     fADC, fADClookup[1] - 2, fMCMWordCrt, fMCMWordsExpected));
805       ++fADClookup[1];
806       fTB = 0;    
807       fTbSwitchCtr = 0;
808       fLastStatus = kNextData;
809       fLastADCmask = (*fDataWord) & 0x3;
810     }
811
812   ++fTbSwitchCtr;
813
814   //decode data here
815   Bool_t kIsDataOK = kFALSE;
816
817   // We have only 21 ADC channels.
818   if ( fADC > (Int_t)fGeo->ADCmax() - 1 ) 
819     {
820       AliWarning(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)*fDataWord, (Int_t)fADC));
821       fRawReader->AddMinorErrorLog(kADCChannelOverflow,Form("Data %08x : fADC=%d", (Int_t)*fDataWord, (Int_t)fADC));
822     }
823   else
824     {
825       // There are 18 pads connected to each MCM ADC channels 2...19. The other channels cross to other
826       // MCMs and are good for online tracking in the MCM.
827       if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax() - 1 ) 
828         {
829           
830           // Get Pad column
831           // fCOL = fFee->GetPadColFromADC(fROB, fMCM, fADC);
832           fCOL = AliTRDfeeParam::Instance()->GetPadColFromADC(fROB, fMCM, fADC);
833           
834           // We have only 144 Pad Columns
835           //if ( fCOL > fColMax-1 || fCOL < 0 ) 
836           if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax ) 
837             {
838               // Decode 32 bit data words with information from 3 time bins and copy the data
839               fSig[0] = (*fDataWord & 0x00000ffc) >> 2;
840               fSig[1] = (*fDataWord & 0x003ff000) >> 12;
841               fSig[2] = (*fDataWord & 0xffc00000) >> 22;
842               
843               // Print data to screen:
844               //AliDebug(5, Form("DATA : 0x%x", *fDataWord));
845               //          AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n",
846               //                           fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2]));            
847               kIsDataOK = kTRUE;
848             }
849           else
850             {
851               AliWarning(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
852                               fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
853               fRawReader->AddMajorErrorLog(kWrongPadcolumn,Form("SM%d L%dS%d: column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM,
854                                                                 fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM ));
855               kIsDataOK = kFALSE;
856             }
857         }
858       else 
859         {      
860           //AliDebug(5, Form("fADC not accepted %d - DATA : 0x%x", fADC, *fDataWord));
861           fCOL = -1;
862           kIsDataOK = kFALSE;
863         }
864     }// if fADC is ok
865
866   ++fMCMWordCrt;
867   //AliDebug(5, Form("We expect %d MCM words. We read %d so far.", fMCMWordsExpected, fMCMWordCrt));
868
869   // all mcm data processed go to next one
870   if ( fMCMWordCrt >= fMCMWordsExpected)
871     {
872       ChangeStatus(kNextMCM);
873     }
874
875   return kIsDataOK;
876 }
877
878 //____________________________________________________________________________
879 Bool_t AliTRDRawStreamV2::DecodeMCM()
880 {
881   //
882   // Decode a single MCM
883   //
884
885   if( ((*fDataWord & 0x80000000) == 0x0) && ((*fDataWord & 0x0000000f) == 0xC) )
886     { // MCM Header
887       DecodeMCMheader();
888       if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 ) 
889         {
890           AliWarning("Wrong fMCM or fROB. Skip this data");
891           fRawReader->AddMajorErrorLog(kWrongMCMorROB,Form("MCM=%d, ROB=%d",fMCM,fROB));
892           ChangeStatus(kNextHC);
893           return kFALSE;
894         }
895
896       fTbSwitch    = 3;  // For first adc channel we expect: (*fDataWord & 3) = 3
897       fTbSwitchCtr = 0;  // 
898       fADC = fTB   = 0;  // Reset Counter
899       fLastADCmask = 0; // Reset
900
901       if (fMCMWordCrt < fMCMWordsExpected)
902         {
903           ChangeStatus(kNextData);
904         }
905       else
906         {
907           ChangeStatus(kNextMCM);
908         }
909       return kTRUE;
910     }
911
912   if ( *fDataWord == fgkEndofrawdatamarker ) 
913     {  // End of half-chamber data, finished
914       fGTUctr1 = -1;
915       ChangeStatus(kNextHC);
916       fEndOfDataFlag = kTRUE;
917       //AliDebug(5, "Expecting MCM header but got End-Of-Raw-Data Marker");
918       if (fMCMWordsExpected == 0 || fMCMWordsExpected == fMCMWordCrt)
919         return kTRUE;
920       else
921         {
922           //AliDebug(5, Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));    
923           //AliWarning(Form("MCM words missing? %d [expected=%d got=%d] ", fMCMWordsExpected - fMCMWordCrt, fMCMWordsExpected, fMCMWordCrt));     
924           return kFALSE;
925         }
926     }
927
928   //AliDebug(3, Form("Expecting MCM header but got 0x%x. Going to Next MCM header.", *fDataWord));
929   AliWarning(Form("Expecting MCM header but got 0x%x. Fall back: Next MCM header.", *fDataWord));
930   ChangeStatus(kNextMCM);      
931
932   return kFALSE;
933 }
934
935 //____________________________________________________________________________
936 Bool_t AliTRDRawStreamV2::DecodeHC()
937 {
938   //
939   // Decode a half chamber
940   //
941
942   if ( fNextStatus == kNextHC )
943     {
944       //AliDebug(5, "kNextHC");
945       //
946       // 1) Find end_of_tracklet_marker
947       //
948       // GTU Link Mask?
949       if (DecodeGTUlinkMask())
950         {
951           return kTRUE;
952         }
953       
954       // endoftrackletmarker?
955       if ( *fDataWord == fgkEndoftrackletmarker ) 
956         {
957           //AliDebug(3, "End-of-tracklet-marker found");
958           //AliDebug(5, Form("Data 0x%x", *fDataWord));
959           ChangeStatus(kSeekNonEoTracklet);
960           return kTRUE;
961         } 
962       else 
963         {
964           // Tracklets found
965           //AliDebug(3, "Tracklet found");
966           //AliDebug(5, Form("Tracklet data 0x%x", *fDataWord));
967           DecodeTracklet();
968           return kTRUE;
969         }
970     } // if next HC
971
972   if (fNextStatus == kSeekNonEoTracklet)
973     {
974       //AliDebug(5, "kSeekNonEoTracklet");
975
976       //
977       // 2) Look for non-end_of_tracklet_marker
978       //
979       //printf("Word %d: 0x%08x\n", fWordCtr, *fDataWord); 
980       
981       if ( *fDataWord != fgkEndoftrackletmarker ) 
982         {
983           ChangeStatus(kDecodeHC);
984           //AliDebug(3, "NON end-of-tracklet-marker found");
985           //AliDebug(5, Form("Data 0x%x", *fDataWord));
986           //// no do not continue - this should be the hcheader
987         }
988       else
989         {
990           //just go on and find the non-end_of_tracklet_marker
991           return kTRUE;
992         }
993     }
994
995   if ( fNextStatus == kDecodeHC )
996     {
997       //AliDebug(5, "kDecodeHC");
998       
999       //
1000       // 3) This Word must be Half Chamber Header
1001       //
1002       if ( (*fDataWord & 0x00000003) == 1 ) 
1003         { // HC header
1004           DecodeHCheader(fTimeBinsCalib); // This is the new header!
1005           fLastDET = fDET;
1006           fDET    = fGeo->GetDetector(fLAYER, fSTACK, fSM);
1007           fRowMax = fGeo->GetRowMax(fLAYER,fSTACK,fSM);
1008           fColMax = fGeo->GetColMax(fROC);
1009           
1010           fMCMHctr2 = 0;
1011           fHCdataCtr = 0;
1012           fChamberDone[fDET]++;
1013           //AliDebug(6, Form("--------------      DET %d fChamberDone[fDET]=%d", fDET, fChamberDone[fDET]));
1014
1015           ChangeStatus(kNextMCM);
1016           return kTRUE;
1017         } //HC header
1018       else
1019         {
1020           AliWarning(Form("Expecting HC header mask but got 0x%x. Fall back: Next HC.", *fDataWord));
1021           ChangeStatus(kNextHC);
1022           // before we went to //ChangeStatus(kNextSM);
1023         }
1024     } // if decode HC
1025   
1026   return kFALSE;
1027 }
1028
1029 //____________________________________________________________________________
1030 Bool_t AliTRDRawStreamV2::DecodeGTUlinkMask()
1031 {
1032   //
1033   // Decode the link masks sent by the GTU. These marke the active optical links
1034   // between GTU and Super Module. Up to now only fully active links are found
1035   // (0xfff = 12 active links).
1036   //
1037
1038   if ( (*fDataWord & 0xfffff000) ==  0xe0000000 )
1039     {
1040       if ( fRawVersion < 1 || fRawVersion > 3 ) 
1041         {
1042           AliError(Form(" Unsupported raw version: %d", fRawVersion));      
1043         }
1044       
1045       if ( fGTUctr1 == -1 ) fGTUctr2++;
1046       fGTUctr1++;
1047
1048       if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) 
1049         {
1050           fGTUlinkMask[fGTUctr2][fGTUctr1] = (*fDataWord & 0xfff);
1051         }
1052      
1053       //AliDebug(5, Form("GTU link mask 0x%x decoded 0x%x", *fDataWord, fGTUlinkMask[fGTUctr2][fGTUctr1]));
1054       return kTRUE;
1055     }
1056
1057   return kFALSE;
1058 }
1059
1060 //____________________________________________________________________________
1061 void AliTRDRawStreamV2::ChangeStatus(Int_t kstat)
1062 {
1063   //
1064   // Change the status
1065   //
1066
1067   fLastStatus = fNextStatus;
1068   fNextStatus = kstat;  
1069 }
1070
1071 //____________________________________________________________________________
1072 Bool_t AliTRDRawStreamV2::DecodeSM()
1073 {
1074   //
1075   // Decode a supermodule
1076   //
1077
1078   fDET     = 0;
1079   fRetVal = 0;
1080   fEqID     = 0;
1081   fDataSize = 0;
1082   fSizeOK = kFALSE;
1083   
1084   // After reading the first word check for size of this data and get Eq. ID
1085   if ( fWordCtr == 1 ) 
1086     {
1087       fDataSize = fRawReader->GetDataSize()/4;  // Size of this payload in 32bit words
1088       fEqID     = fRawReader->GetEquipmentId(); // Get Equipment ID
1089       if ( fDataSize > 0 ) fSizeOK = kTRUE;
1090       //AliDebug(3, Form("fDataSize=%d fEqID=%d", fDataSize, fEqID));
1091     }
1092   
1093   // GTU Link Mask?
1094   if ( DecodeGTUlinkMask() ) 
1095     {
1096       ChangeStatus(kNextHC);
1097       return kTRUE;
1098     } 
1099   else 
1100     {
1101       AliWarning(Form("Equipment %d: First data word is not GTU Link Mask! Fall back: None. Stop.", fEqID));
1102       fRawReader->AddMajorErrorLog(kGTULinkMaskMissing,Form("Equipment %d",fEqID));
1103       ChangeStatus(kStop);
1104     }       
1105
1106   return kFALSE;
1107 }
1108
1109 //____________________________________________________________________________
1110 Bool_t AliTRDRawStreamV2::Next()
1111 {
1112   //
1113   // Updates the next data word pointer
1114   //
1115
1116   if (fNextStatus == kStart)
1117     {
1118       Init();
1119     }
1120
1121   while (fNextStatus != kStop)
1122     { // !kStop
1123       NextData();
1124       
1125       switch (fNextStatus)
1126         {
1127         case kNextData:
1128           {
1129           if (DecodeNextRawWord() == kTRUE)
1130             {
1131               fTB += 3;
1132               if (fSig[0] > fRawDigitThreshold || fSig[1] > fRawDigitThreshold || fSig[2] > fRawDigitThreshold) 
1133                 return kTRUE;
1134             }
1135           }; break;
1136         case kNextMCM:
1137           {
1138             if (DecodeMCM() == kFALSE)
1139               AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));      
1140           }; break;
1141         case kNextHC:
1142         case kSeekNonEoTracklet:
1143         case kDecodeHC:
1144           {
1145             if (DecodeHC() == kFALSE)
1146               {
1147                 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));     
1148               }
1149             else
1150               {
1151                 //the hc header should be decoded by now
1152                 if (fLastStatus == kDecodeHC)
1153                   {
1154                     fLastDET = fDET;
1155                     fChamberDone[fDET]++;
1156                   }
1157               }
1158           }; break;
1159         case kNextSM:
1160           {
1161             if (DecodeSM() == kFALSE)
1162                 AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));     
1163           }; break;
1164         case kStop:
1165           ; break;
1166         default:
1167           AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));  
1168           ChangeStatus(kStop);
1169         };
1170
1171     } // not kStop
1172
1173   //AliDebug(1, Form("That's all folks! %d", fSM));
1174   return kFALSE;
1175 }
1176
1177 //____________________________________________________________________________
1178 Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man)
1179 {
1180   //
1181   // Fills single chamber digit array 
1182   // Return value is the detector number
1183   //
1184
1185   AliTRDdataArrayI *digits = 0;
1186   AliTRDdataArrayI *track0 = 0;
1187   AliTRDdataArrayI *track1 = 0;
1188   AliTRDdataArrayI *track2 = 0; 
1189   AliTRDSignalIndex *indexes = 0;
1190           
1191   if (fNextStatus == kStart)
1192     {
1193       Init();
1194     }
1195
1196 //   while (fNextStatus != kStop)
1197 //     { // !kStop
1198 //       NextData();
1199 //       // catch 3 things
1200 //       // 1) if end of raw data - if chamber complete return
1201 //       // 2) fill the data with signals if data decoded ok
1202 //       // 3) initialize (destroy old) after the det has changed -> just after HC header decoding
1203 //     } // not kStop
1204
1205   while (fNextStatus != kStop)
1206     { // !kStop
1207       NextData();
1208
1209       switch (fNextStatus)
1210         {
1211           
1212         case kNextData:
1213           {
1214             if (DecodeNextRawWord() == kTRUE)
1215               {
1216                 for (Int_t it = 0; it < 3; it++)
1217                   {
1218                     if ( fTB + it < fTBins )
1219                       {
1220                         if ( fSig[it] > fRawDigitThreshold )
1221                           {
1222                             digits->SetDataUnchecked(fROW, fCOL, fTB + it, fSig[it]);
1223                             indexes->AddIndexTBin(fROW, fCOL, fTB + it);
1224                             if (man->UsesDictionaries())
1225                               {
1226                                 track0->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1227                                 track1->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1228                                 track2->SetDataUnchecked(fROW, fCOL, fTB + it, 0);
1229                               } // if dictionaries
1230                           } // signal above zero
1231                       } // check the tbins range
1232                   } // for each tbin of current 3             
1233                 fTB += 3;
1234               }
1235             else
1236               {
1237                 // can be here as a fall back from decode raw data calling decodemcm
1238                 if (fEndOfDataFlag == kTRUE)
1239                   {
1240                     if (fChamberDone[fDET] == 2)
1241                       {
1242                         return fDET;
1243                       }                         
1244                     fEndOfDataFlag = kFALSE;
1245                   }             
1246               }
1247           }; break;
1248
1249         case kNextMCM:
1250           {
1251             if (DecodeMCM() == kFALSE)
1252               {
1253                 AliWarning(Form("Decode MCM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));    
1254               }
1255             // default place for end of raw data...
1256             if (fEndOfDataFlag == kTRUE)
1257               {
1258                 if (fChamberDone[fDET] == 2)
1259                   {
1260                     return fDET;
1261                   }                             
1262                 fEndOfDataFlag = kFALSE;
1263               }      
1264           }; break;
1265
1266         case kNextHC:
1267         case kSeekNonEoTracklet:
1268         case kDecodeHC:
1269           {
1270             if (DecodeHC() == kFALSE)
1271               {
1272                 AliWarning(Form("Decode HC unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));     
1273               }
1274             else
1275               {
1276                 //the hc header should be decoded by now
1277                 if (fLastStatus == kDecodeHC)
1278                   {
1279 //                  AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET));
1280                     // allocate stuff for the new det
1281                     //man->ResetArrays();
1282                     digits = man->GetDigits(fDET);
1283                     track0 = man->GetDictionary(fDET,0);
1284                     track1 = man->GetDictionary(fDET,1);
1285                     track2 = man->GetDictionary(fDET,2);
1286                     
1287                     // Allocate memory space for the digits buffer
1288                     if (digits->GetNtime() == 0) 
1289                       {
1290 //                      AliDebug(5, Form("Alloc digits for det %d rows %d cols %d tbins %d", fDET, fRowMax, fColMax, fTBins));
1291                         digits->Allocate(fRowMax, fColMax, fTBins);
1292                         if (man->UsesDictionaries())
1293                           {
1294                             track0->Allocate(fRowMax, fColMax, fTBins);
1295                             track1->Allocate(fRowMax, fColMax, fTBins);
1296                             track2->Allocate(fRowMax, fColMax, fTBins);
1297                           }
1298                       }
1299                     
1300                     indexes = man->GetIndexes(fDET);
1301                     indexes->SetSM(fSM);
1302                     indexes->SetStack(fSTACK);
1303                     indexes->SetLayer(fLAYER);
1304                     indexes->SetDetNumber(fDET);
1305                     
1306                     if (indexes->IsAllocated() == kFALSE)
1307                       {
1308 //                      AliDebug(4, "Allocating indexes");            
1309                         indexes->Allocate(fRowMax, fColMax, fTBins);
1310                       }
1311                   } // is the HC header already decoded?
1312               } // decode hc ok
1313           }; break;
1314
1315         case kNextSM:
1316           {
1317             if (DecodeSM() == kFALSE)
1318               AliWarning(Form("Decode SM unsuccessfull. Current Word 0x%x at pos 0x%x", *fDataWord, fPos));       
1319           }; break;
1320
1321         case kStop:
1322           ; break;
1323
1324         default:
1325           AliWarning(Form("Unknown state %d. Last state %d. Current Word 0x%x at pos 0x%x", fNextStatus, fLastStatus, *fDataWord, fPos));  
1326           ChangeStatus(kStop);
1327         };
1328
1329     } // not kStop
1330
1331   // we do not return chambers for which the end-of-data was not received twice (for each HC)
1332
1333   //AliDebug(1, Form("That's all folks! %d", fSM));
1334   //return kFALSE;
1335   return -1;
1336 }