TLeafL.cxx

Go to the documentation of this file.
00001 // @(#)root/tree:$Id: TLeafL.cxx 36407 2010-10-22 02:04:08Z pcanal $
00002 // Author: Rene Brun   12/01/96
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 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // A TLeaf for a 64 bit Integer data type.                              //
00015 //////////////////////////////////////////////////////////////////////////
00016 
00017 #include "TLeafL.h"
00018 #include "TBranch.h"
00019 #include "TClonesArray.h"
00020 #include "Riostream.h"
00021 
00022 ClassImp(TLeafL)
00023 
00024 //______________________________________________________________________________
00025 TLeafL::TLeafL(): TLeaf()
00026 {
00027 //*-*-*-*-*-*Default constructor for LeafI*-*-*-*-*-*-*-*-*-*-*-*-*-*
00028 //*-*        ============================
00029 
00030    fLenType = sizeof(Long64_t);
00031    fMinimum = 0;
00032    fMaximum = 0;
00033    fValue   = 0;
00034    fPointer = 0;
00035 }
00036 
00037 //______________________________________________________________________________
00038 TLeafL::TLeafL(TBranch *parent, const char *name, const char *type)
00039    :TLeaf(parent, name,type)
00040 {
00041 //*-*-*-*-*-*-*-*-*-*-*-*-*Create a LeafL*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00042 //*-*                      ==============
00043 //*-*
00044 
00045    fLenType = sizeof(Long64_t);
00046    fMinimum = 0;
00047    fMaximum = 0;
00048    fValue   = 0;
00049    fPointer = 0;
00050 }
00051 
00052 //______________________________________________________________________________
00053 TLeafL::~TLeafL()
00054 {
00055 //*-*-*-*-*-*Default destructor for a LeafL*-*-*-*-*-*-*-*-*-*-*-*
00056 //*-*        ===============================
00057 
00058    if (ResetAddress(0,kTRUE)) delete [] fValue;
00059 }
00060 
00061 
00062 //______________________________________________________________________________
00063 void TLeafL::Export(TClonesArray *list, Int_t n)
00064 {
00065 //*-*-*-*-*-*Export element from local leaf buffer to ClonesArray*-*-*-*-*
00066 //*-*        ======================================================
00067 
00068    Long64_t *value = fValue;
00069    for (Int_t i=0;i<n;i++) {
00070       char *first = (char*)list->UncheckedAt(i);
00071       Long64_t *ii = (Long64_t*)&first[fOffset];
00072       for (Int_t j=0;j<fLen;j++) {
00073          ii[j] = value[j];
00074       }
00075       value += fLen;
00076    }
00077 }
00078 
00079 //______________________________________________________________________________
00080 void TLeafL::FillBasket(TBuffer &b)
00081 {
00082 //*-*-*-*-*-*-*-*-*-*-*Pack leaf elements in Basket output buffer*-*-*-*-*-*-*
00083 //*-*                  =========================================
00084 
00085    Int_t i;
00086    Int_t len = GetLen();
00087    if (fPointer) fValue = *fPointer;
00088    if (IsRange()) {
00089       if (fValue[0] > fMaximum) fMaximum = fValue[0];
00090    }
00091    if (IsUnsigned()) {
00092       for (i=0;i<len;i++) b << (ULong64_t)fValue[i];
00093    } else {
00094       b.WriteFastArray(fValue,len);
00095    }
00096 }
00097 
00098 //______________________________________________________________________________
00099 const char *TLeafL::GetTypeName() const
00100 {
00101 //*-*-*-*-*-*-*-*Returns name of leaf type*-*-*-*-*-*-*-*-*-*-*-*
00102 //*-*            =========================
00103 
00104    if (fIsUnsigned) return "ULong64_t";
00105    return "Long64_t";
00106 }
00107 
00108 
00109 //______________________________________________________________________________
00110 Double_t TLeafL::GetValue(Int_t i) const
00111 {
00112 // Returns current value of leaf
00113 // if leaf is a simple type, i must be set to 0
00114 // if leaf is an array, i is the array element number to be returned
00115 
00116    //unlikely to have unsigned long64.
00117    //cannot cast from ULong64 to Double with VC++6
00118    //if (fIsUnsigned) return (Double_t)((ULong64_t)fValue[i]);
00119    return fValue[i];
00120 }
00121 
00122 
00123 
00124 //______________________________________________________________________________
00125 void TLeafL::Import(TClonesArray *list, Int_t n)
00126 {
00127 //*-*-*-*-*-*Import element from ClonesArray into local leaf buffer*-*-*-*-*
00128 //*-*        ======================================================
00129 
00130    const Int_t kIntUndefined = -9999;
00131    Int_t j = 0;
00132    char *clone;
00133    for (Int_t i=0;i<n;i++) {
00134       clone = (char*)list->UncheckedAt(i);
00135       if (clone) memcpy(&fValue[j],clone + fOffset, 8*fLen);
00136       else       memcpy(&fValue[j],&kIntUndefined,  8*fLen);
00137       j += fLen;
00138    }
00139 }
00140 
00141 //______________________________________________________________________________
00142 void TLeafL::PrintValue(Int_t l) const
00143 {
00144 // Prints leaf value
00145 
00146    if (fIsUnsigned) {
00147       ULong64_t *uvalue = (ULong64_t*)GetValuePointer();
00148       printf("%llu",uvalue[l]);
00149    } else {
00150       Long64_t *value = (Long64_t*)GetValuePointer();
00151       printf("%lld",value[l]);
00152    }
00153 }
00154 
00155 //______________________________________________________________________________
00156 void TLeafL::ReadBasket(TBuffer &b)
00157 {
00158 //*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
00159 //*-*                  ===========================================
00160 
00161    if (!fLeafCount && fNdata == 1) {
00162       b >> fValue[0];
00163    } else {
00164       if (fLeafCount) {
00165          Long64_t entry = fBranch->GetReadEntry();
00166          if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
00167             fLeafCount->GetBranch()->GetEntry(entry);
00168          }
00169          Int_t len = Int_t(fLeafCount->GetValue());
00170          if (len > fLeafCount->GetMaximum()) {
00171             printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
00172             len = fLeafCount->GetMaximum();
00173          }
00174          fNdata = len*fLen;
00175          b.ReadFastArray(fValue,len*fLen);
00176       } else {
00177          b.ReadFastArray(fValue,fLen);
00178       }
00179    }
00180 }
00181 
00182 //______________________________________________________________________________
00183 void TLeafL::ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
00184 {
00185 //*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
00186 //  and export buffer to TClonesArray objects
00187 
00188    if (n*fLen == 1) {
00189       b >> fValue[0];
00190    } else {
00191       b.ReadFastArray(fValue,n*fLen);
00192    }
00193    Long64_t *value = fValue;
00194    for (Int_t i=0;i<n;i++) {
00195       char *first = (char*)list->UncheckedAt(i);
00196       Long64_t *ii = (Long64_t*)&first[fOffset];
00197       for (Int_t j=0;j<fLen;j++) {
00198          ii[j] = value[j];
00199       }
00200       value += fLen;
00201    }
00202 }
00203 
00204 //______________________________________________________________________________
00205 void TLeafL::ReadValue(istream &s)
00206 {
00207 // read a long integer from istream s and store it into the branch buffer
00208 #if defined(_MSC_VER) && (_MSC_VER<1300)
00209    printf("Due to a bug in VC++6, the function TLeafL::ReadValue is dummy\n");
00210 #else
00211    if (fIsUnsigned) {
00212       ULong64_t *uvalue = (ULong64_t*)GetValuePointer();
00213       for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
00214    } else {
00215       Long64_t *value = (Long64_t*)GetValuePointer();
00216       for (Int_t i=0;i<fLen;i++) s >> value[i];
00217    }
00218 #endif
00219 }
00220 
00221 //______________________________________________________________________________
00222 void TLeafL::SetAddress(void *add)
00223 {
00224 //*-*-*-*-*-*-*-*-*-*-*Set leaf buffer data address*-*-*-*-*-*
00225 //*-*                  ============================
00226 
00227    if (ResetAddress(add) && (add!=fValue)) {
00228       delete [] fValue;
00229    }
00230    if (add) {
00231       if (TestBit(kIndirectAddress)) {
00232          fPointer = (Long64_t**) add;
00233          Int_t ncountmax = fLen;
00234          if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
00235          if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
00236              ncountmax > fNdata || *fPointer == 0) {
00237             if (*fPointer) delete [] *fPointer;
00238             if (ncountmax > fNdata) fNdata = ncountmax;
00239             *fPointer = new Long64_t[fNdata];
00240          }
00241          fValue = *fPointer;
00242       } else {
00243          fValue = (Long64_t*)add;
00244       }
00245    } else {
00246       fValue = new Long64_t[fNdata];
00247       fValue[0] = 0;
00248    }
00249 }
00250 

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