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