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 *
7 //*************************************************************************
9 #ifndef ALIHLTTPCCADATACOMPRESSOR_H
10 #define ALIHLTTPCCADATACOMPRESSOR_H
12 #include "AliHLTTPCCADef.h"
13 #include "AliHLTTPCCACompressedInputData.h"
16 * @class AliHLTTPCCADataCompressor
18 * The AliHLTTPCCADataCompressor class is used to
19 * pack and unpack diffferent data, such as TPC cluster IDs, posistion, amplitude etc
22 class AliHLTTPCCADataCompressor
26 GPUhd() static unsigned int IRowIClu2IDrc( unsigned int iRow, unsigned int iCluster ) {
27 return ( iCluster << 8 ) + iRow;
30 GPUhd() static unsigned int IDrc2IRow( unsigned int IDrc ) { return ( IDrc % 256 ); }
31 GPUhd() static unsigned int IDrc2IClu( unsigned int IDrc ) { return ( IDrc >> 8 ); }
34 GPUhd() static unsigned int ISliceIRowIClu2IDsrc( unsigned int iSlice, unsigned int iRow, unsigned int iCluster ) {
35 return ( iCluster << 14 ) + ( iRow << 6 ) + iSlice;
38 GPUhd() static unsigned int IDsrc2ISlice( unsigned int IDsrc ) { return ( IDsrc % 64 ); }
39 GPUhd() static unsigned int IDsrc2IRow ( unsigned int IDsrc ) { return ( ( IDsrc >> 6 ) % 256 ); }
40 GPUhd() static unsigned int IDsrc2IClu ( unsigned int IDsrc ) { return ( IDsrc >> 14 ); }
43 GPUhd() static unsigned short YZ2UShort( float Y, float Z );
44 GPUhd() static float UShort2Y ( unsigned short iYZ );
45 GPUhd() static float UShort2Z ( unsigned short iYZ );
47 static AliHLTTPCCACompressedCluster PackXYZ( int iRow, float X, float Y, float Z )
51 // get coordinates in [um]
53 Double_t rowX = GetRowX( iRow );
55 Double_t x = (X - rowX )*1.e4 + 32768.;
56 Double_t y = Y*1.e4 + 8388608.;
57 Double_t z = Z*1.e4 + 8388608.;
59 // truncate if necessary
60 if( x<0 ) x = 0; else if( x > 0x0000FFFF ) x = 0x0000FFFF;
61 if( y<0 ) y = 0; else if( y > 0x00FFFFFF ) y = 0x00FFFFFF;
62 if( z<0 ) z = 0; else if( z > 0x00FFFFFF ) z = 0x00FFFFFF;
64 UInt_t ix0 = ( (UInt_t) x )&0x000000FF;
65 UInt_t ix1 = (( (UInt_t) x )&0x0000FF00 )>>8;
66 UInt_t iy = ( (UInt_t) y )&0x00FFFFFF;
67 UInt_t iz = ( (UInt_t) z )&0x00FFFFFF;
69 AliHLTTPCCACompressedCluster ret;
70 ret.fP0 = (ix0<<24) + iy;
71 ret.fP1 = (ix1<<24) + iz;
75 static void UnpackXYZ( int iRow, AliHLTTPCCACompressedCluster C, float &X, float &Y, float &Z )
77 Double_t rowX = GetRowX( iRow );
79 UInt_t ix0 = C.fP0 >>24;
80 UInt_t ix1 = C.fP1 >>24;
81 X = (float) ((ix1<<8) + ix0);
82 Y = (float) (C.fP0 & 0x00FFFFFF);
83 Z = (float) (C.fP1 & 0x00FFFFFF);
84 X = (float) ((X - 32768.)*1.e-4 + rowX);
85 Y = (float) ((Y - 8388608.)*1.e-4);
86 Z = (float) ((Z - 8388608.)*1.e-4);
89 static float GetRowX( int iRow ){
90 const float fgX[159] =
259 GPUhd() inline unsigned short AliHLTTPCCADataCompressor::YZ2UShort( float Y, float Z )
261 // compress Y and Z coordinates in range [-3., 3.] to 16 bits
263 const float kMult = 255. / 6.;
264 Y = ( Y + 3.f ) * kMult;
265 Z = ( Z + 3.f ) * kMult;
266 if ( Y < 0. ) Y = 0.;
267 else if ( Y > 255. ) Y = 255.;
268 if ( Z < 0. ) Z = 0.;
269 else if ( Z > 255. ) Z = 255.;
270 return static_cast<unsigned short>( ( static_cast<unsigned int>( Y ) << 8 ) + static_cast<unsigned int>( Z ) );
273 GPUhd() inline float AliHLTTPCCADataCompressor::UShort2Y( unsigned short iYZ )
275 // extract Y coordinate from the compressed 16bits format to [-3.,3.]
277 const float kMult = 6.f / 255.f;
278 return ( iYZ >> 8 )*kMult - 3.f;
281 GPUhd() inline float AliHLTTPCCADataCompressor::UShort2Z( unsigned short iYZ )
283 // extract Z coordinate from the compressed 16bits format to [-3.,3.]
285 const float kMult = 6.f / 255.f;
286 return ( iYZ % 256 )*kMult - 3.f;
289 #endif //ALIHLTTPCCADATACOMPRESSOR_H