Fixed warnings
[u/mrichter/AliRoot.git] / STEER / AliESDHandler.cxx
1
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 //
21 //     Implementation of the Virtual Event Handler Interface for ESD
22 //
23 //-------------------------------------------------------------------------
24
25
26 #include <TTree.h>
27 #include <TFile.h>
28 #include <TString.h>
29 #include <TROOT.h>
30
31 #include "AliLog.h"
32 #include "AliESDHandler.h"
33 #include "AliESDEvent.h"
34 #include "AliESDfriend.h"
35
36
37 ClassImp(AliESDHandler)
38
39 //______________________________________________________________________________
40 AliESDHandler::AliESDHandler() :
41         AliVEventHandler(),
42         fESDEvent(NULL),
43         fesdf(NULL),
44         fTreeE(NULL),
45         fFileE(NULL),
46         fFileEF(NULL),
47         fFileName("")
48 {
49         // default constructor
50 }
51
52 //______________________________________________________________________________
53 AliESDHandler::AliESDHandler(const char* name, const char* title):
54         AliVEventHandler(name, title),
55         fESDEvent(NULL),
56         fesdf(NULL),
57         fTreeE(NULL),
58         fFileE(NULL),
59         fFileEF(NULL),
60         fFileName("")
61 {
62
63         // constructor with name and title
64
65 }
66
67 //______________________________________________________________________________
68 AliESDHandler::~AliESDHandler() 
69 {
70         // Destructor.
71         delete fESDEvent;
72         delete fesdf;
73         if(fFileE){
74                 // is already handled in TerminateIO
75                 fFileE->Close();
76                 delete fFileE;
77         }
78         if(fFileEF){
79                 // is already handled in TerminateIO
80                 fFileEF->Close();
81                 delete fFileEF;
82         }
83         delete fTreeE;
84 }
85
86 //______________________________________________________________________________
87 Bool_t AliESDHandler::Init(Option_t* opt)
88 {
89         //
90         // Initialize IO
91         //
92         
93         // File opening according to execution mode
94         TString option(opt);
95         option.ToLower();
96         TDirectory *owd = gDirectory;
97         if (option.Contains("proof")) {
98                 // proof
99                 // Merging via files. Need to access analysis manager via interpreter.
100                 gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(\"%s\", \"RECREATE\");", fFileName.Data()));
101                 gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer()->SetFile((TFile*)0x%lx);", gFile));
102                 fFileE = gFile;
103         } else {
104                 // local and grid
105                 fFileE = new TFile(fFileName.Data(), "RECREATE");
106         }
107         CreateTree(1);
108         CreateFriends(1);
109         owd->cd();
110         
111         return kTRUE;
112 }
113
114
115 //______________________________________________________________________________
116 Bool_t AliESDHandler::FinishEvent()
117 {
118         //
119         // Fill the tree 
120         //
121
122         FillTree();
123         
124         // resetting
125         fESDEvent->Reset();
126         fesdf->~AliESDfriend();
127         new(fesdf) AliESDfriend();  
128         return kTRUE;
129 }
130
131 //______________________________________________________________________________
132 Bool_t AliESDHandler::Terminate()
133 {
134         //
135         // Terminate 
136         //
137
138         AddESDtoTreeUserInfo();
139         return kTRUE;
140 }
141
142 //______________________________________________________________________________
143 Bool_t AliESDHandler::TerminateIO()
144 {
145         //
146         // Terminate IO
147         //
148
149         if (fFileE) {
150                 fFileE->cd();
151                 fTreeE->Write();
152                 fFileE->Close();
153                 delete fFileE;
154                 fFileE = 0;
155         }
156
157         return kTRUE;
158 }
159
160
161 //______________________________________________________________________________
162 void AliESDHandler::CreateTree(Int_t /*flag*/)
163 {
164         //
165         // Creates the ESD Tree
166         // 
167
168         fTreeE = new TTree("esdTree", "AliESD tree");
169         // Create the ESDevent object
170         if(!fESDEvent){
171                 fESDEvent = new AliESDEvent();
172                 fESDEvent->CreateStdContent();
173         }
174         fESDEvent->WriteToTree(fTreeE);
175 }
176 //______________________________________________________________________________
177 void AliESDHandler::CreateFriends(Int_t /*flag*/)
178 {
179         fesdf = new AliESDfriend();
180
181         TBranch *br=fTreeE->Branch("ESDfriend.","AliESDfriend", &fesdf);
182         br->SetFile("AliESDfriends_v1.root");
183         fESDEvent->AddObject(fesdf);
184 }
185
186 //______________________________________________________________________________
187 void AliESDHandler::FillTree()
188 {
189         //
190         // Fill the ESD Tree
191         //
192
193         AliDebug(2,Form("number of friend tracks = %d\n",fesdf->GetNumberOfTracks()));
194
195         fFileE->cd();
196         fTreeE->Fill();
197 }
198
199 //______________________________________________________________________________
200 void AliESDHandler::AddESDtoTreeUserInfo()
201 {
202         //
203         // Add aod event to tree user info
204         //
205
206         fTreeE->GetUserInfo()->Add(fESDEvent);
207 }
208
209
210