bugfix: memory leak corrected (Stefan Kirsch)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTracklet.cxx
CommitLineData
196a8c4f 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: *
7 * for The ALICE HLT Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18// @file AliHLTTRDTracklet.cxx
19// @author Theodor Rascanu
20// @date
21// @brief A datacontainer for tracklets for the HLT.
22//
23
d679dd6c 24#include "AliHLTTRDTracklet.h"
0fae33c8 25
d679dd6c 26/**
27 * Default Constructor
28 */
29//============================================================================
30AliHLTTRDTracklet::AliHLTTRDTracklet():
93ce7d1b 31 fN(0),
93ce7d1b 32 fdX(-1),
33 fS2Y(-1),
e44c0591 34 fPt(-1),
d679dd6c 35 fX0(-1),
d679dd6c 36 fChi2(-1),
0fae33c8 37 // fExB(-1),
38 // fVD(-1),
39 // fT0(-1),
40 // fS2PRF(-1),
41 // fDiffL(-1),
42 // fDiffT(-1),
43 // fX(-1),
44 // fY(-1),
45 // fZ(-1),
46 // fS2Z(-1),
9630a0b8 47 fDet(-1),
0fae33c8 48 fBits(0),
9630a0b8 49 fCount(0),
93ce7d1b 50#if defined(__HP_aCC) || defined(__DECCXX) || defined(__SUNPRO_CC)
196a8c4f 51 fSize(sizeof(AliHLTTRDTracklet)-sizeof(fClusters[0])),
93ce7d1b 52#else
9630a0b8 53 fSize(sizeof(AliHLTTRDTracklet))
93ce7d1b 54#endif
d679dd6c 55{
56 InitArrays();
d679dd6c 57}
58
59/**
93ce7d1b 60 * Main Constructor
d679dd6c 61 */
62//============================================================================
93ce7d1b 63AliHLTTRDTracklet::AliHLTTRDTracklet(const AliTRDseedV1* const inTracklet):
64 fN(inTracklet->fN),
93ce7d1b 65 fdX(inTracklet->fdX),
66 fS2Y(inTracklet->fS2Y),
67 fPt(inTracklet->fPt),
93ce7d1b 68 fX0(inTracklet->fX0),
93ce7d1b 69 fChi2(inTracklet->fChi2),
0fae33c8 70 // fExB(inTracklet->fExB),
71 // fVD(inTracklet->fVD),
72 // fT0(inTracklet->fT0),
73 // fS2PRF(inTracklet->fS2PRF),
74 // fDiffL(inTracklet->fDiffL),
75 // fDiffT(inTracklet->fDiffT),
76 // fX(inTracklet->fX),
77 // fY(inTracklet->fY),
78 // fZ(inTracklet->fZ),
79 // fS2Z(inTracklet->fS2Z),
9630a0b8 80 fDet(inTracklet->fDet),
0fae33c8 81 fBits(0),
9630a0b8 82 fCount(0),
93ce7d1b 83#if defined(__HP_aCC) || defined(__DECCXX) || defined(__SUNPRO_CC)
196a8c4f 84 fSize(sizeof(AliHLTTRDTracklet)-sizeof(fClusters[0])),
93ce7d1b 85#else
9630a0b8 86 fSize(sizeof(AliHLTTRDTracklet))
93ce7d1b 87#endif
d679dd6c 88{
93ce7d1b 89 CopyDataMembers(inTracklet);
d679dd6c 90}
91
92/**
93 * Copy simple (non-pointer) data members from TRDTracklet to HLTTRDTracklet
94 */
95//============================================================================
93ce7d1b 96void AliHLTTRDTracklet::CopyDataMembers(const AliTRDseedV1* const inTracklet)
d679dd6c 97{
98 for (Int_t i=0; i < 2; i++){
93ce7d1b 99 fYref[i] = inTracklet->fYref[i];
100 fZref[i] = inTracklet->fZref[i];
101 fYfit[i] = inTracklet->fYfit[i];
102 fZfit[i] = inTracklet->fZfit[i];
d679dd6c 103 }
8c5cf34e 104 fC[0] = inTracklet->GetC();
105#ifndef HAVE_NOT_ALITRD_SEEDV1_r39693
106 fC[1] = inTracklet->GetC(1);
107#endif //HAVE_NOT_ALITRD_SEEDV1_r39693
9630a0b8 108 for (Int_t i=0; i < 3; i++){
109 fPad[i] = inTracklet->fPad[i];
0fae33c8 110 // fCov[i] = inTracklet->fCov[i];
9630a0b8 111 }
0fae33c8 112
113 // for (Int_t i=0; i < 7; i++){
114 // fRefCov[i] = inTracklet->fRefCov[i];
115 // }
116
117 // for (Int_t i=0; i < AliTRDseedV1::kNslices; i++){
118 // fdEdx[i] = inTracklet->fdEdx[i];
119 // }
d679dd6c 120
93ce7d1b 121 for (Int_t i=0; i < AliPID::kSPECIES; i++){
122 fProb[i] = inTracklet->fProb[i];
d679dd6c 123 }
124
0fae33c8 125 fBits = UInt_t(inTracklet->TestBits(-1)) >> 14;
126
127 for (Int_t iTimeBin = 0; iTimeBin < AliTRDseedV1::kNclusters; iTimeBin++){
128 AliTRDcluster* trdCluster = inTracklet->GetClusters(iTimeBin);
129 if (trdCluster){
130 fPos[fCount] = iTimeBin;
196a8c4f 131 new (&fClusters[fCount]) AliHLTTRDExtCluster(trdCluster);
0fae33c8 132 fCount++;
196a8c4f 133 fSize += sizeof(fClusters[0]);
93ce7d1b 134 }
0fae33c8 135 }
136 //if((void*)&fClusters[fCount]!=(void*)GetEndPointer()){printf("ERRR");return;}
d679dd6c 137}
138
139/**
140 * Copy data to the output TRDseedV1
141 */
142//============================================================================
93ce7d1b 143void AliHLTTRDTracklet::ExportTRDTracklet(AliTRDseedV1* const outTracklet) const
d679dd6c 144{
93ce7d1b 145 //outTracklet->Reset(); we always use a fresh trdtracklet as input, so this is useless
d8731936 146 outTracklet->SetBit(AliTRDseedV1::kOwner);
93ce7d1b 147
148 outTracklet->fN = fN;
93ce7d1b 149 outTracklet->fdX = fdX;
150 outTracklet->fX0 = fX0;
151 outTracklet->fS2Y = fS2Y;
152 outTracklet->fPt = fPt;
8c5cf34e 153 outTracklet->SetC(fC[0]);
154#ifndef HAVE_NOT_ALITRD_SEEDV1_r39693
155 outTracklet->SetC(fC[1], 1);
156#endif //HAVE_NOT_ALITRD_SEEDV1_r39693
93ce7d1b 157 outTracklet->fChi2 = fChi2;
0fae33c8 158 // outTracklet->fExB = fExB;
159 // outTracklet->fVD = fVD;
160 // outTracklet->fT0 = fT0;
161 // outTracklet->fS2PRF = fS2PRF;
162 // outTracklet->fDiffL = fDiffL;
163 // outTracklet->fDiffT = fDiffT;
164 // outTracklet->fX = fX;
165 // outTracklet->fY = fY;
166 // outTracklet->fZ = fZ;
167 // outTracklet->fS2Z = fS2Z;
168 outTracklet->fDet = fDet;
93ce7d1b 169
d679dd6c 170 for (Int_t i=0; i < 2; i++){
93ce7d1b 171 outTracklet->fYref[i] = fYref[i];
172 outTracklet->fZref[i] = fZref[i];
173 outTracklet->fYfit[i] = fYfit[i];
174 outTracklet->fZfit[i] = fZfit[i];
d679dd6c 175 }
d679dd6c 176
9630a0b8 177 for (Int_t i=0; i < 3; i++){
178 outTracklet->fPad[i] = fPad[i];
0fae33c8 179 // outTracklet->fCov[i] = fCov[i];
9630a0b8 180 }
181
0fae33c8 182 // for (Int_t i=0; i < 7; i++){
183 // outTracklet->fRefCov[i] = fRefCov[i];
184 // }
185
186 // for (Int_t i=0; i < AliTRDseedV1::kNslices; i++){
187 // outTracklet->fdEdx[i] = fdEdx[i];
188 // }
189
93ce7d1b 190 for (Int_t i=0; i < AliPID::kSPECIES; i++){
191 outTracklet->fProb[i] = fProb[i];
d679dd6c 192 }
e3cf3d02 193
0fae33c8 194 outTracklet->SetBit(UInt_t(fBits)<<14);
195
196 for(Int_t iCluster=0; iCluster < fCount; iCluster++){
93ce7d1b 197 AliTRDcluster *trdCluster = new AliTRDcluster();
d55e8c51 198 fClusters[iCluster].ExportTRDCluster(trdCluster);
196a8c4f 199 trdCluster->SetDetector(fDet);
0fae33c8 200 outTracklet->fClusters[fPos[iCluster]] = trdCluster;
201 outTracklet->fIndexes[fPos[iCluster]] = iCluster;
d679dd6c 202 }
d679dd6c 203}
204
205
206/**
207 * Init arrays
208 */
209//============================================================================
210void AliHLTTRDTracklet::InitArrays()
211{
d679dd6c 212 for (Int_t i=0; i < 2; i++){
213 fYref[i] = -1;
214 fZref[i] = -1;
d679dd6c 215 fYfit[i] = -1;
216 fZfit[i] = -1;
d679dd6c 217 }
68f9b6bd 218 fC[0] = 0.; fC[1] = 0.;
93ce7d1b 219 for (Int_t i=0; i < AliPID::kSPECIES; i++)
220 fProb[i]=0;
288725ab 221 for (Int_t i=0; i<AliTRDseedV1::kNclusters; i++)
222 fPos[i]=0;
223
d679dd6c 224}
225
226/**
227 * Prints main info about tracklet
228 */
229//============================================================================
93ce7d1b 230void AliHLTTRDTracklet::Print(Bool_t printClusters) const
d679dd6c 231{
232 //printf("--hltTracklet-- addr 0x%p(%i); fSize %i\n", this, (int)this, fSize);
93ce7d1b 233 printf(" fDet %i; fPt %f; fdX %f fN %i\n", fDet, fPt, fdX, fN);
d679dd6c 234
e3cf3d02 235 if(!printClusters) return;
d55e8c51 236 for (UInt_t iCluster = 0; iCluster < fCount; iCluster++){
237 printf(" [%i] ",iCluster);
238 fClusters[iCluster].Print();
d679dd6c 239 }
d679dd6c 240}
241
242/**
196a8c4f 243 * Save tracklet at block position
d679dd6c 244 */
245//============================================================================
196a8c4f 246AliHLTUInt32_t AliHLTTRDTracklet::SaveAt(AliHLTUInt8_t *const block, const AliTRDseedV1* const inTracklet)
247{
248 AliHLTUInt32_t size=0;
249
250 memcpy(block,inTracklet,sizeof(AliTRDseedV1));
251 size+=sizeof(AliTRDseedV1);
252
253 for(int i=0; i<AliTRDseedV1::kNclusters; i++){
254 AliTRDcluster* inClust = inTracklet->GetClusters(i);
255 if(inClust) size+=AliHLTTRDCluster::SaveAt(block+size, inClust);
256 }
257
258 return size;
259}
260
261/**
262 * Read tracklet from block
263 */
264//============================================================================
265AliHLTUInt32_t AliHLTTRDTracklet::LoadFrom(AliTRDseedV1 *const outTracklet, const AliHLTUInt8_t *const block)
266{
267 AliHLTUInt32_t size=0;
268
269 memcpy(((AliHLTUInt8_t*)outTracklet)+sizeof(void*),block+sizeof(void*),sizeof(AliTRDseedV1)-sizeof(void*));
270 size+=sizeof(AliTRDseedV1);
d8731936 271
196a8c4f 272 for(int i=0; i<AliTRDseedV1::kNclusters; i++){
273 if(outTracklet->GetClusters(i)){
274 AliTRDcluster *const outClust = new AliTRDcluster;
275 outTracklet->fClusters[i]=outClust;
276 size+=AliHLTTRDCluster::LoadFrom(outClust, block+size);
277 }
278 }
279
280 outTracklet->SetBit(AliTRDseedV1::kOwner);
281
282 return size;
283}