00001 // @(#)root/meta: $Id: TVirtualRefProxy.h 20882 2007-11-19 11:31:26Z rdm $ 00002 // Author: Markus Frank 20/05/2005 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2006, 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 #ifndef ROOT_TVirtualRefProxy 00012 #define ROOT_TVirtualRefProxy 00013 00014 // Framework include files 00015 #ifndef ROOT_Rtypes 00016 #include "Rtypes.h" 00017 #endif // ROOT_Rtypes 00018 00019 // Forward declarations 00020 class TClass; 00021 class TFormLeafInfoReference; 00022 00023 //______________________________________________________________________________ 00024 // 00025 // Abstract proxy definition to follow reference objects. 00026 // 00027 // 00028 // Generic Mechanism for Object References 00029 // ======================================= 00030 // 00031 // References are a well known mechanism to support persistency 00032 // of entities, which in C++ typically are represented as 00033 // pointers. The generic mechanism allows clients to supply 00034 // hooks to the ROOT framework in interactive mode in order to 00035 // dereference these objects and access the objects pointed to by 00036 // the reference objects. 00037 // 00038 // Implementations are supplied for ROOT own reference mechanism 00039 // based on instances of the TRef and the TRefArray classes. 00040 // 00041 // To support generality this mechanism was implemented using a 00042 // proxy mechanism, which shields the concrete implementation of the 00043 // reference classes from ROOT. Hence, this mechanism also works for 00044 // references as they are supported by the POOL persistency framework 00045 // and by frameworks like Gaudi. 00046 // 00047 // To enable reference support a concrete sub-class instance of 00048 // the TVirtualRefProxy base class must be attached to the TClass 00049 // instance representing the reference itself. Please see the 00050 // header- and implementation file TRefProxy.h/cxx for details. 00051 // For ROOT's own references this is done simply by a call like: 00052 // 00053 // #include "TROOT.h" 00054 // #include "TClass.h" 00055 // #include "TRefProxy.h" 00056 // 00057 // ... 00058 // gROOT->GetClass("TRef")->AdoptReferenceProxy(new TRefProxy()); 00059 // 00060 // - GetObject() must return the pointer to the referenced 00061 // object. TTreeFormula then figures out how to access the 00062 // value to be plotted. 00063 // Hence, the actual work is done inside a call to: 00064 // 00065 // void* TRefProxy::GetObject(TFormLeafInfoReference* info, void* data, int) 00066 // { 00067 // if ( data ) { 00068 // TRef* ref = (TRef*)((char*)data + info->GetOffset()); 00069 // // Dereference TRef and return pointer to object 00070 // void* obj = ref->GetObject(); 00071 // if ( obj ) { return obj; } 00072 // 00073 // ... else handle error or implement failover .... 00074 // 00075 // 00076 // The type of the referenced object must either be known at compilation 00077 // time or it must be possible to guess it reading the first TTree entry. 00078 // In this case the following conditions must be met: 00079 // - GetValueClass() must return the TClass to the referenced 00080 // objects (or a base class) 00081 // 00082 //______________________________________________________________________________ 00083 class TVirtualRefProxy { 00084 public: 00085 // Virtual Destructor 00086 virtual ~TVirtualRefProxy() {}; 00087 00088 // Release the reference proxy (virtual destructor) 00089 virtual void Release() = 0; 00090 00091 // Clone the reference proxy (virtual constructor) 00092 virtual TVirtualRefProxy* Clone() const = 0; 00093 00094 // Setter of reference class (executed when the proxy is adopted) 00095 // Setup the reference when it is adopted by the TClass structure 00096 // 00097 // classptr [IN] Pointer to the reference class. 00098 virtual void SetClass(TClass *classptr) = 0; 00099 00100 // Getter of reference class. 00101 // The function returns the class description of the reference class 00102 // ie. in the case of TRef TRef::Class 00103 virtual TClass * GetClass() const = 0; 00104 00105 // Access to the target class. 00106 // In the event the value class cannot be specified from the reference 00107 // itself, because the object behind the reference requires a cast, 00108 // the return value must be NULL. 00109 // 00110 // data [IN] Resolved pointer to the referenced object 00111 virtual TClass* GetValueClass(void* data) const = 0; 00112 00113 // Update (and propagate) cached information 00114 virtual Bool_t Update() = 0; 00115 00116 // Flag to indicate if this is a container reference 00117 virtual Bool_t HasCounter() const = 0; 00118 00119 // Access to container size (if container reference (ie TRefArray) etc) 00120 // 00121 // info [IN] Pointer to the structure called by TTree::Draw 00122 // to extract the required object information. 00123 // data [IN] Pointer to the reference object 00124 // 00125 // return value: The prepared pointer to the reference. 00126 virtual Int_t GetCounterValue(TFormLeafInfoReference* info, void *data) = 0; 00127 00128 // Prepare reused reference object (e.g. ZERO data pointers) 00129 // Because TTree::Draw reuses objects some reference implementations 00130 // require setup. For example the pointer to the object the reference points to 00131 // needs to be ZEROed. 00132 // 00133 // data [IN] Pointer to the reference object 00134 // 00135 // return value: The prepared pointer to the reference. 00136 virtual void* GetPreparedReference(void* data) = 0; 00137 00138 // Access referenced object(-data) 00139 // 00140 // info [IN] Pointer to the structure called by TTree::Draw 00141 // to extract the required object information. 00142 // data [IN] Pointer to the referenced object 00143 // instance [IN] Item number if ref collection 00144 // 00145 // return value: Pointer to the requested information 00146 virtual void* GetObject(TFormLeafInfoReference* info, void* data, int instance) = 0; 00147 }; 00148 #endif // ROOT_TVirtualRefProxy