1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
20 // Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
26 #include <TFriendElement.h>
27 #include <TProcessID.h>
28 #include <TCollection.h>
30 #include "AliAODEvent.h"
31 #include "AliAODHeader.h"
32 #include "AliAODTrack.h"
36 // definition of std AOD member names
37 const char* AliAODEvent::fAODListName[kAODListN] = {"header",
49 //______________________________________________________________________________
50 AliAODEvent::AliAODEvent() :
52 fAODObjects(new TList()),
66 // default constructor
69 //______________________________________________________________________________
70 AliAODEvent::AliAODEvent(const AliAODEvent& aod):
72 fAODObjects(new TList()),
73 fAODFolder(new TFolder()),
74 fHeader(new AliAODHeader(*aod.fHeader)),
75 fTracks(new TClonesArray(*aod.fTracks)),
76 fVertices(new TClonesArray(*aod.fVertices)),
77 fV0s(new TClonesArray(*aod.fV0s)),
78 fTracklets(new AliAODTracklets(*aod.fTracklets)),
79 fJets(new TClonesArray(*aod.fJets)),
80 fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)),
81 fPhosCells(new AliAODCaloCells(*aod.fPhosCells)),
82 fCaloClusters(new TClonesArray(*aod.fCaloClusters)),
83 fFmdClusters(new TClonesArray(*aod.fFmdClusters)),
84 fPmdClusters(new TClonesArray(*aod.fPmdClusters))
91 AddObject(fTracklets);
93 AddObject(fEmcalCells);
94 AddObject(fPhosCells);
95 AddObject(fCaloClusters);
96 AddObject(fFmdClusters);
97 AddObject(fPmdClusters);
102 //______________________________________________________________________________
103 AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) {
105 // Assignment operator
107 if(&aod == this) return *this;
108 AliVEvent::operator=(aod);
110 fAODObjects = new TList();
111 fAODFolder = new TFolder();
112 fHeader = new AliAODHeader(*aod.fHeader);
113 fTracks = new TClonesArray(*aod.fTracks);
114 fVertices = new TClonesArray(*aod.fVertices);
115 fV0s = new TClonesArray(*aod.fV0s);
116 fTracklets = new AliAODTracklets(*aod.fTracklets);
117 fJets = new TClonesArray(*aod.fJets);
118 fEmcalCells = new AliAODCaloCells(*aod.fEmcalCells);
119 fPhosCells = new AliAODCaloCells(*aod.fPhosCells);
120 fCaloClusters = new TClonesArray(*aod.fCaloClusters);
121 fFmdClusters = new TClonesArray(*aod.fFmdClusters);
122 fPmdClusters = new TClonesArray(*aod.fPmdClusters);
124 fAODObjects = new TList();
128 AddObject(fVertices);
130 AddObject(fTracklets);
132 AddObject(fEmcalCells);
133 AddObject(fPhosCells);
134 AddObject(fCaloClusters);
135 AddObject(fFmdClusters);
136 AddObject(fPmdClusters);
142 //______________________________________________________________________________
143 AliAODEvent::~AliAODEvent()
150 //______________________________________________________________________________
151 void AliAODEvent::AddObject(TObject* obj)
153 // Add an object to the list of objects.
154 // Please be aware that in order to increase performance you should
155 // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
157 fAODObjects->AddLast(obj);
160 //______________________________________________________________________________
161 void AliAODEvent::RemoveObject(TObject* obj)
163 // Removes an object from the list of objects.
165 fAODObjects->Remove(obj);
168 //______________________________________________________________________________
169 TObject *AliAODEvent::FindListObject(const char *objName)
171 // Return the pointer to the object with the given name.
173 return fAODObjects->FindObject(objName);
176 //______________________________________________________________________________
177 void AliAODEvent::CreateStdContent()
179 // create the standard AOD content and set pointers
181 // create standard objects and add them to the TList of objects
182 AddObject(new AliAODHeader());
183 AddObject(new TClonesArray("AliAODTrack", 0));
184 AddObject(new TClonesArray("AliAODVertex", 0));
185 AddObject(new TClonesArray("AliAODv0", 0));
186 AddObject(new AliAODTracklets());
187 AddObject(new TClonesArray("AliAODJet", 0));
188 AddObject(new AliAODCaloCells());
189 AddObject(new AliAODCaloCells());
190 AddObject(new TClonesArray("AliAODCaloCluster", 0));
191 AddObject(new TClonesArray("AliAODFmdCluster", 0));
192 AddObject(new TClonesArray("AliAODPmdCluster", 0));
196 // read back pointers
202 void AliAODEvent::MakeEntriesReferencable()
204 // Make all entries referencable in a subsequent process
206 TIter next(fAODObjects);
210 if(obj->InheritsFrom("TCollection"))
212 AssignIDtoCollection((TCollection*)obj);
217 //______________________________________________________________________________
218 void AliAODEvent::SetStdNames()
220 // introduce the standard naming
222 if(fAODObjects->GetEntries()==kAODListN){
223 for(int i = 0;i < fAODObjects->GetEntries();i++){
224 TObject *fObj = fAODObjects->At(i);
225 if(fObj->InheritsFrom("TNamed")){
226 ((TNamed*)fObj)->SetName(fAODListName[i]);
228 else if(fObj->InheritsFrom("TClonesArray")){
229 ((TClonesArray*)fObj)->SetName(fAODListName[i]);
234 printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
238 void AliAODEvent::CreateStdFolders()
240 // Create the standard folder structure
241 fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD");
242 if(fAODObjects->GetEntries()==kAODListN){
243 for(int i = 0;i < fAODObjects->GetEntries();i++){
244 TObject *fObj = fAODObjects->At(i);
245 if(fObj->InheritsFrom("TClonesArray")){
246 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], (TCollection*) fObj);
248 fAODFolder->AddFolder(fAODListName[i], fAODListName[i], 0);
253 printf("%s:%d CreateStdFolders() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
257 //______________________________________________________________________________
258 void AliAODEvent::GetStdContent()
260 // set pointers for standard content
262 fHeader = (AliAODHeader*)fAODObjects->FindObject("header");
263 fTracks = (TClonesArray*)fAODObjects->FindObject("tracks");
264 fVertices = (TClonesArray*)fAODObjects->FindObject("vertices");
265 fV0s = (TClonesArray*)fAODObjects->FindObject("v0s");
266 fTracklets = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
267 fJets = (TClonesArray*)fAODObjects->FindObject("jets");
268 fEmcalCells = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells");
269 fPhosCells = (AliAODCaloCells*)fAODObjects->FindObject("phosCells");
270 fCaloClusters = (TClonesArray*)fAODObjects->FindObject("caloClusters");
271 fFmdClusters = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
272 fPmdClusters = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
275 //______________________________________________________________________________
276 void AliAODEvent::ResetStd(Int_t trkArrSize,
284 // deletes content of standard arrays and resets size
286 if (trkArrSize > fTracks->GetSize())
287 fTracks->Expand(trkArrSize);
290 if (vtxArrSize > fVertices->GetSize())
291 fVertices->Expand(vtxArrSize);
294 if (v0ArrSize > fV0s->GetSize())
295 fV0s->Expand(v0ArrSize);
298 if (jetSize > fJets->GetSize())
299 fJets->Expand(jetSize);
301 fCaloClusters->Delete();
302 if (caloClusSize > fCaloClusters->GetSize())
303 fCaloClusters->Expand(caloClusSize);
305 fFmdClusters->Delete();
306 if (fmdClusSize > fFmdClusters->GetSize())
307 fFmdClusters->Expand(fmdClusSize);
309 fPmdClusters->Delete();
310 if (pmdClusSize > fPmdClusters->GetSize())
311 fPmdClusters->Expand(pmdClusSize);
313 // Reset the tracklets
314 fTracklets->DeleteContainer();
315 fPhosCells->DeleteContainer();
316 fEmcalCells->DeleteContainer();
320 void AliAODEvent::ClearStd()
322 // clears the standard arrays
326 fTracklets ->DeleteContainer();
328 fEmcalCells ->DeleteContainer();
329 fPhosCells ->DeleteContainer();
330 fCaloClusters ->Clear();
331 fFmdClusters ->Clear();
332 fPmdClusters ->Clear();
335 //______________________________________________________________________________
336 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
338 // fills the provided TRefArray with all found muon tracks
342 AliAODTrack *track = 0;
343 for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
344 if ((track = GetTrack(iTrack))->IsMuonTrack()) {
345 muonTracks->Add(track);
349 return muonTracks->GetEntriesFast();
353 void AliAODEvent::ReadFromTree(TTree *tree)
355 // connects aod event to tree
358 Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
362 if(!tree->GetTree())tree->LoadTree(0);
364 // Try to find AliAODEvent
365 AliAODEvent *aodEvent = 0;
366 aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
368 // Check if already connected to tree
369 TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
371 // If connected use the connected list if objects
372 fAODObjects->Delete();
373 fAODObjects = connectedList;
378 // prevent a memory leak when reading back the TList
381 // create a new TList from the UserInfo TList...
382 // copy constructor does not work...
383 fAODObjects = (TList*)(aodEvent->GetList()->Clone());
384 fAODObjects->SetOwner(kFALSE);
385 if(fAODObjects->GetEntries()<kAODListN){
386 printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
387 (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN);
390 // Let's find out whether we have friends
391 TList* friendL = tree->GetTree()->GetListOfFriends();
396 while ((fe = (TFriendElement*)next())){
397 aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent"));
399 printf("No UserInfo on tree \n");
402 TList* objL = (TList*)(aodEvent->GetList()->Clone());
403 printf("Get list of object from tree %d !!\n", objL->GetEntries());
404 TIter nextobject(objL);
406 while(obj = nextobject())
408 printf("Adding object from friend %s !\n", obj->GetName());
409 fAODObjects->Add(obj);
410 } // object "branch" loop
416 // set the branch addresses
417 TIter next(fAODObjects);
419 while((el=(TNamed*)next())){
420 TString bname(el->GetName());
421 // check if branch exists under this Name
422 printf("Trying to connect branch %s\n", bname.Data());
423 TBranch *br = tree->GetTree()->GetBranch(bname.Data());
425 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
427 br = tree->GetBranch(Form("%s.",bname.Data()));
429 tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
432 printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n",
433 (char*)__FILE__,__LINE__,bname.Data());
438 // when reading back we are not owner of the list
439 // must not delete it
440 fAODObjects->SetOwner(kFALSE);
441 fAODObjects->SetName("AODObjectsConnectedToTree");
442 // we are not owner of the list objects
443 // must not delete it
444 tree->GetUserInfo()->Add(fAODObjects);
447 // we can't get the list from the user data, create standard content
448 // and set it by hand
450 TIter next(fAODObjects);
452 while((el=(TNamed*)next())){
453 TString bname(el->GetName());
454 tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
457 // when reading back we are not owner of the list
458 // must not delete it
459 fAODObjects->SetOwner(kFALSE);
463 //______________________________________________________________________________
464 void AliAODEvent::Print(Option_t *) const
466 // Something meaningful should be implemented here.
471 void AliAODEvent::AssignIDtoCollection(TCollection* col)
473 // Static method which assigns a ID to each object in a collection
474 // In this way the objects are marked as referenced and written with
475 // an ID. This has the advantage that TRefs to this objects can be
476 // written by a subsequent process.
480 TProcessID::AssignID(obj);