]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCADataCompressor.h
bug fix: reconstruction crash when the output buffer size exceed
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCADataCompressor.h
1 //-*- Mode: C++ -*-
2 // ************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project        *
4 // ALICE Experiment at CERN, All rights reserved.                         *
5 // See cxx source for full Copyright notice                               *
6 //                                                                        *
7 //*************************************************************************
8
9 #ifndef ALIHLTTPCCADATACOMPRESSOR_H
10 #define ALIHLTTPCCADATACOMPRESSOR_H
11
12 #include "AliHLTTPCCADef.h"
13
14 /**
15  * @class AliHLTTPCCADataCompressor
16  *
17  * The AliHLTTPCCADataCompressor class is used to
18  * pack and unpack diffferent data, such as TPC cluster IDs, posistion, amplitude etc
19  *
20  */
21 class AliHLTTPCCADataCompressor
22 {
23   public:
24
25     GPUhd() static unsigned int IRowIClu2IDrc( unsigned int iRow, unsigned int iCluster ) {
26       return ( iCluster << 8 ) + iRow;
27     }
28
29     GPUhd() static unsigned int IDrc2IRow( unsigned int IDrc ) { return ( IDrc % 256 ); }
30     GPUhd() static unsigned int IDrc2IClu( unsigned int IDrc ) { return ( IDrc >> 8  ); }
31
32
33     GPUhd() static unsigned int ISliceIRowIClu2IDsrc( unsigned int iSlice, unsigned int iRow, unsigned int iCluster ) {
34       return ( iCluster << 14 ) + ( iRow << 6 ) + iSlice;
35     }
36
37     GPUhd() static unsigned int IDsrc2ISlice( unsigned int IDsrc ) {  return (  IDsrc % 64      ); }
38     GPUhd() static unsigned int IDsrc2IRow  ( unsigned int IDsrc ) {  return ( ( IDsrc >> 6 ) % 256 ); }
39     GPUhd() static unsigned int IDsrc2IClu  ( unsigned int IDsrc ) {  return (  IDsrc >> 14     ); }
40
41
42     GPUhd() static unsigned short YZ2UShort( float Y, float Z );
43     GPUhd() static float  UShort2Y ( unsigned short iYZ );
44     GPUhd() static float  UShort2Z ( unsigned short iYZ );
45
46 };
47
48
49 // Inline methods
50
51
52 GPUhd() inline unsigned short AliHLTTPCCADataCompressor::YZ2UShort( float Y, float Z )
53 {
54   // compress Y and Z coordinates in range [-3., 3.] to 16 bits
55
56   const float kMult = 255. / 6.;
57   Y = ( Y + 3.f ) * kMult;
58   Z = ( Z + 3.f ) * kMult;
59   if ( Y < 0. ) Y = 0.;
60   else if ( Y > 255. ) Y = 255.;
61   if ( Z < 0. ) Z = 0.;
62   else if ( Z > 255. ) Z = 255.;
63   return static_cast<unsigned short>( ( static_cast<unsigned int>( Y ) << 8 ) + static_cast<unsigned int>( Z ) );
64 }
65
66 GPUhd() inline float AliHLTTPCCADataCompressor::UShort2Y( unsigned short iYZ )
67 {
68   // extract Y coordinate from the compressed 16bits format to [-3.,3.]
69
70   const float kMult = 6.f / 255.f;
71   return ( iYZ >> 8 )*kMult - 3.f;
72 }
73
74 GPUhd() inline float AliHLTTPCCADataCompressor::UShort2Z( unsigned short iYZ )
75 {
76   // extract Z coordinate from the compressed 16bits format to [-3.,3.]
77
78   const float kMult = 6.f / 255.f;
79   return ( iYZ % 256 )*kMult - 3.f;
80 }
81
82 #endif //ALIHLTTPCCADATACOMPRESSOR_H