AliRoot Core  edcc906 (edcc906)
AliESDHandler.cxx
Go to the documentation of this file.
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 ClassImp(AliESDHandler)
37 
38 //______________________________________________________________________________
41  fesdf(NULL),
42  fTreeEF(NULL),
43  fFileEF(NULL),
44  fFileName("AliESDfriends_v1.root"),
45  fIsEventSelectedForFriends(kFALSE)
46 {
47 
48  // default constructor
49 }
50 
51 //______________________________________________________________________________
52 AliESDHandler::AliESDHandler(const char* name, const char* title):
53  AliVEventHandler(name, title),
54  fesdf(NULL),
55  fTreeEF(NULL),
56  fFileEF(NULL),
57  fFileName("AliESDfriends_v1.root"),
58  fIsEventSelectedForFriends(kFALSE)
59 {
60 
61  // constructor with name and title
62 
63 }
64 
65 //______________________________________________________________________________
67 {
68  // Destructor.
69  delete fesdf;
70  if(fFileEF){
71  // is already handled in TerminateIO
72  fFileEF->Close();
73  delete fFileEF;
74  }
75  delete fTreeEF;
76 }
77 
78 //______________________________________________________________________________
79 Bool_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;
89 
90  fesdf = new AliESDfriend();
91 
92  // Open the file with friends
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()));
97  gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer()->SetFile((TFile*)0x%p);", gFile));
98  fFileEF = gFile;
99  } else {
100  // local and grid
101  fFileEF = new TFile(fFileName.Data(), "RECREATE");
102  }
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 
109  owd->cd();
110 
111  return kTRUE;
112 }
113 
114 
115 //______________________________________________________________________________
117 {
118  //
119  // Fill the tree
120  //
121 
122  FillTree();
123 
124  // resetting
125  if (fesdf) fesdf->~AliESDfriend();
126  new(fesdf) AliESDfriend();
127  return kTRUE;
128 }
129 
130 //______________________________________________________________________________
132 {
133  //
134  // Terminate
135  //
136 
137  return kTRUE;
138 }
139 
140 //______________________________________________________________________________
142 {
143  //
144  // Terminate IO
145  //
146 
147  if (fFileEF) {
148  fFileEF->cd();
149  fTreeEF->Write();
150  fFileEF->Close();
151  delete fFileEF;
152  fFileEF = 0;
153  }
154 
155  return kTRUE;
156 }
157 
158 //______________________________________________________________________________
160 {
161  //
162  // Fill the ESD Tree
163  //
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));
171  fFileEF->cd();
172  fTreeEF->Fill();
173 }
Bool_t fIsEventSelectedForFriends
Output file name for friends.
Definition: AliESDHandler.h:56
void SetSkipBit(Bool_t skip)
Definition: AliESDfriend.h:74
AliESDfriend * fesdf
Definition: AliESDHandler.h:52
virtual ~AliESDHandler()
TROOT * gROOT
virtual Bool_t TerminateIO()
virtual Bool_t Terminate()
TTree * fTreeEF
Pointer to the ESD friend.
Definition: AliESDHandler.h:53
Int_t GetNumberOfTracks() const
Definition: AliESDfriend.h:40
virtual Bool_t Init(Option_t *option)
virtual Bool_t FinishEvent()
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
virtual ~AliESDfriend()
TFile * fFileEF
Output tree for friends.
Definition: AliESDHandler.h:54
TString fFileName
Output file for friends.
Definition: AliESDHandler.h:55