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