Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSelectorEntries.cxx
Go to the documentation of this file.
1// @(#)root/treeplayer:$Id$
2// Author: Philippe Canal 09/06/2006
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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/** \class TSelectorEntries
13The class is derived from the ROOT class TSelector. For more
14information on the TSelector framework see
15$ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
16
17The following methods are defined in this file:
18
19 - Begin(): called every time a loop on the tree starts,
20 a convenient place to create your histograms.
21 - SlaveBegin(): called after Begin()
22 - Process(): called for each event, in this function you decide what
23 to read and fill your histograms.
24 - SlaveTerminate(): called at the end of the loop on the tree
25 - Terminate(): called at the end of the loop on the tree,
26 a convenient place to draw/fit your histograms.
27
28To use this file, try the following session on your Tree T:
29~~~{.cpp}
30 Root > T->Process("TSelectorEntries.C")
31 Root > T->Process("TSelectorEntries.C","some options")
32 Root > T->Process("TSelectorEntries.C+")
33~~~
34*/
35
36#include "TSelectorEntries.h"
37#include "TTree.h"
38#include "TTreeFormula.h"
39#include "TSelectorScalar.h"
40
41////////////////////////////////////////////////////////////////////////////////
42/// Default, constructor.
43
45 fOwnInput(false), fChain(tree), fSelect(nullptr), fSelectedRows(0), fSelectMultiple(false)
46{
47 if (selection && selection[0]) {
49 }
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Constructor.
54
56 fOwnInput(false), fChain(nullptr), fSelect(nullptr), fSelectedRows(0), fSelectMultiple(false)
57{
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Destructor.
63
65{
66 delete fSelect; fSelect = nullptr;
67 if (fOwnInput) {
68 fInput->Delete();
69 delete fInput;
70 fInput = nullptr;
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// The Begin() function is called at the start of the query.
76
78{
80 fChain = tree;
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// The SlaveBegin() function is called after the Begin() function.
85
87{
88 fChain = tree;
90
91 SetStatus(0);
92 fSelectedRows = 0;
93 TObject *selectObj = fInput->FindObject("selection");
94 const char *selection = selectObj ? selectObj->GetTitle() : "";
95
96 if (strlen(selection)) {
97 fSelect = new TTreeFormula("Selection",selection,fChain);
98 fSelect->SetQuickLoad(true);
99 if (!fSelect->GetNdim()) {delete fSelect; fSelect = nullptr; return; }
100 }
102
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Read entry.
108
113
114////////////////////////////////////////////////////////////////////////////////
115/// The Init() function is called when the selector needs to initialize
116/// a new tree or chain. Typically here the branch addresses and branch
117/// pointers of the tree will be set.
118/// It is normally not necessary to make changes to the generated
119/// code, but the routine can be extended by the user if needed.
120
122{
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// This function is called at the first entry of a new tree in a chain.
127
129{
131 return true;
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// The Process() function is called for each entry in the tree to be
136/// processed. The entry argument specifies which entry in the
137/// currently loaded tree is to be processed.
138/// It can be passed to either TSelectorEntries::GetEntry() or TBranch::GetEntry()
139/// to read either all or the required parts of the data.
140///
141/// This function should contain the "body" of the analysis. It can contain
142/// simple or elaborate selection criteria, run algorithms on the data
143/// of the event and typically fill histograms.
144///
145/// The processing can be stopped by calling Abort().
146///
147/// Use fStatus to set the return value of TTree::Process().
148///
149/// The return value is currently not used.
150
152{
153 if (!fSelectMultiple) {
154 if (fSelect) {
155 if ( fSelect->EvalInstance(0) ) {
157 }
158 } else {
160 }
161 } else if (fSelect) {
162 // Grab the array size of the formulas for this entry
164
165 // No data at all, let's move on to the next entry.
166 if (!ndata) return true;
167
168 // Calculate the first values
169 // Always call EvalInstance(0) to insure the loading
170 // of the branches.
171 if (fSelect->EvalInstance(0)) {
173 } else {
174 for (Int_t i=1;i<ndata;i++) {
175 if (fSelect->EvalInstance(i)) {
177 break;
178 }
179 }
180 }
181 }
182 return true;
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Set the selection expression.
187
189{
190 if (!fInput) {
191 fOwnInput = true;
192 fInput = new TList;
193 }
194 TNamed *cselection = (TNamed*)fInput->FindObject("selection");
195 if (!cselection) {
196 cselection = new TNamed("selection","");
198 }
199 cselection->SetTitle(selection);
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// The SlaveTerminate() function is called after all entries or objects
204
206{
207 fOutput->Add(new TSelectorScalar("fSelectedRows",fSelectedRows));
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// The Terminate() function is the last function to be called during
212/// a query. It always runs on the client, it can be used to present
213/// the results graphically or save the results to file.
214
216{
218 if (rows)
219 {
220 fSelectedRows = rows->GetVal();
221 } else {
222 Error("Terminate","fSelectedRows is missing in fOutput");
223 }
224}
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
virtual Int_t GetNdim() const
Definition TFormula.h:238
TObject * FindObject(const char *name) const override
Find object using its name.
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1072
void ResetBit(UInt_t f)
Definition TObject.h:201
bool Notify() override
This function is called at the first entry of a new tree in a chain.
~TSelectorEntries() override
Destructor.
TTree * fChain
! Pointer to the analyzed TTree or TChain
void Begin(TTree *tree) override
The Begin() function is called at the start of the query.
TSelectorEntries(TTree *tree=nullptr, const char *selection=nullptr)
Default, constructor.
void SlaveTerminate() override
The SlaveTerminate() function is called after all entries or objects.
TTreeFormula * fSelect
Pointer to selection formula.
bool fOwnInput
True if we created the input list.
virtual void SetSelection(const char *selection)
Set the selection expression.
bool fSelectMultiple
True if selection has a variable index.
void Init(TTree *tree) override
The Init() function is called when the selector needs to initialize a new tree or chain.
Long64_t fSelectedRows
Number of selected entries.
void SlaveBegin(TTree *tree) override
The SlaveBegin() function is called after the Begin() function.
void Terminate() override
The Terminate() function is the last function to be called during a query.
Int_t GetEntry(Long64_t entry, Int_t getall=0) override
Read entry.
bool Process(Long64_t entry) override
The Process() function is called for each entry in the tree to be processed.
Named scalar type, based on Long64_t, streamable, storable and mergeable.
virtual void SetStatus(Long64_t status)
Definition TSelector.h:67
TList * fInput
List of objects available during processing.
Definition TSelector.h:41
TSelectorList * fOutput
! List of objects created during processing
Definition TSelector.h:42
const char * GetOption() const override
Definition TSelector.h:57
Basic string class.
Definition TString.h:138
Used to pass a selection expression to the Tree drawing routine.
virtual Int_t GetMultiplicity() const
T EvalInstance(Int_t i=0, const char *stringStack[]=nullptr)
Evaluate this treeformula.
void SetQuickLoad(bool quick)
virtual void UpdateFormulaLeaves()
This function is called TTreePlayer::UpdateFormulaLeaves, itself called by TChain::LoadTree when a ne...
virtual Int_t GetNdata()
Return number of available instances in the formula.
A TTree represents a columnar dataset.
Definition TTree.h:89
virtual TTree * GetTree() const
Definition TTree.h:594
@ kForceRead
Definition TTree.h:285