00001 // @(#)root/meta:$Id: TRefProxy.cxx 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Markus Frank 10/02/2006 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 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 #include "TRef.h" 00013 #include "TTree.h" 00014 #include "TError.h" 00015 #include "TBranch.h" 00016 #include "TRefProxy.h" 00017 #include "TBranchRef.h" 00018 #include "TRefTable.h" 00019 #include "TTreeFormula.h" 00020 #include "TFormLeafInfoReference.h" 00021 #include <iostream> 00022 00023 //______________________________________________________________________________ 00024 // 00025 // TRefProxy is a reference proxy, which allows to access ROOT references (TRef) 00026 // stored contained in other objects from TTree::Draw 00027 00028 //______________________________________________________________________________ 00029 TRefProxy::~TRefProxy() 00030 { 00031 // Default destructor 00032 } 00033 00034 //______________________________________________________________________________ 00035 Bool_t TRefProxy::Update() 00036 { 00037 // TVirtualRefProxy overload: Update (and propagate) cached information 00038 00039 return kTRUE; 00040 } 00041 00042 //______________________________________________________________________________ 00043 TClass* TRefProxy::GetValueClass(void* data) const 00044 { 00045 // TVirtualRefProxy overload: Access to value class 00046 00047 TObject* obj = (TObject*)data; 00048 return ( obj ) ? obj->IsA() : 0; 00049 } 00050 00051 //______________________________________________________________________________ 00052 void* TRefProxy::GetObject(TFormLeafInfoReference* info, void* data, int) 00053 { 00054 // Access referenced object(-data) 00055 00056 if ( data ) { 00057 TRef* ref = (TRef*)((char*)data + info->GetOffset()); 00058 void* obj = ref->GetObject(); 00059 // std::cout << "UID=" << ref->GetUniqueID() << std::endl; 00060 if ( obj ) { 00061 return obj; 00062 } 00063 else { 00064 TBranch* branch = info->GetBranch(); 00065 if ( branch ) { 00066 UInt_t uid = ref->GetUniqueID(); 00067 Long64_t ent = branch->GetReadEntry(); 00068 TRefTable *table = TRefTable::GetRefTable(); 00069 table->SetUID(uid, ref->GetPID()); 00070 ((TBranch*)table->GetOwner())->GetEntry(ent); 00071 TBranch *b = (TBranch*)table->GetParent(uid, ref->GetPID()); 00072 if ( 0 == b ) { 00073 ((TBranch*)table->GetOwner())->GetEntry(ent); 00074 b = (TBranch*)table->GetParent(uid, ref->GetPID()); 00075 } 00076 if ( 0 != b ) { 00077 TBranch* br = b->GetMother(); 00078 if ( br ) br->GetEntry(ent); 00079 } 00080 obj = ref->GetObject(); 00081 if ( obj ) { 00082 (*ref) = 0; 00083 return obj; 00084 } 00085 } 00086 } 00087 } 00088 return 0; 00089 }