]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCASliceData.h
changes from Matthias
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCASliceData.h
1 /*
2     Copyright (C) 2009 Matthias Kretz <kretz@kde.org>
3
4     This program is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) version 3.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18
19 */
20
21 #ifndef SLICEDATA_H
22 #define SLICEDATA_H
23
24 #include "AliHLTTPCCARow.h"
25 #include "AliHLTTPCCAMath.h"
26
27 typedef int int_v;
28 typedef unsigned int uint_v;
29 typedef short short_v;
30 typedef unsigned short ushort_v;
31 typedef float float_v;
32
33 class AliHLTTPCCAClusterData;
34 template<typename T, int Dim> class AliHLTArray;
35 class AliHLTTPCCAHit;
36 class AliHLTTPCCAParam;
37
38 /**
39  * Data abstraction class for the Slice Tracker.
40  *
41  * Different architectures implement this for the most efficient loads and stores. All access to the
42  * data happens through inline functions so that access to the data has no extra costs.
43  */
44 class AliHLTTPCCASliceData
45 {
46   public:
47     AliHLTTPCCASliceData()
48         : fNumberOfHits( 0 ), fMemorySize( 0 ), fMemory( 0 ), fLinkUpData( 0 ),
49         fLinkDownData( 0 ), fHitDataY( 0 ), fHitDataZ( 0 ), fClusterDataIndex( 0 ),
50         fFirstHitInBin( 0 ), fHitWeights( 0 ) {}
51
52     void InitializeRows( const AliHLTTPCCAParam &parameters );
53
54     /**
55      * (Re)Create the data that is tuned for optimal performance of the algorithm from the cluster
56      * data.
57      */
58     void InitFromClusterData( const AliHLTTPCCAClusterData &data );
59
60     /**
61      * Clear the slice data (e.g. for an empty slice)
62      */
63     void Clear();
64
65     /**
66      * Return the number of hits in this slice.
67      */
68     int NumberOfHits() const { return fNumberOfHits; }
69
70     /**
71      * Access to the hit links.
72      *
73      * The links values give the hit index in the row above/below. Or -1 if there is no link.
74      */
75     short_v HitLinkUpData  ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
76     short_v HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const;
77     void SetHitLinkUpData  ( const AliHLTTPCCARow &row, const short_v &hitIndex,
78                              const short_v &value );
79     void SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex,
80                              const short_v &value );
81
82     /**
83      * Reset all links to -1.
84      */
85     void ClearLinks();
86
87     /**
88      * Return the y and z coordinate(s) of the given hit(s).
89      */
90     // TODO return float_v
91     short_v HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
92     short_v HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const;
93
94     /**
95      * For a given bin index, content tells how many hits there are in the preceding bins. This maps
96      * directly to the hit index in the given row.
97      *
98      * \param binIndexes in the range 0 to row.Grid.N + row.Grid.Ny + 3.
99      */
100     ushort_v FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const;
101
102     /**
103      * If the given weight is higher than what is currently stored replace with the new weight.
104      */
105     void MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight );
106
107     /**
108      * Return the maximal weight the given hit got from one tracklet
109      */
110     int_v HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
111
112     /**
113      * Reset all hit weights to 0.
114      */
115     void ClearHitWeights();
116
117     /**
118      * Returns the index in the original AliHLTTPCCAClusterData object of the given hit
119      */
120     int_v ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const;
121
122     /**
123      * Return the row object for the given row index.
124      */
125     const AliHLTTPCCARow &Row( int rowIndex ) const;
126
127   private:
128     void createGrid( AliHLTTPCCARow *row, const AliHLTTPCCAClusterData &data );
129     void PackHitData( AliHLTTPCCARow *row, const AliHLTArray<AliHLTTPCCAHit, 1> &binSortedHits );
130
131     AliHLTTPCCARow fRows[200]; // The row objects needed for most accessor functions
132
133     int fNumberOfHits;         // the number of hits in this slice
134     int fMemorySize;           // size of the allocated memory in bytes
135     char *fMemory;             // pointer to the allocated memory where all the following arrays reside in
136
137     short *fLinkUpData;        // hit index in the row above which is linked to the given (global) hit index
138     short *fLinkDownData;      // hit index in the row below which is linked to the given (global) hit index
139
140     unsigned short *fHitDataY;         // packed y coordinate of the given (global) hit index
141     unsigned short *fHitDataZ;         // packed z coordinate of the given (global) hit index
142
143     int *fClusterDataIndex;    // see ClusterDataIndex()
144
145     /*
146      * The size of the array is row.Grid.N + row.Grid.Ny + 3. The row.Grid.Ny + 3 is an optimization
147      * to remove the need for bounds checking. The last values are the same as the entry at [N - 1].
148      */
149     unsigned short *fFirstHitInBin;         // see FirstHitInBin
150
151     int *fHitWeights;          // the weight of the longest tracklet crossed the cluster
152
153 };
154
155 inline short_v AliHLTTPCCASliceData::HitLinkUpData  ( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
156 {
157   return fLinkUpData[row.fHitNumberOffset + hitIndex];
158 }
159
160 inline short_v AliHLTTPCCASliceData::HitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex ) const
161 {
162   return fLinkDownData[row.fHitNumberOffset + hitIndex];
163 }
164
165 inline void AliHLTTPCCASliceData::SetHitLinkUpData  ( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
166 {
167   fLinkUpData[row.fHitNumberOffset + hitIndex] = value;
168 }
169
170 inline void AliHLTTPCCASliceData::SetHitLinkDownData( const AliHLTTPCCARow &row, const short_v &hitIndex, const short_v &value )
171 {
172   fLinkDownData[row.fHitNumberOffset + hitIndex] = value;
173 }
174
175 inline short_v AliHLTTPCCASliceData::HitDataY( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
176 {
177   return fHitDataY[row.fHitNumberOffset + hitIndex];
178 }
179
180 inline short_v AliHLTTPCCASliceData::HitDataZ( const AliHLTTPCCARow &row, const uint_v &hitIndex ) const
181 {
182   return fHitDataZ[row.fHitNumberOffset + hitIndex];
183 }
184
185 inline ushort_v AliHLTTPCCASliceData::FirstHitInBin( const AliHLTTPCCARow &row, ushort_v binIndexes ) const
186 {
187   return fFirstHitInBin[row.fFirstHitInBinOffset + binIndexes];
188 }
189
190 inline int_v AliHLTTPCCASliceData::ClusterDataIndex( const AliHLTTPCCARow &row, uint_v hitIndex ) const
191 {
192   return fClusterDataIndex[row.fHitNumberOffset + hitIndex];
193 }
194
195 inline const AliHLTTPCCARow &AliHLTTPCCASliceData::Row( int rowIndex ) const
196 {
197   return fRows[rowIndex];
198 }
199
200 inline void AliHLTTPCCASliceData::MaximizeHitWeight( const AliHLTTPCCARow &row, uint_v hitIndex, int_v weight )
201 {
202   CAMath::AtomicMax( &fHitWeights[row.fHitNumberOffset + hitIndex], weight );
203 }
204
205 inline int_v AliHLTTPCCASliceData::HitWeight( const AliHLTTPCCARow &row, uint_v hitIndex ) const
206 {
207   return fHitWeights[row.fHitNumberOffset + hitIndex];
208 }
209
210 typedef AliHLTTPCCASliceData SliceData;
211
212 #endif // SLICEDATA_H