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