]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Reve/TTreeTools.cxx
Record changes.
[u/mrichter/AliRoot.git] / EVE / Reve / TTreeTools.cxx
1 // $Header$
2
3 //__________________________________________________________________________
4 // TTreeTools
5 //
6 // Collection of classes for TTree interaction.
7
8 #include "TTreeTools.h"
9 #include <TTree.h>
10 #include <TTreeFormula.h>
11
12 /**************************************************************************/
13 /**************************************************************************/
14
15 ClassImp(TSelectorToEventList)
16
17 TSelectorToEventList::TSelectorToEventList(TEventList* evl, const Text_t* sel) :
18   TSelectorDraw(), fEvList(evl)
19 {
20   fInput.Add(new TNamed("varexp", ""));
21   fInput.Add(new TNamed("selection", sel));
22   SetInputList(&fInput);
23 }
24
25 Bool_t TSelectorToEventList::Process(Long64_t entry)
26 {
27   if(GetSelect()->EvalInstance(0) != 0)
28     fEvList->Enter(entry);
29   return kTRUE;
30 }
31
32 /**************************************************************************/
33 /**************************************************************************/
34
35 ClassImp(TTreeQuery)
36
37 Int_t TTreeQuery::Select(TTree* t, const Text_t* selection)
38 {
39   TSelectorToEventList sel(this, selection);
40   t->Process(&sel, "goff");
41   return GetN();
42 }
43
44 /**************************************************************************/
45 // TPointSelectorConsumer, TPointSelector
46 /**************************************************************************/
47
48 ClassImp(TPointSelectorConsumer)
49 ClassImp(TPointSelector)
50
51 TPointSelector::TPointSelector(TTree* t,
52                                TPointSelectorConsumer* c,
53                                const Text_t* vexp, const Text_t* sel) :
54   TSelectorDraw(),
55
56   fTree      (t),
57   fConsumer  (c),
58   fVarexp    (vexp),
59   fSelection (sel),
60   fSubIdExp  (),
61   fSubIdNum  (0)
62 {
63   SetInputList(&fInput);
64 }
65
66 Long64_t TPointSelector::Select(const Text_t* selection)
67 {
68   TString var(fVarexp);
69   if (fSubIdExp.IsNull()) {
70     fSubIdNum = 0;
71   } else {
72     fSubIdNum = fSubIdExp.CountChar(':') + 1;
73     var += ":" + fSubIdExp;
74   }
75
76   TString sel;
77   if (selection != 0)
78     sel = selection;
79   else
80     sel = fSelection;
81
82   fInput.Delete();
83   fInput.Add(new TNamed("varexp",    var.Data()));
84   fInput.Add(new TNamed("selection", sel.Data()));
85
86   if (fConsumer)
87     fConsumer->InitFill(fSubIdNum);
88
89   // 'para' option -> hack allowing arbitrary dimensions.
90   if(fTree)
91     fTree->Process(this, "goff para");
92
93   return fSelectedRows;
94 }
95
96 Long64_t TPointSelector::Select(TTree* t, const Text_t* selection)
97 {
98   fTree = t;
99   return Select(selection);
100 }
101
102 void TPointSelector::TakeAction()
103 {
104   fSelectedRows += fNfill;
105   // printf("TPointSelector::TakeAction nfill=%d, nall=%lld\n", fNfill, fSelectedRows);
106   if (fConsumer) {
107     fConsumer->TakeAction(this);
108   }
109 }