]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/tracking-ca/AliHLTTPCCATracker.h
bug fix: reconstruction crash when the output buffer size exceed
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATracker.h
CommitLineData
326c2d4b 1//-*- Mode: C++ -*-
2// @(#) $Id$
ce565086 3// ************************************************************************
fbb9b71b 4// This file is property of and copyright by the ALICE HLT Project *
ce565086 5// ALICE Experiment at CERN, All rights reserved. *
6// See cxx source for full Copyright notice *
7// *
8//*************************************************************************
326c2d4b 9
10#ifndef ALIHLTTPCCATRACKER_H
11#define ALIHLTTPCCATRACKER_H
12
13
00d07bcd 14#include "AliHLTTPCCADef.h"
b22af1bf 15#include "AliHLTTPCCAGPUConfig.h"
326c2d4b 16#include "AliHLTTPCCAParam.h"
4687b8fc 17#include <iostream>
4acc2401 18#include "AliHLTTPCCAHitId.h"
19#include "AliHLTTPCCASliceData.h"
b22af1bf 20#include "AliHLTTPCCASliceOutput.h"
21#include "AliHLTTPCCATrackletConstructor.h"
a59a784e 22#include "AliHLTTPCCATracklet.h"
326c2d4b 23
d54804bf 24class AliHLTTPCCATrack;
d54804bf 25class AliHLTTPCCATrackParam;
4acc2401 26class AliHLTTPCCAClusterData;
a59a784e 27class AliHLTTPCCARow;
326c2d4b 28
29/**
30 * @class AliHLTTPCCATracker
fbb9b71b 31 *
32 * Slice tracker for ALICE HLT.
dc4788ec 33 * The class reconstructs tracks in one slice of TPC.
34 * The reconstruction algorithm is based on the Cellular Automaton method
35 *
fbb9b71b 36 * The CA tracker is designed stand-alone.
dc4788ec 37 * It is integrated to the HLT framework via AliHLTTPCCATrackerComponent interface.
38 * The class is under construction.
39 *
326c2d4b 40 */
b22af1bf 41
42class AliHLTTPCCAClusterData;
43
326c2d4b 44class AliHLTTPCCATracker
45{
fbb9b71b 46 public:
326c2d4b 47
a59a784e 48 AliHLTTPCCATracker()
49 : fParam(),
50 fOutputControl(),
51 fClusterData( 0 ),
52 fData(),
53 fIsGPUTracker( false ),
54 fGPUDebugLevel( 0 ),
55 fGPUDebugOut( 0 ),
56 fRowStartHitCountOffset( NULL ),
57 fTrackletTmpStartHits( NULL ),
58 fGPUTrackletTemp( NULL ),
59 fRowBlockTracklets( NULL ),
60 fRowBlockPos( NULL ),
61 fBlockStartingTracklet( NULL ),
62 fGPUParametersConst(),
63 fCommonMem( 0 ),
64 fHitMemory( 0 ),
65 fHitMemorySize( 0 ),
66 fTrackletMemory( 0 ),
67 fTrackletMemorySize( 0 ),
68 fTrackMemory( 0 ),
69 fTrackMemorySize( 0 ),
70 fTrackletStartHits( 0 ),
71 fTracklets( 0 ),
72 fTrackletRowHits( NULL ),
73 fTracks( 0 ),
74 fTrackHits( 0 ),
75 fOutput( 0 )
76 {
77 // constructor
78 }
79 ~AliHLTTPCCATracker();
80
81 struct StructGPUParameters
82 {
83 StructGPUParameters() : fScheduleFirstDynamicTracklet( 0 ), fGPUError( 0 ) {}
84 int fScheduleFirstDynamicTracklet; //Last Tracklet with fixed position in sheduling
85 int fGPUError; //Signalizes error on GPU during GPU Reconstruction, kind of return value
86 };
87
88 struct StructGPUParametersConst
89 {
90 StructGPUParametersConst() : fGPUFixedBlockCount( 0 ), fGPUiSlice( 0 ), fGPUnSlices( 0 ) {}
91 int fGPUFixedBlockCount; //Count of blocks that is used for this tracker in fixed schedule situations
78c19cec 92 int fGPUiSlice; // slice number processed by running GPU MP
93 int fGPUnSlices; // n of slices to be processed in parallel
a59a784e 94 };
95
96 struct commonMemoryStruct
97 {
98 commonMemoryStruct() : fNTracklets( 0 ), fNTracks( 0 ), fNTrackHits( 0 ), fGPUParameters() {}
99 int fNTracklets; // number of tracklets
100 int fNTracks; // number of reconstructed tracks
101 int fNTrackHits; // number of track hits
102 StructGPUParameters fGPUParameters; // GPU parameters
103 };
104
105 void Initialize( const AliHLTTPCCAParam &param );
106
107 void StartEvent();
108
109 int CheckEmptySlice() const;
110 void WriteOutput();
111
7be9b0d7 112#if !defined(HLTCA_GPUCODE)
a59a784e 113 void Reconstruct();
31649d4b 114#endif //!HLTCA_GPUCODE
a59a784e 115
116 //Make Reconstruction steps directly callable (Used for GPU debugging)
117 void RunNeighboursFinder();
118 void RunNeighboursCleaner();
119 void RunStartHitsFinder();
8566066c 120 void RunTrackletConstructor();
a59a784e 121 void RunTrackletSelector();
122
123 //GPU Tracker Interface
124 void SetGPUTracker();
125 void SetGPUDebugLevel(int Level, std::ostream *NewDebugOut = NULL) {fGPUDebugLevel = Level;if (NewDebugOut) fGPUDebugOut = NewDebugOut;}
126
8566066c 127 char* SetGPUTrackerCommonMemory(char* const pGPUMemory);
a59a784e 128 char* SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits);
129 char* SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracklets);
130 char* SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits );
131
132 //Debugging Stuff
133 void DumpSliceData(std::ostream &out); //Dump Input Slice Data
134 void DumpLinks(std::ostream &out); //Dump all links to file (for comparison after NeighboursFinder/Cleaner)
135 void DumpStartHits(std::ostream &out); //Same for Start Hits
136 void DumpHitWeights(std::ostream &out); //....
137 void DumpTrackHits(std::ostream &out); //Same for Track Hits
138 void DumpTrackletHits(std::ostream &out); //Same for Track Hits
139
140 GPUd() void GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const;
141 GPUd() void GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const;
142
143 void FitTrack( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
144 void FitTrackFull( const AliHLTTPCCATrack &track, float *t0 = 0 ) const;
145
146 void SetupCommonMemory();
147 void SetPointersHits( int MaxNHits );
148 void SetPointersTracklets ( int MaxNTracklets );
149 void SetPointersTracks( int MaxNTracks, int MaxNHits );
8566066c 150 size_t SetPointersSliceData(const AliHLTTPCCAClusterData *data, bool allocate = false) { return(fData.SetPointers(data, allocate)); }
a59a784e 151
152 void SetOutput( AliHLTTPCCASliceOutput** out ) { fOutput = out; }
153
154 void ReadEvent( AliHLTTPCCAClusterData *clusterData );
155
b22af1bf 156#if !defined(HLTCA_GPUCODE)
a59a784e 157 GPUh() void WriteEvent( std::ostream &out );
158 GPUh() void WriteTracks( std::ostream &out ) ;
159 GPUh() void ReadTracks( std::istream &in );
31649d4b 160#endif //!HLTCA_GPUCODE
a59a784e 161
162 GPUhd() const AliHLTTPCCAParam &Param() const { return fParam; }
163 GPUhd() void SetParam( const AliHLTTPCCAParam &v ) { fParam = v; }
164
8566066c 165 GPUhd() const AliHLTTPCCASliceOutput::outputControlStruct* OutputControl() const { return fOutputControl; }
166 GPUh() void SetOutputControl( AliHLTTPCCASliceOutput::outputControlStruct* const val) { fOutputControl = val; }
167
a59a784e 168 GPUhd() AliHLTTPCCAClusterData *ClusterData() const { return fClusterData; }
169 GPUhd() const AliHLTTPCCASliceData &Data() const { return fData; }
a59a784e 170
171 GPUh() void ClearSliceDataHitWeights() {fData.ClearHitWeights();}
172
173 GPUhd() const AliHLTTPCCARow &Row( int rowIndex ) const { return fData.Row( rowIndex ); }
174 GPUh() const AliHLTTPCCARow &Row( const AliHLTTPCCAHitId &HitId ) const { return fData.Row( HitId.RowIndex() ); }
175
176 GPUhd() double Timer( int i ) const { return fTimers[i]; }
177 GPUhd() void SetTimer( int i, double v ) { fTimers[i] = v; }
178
179 GPUhd() int NHitsTotal() const { return fData.NumberOfHits(); }
180
181 GPUd() void SetHitLinkUpData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkUpData( row, hitIndex, v ); }
182 GPUd() void SetHitLinkDownData( const AliHLTTPCCARow &row, int hitIndex, short v ) { fData.SetHitLinkDownData( row, hitIndex, v ); }
183 GPUd() short HitLinkUpData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkUpData( row, hitIndex ); }
184 GPUd() short HitLinkDownData( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.HitLinkDownData( row, hitIndex ); }
185
186 GPUd() const ushort2 *HitData( const AliHLTTPCCARow &row ) const { return fData.HitData(row); }
187 GPUd() const short_v *HitLinkUpData ( const AliHLTTPCCARow &row ) const { return fData.HitLinkUpData(row); }
188 GPUd() const short_v *HitLinkDownData( const AliHLTTPCCARow &row ) const { return fData.HitLinkDownData(row); }
189 GPUd() const ushort_v *FirstHitInBin( const AliHLTTPCCARow &row ) const { return fData.FirstHitInBin(row); }
190
191 GPUd() int FirstHitInBin( const AliHLTTPCCARow &row, int binIndex ) const { return fData.FirstHitInBin( row, binIndex ); }
192
193 GPUd() unsigned short HitDataY( const AliHLTTPCCARow &row, int hitIndex ) const {
194 return fData.HitDataY( row, hitIndex );
195 }
196 GPUd() unsigned short HitDataZ( const AliHLTTPCCARow &row, int hitIndex ) const {
197 return fData.HitDataZ( row, hitIndex );
198 }
199 GPUd() ushort2 HitData( const AliHLTTPCCARow &row, int hitIndex ) const {
200 return fData.HitData( row, hitIndex );
201 }
202
203 GPUhd() int HitInputID( const AliHLTTPCCARow &row, int hitIndex ) const { return fData.ClusterDataIndex( row, hitIndex ); }
204
205 /**
206 * The hit weight is used to determine whether a hit belongs to a certain tracklet or another one
207 * competing for the same hit. The tracklet that has a higher weight wins. Comparison is done
208 * using the the number of hits in the tracklet (the more hits it has the more it keeps). If
209 * tracklets have the same number of hits then it doesn't matter who gets it, but it should be
210 * only one. So a unique number (row index is good) is added in the least significant part of
211 * the weight
212 */
213 static int CalculateHitWeight( int NHits, int unique ) {
214 return ( NHits << 16 ) + unique;
215 }
216 GPUd() void MaximizeHitWeight( const AliHLTTPCCARow &row, int hitIndex, int weight ) {
217 fData.MaximizeHitWeight( row, hitIndex, weight );
218 }
219 GPUd() int HitWeight( const AliHLTTPCCARow &row, int hitIndex ) const {
220 return fData.HitWeight( row, hitIndex );
221 }
222
444e5682 223 GPUhd() int *NTracklets() const { return &fCommonMem->fNTracklets; }
a59a784e 224
225 GPUhd() const AliHLTTPCCAHitId &TrackletStartHit( int i ) const { return fTrackletStartHits[i]; }
226 GPUhd() AliHLTTPCCAHitId *TrackletStartHits() const { return fTrackletStartHits; }
227 GPUhd() AliHLTTPCCAHitId *TrackletTmpStartHits() const { return fTrackletTmpStartHits; }
228 GPUhd() const AliHLTTPCCATracklet &Tracklet( int i ) const { return fTracklets[i]; }
229 GPUhd() AliHLTTPCCATracklet *Tracklets() const { return fTracklets;}
444e5682 230 GPUhd() int* TrackletRowHits() const { return fTrackletRowHits; }
a59a784e 231
232 GPUhd() int *NTracks() const { return &fCommonMem->fNTracks; }
233 GPUhd() AliHLTTPCCATrack *Tracks() const { return fTracks; }
234 GPUhd() int *NTrackHits() const { return &fCommonMem->fNTrackHits; }
235 GPUhd() AliHLTTPCCAHitId *TrackHits() const { return fTrackHits; }
236
237 GPUhd() AliHLTTPCCASliceOutput** Output() const { return fOutput; }
238
444e5682 239 GPUh() commonMemoryStruct *CommonMemory() const {return(fCommonMem); }
a59a784e 240 GPUh() static size_t CommonMemorySize() { return(sizeof(AliHLTTPCCATracker::commonMemoryStruct)); }
444e5682 241 GPUh() char* HitMemory() const {return(fHitMemory); }
a59a784e 242 GPUh() size_t HitMemorySize() const {return(fHitMemorySize); }
444e5682 243 GPUh() char* TrackletMemory() {return(fTrackletMemory); }
a59a784e 244 GPUh() size_t TrackletMemorySize() const {return(fTrackletMemorySize); }
444e5682 245 GPUh() char* TrackMemory() {return(fTrackMemory); }
a59a784e 246 GPUh() size_t TrackMemorySize() const {return(fTrackMemorySize); }
444e5682 247 GPUhd() AliHLTTPCCARow* SliceDataRows() const {return(fData.Rows()); }
a59a784e 248
249 GPUhd() uint3* RowStartHitCountOffset() const {return(fRowStartHitCountOffset);}
250 GPUhd() AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory* GPUTrackletTemp() const {return(fGPUTrackletTemp);}
251 GPUhd() int* RowBlockTracklets(int reverse, int iRowBlock) const {return(&fRowBlockTracklets[(reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock) * fCommonMem->fNTracklets]);}
252 GPUhd() int* RowBlockTracklets() const {return(fRowBlockTracklets);}
253 GPUhd() int4* RowBlockPos(int reverse, int iRowBlock) const {return(&fRowBlockPos[reverse * ((fParam.NRows() / HLTCA_GPU_SCHED_ROW_STEP) + 1) + iRowBlock]);}
254 GPUhd() int4* RowBlockPos() const {return(fRowBlockPos);}
255 GPUhd() uint2* BlockStartingTracklet() const {return(fBlockStartingTracklet);}
256 GPUhd() StructGPUParameters* GPUParameters() const {return(&fCommonMem->fGPUParameters);}
257 GPUhd() StructGPUParametersConst* GPUParametersConst() {return(&fGPUParametersConst);}
78c19cec 258 GPUhd() void SetGPUTextureBase(char* val) { fData.SetGPUTextureBase(val); }
259 GPUh() void SetGPUSliceDataMemory(void* const pSliceMemory, void* const pRowMemory) { fData.SetGPUSliceDataMemory(pSliceMemory, pRowMemory); }
8566066c 260
a59a784e 261 GPUh() unsigned long long int* PerfTimer(unsigned int i) {return &fPerfTimers[i]; }
262
263private:
264
b22af1bf 265#ifdef HLTCA_GPU_TRACKLET_CONSTRUCTOR_DO_PROFILE
a59a784e 266 char* fStageAtSync; //Pointer to array storing current stage for every thread at every sync point
31649d4b 267#endif //HLTCA_GPU_TRACKLET_CONSTRUCTOR_DO_PROFILE
a59a784e 268
269 AliHLTTPCCAParam fParam; // parameters
270 double fTimers[10]; // timers
271 unsigned long long int fPerfTimers[16]; // running CPU time for different parts of the algorithm
272 void StandalonePerfTime(int i);
273
274 AliHLTTPCCASliceOutput::outputControlStruct* fOutputControl; // output control
275
276 /** A pointer to the ClusterData object that the SliceData was created from. This can be used to
277 * merge clusters from inside the SliceTracker code and recreate the SliceData. */
278 AliHLTTPCCAClusterData *fClusterData; // ^
279 AliHLTTPCCASliceData fData; // The SliceData object. It is used to encapsulate the storage in memory from the access
280
281 bool fIsGPUTracker; // is it GPU tracker object
282 int fGPUDebugLevel; // debug level
283 std::ostream *fGPUDebugOut; // debug stream
284
285 //GPU Temp Arrays
286 uint3* fRowStartHitCountOffset; //Offset, length and new offset of start hits in row
287 AliHLTTPCCAHitId *fTrackletTmpStartHits; //Unsorted start hits
288 AliHLTTPCCATrackletConstructor::AliHLTTPCCAGPUTempMemory *fGPUTrackletTemp; //Temp Memory for GPU Tracklet Constructor
289 int* fRowBlockTracklets; //Reference which tracklet is processed in which rowblock next
8566066c 290 int4* fRowBlockPos; //x is last tracklet to be processed, y is last tracklet already processed, z is last tracklet to be processed in next iteration, w is initial x value to check if tracklet must be initialized
291 uint2* fBlockStartingTracklet; // First Tracklet that is to be processed by current GPU MP
292
293 StructGPUParametersConst fGPUParametersConst; // Parameters for GPU if this is a GPU tracker
294
a59a784e 295 // event
296
297 commonMemoryStruct *fCommonMem; // common event memory
298
299 char *fHitMemory; // event memory for hits
8566066c 300 size_t fHitMemorySize; // size of the event memory for hits [bytes]
301
302 char *fTrackletMemory; //event memory for tracklets
303 size_t fTrackletMemorySize; //size of the event memory for tracklets
304
a59a784e 305 char *fTrackMemory; // event memory for tracks
8566066c 306 size_t fTrackMemorySize; // size of the event memory for tracks [bytes]
307
a59a784e 308 AliHLTTPCCAHitId *fTrackletStartHits; // start hits for the tracklets
309 AliHLTTPCCATracklet *fTracklets; // tracklets
8566066c 310 int *fTrackletRowHits; //Hits for each Tracklet in each row
311
a59a784e 312 //
313 AliHLTTPCCATrack *fTracks; // reconstructed tracks
314 AliHLTTPCCAHitId *fTrackHits; // array of track hit numbers
315
316 // output
317
8566066c 318 AliHLTTPCCASliceOutput **fOutput; //address of pointer pointing to SliceOutput Object
a59a784e 319
320 // disable copy
321 AliHLTTPCCATracker( const AliHLTTPCCATracker& );
322 AliHLTTPCCATracker &operator=( const AliHLTTPCCATracker& );
323
324 static int StarthitSortComparison(const void*a, const void* b);
326c2d4b 325};
326
00d07bcd 327
31649d4b 328#endif //ALIHLTTPCCATRACKER_H