TBranchProxyDirector.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TBranchProxyDirector.cxx 36035 2010-10-01 20:59:21Z pcanal $
00002 // Author: Philippe Canal  13/05/2003
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun, Fons Rademakers and al.           *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 ////////////////////////////////////////////////////////////////////////////
00013 //                                                                        //
00014 // TBranchProxyDirector                                                   //
00015 //                                                                        //
00016 // This class is used to 'drive' and hold a serie of TBranchProxy objects //
00017 // which represent and give access to the content of TTree object.        //
00018 // This is intended to be used as part of a generate Selector class       //
00019 // which will hold the directory and its associate                        //
00020 //                                                                        //
00021 ////////////////////////////////////////////////////////////////////////////
00022 
00023 #include "TBranchProxyDirector.h"
00024 #include "TBranchProxy.h"
00025 #include "TFriendProxy.h"
00026 #include "TTree.h"
00027 #include "TEnv.h"
00028 #include "TH1F.h"
00029 #include "TPad.h"
00030 #include "TList.h"
00031 
00032 #include <algorithm>
00033 
00034 namespace std {} using namespace std;
00035 
00036 ClassImp(ROOT::TBranchProxyDirector);
00037 
00038 namespace ROOT {
00039 
00040    // Helper function to call Reset on each TBranchProxy
00041    void Reset(TBranchProxy *x) { x->Reset(); } 
00042 
00043    // Helper function to call SetReadEntry on all TFriendProxy
00044    void ResetReadEntry(TFriendProxy *x) { x->ResetReadEntry(); }
00045 
00046    // Helper class to call Update on all TFriendProxy
00047    struct Update {
00048       Update(TTree *newtree) : fNewTree(newtree) {}
00049       TTree *fNewTree;
00050       void operator()(TFriendProxy *x) { x->Update(fNewTree); }
00051    };
00052 
00053 
00054    TBranchProxyDirector::TBranchProxyDirector(TTree* tree, Long64_t i) : 
00055       fTree(tree),
00056       fEntry(i) 
00057    {
00058       // Simple constructor
00059    }
00060 
00061    TBranchProxyDirector::TBranchProxyDirector(TTree* tree, Int_t i) :  
00062       // cint has a problem casting int to long long
00063       fTree(tree),
00064       fEntry(i) 
00065    {
00066       // Simple constructor
00067    }
00068       
00069    void TBranchProxyDirector::Attach(TBranchProxy* p) {
00070 
00071       // Attach a TBranchProxy object to this director.  The director just
00072       // 'remembers' this BranchProxy and does not own it.  It will be use
00073       // to apply Tree wide operation (like reseting).
00074       fDirected.push_back(p);
00075    }
00076 
00077    void TBranchProxyDirector::Attach(TFriendProxy* p) {
00078 
00079       // Attach a TFriendProxy object to this director.  The director just
00080       // 'remembers' this BranchProxy and does not own it.  It will be use
00081       // to apply Tree wide operation (like reseting).
00082       fFriends.push_back(p);
00083    }
00084 
00085    TH1F* TBranchProxyDirector::CreateHistogram(const char *options) {
00086       // Create a temporary 1D histogram.
00087       
00088       Int_t nbins = gEnv->GetValue("Hist.Binning.1D.x",100);
00089       Double_t vmin=0, vmax=0;
00090       Double_t xmin=0, xmax=0;
00091       Bool_t canRebin = kTRUE;
00092       TString opt( options ); 
00093       Bool_t optSame = opt.Contains("same");
00094       if (optSame) canRebin = kFALSE;
00095       
00096       if (gPad && optSame) {
00097          TListIter np(gPad->GetListOfPrimitives());
00098          TObject *op;
00099          TH1 *oldhtemp = 0;
00100          while ((op = np()) && !oldhtemp) {
00101             if (op->InheritsFrom(TH1::Class())) oldhtemp = (TH1 *)op;
00102          }
00103          if (oldhtemp) {
00104             nbins = oldhtemp->GetXaxis()->GetNbins();
00105             vmin = oldhtemp->GetXaxis()->GetXmin();
00106             vmax = oldhtemp->GetXaxis()->GetXmax();
00107          } else {
00108             vmin = gPad->GetUxmin();
00109             vmax = gPad->GetUxmax();
00110          }
00111       } else {
00112          vmin = xmin;
00113          vmax = xmax;
00114          if (xmin < xmax) canRebin = kFALSE;
00115       }
00116       TH1F *hist = new TH1F("htemp","htemp",nbins,vmin,vmax);
00117       hist->SetLineColor(fTree->GetLineColor());
00118       hist->SetLineWidth(fTree->GetLineWidth());
00119       hist->SetLineStyle(fTree->GetLineStyle());
00120       hist->SetFillColor(fTree->GetFillColor());
00121       hist->SetFillStyle(fTree->GetFillStyle());
00122       hist->SetMarkerStyle(fTree->GetMarkerStyle());
00123       hist->SetMarkerColor(fTree->GetMarkerColor());
00124       hist->SetMarkerSize(fTree->GetMarkerSize());
00125       if (canRebin) hist->SetBit(TH1::kCanRebin);
00126       hist->GetXaxis()->SetTitle("var");
00127       hist->SetBit(kCanDelete);
00128       hist->SetDirectory(0);
00129       
00130       if (opt.Length() && opt.Contains("e")) hist->Sumw2();
00131       return hist;
00132    }
00133 
00134    void TBranchProxyDirector::SetReadEntry(Long64_t entry) {
00135 
00136       // move to a new entry to read
00137       fEntry = entry;
00138       if (!fFriends.empty()) {
00139          for_each(fFriends.begin(),fFriends.end(),ResetReadEntry);
00140       }
00141    }
00142 
00143    TTree* TBranchProxyDirector::SetTree(TTree *newtree) {
00144       
00145       // Set the BranchProxy to be looking at a new tree.
00146       // Reset all.
00147       // Return the old tree.
00148       
00149       TTree* oldtree = fTree;
00150       fTree = newtree;
00151       fEntry = -1;
00152       //if (fInitialized) fInitialized = setup();
00153       //fprintf(stderr,"calling SetTree for %p\n",this);
00154       for_each(fDirected.begin(),fDirected.end(),Reset);
00155       Update update(fTree);
00156       for_each(fFriends.begin(),fFriends.end(),update);
00157       return oldtree;
00158    }
00159 
00160 } // namespace ROOT

Generated on Tue Jul 5 15:42:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1