Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : /* $Id$ */
17 :
18 : // Selector base class for analysis based on ESD
19 : // Please derive your selector-based analysis from this class, if you just want to use
20 : // information from the ESD.
21 : //
22 : // The ESD is available as member fESD
23 : //
24 : // The following methods can be overrriden. Please do not forgot to call the base class function.
25 : //
26 : // Begin(): called everytime a loop on the tree starts,
27 : // a convenient place to create your histograms.
28 : // SlaveBegin(): called after Begin(), when on PROOF called only on the
29 : // slave servers.
30 : // Init(): called for each new tree. Enable/Disable branches here.
31 : // Process(): called for each event, in this function you decide what
32 : // to read and fill your histograms.
33 : // SlaveTerminate: called at the end of the loop on the tree, when on PROOF
34 : // called only on the slave servers.
35 : // Terminate(): called at the end of the loop on the tree,
36 : // a convenient place to draw/fit your histograms.
37 : //
38 : // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
39 :
40 : #include "AliSelector.h"
41 :
42 : #include <TStyle.h>
43 : #include <TSystem.h>
44 : #include <TCanvas.h>
45 : #include <TRegexp.h>
46 : #include <TTime.h>
47 : #include <TFriendElement.h>
48 : #include <TTree.h>
49 : #include <TChain.h>
50 : #include <TFile.h>
51 : #include <TTimeStamp.h>
52 :
53 : #include "AliLog.h"
54 : #include "AliESD.h"
55 :
56 172 : ClassImp(AliSelector)
57 :
58 : AliSelector::AliSelector() :
59 0 : TSelector(),
60 0 : fTree(0),
61 0 : fESD(0),
62 0 : fCountFiles(0)
63 0 : {
64 : //
65 : // Constructor. Initialization of pointers
66 : //
67 0 : }
68 :
69 : AliSelector::~AliSelector()
70 0 : {
71 : //
72 : // Destructor
73 : //
74 :
75 0 : if (fTree)
76 0 : fTree->ResetBranchAddresses();
77 :
78 0 : if (fESD)
79 : {
80 0 : delete fESD;
81 0 : fESD = 0;
82 0 : }
83 0 : }
84 :
85 : void AliSelector::CheckOptions()
86 : {
87 : // checks the option string for the debug flag
88 :
89 0 : AliLog::SetClassDebugLevel(ClassName(), AliLog::kInfo);
90 :
91 0 : TString option = GetOption();
92 :
93 0 : if (option.Contains("moredebug"))
94 : {
95 0 : printf("Enabling verbose debug mode for %s\n", ClassName());
96 0 : AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug+1);
97 0 : AliInfo(Form("Called with option %s.", option.Data()));
98 : }
99 0 : else if (option.Contains("debug"))
100 : {
101 0 : printf("Enabling debug mode for %s\n", ClassName());
102 0 : AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug);
103 0 : AliInfo(Form("Called with option %s.", option.Data()));
104 : }
105 0 : }
106 :
107 : void AliSelector::Begin(TTree*)
108 : {
109 : // The Begin() function is called at the start of the query.
110 : // When running with PROOF Begin() is only called on the client.
111 : // The tree argument is deprecated (on PROOF 0 is passed).
112 :
113 0 : CheckOptions();
114 :
115 0 : AliDebug(AliLog::kDebug, "============BEGIN===========");
116 0 : }
117 :
118 : void AliSelector::SlaveBegin(TTree* tree)
119 : {
120 : // The SlaveBegin() function is called after the Begin() function.
121 : // When running with PROOF SlaveBegin() is called on each slave server.
122 : // The tree argument is deprecated (on PROOF 0 is passed).
123 :
124 0 : CheckOptions();
125 :
126 0 : AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
127 0 : AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
128 0 : AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
129 :
130 0 : if (tree != 0)
131 0 : Init(tree);
132 0 : }
133 :
134 : void AliSelector::Init(TTree *tree)
135 : {
136 : // The Init() function is called when the selector needs to initialize
137 : // a new tree or chain. Typically here the branch addresses of the tree
138 : // will be set. It is normaly not necessary to make changes to the
139 : // generated code, but the routine can be extended by the user if needed.
140 : // Init() will be called many times when running with PROOF.
141 :
142 0 : AliDebug(AliLog::kDebug, "=========Init==========");
143 :
144 0 : fTree = tree;
145 :
146 0 : if (fTree == 0)
147 : {
148 0 : AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
149 : return;
150 : }
151 :
152 : // Set branch address
153 0 : fTree->SetBranchAddress("ESD", &fESD);
154 0 : if (fESD != 0)
155 0 : AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
156 0 : }
157 :
158 : Bool_t AliSelector::Notify()
159 : {
160 : // The Notify() function is called when a new file is opened. This
161 : // can be either for a new TTree in a TChain or when when a new TTree
162 : // is started when using PROOF. Typically here the branch pointers
163 : // will be retrieved. It is normaly not necessary to make changes
164 : // to the generated code, but the routine can be extended by the
165 : // user if needed.
166 :
167 0 : AliDebug(AliLog::kDebug, "=========NOTIFY==========");
168 0 : AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
169 0 : AliDebug(AliLog::kDebug, Form("Time: %s", TTimeStamp(time(0)).AsString()));
170 :
171 0 : ++fCountFiles;
172 0 : if (fTree)
173 : {
174 0 : TFile *f = fTree->GetCurrentFile();
175 0 : if (f)
176 : {
177 0 : AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
178 : }
179 : else
180 0 : AliDebug(AliLog::kError, "fTree->GetCurrentFile() is 0");
181 0 : }
182 : else
183 : {
184 0 : AliDebug(AliLog::kError, "fTree not available");
185 : }
186 :
187 0 : return kTRUE;
188 0 : }
189 :
190 : Bool_t AliSelector::Process(Long64_t entry)
191 : {
192 : // The Process() function is called for each entry in the tree (or possibly
193 : // keyed object in the case of PROOF) to be processed. The entry argument
194 : // specifies which entry in the currently loaded tree is to be processed.
195 : // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
196 : // to read either all or the required parts of the data. When processing
197 : // keyed objects with PROOF, the object is already loaded and is available
198 : // via the fObject pointer.
199 : //
200 : // This function should contain the "body" of the analysis. It can contain
201 : // simple or elaborate selection criteria, run algorithms on the data
202 : // of the event and typically fill histograms.
203 :
204 : // WARNING when a selector is used with a TChain, you must use
205 : // the pointer to the current TTree to call GetEntry(entry).
206 : // The entry is always the local entry number in the current tree.
207 : // Assuming that fTree is the pointer to the TChain being processed,
208 : // use fTree->GetTree()->GetEntry(entry).
209 :
210 0 : AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
211 :
212 0 : if (!fTree)
213 : {
214 0 : AliDebug(AliLog::kError, "ERROR: fTree is 0.");
215 0 : return kFALSE;
216 : }
217 :
218 0 : fTree->GetTree()->GetEntry(entry);
219 :
220 0 : if (fESD)
221 0 : AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
222 :
223 0 : return kTRUE;
224 0 : }
225 :
226 : void AliSelector::SlaveTerminate()
227 : {
228 : // The SlaveTerminate() function is called after all entries or objects
229 : // have been processed. When running with PROOF SlaveTerminate() is called
230 : // on each slave server.
231 :
232 0 : AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
233 0 : }
234 :
235 : void AliSelector::Terminate()
236 : {
237 : // The Terminate() function is the last function to be called during
238 : // a query. It always runs on the client, it can be used to present
239 : // the results graphically or save the results to file.
240 :
241 0 : AliDebug(AliLog::kDebug, "=========TERMINATE==========");
242 0 : }
|