1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
22 // The ESD is available as member fESD
24 // The following methods can be overrriden. Please do not forgot to call the base class function.
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
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.
38 // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
40 #include "AliSelector.h"
47 #include <TFriendElement.h>
51 #include <TTimeStamp.h>
58 AliSelector::AliSelector() :
65 // Constructor. Initialization of pointers
69 AliSelector::~AliSelector()
76 fTree->ResetBranchAddresses();
85 void AliSelector::CheckOptions()
87 // checks the option string for the debug flag
89 AliLog::SetClassDebugLevel(ClassName(), AliLog::kInfo);
91 TString option = GetOption();
93 if (option.Contains("moredebug"))
95 printf("Enabling verbose debug mode for %s\n", ClassName());
96 AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug+1);
97 AliInfo(Form("Called with option %s.", option.Data()));
99 else if (option.Contains("debug"))
101 printf("Enabling debug mode for %s\n", ClassName());
102 AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug);
103 AliInfo(Form("Called with option %s.", option.Data()));
107 void AliSelector::Begin(TTree*)
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).
115 AliDebug(AliLog::kDebug, "============BEGIN===========");
118 void AliSelector::SlaveBegin(TTree* tree)
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).
126 AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
127 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
128 AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
134 void AliSelector::Init(TTree *tree)
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.
142 AliDebug(AliLog::kDebug, "=========Init==========");
148 AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
152 // Set branch address
153 fTree->SetBranchAddress("ESD", &fESD);
155 AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
158 Bool_t AliSelector::Notify()
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
167 AliDebug(AliLog::kDebug, "=========NOTIFY==========");
168 AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
169 AliDebug(AliLog::kDebug, Form("Time: %s", TTimeStamp(time(0)).AsString()));
174 TFile *f = fTree->GetCurrentFile();
177 AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
180 AliDebug(AliLog::kError, "fTree->GetCurrentFile() is 0");
184 AliDebug(AliLog::kError, "fTree not available");
190 Bool_t AliSelector::Process(Long64_t entry)
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.
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.
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).
210 AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
214 AliDebug(AliLog::kError, "ERROR: fTree is 0.");
218 fTree->GetTree()->GetEntry(entry);
221 AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
226 void AliSelector::SlaveTerminate()
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.
232 AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
235 void AliSelector::Terminate()
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.
241 AliDebug(AliLog::kDebug, "=========TERMINATE==========");