]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCASliceData.h
style changes
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCASliceData.h
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
19
20 #include "AliHLTTPCCARow.h"
21 #include "AliHLTTPCCAMath.h"
22
23 typedef int int_v;
24 typedef unsigned int uint_v;
25 typedef short short_v;
26 typedef unsigned short ushort_v;
27 typedef float float_v;
28
29 class AliHLTTPCCAClusterData;
30 template<typename T, int Dim> class AliHLTArray;
31 class AliHLTTPCCAHit;
32 class AliHLTTPCCAParam;
33
34 /**
35  * Data abstraction class for the Slice Tracker.
36  *
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.
39  */
40 class AliHLTTPCCASliceData
41 {
42   public:
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 ) {}
47
48     void InitializeRows( const AliHLTTPCCAParam &parameters );
49
50     /**
51      * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
52      * data.
53      */
54     void InitFromClusterData( const AliHLTTPCCAClusterData &data );
55
56     /**
57      * Clear the slice data (e.g. for an empty slice)
58      */
59     void Clear();
60
61     /**
62      * Return the number of hits in this slice.
63      */
64     int NumberOfHits() const { return fNumberOfHits; }
65
66     /**
67      * Access to the hit links.
68      *
69      * The links values give the hit index in the row above/below. Or -1 if there is no link.
70      */
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 );
77
78     /**
79      * Reset all links to -1.
80      */
81     void ClearLinks();
82
83     /**
84      * Return the y and z coordinate(s) of the given hit(s).
85      */
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;
89
90     /**
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.
93      *
94      * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
95      */
96     ushort_v FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const;
97
98     /**
99      * If the given weight is higher than what is currently stored replace with the new weight.
100      */
101     void MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight );
102
103     /**
104      * Return the maximal weight the given hit got from one tracklet
105      */
106     int_v HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
107
108     /**
109      * Reset all hit weights to 0.
110      */
111     void ClearHitWeights();
112
113     /**
114      * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
115      */
116     int_v ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
117
118     /**
119      * Return the row object for the given row index.
120      */
121     const AliHLTTPCCARow &Row( int rowIndex ) const;
122
123   private:
124
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 ) {}
129
130     AliHLTTPCCASliceData& operator=( const AliHLTTPCCASliceData & ) {
131       return *this;
132     }
133
134     void CreateGrid( AliHLTTPCCARow *row, const AliHLTTPCCAClusterData &data );
135     void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
136
137     AliHLTTPCCARow fRows[200]; // The row objects needed for most accessor functions
138
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
142
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
145
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
148
149     int *fClusterDataIndex;    // see ClusterDataIndex()
150
151     /*
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].
154      */
155     unsigned short *fFirstHitInBin;         // see FirstHitInBin
156
157     int *fHitWeights;          // the weight of the longest tracklet crossed the cluster
158
159 };
160
161 inline short_v AliHLTTPCCASliceData::HitLinkUpData  ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
162 {
163   return fLinkUpData[row.fHitNumberOffset + hitIndex];
164 }
165
166 inline short_v AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
167 {
168   return fLinkDownData[row.fHitNumberOffset + hitIndex];
169 }
170
171 inline void AliHLTTPCCASliceData::SetHitLinkUpData  ( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
172 {
173   fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
174 }
175
176 inline void AliHLTTPCCASliceData::SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
177 {
178   fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
179 }
180
181 inline short_v AliHLTTPCCASliceData::HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
182 {
183   return fHitDataY[row.fHitNumberOffset + hitIndex];
184 }
185
186 inline short_v AliHLTTPCCASliceData::HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
187 {
188   return fHitDataZ[row.fHitNumberOffset + hitIndex];
189 }
190
191 inline ushort_v AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const
192 {
193   return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
194 }
195
196 inline int_v AliHLTTPCCASliceData::ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const
197 {
198   return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
199 }
200
201 inline const AliHLTTPCCARow &AliHLTTPCCASliceData::Row( int rowIndex ) const
202 {
203   return fRows[rowIndex];
204 }
205
206 inline void AliHLTTPCCASliceData::MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight )
207 {
208   CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
209 }
210
211 inline int_v AliHLTTPCCASliceData::HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const
212 {
213   return fHitWeights[row.fHitNumberOffset + hitIndex];
214 }
215
216 typedef AliHLTTPCCASliceData SliceData;
217
218 #endif // SLICEDATA_H