]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCADataCompressor.h
Temporary protection if one runs raw->sdigits for the real data.
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCADataCompressor.h
CommitLineData
63d8b79d 1//-*- Mode: C++ -*-
2// ************************************************************************
fbb9b71b 3// This file is property of and copyright by the ALICE HLT Project *
63d8b79d 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"
70e4a065 13#include "AliHLTTPCCACompressedInputData.h"
14#include "AliHLTTPCTransform.h"
63d8b79d 15
16/**
17 * @class AliHLTTPCCADataCompressor
18 *
19 * The AliHLTTPCCADataCompressor class is used to
20 * pack and unpack diffferent data, such as TPC cluster IDs, posistion, amplitude etc
21 *
22 */
23class AliHLTTPCCADataCompressor
24{
fbb9b71b 25 public:
63d8b79d 26
fbb9b71b 27 GPUhd() static unsigned int IRowIClu2IDrc( unsigned int iRow, unsigned int iCluster ) {
28 return ( iCluster << 8 ) + iRow;
29 }
63d8b79d 30
fbb9b71b 31 GPUhd() static unsigned int IDrc2IRow( unsigned int IDrc ) { return ( IDrc % 256 ); }
32 GPUhd() static unsigned int IDrc2IClu( unsigned int IDrc ) { return ( IDrc >> 8 ); }
63d8b79d 33
63d8b79d 34
fbb9b71b 35 GPUhd() static unsigned int ISliceIRowIClu2IDsrc( unsigned int iSlice, unsigned int iRow, unsigned int iCluster ) {
36 return ( iCluster << 14 ) + ( iRow << 6 ) + iSlice;
37 }
63d8b79d 38
fbb9b71b 39 GPUhd() static unsigned int IDsrc2ISlice( unsigned int IDsrc ) { return ( IDsrc % 64 ); }
40 GPUhd() static unsigned int IDsrc2IRow ( unsigned int IDsrc ) { return ( ( IDsrc >> 6 ) % 256 ); }
41 GPUhd() static unsigned int IDsrc2IClu ( unsigned int IDsrc ) { return ( IDsrc >> 14 ); }
42
43
44 GPUhd() static unsigned short YZ2UShort( float Y, float Z );
45 GPUhd() static float UShort2Y ( unsigned short iYZ );
46 GPUhd() static float UShort2Z ( unsigned short iYZ );
63d8b79d 47
70e4a065 48 static AliHLTTPCCACompressedCluster PackXYZ( int iRow, float X, float Y, float Z )
49 {
50 // pack the cluster
51
52 // get coordinates in [um]
53
54 Double_t rowX = AliHLTTPCTransform::Row2X( iRow );
55
56 Double_t x = (X - rowX )*1.e4 + 32768.;
57 Double_t y = Y*1.e4 + 8388608.;
58 Double_t z = Z*1.e4 + 8388608.;
59
60 // truncate if necessary
61 if( x<0 ) x = 0; else if( x > 0x0000FFFF ) x = 0x0000FFFF;
62 if( y<0 ) y = 0; else if( y > 0x00FFFFFF ) y = 0x00FFFFFF;
63 if( z<0 ) z = 0; else if( z > 0x00FFFFFF ) z = 0x00FFFFFF;
64
65 UInt_t ix0 = ( (UInt_t) x )&0x000000FF;
66 UInt_t ix1 = (( (UInt_t) x )&0x0000FF00 )>>8;
67 UInt_t iy = ( (UInt_t) y )&0x00FFFFFF;
68 UInt_t iz = ( (UInt_t) z )&0x00FFFFFF;
69
70 AliHLTTPCCACompressedCluster ret;
71 ret.fP0 = (ix0<<24) + iy;
72 ret.fP1 = (ix1<<24) + iz;
73 return ret;
74 }
75
76 static void UnpackXYZ( int iRow, AliHLTTPCCACompressedCluster C, float &X, float &Y, float &Z )
77 {
78 Double_t rowX = AliHLTTPCTransform::Row2X( iRow );
79
80 UInt_t ix0 = C.fP0 >>24;
81 UInt_t ix1 = C.fP1 >>24;
82 X = (ix1<<8) + ix0;
83 Y = C.fP0 & 0x00FFFFFF;
84 Z = C.fP1 & 0x00FFFFFF;
85 X = (X - 32768.)*1.e-4 + rowX;
86 Y = (Y - 8388608.)*1.e-4;
87 Z = (Z - 8388608.)*1.e-4;
88 }
89
63d8b79d 90};
91
92
93// Inline methods
94
95
fbb9b71b 96GPUhd() inline unsigned short AliHLTTPCCADataCompressor::YZ2UShort( float Y, float Z )
97{
63d8b79d 98 // compress Y and Z coordinates in range [-3., 3.] to 16 bits
99
fbb9b71b 100 const float kMult = 255. / 6.;
7be9b0d7 101 Y = ( Y + 3.f ) * kMult;
102 Z = ( Z + 3.f ) * kMult;
fbb9b71b 103 if ( Y < 0. ) Y = 0.;
104 else if ( Y > 255. ) Y = 255.;
105 if ( Z < 0. ) Z = 0.;
106 else if ( Z > 255. ) Z = 255.;
107 return static_cast<unsigned short>( ( static_cast<unsigned int>( Y ) << 8 ) + static_cast<unsigned int>( Z ) );
108}
109
110GPUhd() inline float AliHLTTPCCADataCompressor::UShort2Y( unsigned short iYZ )
111{
63d8b79d 112 // extract Y coordinate from the compressed 16bits format to [-3.,3.]
113
7be9b0d7 114 const float kMult = 6.f / 255.f;
115 return ( iYZ >> 8 )*kMult - 3.f;
fbb9b71b 116}
63d8b79d 117
fbb9b71b 118GPUhd() inline float AliHLTTPCCADataCompressor::UShort2Z( unsigned short iYZ )
119{
63d8b79d 120 // extract Z coordinate from the compressed 16bits format to [-3.,3.]
121
7be9b0d7 122 const float kMult = 6.f / 255.f;
123 return ( iYZ % 256 )*kMult - 3.f;
63d8b79d 124}
125
31649d4b 126#endif //ALIHLTTPCCADATACOMPRESSOR_H