TFormLeafInfoReference.cxx

Go to the documentation of this file.
00001 // @(#)root/treeplayer:$Id: TFormLeafInfoReference.cxx 32930 2010-04-09 16:18:32Z pcanal $
00002 // Author: Markus Frank 01/02/2006
00003 
00004 /*************************************************************************
00005 * Copyright (C) 1995-2000, Rene Brun and 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 #include "TError.h"
00013 #include "TLeafObject.h"
00014 #include "TInterpreter.h"
00015 #include "TVirtualRefProxy.h"
00016 #include "TFormLeafInfoReference.h"
00017 
00018 //______________________________________________________________________________
00019 //
00020 // TFormLeafInfoReference is a small helper class to implement the following
00021 // of reference objects stored in a TTree
00022 
00023 //______________________________________________________________________________
00024 TFormLeafInfoReference::TFormLeafInfoReference(TClass* cl, TStreamerElement* e, int off)
00025 : TFormLeafInfo(cl,off,e), fProxy(0), fBranch(0)
00026 {
00027    // Constructor.
00028 
00029    TVirtualRefProxy* p = cl->GetReferenceProxy();
00030    if ( !p )  {
00031       ::Error("TFormLeafInfoReference","No reference proxy for class %s availible",cl->GetName());
00032       return;
00033    }
00034    fProxy = p->Clone();
00035 }
00036 
00037 //______________________________________________________________________________
00038 TFormLeafInfoReference::TFormLeafInfoReference(const TFormLeafInfoReference& org)
00039 : TFormLeafInfo(org), fProxy(0), fBranch(org.fBranch)
00040 {
00041    // Copy constructor.
00042 
00043    TVirtualRefProxy* p = org.fProxy;
00044    if ( !p )  {
00045       ::Error("TFormLeafInfoReference","No reference proxy for class %s availible",fClass->GetName());
00046       return;
00047    }
00048    fProxy = p->Clone();
00049 }
00050 
00051 //______________________________________________________________________________
00052 TFormLeafInfoReference::~TFormLeafInfoReference()
00053 {
00054    // Destructor.
00055 
00056    if ( fProxy ) fProxy->Release();
00057 }
00058 
00059 //______________________________________________________________________________
00060 TFormLeafInfo* TFormLeafInfoReference::DeepCopy() const
00061 {
00062    // Virtual copy constructor.
00063 
00064    return new TFormLeafInfoReference(*this);
00065 }
00066 
00067 //______________________________________________________________________________
00068 TClass* TFormLeafInfoReference::GetClass() const
00069 {
00070    // Access to target class pointer (if available)
00071 
00072    return fNext ? fNext->GetClass() : 0;
00073 }
00074 
00075 //______________________________________________________________________________
00076 Bool_t TFormLeafInfoReference::HasCounter() const
00077 {
00078    // Return true if any of underlying data has a array size counter
00079 
00080    Bool_t result = fProxy ? fProxy->HasCounter() : false;
00081    if (fNext) result |= fNext->HasCounter();
00082    return fCounter!=0 || result;
00083 }
00084 //______________________________________________________________________________
00085 Int_t TFormLeafInfoReference::ReadCounterValue(char *where)
00086 {
00087    // Return the size of the underlying array for the current entry in the TTree.
00088 
00089    Int_t result = 0;
00090    if ( where && HasCounter() )  {
00091       where = (char*)fProxy->GetPreparedReference(where);
00092       if ( where )  {
00093          return fProxy->GetCounterValue(this, where);
00094       }
00095    }
00096    gInterpreter->ClearStack();
00097    // Get rid of temporary return object.
00098    return result;
00099 }
00100 
00101 //______________________________________________________________________________
00102 Int_t TFormLeafInfoReference::GetCounterValue(TLeaf* leaf)  {
00103    // Return the current size of the array container
00104 
00105    if ( HasCounter() )  {
00106       char *thisobj = 0;
00107       Int_t instance = 0;
00108       if (leaf->InheritsFrom(TLeafObject::Class()) ) {
00109          thisobj = (char*)((TLeafObject*)leaf)->GetObject();
00110       } else {
00111          thisobj = GetObjectAddress((TLeafElement*)leaf, instance); // instance might be modified
00112       }
00113       return ReadCounterValue(thisobj);
00114    }
00115    return 0;
00116 }
00117 
00118 //______________________________________________________________________________
00119 TClass* TFormLeafInfoReference::GetValueClass(TLeaf* leaf)  
00120 {
00121    // Access to the value class of the reference proxy
00122 
00123    return this->GetValueClass(this->GetLocalValuePointer(leaf,0));
00124 }
00125 
00126 //______________________________________________________________________________
00127 TClass* TFormLeafInfoReference::GetValueClass(void* obj)  
00128 {
00129    // Access to the value class of the reference proxy
00130 
00131    return fProxy ? fProxy->GetValueClass(obj) : 0;
00132 }
00133 
00134 //______________________________________________________________________________
00135 Bool_t TFormLeafInfoReference::Update()
00136 {
00137    // TFormLeafInfo overload: Update (and propagate) cached information
00138 
00139    Bool_t res = this->TFormLeafInfo::Update();
00140    if ( fProxy ) fProxy->Update();
00141    return res;
00142 }
00143 
00144 //______________________________________________________________________________
00145 Double_t TFormLeafInfoReference::GetValue(TLeaf *leaf, Int_t instance)
00146 {
00147    // Return result of a leafobject method
00148 
00149    fBranch = leaf->GetBranch();
00150    return TFormLeafInfo::GetValue(leaf, instance);
00151 }
00152 
00153 //______________________________________________________________________________
00154 void *TFormLeafInfoReference::GetLocalValuePointer( TLeaf *from, Int_t instance)
00155 {
00156    // This is implemented here because some compiler want ALL the
00157    // signature of an overloaded function to be re-implemented.
00158 
00159    fBranch = from->GetBranch();
00160    return TFormLeafInfo::GetLocalValuePointer(from, instance);
00161 }
00162 
00163 //______________________________________________________________________________
00164 void *TFormLeafInfoReference::GetLocalValuePointer(char *where, Int_t instance)
00165 {
00166    // Access value of referenced object
00167 
00168    if (where) {
00169       where = (char*)fProxy->GetPreparedReference(where);
00170       if (where) {
00171          void* result = fProxy->GetObject(this, where, instance);
00172          gInterpreter->ClearStack();
00173          return result;
00174       }
00175    }
00176    gInterpreter->ClearStack();
00177    return 0;
00178 }
00179 
00180 //______________________________________________________________________________
00181 Double_t TFormLeafInfoReference::ReadValue(char *where, Int_t instance)
00182 {
00183    // Execute the method on the given address
00184 
00185    Double_t result = 0;
00186    if ( where )  {
00187       where = (char*)fProxy->GetPreparedReference(where);
00188       if ( where )  {
00189          void* res = fProxy->GetObject(this, where, instance);
00190          if ( res )  {
00191             result = (fNext) ? fNext->ReadValue((char*)res,instance) : *(Double_t*)res;
00192          }
00193       }
00194    }
00195    gInterpreter->ClearStack();
00196    // Get rid of temporary return object.
00197    return result;
00198 }

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