]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliSelector.cxx
Modifying processing of Pressure sensors:
[u/mrichter/AliRoot.git] / STEER / AliSelector.cxx
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 ClassImp(AliSelector)
57
58 AliSelector::AliSelector() :
59   TSelector(),
60   fTree(0),
61   fESD(0),
62   fCountFiles(0)
63 {
64   //
65   // Constructor. Initialization of pointers
66   //
67 }
68
69 AliSelector::~AliSelector()
70 {
71   //
72   // Destructor
73   //
74
75  if (fTree)
76    fTree->ResetBranchAddresses();
77
78  if (fESD)
79  {
80    delete fESD;
81    fESD = 0;
82  }
83 }
84
85 void AliSelector::CheckOptions()
86 {
87   // checks the option string for the debug flag
88
89   AliLog::SetClassDebugLevel(ClassName(), AliLog::kInfo);
90
91   TString option = GetOption();
92
93   if (option.Contains("moredebug"))
94   {
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()));
98   }
99   else if (option.Contains("debug"))
100   {
101     printf("Enabling debug mode for %s\n", ClassName());
102     AliLog::SetClassDebugLevel(ClassName(), AliLog::kDebug);
103     AliInfo(Form("Called with option %s.", option.Data()));
104   }
105 }
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   CheckOptions();
114
115   AliDebug(AliLog::kDebug, "============BEGIN===========");
116 }
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   CheckOptions();
125
126   AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
127   AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
128   AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
129
130   if (tree != 0)
131     Init(tree);
132 }
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   AliDebug(AliLog::kDebug, "=========Init==========");
143
144   fTree = tree;
145
146   if (fTree == 0)
147   {
148     AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
149     return;
150   }
151
152   // Set branch address
153   fTree->SetBranchAddress("ESD", &fESD);
154   if (fESD != 0)
155     AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
156 }
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   AliDebug(AliLog::kDebug, "=========NOTIFY==========");
168   AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
169   AliDebug(AliLog::kDebug, Form("Time: %s", TTimeStamp(time(0)).AsString()));
170
171   ++fCountFiles;
172   if (fTree)
173   {
174     TFile *f = fTree->GetCurrentFile();
175     if (f)
176     {
177       AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
178     }
179     else
180       AliDebug(AliLog::kError, "fTree->GetCurrentFile() is 0");
181   }
182   else
183   {
184     AliDebug(AliLog::kError, "fTree not available");
185   }
186
187   return kTRUE;
188 }
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   AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
211
212   if (!fTree)
213   {
214     AliDebug(AliLog::kError, "ERROR: fTree is 0.");
215     return kFALSE;
216   }
217
218   fTree->GetTree()->GetEntry(entry);
219
220   if (fESD)
221     AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
222
223   return kTRUE;
224 }
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   AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
233 }
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   AliDebug(AliLog::kDebug, "=========TERMINATE==========");
242 }