]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODEvent.cxx
Enable to read chained AOD events/files.
[u/mrichter/AliRoot.git] / STEER / AliAODEvent.cxx
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
23 #include <TTree.h>
24
25 #include "AliAODEvent.h"
26 #include "AliAODHeader.h"
27 #include "AliAODTrack.h"
28
29 ClassImp(AliAODEvent)
30
31 // definition of std AOD member names
32   const char* AliAODEvent::fAODListName[kAODListN] = {"header",
33                                                       "tracks",
34                                                       "vertices",
35                                                       "v0s",
36                                                       "tracklets",
37                                                       "jets",
38                                                       "emcalCells",
39                                                       "phosCells",
40                                                       "caloClusters",
41                                                       "fmdClusters",
42                                                       "pmdClusters"
43 };
44 //______________________________________________________________________________
45 AliAODEvent::AliAODEvent() :
46   AliVEvent(),
47   fAODObjects(new TList()),
48   fHeader(0),
49   fTracks(0),
50   fVertices(0),
51   fV0s(0),
52   fTracklets(0),
53   fJets(0),
54   fEmcalCells(0),
55   fPhosCells(0),
56   fCaloClusters(0),
57   fFmdClusters(0),
58   fPmdClusters(0)
59 {
60   // default constructor
61 }
62
63 //______________________________________________________________________________
64 AliAODEvent::~AliAODEvent() 
65 {
66 // destructor
67     delete fAODObjects;
68 }
69
70 //______________________________________________________________________________
71 void AliAODEvent::AddObject(TObject* obj) 
72 {
73   // Add an object to the list of objects.
74   // Please be aware that in order to increase performance you should
75   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
76   
77   fAODObjects->AddLast(obj);
78 }
79
80 //______________________________________________________________________________
81 void AliAODEvent::RemoveObject(TObject* obj) 
82 {
83   // Removes an object from the list of objects.
84   
85   fAODObjects->Remove(obj);
86 }
87
88 //______________________________________________________________________________
89 TObject *AliAODEvent::FindListObject(const char *objName)
90 {
91   // Return the pointer to the object with the given name.
92
93   return fAODObjects->FindObject(objName);
94 }
95
96 //______________________________________________________________________________
97 void AliAODEvent::CreateStdContent() 
98 {
99   // create the standard AOD content and set pointers
100
101   // create standard objects and add them to the TList of objects
102   AddObject(new AliAODHeader());
103   AddObject(new TClonesArray("AliAODTrack", 0));
104   AddObject(new TClonesArray("AliAODVertex", 0));
105   AddObject(new TClonesArray("AliAODv0", 0));
106   AddObject(new AliAODTracklets());
107   AddObject(new TClonesArray("AliAODJet", 0));
108   AddObject(new AliAODCaloCells());
109   AddObject(new AliAODCaloCells());
110   AddObject(new TClonesArray("AliAODCaloCluster", 0));
111   AddObject(new TClonesArray("AliAODFmdCluster", 0));
112   AddObject(new TClonesArray("AliAODPmdCluster", 0));
113   // set names
114   SetStdNames();
115
116   // read back pointers
117   GetStdContent();
118
119   return;
120 }
121
122 //______________________________________________________________________________
123 void AliAODEvent::SetStdNames()
124 {
125   // introduce the standard naming
126
127   if(fAODObjects->GetEntries()==kAODListN){
128     for(int i = 0;i < fAODObjects->GetEntries();i++){
129       TObject *fObj = fAODObjects->At(i);
130       if(fObj->InheritsFrom("TNamed")){
131         ((TNamed*)fObj)->SetName(fAODListName[i]);
132       }
133       else if(fObj->InheritsFrom("TClonesArray")){
134         ((TClonesArray*)fObj)->SetName(fAODListName[i]);
135       }
136     }
137   }
138   else{
139     printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__);
140   }
141
142
143 //______________________________________________________________________________
144 void AliAODEvent::GetStdContent()
145 {
146   // set pointers for standard content
147
148   fHeader        = (AliAODHeader*)fAODObjects->FindObject("header");
149   fTracks        = (TClonesArray*)fAODObjects->FindObject("tracks");
150   fVertices      = (TClonesArray*)fAODObjects->FindObject("vertices");
151   fV0s           = (TClonesArray*)fAODObjects->FindObject("v0s");
152   fTracklets     = (AliAODTracklets*)fAODObjects->FindObject("tracklets");
153   fJets          = (TClonesArray*)fAODObjects->FindObject("jets");
154   fEmcalCells    = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells");
155   fPhosCells     = (AliAODCaloCells*)fAODObjects->FindObject("phosCells");
156   fCaloClusters  = (TClonesArray*)fAODObjects->FindObject("caloClusters");
157   fFmdClusters   = (TClonesArray*)fAODObjects->FindObject("fmdClusters");
158   fPmdClusters   = (TClonesArray*)fAODObjects->FindObject("pmdClusters");
159 }
160
161 //______________________________________________________________________________
162 void AliAODEvent::ResetStd(Int_t trkArrSize, 
163                            Int_t vtxArrSize, 
164                            Int_t v0ArrSize, 
165                            Int_t jetSize, 
166                            Int_t caloClusSize, 
167                            Int_t fmdClusSize, 
168                            Int_t pmdClusSize)
169 {
170   // deletes content of standard arrays and resets size 
171
172   fTracks->Delete();
173   if (trkArrSize > fTracks->GetSize()) 
174     fTracks->Expand(trkArrSize);
175
176   fVertices->Delete();
177   if (vtxArrSize > fVertices->GetSize()) 
178     fVertices->Expand(vtxArrSize);
179  
180   fV0s->Delete();
181   if (v0ArrSize > fV0s->GetSize()) 
182     fV0s->Expand(v0ArrSize);
183
184   fJets->Delete();
185   if (jetSize > fJets->GetSize()) 
186     fJets->Expand(jetSize);
187
188   fCaloClusters->Delete();
189   if (caloClusSize > fCaloClusters->GetSize()) 
190     fCaloClusters->Expand(caloClusSize);
191
192   fFmdClusters->Delete();
193   if (fmdClusSize > fFmdClusters->GetSize()) 
194     fFmdClusters->Expand(fmdClusSize);
195
196   fPmdClusters->Delete();
197   if (pmdClusSize > fPmdClusters->GetSize()) 
198     fPmdClusters->Expand(pmdClusSize);
199
200   // Reset the tracklets
201   fTracklets->DeleteContainer();
202   fPhosCells->DeleteContainer();  
203   fEmcalCells->DeleteContainer();
204
205 }
206
207 void AliAODEvent::ClearStd()
208 {
209   // clears the standard arrays
210   fTracks        ->Clear();
211   fVertices      ->Clear();
212   fV0s           ->Clear();
213   fTracklets     ->DeleteContainer();
214   fJets          ->Delete();
215   fEmcalCells    ->DeleteContainer();
216   fPhosCells     ->DeleteContainer();
217   fCaloClusters  ->Clear();
218   fFmdClusters   ->Clear();
219   fPmdClusters   ->Clear();
220 }
221
222 //______________________________________________________________________________
223 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
224 {
225   // fills the provided TRefArray with all found muon tracks
226
227   muonTracks->Clear();
228
229   AliAODTrack *track = 0;
230   for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
231     if ((track = GetTrack(iTrack))->IsMuonTrack()) {
232       muonTracks->Add(track);
233     }
234   }
235   
236   return muonTracks->GetEntriesFast();
237 }
238
239
240 void AliAODEvent::ReadFromTree(TTree *tree)
241 {
242   // connects aod event to tree
243   
244   if(!tree){
245     Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__);
246     return;
247   }
248   // load the TTree
249   if(!tree->GetTree())tree->LoadTree(0);
250
251   // Try to find AliAODEvent
252   AliAODEvent *aodEvent = 0;
253   aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent");
254   if(aodEvent){
255     // Check if already connected to tree
256     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
257     if (connectedList) {
258       // If connected use the connected list if objects
259       fAODObjects->Delete();
260       fAODObjects = connectedList;
261       GetStdContent(); 
262       return;
263     }
264     // Connect to tree
265     // prevent a memory leak when reading back the TList
266     delete fAODObjects;
267     fAODObjects = 0;
268     // create a new TList from the UserInfo TList... 
269     // copy constructor does not work...
270     fAODObjects = (TList*)(aodEvent->GetList()->Clone());
271     fAODObjects->SetOwner(kFALSE);
272     if(fAODObjects->GetEntries()<kAODListN){
273       printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
274              (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN);
275     }
276     // set the branch addresses
277     TIter next(fAODObjects);
278     TNamed *el;
279     while((el=(TNamed*)next())){
280       TString bname(el->GetName());
281       // check if branch exists under this Name
282       TBranch *br = tree->GetBranch(bname.Data());
283       if(br){
284         tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
285       }
286       else{
287         br = tree->GetBranch(Form("%s.",bname.Data()));
288         if(br){
289           tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el));
290         }
291         else{
292           printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s or %s. \n",
293                  (char*)__FILE__,__LINE__,bname.Data(),bname.Data());
294         }       
295       }
296     }
297     
298     GetStdContent();
299     // when reading back we are not owner of the list 
300     // must not delete it
301     fAODObjects->SetOwner(kFALSE);
302     fAODObjects->SetName("AODObjectsConnectedToTree");
303     // we are not owner of the list objects 
304     // must not delete it
305     tree->GetUserInfo()->Add(fAODObjects);
306   }// no aodEvent
307   else {
308     // we can't get the list from the user data, create standard content
309     // and set it by hand
310     CreateStdContent();
311     TIter next(fAODObjects);
312     TNamed *el;
313     while((el=(TNamed*)next())){
314       TString bname(el->GetName());    
315       tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
316     }
317     GetStdContent();
318     // when reading back we are not owner of the list 
319     // must not delete it
320     fAODObjects->SetOwner(kFALSE);
321   }
322 }
323
324 //______________________________________________________________________________
325 void AliAODEvent::Print(Option_t *) const
326 {
327   // Something meaningful should be implemented here.
328   
329   return;
330 }