When Pt is bad defined (ex. no field), the multiple scattering effect is calculated...
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCASliceData.h
CommitLineData
6de2bc40 1// **************************************************************************
2// * This file is property of and copyright by the ALICE HLT Project *
3// * All rights reserved. *
4// * *
5// * Primary Authors: *
6// * Copyright 2009 Matthias Kretz <kretz@kde.org> *
7// * *
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// **************************************************************************
16
17#ifndef ALIHLTTPCCASLICEDATA_H
18#define ALIHLTTPCCASLICEDATA_H
4acc2401 19
7be9b0d7 20#include "AliHLTTPCCADef.h"
4acc2401 21#include "AliHLTTPCCARow.h"
22#include "AliHLTTPCCAMath.h"
7be9b0d7 23#include "AliHLTArray.h"
b22af1bf 24#include "AliHLTTPCCAGPUConfig.h"
4acc2401 25
26typedef int int_v;
27typedef unsigned int uint_v;
28typedef short short_v;
29typedef unsigned short ushort_v;
30typedef float float_v;
31
32class AliHLTTPCCAClusterData;
33template<typename T, int Dim> class AliHLTArray;
34class AliHLTTPCCAHit;
35class AliHLTTPCCAParam;
36
37/**
38 * Data abstraction class for the Slice Tracker.
39 *
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.
42 */
43class AliHLTTPCCASliceData
44{
45 public:
46 AliHLTTPCCASliceData()
b22af1bf 47 :
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 )
51 {
52 }
53
54#ifndef HLTCA_GPUCODE
55 ~AliHLTTPCCASliceData();
56#endif
4acc2401 57
58 void InitializeRows( const AliHLTTPCCAParam &parameters );
59
60 /**
61 * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
62 * data.
63 */
7be9b0d7 64
b22af1bf 65 void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory);
7be9b0d7 66 size_t SetPointers(const AliHLTTPCCAClusterData *data, bool allocate = false);
4acc2401 67 void InitFromClusterData( const AliHLTTPCCAClusterData &data );
68
69 /**
70 * Clear the slice data (e.g. for an empty slice)
71 */
72 void Clear();
73
74 /**
75 * Return the number of hits in this slice.
76 */
7be9b0d7 77 GPUhd() int NumberOfHits() const { return fNumberOfHits; }
b22af1bf 78 GPUhd() int NumberOfHitsPlusAlign() const { return fNumberOfHitsPlusAlign; }
4acc2401 79
80 /**
81 * Access to the hit links.
82 *
83 * The links values give the hit index in the row above/below. Or -1 if there is no link.
84 */
85 short_v HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
86 short_v HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
b22af1bf 87
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;
93
4acc2401 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 );
98
99 /**
100 * Reset all links to -1.
101 */
102 void ClearLinks();
103
104 /**
105 * Return the y and z coordinate(s) of the given hit(s).
106 */
107 // TODO return float_v
b22af1bf 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;
4acc2401 111
112 /**
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.
115 *
116 * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
117 */
118 ushort_v FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const;
119
120 /**
121 * If the given weight is higher than what is currently stored replace with the new weight.
122 */
123 void MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight );
124
125 /**
126 * Return the maximal weight the given hit got from one tracklet
127 */
128 int_v HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
129
130 /**
131 * Reset all hit weights to 0.
132 */
133 void ClearHitWeights();
134
135 /**
136 * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
137 */
138 int_v ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
139
140 /**
141 * Return the row object for the given row index.
142 */
143 const AliHLTTPCCARow &Row( int rowIndex ) const;
b22af1bf 144 GPUhd() AliHLTTPCCARow* Rows() const {return fRows;}
4acc2401 145
b22af1bf 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); }
6de2bc40 150
b22af1bf 151 GPUhd() void SetGPUTextureBase(char* val) {fGPUTextureBase = val;}
152 GPUhd() char* GPUTextureBase() const { return(fGPUTextureBase); }
153 GPUhd() char* GPUTextureBaseConst() const { return(fGPUTextureBase); }
154
155 GPUh() int GPUSharedDataReq() const { return fGPUSharedDataReq; }
156
157 void SetGpuSliceData() { fIsGpuSliceData = 1; }
6de2bc40 158
b22af1bf 159 private:
160 AliHLTTPCCASliceData( const AliHLTTPCCASliceData & )
161 :
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 )
165 {
166 }
b8139972 167 AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
6de2bc40 168 return *this;
169 }
b8139972 170
b22af1bf 171 void CreateGrid( AliHLTTPCCARow *row, const AliHLTTPCCAClusterData &data, int ClusterDataHitNumberOffset );
4acc2401 172 void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
173
b22af1bf 174 int fIsGpuSliceData; //Slice Data for GPU Tracker?
175 int fGPUSharedDataReq; //Size of shared memory required for GPU Reconstruction
4acc2401 176
177 int fNumberOfHits; // the number of hits in this slice
b22af1bf 178 int fNumberOfHitsPlusAlign;
179
4acc2401 180 int fMemorySize; // size of the allocated memory in bytes
b22af1bf 181 int fGpuMemorySize; // size of Memory needed to be transfered to GPU
4acc2401 182 char *fMemory; // pointer to the allocated memory where all the following arrays reside in
b22af1bf 183 char *fGPUTextureBase; // pointer to start of GPU texture
4acc2401 184
b22af1bf 185 AliHLTTPCCARow *fRows; // The row objects needed for most accessor functions
186
187 short *fLinkUpData; // hit index in the row above which is linked to the given (global) hit index
4acc2401 188 short *fLinkDownData; // hit index in the row below which is linked to the given (global) hit index
189
b22af1bf 190 ushort2 *fHitData; // packed y,z coordinate of the given (global) hit index
4acc2401 191
192 int *fClusterDataIndex; // see ClusterDataIndex()
193
194 /*
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].
197 */
198 unsigned short *fFirstHitInBin; // see FirstHitInBin
199
200 int *fHitWeights; // the weight of the longest tracklet crossed the cluster
201
202};
203
7be9b0d7 204GPUd() inline short_v AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
4acc2401 205{
206 return fLinkUpData[row.fHitNumberOffset + hitIndex];
207}
208
7be9b0d7 209GPUd() inline short_v AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
4acc2401 210{
211 return fLinkDownData[row.fHitNumberOffset + hitIndex];
212}
213
b22af1bf 214GPUd() inline const ushort_v *AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row ) const
215{
216 return &fFirstHitInBin[row.fFirstHitInBinOffset];
217}
218
219GPUd() inline const short_v *AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row ) const
220{
221 return &fLinkUpData[row.fHitNumberOffset];
222}
223
224GPUd() inline const short_v *AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row ) const
225{
226 return &fLinkDownData[row.fHitNumberOffset];
227}
228
229GPUhd() inline const ushort2 *AliHLTTPCCASliceData::HitData( const AliHLTTPCCARow &row ) const
230{
231 return &fHitData[row.fHitNumberOffset];
232}
233
7be9b0d7 234GPUd() inline void AliHLTTPCCASliceData::SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
4acc2401 235{
236 fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
237}
238
7be9b0d7 239GPUd() inline void AliHLTTPCCASliceData::SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
4acc2401 240{
241 fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
242}
243
b22af1bf 244GPUd() inline ushort_v AliHLTTPCCASliceData::HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
245{
246 return fHitData[row.fHitNumberOffset + hitIndex].x;
247}
248
249GPUd() inline ushort_v AliHLTTPCCASliceData::HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
4acc2401 250{
b22af1bf 251 return fHitData[row.fHitNumberOffset + hitIndex].y;
4acc2401 252}
253
b22af1bf 254GPUd() inline ushort2 AliHLTTPCCASliceData::HitData( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
4acc2401 255{
b22af1bf 256 return fHitData[row.fHitNumberOffset + hitIndex];
4acc2401 257}
258
7be9b0d7 259GPUd() inline ushort_v AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const
4acc2401 260{
261 return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
262}
263
7be9b0d7 264GPUhd() inline int_v AliHLTTPCCASliceData::ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const
4acc2401 265{
266 return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
267}
268
7be9b0d7 269GPUhd() inline const AliHLTTPCCARow &AliHLTTPCCASliceData::Row( int rowIndex ) const
4acc2401 270{
271 return fRows[rowIndex];
272}
273
7be9b0d7 274GPUd() inline void AliHLTTPCCASliceData::MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight )
4acc2401 275{
276 CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
277}
278
7be9b0d7 279GPUd() inline int_v AliHLTTPCCASliceData::HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const
4acc2401 280{
281 return fHitWeights[row.fHitNumberOffset + hitIndex];
282}
283
284typedef AliHLTTPCCASliceData SliceData;
285
286#endif // SLICEDATA_H