Logo ROOT  
Reference Guide
TBranchProxyDirector.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Philippe Canal 13/05/2003
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun, Fons Rademakers and al. *
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 /** TBranchProxyDirector
13 This class is used to 'drive' and hold a serie of TBranchProxy objects
14 which represent and give access to the content of TTree object.
15 This is intended to be used as part of a generate Selector class
16 which will hold the directory and its associate
17 */
18 
19 #include "TBranchProxyDirector.h"
20 #include "TBranchProxy.h"
21 #include "TFriendProxy.h"
22 #include "TTree.h"
23 #include "TEnv.h"
24 #include "TH1F.h"
25 #include "TVirtualPad.h"
26 #include "TList.h"
27 
28 #include <algorithm>
29 
31 
32 namespace ROOT {
33 namespace Internal {
34 
35  // Helper function to call Reset on each TBranchProxy
36  void NotifyDirected(Detail::TBranchProxy *x) { x->Notify(); }
37 
38  // Helper function to call SetReadEntry on all TFriendProxy
39  void ResetReadEntry(TFriendProxy *fp) { fp->ResetReadEntry(); }
40 
41  // Helper class to call Update on all TFriendProxy
42  struct Update {
43  Update(TTree *newtree) : fNewTree(newtree) {}
44  TTree *fNewTree;
45  void operator()(TFriendProxy *x) { x->Update(fNewTree); }
46  };
47 
48 
50  fTree(tree),
51  fEntry(i)
52  {
53  // Simple constructor
54  }
55 
57  // cint has a problem casting int to long long
58  fTree(tree),
59  fEntry(i)
60  {
61  // Simple constructor
62  }
63 
65 
66  // Attach a TBranchProxy object to this director. The director just
67  // 'remembers' this BranchProxy and does not own it. It will be use
68  // to apply Tree wide operation (like reseting).
69  fDirected.push_back(p);
70  }
71 
73 
74  // Attach a TFriendProxy object to this director. The director just
75  // 'remembers' this BranchProxy and does not own it. It will be use
76  // to apply Tree wide operation (like reseting).
77  fFriends.push_back(p);
78  }
79 
80  TH1F* TBranchProxyDirector::CreateHistogram(const char *options) {
81  // Create a temporary 1D histogram.
82 
83  Int_t nbins = gEnv->GetValue("Hist.Binning.1D.x",100);
84  Double_t vmin=0, vmax=0;
85  Double_t xmin=0, xmax=0;
86  Bool_t canExtend = kTRUE;
87  TString opt( options );
88  Bool_t optSame = opt.Contains("same");
89  if (optSame) canExtend = kFALSE;
90 
91  if (gPad && optSame) {
92  TListIter np(gPad->GetListOfPrimitives());
93  TObject *op;
94  TH1 *oldhtemp = 0;
95  while ((op = np()) && !oldhtemp) {
96  if (op->InheritsFrom(TH1::Class())) oldhtemp = (TH1 *)op;
97  }
98  if (oldhtemp) {
99  nbins = oldhtemp->GetXaxis()->GetNbins();
100  vmin = oldhtemp->GetXaxis()->GetXmin();
101  vmax = oldhtemp->GetXaxis()->GetXmax();
102  } else {
103  vmin = gPad->GetUxmin();
104  vmax = gPad->GetUxmax();
105  }
106  } else {
107  vmin = xmin;
108  vmax = xmax;
109  if (xmin < xmax) canExtend = kFALSE;
110  }
111  TH1F *hist = new TH1F("htemp","htemp",nbins,vmin,vmax);
112  hist->SetLineColor(fTree->GetLineColor());
113  hist->SetLineWidth(fTree->GetLineWidth());
114  hist->SetLineStyle(fTree->GetLineStyle());
115  hist->SetFillColor(fTree->GetFillColor());
116  hist->SetFillStyle(fTree->GetFillStyle());
117  hist->SetMarkerStyle(fTree->GetMarkerStyle());
118  hist->SetMarkerColor(fTree->GetMarkerColor());
119  hist->SetMarkerSize(fTree->GetMarkerSize());
120  if (canExtend) hist->SetCanExtend(TH1::kAllAxes);
121  hist->GetXaxis()->SetTitle("var");
122  hist->SetBit(kCanDelete);
123  hist->SetDirectory(0);
124 
125  if (opt.Length() && opt.Contains("e")) hist->Sumw2();
126  return hist;
127  }
128 
130 
131  // Set the BranchProxy to be looking at a new tree.
132  // Reset all.
133  // Return the old tree.
134 
135  TTree* oldtree = fTree;
136  fTree = newtree;
137  if(!Notify()) return nullptr;
138  return oldtree;
139  }
140 
142  fEntry = -1;
143  bool retVal = true;
144  for_each(fDirected.begin(),fDirected.end(),NotifyDirected);
145  for (auto brProxy : fDirected) {
146  retVal = retVal && brProxy->Notify();
147  }
148  Update update(fTree);
149  for_each(fFriends.begin(),fFriends.end(),update);
150  return retVal;
151  }
152 
153 } // namespace Internal
154 } // namespace ROOT
ROOT::Internal::TBranchProxyDirector::Notify
Bool_t Notify()
Definition: TBranchProxyDirector.cxx:153
ROOT::Internal::TBranchProxyDirector
Definition: TBranchProxyDirector.h:35
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TH1F.h
kCanDelete
@ kCanDelete
Definition: TObject.h:339
gEnv
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
tree
Definition: tree.py:1
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
xmax
float xmax
Definition: THbookFile.cxx:95
ROOT::Internal::TBranchProxyDirector::TBranchProxyDirector
TBranchProxyDirector(const TBranchProxyDirector &)
Definition: TBranchProxyDirector.h:44
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TTree
Definition: TTree.h:79
Int_t
int Int_t
Definition: RtypesCore.h:45
TH1::SetCanExtend
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:6290
x
Double_t x[n]
Definition: legend1.C:17
operator()
TRObject operator()(const T1 &t1) const
Definition: TRFunctionImport__oprtr.h:14
TList.h
TEnv::GetValue
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:492
ROOT::Internal::TBranchProxyDirector::fTree
TTree * fTree
Definition: TBranchProxyDirector.h:38
TBranchProxy.h
TEnv.h
TTree.h
TString
Definition: TString.h:136
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
ROOT::Internal::TBranchProxyDirector::SetTree
TTree * SetTree(TTree *newtree)
Definition: TBranchProxyDirector.cxx:141
bool
TListIter
Definition: TList.h:197
TH1::kAllAxes
@ kAllAxes
Definition: TH1.h:74
update
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
Definition: RooAdaptiveGaussKronrodIntegrator1D.cxx:652
ROOT::Internal::TBranchProxyDirector::fEntry
Long64_t fEntry
Definition: TBranchProxyDirector.h:39
TAxis::GetXmin
Double_t GetXmin() const
Definition: TAxis.h:133
xmin
float xmin
Definition: THbookFile.cxx:95
TObject::SetBit
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:696
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
ROOT::Internal::TFriendProxy
Definition: TFriendProxy.h:22
TVirtualPad.h
TH1::SetDirectory
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:8392
TBranchProxyDirector.h
ROOT::Internal::TBranchProxyDirector::Attach
void Attach(Detail::TBranchProxy *p)
Definition: TBranchProxyDirector.cxx:76
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
ROOT::Detail::TBranchProxy
Definition: TBranchProxy.h:69
ROOT::Internal::TBranchProxyDirector::CreateHistogram
TH1F * CreateHistogram(const char *options)
Definition: TBranchProxyDirector.cxx:92
ROOT::Internal::NotifyDirected
void NotifyDirected(Detail::TBranchProxy *x)
Definition: TBranchProxyDirector.cxx:48
Double_t
double Double_t
Definition: RtypesCore.h:59
ROOT::Internal::ResetReadEntry
void ResetReadEntry(TFriendProxy *fp)
Definition: TBranchProxyDirector.cxx:51
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
ROOT::Internal::TBranchProxyDirector::fDirected
std::list< Detail::TBranchProxy * > fDirected
Definition: TBranchProxyDirector.h:41
TH1::Sumw2
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition: TH1.cxx:8475
TObject
Definition: TObject.h:37
TH1
Definition: TH1.h:57
ROOT::Internal::TBranchProxyDirector::fFriends
std::vector< TFriendProxy * > fFriends
Definition: TBranchProxyDirector.h:42
gPad
#define gPad
Definition: TVirtualPad.h:287
TAxis::GetXmax
Double_t GetXmax() const
Definition: TAxis.h:134
Class
void Class()
Definition: Class.C:29
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
TFriendProxy.h
ROOT
VSD Structures.
Definition: StringConv.hxx:21
TAxis::GetNbins
Int_t GetNbins() const
Definition: TAxis.h:121