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 "AliHLTTPCCARow.h"
21 #include "AliHLTTPCCAMath.h"
24 typedef unsigned int uint_v;
25 typedef short short_v;
26 typedef unsigned short ushort_v;
27 typedef float float_v;
29 class AliHLTTPCCAClusterData;
30 template<typename T, int Dim> class AliHLTArray;
32 class AliHLTTPCCAParam;
35 * Data abstraction class for the Slice Tracker.
37 * Different architectures implement this for the most efficient loads and stores. All access to the
38 * data happens through inline functions so that access to the data has no extra costs.
40 class AliHLTTPCCASliceData
43 AliHLTTPCCASliceData()
44 : fNumberOfHits( 0 ), fMemorySize( 0 ), fMemory( 0 ), fLinkUpData( 0 ),
45 fLinkDownData( 0 ), fHitDataY( 0 ), fHitDataZ( 0 ), fClusterDataIndex( 0 ),
46 fFirstHitInBin( 0 ), fHitWeights( 0 ) {}
48 void InitializeRows( const AliHLTTPCCAParam ¶meters );
51 * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
54 void InitFromClusterData( const AliHLTTPCCAClusterData &data );
57 * Clear the slice data (e.g. for an empty slice)
62 * Return the number of hits in this slice.
64 int NumberOfHits() const { return fNumberOfHits; }
67 * Access to the hit links.
69 * The links values give the hit index in the row above/below. Or -1 if there is no link.
71 short_v HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
72 short_v HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
73 void SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex,
74 const short_v &value );
75 void SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex,
76 const short_v &value );
79 * Reset all links to -1.
84 * Return the y and z coordinate(s) of the given hit(s).
86 // TODO return float_v
87 short_v HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
88 short_v HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
91 * For a given bin index, content tells how many hits there are in the preceding bins. This maps
92 * directly to the hit index in the given row.
94 * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
96 ushort_v FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const;
99 * If the given weight is higher than what is currently stored replace with the new weight.
101 void MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight );
104 * Return the maximal weight the given hit got from one tracklet
106 int_v HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
109 * Reset all hit weights to 0.
111 void ClearHitWeights();
114 * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
116 int_v ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
119 * Return the row object for the given row index.
121 const AliHLTTPCCARow &Row( int rowIndex ) const;
125 AliHLTTPCCASliceData( const AliHLTTPCCASliceData & )
126 : fNumberOfHits( 0 ), fMemorySize( 0 ), fMemory( 0 ), fLinkUpData( 0 ),
127 fLinkDownData( 0 ), fHitDataY( 0 ), fHitDataZ( 0 ), fClusterDataIndex( 0 ),
128 fFirstHitInBin( 0 ), fHitWeights( 0 ) {}
130 AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
134 void CreateGrid( AliHLTTPCCARow *row, const AliHLTTPCCAClusterData &data );
135 void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
137 AliHLTTPCCARow fRows[200]; // The row objects needed for most accessor functions
139 int fNumberOfHits; // the number of hits in this slice
140 int fMemorySize; // size of the allocated memory in bytes
141 char *fMemory; // pointer to the allocated memory where all the following arrays reside in
143 short *fLinkUpData; // hit index in the row above which is linked to the given (global) hit index
144 short *fLinkDownData; // hit index in the row below which is linked to the given (global) hit index
146 unsigned short *fHitDataY; // packed y coordinate of the given (global) hit index
147 unsigned short *fHitDataZ; // packed z coordinate of the given (global) hit index
149 int *fClusterDataIndex; // see ClusterDataIndex()
152 * The size of the array is row.Grid.N + row.Grid.Ny + 3. The row.Grid.Ny + 3 is an optimization
153 * to remove the need for bounds checking. The last values are the same as the entry at [N - 1].
155 unsigned short *fFirstHitInBin; // see FirstHitInBin
157 int *fHitWeights; // the weight of the longest tracklet crossed the cluster
161 inline short_v AliHLTTPCCASliceData::HitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
163 return fLinkUpData[row.fHitNumberOffset + hitIndex];
166 inline short_v AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
168 return fLinkDownData[row.fHitNumberOffset + hitIndex];
171 inline void AliHLTTPCCASliceData::SetHitLinkUpData ( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
173 fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
176 inline void AliHLTTPCCASliceData::SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
178 fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
181 inline short_v AliHLTTPCCASliceData::HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
183 return fHitDataY[row.fHitNumberOffset + hitIndex];
186 inline short_v AliHLTTPCCASliceData::HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
188 return fHitDataZ[row.fHitNumberOffset + hitIndex];
191 inline ushort_v AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const
193 return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
196 inline int_v AliHLTTPCCASliceData::ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const
198 return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
201 inline const AliHLTTPCCARow &AliHLTTPCCASliceData::Row( int rowIndex ) const
203 return fRows[rowIndex];
206 inline void AliHLTTPCCASliceData::MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight )
208 CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
211 inline int_v AliHLTTPCCASliceData::HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const
213 return fHitWeights[row.fHitNumberOffset + hitIndex];
216 typedef AliHLTTPCCASliceData SliceData;
218 #endif // SLICEDATA_H