]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAODHandler.cxx
Number of findable cluster needed in AODTrack
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
CommitLineData
3fbf06a3 1
ec4af4c1 2/**************************************************************************
3 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17/* $Id$ */
18
19//-------------------------------------------------------------------------
20// Implementation of the Virtual Event Handler Interface for AOD
21// Author: Andreas Morsch, CERN
22//-------------------------------------------------------------------------
23
052994fb 24
ec4af4c1 25#include <TTree.h>
e910dd36 26#include <TFile.h>
7970f4ac 27#include <TString.h>
dce1b636 28#include <TList.h>
160959a9 29#include <TROOT.h>
e910dd36 30
da97a08a 31#include "AliLog.h"
ec4af4c1 32#include "AliAODHandler.h"
33#include "AliAODEvent.h"
da97a08a 34#include "AliAODTracklets.h"
35#include "AliStack.h"
36#include "AliAODMCParticle.h"
dce1b636 37#include "AliAODMCHeader.h"
da97a08a 38#include "AliMCEventHandler.h"
39#include "AliMCEvent.h"
dce1b636 40#include "AliGenEventHeader.h"
41#include "AliGenHijingEventHeader.h"
42#include "AliGenDPMjetEventHeader.h"
43#include "AliGenPythiaEventHeader.h"
44#include "AliGenCocktailEventHeader.h"
26ba01d4 45#include "AliCodeTimer.h"
46#include "AliAODBranchReplicator.h"
47#include "Riostream.h"
ec4af4c1 48
49ClassImp(AliAODHandler)
50
51//______________________________________________________________________________
52AliAODHandler::AliAODHandler() :
f3214a54 53 AliVEventHandler(),
78f7f935 54 fIsStandard(kTRUE),
da97a08a 55 fFillAOD(kTRUE),
41b01ae4 56 fFillAODRun(kTRUE),
ca2834f6 57 fFillExtension(kTRUE),
7c3a9fbf 58 fNeedsHeaderReplication(kFALSE),
75754ba8 59 fNeedsTracksBranchReplication(kFALSE),
60 fNeedsVerticesBranchReplication(kFALSE),
61 fNeedsV0sBranchReplication(kFALSE),
e0107012 62 fNeedsCascadesBranchReplication(kFALSE),
75754ba8 63 fNeedsTrackletsBranchReplication(kFALSE),
64 fNeedsPMDClustersBranchReplication(kFALSE),
65 fNeedsJetsBranchReplication(kFALSE),
66 fNeedsFMDClustersBranchReplication(kFALSE),
67 fNeedsCaloClustersBranchReplication(kFALSE),
3549c522 68 fNeedsMCParticlesBranchReplication(kFALSE),
866d8d78 69 fNeedsDimuonsBranchReplication(kFALSE),
75754ba8 70 fAODIsReplicated(kFALSE),
ec4af4c1 71 fAODEvent(NULL),
da97a08a 72 fMCEventH(NULL),
e910dd36 73 fTreeA(NULL),
74 fFileA(NULL),
9066c676 75 fFileName(""),
582cfeb5 76 fExtensions(NULL),
77 fFilters(NULL)
ec4af4c1 78{
79 // default constructor
80}
81
82//______________________________________________________________________________
83AliAODHandler::AliAODHandler(const char* name, const char* title):
f3214a54 84 AliVEventHandler(name, title),
78f7f935 85 fIsStandard(kTRUE),
da97a08a 86 fFillAOD(kTRUE),
41b01ae4 87 fFillAODRun(kTRUE),
ca2834f6 88 fFillExtension(kTRUE),
7c3a9fbf 89 fNeedsHeaderReplication(kFALSE),
75754ba8 90 fNeedsTracksBranchReplication(kFALSE),
91 fNeedsVerticesBranchReplication(kFALSE),
92 fNeedsV0sBranchReplication(kFALSE),
e0107012 93 fNeedsCascadesBranchReplication(kFALSE),
75754ba8 94 fNeedsTrackletsBranchReplication(kFALSE),
95 fNeedsPMDClustersBranchReplication(kFALSE),
96 fNeedsJetsBranchReplication(kFALSE),
97 fNeedsFMDClustersBranchReplication(kFALSE),
98 fNeedsCaloClustersBranchReplication(kFALSE),
3549c522 99 fNeedsMCParticlesBranchReplication(kFALSE),
866d8d78 100 fNeedsDimuonsBranchReplication(kFALSE),
75754ba8 101 fAODIsReplicated(kFALSE),
ec4af4c1 102 fAODEvent(NULL),
da97a08a 103 fMCEventH(NULL),
e910dd36 104 fTreeA(NULL),
105 fFileA(NULL),
9066c676 106 fFileName(""),
582cfeb5 107 fExtensions(NULL),
108 fFilters(NULL)
ec4af4c1 109{
582cfeb5 110// Normal constructor.
ec4af4c1 111}
112
113//______________________________________________________________________________
114AliAODHandler::~AliAODHandler()
115{
9066c676 116 // Destructor.
14d6fad5 117
118 delete fAODEvent;
119
120 if (fFileA)
121 {
6989bff3 122 // is already handled in TerminateIO
123 fFileA->Close();
124 delete fFileA;
48f1c230 125 fTreeA = 0;
6989bff3 126 }
14d6fad5 127 delete fTreeA;
128 delete fExtensions;
129 delete fFilters;
ec4af4c1 130}
131
7970f4ac 132//______________________________________________________________________________
300d5701 133Bool_t AliAODHandler::Init(Option_t* opt)
ec4af4c1 134{
6989bff3 135 // Initialize IO
136 //
137 // Create the AODevent object
e0107012 138
4e6d5854 139 Bool_t createStdAOD = fIsStandard || fFillAOD;
aa399a26 140 if(!fAODEvent && createStdAOD){
ec4af4c1 141 fAODEvent = new AliAODEvent();
c8fe2783 142 if (fIsStandard)
143 fAODEvent->CreateStdContent();
6989bff3 144 }
145 //
146 // File opening according to execution mode
7970f4ac 147 TString option(opt);
148 option.ToLower();
aa399a26 149 if (createStdAOD) {
150 TDirectory *owd = gDirectory;
151 if (option.Contains("proof")) {
152 // proof
153 // Merging via files. Need to access analysis manager via interpreter.
154 gROOT->ProcessLine(Form("AliAnalysisDataContainer *c_common_out = AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer();"));
155 gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(c_common_out, \"RECREATE\");"));
156 fFileA = gFile;
157 } else {
158 // local and grid
159 fFileA = new TFile(fFileName.Data(), "RECREATE");
160 }
161 CreateTree(1);
162 owd->cd();
163 }
9066c676 164 if (fExtensions) {
165 TIter next(fExtensions);
166 AliAODExtension *ext;
167 while ((ext=(AliAODExtension*)next())) ext->Init(option);
168 }
582cfeb5 169 if (fFilters) {
170 TIter nextf(fFilters);
171 AliAODExtension *filteredAOD;
172 while ((filteredAOD=(AliAODExtension*)nextf())) {
173 filteredAOD->SetEvent(fAODEvent);
174 filteredAOD->Init(option);
14d6fad5 175 }
582cfeb5 176 }
14d6fad5 177
6989bff3 178 return kTRUE;
ec4af4c1 179}
180
26ba01d4 181//______________________________________________________________________________
182void AliAODHandler::Print(Option_t* opt) const
183{
184 // Print info about this object
185
186 cout << opt << Form("IsStandard %d filename=%s",fIsStandard,fFileName.Data()) << endl;
187
188 if ( fExtensions )
189 {
190 cout << opt << fExtensions->GetEntries() << " extensions :" << endl;
b5b9155e 191 PrintExtensions(*fExtensions);
26ba01d4 192 }
193 if ( fFilters )
194 {
195 cout << opt << fFilters->GetEntries() << " filters :" << endl;
b5b9155e 196 PrintExtensions(*fFilters);
26ba01d4 197 }
198}
199
200//______________________________________________________________________________
b5b9155e 201void AliAODHandler::PrintExtensions(const TObjArray& array) const
26ba01d4 202{
203 // Show the list of aod extensions
204 TIter next(&array);
205 AliAODExtension* ext(0x0);
206 while ( ( ext = static_cast<AliAODExtension*>(next()) ) )
207 {
208 ext->Print(" ");
209 }
210}
211
9066c676 212//______________________________________________________________________________
da97a08a 213void AliAODHandler::StoreMCParticles(){
dce1b636 214
da97a08a 215 //
216 // Remap the labels from ESD stack and store
217 // the AODMCParticles, makes only sense if we have
218 // the mcparticles branch
219 // has to be done here since we cannot know in advance
220 // which particles are needed (e.g. by the tracks etc.)
221 //
222 // Particles have been selected by AliMCEventhanlder->SelectParticle()
223 // To use the MCEventhandler here we need to set it from the outside
224 // can vanish when Handler go to the ANALYSISalice library
dce1b636 225 //
226 // The Branch booking for mcParticles and mcHeader has to happen
227 // in an external task for now since the AODHandler does not have access
228 // the AnalysisManager. For the same reason the pointer t o the MCEventH
229 // has to passed to the AOD Handler by this task
230 // (doing this in the steering macro would not work on PROOF)
da97a08a 231
aa399a26 232 if (!fAODEvent) return;
da97a08a 233 TClonesArray *mcarray = (TClonesArray*)fAODEvent->FindListObject(AliAODMCParticle::StdBranchName());
234 if(!mcarray)return;
da97a08a 235
dce1b636 236 AliAODMCHeader *mcHeader = (AliAODMCHeader*)fAODEvent->FindListObject(AliAODMCHeader::StdBranchName());
237 if(!mcHeader)return;
238
da97a08a 239 // Get the MC Infos.. Handler needs to be set before
240 // while adding the branch
241 // This needs to be done, not to depend on the AnalysisManager
242
243 if(!fMCEventH)return;
244 if(!fMCEventH->MCEvent())return;
245 AliStack *pStack = fMCEventH->MCEvent()->Stack();
246 if(!pStack)return;
247
248 fMCEventH->CreateLabelMap();
249
dce1b636 250 //
251 // Get the Event Header
252 //
253
254 AliHeader* header = fMCEventH->MCEvent()->Header();
9efd8e10 255 // get the MC vertex
256 AliGenEventHeader* genHeader = 0;
257 if (header) genHeader = header->GenEventHeader();
258 if (genHeader) {
259 TArrayF vtxMC(3);
260 genHeader->PrimaryVertex(vtxMC);
261 mcHeader->SetVertex(vtxMC[0],vtxMC[1],vtxMC[2]);
262
263 // we search the MCEventHeaders first
264 // Two cases, cocktail or not...
265 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(genHeader);
266 if(genCocktailHeader){
267 // we have a coktail header
268 mcHeader->AddGeneratorName(genHeader->GetName());
269 // Loop from the back so that the first one sets the process type
270 TList* headerList = genCocktailHeader->GetHeaders();
271 for(int i = headerList->GetEntries()-1;i>=0;--i){
272 AliGenEventHeader *headerEntry = dynamic_cast<AliGenEventHeader*>(headerList->At(i));
273 SetMCHeaderInfo(mcHeader,headerEntry);
274 }
275 }
276 else{
277 // No Cocktail just take the first one
278 SetMCHeaderInfo(mcHeader,genHeader);
279 }
dce1b636 280 }
9efd8e10 281
dce1b636 282
283
284
285
286 // Store the AliAODParticlesMC
93836e1b 287 AliMCEvent* mcEvent = fMCEventH->MCEvent();
288
289 Int_t np = mcEvent->GetNumberOfTracks();
290 Int_t nprim = mcEvent->GetNumberOfPrimaries();
da97a08a 291
292
293 Int_t j = 0;
294 TClonesArray& l = *mcarray;
295
93836e1b 296 for(int i = 0; i < np; ++i){
297 if(fMCEventH->IsParticleSelected(i)){
298 Int_t flag = 0;
6cd07d0a 299 AliMCParticle* mcpart = (AliMCParticle*) mcEvent->GetTrack(i);
93836e1b 300 if(i<nprim)flag |= AliAODMCParticle::kPrimary;
301
302 if(mcEvent->IsPhysicalPrimary(i))flag |= AliAODMCParticle::kPhysicalPrim;
303
304 if(fMCEventH->GetNewLabel(i)!=j){
305 AliError(Form("MISMATCH New label %d j: %d",fMCEventH->GetNewLabel(i),j));
da97a08a 306 }
da97a08a 307
93836e1b 308 AliAODMCParticle mcpart_tmp(mcpart,i,flag);
309
6326aeae 310 mcpart_tmp.SetStatus(mcpart->Particle()->GetStatusCode());
93836e1b 311 //
312 Int_t d0 = mcpart_tmp.GetDaughter(0);
313 Int_t d1 = mcpart_tmp.GetDaughter(1);
314 Int_t m = mcpart_tmp.GetMother();
315
316 // other than for the track labels, negative values mean
317 // no daughter/mother so preserve it
318
319 if(d0<0 && d1<0){
320 // no first daughter -> no second daughter
321 // nothing to be done
322 // second condition not needed just for sanity check at the end
323 mcpart_tmp.SetDaughter(0,d0);
324 mcpart_tmp.SetDaughter(1,d1);
325 } else if(d1 < 0 && d0 >= 0) {
326 // Only one daughter
327 // second condition not needed just for sanity check at the end
328 if(fMCEventH->IsParticleSelected(d0)){
329 mcpart_tmp.SetDaughter(0,fMCEventH->GetNewLabel(d0));
330 } else {
331 mcpart_tmp.SetDaughter(0,-1);
332 }
333 mcpart_tmp.SetDaughter(1,d1);
334 }
335 else if (d0 > 0 && d1 > 0 ){
336 // we have two or more daughters loop on the stack to see if they are
337 // selected
338 Int_t d0_tmp = -1;
339 Int_t d1_tmp = -1;
340 for(int id = d0; id<=d1;++id){
341 if(fMCEventH->IsParticleSelected(id)){
342 if(d0_tmp==-1){
343 // first time
344 d0_tmp = fMCEventH->GetNewLabel(id);
345 d1_tmp = d0_tmp; // this is to have the same schema as on the stack i.e. with one daugther d0 and d1 are the same
346 }
347 else d1_tmp = fMCEventH->GetNewLabel(id);
348 }
349 }
350 mcpart_tmp.SetDaughter(0,d0_tmp);
351 mcpart_tmp.SetDaughter(1,d1_tmp);
352 } else {
353 AliError(Form("Unxpected indices %d %d",d0,d1));
354 }
355
356 if(m<0){
357 mcpart_tmp.SetMother(m);
358 } else {
359 if(fMCEventH->IsParticleSelected(m))mcpart_tmp.SetMother(fMCEventH->GetNewLabel(m));
360 else AliError(Form("PROBLEM Mother not selected %d \n", m));
361 }
6326aeae 362
93836e1b 363 new (l[j++]) AliAODMCParticle(mcpart_tmp);
364
da97a08a 365 }
da97a08a 366 }
93836e1b 367 AliInfo(Form("AliAODHandler::StoreMCParticles: Selected %d (Primaries %d / total %d) after validation \n",
da97a08a 368 j,nprim,np));
369
370 // Set the labels in the AOD output...
371 // Remapping
372
373 // AODTracks
374 TClonesArray* tracks = fAODEvent->GetTracks();
375 if(tracks){
376 for(int it = 0; it < fAODEvent->GetNTracks();++it){
377 AliAODTrack *track = fAODEvent->GetTrack(it);
378
91dece68 379 Int_t sign = 1;
380 Int_t label = track->GetLabel();
381 if(label<0){ // preserve the sign for later usage
382 label *= -1;
383 sign = -1;
384 }
385
93836e1b 386 if (label >= AliMCEvent::BgLabelOffset()) label = mcEvent->BgLabelToIndex(label);
93836e1b 387 if(label > np || track->GetLabel() == 0){
388 AliWarning(Form("Wrong ESD track label %5d (%5d)",track->GetLabel(), label));
da97a08a 389 }
93836e1b 390 if(fMCEventH->GetNewLabel(label) == 0){
391 AliWarning(Form("New label not found for %5d (%5d)",track->GetLabel(), label));
da97a08a 392 }
91dece68 393 track->SetLabel(sign*fMCEventH->GetNewLabel(label));
da97a08a 394 }
395 }
396
397 // AOD calo cluster
398 TClonesArray *clusters = fAODEvent->GetCaloClusters();
399 if(clusters){
c8fe2783 400 for (Int_t iClust = 0;iClust < fAODEvent->GetNumberOfCaloClusters(); ++iClust) {
da97a08a 401 AliAODCaloCluster * cluster = fAODEvent->GetCaloCluster(iClust);
c8fe2783 402 UInt_t nLabel = cluster->GetNLabels();
da97a08a 403 // Ugly but do not want to fragment memory by creating
404 // new Int_t (nLabel)
405 Int_t* labels = const_cast<Int_t*>(cluster->GetLabels());
406 if (labels){
407 for(UInt_t i = 0;i < nLabel;++i){
c8fe2783 408 labels[i] = fMCEventH->GetNewLabel(cluster->GetLabelAt(i));
da97a08a 409 }
410 }
411 // cluster->SetLabels(labels,nLabel);
412 }// iClust
413 }// clusters
414
415 // AOD tracklets
416 AliAODTracklets *tracklets = fAODEvent->GetTracklets();
417 if(tracklets){
418 for(int it = 0;it < tracklets->GetNumberOfTracklets();++it){
419 int label0 = tracklets->GetLabel(it,0);
420 int label1 = tracklets->GetLabel(it,1);
421 if(label0>=0)label0 = fMCEventH->GetNewLabel(label0);
422 if(label1>=0)label1 = fMCEventH->GetNewLabel(label1);
423 tracklets->SetLabel(it,0,label0);
424 tracklets->SetLabel(it,1,label1);
425 }
426 }
427
428}
429
9066c676 430//______________________________________________________________________________
5f380da9 431Bool_t AliAODHandler::FinishEvent()
ec4af4c1 432{
da97a08a 433 // Fill data structures
14d6fad5 434
4e6d5854 435 if(fFillAOD && fFillAODRun && fAODEvent){
b8b7dd5c 436 fAODEvent->MakeEntriesReferencable();
e0107012 437 fTreeA->BranchRef();
b8b7dd5c 438 FillTree();
4e6d5854 439 }
f133e976 440
ca2834f6 441 if ((fFillAOD && fFillAODRun) || fFillExtension) {
14d6fad5 442 if (fExtensions) {
443 TIter next(fExtensions);
444 AliAODExtension *ext;
445 while ((ext=(AliAODExtension*)next())) ext->FinishEvent();
446 }
447 if (fFilters) {
448 TIter nextf(fFilters);
449 AliAODExtension *ext;
450 while ((ext=(AliAODExtension*)nextf())) {
b8b7dd5c 451 ext->FinishEvent();
14d6fad5 452 }
453 }
aa399a26 454 }
14d6fad5 455
456 if (fIsStandard)
457 {
458 fAODEvent->ResetStd();
459 }
460
461 if (fAODEvent)
462 {
463 TClonesArray *mcarray = static_cast<TClonesArray*>(fAODEvent->FindListObject(AliAODMCParticle::StdBranchName()));
ef89f372 464 if(mcarray) mcarray->Delete();
465
14d6fad5 466 AliAODMCHeader *mcHeader = static_cast<AliAODMCHeader*>(fAODEvent->FindListObject(AliAODMCHeader::StdBranchName()));
ef89f372 467 if(mcHeader) mcHeader->Reset();
468 }
14d6fad5 469
da97a08a 470 // Reset AOD replication flag
471 fAODIsReplicated = kFALSE;
472 return kTRUE;
ec4af4c1 473}
474
7970f4ac 475//______________________________________________________________________________
ec4af4c1 476Bool_t AliAODHandler::Terminate()
477{
9066c676 478 // Terminate
479 AddAODtoTreeUserInfo();
14d6fad5 480
481 TIter nextF(fFilters);
482 AliAODExtension *ext;
483 while ((ext=static_cast<AliAODExtension*>(nextF())))
484 {
485 ext->AddAODtoTreeUserInfo();
486 }
487
488 TIter nextE(fExtensions);
489 while ((ext=static_cast<AliAODExtension*>(nextE())))
490 {
491 ext->AddAODtoTreeUserInfo();
492 }
493
9066c676 494 return kTRUE;
ec4af4c1 495}
496
7970f4ac 497//______________________________________________________________________________
ec4af4c1 498Bool_t AliAODHandler::TerminateIO()
499{
9066c676 500 // Terminate IO
501 if (fFileA) {
aa399a26 502 fFileA->Write();
9066c676 503 fFileA->Close();
504 delete fFileA;
505 fFileA = 0;
48f1c230 506 // When closing the file, the tree is also deleted.
507 fTreeA = 0;
9066c676 508 }
14d6fad5 509
510 TIter nextF(fFilters);
511 AliAODExtension *ext;
512 while ((ext=static_cast<AliAODExtension*>(nextF())))
513 {
514 ext->TerminateIO();
9066c676 515 }
14d6fad5 516
517 TIter nextE(fExtensions);
518 while ((ext=static_cast<AliAODExtension*>(nextE())))
519 {
520 ext->TerminateIO();
582cfeb5 521 }
14d6fad5 522
9066c676 523 return kTRUE;
ec4af4c1 524}
525
7970f4ac 526//______________________________________________________________________________
954526ed 527void AliAODHandler::CreateTree(Int_t flag)
ec4af4c1 528{
529 // Creates the AOD Tree
f3214a54 530 fTreeA = new TTree("aodTree", "AliAOD tree");
ec4af4c1 531 fTreeA->Branch(fAODEvent->GetList());
954526ed 532 if (flag == 0) fTreeA->SetDirectory(0);
ec4af4c1 533}
534
7970f4ac 535//______________________________________________________________________________
ec4af4c1 536void AliAODHandler::FillTree()
537{
866d8d78 538
ec4af4c1 539 // Fill the AOD Tree
e0107012 540 fTreeA->Fill();
ec4af4c1 541}
542
7970f4ac 543//______________________________________________________________________________
ec4af4c1 544void AliAODHandler::AddAODtoTreeUserInfo()
545{
dce1b636 546 // Add aod event to tree user info
aa399a26 547 if (fTreeA) fTreeA->GetUserInfo()->Add(fAODEvent);
48f1c230 548 // Now the tree owns our fAODEvent...
549 fAODEvent = 0;
ec4af4c1 550}
490e9023 551
7970f4ac 552//______________________________________________________________________________
9066c676 553void AliAODHandler::AddBranch(const char* cname, void* addobj, const char* filename)
490e9023 554{
14d6fad5 555 // Add a new branch to the aod. Added optional filename parameter if the
556 // branch should be written to a separate file.
557
558 if (strlen(filename))
559 {
560 AliAODExtension *ext = AddExtension(filename);
561 ext->AddBranch(cname, addobj);
562 return;
563 }
564
565 // Add branch to all filters
566 // Add branch to all filters
567 if (fFilters) {
568 TIter next(fFilters);
569 AliAODExtension *ext;
570 while ((ext=(AliAODExtension*)next())) ext->AddBranch(cname, addobj);
571 }
572
573 TDirectory *owd = gDirectory;
574 if (fFileA)
575 {
576 fFileA->cd();
577 }
dce1b636 578
14d6fad5 579 char** apointer = (char**) addobj;
580 TObject* obj = (TObject*) *apointer;
581
582 fAODEvent->AddObject(obj);
583
584 const Int_t kSplitlevel = 99; // default value in TTree::Branch()
585 const Int_t kBufsize = 32000; // default value in TTree::Branch()
586
587 if (!fTreeA->FindBranch(obj->GetName()))
588 {
589 // Do the same as if we book via
590 // TTree::Branch(TCollection*)
591
592 fTreeA->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj),
593 kBufsize, kSplitlevel - 1);
594 }
595 owd->cd();
490e9023 596}
7970f4ac 597
9066c676 598//______________________________________________________________________________
599AliAODExtension *AliAODHandler::AddExtension(const char *filename, const char *title)
600{
14d6fad5 601 // Add an AOD extension with some branches in a different file.
26ba01d4 602
14d6fad5 603 TString fname(filename);
604 if (!fname.EndsWith(".root")) fname += ".root";
605 if (!fExtensions) {
606 fExtensions = new TObjArray();
607 fExtensions->SetOwner();
608 }
609 AliAODExtension *ext = (AliAODExtension*)fExtensions->FindObject(fname);
610 if (!ext) {
611 ext = new AliAODExtension(fname, title);
612 fExtensions->Add(ext);
613 }
614 return ext;
9066c676 615}
582cfeb5 616
617//______________________________________________________________________________
618AliAODExtension *AliAODHandler::GetExtension(const char *filename) const
619{
14d6fad5 620 // Getter for AOD extensions via file name.
621 if (!fExtensions) return NULL;
622 return (AliAODExtension*)fExtensions->FindObject(filename);
582cfeb5 623}
624
625//______________________________________________________________________________
626AliAODExtension *AliAODHandler::AddFilteredAOD(const char *filename, const char *filtername)
627{
14d6fad5 628 // Add an AOD extension that can write only AOD events that pass a user filter.
629 if (!fFilters) {
630 fFilters = new TObjArray();
631 fFilters->SetOwner();
632 }
633 AliAODExtension *filter = (AliAODExtension*)fFilters->FindObject(filename);
634 if (!filter) {
635 filter = new AliAODExtension(filename, filtername, kTRUE);
636 fFilters->Add(filter);
637 }
638 return filter;
582cfeb5 639}
640
641//______________________________________________________________________________
642AliAODExtension *AliAODHandler::GetFilteredAOD(const char *filename) const
643{
14d6fad5 644 // Getter for AOD filters via file name.
645 if (!fFilters) return NULL;
646 return (AliAODExtension*)fFilters->FindObject(filename);
582cfeb5 647}
14d6fad5 648
7970f4ac 649//______________________________________________________________________________
650void AliAODHandler::SetOutputFileName(const char* fname)
651{
652// Set file name.
653 fFileName = fname;
654}
655
656//______________________________________________________________________________
657const char *AliAODHandler::GetOutputFileName()
658{
659// Get file name.
660 return fFileName.Data();
661}
dce1b636 662
90d50a8c 663//______________________________________________________________________________
664const char *AliAODHandler::GetExtraOutputs() const
665{
14d6fad5 666 // Get extra outputs as a string separated by commas.
667 static TString eoutputs;
668 eoutputs = "";
669 TObject *obj;
670 if (fExtensions) {
671 TIter next1(fExtensions);
672 while ((obj=next1())) {
673 if (!eoutputs.IsNull()) eoutputs += ",";
674 eoutputs += obj->GetName();
675 }
676 }
677 if (fFilters) {
678 TIter next2(fFilters);
679 while ((obj=next2())) {
680 if (!eoutputs.IsNull()) eoutputs += ",";
681 eoutputs += obj->GetName();
682 }
683 }
684 return eoutputs.Data();
685}
686
687//______________________________________________________________________________
688Bool_t AliAODHandler::HasExtensions() const
689{
690 // Whether or not we manage extensions
691
692 if ( fExtensions && fExtensions->GetEntries()>0 ) return kTRUE;
693
694 return kFALSE;
90d50a8c 695}
696
9066c676 697//______________________________________________________________________________
dce1b636 698void AliAODHandler::SetMCHeaderInfo(AliAODMCHeader *mcHeader,AliGenEventHeader *genHeader){
699
700
701 // Utility function to cover different cases for the AliGenEventHeader
702 // Needed since different ProcessType and ImpactParamter are not
703 // in the base class...
704 // We don't encode process types for event cocktails yet
9066c676 705 // could be done e.g. by adding offsets depnding on the generator
dce1b636 706
707 mcHeader->AddGeneratorName(genHeader->GetName());
dce1b636 708 if(!genHeader)return;
709 AliGenPythiaEventHeader *pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(genHeader);
710 if (pythiaGenHeader) {
711 mcHeader->SetEventType(pythiaGenHeader->ProcessType());
0fd37a1f 712 mcHeader->SetPtHard(pythiaGenHeader->GetPtHard());
dce1b636 713 return;
714 }
715
716 AliGenDPMjetEventHeader* dpmJetGenHeader = dynamic_cast<AliGenDPMjetEventHeader*>(genHeader);
717
718 if (dpmJetGenHeader){
719 mcHeader->SetEventType(dpmJetGenHeader->ProcessType());
720 return;
721 }
722
723 AliGenHijingEventHeader* hijingGenHeader = dynamic_cast<AliGenHijingEventHeader*>(genHeader);
724 if(hijingGenHeader){
725 mcHeader->SetImpactParameter(hijingGenHeader->ImpactParameter());
726 return;
727 }
728
729 AliWarning(Form("MC Eventheader not known: %s",genHeader->GetName()));
730
731}
9066c676 732