00001 // @(#)root/base:$Id: TFriendProxy.cxx 29044 2009-06-17 01:39:14Z 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 // TFriendProxy // 00015 // // 00016 // Concrete implementation of the proxy around a Friend Tree. // 00017 // // 00018 ////////////////////////////////////////////////////////////////////////// 00019 00020 #include "TFriendProxy.h" 00021 #include "TTree.h" 00022 #include "TList.h" 00023 #include "TFriendElement.h" 00024 00025 ClassImp(ROOT::TFriendProxy); 00026 00027 namespace ROOT { 00028 00029 //------------------------------------------------------------------------------------ 00030 TFriendProxy::TFriendProxy() : fDirector(0,-1), fIndex(-1) 00031 { 00032 } 00033 00034 //------------------------------------------------------------------------------------ 00035 TFriendProxy::TFriendProxy(TBranchProxyDirector *director, TTree *main, Int_t index) : 00036 fDirector(0,-1), fIndex(index) 00037 { 00038 // Constructor. 00039 00040 if (main) { 00041 TObject *obj = main->GetListOfFriends()->At(fIndex); 00042 TFriendElement *element = dynamic_cast<TFriendElement*>( obj ); 00043 if (element) fDirector.SetTree(element->GetTree()); 00044 } 00045 director->Attach(this); 00046 } 00047 00048 //------------------------------------------------------------------------------------ 00049 Long64_t TFriendProxy::GetReadEntry() const 00050 { 00051 // Return the entry number currently being looked at. 00052 00053 return fDirector.GetReadEntry(); 00054 } 00055 00056 //------------------------------------------------------------------------------------ 00057 void TFriendProxy::ResetReadEntry() 00058 { 00059 // Refresh the cached read entry number from the original tree. 00060 00061 // The 2nd call to GetTree is to insure we get the 'local' tree's entry in the case of a 00062 // chain. 00063 if (fDirector.GetTree()) fDirector.SetReadEntry(fDirector.GetTree()->GetTree()->GetReadEntry()); 00064 } 00065 00066 //------------------------------------------------------------------------------------ 00067 void TFriendProxy::Update(TTree *newmain) 00068 { 00069 // Update the address of the underlying tree. 00070 00071 if (newmain) { 00072 TObject *obj = newmain->GetListOfFriends()->At(fIndex); 00073 TFriendElement *element = dynamic_cast<TFriendElement*>( obj ); 00074 if (element) fDirector.SetTree(element->GetTree()); 00075 else fDirector.SetTree(0); 00076 } else { 00077 fDirector.SetTree(0); 00078 } 00079 } 00080 }