Call MakeEntriesReferencable before filling the tree.
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
CommitLineData
ec4af4c1 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// Implementation of the Virtual Event Handler Interface for AOD
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
052994fb 23
ec4af4c1 24#include <TTree.h>
e910dd36 25#include <TFile.h>
26
ec4af4c1 27#include "AliAODHandler.h"
28#include "AliAODEvent.h"
29
30ClassImp(AliAODHandler)
31
32//______________________________________________________________________________
33AliAODHandler::AliAODHandler() :
f3214a54 34 AliVEventHandler(),
78f7f935 35 fIsStandard(kTRUE),
ec4af4c1 36 fAODEvent(NULL),
e910dd36 37 fTreeA(NULL),
38 fFileA(NULL),
39 fName("")
ec4af4c1 40{
41 // default constructor
42}
43
44//______________________________________________________________________________
45AliAODHandler::AliAODHandler(const char* name, const char* title):
f3214a54 46 AliVEventHandler(name, title),
78f7f935 47 fIsStandard(kTRUE),
ec4af4c1 48 fAODEvent(NULL),
e910dd36 49 fTreeA(NULL),
50 fFileA(NULL),
51 fName("")
ec4af4c1 52{
53}
54
55//______________________________________________________________________________
56AliAODHandler::~AliAODHandler()
57{
6989bff3 58 delete fAODEvent;
59 if(fFileA){
60 // is already handled in TerminateIO
61 fFileA->Close();
62 delete fFileA;
63 }
64 delete fTreeA;
65 delete fName;
66 // destructor
ec4af4c1 67}
68
69
300d5701 70Bool_t AliAODHandler::Init(Option_t* opt)
ec4af4c1 71{
6989bff3 72 // Initialize IO
73 //
74 // Create the AODevent object
75 if(!fAODEvent){
ec4af4c1 76 fAODEvent = new AliAODEvent();
78f7f935 77 if (fIsStandard) fAODEvent->CreateStdContent();
6989bff3 78 }
79 //
80 // File opening according to execution mode
81
82 if (!(strcmp(opt, "proof"))) {
83 // proof
84 CreateTree(0);
85 } else {
86 // local and grid
26b9ac7a 87 TDirectory *owd = gDirectory;
6989bff3 88 fFileA = new TFile(fName, "RECREATE");
89 CreateTree(1);
26b9ac7a 90 owd->cd();
6989bff3 91 }
92 return kTRUE;
ec4af4c1 93}
94
5f380da9 95Bool_t AliAODHandler::FinishEvent()
ec4af4c1 96{
97 // Fill data structures
f4e5f8d5 98 fAODEvent->MakeEntriesReferencable();
ec4af4c1 99 FillTree();
78f7f935 100 if (fIsStandard) fAODEvent->ResetStd();
ec4af4c1 101 return kTRUE;
102}
103
104Bool_t AliAODHandler::Terminate()
105{
106 // Terminate
107 AddAODtoTreeUserInfo();
108 return kTRUE;
109}
110
111Bool_t AliAODHandler::TerminateIO()
112{
113 // Terminate IO
21501411 114 if (fFileA) {
490e9023 115 fFileA->ls();
21501411 116 fFileA->Close();
117 delete fFileA;
118 }
ec4af4c1 119 return kTRUE;
120}
121
122
954526ed 123void AliAODHandler::CreateTree(Int_t flag)
ec4af4c1 124{
125 // Creates the AOD Tree
f3214a54 126 fTreeA = new TTree("aodTree", "AliAOD tree");
ec4af4c1 127 fTreeA->Branch(fAODEvent->GetList());
954526ed 128 if (flag == 0) fTreeA->SetDirectory(0);
ec4af4c1 129}
130
131void AliAODHandler::FillTree()
132{
133 // Fill the AOD Tree
134 fTreeA->Fill();
135}
136
137
138void AliAODHandler::AddAODtoTreeUserInfo()
139{
140 // Add aod event to tree user info
141 fTreeA->GetUserInfo()->Add(fAODEvent);
142}
490e9023 143
78f7f935 144void AliAODHandler::AddBranch(const char* cname, TObject* addobj)
490e9023 145{
146 // Add a new branch to the aod
147 TDirectory *owd = gDirectory;
148 if (fFileA) {
149 fFileA->cd();
150 }
78f7f935 151 fTreeA->Branch(addobj->GetName(), cname, &addobj);
490e9023 152 fAODEvent->AddObject(addobj);
153 owd->cd();
154}