Fixes for some mem-leaks: most changes where pretty basic (i.e. adding deletes).
[u/mrichter/AliRoot.git] / STEER / AliESDEvent.cxx
CommitLineData
af885e0f 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/* $Id$ */
17
18//-----------------------------------------------------------------
f56a9fa7 19// Implementation of the AliESDEvent class
20// This is the class to deal with during the phisical analysis of data.
21// It also ensures the backward compatibility with the old ESD format.
22//
23// Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
af885e0f 24//-----------------------------------------------------------------
25
26#include "TList.h"
27#include <TNamed.h>
28
29#include "AliESDEvent.h"
30#include "AliESDfriend.h"
31#include "AliESDVZERO.h"
32#include "AliESDHLTtrack.h"
33#include "AliESDFMD.h"
34#include "AliESD.h"
f0106218 35#include "AliESDMuonTrack.h"
36#include "AliESDPmdTrack.h"
37#include "AliESDTrdTrack.h"
38#include "AliESDVertex.h"
39#include "AliESDcascade.h"
40#include "AliESDPmdTrack.h"
41#include "AliESDTrdTrack.h"
42#include "AliESDVertex.h"
43#include "AliESDcascade.h"
44#include "AliESDkink.h"
45#include "AliESDtrack.h"
46#include "AliESDHLTtrack.h"
47#include "AliESDCaloCluster.h"
48#include "AliESDv0.h"
49#include "AliESDFMD.h"
50#include "AliESDVZERO.h"
51#include "AliMultiplicity.h"
52#include "AliRawDataErrorLog.h"
af885e0f 53
54
55ClassImp(AliESDEvent)
56
60e8f114 57
58
59// here we define the names, some classes are no TNamed, therefore the classnames
60// are the Names
61 const char* AliESDEvent::fESDListName[kESDListN] = {"AliESDRun",
62 "AliESDHeader",
63 "AliESDZDC",
64 "AliESDFMD",
65 "AliESDVZERO",
66 "AliESDTZERO",
67 "SPDVertex",
68 "PrimaryVertex",
69 "AliMultiplicity",
70 "PHOSTrigger",
71 "EMCALTrigger",
72 "Tracks",
73 "MuonTracks",
74 "PmdTracks",
75 "TrdTracks",
76 "V0s",
72da5d8c 77 "Cascades",
60e8f114 78 "Kinks",
79 "CaloClusters",
80 "AliRawDataErrorLogs"};
af885e0f 81//______________________________________________________________________________
82AliESDEvent::AliESDEvent():
024c7734 83 AliVEvent(),
af885e0f 84 fESDObjects(new TList()),
85 fESDRun(0),
86 fHeader(0),
87 fESDZDC(0),
88 fESDFMD(0),
89 fESDVZERO(0),
90 fESDTZERO(0),
91 fSPDVertex(0),
92 fPrimaryVertex(0),
93 fSPDMult(0),
94 fPHOSTrigger(0),
95 fEMCALTrigger(0),
96 fTracks(0),
97 fMuonTracks(0),
98 fPmdTracks(0),
99 fTrdTracks(0),
100 fV0s(0),
101 fCascades(0),
102 fKinks(0),
103 fCaloClusters(0),
104 fErrorLogs(0),
105 fESDOld(0),
60e8f114 106 fConnected(kFALSE),
af885e0f 107 fEMCALClusters(0),
108 fFirstEMCALCluster(-1),
109 fPHOSClusters(0),
110 fFirstPHOSCluster(-1)
111{
112}
113//______________________________________________________________________________
114AliESDEvent::AliESDEvent(const AliESDEvent& esd):
024c7734 115 AliVEvent(esd),
af885e0f 116 fESDObjects(new TList()),
117 fESDRun(new AliESDRun(*esd.fESDRun)),
118 fHeader(new AliESDHeader(*esd.fHeader)),
119 fESDZDC(new AliESDZDC(*esd.fESDZDC)),
120 fESDFMD(new AliESDFMD(*esd.fESDFMD)),
121 fESDVZERO(new AliESDVZERO(*esd.fESDVZERO)),
122 fESDTZERO(new AliESDTZERO(*esd.fESDTZERO)),
123 fSPDVertex(new AliESDVertex(*esd.fSPDVertex)),
124 fPrimaryVertex(new AliESDVertex(*esd.fPrimaryVertex)),
125 fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
126 fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
127 fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
128 fTracks(new TClonesArray(*esd.fTracks)),
129 fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
130 fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
131 fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
132 fV0s(new TClonesArray(*esd.fV0s)),
133 fCascades(new TClonesArray(*esd.fCascades)),
134 fKinks(new TClonesArray(*esd.fKinks)),
135 fCaloClusters(new TClonesArray(*esd.fCaloClusters)),
136 fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
137 fESDOld(new AliESD(*esd.fESDOld)),
60e8f114 138 fConnected(esd.fConnected),
af885e0f 139 fEMCALClusters(esd.fEMCALClusters),
140 fFirstEMCALCluster(esd.fFirstEMCALCluster),
141 fPHOSClusters(esd.fPHOSClusters),
142 fFirstPHOSCluster(esd.fFirstPHOSCluster)
143
144{
145 // CKB init in the constructor list and only add here ...
146 AddObject(fESDRun);
147 AddObject(fHeader);
148 AddObject(fESDZDC);
149 AddObject(fESDFMD);
150 AddObject(fESDVZERO);
151 AddObject(fESDTZERO);
152 AddObject(fSPDVertex);
153 AddObject(fPrimaryVertex);
154 AddObject(fSPDMult);
155 AddObject(fPHOSTrigger);
156 AddObject(fEMCALTrigger);
157 AddObject(fTracks);
158 AddObject(fMuonTracks);
159 AddObject(fPmdTracks);
160 AddObject(fTrdTracks);
161 AddObject(fV0s);
162 AddObject(fCascades);
163 AddObject(fKinks);
164 AddObject(fCaloClusters);
165 AddObject(fErrorLogs);
166
167 GetStdContent();
168
169}
170
171//______________________________________________________________________________
172AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
173
174 // Assignment operator
175
176 if(&source == this) return *this;
024c7734 177 AliVEvent::operator=(source);
af885e0f 178
179 fESDRun = new AliESDRun(*source.fESDRun);
180 fHeader = new AliESDHeader(*source.fHeader);
181 fESDZDC = new AliESDZDC(*source.fESDZDC);
182 fESDFMD = new AliESDFMD(*source.fESDFMD);
183 fESDVZERO = new AliESDVZERO(*source.fESDVZERO);
184 fESDTZERO = new AliESDTZERO(*source.fESDTZERO);
185 fSPDVertex = new AliESDVertex(*source.fSPDVertex);
186 fPrimaryVertex = new AliESDVertex(*source.fPrimaryVertex);
187 fSPDMult = new AliMultiplicity(*source.fSPDMult);
188 fPHOSTrigger = new AliESDCaloTrigger(*source.fPHOSTrigger);
189 fEMCALTrigger = new AliESDCaloTrigger(*source.fEMCALTrigger);
190 fTracks = new TClonesArray(*source.fTracks);
191 fMuonTracks = new TClonesArray(*source.fMuonTracks);
192 fPmdTracks = new TClonesArray(*source.fPmdTracks);
193 fTrdTracks = new TClonesArray(*source.fTrdTracks);
194 fV0s = new TClonesArray(*source.fV0s);
195 fCascades = new TClonesArray(*source.fCascades);
196 fKinks = new TClonesArray(*source.fKinks);
197 fCaloClusters = new TClonesArray(*source.fCaloClusters);
198 fErrorLogs = new TClonesArray(*source.fErrorLogs);
199 fESDOld = new AliESD(*source.fESDOld);
200 // CKB this way?? or
201 // or AddObject( fESDZDC = new AliESDZDC(*source.fESDZDC));
202
203 fESDObjects = new TList();
204 AddObject(fESDRun);
205 AddObject(fHeader);
206 AddObject(fESDZDC);
207 AddObject(fESDFMD);
208 AddObject(fESDVZERO);
209 AddObject(fESDTZERO);
210 AddObject(fSPDVertex);
211 AddObject(fPrimaryVertex);
212 AddObject(fSPDMult);
213 AddObject(fPHOSTrigger);
214 AddObject(fEMCALTrigger);
215 AddObject(fTracks);
216 AddObject(fMuonTracks);
217 AddObject(fPmdTracks);
218 AddObject(fTrdTracks);
219 AddObject(fV0s);
220 AddObject(fCascades);
221 AddObject(fKinks);
222 AddObject(fCaloClusters);
223 AddObject(fErrorLogs);
224
60e8f114 225 fConnected = source.fConnected;
af885e0f 226 fEMCALClusters = source.fEMCALClusters;
227 fFirstEMCALCluster = source.fFirstEMCALCluster;
228 fPHOSClusters = source.fPHOSClusters;
229 fFirstPHOSCluster = source.fFirstPHOSCluster;
230
231
232
233 return *this;
234
235}
236
237
238//______________________________________________________________________________
239AliESDEvent::~AliESDEvent()
240{
241 //
242 // Standard destructor
243 //
244
001b9beb 245 // everthing on the list gets deleted automatically
139f2194 246
247
60e8f114 248 if(fESDObjects&&!fConnected)
249 {
250 delete fESDObjects;
251 fESDObjects = 0;
252 }
139f2194 253
60e8f114 254
af885e0f 255}
256
257//______________________________________________________________________________
258void AliESDEvent::Reset()
259{
260
261
262 // Reset the standard contents
263 ResetStdContent();
264
265 if(fESDOld)fESDOld->Reset();
001b9beb 266 // call reset for user supplied data?
af885e0f 267}
268
269void AliESDEvent::ResetStdContent()
270{
271 // Reset the standard contents
272 if(fESDRun) fESDRun->Reset();
273 if(fHeader) fHeader->Reset();
274 if(fESDZDC) fESDZDC->Reset();
275 if(fESDFMD) fESDFMD->Clear(); // why clear.... need consistend names
276 // if(fESDVZERO) fESDVZERO->; // NOT IMPLEMENTED
277 // if(fESDVZERO) new (fESDVZERO) AliESDVZERO();
278 if(fESDTZERO) fESDTZERO->Reset();
279 // CKB no clear/reset implemented
280 if(fSPDVertex){
316c6cd9 281 fSPDVertex->~AliESDVertex();
af885e0f 282 new (fSPDVertex) AliESDVertex();
60e8f114 283 fSPDVertex->SetName(fESDListName[kSPDVertex]);
af885e0f 284 }
285 if(fPrimaryVertex){
316c6cd9 286 fPrimaryVertex->~AliESDVertex();
af885e0f 287 new (fPrimaryVertex) AliESDVertex();
60e8f114 288 fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
af885e0f 289 }
316c6cd9 290 if(fSPDMult){
291 fSPDMult->~AliMultiplicity();
292 new (fSPDMult) AliMultiplicity();
293 }
af885e0f 294 if(fPHOSTrigger)fPHOSTrigger->Reset();
295 if(fEMCALTrigger)fEMCALTrigger->Reset();
bc9a7b42 296 if(fTracks)fTracks->Delete();
af885e0f 297 if(fMuonTracks)fMuonTracks->Clear();
298 if(fPmdTracks)fPmdTracks->Clear();
299 if(fTrdTracks)fTrdTracks->Clear();
300 if(fV0s)fV0s->Clear();
301 if(fCascades)fCascades->Clear();
302 if(fKinks)fKinks->Clear();
bc9a7b42 303 if(fCaloClusters)fCaloClusters->Delete();
af885e0f 304 if(fErrorLogs) fErrorLogs->Clear();
305
60e8f114 306 // don't reset fconnected fConnected ;
307
af885e0f 308 fEMCALClusters=0;
309 fFirstEMCALCluster=-1;
310 fPHOSClusters=0;
311 fFirstPHOSCluster=-1;
312}
313
314
315Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
316 //
317 // Add V0
318 //
319 TClonesArray &fv = *fV0s;
320 Int_t idx=fV0s->GetEntriesFast();
321 new(fv[idx]) AliESDv0(*v);
322 return idx;
323}
324
325//______________________________________________________________________________
326void AliESDEvent::Print(Option_t *) const
327{
328 //
329 // Print header information of the event
330 //
331 printf("ESD run information\n");
332 printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld Magnetic field %f \n",
333 GetEventNumberInFile(),
334 GetBunchCrossNumber(),
335 GetOrbitNumber(),
336 GetPeriodNumber(),
337 GetRunNumber(),
338 GetTriggerMask(),
339 GetMagneticField() );
340 printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
341 fPrimaryVertex->GetXv(), fPrimaryVertex->GetXRes(),
342 fPrimaryVertex->GetYv(), fPrimaryVertex->GetYRes(),
343 fPrimaryVertex->GetZv(), fPrimaryVertex->GetZRes());
344 printf("Mean vertex in RUN: X=%.4f Y=%.4f cm\n",
345 GetDiamondX(),GetDiamondY());
346 printf("SPD Multiplicity. Number of tracklets %d \n",
347 fSPDMult->GetNumberOfTracklets());
348 printf("Number of tracks: \n");
349 printf(" charged %d\n", GetNumberOfTracks());
350 printf(" muon %d\n", GetNumberOfMuonTracks());
351 printf(" pmd %d\n", GetNumberOfPmdTracks());
352 printf(" trd %d\n", GetNumberOfTrdTracks());
353 printf(" v0 %d\n", GetNumberOfV0s());
354 printf(" cascades %d\n", GetNumberOfCascades());
355 printf(" kinks %d\n", GetNumberOfKinks());
356 printf(" CaloClusters %d\n", GetNumberOfCaloClusters());
357 printf(" phos %d\n", GetNumberOfPHOSClusters());
358 printf(" emcal %d\n", GetNumberOfEMCALClusters());
359 printf(" FMD %s\n", (fESDFMD ? "yes" : "no"));
360 printf(" VZERO %s\n", (fESDVZERO ? "yes" : "no"));
024c7734 361
362 return;
af885e0f 363}
364
365void AliESDEvent::SetESDfriend(const AliESDfriend *ev) {
366 //
367 // Attaches the complementary info to the ESD
368 //
369 if (!ev) return;
370
5300bdab 371 // to be sure that we set the tracks also
372 // in case of old esds
60e8f114 373 // if(fESDOld)CopyFromOldESD();
5300bdab 374
af885e0f 375 Int_t ntrk=ev->GetNumberOfTracks();
376
377 for (Int_t i=0; i<ntrk; i++) {
378 const AliESDfriendTrack *f=ev->GetTrack(i);
379 GetTrack(i)->SetFriendTrack(f);
380 }
381}
382
d64bd07d 383Bool_t AliESDEvent::RemoveTrack(Int_t /*i*/) {
384 // ---------------------------------------------------------
385 // Remove track
386 // ---------------------------------------------------------
387
388 // Check if this track comes from a reconstructed decay
389 // if (yes) return kFALSE
390
391 // Remap the indices of the daughters of recosntructed decays
392
393 // Remove the track
394 // delete fTracks->RemoveAt(i);
395
396 // Compress the array with tracks
397 // fTracks->Compress();
398
399 return kTRUE;
400}
401
402
af885e0f 403Int_t AliESDEvent::AddTrack(const AliESDtrack *t) {
404 // Add track
405 TClonesArray &ftr = *fTracks;
406 AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
407 track->SetID(fTracks->GetEntriesFast()-1);
408 return track->GetID();
409}
410
f0106218 411 void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) {
412 TClonesArray &fmu = *fMuonTracks;
413 new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
414}
415
416void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) {
417 TClonesArray &fpmd = *fPmdTracks;
418 new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
419}
420
421void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) {
422 TClonesArray &ftrd = *fTrdTracks;
423 new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
424}
425
426
427
428
af885e0f 429Int_t AliESDEvent::AddKink(const AliESDkink *c) {
430 // Add kink
431 TClonesArray &fk = *fKinks;
432 AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
433 kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
434 return fKinks->GetEntriesFast()-1;
435}
436
f0106218 437
438void AliESDEvent::AddCascade(const AliESDcascade *c) {
439 TClonesArray &fc = *fCascades;
440 new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
441}
442
443
af885e0f 444Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) {
445 // Add calocluster
446 TClonesArray &fc = *fCaloClusters;
447 AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
448 clus->SetID(fCaloClusters->GetEntriesFast()-1);
449 return fCaloClusters->GetEntriesFast()-1;
450 }
451
452
f0106218 453 void AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) {
454 TClonesArray &errlogs = *fErrorLogs;
455 new(errlogs[errlogs.GetEntriesFast()]) AliRawDataErrorLog(*log);
456 }
457
60e8f114 458void AliESDEvent::SetVertex(const AliESDVertex *vertex) {
459 // use already allocated space
460 if(fSPDVertex){
316c6cd9 461 *fSPDVertex = *vertex;
60e8f114 462 fSPDVertex->SetName(fESDListName[kSPDVertex]);
463 }
464}
465
466void AliESDEvent::SetPrimaryVertex(const AliESDVertex *vertex) {
60e8f114 467 if(fPrimaryVertex){
316c6cd9 468 *fPrimaryVertex = *vertex;
60e8f114 469 fPrimaryVertex->SetName(fESDListName[kPrimaryVertex]);
470 }
471}
472
f0106218 473void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) {
474 if(fSPDMult){
316c6cd9 475 *fSPDMult = *mul;
f0106218 476 }
477}
478
479
af885e0f 480void AliESDEvent::SetFMDData(AliESDFMD * obj) {
481 // use already allocated space
482 if(fESDFMD){
316c6cd9 483 *fESDFMD = *obj;
af885e0f 484 }
485}
486
487void AliESDEvent::SetVZEROData(AliESDVZERO * obj){
488 // use already allocated space
489 if(fESDVZERO)
490 new(fESDVZERO) AliESDVZERO(*obj);
491}
492
493void AliESDEvent::GetESDfriend(AliESDfriend *ev) const {
494 //
495 // Extracts the complementary info from the ESD
496 //
497 if (!ev) return;
498
499 Int_t ntrk=GetNumberOfTracks();
500
501 for (Int_t i=0; i<ntrk; i++) {
502 const AliESDtrack *t=GetTrack(i);
503 const AliESDfriendTrack *f=t->GetFriendTrack();
504 ev->AddTrack(f);
505 }
506}
507
508
509void AliESDEvent::AddObject(TObject* obj)
510{
511 // Add an object to the list of object.
512 // Please be aware that in order to increase performance you should
513 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
514 fESDObjects->SetOwner(kTRUE);
515 fESDObjects->AddLast(obj);
516}
517
518
519void AliESDEvent::GetStdContent()
520{
521 // set pointers for standard content
60e8f114 522 // get by name much safer and not a big overhead since not called very often
523
524 fESDRun = (AliESDRun*)fESDObjects->FindObject(fESDListName[kESDRun]);
525 fHeader = (AliESDHeader*)fESDObjects->FindObject(fESDListName[kHeader]);
526 fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fESDListName[kESDZDC]);
527 fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fESDListName[kESDFMD]);
528 fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fESDListName[kESDVZERO]);
529 fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fESDListName[kESDTZERO]);
530 fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fESDListName[kSPDVertex]);
531 fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fESDListName[kPrimaryVertex]);
532 fSPDMult = (AliMultiplicity*)fESDObjects->FindObject(fESDListName[kSPDMult]);
533 fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fESDListName[kPHOSTrigger]);
534 fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fESDListName[kEMCALTrigger]);
535 fTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kTracks]);
536 fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kMuonTracks]);
537 fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kPmdTracks]);
538 fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kTrdTracks]);
539 fV0s = (TClonesArray*)fESDObjects->FindObject(fESDListName[kV0s]);
540 fCascades = (TClonesArray*)fESDObjects->FindObject(fESDListName[kCascades]);
541 fKinks = (TClonesArray*)fESDObjects->FindObject(fESDListName[kKinks]);
542 fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fESDListName[kCaloClusters]);
543 fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fESDListName[kErrorLogs]);
af885e0f 544
545}
546
547void AliESDEvent::SetStdNames(){
548 // Set the names of the standard contents
60e8f114 549 //
550 if(fESDObjects->GetEntries()==kESDListN){
551 for(int i = 0;i < fESDObjects->GetEntries();i++){
552 TObject *fObj = fESDObjects->At(i);
553 if(fObj->InheritsFrom("TNamed")){
554 ((TNamed*)fObj)->SetName(fESDListName[i]);
555 }
556 else if(fObj->InheritsFrom("TClonesArray")){
557 ((TClonesArray*)fObj)->SetName(fESDListName[i]);
558 }
559 }
560 }
561 else{
562 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
563 }
af885e0f 564}
565
566void AliESDEvent::CreateStdContent()
567{
568 // create the standard AOD content and set pointers
569
570 // create standard objects and add them to the TList of objects
571 AddObject(new AliESDRun());
572 AddObject(new AliESDHeader());
573 AddObject(new AliESDZDC());
574 AddObject(new AliESDFMD());
575 AddObject(new AliESDVZERO());
576 AddObject(new AliESDTZERO());
577 AddObject(new AliESDVertex());
578 AddObject(new AliESDVertex());
579 AddObject(new AliMultiplicity());
580 AddObject(new AliESDCaloTrigger());
581 AddObject(new AliESDCaloTrigger());
582 AddObject(new TClonesArray("AliESDtrack",0));
583 AddObject(new TClonesArray("AliESDMuonTrack",0));
584 AddObject(new TClonesArray("AliESDPmdTrack",0));
585 AddObject(new TClonesArray("AliESDTrdTrack",0));
586 AddObject(new TClonesArray("AliESDv0",0));
587 AddObject(new TClonesArray("AliESDcascade",0));
588 AddObject(new TClonesArray("AliESDkink",0));
589 AddObject(new TClonesArray("AliESDCaloCluster",0));
590 AddObject(new TClonesArray("AliRawDataErrorLog",0));
591
592 // check the order of the indices against enum...
593
af885e0f 594 // set names
595 SetStdNames();
60e8f114 596 // read back pointers
597 GetStdContent();
af885e0f 598}
599
001b9beb 600TObject* AliESDEvent::FindListObject(const char *name){
601 if(fESDObjects)return fESDObjects->FindObject(name);
602 return 0;
603}
604
af885e0f 605void AliESDEvent::ReadFromTree(TTree *tree){
024c7734 606
607 // load the TTree
608 tree->LoadTree(0);
609
001b9beb 610 // if we find the "ESD" branch on the tree we do have the old structure
af885e0f 611 if(tree->GetBranch("ESD")){
b93c2026 612 char ** address = (char **)(tree->GetBranch("ESD")->GetAddress());
613 if (!address) {
614 printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
615 tree->SetBranchAddress("ESD",&fESDOld);
616 } else {
617 printf("%s %d AliESDEvent::ReadFromTree() Reading old Tree \n",(char*)__FILE__,__LINE__);
618 printf("%s %d Branch already connected. Using existing branch address. \n",(char*)__FILE__,__LINE__);
619 fESDOld = (AliESD*) (*address);
620 }
621
622
623 CreateStdContent(); // create for copy
624 // when reading back we are not owner of the list
625 // must not delete it
626 fESDObjects->SetOwner(kFALSE);
627 return;
af885e0f 628 }
629
630 fESDOld = 0;
631
632
633 // Try to find AliESDEvent
634 AliESDEvent *esdEvent = 0;
635 esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
bff64acf 636 //esdEvent = (AliESDEvent*)tree->GetUserInfo()->FindObject("AliESDEvent");
af885e0f 637
001b9beb 638 if(esdEvent){
941603c0 639 // Check if already connected to tree
139f2194 640 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
641 if (connectedList) {
642 // If connected use the connected list if objects
643 fESDObjects->Delete();
b5bc83df 644 fESDObjects = connectedList;
645 GetStdContent();
60e8f114 646 fConnected = true;
139f2194 647 return;
648 }
649 // Connect to tree
001b9beb 650 if(fESDObjects->GetEntries()!=0){
651 // this should not happen here put a warning?
652 }
653 // prevent a memory leak when reading back the TList
654 delete fESDObjects;
655 fESDObjects = 0;
af885e0f 656 // create a new TList from the UserInfo TList...
657 // copy constructor does not work...
658 fESDObjects = (TList*)(esdEvent->GetList()->Clone());
139f2194 659 fESDObjects->SetOwner(kFALSE);
af885e0f 660 if(fESDObjects->GetEntries()<kESDListN){
941603c0 661 printf("%s %d AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
662 (char*)__FILE__,__LINE__,fESDObjects->GetEntries(),kESDListN);
af885e0f 663 }
664 // set the branch addresses
665 TIter next(fESDObjects);
666 TNamed *el;
667 while((el=(TNamed*)next())){
668 TString bname(el->GetName());
669
670 if(bname.CompareTo("AliESDfriend")==0)
671 {
672 // AliESDfriend does not have a name ...
af885e0f 673 tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
674 }
675 else{
676 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
677 }
678 }
679 GetStdContent();
680 // when reading back we are not owner of the list
681 // must not delete it
682 fESDObjects->SetOwner(kFALSE);
60e8f114 683 fESDObjects->SetName("ESDObjectsConnectedToTree");
139f2194 684 // we are not owner of the list objects
685 // must not delete it
60e8f114 686 tree->GetUserInfo()->Add(fESDObjects);
687 fConnected = true;
af885e0f 688 }// no esdEvent
689 else {
001b9beb 690 // we can't get the list from the user data, create standard content
691 // and set it by hand (no ESDfriend at the moment
af885e0f 692 CreateStdContent();
693 TIter next(fESDObjects);
694 TNamed *el;
695 while((el=(TNamed*)next())){
696 TString bname(el->GetName());
697 tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
698 }
699 GetStdContent();
700 // when reading back we are not owner of the list
701 // must not delete it
702 fESDObjects->SetOwner(kFALSE);
703 }
704
705
706
707}
708
709
710void AliESDEvent::CopyFromOldESD()
711{
712 // Method which copies over everthing from the old esd structure to the
713 // new
714
715 if(fESDOld){
716 ResetStdContent();
717 // Run
718 SetRunNumber(fESDOld->GetRunNumber());
719 SetPeriodNumber(fESDOld->GetPeriodNumber());
720 SetMagneticField(fESDRun->GetMagneticField());
721
722 // leave out diamond ...
723 // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
724
725 // header
726 SetTriggerMask(fESDOld->GetTriggerMask());
727 SetOrbitNumber(fESDOld->GetOrbitNumber());
728 SetTimeStamp(fESDOld->GetTimeStamp());
729 SetEventType(fESDOld->GetEventType());
730 SetEventNumberInFile(fESDOld->GetEventNumberInFile());
731 SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
732 SetTriggerCluster(fESDOld->GetTriggerCluster());
733
734 // ZDC
735
736 SetZDC(fESDOld->GetZDCN1Energy(),
737 fESDOld->GetZDCP1Energy(),
738 fESDOld->GetZDCEMEnergy(),
739 fESDOld->GetZDCN2Energy(),
740 fESDOld->GetZDCP2Energy(),
741 fESDOld->GetZDCParticipants());
742
743 // FMD
744
745 SetFMDData(fESDOld->GetFMDData());
746
747 // T0
748
749 SetT0zVertex(fESDOld->GetT0zVertex());
750 SetT0(fESDOld->GetT0());
751 // leave amps out
752
753 // VZERO
c06eaba2 754 if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
af885e0f 755
756 SetVertex(fESDOld->GetVertex());
757
758 SetPrimaryVertex(fESDOld->GetPrimaryVertex());
759
760 SetMultiplicity(fESDOld->GetMultiplicity());
761
762 for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
763 AddTrack(fESDOld->GetTrack(i));
764 }
765
766 for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
767 AddMuonTrack(fESDOld->GetMuonTrack(i));
768 }
769
770 for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
771 AddPmdTrack(fESDOld->GetPmdTrack(i));
772 }
773
774 for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
775 AddTrdTrack(fESDOld->GetTrdTrack(i));
776 }
777
778 for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
779 AddV0(fESDOld->GetV0(i));
780 }
781
782 for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
783 AddCascade(fESDOld->GetCascade(i));
784 }
785
786 for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
787 AddKink(fESDOld->GetKink(i));
788 }
789
790
791 for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
792 AddCaloCluster(fESDOld->GetCaloCluster(i));
793 }
794 }// if fesdold
795}
796
797
798