]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliTrackResiduals.cxx
Fixes for some mem-leaks: most changes where pretty basic (i.e. adding deletes).
[u/mrichter/AliRoot.git] / STEER / AliTrackResiduals.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //-----------------------------------------------------------------
17 //   Implementation of the base class for track residuals
18 //
19 //
20 //-----------------------------------------------------------------
21
22 #include "AliTrackResiduals.h"
23
24 #include "AliAlignObj.h"
25 #include "AliAlignObjParams.h"
26 #include "AliTrackPointArray.h"
27
28 ClassImp(AliTrackResiduals)
29
30 //_____________________________________________________________________________
31 AliTrackResiduals::AliTrackResiduals():
32   fN(0),
33   fLast(0),
34   fAlignObj(0),
35   fVolArray(0),
36   fTrackArray(0),
37   fChi2(0),
38   fNdf(0),
39   fMinNPoints(0),
40   fIsOwner(kTRUE)
41 {
42   // Default constructor
43   for (Int_t ipar=0; ipar<6; ipar++){
44     fBFixed[ipar] = kFALSE;
45     fFixed[ipar]  = 0.;
46   }  
47 }
48
49 //_____________________________________________________________________________
50 AliTrackResiduals::AliTrackResiduals(Int_t ntracks):
51   fN(ntracks),
52   fLast(0),
53   fAlignObj(0),
54   fVolArray(0),
55   fTrackArray(0),
56   fChi2(0),
57   fNdf(0),
58   fMinNPoints(0),
59   fIsOwner(kTRUE)
60 {
61   // Constructor
62   if (ntracks > 0) {
63     fVolArray = new AliTrackPointArray*[ntracks];
64     fTrackArray = new AliTrackPointArray*[ntracks];
65     for (Int_t itrack = 0; itrack < ntracks; itrack++)
66       fVolArray[itrack] = fTrackArray[itrack] = 0x0;
67   }
68   for (Int_t ipar=0; ipar<6; ipar++){
69     fBFixed[ipar] = kFALSE;
70     fFixed[ipar]  = 0.;
71   }  
72 }
73
74 //_____________________________________________________________________________
75 AliTrackResiduals::AliTrackResiduals(const AliTrackResiduals &res):
76   TObject(res),
77   fN(res.fN),
78   fLast(res.fLast),
79   fAlignObj(0),
80   fVolArray(0),
81   fTrackArray(0),
82   fChi2(res.fChi2),
83   fNdf(res.fNdf),
84   fMinNPoints(res.fMinNPoints),
85   fIsOwner(kTRUE)
86 {
87   // Copy constructor
88   // By default the created copy owns the track point arrays
89   if (res.fAlignObj)
90     fAlignObj = (AliAlignObj *)res.fAlignObj->Clone();
91
92   if (fN > 0) {
93     fVolArray = new AliTrackPointArray*[fN];
94     fTrackArray = new AliTrackPointArray*[fN];
95     for (Int_t itrack = 0; itrack < fN; itrack++)
96       {
97         if (res.fVolArray[itrack])
98           fVolArray[itrack] = new AliTrackPointArray(*res.fVolArray[itrack]);
99         else
100           fVolArray = 0x0;
101         if (res.fTrackArray[itrack])
102           fTrackArray[itrack] = new AliTrackPointArray(*res.fTrackArray[itrack]);
103         else
104           fTrackArray = 0x0;
105       }
106   }
107   for(Int_t i=0;i<6;i++) { 
108     fBFixed[i]=res.fBFixed[i];
109     fFixed[i]=res.fFixed[i];
110   }
111 }
112
113 //_____________________________________________________________________________
114 AliTrackResiduals &AliTrackResiduals::operator =(const AliTrackResiduals& res)
115 {
116   // assignment operator
117   // Does not copy the track point arrays
118   if(this==&res) return *this;
119   ((TObject *)this)->operator=(res);
120
121   fN = res.fN;
122   fLast = res.fLast;
123   fChi2 = res.fChi2;
124   fNdf  = res.fNdf;
125   fMinNPoints = res.fMinNPoints;
126   fIsOwner = kFALSE;
127   fAlignObj = res.fAlignObj;
128
129   fVolArray = res.fVolArray;
130   fTrackArray = res.fTrackArray;
131
132   for(Int_t i=0;i<6;i++) { 
133     fBFixed[i]=res.fBFixed[i];
134     fFixed[i]=res.fFixed[i];
135   }
136
137   return *this;
138 }
139
140 //_____________________________________________________________________________
141 AliTrackResiduals::~AliTrackResiduals()
142 {
143   // Destructor
144   if (fAlignObj) delete fAlignObj;
145   DeleteTrackPointArrays();
146 }
147
148 //_____________________________________________________________________________
149 void AliTrackResiduals::SetNTracks(Int_t ntracks)
150 {
151   // Set new size for the track point arrays.
152   // Delete the old arrays and allocate the
153   // new ones.
154   DeleteTrackPointArrays();
155
156   fN = ntracks;
157   fLast = 0;
158   fChi2 = 0;
159   fNdf  = 0;
160   fIsOwner = kTRUE;
161
162   if (ntracks > 0) {
163     fVolArray = new AliTrackPointArray*[ntracks];
164     fTrackArray = new AliTrackPointArray*[ntracks];
165     for (Int_t itrack = 0; itrack < ntracks; itrack++)
166       fVolArray[itrack] = fTrackArray[itrack] = 0x0;
167   }
168 }
169
170 //_____________________________________________________________________________
171 Bool_t AliTrackResiduals::AddTrackPointArrays(AliTrackPointArray *volarray, AliTrackPointArray *trackarray)
172 {
173   // Adds pair of track space point and
174   // track extrapolation point arrays
175   if (!fVolArray || !fTrackArray) return kFALSE;
176
177   if (!volarray || !trackarray) return kFALSE;
178
179   if (volarray->GetNPoints() < fMinNPoints) return kFALSE;
180
181   if (fLast >= fN) return kFALSE;
182
183   fVolArray[fLast] = volarray;
184   fTrackArray[fLast] = trackarray;
185   fLast++;
186
187   return kTRUE;
188 }
189
190 //_____________________________________________________________________________
191 void AliTrackResiduals::InitAlignObj()
192 {
193   // Create the alignment object 
194   // to be updated
195   if (fAlignObj) delete fAlignObj;
196   fAlignObj = new AliAlignObjParams;
197 }
198
199
200 //_____________________________________________________________________________
201 Bool_t AliTrackResiduals::GetTrackPointArrays(Int_t i, AliTrackPointArray* &volarray, AliTrackPointArray* &trackarray) const
202 {
203   // Provide an access to a pair of track point arrays
204   // with given index
205   if (i >= fLast) {
206     volarray = trackarray = 0x0;
207     return kFALSE;
208   }
209   else {
210     volarray = fVolArray[i];
211     trackarray = fTrackArray[i];
212     return kTRUE;
213   }
214 }
215
216 //_____________________________________________________________________________
217 void AliTrackResiduals::DeleteTrackPointArrays()
218 {
219   // Deletes the track point arrays only in case
220   // the object is their owner.
221   // Called by the destructor and SetNTracks methods.
222   if (fIsOwner) {
223     for (Int_t itrack = 0; itrack < fLast; itrack++)
224       {
225         delete fVolArray[itrack];
226         delete fTrackArray[itrack];
227       }
228     delete [] fVolArray;
229     delete [] fTrackArray;
230   }
231 }