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