Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
REveTreeTools.cxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, 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 // TTreeTools
14 //
15 // Collection of classes for TTree interaction.
16 
17 #include <ROOT/REveTreeTools.hxx>
18 
19 #include "TTree.h"
20 #include "TTreeFormula.h"
21 
22 using namespace ROOT::Experimental;
23 namespace REX = ROOT::Experimental;
24 
25 /** \class REveSelectorToEventList
26 \ingroup REve
27 TSelector that stores entry numbers of matching TTree entries into
28 an event-list.
29 */
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Constructor.
33 
34 REveSelectorToEventList::REveSelectorToEventList(TEventList* evl, const char* sel) :
35  TSelectorDraw(), fEvList(evl)
36 {
37  fInput.Add(new TNamed("varexp", ""));
38  fInput.Add(new TNamed("selection", sel));
39  SetInputList(&fInput);
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Process entry.
44 
45 Bool_t REveSelectorToEventList::Process(Long64_t entry)
46 {
47  if(GetSelect()->EvalInstance(0) != 0)
48  fEvList->Enter(entry);
49  return kTRUE;
50 }
51 
52 /** \class REvePointSelectorConsumer
53 \ingroup REve
54 REvePointSelectorConsumer is a virtual base for classes that can be
55 filled from TTree data via the REvePointSelector class.
56 */
57 
58 /** \class REvePointSelector
59 \ingroup REve
60 REvePointSelector is a sub-class of TSelectorDraw for direct
61 extraction of point-like data from a Tree.
62 */
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 /// Constructor.
66 
67 REvePointSelector::REvePointSelector(TTree* t,
68  REvePointSelectorConsumer* c,
69  const char* vexp, const char* sel) :
70  TSelectorDraw(),
71 
72  fTree (t),
73  fConsumer (c),
74  fVarexp (vexp),
75  fSelection (sel),
76  fSubIdExp (),
77  fSubIdNum (0)
78 {
79  SetInputList(&fInput);
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Process the tree, select points matching 'selection'.
84 
85 Long64_t REvePointSelector::Select(const char* selection)
86 {
87  TString var(fVarexp);
88  if (fSubIdExp.IsNull()) {
89  fSubIdNum = 0;
90  } else {
91  fSubIdNum = fSubIdExp.CountChar(':') + 1;
92  var += ":" + fSubIdExp;
93  }
94 
95  TString sel;
96  if (selection)
97  sel = selection;
98  else
99  sel = fSelection;
100 
101  fInput.Delete();
102  fInput.Add(new TNamed("varexp", var.Data()));
103  fInput.Add(new TNamed("selection", sel.Data()));
104 
105  if (fConsumer)
106  fConsumer->InitFill(fSubIdNum);
107 
108  if (fTree)
109  fTree->Process(this, "goff");
110 
111  return fSelectedRows;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Process tree 't', select points matching 'selection'.
116 
117 Long64_t REvePointSelector::Select(TTree *t, const char *selection)
118 {
119  fTree = t;
120  return Select(selection);
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Callback from tree-player after a chunk of data has been processed.
125 /// This is forwarded to the current point-consumer.
126 
127 void REvePointSelector::TakeAction()
128 {
129  fSelectedRows += fNfill;
130  // printf("REvePointSelector::TakeAction nfill=%d, nall=%lld\n", fNfill, fSelectedRows);
131  if (fConsumer) {
132  fConsumer->TakeAction(this);
133  }
134 }