Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TRefProxy.cxx
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Markus Frank 10/02/2006
3 
4 /*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
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 #include "TRef.h"
13 #include "TTree.h"
14 #include "TError.h"
15 #include "TBranch.h"
16 #include "TRefProxy.h"
17 #include "TBranchRef.h"
18 #include "TRefTable.h"
19 #include "TTreeFormula.h"
20 #include "TFormLeafInfoReference.h"
21 #include <iostream>
22 
23 /** class TRefProxy
24 A reference proxy, which allows to access ROOT references (TRef)
25 stored contained in other objects from TTree::Draw
26 */
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// TVirtualRefProxy overload: Update (and propagate) cached information
30 
31 Bool_t TRefProxy::Update()
32 {
33  return kTRUE;
34 }
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// TVirtualRefProxy overload: Access to value class
38 
39 TClass* TRefProxy::GetValueClass(void* data) const
40 {
41  TObject* obj = (TObject*)data;
42  return ( obj ) ? obj->IsA() : 0;
43 }
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 /// Access referenced object(-data)
47 
48 void* TRefProxy::GetObject(TFormLeafInfoReference* info, void* data, int)
49 {
50  if ( data ) {
51  TRef* ref = (TRef*)((char*)data + info->GetOffset());
52  void* obj = ref->GetObject();
53  // std::cout << "UID=" << ref->GetUniqueID() << std::endl;
54  if ( obj ) {
55  return obj;
56  }
57  else {
58  TBranch* branch = info->GetBranch();
59  if ( branch ) {
60  UInt_t uid = ref->GetUniqueID();
61  Long64_t ent = branch->GetReadEntry();
62  TRefTable *table = TRefTable::GetRefTable();
63  table->SetUID(uid, ref->GetPID());
64  ((TBranch*)table->GetOwner())->GetEntry(ent);
65  TBranch *b = (TBranch*)table->GetParent(uid, ref->GetPID());
66  if ( 0 == b ) {
67  ((TBranch*)table->GetOwner())->GetEntry(ent);
68  b = (TBranch*)table->GetParent(uid, ref->GetPID());
69  }
70  if ( 0 != b ) {
71  TBranch* br = b->GetMother();
72  if ( br ) br->GetEntry(ent);
73  }
74  obj = ref->GetObject();
75  if ( obj ) {
76  (*ref) = 0;
77  return obj;
78  }
79  }
80  }
81  }
82  return 0;
83 }