]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/AliSelector.cxx
introducing monalisa monitoring
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
CommitLineData
dc740de4 1/* $Id$ */
2
539b6cb4 3// The class definition in esdV0.h has been generated automatically
4// by the ROOT utility TTree::MakeSelector(). This class is derived
5// from the ROOT class TSelector. For more information on the TSelector
6// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
7
8// The following methods are defined in this file:
9// Begin(): called everytime a loop on the tree starts,
10// a convenient place to create your histograms.
11// SlaveBegin(): called after Begin(), when on PROOF called only on the
12// slave servers.
13// Process(): called for each event, in this function you decide what
14// to read and fill your histograms.
15// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
16// called only on the slave servers.
17// Terminate(): called at the end of the loop on the tree,
18// a convenient place to draw/fit your histograms.
19//
20// To use this file, try the following session on your Tree T:
21//
22// Root > T->Process("AliSelector.C")
23// Root > T->Process("AliSelector.C","some options")
24// Root > T->Process("AliSelector.C+")
25//
26
27#include "AliSelector.h"
b8e8168f 28
539b6cb4 29#include <TStyle.h>
30#include <TSystem.h>
31#include <TCanvas.h>
32#include <TRegexp.h>
b8e8168f 33#include <TTime.h>
dc740de4 34#include <TFriendElement.h>
f8e00da3 35#include <TTree.h>
36#include <TChain.h>
37#include <TFile.h>
539b6cb4 38
b8e8168f 39#include <AliLog.h>
f8e00da3 40#include <AliESD.h>
539b6cb4 41
42ClassImp(AliSelector)
43
ee998961 44AliSelector::AliSelector() :
539b6cb4 45 TSelector(),
16e24ca3 46 fTree(0),
539b6cb4 47 fESD(0),
dc740de4 48 fCountFiles(0),
16e24ca3 49 fKineFile(0)
539b6cb4 50{
79ab56b9 51 //
539b6cb4 52 // Constructor. Initialization of pointers
79ab56b9 53 //
539b6cb4 54}
55
56AliSelector::~AliSelector()
57{
79ab56b9 58 //
59 // Destructor
60 //
539b6cb4 61
05317a93 62 if (fTree)
63 fTree->ResetBranchAddresses();
64
65 if (fESD)
66 {
67 delete fESD;
68 fESD = 0;
69 }
539b6cb4 70}
71
18be36ae 72void AliSelector::CheckOptions()
539b6cb4 73{
18be36ae 74 // checks the option string for the debug flag
75
76 AliLog::SetClassDebugLevel(ClassName(), AliLog::kInfo);
25db2d85 77
0ab29cfa 78 TString option = GetOption();
79
80 if (option.Contains("debug"))
81 {
18be36ae 82 printf("Enabling debug more for %s\n", ClassName());
83 AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug);
0ab29cfa 84 AliInfo(Form("Called with option %s.", option.Data()));
85 }
18be36ae 86}
87
88void AliSelector::Begin(TTree*)
89{
90 // The Begin() function is called at the start of the query.
91 // When running with PROOF Begin() is only called on the client.
92 // The tree argument is deprecated (on PROOF 0 is passed).
93
94 CheckOptions();
0ab29cfa 95
25db2d85 96 AliDebug(AliLog::kDebug, "============BEGIN===========");
539b6cb4 97}
98
16e24ca3 99void AliSelector::SlaveBegin(TTree* tree)
539b6cb4 100{
101 // The SlaveBegin() function is called after the Begin() function.
102 // When running with PROOF SlaveBegin() is called on each slave server.
103 // The tree argument is deprecated (on PROOF 0 is passed).
104
18be36ae 105 CheckOptions();
ea1224c5 106
b8e8168f 107 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
108 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
109 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
539b6cb4 110
16e24ca3 111 if (tree != 0)
112 Init(tree);
539b6cb4 113}
114
115void AliSelector::Init(TTree *tree)
116{
117 // The Init() function is called when the selector needs to initialize
118 // a new tree or chain. Typically here the branch addresses of the tree
119 // will be set. It is normaly not necessary to make changes to the
120 // generated code, but the routine can be extended by the user if needed.
121 // Init() will be called many times when running with PROOF.
122
b8e8168f 123 AliDebug(AliLog::kDebug, "=========Init==========");
539b6cb4 124
16e24ca3 125 fTree = tree;
539b6cb4 126
16e24ca3 127 if (fTree == 0)
539b6cb4 128 {
16e24ca3 129 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
539b6cb4 130 return;
131 }
132
16e24ca3 133 // Set branch address
134 fTree->SetBranchAddress("ESD", &fESD);
539b6cb4 135 if (fESD != 0)
b8e8168f 136 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
539b6cb4 137}
138
139Bool_t AliSelector::Notify()
140{
141 // The Notify() function is called when a new file is opened. This
142 // can be either for a new TTree in a TChain or when when a new TTree
143 // is started when using PROOF. Typically here the branch pointers
144 // will be retrieved. It is normaly not necessary to make changes
145 // to the generated code, but the routine can be extended by the
146 // user if needed.
147
b8e8168f 148 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
149 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
150 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
ee998961 151
dc740de4 152 ++fCountFiles;
16e24ca3 153 if (fTree)
154 {
155 TFile *f = fTree->GetCurrentFile();
156 AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
157 }
158 else
159 {
160 AliDebug(AliLog::kError, "fTree not available");
161 }
539b6cb4 162
163 DeleteKinematicsFile();
dc740de4 164
539b6cb4 165 return kTRUE;
166}
167
168Bool_t AliSelector::Process(Long64_t entry)
169{
170 // The Process() function is called for each entry in the tree (or possibly
171 // keyed object in the case of PROOF) to be processed. The entry argument
172 // specifies which entry in the currently loaded tree is to be processed.
173 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
174 // to read either all or the required parts of the data. When processing
175 // keyed objects with PROOF, the object is already loaded and is available
176 // via the fObject pointer.
177 //
178 // This function should contain the "body" of the analysis. It can contain
179 // simple or elaborate selection criteria, run algorithms on the data
180 // of the event and typically fill histograms.
181
182 // WARNING when a selector is used with a TChain, you must use
183 // the pointer to the current TTree to call GetEntry(entry).
184 // The entry is always the local entry number in the current tree.
16e24ca3 185 // Assuming that fTree is the pointer to the TChain being processed,
186 // use fTree->GetTree()->GetEntry(entry).
539b6cb4 187
b8e8168f 188 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
539b6cb4 189
16e24ca3 190 if (!fTree)
539b6cb4 191 {
16e24ca3 192 AliDebug(AliLog::kError, "ERROR: fTree is 0.");
539b6cb4 193 return kFALSE;
194 }
195
16e24ca3 196 fTree->GetTree()->GetEntry(entry);
539b6cb4 197
198 if (fESD)
b8e8168f 199 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
539b6cb4 200
539b6cb4 201 return kTRUE;
202}
203
204void AliSelector::SlaveTerminate()
205{
206 // The SlaveTerminate() function is called after all entries or objects
207 // have been processed. When running with PROOF SlaveTerminate() is called
208 // on each slave server.
209
25db2d85 210 AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
211
539b6cb4 212 DeleteKinematicsFile();
539b6cb4 213}
214
215void AliSelector::Terminate()
216{
217 // The Terminate() function is the last function to be called during
218 // a query. It always runs on the client, it can be used to present
219 // the results graphically or save the results to file.
220
b8e8168f 221 AliDebug(AliLog::kDebug, "=========TERMINATE==========");
539b6cb4 222}
223
224TTree* AliSelector::GetKinematics()
225{
16e24ca3 226 // Returns kinematics tree corresponding to current ESD active in fTree
79ab56b9 227 // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
228 // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
229
539b6cb4 230 if (!fKineFile)
231 {
16e24ca3 232 if (!fTree->GetCurrentFile())
539b6cb4 233 return 0;
234
16e24ca3 235 TString fileName(fTree->GetCurrentFile()->GetName());
539b6cb4 236 fileName.ReplaceAll("AliESDs", "Kinematics");
237
dc740de4 238 AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
239
539b6cb4 240 fKineFile = TFile::Open(fileName);
241 if (!fKineFile)
242 return 0;
243 }
244
16e24ca3 245 return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
539b6cb4 246}
247
248void AliSelector::DeleteKinematicsFile()
249{
79ab56b9 250 //
251 // Closes the kinematics file and deletes the pointer.
252 //
253
539b6cb4 254 if (fKineFile)
255 {
256 fKineFile->Close();
257 delete fKineFile;
258 fKineFile = 0;
259 }
260}