1 // **************************************************************************
2 // * This file is property of and copyright by the ALICE HLT Project *
3 // * All rights reserved. *
5 // * Primary Authors: *
6 // * Copyright 2009 Matthias Kretz <kretz@kde.org> *
8 // * Permission to use, copy, modify and distribute this software and its *
9 // * documentation strictly for non-commercial purposes is hereby granted *
10 // * without fee, provided that the above copyright notice appears in all *
11 // * copies and that both the copyright notice and this permission notice *
12 // * appear in the supporting documentation. The authors make no claims *
13 // * about the suitability of this software for any purpose. It is *
14 // * provided "as is" without express or implied warranty. *
15 // **************************************************************************
17 #ifndef ALIHLTTPCCASLICEDATA_H
18 #define ALIHLTTPCCASLICEDATA_H
20 #include "AliHLTTPCCADef.h"
21 #include "AliHLTTPCCARow.h"
22 #include "AliHLTTPCCAMath.h"
23 #include "AliHLTArray.h"
24 #include "AliHLTTPCCAGPUConfig.h"
27 typedef unsigned int uint_v;
28 typedef short short_v;
29 typedef unsigned short ushort_v;
30 typedef float float_v;
32 class AliHLTTPCCAClusterData;
33 template<typename T, int Dim> class AliHLTArray;
35 class AliHLTTPCCAParam;
38 * Data abstraction class for the Slice Tracker.
40 * Different architectures implement this for the most efficient loads and stores. All access to the
41 * data happens through inline functions so that access to the data has no extra costs.
43 class AliHLTTPCCASliceData
46 AliHLTTPCCASliceData()
48 fIsGpuSliceData(0), fGPUSharedDataReq(0), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 )
49 ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 )
50 , fFirstHitInBin( 0 ), fHitWeights( 0 )
55 ~AliHLTTPCCASliceData();
56 #endif //!HLTCA_GPUCODE
58 void InitializeRows( const AliHLTTPCCAParam ¶meters );
61 * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
65 void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory);
66 size_t SetPointers(const AliHLTTPCCAClusterData *data, bool allocate = false);
67 void InitFromClusterData( const AliHLTTPCCAClusterData &data );
70 * Clear the slice data (e.g. for an empty slice)
75 * Return the number of hits in this slice.
77 GPUhd() int NumberOfHits() const { return fNumberOfHits; }
78 GPUhd() int NumberOfHitsPlusAlign() const { return fNumberOfHitsPlusAlign; }
81 * Access to the hit links.
83 * The links values give the hit index in the row above/below. Or -1 if there is no link.
85 short_v HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
86 short_v HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
88 GPUhd() const ushort2 *HitData( const AliHLTTPCCARow &row ) const;
89 GPUhd() const ushort2 *HitData() const { return(fHitData); }
90 GPUd() const short_v *HitLinkUpData ( const AliHLTTPCCARow &row ) const;
91 GPUd() const short_v *HitLinkDownData( const AliHLTTPCCARow &row ) const;
92 GPUd() const ushort_v *FirstHitInBin( const AliHLTTPCCARow &row ) const;
94 void SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex,
95 const short_v &value );
96 void SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex,
97 const short_v &value );
100 * Reset all links to -1.
105 * Return the y and z coordinate(s) of the given hit(s).
107 // TODO return float_v
108 ushort_v HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
109 ushort_v HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
110 ushort2 HitData( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
113 * For a given bin index, content tells how many hits there are in the preceding bins. This maps
114 * directly to the hit index in the given row.
116 * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
118 ushort_v FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const;
121 * If the given weight is higher than what is currently stored replace with the new weight.
123 void MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight );
126 * Return the maximal weight the given hit got from one tracklet
128 int_v HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
131 * Reset all hit weights to 0.
133 void ClearHitWeights();
136 * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
138 int_v ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
141 * Return the row object for the given row index.
143 const AliHLTTPCCARow &Row( int rowIndex ) const;
144 GPUhd() AliHLTTPCCARow* Rows() const {return fRows;}
146 GPUh() char *Memory() const {return(fMemory); }
147 GPUh() size_t MemorySize() const {return(fMemorySize); }
148 GPUh() size_t GpuMemorySize() const {return(fGpuMemorySize); }
149 GPUh() int* HitWeights() const {return(fHitWeights); }
151 GPUhd() void SetGPUTextureBase(char* const val) {fGPUTextureBase = val;}
152 GPUhd() char* GPUTextureBase() const { return(fGPUTextureBase); }
153 GPUhd() char* GPUTextureBaseConst() const { return(fGPUTextureBase); }
155 GPUh() int GPUSharedDataReq() const { return fGPUSharedDataReq; }
157 void SetGpuSliceData() { fIsGpuSliceData = 1; }
160 AliHLTTPCCASliceData( const AliHLTTPCCASliceData & )
162 fIsGpuSliceData(0), fGPUSharedDataReq(0), fNumberOfHits( 0 ), fNumberOfHitsPlusAlign( 0 ), fMemorySize( 0 ), fGpuMemorySize( 0 ), fMemory( 0 ), fGPUTextureBase( 0 )
163 ,fRows( NULL ), fLinkUpData( 0 ), fLinkDownData( 0 ), fHitData( 0 ), fClusterDataIndex( 0 )
164 , fFirstHitInBin( 0 ), fHitWeights( 0 )
167 AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
171 void CreateGrid( AliHLTTPCCARow *row, const AliHLTTPCCAClusterData &data, int ClusterDataHitNumberOffset );
172 void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
174 int fIsGpuSliceData; //Slice Data for GPU Tracker?
175 int fGPUSharedDataReq; //Size of shared memory required for GPU Reconstruction
177 int fNumberOfHits; // the number of hits in this slice
178 int fNumberOfHitsPlusAlign;
180 int fMemorySize; // size of the allocated memory in bytes
181 int fGpuMemorySize; // size of Memory needed to be transfered to GPU
182 char *fMemory; // pointer to the allocated memory where all the following arrays reside in
183 char *fGPUTextureBase; // pointer to start of GPU texture
185 AliHLTTPCCARow *fRows; // The row objects needed for most accessor functions
187 short *fLinkUpData; // hit index in the row above which is linked to the given (global) hit index
188 short *fLinkDownData; // hit index in the row below which is linked to the given (global) hit index
190 ushort2 *fHitData; // packed y,z coordinate of the given (global) hit index
192 int *fClusterDataIndex; // see ClusterDataIndex()
195 * The size of the array is row.Grid.N + row.Grid.Ny + 3. The row.Grid.Ny + 3 is an optimization
196 * to remove the need for bounds checking. The last values are the same as the entry at [N - 1].
198 unsigned short *fFirstHitInBin; // see FirstHitInBin
200 int *fHitWeights; // the weight of the longest tracklet crossed the cluster
204 GPUd() inline short_v AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
206 return fLinkUpData[row.fHitNumberOffset + hitIndex];
209 GPUd() inline short_v AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
211 return fLinkDownData[row.fHitNumberOffset + hitIndex];
214 GPUd() inline const ushort_v *AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row ) const
216 return &fFirstHitInBin[row.fFirstHitInBinOffset];
219 GPUd() inline const short_v *AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row ) const
221 return &fLinkUpData[row.fHitNumberOffset];
224 GPUd() inline const short_v *AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row ) const
226 return &fLinkDownData[row.fHitNumberOffset];
229 GPUhd() inline const ushort2 *AliHLTTPCCASliceData::HitData( const AliHLTTPCCARow &row ) const
231 return &fHitData[row.fHitNumberOffset];
234 GPUd() inline void AliHLTTPCCASliceData::SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
236 fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
239 GPUd() inline void AliHLTTPCCASliceData::SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
241 fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
244 GPUd() inline ushort_v AliHLTTPCCASliceData::HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
246 return fHitData[row.fHitNumberOffset + hitIndex].x;
249 GPUd() inline ushort_v AliHLTTPCCASliceData::HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
251 return fHitData[row.fHitNumberOffset + hitIndex].y;
254 GPUd() inline ushort2 AliHLTTPCCASliceData::HitData( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
256 return fHitData[row.fHitNumberOffset + hitIndex];
259 GPUd() inline ushort_v AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const
261 return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
264 GPUhd() inline int_v AliHLTTPCCASliceData::ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const
266 return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
269 GPUhd() inline const AliHLTTPCCARow &AliHLTTPCCASliceData::Row( int rowIndex ) const
271 return fRows[rowIndex];
274 GPUd() inline void AliHLTTPCCASliceData::MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight )
276 CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
279 GPUd() inline int_v AliHLTTPCCASliceData::HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const
281 return fHitWeights[row.fHitNumberOffset + hitIndex];
284 typedef AliHLTTPCCASliceData SliceData;
286 #endif // ALIHLTTPCCASLICEDATA_H