]>
Commit | Line | Data |
---|---|---|
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> | |
a0df0b6a | 29 | #include "Riostream.h" |
df9db588 | 30 | #include "AliAODEvent.h" |
31 | #include "AliAODHeader.h" | |
32 | #include "AliAODTrack.h" | |
866d8d78 | 33 | #include "AliAODDimuon.h" |
df9db588 | 34 | |
35 | ClassImp(AliAODEvent) | |
36 | ||
08e4c457 | 37 | // definition of std AOD member names |
38 | const char* AliAODEvent::fAODListName[kAODListN] = {"header", | |
39 | "tracks", | |
40 | "vertices", | |
3dd9f9e3 | 41 | "v0s", |
9a244178 | 42 | "cascades", |
3dd9f9e3 | 43 | "tracklets", |
08e4c457 | 44 | "jets", |
37792174 | 45 | "emcalCells", |
46 | "phosCells", | |
3dd9f9e3 | 47 | "caloClusters", |
48 | "fmdClusters", | |
866d8d78 | 49 | "pmdClusters", |
50 | "dimuons" | |
9a244178 | 51 | |
3dd9f9e3 | 52 | }; |
df9db588 | 53 | //______________________________________________________________________________ |
54 | AliAODEvent::AliAODEvent() : | |
08e4c457 | 55 | AliVEvent(), |
df9db588 | 56 | fAODObjects(new TList()), |
5c1dc41f | 57 | fAODFolder(0), |
dd389a30 | 58 | fConnected(kFALSE), |
ec4af4c1 | 59 | fHeader(0), |
60 | fTracks(0), | |
61 | fVertices(0), | |
3dd9f9e3 | 62 | fV0s(0), |
9a244178 | 63 | fCascades(0), |
3dd9f9e3 | 64 | fTracklets(0), |
821f8f1d | 65 | fJets(0), |
37792174 | 66 | fEmcalCells(0), |
67 | fPhosCells(0), | |
3dd9f9e3 | 68 | fCaloClusters(0), |
69 | fFmdClusters(0), | |
866d8d78 | 70 | fPmdClusters(0), |
71 | fDimuons(0) | |
df9db588 | 72 | { |
73 | // default constructor | |
74 | } | |
75 | ||
5c1dc41f | 76 | //______________________________________________________________________________ |
77 | AliAODEvent::AliAODEvent(const AliAODEvent& aod): | |
78 | AliVEvent(aod), | |
79 | fAODObjects(new TList()), | |
80 | fAODFolder(new TFolder()), | |
dd389a30 | 81 | fConnected(kFALSE), |
5c1dc41f | 82 | fHeader(new AliAODHeader(*aod.fHeader)), |
83 | fTracks(new TClonesArray(*aod.fTracks)), | |
84 | fVertices(new TClonesArray(*aod.fVertices)), | |
85 | fV0s(new TClonesArray(*aod.fV0s)), | |
9a244178 | 86 | fCascades(new TClonesArray(*aod.fCascades)), |
5c1dc41f | 87 | fTracklets(new AliAODTracklets(*aod.fTracklets)), |
88 | fJets(new TClonesArray(*aod.fJets)), | |
89 | fEmcalCells(new AliAODCaloCells(*aod.fEmcalCells)), | |
90 | fPhosCells(new AliAODCaloCells(*aod.fPhosCells)), | |
91 | fCaloClusters(new TClonesArray(*aod.fCaloClusters)), | |
92 | fFmdClusters(new TClonesArray(*aod.fFmdClusters)), | |
866d8d78 | 93 | fPmdClusters(new TClonesArray(*aod.fPmdClusters)), |
94 | fDimuons(new TClonesArray(*aod.fDimuons)) | |
5c1dc41f | 95 | { |
96 | // Copy constructor | |
97 | AddObject(fHeader); | |
98 | AddObject(fTracks); | |
99 | AddObject(fVertices); | |
100 | AddObject(fV0s); | |
9a244178 | 101 | AddObject(fCascades); |
5c1dc41f | 102 | AddObject(fTracklets); |
103 | AddObject(fJets); | |
104 | AddObject(fEmcalCells); | |
105 | AddObject(fPhosCells); | |
106 | AddObject(fCaloClusters); | |
107 | AddObject(fFmdClusters); | |
108 | AddObject(fPmdClusters); | |
866d8d78 | 109 | AddObject(fDimuons); |
dd389a30 | 110 | fConnected = aod.fConnected; |
5c1dc41f | 111 | GetStdContent(); |
48f1c230 | 112 | CreateStdFolders(); |
5c1dc41f | 113 | } |
114 | ||
115 | //______________________________________________________________________________ | |
116 | AliAODEvent & AliAODEvent::operator=(const AliAODEvent& aod) { | |
117 | ||
118 | // Assignment operator | |
119 | ||
48f1c230 | 120 | if(&aod == this) return *this; |
121 | AliVEvent::operator=(aod); | |
5c1dc41f | 122 | |
48f1c230 | 123 | // This assumes that the list is already created |
124 | // and that the virtual void Copy(Tobject&) function | |
125 | // is correctly implemented in the derived class | |
126 | // otherwise only TObject::Copy() will be used | |
127 | ||
128 | if((fAODObjects->GetSize()==0)&&(aod.fAODObjects->GetSize()>=kAODListN)){ | |
129 | // We cover the case that we do not yet have the | |
130 | // standard content but the source has it | |
131 | CreateStdContent(); | |
132 | } | |
133 | ||
134 | // Here we have the standard content without user additions, but the content is | |
135 | // not matching the aod source. | |
136 | ||
137 | // Iterate the list of source objects | |
138 | TIter next(aod.GetList()); | |
139 | TObject *its = 0; | |
140 | TString name; | |
141 | while ((its = next())) { | |
142 | name = its->GetName(); | |
143 | // Check if we have this object type in out list | |
144 | TObject *mine = fAODObjects->FindObject(name); | |
145 | if(!mine) { | |
146 | // We have to create the same type of object. | |
147 | TClass* pClass=TClass::GetClass(its->ClassName()); | |
148 | if (!pClass) { | |
149 | AliWarning(Form("Can not find class description for entry %s (%s)\n", | |
150 | its->ClassName(), name.Data())); | |
151 | continue; | |
152 | } | |
153 | mine=(TObject*)pClass->New(); | |
154 | if(!mine){ | |
155 | // not in this: can be added to list | |
156 | AliWarning(Form("%s:%d Could not find %s for copying \n", | |
157 | (char*)__FILE__,__LINE__,name.Data())); | |
158 | continue; | |
159 | } | |
160 | if(mine->InheritsFrom("TNamed")) { | |
161 | ((TNamed*)mine)->SetName(name); | |
162 | } else if(mine->InheritsFrom("TCollection")){ | |
163 | if(mine->InheritsFrom("TClonesArray")) { | |
164 | TClonesArray *itscl = dynamic_cast<TClonesArray*>(its); | |
165 | if (!itscl) { | |
166 | AliWarning(Form("Class description for entry %s (%s) not TClonesArray\n", | |
167 | its->ClassName(), name.Data())); | |
168 | continue; | |
169 | ||
170 | } | |
171 | dynamic_cast<TClonesArray*>(mine)->SetClass(itscl->GetClass(), itscl->GetSize()); | |
172 | } | |
173 | dynamic_cast<TCollection*>(mine)->SetName(name); | |
174 | } | |
175 | AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName())); | |
176 | AddObject(mine); | |
177 | } | |
178 | // Now we have an object of the same type and name, but different content. | |
179 | if(!its->InheritsFrom("TCollection")){ | |
180 | // simple objects (do they have a Copy method that calls operator= ?) | |
181 | its->Copy(*mine); | |
182 | } else if (its->InheritsFrom("TClonesArray")) { | |
183 | // Create or expand the tclonesarray pointers | |
184 | // so we can directly copy to the object | |
185 | TClonesArray *its_tca = (TClonesArray*)its; | |
186 | TClonesArray *mine_tca = (TClonesArray*)mine; | |
187 | // this leaves the capacity of the TClonesArray the same | |
188 | // except for a factor of 2 increase when size > capacity | |
189 | // does not release any memory occupied by the tca | |
190 | Int_t its_entries = its_tca->GetEntriesFast(); | |
191 | mine_tca->ExpandCreate(its_entries); | |
192 | for(int i=0; i<its_entries; i++){ | |
193 | // copy | |
194 | TObject *mine_tca_obj = mine_tca->At(i); | |
195 | TObject *its_tca_obj = its_tca->At(i); | |
196 | // no need to delete first | |
197 | // pointers within the class should be handled by Copy()... | |
198 | // Can there be Empty slots? | |
199 | its_tca_obj->Copy(*mine_tca_obj); | |
200 | } | |
201 | } else { | |
202 | AliWarning(Form("%s:%d cannot copy TCollection \n", | |
203 | (char*)__FILE__,__LINE__)); | |
204 | } | |
205 | } | |
206 | fConnected = aod.fConnected; | |
207 | return *this; | |
5c1dc41f | 208 | } |
209 | ||
210 | ||
df9db588 | 211 | //______________________________________________________________________________ |
212 | AliAODEvent::~AliAODEvent() | |
213 | { | |
ec4af4c1 | 214 | // destructor |
dd389a30 | 215 | if(fAODObjects&&!fConnected) |
216 | { | |
217 | delete fAODObjects; | |
218 | fAODObjects = 0; | |
219 | } | |
220 | ||
5c1dc41f | 221 | delete fAODFolder; |
df9db588 | 222 | } |
223 | ||
224 | //______________________________________________________________________________ | |
225 | void AliAODEvent::AddObject(TObject* obj) | |
226 | { | |
4b3de353 | 227 | // Add an object to the list of objects. |
df9db588 | 228 | // Please be aware that in order to increase performance you should |
229 | // refrain from using TObjArrays (if possible). Use TClonesArrays, instead. | |
230 | ||
231 | fAODObjects->AddLast(obj); | |
232 | } | |
233 | ||
4b3de353 | 234 | //______________________________________________________________________________ |
235 | void AliAODEvent::RemoveObject(TObject* obj) | |
236 | { | |
237 | // Removes an object from the list of objects. | |
238 | ||
239 | fAODObjects->Remove(obj); | |
240 | } | |
241 | ||
df9db588 | 242 | //______________________________________________________________________________ |
08e4c457 | 243 | TObject *AliAODEvent::FindListObject(const char *objName) |
df9db588 | 244 | { |
245 | // Return the pointer to the object with the given name. | |
246 | ||
247 | return fAODObjects->FindObject(objName); | |
248 | } | |
249 | ||
250 | //______________________________________________________________________________ | |
251 | void AliAODEvent::CreateStdContent() | |
252 | { | |
253 | // create the standard AOD content and set pointers | |
254 | ||
255 | // create standard objects and add them to the TList of objects | |
256 | AddObject(new AliAODHeader()); | |
257 | AddObject(new TClonesArray("AliAODTrack", 0)); | |
258 | AddObject(new TClonesArray("AliAODVertex", 0)); | |
3dd9f9e3 | 259 | AddObject(new TClonesArray("AliAODv0", 0)); |
9a244178 | 260 | AddObject(new TClonesArray("AliAODcascade", 0)); |
821f8f1d | 261 | AddObject(new AliAODTracklets()); |
3dd9f9e3 | 262 | AddObject(new TClonesArray("AliAODJet", 0)); |
263 | AddObject(new AliAODCaloCells()); | |
37792174 | 264 | AddObject(new AliAODCaloCells()); |
3dd9f9e3 | 265 | AddObject(new TClonesArray("AliAODCaloCluster", 0)); |
266 | AddObject(new TClonesArray("AliAODFmdCluster", 0)); | |
267 | AddObject(new TClonesArray("AliAODPmdCluster", 0)); | |
866d8d78 | 268 | AddObject(new TClonesArray("AliAODDimuon", 0)); |
08e4c457 | 269 | // set names |
270 | SetStdNames(); | |
271 | ||
df9db588 | 272 | // read back pointers |
273 | GetStdContent(); | |
5c1dc41f | 274 | CreateStdFolders(); |
08e4c457 | 275 | return; |
df9db588 | 276 | } |
277 | ||
c8e4f399 | 278 | void AliAODEvent::MakeEntriesReferencable() |
279 | { | |
280 | // Make all entries referencable in a subsequent process | |
281 | // | |
282 | TIter next(fAODObjects); | |
283 | TObject* obj; | |
8ac4fa64 | 284 | while ((obj = next())) |
c8e4f399 | 285 | { |
286 | if(obj->InheritsFrom("TCollection")) | |
287 | { | |
288 | AssignIDtoCollection((TCollection*)obj); | |
289 | } | |
290 | } | |
291 | } | |
292 | ||
08e4c457 | 293 | //______________________________________________________________________________ |
294 | void AliAODEvent::SetStdNames() | |
295 | { | |
296 | // introduce the standard naming | |
297 | ||
298 | if(fAODObjects->GetEntries()==kAODListN){ | |
299 | for(int i = 0;i < fAODObjects->GetEntries();i++){ | |
300 | TObject *fObj = fAODObjects->At(i); | |
301 | if(fObj->InheritsFrom("TNamed")){ | |
302 | ((TNamed*)fObj)->SetName(fAODListName[i]); | |
303 | } | |
304 | else if(fObj->InheritsFrom("TClonesArray")){ | |
305 | ((TClonesArray*)fObj)->SetName(fAODListName[i]); | |
306 | } | |
307 | } | |
308 | } | |
309 | else{ | |
310 | printf("%s:%d SetStdNames() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__); | |
311 | } | |
312 | } | |
313 | ||
5c1dc41f | 314 | void AliAODEvent::CreateStdFolders() |
315 | { | |
316 | // Create the standard folder structure | |
317 | fAODFolder = gROOT->GetRootFolder()->AddFolder("AOD", "AOD"); | |
318 | if(fAODObjects->GetEntries()==kAODListN){ | |
319 | for(int i = 0;i < fAODObjects->GetEntries();i++){ | |
320 | TObject *fObj = fAODObjects->At(i); | |
321 | if(fObj->InheritsFrom("TClonesArray")){ | |
322 | fAODFolder->AddFolder(fAODListName[i], fAODListName[i], (TCollection*) fObj); | |
323 | } else { | |
324 | fAODFolder->AddFolder(fAODListName[i], fAODListName[i], 0); | |
325 | } | |
326 | } | |
327 | } | |
328 | else{ | |
329 | printf("%s:%d CreateStdFolders() Wrong number of Std Entries \n",(char*)__FILE__,__LINE__); | |
330 | } | |
331 | } | |
332 | ||
df9db588 | 333 | //______________________________________________________________________________ |
ec4af4c1 | 334 | void AliAODEvent::GetStdContent() |
df9db588 | 335 | { |
336 | // set pointers for standard content | |
337 | ||
3dd9f9e3 | 338 | fHeader = (AliAODHeader*)fAODObjects->FindObject("header"); |
339 | fTracks = (TClonesArray*)fAODObjects->FindObject("tracks"); | |
340 | fVertices = (TClonesArray*)fAODObjects->FindObject("vertices"); | |
341 | fV0s = (TClonesArray*)fAODObjects->FindObject("v0s"); | |
9a244178 | 342 | fCascades = (TClonesArray*)fAODObjects->FindObject("cascades"); |
3dd9f9e3 | 343 | fTracklets = (AliAODTracklets*)fAODObjects->FindObject("tracklets"); |
344 | fJets = (TClonesArray*)fAODObjects->FindObject("jets"); | |
37792174 | 345 | fEmcalCells = (AliAODCaloCells*)fAODObjects->FindObject("emcalCells"); |
346 | fPhosCells = (AliAODCaloCells*)fAODObjects->FindObject("phosCells"); | |
3dd9f9e3 | 347 | fCaloClusters = (TClonesArray*)fAODObjects->FindObject("caloClusters"); |
348 | fFmdClusters = (TClonesArray*)fAODObjects->FindObject("fmdClusters"); | |
349 | fPmdClusters = (TClonesArray*)fAODObjects->FindObject("pmdClusters"); | |
866d8d78 | 350 | fDimuons = (TClonesArray*)fAODObjects->FindObject("dimuons"); |
df9db588 | 351 | } |
352 | ||
353 | //______________________________________________________________________________ | |
3dd9f9e3 | 354 | void AliAODEvent::ResetStd(Int_t trkArrSize, |
355 | Int_t vtxArrSize, | |
9a244178 | 356 | Int_t v0ArrSize, |
357 | Int_t cascadeArrSize, | |
3dd9f9e3 | 358 | Int_t jetSize, |
359 | Int_t caloClusSize, | |
360 | Int_t fmdClusSize, | |
866d8d78 | 361 | Int_t pmdClusSize, |
362 | Int_t dimuonArrSize | |
9a244178 | 363 | ) |
df9db588 | 364 | { |
3dd9f9e3 | 365 | // deletes content of standard arrays and resets size |
9a244178 | 366 | |
df9db588 | 367 | fTracks->Delete(); |
368 | if (trkArrSize > fTracks->GetSize()) | |
369 | fTracks->Expand(trkArrSize); | |
370 | ||
371 | fVertices->Delete(); | |
372 | if (vtxArrSize > fVertices->GetSize()) | |
373 | fVertices->Expand(vtxArrSize); | |
9a244178 | 374 | |
3dd9f9e3 | 375 | fV0s->Delete(); |
376 | if (v0ArrSize > fV0s->GetSize()) | |
377 | fV0s->Expand(v0ArrSize); | |
9a244178 | 378 | |
379 | fCascades->Delete(); | |
380 | if (cascadeArrSize > fCascades->GetSize()) | |
381 | fCascades->Expand(cascadeArrSize); | |
382 | ||
3dd9f9e3 | 383 | fJets->Delete(); |
9a244178 | 384 | if (jetSize > fJets->GetSize()) |
3dd9f9e3 | 385 | fJets->Expand(jetSize); |
386 | ||
387 | fCaloClusters->Delete(); | |
388 | if (caloClusSize > fCaloClusters->GetSize()) | |
389 | fCaloClusters->Expand(caloClusSize); | |
390 | ||
391 | fFmdClusters->Delete(); | |
392 | if (fmdClusSize > fFmdClusters->GetSize()) | |
393 | fFmdClusters->Expand(fmdClusSize); | |
394 | ||
395 | fPmdClusters->Delete(); | |
396 | if (pmdClusSize > fPmdClusters->GetSize()) | |
397 | fPmdClusters->Expand(pmdClusSize); | |
866d8d78 | 398 | |
399 | fDimuons->Delete(); | |
400 | if (dimuonArrSize > fDimuons->GetSize()) | |
401 | fDimuons->Expand(dimuonArrSize); | |
6989bff3 | 402 | |
403 | // Reset the tracklets | |
404 | fTracklets->DeleteContainer(); | |
405 | fPhosCells->DeleteContainer(); | |
406 | fEmcalCells->DeleteContainer(); | |
407 | ||
df9db588 | 408 | } |
409 | ||
ec4af4c1 | 410 | void AliAODEvent::ClearStd() |
411 | { | |
412 | // clears the standard arrays | |
d8f5fda5 | 413 | fHeader ->RemoveQTheta(); |
414 | fTracks ->Delete(); | |
415 | fVertices ->Delete(); | |
416 | fV0s ->Delete(); | |
9a244178 | 417 | fCascades ->Delete(); |
3dd9f9e3 | 418 | fTracklets ->DeleteContainer(); |
1c37410a | 419 | fJets ->Delete(); |
37792174 | 420 | fEmcalCells ->DeleteContainer(); |
421 | fPhosCells ->DeleteContainer(); | |
d8f5fda5 | 422 | fCaloClusters ->Delete(); |
37792174 | 423 | fFmdClusters ->Clear(); |
424 | fPmdClusters ->Clear(); | |
866d8d78 | 425 | fDimuons ->Clear(); |
ec4af4c1 | 426 | } |
427 | ||
78902954 | 428 | //_________________________________________________________________ |
429 | Int_t AliAODEvent::GetPHOSClusters(TRefArray *clusters) const | |
430 | { | |
431 | // fills the provided TRefArray with all found phos clusters | |
432 | ||
433 | clusters->Clear(); | |
434 | ||
435 | AliAODCaloCluster *cl = 0; | |
a0df0b6a | 436 | Bool_t first = kTRUE; |
78902954 | 437 | for (Int_t i = 0; i < GetNCaloClusters() ; i++) { |
78902954 | 438 | if ( (cl = GetCaloCluster(i)) ) { |
439 | if (cl->IsPHOSCluster()){ | |
a0df0b6a | 440 | if(first) { |
441 | new (clusters) TRefArray(TProcessID::GetProcessWithUID(cl)); | |
442 | first=kFALSE; | |
443 | } | |
78902954 | 444 | clusters->Add(cl); |
a0df0b6a | 445 | //printf("IsPHOS cluster %d, E %2.3f Size: %d \n",i,cl->E(),clusters->GetEntriesFast()); |
78902954 | 446 | } |
447 | } | |
448 | } | |
449 | return clusters->GetEntriesFast(); | |
450 | } | |
451 | ||
452 | //_________________________________________________________________ | |
453 | Int_t AliAODEvent::GetEMCALClusters(TRefArray *clusters) const | |
454 | { | |
455 | // fills the provided TRefArray with all found emcal clusters | |
456 | ||
457 | clusters->Clear(); | |
78902954 | 458 | AliAODCaloCluster *cl = 0; |
a0df0b6a | 459 | Bool_t first = kTRUE; |
78902954 | 460 | for (Int_t i = 0; i < GetNCaloClusters(); i++) { |
78902954 | 461 | if ( (cl = GetCaloCluster(i)) ) { |
462 | if (cl->IsEMCALCluster()){ | |
a0df0b6a | 463 | if(first) { |
464 | new (clusters) TRefArray(TProcessID::GetProcessWithUID(cl)); | |
465 | first=kFALSE; | |
466 | } | |
78902954 | 467 | clusters->Add(cl); |
a0df0b6a | 468 | //printf("IsEMCal cluster %d, E %2.3f Size: %d \n",i,cl->E(),clusters->GetEntriesFast()); |
78902954 | 469 | } |
470 | } | |
471 | } | |
472 | return clusters->GetEntriesFast(); | |
473 | } | |
474 | ||
475 | ||
fb41236c | 476 | //______________________________________________________________________________ |
477 | Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const | |
478 | { | |
479 | // fills the provided TRefArray with all found muon tracks | |
df9db588 | 480 | |
fb41236c | 481 | muonTracks->Clear(); |
df9db588 | 482 | |
fb41236c | 483 | AliAODTrack *track = 0; |
484 | for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) { | |
08e4c457 | 485 | if ((track = GetTrack(iTrack))->IsMuonTrack()) { |
fb41236c | 486 | muonTracks->Add(track); |
487 | } | |
488 | } | |
489 | ||
3dd9f9e3 | 490 | return muonTracks->GetEntriesFast(); |
fb41236c | 491 | } |
ec4af4c1 | 492 | |
493 | ||
3b93c32a | 494 | void AliAODEvent::ReadFromTree(TTree *tree, Option_t* opt /*= ""*/) |
8ff33247 | 495 | { |
3b93c32a | 496 | // Connects aod event to tree |
08e4c457 | 497 | |
61cb38c7 | 498 | if(!tree){ |
499 | Printf("%s %d AliAODEvent::ReadFromTree() Zero Pointer to Tree \n",(char*)__FILE__,__LINE__); | |
500 | return; | |
501 | } | |
08e4c457 | 502 | // load the TTree |
61cb38c7 | 503 | if(!tree->GetTree())tree->LoadTree(0); |
504 | ||
505 | // Try to find AliAODEvent | |
506 | AliAODEvent *aodEvent = 0; | |
507 | aodEvent = (AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent"); | |
508 | if(aodEvent){ | |
509 | // Check if already connected to tree | |
510 | TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("AODObjectsConnectedToTree")); | |
3b93c32a | 511 | if (connectedList && (strcmp(opt, "reconnect"))) { |
d8f5fda5 | 512 | // If connected use the connected list of objects |
3b93c32a | 513 | fAODObjects->Delete(); |
514 | fAODObjects = connectedList; | |
515 | GetStdContent(); | |
dd389a30 | 516 | fConnected = kTRUE; |
3b93c32a | 517 | return; |
d8f5fda5 | 518 | } |
61cb38c7 | 519 | // Connect to tree |
520 | // prevent a memory leak when reading back the TList | |
383a295a | 521 | // if (!(strcmp(opt, "reconnect"))) fAODObjects->Delete(); |
316cf4cc | 522 | |
61cb38c7 | 523 | // create a new TList from the UserInfo TList... |
524 | // copy constructor does not work... | |
525 | fAODObjects = (TList*)(aodEvent->GetList()->Clone()); | |
316cf4cc | 526 | fAODObjects->SetOwner(kTRUE); |
61cb38c7 | 527 | if(fAODObjects->GetEntries()<kAODListN){ |
528 | printf("%s %d AliAODEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n", | |
529 | (char*)__FILE__,__LINE__,fAODObjects->GetEntries(),kAODListN); | |
530 | } | |
298d3d58 | 531 | // |
532 | // Let's find out whether we have friends | |
ced57103 | 533 | TList* friendL = tree->GetTree()->GetListOfFriends(); |
298d3d58 | 534 | if (friendL) |
535 | { | |
536 | TIter next(friendL); | |
537 | TFriendElement* fe; | |
538 | while ((fe = (TFriendElement*)next())){ | |
539 | aodEvent = (AliAODEvent*)(fe->GetTree()->GetUserInfo()->FindObject("AliAODEvent")); | |
540 | if (!aodEvent) { | |
541 | printf("No UserInfo on tree \n"); | |
542 | } else { | |
543 | ||
544 | TList* objL = (TList*)(aodEvent->GetList()->Clone()); | |
545 | printf("Get list of object from tree %d !!\n", objL->GetEntries()); | |
546 | TIter nextobject(objL); | |
547 | TObject* obj = 0; | |
8ac4fa64 | 548 | while((obj = nextobject())) |
298d3d58 | 549 | { |
550 | printf("Adding object from friend %s !\n", obj->GetName()); | |
551 | fAODObjects->Add(obj); | |
552 | } // object "branch" loop | |
553 | } // has userinfo | |
554 | } // friend loop | |
555 | } // has friends | |
556 | ||
557 | ||
558 | // set the branch addresses | |
61cb38c7 | 559 | TIter next(fAODObjects); |
560 | TNamed *el; | |
561 | while((el=(TNamed*)next())){ | |
562 | TString bname(el->GetName()); | |
563 | // check if branch exists under this Name | |
ced57103 | 564 | TBranch *br = tree->GetTree()->GetBranch(bname.Data()); |
61cb38c7 | 565 | if(br){ |
566 | tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el)); | |
ced57103 | 567 | } else { |
298d3d58 | 568 | br = tree->GetBranch(Form("%s.",bname.Data())); |
569 | if(br){ | |
570 | tree->SetBranchAddress(Form("%s.",bname.Data()),fAODObjects->GetObjectRef(el)); | |
571 | } | |
572 | else{ | |
573 | printf("%s %d AliAODEvent::ReadFromTree() No Branch found with Name %s. \n", | |
574 | (char*)__FILE__,__LINE__,bname.Data()); | |
575 | } | |
61cb38c7 | 576 | } |
577 | } | |
61cb38c7 | 578 | GetStdContent(); |
579 | // when reading back we are not owner of the list | |
580 | // must not delete it | |
316cf4cc | 581 | fAODObjects->SetOwner(kTRUE); |
61cb38c7 | 582 | fAODObjects->SetName("AODObjectsConnectedToTree"); |
583 | // we are not owner of the list objects | |
584 | // must not delete it | |
585 | tree->GetUserInfo()->Add(fAODObjects); | |
dd389a30 | 586 | fConnected = kTRUE; |
61cb38c7 | 587 | }// no aodEvent |
588 | else { | |
589 | // we can't get the list from the user data, create standard content | |
590 | // and set it by hand | |
591 | CreateStdContent(); | |
592 | TIter next(fAODObjects); | |
593 | TNamed *el; | |
594 | while((el=(TNamed*)next())){ | |
595 | TString bname(el->GetName()); | |
596 | tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el)); | |
597 | } | |
598 | GetStdContent(); | |
599 | // when reading back we are not owner of the list | |
600 | // must not delete it | |
316cf4cc | 601 | fAODObjects->SetOwner(kTRUE); |
08e4c457 | 602 | } |
8ff33247 | 603 | } |
604 | ||
08e4c457 | 605 | //______________________________________________________________________________ |
606 | void AliAODEvent::Print(Option_t *) const | |
607 | { | |
4922c144 | 608 | // Print the names of the all branches |
609 | TIter next(fAODObjects); | |
610 | TNamed *el; | |
611 | Printf(">>>>> AOD Content <<<<<"); | |
612 | while((el=(TNamed*)next())){ | |
613 | Printf(">> %s ",el->GetName()); | |
614 | } | |
615 | Printf(">>>>> <<<<<"); | |
08e4c457 | 616 | |
617 | return; | |
618 | } | |
c8e4f399 | 619 | |
620 | void AliAODEvent::AssignIDtoCollection(TCollection* col) | |
621 | { | |
622 | // Static method which assigns a ID to each object in a collection | |
623 | // In this way the objects are marked as referenced and written with | |
624 | // an ID. This has the advantage that TRefs to this objects can be | |
625 | // written by a subsequent process. | |
626 | TIter next(col); | |
627 | TObject* obj; | |
8ac4fa64 | 628 | while ((obj = next())) |
c8e4f399 | 629 | TProcessID::AssignID(obj); |
630 | } |