ROOT  6.06/09
Reference Guide
TSelEvent.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: Sangsu Ryu 22/06/2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TSelEvent //
15 // //
16 // PROOF selector for I/O benchmark test. //
17 // For I/O benchmark, event files are read in and histograms are filled.//
18 // For memory clean-up, dedicated files large enough to clean up memory //
19 // cache on the machine are read in. Or memory clean-up can be //
20 // accompolished by system call on Linux machine inside SlaveBegin(..) //
21 // which should be much faster the reading in large files. //
22 // //
23 //////////////////////////////////////////////////////////////////////////
24 
25 #define TSelEvent_cxx
26 
27 #include "TSelEvent.h"
28 #include <TH1F.h>
29 #include <TStyle.h>
30 #include "TParameter.h"
31 #include "TProofBenchTypes.h"
32 #include "TTree.h"
33 #include "TCanvas.h"
34 #include "TFileInfo.h"
35 #include "THashList.h"
36 #include "TClonesArray.h"
37 #include "TRefArray.h"
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <unistd.h>
41 #include "TSystem.h"
42 #include "TROOT.h"
43 
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 /// Constructor
48 
50  : fReadType(0), fDebug(kFALSE), fCHist(0), fPtHist(0),
51  fNTracksHist(0), fEventName(0), fTracks(0), fHighPt(0), fMuons(0),
52  fH(0), b_event_fType(0), b_fEventName(0), b_event_fNtrack(0), b_event_fNseg(0),
53  b_event_fNvertex(0), b_event_fFlag(0), b_event_fTemperature(0),
54  b_event_fMeasures(0), b_event_fMatrix(0), b_fClosestDistance(0),
55  b_event_fEvtHdr(0), b_fTracks(0), b_fHighPt(0), b_fMuons(0),
56  b_event_fLastTrack(0), b_event_fWebHistogram(0), b_fH(0),
57  b_event_fTriggerBits(0), b_event_fIsValid(0)
58 {
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Constructor
63 
65  : fReadType(0), fDebug(kFALSE), fCHist(0), fPtHist(0),
66  fNTracksHist(0), fEventName(0), fTracks(0), fHighPt(0), fMuons(0),
67  fH(0), b_event_fType(0), b_fEventName(0), b_event_fNtrack(0), b_event_fNseg(0),
68  b_event_fNvertex(0), b_event_fFlag(0), b_event_fTemperature(0),
69  b_event_fMeasures(0), b_event_fMatrix(0), b_fClosestDistance(0),
70  b_event_fEvtHdr(0), b_fTracks(0), b_fHighPt(0), b_fMuons(0),
71  b_event_fLastTrack(0), b_event_fWebHistogram(0), b_fH(0),
72  b_event_fTriggerBits(0), b_event_fIsValid(0)
73 {
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// The Begin() function is called at the start of the query.
78 /// When running with PROOF Begin() is only called on the client.
79 /// The tree argument is deprecated (on PROOF 0 is passed).
80 
82 {
83  TString option = GetOption();
84 
85  //get parameters
86 
87  Bool_t found_readtype=kFALSE;
88  Bool_t found_debug=kFALSE;
89 
90  TIter nxt(fInput);
91  TString sinput;
92  TObject *obj;
93  while ((obj = nxt())){
94  sinput=obj->GetName();
95  //Info("Begin", "name=%s", sinput.Data());
96  if (sinput.Contains("PROOF_Benchmark_ReadType")){
97  if ((fReadType = dynamic_cast<TPBReadType *>(obj))) found_readtype = kTRUE;
98  continue;
99  }
100  if (sinput.Contains("PROOF_BenchmarkDebug")){
101  TParameter<Int_t>* a=dynamic_cast<TParameter<Int_t>*>(obj);
102  if (a){
103  fDebug= a->GetVal();
104  found_debug=kTRUE;
105  //Info("Begin", "PROOF_BenchmarkDebug=%d", fDebug);
106  }
107  else{
108  Error("Begin", "PROOF_BenchmarkDebug not type TParameter<Int_t>*");
109  }
110  continue;
111  }
112  }
113 
114  if (!found_readtype){
116  Warning("Begin", "PROOF_Benchmark_ReadType not found; using default: %d",
117  fReadType->GetType());
118  }
119  if (!found_debug){
120  Warning("Begin", "PROOF_BenchmarkDebug not found; using default: %d",
121  fDebug);
122  }
123 }
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// The SlaveBegin() function is called after the Begin() function.
127 /// When running with PROOF SlaveBegin() is called on each slave server.
128 /// The tree argument is deprecated (on PROOF 0 is passed).
129 
131 {
132  Init(tree);
133 
134  TString option = GetOption();
135 
136  Bool_t found_readtype=kFALSE;
137  Bool_t found_debug=kFALSE;
138 
139  //fInput->Print("A");
140  TIter nxt(fInput);
141  TString sinput;
142  TObject *obj;
143  while ((obj = nxt())){
144  sinput=obj->GetName();
145  //Info("SlaveBegin", "name=%s", sinput.Data());
146  if (sinput.Contains("PROOF_Benchmark_ReadType")){
147  if ((fReadType = dynamic_cast<TPBReadType *>(obj))) found_readtype = kTRUE;
148  continue;
149  }
150  if (sinput.Contains("PROOF_BenchmarkDebug")){
151  TParameter<Int_t>* a=dynamic_cast<TParameter<Int_t>*>(obj);
152  if (a){
153  fDebug= a->GetVal();
154  found_debug=kTRUE;
155  //Info("SlaveBegin", "PROOF_BenchmarkDebug=%d", fDebug);
156  }
157  else{
158  Error("SlaveBegin", "PROOF_BenchmarkDebug not type TParameter"
159  "<Int_t>*");
160  }
161  continue;
162  }
163  }
164 
165  if (!found_readtype){
167  Warning("SlaveBegin", "PROOF_Benchmark_ReadType not found; using default: %d",
168  fReadType->GetType());
169  }
170  if (!found_debug){
171  Warning("SlaveBegin", "PROOF_BenchmarkDebug not found; using default: %d",
172  fDebug);
173  }
174 
175  fPtHist = new TH1F("pt_dist","p_{T} Distribution", 100, 0, 5);
176  fPtHist->SetDirectory(0);
177  fPtHist->GetXaxis()->SetTitle("p_{T}");
178  fPtHist->GetYaxis()->SetTitle("dN/p_{T}dp_{T}");
179 
180  fNTracksHist = new TH1F("ntracks_dist","N_{Tracks} per Event"
181  " Distribution", 100, 50, 150);
182  //enable rebinning
185  fNTracksHist->GetXaxis()->SetTitle("N_{Tracks}");
186  fNTracksHist->GetYaxis()->SetTitle("N_{Events}");
187 }
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 /// The Process() function is called for each entry in the tree (or possibly
191 /// keyed object in the case of PROOF) to be processed. The entry argument
192 /// specifies which entry in the currently loaded tree is to be processed.
193 /// It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
194 /// to read either all or the required parts of the data. When processing
195 /// keyed objects with PROOF, the object is already loaded and is available
196 /// via the fObject pointer.
197 ///
198 /// This function should contain the "body" of the analysis. It can contain
199 /// simple or elaborate selection criteria, run algorithms on the data
200 /// of the event and typically fill histograms.
201 
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 fChain is the pointer to the TChain being processed,
208  // use fChain->GetTree()->GetEntry(entry).
209 
211  switch (fReadType->GetType()){
213  // Full read
214  fChain->GetTree()->GetEntry(entry);
216 
217  for(Int_t j=0;j<fTracks->GetEntries();j++){
218  Track* curtrack = dynamic_cast<Track*>(fTracks->At(j));
219  fPtHist->Fill(curtrack->GetPt(),1./curtrack->GetPt());
220  }
221  fTracks->Clear("C");
222  break;
224  // Partial read
225  b_event_fNtrack->GetEntry(entry);
226 
228 
229  if (fNtrack>0) {
230  b_fTracks->GetEntry(entry);
231  for(Int_t j=0;j<fTracks->GetEntries();j++){
232  Track* curtrack = dynamic_cast<Track*>(fTracks->At(j));
233  fPtHist->Fill(curtrack->GetPt(),1./curtrack->GetPt());
234  }
235  fTracks->Clear("C");
236  }
237  break;
239  // No read
240  break;
241  default:
242  Error("Process", "Read type not supported; %d", fReadType->GetType());
243  return kFALSE;
244  break;
245  }
246  }
247  return kTRUE;
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// The SlaveTerminate() function is called after all entries or objects
252 /// have been processed. When running with PROOF SlaveTerminate() is called
253 /// on each slave server.
254 
256 {
257 }
258 
259 ////////////////////////////////////////////////////////////////////////////////
260 /// The Terminate() function is the last function to be called during
261 /// a query. It always runs on the client, it can be used to present
262 /// the results graphically or save the results to file.
263 
265 {
266 }
virtual const char * GetOption() const
Definition: TSelector.h:65
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
long long Long64_t
Definition: RtypesCore.h:69
TTree * fChain
Definition: TSelEvent.h:66
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8266
TBranch * b_fTracks
Definition: TSelEvent.h:102
TPBReadType * fReadType
Definition: TSelEvent.h:56
virtual void Begin(TTree *)
The Begin() function is called at the start of the query.
Definition: TSelEvent.cxx:81
THist< 1, float > TH1F
Definition: THist.h:315
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition: TTree.cxx:5163
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void Init(TTree *tree)
virtual void SlaveTerminate()
The SlaveTerminate() function is called after all entries or objects have been processed.
Definition: TSelEvent.cxx:255
TClonesArray * fTracks
Definition: TSelEvent.h:81
virtual void SlaveBegin(TTree *tree)
The SlaveBegin() function is called after the Begin() function.
Definition: TSelEvent.cxx:130
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
virtual void Clear(Option_t *option="")
Clear the clones array.
Named parameter, streamable and storable.
Definition: TParameter.h:49
TH1F * fPtHist
Definition: TSelEvent.h:61
EReadType GetType() const
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
Definition: TBranch.cxx:1198
TAxis * GetYaxis()
Definition: TH1.h:320
Int_t fNtrack
Definition: TSelEvent.h:72
Long64_t entry
ClassImp(TSelEvent) TSelEvent
Constructor.
Definition: TSelEvent.cxx:44
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
virtual Bool_t Process(Long64_t entry)
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
Definition: TSelEvent.cxx:202
TSelEvent()
Constructor.
Definition: TSelEvent.cxx:64
virtual TTree * GetTree() const
Definition: TTree.h:432
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:493
virtual UInt_t SetCanExtend(UInt_t extendBitMask)
make the histogram axes extendable / not extendable according to the bit mask returns the previous bi...
Definition: TH1.cxx:6211
Mother of all ROOT objects.
Definition: TObject.h:58
TList * fInput
Current object if processing object (vs. TTree)
Definition: TSelector.h:49
virtual void Terminate()
The Terminate() function is the last function to be called during a query.
Definition: TSelEvent.cxx:264
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
TH1F * fNTracksHist
Definition: TSelEvent.h:62
TBranch * b_event_fNtrack
Definition: TSelEvent.h:93
A TTree object has a header with a name and a title.
Definition: TTree.h:94
const AParamType & GetVal() const
Definition: TParameter.h:77
TObject * At(Int_t idx) const
Definition: TObjArray.h:167
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TObject * obj
Bool_t fDebug
Definition: TSelEvent.h:57
TAxis * GetXaxis()
Definition: TH1.h:319
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904