In AddTaskPHOSPi0Flow.C set Cent. Bin past event buffers/lists,
[u/mrichter/AliRoot.git] / STEER / ESD / AliESDHandler.cxx
CommitLineData
6d3a7bbf 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
6d3a7bbf 36ClassImp(AliESDHandler)
37
38//______________________________________________________________________________
39AliESDHandler::AliESDHandler() :
40 AliVEventHandler(),
6d3a7bbf 41 fesdf(NULL),
03a8000a 42 fTreeEF(NULL),
6d3a7bbf 43 fFileEF(NULL),
3e341ccb 44 fFileName("AliESDfriends_v1.root"),
45 fIsEventSelectedForFriends(kFALSE)
6d3a7bbf 46{
3e341ccb 47
6d3a7bbf 48 // default constructor
49}
50
51//______________________________________________________________________________
52AliESDHandler::AliESDHandler(const char* name, const char* title):
53 AliVEventHandler(name, title),
6d3a7bbf 54 fesdf(NULL),
03a8000a 55 fTreeEF(NULL),
6d3a7bbf 56 fFileEF(NULL),
3e341ccb 57 fFileName("AliESDfriends_v1.root"),
58 fIsEventSelectedForFriends(kFALSE)
6d3a7bbf 59{
60
61 // constructor with name and title
62
63}
64
65//______________________________________________________________________________
66AliESDHandler::~AliESDHandler()
67{
68 // Destructor.
6d3a7bbf 69 delete fesdf;
6d3a7bbf 70 if(fFileEF){
71 // is already handled in TerminateIO
72 fFileEF->Close();
73 delete fFileEF;
74 }
03a8000a 75 delete fTreeEF;
6d3a7bbf 76}
77
78//______________________________________________________________________________
79Bool_t AliESDHandler::Init(Option_t* opt)
80{
81 //
82 // Initialize IO
83 //
84
85 // File opening according to execution mode
86 TString option(opt);
87 option.ToLower();
88 TDirectory *owd = gDirectory;
03a8000a 89
90 fesdf = new AliESDfriend();
91
92 // Open the file with friends
6d3a7bbf 93 if (option.Contains("proof")) {
94 // proof
95 // Merging via files. Need to access analysis manager via interpreter.
96 gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(\"%s\", \"RECREATE\");", fFileName.Data()));
65b25288 97 gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer()->SetFile((TFile*)0x%p);", gFile));
03a8000a 98 fFileEF = gFile;
6d3a7bbf 99 } else {
100 // local and grid
03a8000a 101 fFileEF = new TFile(fFileName.Data(), "RECREATE");
6d3a7bbf 102 }
03a8000a 103
104 // Create the friends tree
105 fFileEF->cd();
106 fTreeEF = new TTree("esdFriendTree", "Tree with ESD friends");
107 fTreeEF->Branch("ESDfriend.","AliESDfriend", &fesdf);
108
6d3a7bbf 109 owd->cd();
110
111 return kTRUE;
112}
113
114
115//______________________________________________________________________________
116Bool_t AliESDHandler::FinishEvent()
117{
118 //
119 // Fill the tree
120 //
121
122 FillTree();
123
124 // resetting
3e341ccb 125 if (fesdf) fesdf->~AliESDfriend();
6d3a7bbf 126 new(fesdf) AliESDfriend();
127 return kTRUE;
128}
129
130//______________________________________________________________________________
131Bool_t AliESDHandler::Terminate()
132{
133 //
134 // Terminate
135 //
136
6d3a7bbf 137 return kTRUE;
138}
139
140//______________________________________________________________________________
141Bool_t AliESDHandler::TerminateIO()
142{
143 //
144 // Terminate IO
145 //
146
03a8000a 147 if (fFileEF) {
148 fFileEF->cd();
149 fTreeEF->Write();
150 fFileEF->Close();
151 delete fFileEF;
152 fFileEF = 0;
6d3a7bbf 153 }
154
155 return kTRUE;
156}
157
6d3a7bbf 158//______________________________________________________________________________
159void AliESDHandler::FillTree()
160{
161 //
162 // Fill the ESD Tree
163 //
3e341ccb 164 if (fIsEventSelectedForFriends){
165 AliDebug(2,Form("number of friend tracks = %d\n",fesdf->GetNumberOfTracks()));
166 }
167 else {
168 fesdf->SetSkipBit(kTRUE);
169 }
170 AliDebug(2,Form("friend = %p",fesdf));
03a8000a 171 fFileEF->cd();
172 fTreeEF->Fill();
6d3a7bbf 173}