]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCTrackArray.h
correcting bounds check for array
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCTrackArray.h
1 // -*- Mode: C++ -*-
2 // @(#) $Id$
3 // Original: AliHLTTrackArray.h,v 1.7 2004/06/11 16:06:33 loizides 
4 #ifndef ALIHLTTPCTRACKARRAY_H
5 #define ALIHLTTPCTRACKARRAY_H
6
7 //* This file is property of and copyright by the ALICE HLT Project        * 
8 //* ALICE Experiment at CERN, All rights reserved.                         *
9 //* See cxx source for full Copyright notice                               *
10
11 /** @file   AliHLTTPCTrackArray.h
12     @author Uli Frankenfeld, maintained by Matthias Richter
13     @date   
14     @brief  Array of AliHLTTPCTracks
15 */
16
17 #include "AliHLTTPCRootTypes.h"
18
19 class AliHLTTPCConfMapTrack;
20 class AliHLTTPCTrack;
21 class AliHLTTPCTrackSegmentData;
22 class AliHLTTPCTrackSegmentDataV1;
23 class AliHLTExternalTrackParam;
24 /**
25  * @class AliHLTTPCTrackArray
26  * Array of AliHLTTrack objects.
27  * The class implements a dynamic array and handler methods.
28  *
29  * @ingroup alihlt_tpc
30  */
31 class AliHLTTPCTrackArray {
32  public:
33   /** default constructor */
34   AliHLTTPCTrackArray();
35   /**
36    * constructor 
37    * @param ntrack     initial size
38    */
39   AliHLTTPCTrackArray(Int_t ntrack);
40   /**
41    * constructor 
42    * @param tracktype  string describing type, one of
43    *   - AliHLTTPCTrack        -> 't'
44    *   - AliHLTTPCConfMapTrack -> 'c'
45    *   - AliHLTTPCHoughTrack   -> 'h'
46    *   - AliHLTTPCModelTrack   -> 'm'
47    * @param ntrack     initial size
48    */
49   AliHLTTPCTrackArray(const char* tracktype,Int_t ntrack);
50   /**
51    * constructor 
52    * @param tracktype  string describing type, one of
53    *   - AliHLTTPCTrack        -> 't'
54    *   - AliHLTTPCConfMapTrack -> 'c'
55    *   - AliHLTTPCHoughTrack   -> 'h'
56    *   - AliHLTTPCModelTrack   -> 'm'
57    */
58   AliHLTTPCTrackArray(const char* tracktype);
59   /** destructor */
60   virtual ~AliHLTTPCTrackArray();
61
62   /**
63    * Get type of track.
64    * @return one of
65    *   - 't' -> AliHLTTPCTrack        
66    *   - 'c' -> AliHLTTPCConfMapTrack 
67    *   - 'h' -> AliHLTTPCHoughTrack   
68    *   - 'm' -> AliHLTTPCModelTrack   
69    */
70   Int_t GetTrackType(){return fTrackType;}
71
72   /**
73    * Get size of the array.
74    * @return size of the array
75    */
76   Int_t GetSize() const {return fSize;}
77
78   /**
79    * Set size.
80    * If the current size is smaller, the array is grown to the new size.
81    * @return kTRUE if the array was grown, kFALSE otherwise
82    */
83   Bool_t SetSize(Int_t newsize=0);
84
85   Int_t GetNPresent() const {return (fNTracks- fNAbsent);}
86   Int_t GetNTracks() const {return fNTracks;}
87
88   /**
89    * Return pointer to next free track object.
90    * The array is grown if necessary.
91    */
92   AliHLTTPCTrack *NextTrack();
93   AliHLTTPCTrack *GetCheckedTrack(Int_t t){if(fIsPresent[t]) return fTrack[t]; return 0;}
94   AliHLTTPCTrack *GetTrack(Int_t t){return fTrack[t];}
95
96   void Remove(Int_t track); 
97   void RemoveLast() {fNTracks--;}
98   void Compress();
99   void Reset();
100   void QSort();
101   void QSort( AliHLTTPCTrack **a, Int_t first, Int_t last);
102   Int_t TrackCompare(AliHLTTPCTrack *a, AliHLTTPCTrack *b) const;
103
104   /**
105    * Fill track array from track segment array.
106    * Old method excluding buffer protection kept for backward compatibility.
107    * Forwarded to FillTracksChecked().
108    * @param ntracks      size of the input array
109    * @param tr           array of AliHLTTrackSegmentData
110    * @param slice        slice no to transform the tracks to
111    * @param bTransform   transform to global coordinates if 1
112    */
113   int FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr, Int_t slice=-1, Int_t bTransform=1);
114
115   /**
116    * Fill track array from track segment array.
117    * Reads the track from an array of AliHLTTrackSegmentData. The coordinates
118    * are transformed to global coordinates if the slice parameter is specified.
119    * In that case to internal slice variable is set to zero.
120    * 
121    * The sizeInByte parameter allows an additional buffer protection if
122    * non-zero. The size of the AliHLTTPCTrackSegmentData is not fixed due to
123    * variable array at the end of the structure. The pointer to the next
124    * entry must be set according to the variable array.
125    * @param ntracks      size of the input array
126    * @param tr           array of AliHLTTrackSegmentData
127    * @param sizeInByte   additional size protection
128    * @param slice        slice no to transform the tracks to
129    * @param bTransform   transform to global coordinates if 1
130    */
131   int FillTracksChecked(AliHLTTPCTrackSegmentData* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice=-1, Int_t bTransform=1);
132   int FillTracksChecked(AliHLTExternalTrackParam* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice=-1, Int_t bTransform=1);
133
134   /**
135    * Fill array from version1 structure.
136    * The version 1 of ALiHLTTPCTrackSegmentData was valid until July 2008
137    * revision 27415.
138    *
139    * Similar behavior like FillTracksChecked.
140    */
141   int FillTracksVersion1(AliHLTTPCTrackSegmentDataV1* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice=-1, Int_t bTransform=1);
142
143   UInt_t WriteTracks(AliHLTTPCTrackSegmentData* tr); //Write tracks
144   UInt_t WriteTracks(UInt_t & ntracks,AliHLTTPCTrackSegmentData* tr); //Write tracks
145   UInt_t GetOutSize();
146   UInt_t GetOutCount(){return (UInt_t) GetNPresent();}
147   void AddTracks(AliHLTTPCTrackArray *newtrack,Bool_t remove_old=kTRUE,Int_t slice=-1);//add all Tracks to this 
148   void AddLast(AliHLTTPCTrack *track);
149
150   AliHLTTPCTrack* operator[](int index);
151
152  private:
153   /** copy constructor prohibited */
154   AliHLTTPCTrackArray(const AliHLTTPCTrackArray&);
155   /** assignment operator prohibited */
156   AliHLTTPCTrackArray& operator=(const AliHLTTPCTrackArray&);
157
158   Char_t fTrackType; //track type
159   Int_t fSize; //size of array
160   Bool_t *fIsPresent;//!
161   Int_t fNAbsent; //ntracks absent
162
163   AliHLTTPCTrack **fTrack;//!
164   Int_t fNTracks; //ntracks in
165
166   UInt_t WriteConfMapTracks(AliHLTTPCTrackSegmentData* tr); 
167   void DeleteArray();
168
169   ClassDef(AliHLTTPCTrackArray,2) //Track array class
170 };
171
172 #endif