]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODEvent.cxx
removed illegal delete in dtor
[u/mrichter/AliRoot.git] / STEER / AliAODEvent.cxx
CommitLineData
df9db588 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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//-------------------------------------------------------------------------
19// AOD base class
20// Author: Markus Oldenburg, CERN
21//-------------------------------------------------------------------------
22
5c1dc41f 23#include <TROOT.h>
ec4af4c1 24#include <TTree.h>
5c1dc41f 25#include <TFolder.h>
298d3d58 26#include <TFriendElement.h>
c8e4f399 27#include <TProcessID.h>
28#include <TCollection.h>
ec4af4c1 29
df9db588 30#include "AliAODEvent.h"
31#include "AliAODHeader.h"
32#include "AliAODTrack.h"
33
34ClassImp(AliAODEvent)
35
08e4c457 36// definition of std AOD member names
37 const char* AliAODEvent::fAODListName[kAODListN] = {"header",
38 "tracks",
39 "vertices",
3dd9f9e3 40 "v0s",
41 "tracklets",
08e4c457 42 "jets",
37792174 43 "emcalCells",
44 "phosCells",
3dd9f9e3 45 "caloClusters",
46 "fmdClusters",
47 "pmdClusters"
48};
df9db588 49//______________________________________________________________________________
50AliAODEvent::AliAODEvent() :
08e4c457 51 AliVEvent(),
df9db588 52 fAODObjects(new TList()),
5c1dc41f 53 fAODFolder(0),
dd389a30 54 fConnected(kFALSE),
ec4af4c1 55 fHeader(0),
56 fTracks(0),
57 fVertices(0),
3dd9f9e3 58 fV0s(0),
59 fTracklets(0),
821f8f1d 60 fJets(0),
37792174 61 fEmcalCells(0),
62 fPhosCells(0),
3dd9f9e3 63 fCaloClusters(0),
64 fFmdClusters(0),
65 fPmdClusters(0)
df9db588 66{
67 // default constructor
68}
69
5c1dc41f 70//______________________________________________________________________________
71AliAODEvent::AliAODEvent(const AliAODEvent& aod):
72 AliVEvent(aod),
73 fAODObjects(new TList()),
74 fAODFolder(new TFolder()),
dd389a30 75 fConnected(kFALSE),
5c1dc41f 76 fHeader(new AliAODHeader(*aod.fHeader)),
77 fTracks(new TClonesArray(*aod.fTracks)),
78 fVertices(new TClonesArray(*aod.fVertices)),
79 fV0s(new TClonesArray(*aod.fV0s)),
80 fTracklets(new AliAODTracklets(*aod.fTracklets)),
81 fJets(new TClonesArray(*aod.fJets)),
82 fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)),
83 fPhosCells(new AliAODCaloCells(*aod.fPhosCells)),
84 fCaloClusters(new TClonesArray(*aod.fCaloClusters)),
85 fFmdClusters(new TClonesArray(*aod.fFmdClusters)),
86 fPmdClusters(new TClonesArray(*aod.fPmdClusters))
87{
88 // Copy constructor
89 AddObject(fHeader);
90 AddObject(fTracks);
91 AddObject(fVertices);
92 AddObject(fV0s);
93 AddObject(fTracklets);
94 AddObject(fJets);
95 AddObject(fEmcalCells);
96 AddObject(fPhosCells);
97 AddObject(fCaloClusters);
98 AddObject(fFmdClusters);
99 AddObject(fPmdClusters);
dd389a30 100 fConnected = aod.fConnected;
5c1dc41f 101 GetStdContent();
102}
103
104//______________________________________________________________________________
105AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
106
107 // Assignment operator
108
109 if(&aod == this) return *this;
110 AliVEvent::operator=(aod);
111
112 fAODObjects = new TList();
113 fAODFolder = new TFolder();
dd389a30 114 fConnected = aod.fConnected;
5c1dc41f 115 fHeader = new AliAODHeader(*aod.fHeader);
116 fTracks = new TClonesArray(*aod.fTracks);
117 fVertices = new TClonesArray(*aod.fVertices);
118 fV0s = new TClonesArray(*aod.fV0s);
119 fTracklets = new AliAODTracklets(*aod.fTracklets);
120 fJets = new TClonesArray(*aod.fJets);
121 fEmcalCells = new AliAODCaloCells(*aod.fEmcalCells);
122 fPhosCells = new AliAODCaloCells(*aod.fPhosCells);
123 fCaloClusters = new TClonesArray(*aod.fCaloClusters);
124 fFmdClusters = new TClonesArray(*aod.fFmdClusters);
125 fPmdClusters = new TClonesArray(*aod.fPmdClusters);
126
127 fAODObjects = new TList();
128
129 AddObject(fHeader);
130 AddObject(fTracks);
131 AddObject(fVertices);
132 AddObject(fV0s);
133 AddObject(fTracklets);
134 AddObject(fJets);
135 AddObject(fEmcalCells);
136 AddObject(fPhosCells);
137 AddObject(fCaloClusters);
138 AddObject(fFmdClusters);
139 AddObject(fPmdClusters);
140 GetStdContent();
141 return *this;
142}
143
144
df9db588 145//______________________________________________________________________________
146AliAODEvent::~AliAODEvent()
147{
ec4af4c1 148// destructor
dd389a30 149 if(fAODObjects&&!fConnected)
150 {
151 delete fAODObjects;
152 fAODObjects = 0;
153 }
154
5c1dc41f 155 delete fAODFolder;
df9db588 156}
157
158//______________________________________________________________________________
159void AliAODEvent::AddObject(TObject* obj)
160{
4b3de353 161 // Add an object to the list of objects.
df9db588 162 // Please be aware that in order to increase performance you should
163 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
164
165 fAODObjects->AddLast(obj);
166}
167
4b3de353 168//______________________________________________________________________________
169void AliAODEvent::RemoveObject(TObject* obj)
170{
171 // Removes an object from the list of objects.
172
173 fAODObjects->Remove(obj);
174}
175
df9db588 176//______________________________________________________________________________
08e4c457 177TObject *AliAODEvent::FindListObject(const char *objName)
df9db588 178{
179 // Return the pointer to the object with the given name.
180
181 return fAODObjects->FindObject(objName);
182}
183
184//______________________________________________________________________________
185void AliAODEvent::CreateStdContent()
186{
187 // create the standard AOD content and set pointers
188
189 // create standard objects and add them to the TList of objects
190 AddObject(new AliAODHeader());
191 AddObject(new TClonesArray("AliAODTrack", 0));
192 AddObject(new TClonesArray("AliAODVertex", 0));
3dd9f9e3 193 AddObject(new TClonesArray("AliAODv0", 0));
821f8f1d 194 AddObject(new AliAODTracklets());
3dd9f9e3 195 AddObject(new TClonesArray("AliAODJet", 0));
196 AddObject(new AliAODCaloCells());
37792174 197 AddObject(new AliAODCaloCells());
3dd9f9e3 198 AddObject(new TClonesArray("AliAODCaloCluster", 0));
199 AddObject(new TClonesArray("AliAODFmdCluster", 0));
200 AddObject(new TClonesArray("AliAODPmdCluster", 0));
08e4c457 201 // set names
202 SetStdNames();
203
df9db588 204 // read back pointers
205 GetStdContent();
5c1dc41f 206 CreateStdFolders();
08e4c457 207 return;
df9db588 208}
209
c8e4f399 210void AliAODEvent::MakeEntriesReferencable()
211{
212 // Make all entries referencable in a subsequent process
213 //
214 TIter next(fAODObjects);
215 TObject* obj;
8ac4fa64 216 while ((obj = next()))
c8e4f399 217 {
218 if(obj->InheritsFrom("TCollection"))
219 {
220 AssignIDtoCollection((TCollection*)obj);
221 }
222 }
223}
224
08e4c457 225//______________________________________________________________________________
226void AliAODEvent::SetStdNames()
227{
228 // introduce the standard naming
229
230 if(fAODObjects->GetEntries()==kAODListN){
231 for(int i = 0;i < fAODObjects->GetEntries();i++){
232 TObject *fObj = fAODObjects->At(i);
233 if(fObj->InheritsFrom("TNamed")){
234 ((TNamed*)fObj)->SetName(fAODListName[i]);
235 }
236 else if(fObj->InheritsFrom("TClonesArray")){
237 ((TClonesArray*)fObj)->SetName(fAODListName[i]);
238 }
239 }
240 }
241 else{
242 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
243 }
244}
245
5c1dc41f 246void AliAODEvent::CreateStdFolders()
247{
248 // Create the standard folder structure
249 fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD");
250 if(fAODObjects->GetEntries()==kAODListN){
251 for(int i = 0;i < fAODObjects->GetEntries();i++){
252 TObject *fObj = fAODObjects->At(i);
253 if(fObj->InheritsFrom("TClonesArray")){
254 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], (TCollection*) fObj);
255 } else {
256 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], 0);
257 }
258 }
259 }
260 else{
261 printf("%s:%d CreateStdFolders() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
262 }
263}
264
df9db588 265//______________________________________________________________________________
ec4af4c1 266void AliAODEvent::GetStdContent()
df9db588 267{
268 // set pointers for standard content
269
3dd9f9e3 270 fHeader = (AliAODHeader*)fAODObjects->FindObject("header");
271 fTracks = (TClonesArray*)fAODObjects->FindObject("tracks");
272 fVertices = (TClonesArray*)fAODObjects->FindObject("vertices");
273 fV0s = (TClonesArray*)fAODObjects->FindObject("v0s");
274 fTracklets = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
275 fJets = (TClonesArray*)fAODObjects->FindObject("jets");
37792174 276 fEmcalCells = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells");
277 fPhosCells = (AliAODCaloCells*)fAODObjects->FindObject("phosCells");
3dd9f9e3 278 fCaloClusters = (TClonesArray*)fAODObjects->FindObject("caloClusters");
279 fFmdClusters = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
280 fPmdClusters = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
df9db588 281}
282
283//______________________________________________________________________________
3dd9f9e3 284void AliAODEvent::ResetStd(Int_t trkArrSize,
285 Int_t vtxArrSize,
286 Int_t v0ArrSize,
287 Int_t jetSize,
288 Int_t caloClusSize,
289 Int_t fmdClusSize,
290 Int_t pmdClusSize)
df9db588 291{
3dd9f9e3 292 // deletes content of standard arrays and resets size
df9db588 293 fTracks->Delete();
294 if (trkArrSize > fTracks->GetSize())
295 fTracks->Expand(trkArrSize);
296
297 fVertices->Delete();
298 if (vtxArrSize > fVertices->GetSize())
299 fVertices->Expand(vtxArrSize);
3dd9f9e3 300
301 fV0s->Delete();
302 if (v0ArrSize > fV0s->GetSize())
303 fV0s->Expand(v0ArrSize);
304
305 fJets->Delete();
306 if (jetSize > fJets->GetSize())
307 fJets->Expand(jetSize);
308
309 fCaloClusters->Delete();
310 if (caloClusSize > fCaloClusters->GetSize())
311 fCaloClusters->Expand(caloClusSize);
312
313 fFmdClusters->Delete();
314 if (fmdClusSize > fFmdClusters->GetSize())
315 fFmdClusters->Expand(fmdClusSize);
316
317 fPmdClusters->Delete();
318 if (pmdClusSize > fPmdClusters->GetSize())
319 fPmdClusters->Expand(pmdClusSize);
6989bff3 320
321 // Reset the tracklets
322 fTracklets->DeleteContainer();
323 fPhosCells->DeleteContainer();
324 fEmcalCells->DeleteContainer();
325
df9db588 326}
327
ec4af4c1 328void AliAODEvent::ClearStd()
329{
330 // clears the standard arrays
3dd9f9e3 331 fTracks ->Clear();
332 fVertices ->Clear();
333 fV0s ->Clear();
334 fTracklets ->DeleteContainer();
1c37410a 335 fJets ->Delete();
37792174 336 fEmcalCells ->DeleteContainer();
337 fPhosCells ->DeleteContainer();
338 fCaloClusters ->Clear();
339 fFmdClusters ->Clear();
340 fPmdClusters ->Clear();
ec4af4c1 341}
342
78902954 343//_________________________________________________________________
344Int_t AliAODEvent::GetPHOSClusters(TRefArray *clusters) const
345{
346 // fills the provided TRefArray with all found phos clusters
347
348 clusters->Clear();
349
350 AliAODCaloCluster *cl = 0;
351 for (Int_t i = 0; i < GetNCaloClusters() ; i++) {
352
353 if ( (cl = GetCaloCluster(i)) ) {
354 if (cl->IsPHOSCluster()){
355 clusters->Add(cl);
356 //AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
357 }
358 }
359 }
360 return clusters->GetEntriesFast();
361}
362
363//_________________________________________________________________
364Int_t AliAODEvent::GetEMCALClusters(TRefArray *clusters) const
365{
366 // fills the provided TRefArray with all found emcal clusters
367
368 clusters->Clear();
369
370 AliAODCaloCluster *cl = 0;
371 for (Int_t i = 0; i < GetNCaloClusters(); i++) {
372
373 if ( (cl = GetCaloCluster(i)) ) {
374 if (cl->IsEMCALCluster()){
375 clusters->Add(cl);
376 //AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
377 }
378 }
379 }
380 return clusters->GetEntriesFast();
381}
382
383
fb41236c 384//______________________________________________________________________________
385Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
386{
387 // fills the provided TRefArray with all found muon tracks
df9db588 388
fb41236c 389 muonTracks->Clear();
df9db588 390
fb41236c 391 AliAODTrack *track = 0;
392 for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
08e4c457 393 if ((track = GetTrack(iTrack))->IsMuonTrack()) {
fb41236c 394 muonTracks->Add(track);
395 }
396 }
397
3dd9f9e3 398 return muonTracks->GetEntriesFast();
fb41236c 399}
ec4af4c1 400
401
3b93c32a 402void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/)
8ff33247 403{
3b93c32a 404 // Connects aod event to tree
08e4c457 405
61cb38c7 406 if(!tree){
407 Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
408 return;
409 }
08e4c457 410 // load the TTree
61cb38c7 411 if(!tree->GetTree())tree->LoadTree(0);
412
413 // Try to find AliAODEvent
414 AliAODEvent *aodEvent = 0;
415 aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
416 if(aodEvent){
417 // Check if already connected to tree
418 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
3b93c32a 419 if (connectedList && (strcmp(opt, "reconnect"))) {
420 // If connected use the connected list if objects
421 fAODObjects->Delete();
422 fAODObjects = connectedList;
423 GetStdContent();
dd389a30 424 fConnected = kTRUE;
3b93c32a 425 return;
61cb38c7 426 }
427 // Connect to tree
428 // prevent a memory leak when reading back the TList
429 delete fAODObjects;
430 fAODObjects = 0;
431 // create a new TList from the UserInfo TList...
432 // copy constructor does not work...
433 fAODObjects = (TList*)(aodEvent->GetList()->Clone());
434 fAODObjects->SetOwner(kFALSE);
435 if(fAODObjects->GetEntries()<kAODListN){
436 printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
437 (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN);
438 }
298d3d58 439 //
440 // Let's find out whether we have friends
ced57103 441 TList* friendL = tree->GetTree()->GetListOfFriends();
298d3d58 442 if (friendL)
443 {
444 TIter next(friendL);
445 TFriendElement* fe;
446 while ((fe = (TFriendElement*)next())){
447 aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent"));
448 if (!aodEvent) {
449 printf("No UserInfo on tree \n");
450 } else {
451
452 TList* objL = (TList*)(aodEvent->GetList()->Clone());
453 printf("Get list of object from tree %d !!\n", objL->GetEntries());
454 TIter nextobject(objL);
455 TObject* obj = 0;
8ac4fa64 456 while((obj = nextobject()))
298d3d58 457 {
458 printf("Adding object from friend %s !\n", obj->GetName());
459 fAODObjects->Add(obj);
460 } // object "branch" loop
461 } // has userinfo
462 } // friend loop
463 } // has friends
464
465
466// set the branch addresses
61cb38c7 467 TIter next(fAODObjects);
468 TNamed *el;
469 while((el=(TNamed*)next())){
470 TString bname(el->GetName());
471 // check if branch exists under this Name
ced57103 472 TBranch *br = tree->GetTree()->GetBranch(bname.Data());
61cb38c7 473 if(br){
474 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
ced57103 475 } else {
298d3d58 476 br = tree->GetBranch(Form("%s.",bname.Data()));
477 if(br){
478 tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
479 }
480 else{
481 printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n",
482 (char*)__FILE__,__LINE__,bname.Data());
483 }
61cb38c7 484 }
485 }
61cb38c7 486 GetStdContent();
487 // when reading back we are not owner of the list
488 // must not delete it
489 fAODObjects->SetOwner(kFALSE);
490 fAODObjects->SetName("AODObjectsConnectedToTree");
491 // we are not owner of the list objects
492 // must not delete it
493 tree->GetUserInfo()->Add(fAODObjects);
dd389a30 494 fConnected = kTRUE;
61cb38c7 495 }// no aodEvent
496 else {
497 // we can't get the list from the user data, create standard content
498 // and set it by hand
499 CreateStdContent();
500 TIter next(fAODObjects);
501 TNamed *el;
502 while((el=(TNamed*)next())){
503 TString bname(el->GetName());
504 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
505 }
506 GetStdContent();
507 // when reading back we are not owner of the list
508 // must not delete it
509 fAODObjects->SetOwner(kFALSE);
08e4c457 510 }
8ff33247 511}
512
08e4c457 513//______________________________________________________________________________
514void AliAODEvent::Print(Option_t *) const
515{
516 // Something meaningful should be implemented here.
517
518 return;
519}
c8e4f399 520
521void AliAODEvent::AssignIDtoCollection(TCollection* col)
522{
523 // Static method which assigns a ID to each object in a collection
524 // In this way the objects are marked as referenced and written with
525 // an ID. This has the advantage that TRefs to this objects can be
526 // written by a subsequent process.
527 TIter next(col);
528 TObject* obj;
8ac4fa64 529 while ((obj = next()))
c8e4f399 530 TProcessID::AssignID(obj);
531}