]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitReaderRaw.cxx
2526cd700e8b575ea0feef583da4ec68b2ff22e0
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderRaw.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
7  *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
8  *          Jochen Thaeder <thaeder@kip.uni-heidelberg.de>                *
9  *          for The ALICE Off-line Project.                               *
10  *                                                                        *
11  * Permission to use, copy, modify and distribute this software and its   *
12  * documentation strictly for non-commercial purposes is hereby granted   *
13  * without fee, provided that the above copyright notice appears in all   *
14  * copies and that both the copyright notice and this permission notice   *
15  * appear in the supporting documentation. The authors make no claims     *
16  * about the suitability of this software for any purpose. It is          *
17  * provided "as is" without express or implied warranty.                  *
18  **************************************************************************/
19
20 /** @file   AliHLTTPCDigitReaderRaw.cxx
21     @author Timm Steinbeck
22     @date   
23     @brief  A digit reader implementation for the RAW data coming from the RCU.
24 */
25
26 #if __GNUC__>= 3
27 using namespace std;
28 #endif
29
30 #if defined(HAVE_TPC_MAPPING)
31
32 #include "AliHLTTPCDigitReaderRaw.h"
33 #include "AliHLTTPCTransform.h"
34 #include "AliHLTTPCRootTypes.h"
35 #include "AliHLTTPCStandardIncludes.h"
36 #include "AliHLTTPCLogging.h"
37
38 ClassImp(AliHLTTPCDigitReaderRaw)
39
40 AliHLTTPCDigitReaderRaw::AliHLTTPCDigitReaderRaw( unsigned formatVersion )
41   :
42   fBuffer(NULL),
43   fBufferSize(0),
44   fPatch(-1),
45   fSlice(-1),
46   fDataFormatVersion(formatVersion),
47   fCurrentRow(0),
48   fCurrentPad(0),
49   fCurrentBin(-1),
50   fVerify(false),
51   
52   // For sorting
53   fNRows(0),
54   fRowOffset(0),
55   fNMaxRows(0),
56   fNMaxPads(0),
57   fNTimeBins(0),
58   fData(NULL)
59 {
60     if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
61       {
62         
63         // get max number of rows
64         for (Int_t ii=0; ii < 6; ii++)
65           if (AliHLTTPCTransform::GetNRows(ii) > fNMaxRows) 
66             fNMaxRows = AliHLTTPCTransform::GetNRows(ii);
67         
68         // get max number of pads
69         for (Int_t ii=0; ii < AliHLTTPCTransform::GetNRows();ii++ )
70           if (AliHLTTPCTransform::GetNPads(ii) > fNMaxPads) 
71             fNMaxPads = AliHLTTPCTransform::GetNPads(ii);
72         
73         // get max number of bins
74         fNTimeBins = AliHLTTPCTransform::GetNTimeBins();
75         
76         HLTDebug("Array Borders ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d", 
77                  fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads);
78         
79         // init Data array
80         fData = new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
81       }
82 }
83
84 AliHLTTPCDigitReaderRaw::AliHLTTPCDigitReaderRaw(const AliHLTTPCDigitReaderRaw& src)
85   :
86   fBuffer(NULL),
87   fBufferSize(0),
88   fPatch(-1),
89   fSlice(-1),
90   fDataFormatVersion(src.fDataFormatVersion),
91   fCurrentRow(0),
92   fCurrentPad(0),
93   fCurrentBin(-1),
94   fVerify(false),
95   
96   // For sorting
97   fNRows(0),
98   fRowOffset(0),
99   fNMaxRows(0),
100   fNMaxPads(0),
101   fNTimeBins(0),
102   fData(NULL)
103 {
104   HLTFatal("copy constructor not for use");
105 }
106
107 AliHLTTPCDigitReaderRaw& AliHLTTPCDigitReaderRaw::operator=(const AliHLTTPCDigitReaderRaw& src)
108 {
109   fBuffer=NULL;
110   fBufferSize=0;
111   fPatch=-1;
112   fSlice=-1;
113   fDataFormatVersion=src.fDataFormatVersion;
114   fCurrentRow=0;
115   fCurrentPad=0;
116   fCurrentBin=-1;
117   fVerify=false;
118   
119   // For sorting
120   fNRows=0;
121   fRowOffset=0;
122   fNMaxRows=0;
123   fNMaxPads=0;
124   fNTimeBins=0;
125   fData=NULL;
126   HLTFatal("assignment operator not for use");
127   return (*this);
128 }
129
130 AliHLTTPCDigitReaderRaw::~AliHLTTPCDigitReaderRaw(){
131   if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
132     {
133       if ( fData )
134         delete [] fData;
135       fData = NULL;
136     }
137 }
138
139 int AliHLTTPCDigitReaderRaw::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
140
141     fBuffer = (AliHLTUInt8_t*) ptr;
142     if (fBuffer==NULL) {
143       HLTError("invalid data buffer");
144       return -EINVAL;
145     }
146     fBufferSize = size;
147     if (fBufferSize<=0) HLTWarning("no data available: zero length buffer");
148     fPatch = patch;
149     fSlice = slice;
150     fPad = -1;
151     fRow = -1;
152     
153     fAltroBlockPositionBytes = 0;
154     fAltroBlockLengthBytes = 0;
155     fAltroBlock10BitWordCnt = 0xFFFFU;
156     fAltroBlockHWAddress = 0xFFFFU;
157     fBunchPosition = 0xFFFFU;
158     fBunchTimebinStart = ~0U;
159     fBunchLength = 0;
160     fWordInBunch = (unsigned)-1;
161
162     Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch);
163     Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch);
164
165     if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
166       {
167         fCurrentRow = 0;
168         fCurrentPad = 0;
169         fCurrentBin = -1;
170         
171         fNRows = lastrow - firstrow + 1;
172         
173         Int_t offset=0;
174         if (patch > 1) offset =  AliHLTTPCTransform::GetFirstRow( 2 );
175         
176         fRowOffset = firstrow - offset;
177         firstrow -= offset;
178         lastrow  -= offset;
179         
180         // Init array with -1
181         memset( fData, 0xFF, sizeof(Int_t)*(fNMaxRows*fNMaxPads*fNTimeBins) );
182
183         const Int_t maxErrorPrintout=20;
184         Int_t errorCount=0;
185         Int_t entryCount=0;
186         // read data and fill in array
187
188         while( RealNext()){
189
190           entryCount++;
191           Int_t row = GetRealRow();
192           Int_t pad = GetRealPad();
193           Int_t bin = GetRealTime();
194           
195 //        HLTFatal("Index out of array range: PAD=%d ||| ROW=%d ||| BIN=%d ||| OFFSET=%d ||| ROWOFFSET=%d", pad, row, bin, offset, fRowOffset);
196
197           if ( row < firstrow || row > lastrow || pad > AliHLTTPCTransform::GetNPads(row + offset) || bin > fNTimeBins || pad<0 || bin<0){
198 //        if ( row < firstrow || row > lastrow || pad > AliHLTTPCTransform::GetNPads(row + offset) || bin > fNTimeBins){
199             if (errorCount++<maxErrorPrintout) {
200               HLTFatal("Index out of range. Probably wrong patch! slice %d - patch %d", slice, patch);
201               HLTFatal("PAD=%d out of %d ||| ROW=%d (%d to %d)  ||| BIN=%d out of %d  ||| OFFSET=%d ||| ROWOFFSET=%d",
202                        pad, AliHLTTPCTransform::GetNPads(row + offset), row, firstrow, lastrow, bin, fNTimeBins,
203                        offset, fRowOffset);
204
205               if ( row < firstrow || row > lastrow ) 
206                 HLTFatal("Row out of range: %d  ( %d to %d)", row, firstrow, lastrow);
207               if ( pad > AliHLTTPCTransform::GetNPads(row + offset) ) 
208                 HLTFatal("Pad out of range: %d  (pad count %d)", pad, AliHLTTPCTransform::GetNPads(row + offset));
209               if ( bin > fNTimeBins )
210                 HLTFatal("Time bin out of range: %d (bin count %d)", bin, fNTimeBins);
211             }
212             continue;
213           } else if ((row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin >=  fNMaxRows*fNMaxPads*fNTimeBins ) {
214             if (errorCount++<maxErrorPrintout) {
215               HLTFatal("index out of range: PAD=%d ||| ROW=%d ||| BIN=%d ||| OFFSET=%d ||| ROWOFFSET=%d", pad, row, bin, offset, fRowOffset);
216             }
217             continue;
218           } else {
219             fData[ (row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin ] = GetRealSignal() ;
220           }
221         }
222         if (errorCount>0) {
223           HLTFatal("%d of %d entries out of range", errorCount, entryCount);
224         }
225       }
226
227     return 0;
228 }
229
230 bool AliHLTTPCDigitReaderRaw::Next(){
231   if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
232     {
233       Bool_t readvalue = kTRUE;
234       while (1) {
235         fCurrentBin++;
236         if (fCurrentBin >= fNTimeBins){
237           fCurrentBin = 0;
238           fCurrentPad++;
239           
240           if (fCurrentPad >=fNMaxPads){
241             fCurrentPad = 0;
242             fCurrentRow++;
243             
244             if (fCurrentRow >= fNMaxRows){
245               readvalue = kFALSE;
246               break;
247             }
248           }
249         }
250         
251         if (fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin >=  fNMaxRows*fNMaxPads*fNTimeBins ) {
252           HLTFatal("Overflow: fCurrentRow=%d fCurrentPad=%d fCurrentBin=%d", fCurrentRow, fCurrentPad, fCurrentBin);
253           readvalue = kFALSE;
254           break;
255         }
256         
257         if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin  ] != -1) break;
258       }
259       return readvalue;
260     }
261   else
262     return RealNext();
263 }
264
265 int AliHLTTPCDigitReaderRaw::GetRow(){
266   if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
267     {
268       return (fCurrentRow + fRowOffset);
269     }
270   else
271     return GetRealRow();
272 }
273 int AliHLTTPCDigitReaderRaw::GetPad(){
274   if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
275     {
276       return fCurrentPad;
277     }
278   else
279     return GetRealPad();
280 }
281 int AliHLTTPCDigitReaderRaw::GetSignal(){
282   if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
283     {
284       return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
285     }
286   else
287     return GetRealSignal();
288 }
289 int AliHLTTPCDigitReaderRaw::GetTime(){
290   if ( fDataFormatVersion==0 || fDataFormatVersion==2 )
291     {
292       return fCurrentBin;
293     }
294   else
295     return GetRealTime();
296 }
297
298
299 bool AliHLTTPCDigitReaderRaw::RealNext(){
300 //    printf( "%u %u %u %u %u\n", fBunchPosition, fBunchLength, fBunchTimebinStart, fWordInBunch, (unsigned)fAltroBlock10BitWordCnt );
301     fWordInBunch++; // use next word in bunch
302     if ( fWordInBunch==fBunchLength ) { // we have a bunch at all but have reached its end (or do not have an altro block yet)
303         if ( fBunchPosition+fBunchLength==fAltroBlock10BitWordCnt ) { // We were at the last bunch of this altro block (or do not have an altro block yet)
304             if ( !NextAltroBlock() )
305                 return false;
306             fBunchPosition = 0;
307         }
308         else {
309             fBunchPosition += fBunchLength;
310         }
311         fBunchLength = GetAltroBlock10BitWord( fBunchPosition );
312         fBunchTimebinStart = GetAltroBlock10BitWord( fBunchPosition+1 );
313         fWordInBunch = 2;
314     }
315     //HLTDebug( "%u %u %u %u %u\n", fBunchPosition, fBunchLength, fBunchTimebinStart, fWordInBunch, (unsigned)fAltroBlock10BitWordCnt );
316     return true;
317 }
318 int AliHLTTPCDigitReaderRaw::GetRealRow(){
319     return fRow;
320 }
321 int AliHLTTPCDigitReaderRaw::GetRealPad(){
322     return fPad;
323 }
324 int AliHLTTPCDigitReaderRaw::GetRealSignal(){
325     return GetAltroBlock10BitWord( fBunchPosition+fWordInBunch );
326 }
327 int AliHLTTPCDigitReaderRaw::GetRealTime(){
328   //HLTDebug( "GetRealTime: %u - %u\n", fBunchTimebinStart, fWordInBunch );
329     return fBunchTimebinStart-(fWordInBunch-2);
330 }
331
332 AliHLTUInt32_t AliHLTTPCDigitReaderRaw::GetRCUTrailer(){
333   if (fBufferSize<=0) return 0;
334   unsigned rcuDataBlockLen = GetRCUDataBlockLength(); 
335   return *((AliHLTUInt32_t*)(fBuffer+fBufferSize-rcuDataBlockLen));
336 }
337
338 bool AliHLTTPCDigitReaderRaw::NextAltroBlock()
339     {
340     if (fBufferSize<=0) return 0;
341     if ( !fAltroBlockLengthBytes )
342         {
343         // First block in back linked list (last block in memory)
344         fAltroBlockPositionBytes = fBufferSize-GetRCUDataBlockLength();
345         }
346     else
347         {
348         if ( fAltroBlockPositionBytes<fAltroBlockLengthBytes+GetCommonDataHeaderSize() )
349           {
350             HLTFatal("Inconsistent Data: fAltroBlockPositionBytes=%d fAltroBlockLengthBytes=%d", fAltroBlockPositionBytes, fAltroBlockLengthBytes);
351           }
352         if ( fAltroBlockPositionBytes<=fAltroBlockLengthBytes+GetCommonDataHeaderSize() )
353             return false; // We have reached the end of the back linked list
354         fAltroBlockPositionBytes -= fAltroBlockLengthBytes;
355         }
356
357       AliHLTUInt64_t altroTrailerWord = GetAltroBlock40BitWord( 0 );
358
359       if ( fVerify && ((altroTrailerWord & 0xFFFC000000ULL)!=0xAAA8000000ULL) )
360         {
361           HLTFatal("Data inconsistency in Altro Block at byte position %#x (%d): Expected 0x2AAA in high 14 bits of altro trailer word; Found %#llx (%#llx)",
362                    fAltroBlockPositionBytes, fAltroBlockPositionBytes, 
363                    ((altroTrailerWord & 0xFFFC000000ULL) >> 26), altroTrailerWord);
364
365
366           return false;
367         }
368
369       if ( fVerify && ((altroTrailerWord & 0x000000F000ULL)!=0x000000A000ULL) )
370         {
371           HLTFatal("Data inconsistency in Altro Block at byte position %#x (%d): Expected 0xA in bits 12-15 of altro trailer word; Found %#llx .",
372                    fAltroBlockPositionBytes, fAltroBlockPositionBytes,  ((altroTrailerWord & 0x000000F000ULL) >> 12)); 
373
374           return false;
375         }
376
377       fAltroBlock10BitWordCnt = (altroTrailerWord >> 16) & 0x3FF;
378       fAltroBlockHWAddress = altroTrailerWord & 0xFFF;
379
380       // ApplyMapping
381       if (!ApplyMapping())
382         {
383           HLTFatal("Mapping failed Patch %d HWA %#x (%d) - maxHWA %#x (%d)",
384                    fPatch, fAltroBlockHWAddress, fAltroBlockHWAddress, fMaxHWA[fPatch], fMaxHWA[fPatch]);
385
386         }
387
388       unsigned words40Bit = fAltroBlock10BitWordCnt/4;
389       if ( fAltroBlock10BitWordCnt % 4 )
390           words40Bit++;
391       words40Bit++;
392       fAltroBlockLengthBytes = words40Bit*5;
393     if ( fAltroBlock10BitWordCnt % 4 )
394         fAltroBlock10BitFillWordCnt = 4-(fAltroBlock10BitWordCnt % 4);
395     else
396         fAltroBlock10BitFillWordCnt=0;
397     if ( fVerify )
398       {
399         for ( unsigned b = 0; b < fAltroBlock10BitFillWordCnt; b++ )
400           {
401             if ( GetAltroBlockReal10BitWord(b)!=0x2AA )
402               {
403                 HLTFatal("Data inconsistency in trailing 10 bit fill word of Altro Block at byte position %#x (%d): Expected 0x2AA; Found %#x",
404                          fAltroBlockPositionBytes, fAltroBlockPositionBytes, GetAltroBlockReal10BitWord(b));
405                 
406                 return false;
407               }
408           }
409       }
410     return true;
411     }
412
413 AliHLTUInt32_t AliHLTTPCDigitReaderRaw::GetAltroBlockHWaddr(){
414 return fAltroBlockHWAddress;
415 }
416 unsigned AliHLTTPCDigitReaderRaw::GetAltroBlock10BitWordCnt(){
417 return fAltroBlock10BitWordCnt;
418 }
419 AliHLTUInt64_t AliHLTTPCDigitReaderRaw::GetAltroBlock40BitWord( unsigned long ndx ){
420 AliHLTUInt64_t val=0;
421 unsigned wordOffset32Bit = (ndx / 4)*5;
422 switch ( ndx % 4 ) // 40 bit word index in a 4*40 bit=5*32 bit group
423     {
424     case 0:
425         val = (*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+1)*sizeof(AliHLTUInt32_t)));
426         val <<= 8;
427         val |= (*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+2)*sizeof(AliHLTUInt32_t))) >> 24;
428         break;
429     case 1:
430         val = ((*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+2)*sizeof(AliHLTUInt32_t))) & 0x00FFFFFF);
431         val <<= 16;
432         val |= ((*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+3)*sizeof(AliHLTUInt32_t))) >> 16) & 0xFFFF;
433         break;
434     case 2:
435         val = ((*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+3)*sizeof(AliHLTUInt32_t))) & 0xFFFF);
436         val <<= 24;
437         val |= ((*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+4)*sizeof(AliHLTUInt32_t))) >> 8);
438         break;
439     case 3:
440         val = ((*(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+4)*sizeof(AliHLTUInt32_t))) & 0xFF);
441         val <<= 32;
442         val |= *(AliHLTUInt32_t*)(fBuffer+fAltroBlockPositionBytes-(wordOffset32Bit+5)*sizeof(AliHLTUInt32_t));
443         break;
444     }
445 return val;
446 }
447 AliHLTUInt16_t AliHLTTPCDigitReaderRaw::GetAltroBlock10BitWord( unsigned long ndx ){
448 unsigned long realNdx = ndx+fAltroBlock10BitFillWordCnt;
449 unsigned long word40BitNdx = (realNdx / 4)+1;
450 AliHLTUInt64_t word40Bit = GetAltroBlock40BitWord( word40BitNdx );
451 switch ( realNdx % 4 )
452     {
453     case 3:
454         return word40Bit & 0x3FF;
455     case 2:
456         return (word40Bit>>10) & 0x3FF;
457     case 1:
458         return (word40Bit>>20) & 0x3FF;
459     case 0:
460         return (word40Bit>>30) & 0x3FF;
461     }
462
463  return 0xFFFF; 
464 }
465
466 AliHLTUInt16_t AliHLTTPCDigitReaderRaw::GetAltroBlockReal10BitWord( unsigned long ndx ){
467 unsigned long word40BitNdx = (ndx / 4)+1;
468 AliHLTUInt64_t word40Bit = GetAltroBlock40BitWord( word40BitNdx );
469 switch ( ndx % 4 )
470     {
471     case 3:
472         return word40Bit & 0x3FF;
473     case 2:
474         return (word40Bit>>10) & 0x3FF;
475     case 1:
476         return (word40Bit>>20) & 0x3FF;
477     case 0:
478         return (word40Bit>>30) & 0x3FF;
479     }
480
481  return 0xFFFF; 
482 }
483
484 // Return length of trailing RCU data block in bytes
485 unsigned AliHLTTPCDigitReaderRaw::GetRCUDataBlockLength() const
486     {
487     switch ( fDataFormatVersion )
488         {
489         case 0:
490         case 1:
491             return 4;
492             break;
493         case 2:
494         case 3:
495             return 12;
496             break;
497         default:
498             return fBufferSize;
499         }
500     }
501
502 unsigned AliHLTTPCDigitReaderRaw::GetCommonDataHeaderSize() const
503     {
504     return 32;
505     }
506
507
508 Bool_t AliHLTTPCDigitReaderRaw::ApplyMapping(){
509
510     if ( (unsigned)fAltroBlockHWAddress > fMaxHWA[fPatch]){
511         fPad = -1;
512         fRow = -1;
513         return kFALSE;
514     }
515
516     switch(fPatch){
517         case 0:
518             fRow = fMapping_0[(unsigned)fAltroBlockHWAddress][0];
519             fPad = fMapping_0[(unsigned)fAltroBlockHWAddress][1];
520             break;
521         case 1:
522             fRow = AliHLTTPCDigitReaderRaw::fMapping_1[(unsigned)fAltroBlockHWAddress][0];
523             fPad = AliHLTTPCDigitReaderRaw::fMapping_1[(unsigned)fAltroBlockHWAddress][1];
524 #if 0
525             printf ("pad %d # row %d (hwa: %u / 0x%08X\n", fMapping_1[(unsigned)fAltroBlockHWAddress][0],fMapping_1[(unsigned)fAltroBlockHWAddress][1], (unsigned)fAltroBlockHWAddress, (unsigned)fAltroBlockHWAddress);
526             printf ("pad %d # row %d (hwa: %u / 0x%08X\n", fMapping_1[(unsigned)fAltroBlockHWAddress-1][0],fMapping_1[(unsigned)fAltroBlockHWAddress-1][1], (unsigned)fAltroBlockHWAddress-1, (unsigned)fAltroBlockHWAddress-1);
527             printf ("pad %d # row %d (hwa: %u / 0x%08X\n", fMapping_1[(unsigned)fAltroBlockHWAddress+1][0],fMapping_1[(unsigned)fAltroBlockHWAddress+1][1], (unsigned)fAltroBlockHWAddress+1, (unsigned)fAltroBlockHWAddress+1);
528 #endif
529             break;
530         case 2:
531             fRow = fMapping_2[(unsigned)fAltroBlockHWAddress][0];
532             fPad = fMapping_2[(unsigned)fAltroBlockHWAddress][1];
533             break;
534         case 3:
535             fRow = fMapping_3[(unsigned)fAltroBlockHWAddress][0];
536             fPad = fMapping_3[(unsigned)fAltroBlockHWAddress][1];
537             break;
538         case 4:
539             fRow = fMapping_4[(unsigned)fAltroBlockHWAddress][0];
540             fPad = fMapping_4[(unsigned)fAltroBlockHWAddress][1];
541             break;
542         case 5:
543             fRow = fMapping_5[(unsigned)fAltroBlockHWAddress][0];
544             fPad = fMapping_5[(unsigned)fAltroBlockHWAddress][1];
545             break;
546         default:
547             fRow = -1;
548             fPad = -1;
549             return kFALSE;
550     }
551     return kTRUE;
552 }
553
554
555 Int_t AliHLTTPCDigitReaderRaw::GetRow( unsigned patch, unsigned hw_addr )
556 {
557     if ( (unsigned)hw_addr > fMaxHWA[fPatch]){
558         return -1;
559     }
560
561     switch(fPatch){
562         case 0:
563             return fMapping_0[hw_addr][0];
564         case 1:
565             return fMapping_1[hw_addr][0];
566         case 2:
567             return fMapping_2[hw_addr][0];
568         case 3:
569             return fMapping_3[hw_addr][0];
570         case 4:
571             return fMapping_4[hw_addr][0];
572         case 5:
573             return fMapping_5[hw_addr][0];
574         default:
575           return -1;
576     }
577 }
578 Int_t AliHLTTPCDigitReaderRaw::GetPad( unsigned patch, unsigned hw_addr )
579 {
580     if ( (unsigned)hw_addr > fMaxHWA[fPatch]){
581         return -1;
582     }
583
584     switch(fPatch){
585         case 0:
586             return fMapping_0[hw_addr][1];
587         case 1:
588             return fMapping_1[hw_addr][1];
589         case 2:
590             return fMapping_2[hw_addr][1];
591         case 3:
592             return fMapping_3[hw_addr][1];
593         case 4:
594             return fMapping_4[hw_addr][1];
595         case 5:
596             return fMapping_5[hw_addr][1];
597         default:
598           return -1;
599     }
600 }
601
602 unsigned AliHLTTPCDigitReaderRaw::GetMaxHWA( unsigned patch )
603 {
604   if ( patch>=6 )
605     return 0;
606   return fMaxHWA[patch];
607 }
608
609
610 // ----- MAPPING ARRAYS
611 #include "mapping_array_out.inc"
612
613 #endif //#if defined(HAVE_TPC_MAPPING)