TLeafF.cxx

Go to the documentation of this file.
00001 // @(#)root/tree:$Id: TLeafF.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 32 bit floating point data type.                       //
00015 //////////////////////////////////////////////////////////////////////////
00016 
00017 #include "TLeafF.h"
00018 #include "TBranch.h"
00019 #include "TClonesArray.h"
00020 #include "Riostream.h"
00021 
00022 ClassImp(TLeafF)
00023 
00024 //______________________________________________________________________________
00025 TLeafF::TLeafF(): TLeaf()
00026 {
00027 //*-*-*-*-*-*Default constructor for LeafF*-*-*-*-*-*-*-*-*-*-*-*-*-*
00028 //*-*        ============================
00029 
00030    fLenType = 4;
00031    fMinimum = 0;
00032    fMaximum = 0;
00033    fValue   = 0;
00034    fPointer = 0;
00035 }
00036 
00037 //______________________________________________________________________________
00038 TLeafF::TLeafF(TBranch *parent, const char *name, const char *type)
00039    :TLeaf(parent, name,type)
00040 {
00041 //*-*-*-*-*-*-*-*-*-*-*-*-*Create a LeafF*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
00042 //*-*                      ==============
00043 //*-*
00044 
00045    fLenType = 4;
00046    fMinimum = 0;
00047    fMaximum = 0;
00048    fValue   = 0;
00049    fPointer = 0;
00050 }
00051 
00052 //______________________________________________________________________________
00053 TLeafF::~TLeafF()
00054 {
00055 //*-*-*-*-*-*Default destructor for a LeafF*-*-*-*-*-*-*-*-*-*-*-*
00056 //*-*        ===============================
00057 
00058    if (ResetAddress(0,kTRUE)) delete [] fValue;
00059 }
00060 
00061 
00062 
00063 //______________________________________________________________________________
00064 void TLeafF::Export(TClonesArray *list, Int_t n)
00065 {
00066 //*-*-*-*-*-*Export element from local leaf buffer to ClonesArray*-*-*-*-*
00067 //*-*        ====================================================
00068 
00069    Float_t *value = fValue;
00070    for (Int_t i=0;i<n;i++) {
00071       char *first = (char*)list->UncheckedAt(i);
00072       Float_t *ff = (Float_t*)&first[fOffset];
00073       for (Int_t j=0;j<fLen;j++) {
00074          ff[j] = value[j];
00075       }
00076       value += fLen;
00077    }
00078 }
00079 
00080 //______________________________________________________________________________
00081 void TLeafF::FillBasket(TBuffer &b)
00082 {
00083 //*-*-*-*-*-*-*-*-*-*-*Pack leaf elements in Basket output buffer*-*-*-*-*-*-*
00084 //*-*                  ==========================================
00085 
00086    Int_t len = GetLen();
00087    if (fPointer) fValue = *fPointer;
00088    b.WriteFastArray(fValue,len);
00089 }
00090 
00091 
00092 //______________________________________________________________________________
00093 void TLeafF::Import(TClonesArray *list, Int_t n)
00094 {
00095 //*-*-*-*-*-*Import element from ClonesArray into local leaf buffer*-*-*-*-*
00096 //*-*        ======================================================
00097 
00098    const Float_t kFloatUndefined = -9999.;
00099    Int_t j = 0;
00100    char *clone;
00101    for (Int_t i=0;i<n;i++) {
00102       clone = (char*)list->UncheckedAt(i);
00103       if (clone) memcpy(&fValue[j],clone + fOffset,  4*fLen);
00104       else       memcpy(&fValue[j],&kFloatUndefined, 4*fLen);
00105       j += fLen;
00106    }
00107 }
00108 
00109 //______________________________________________________________________________
00110 void TLeafF::PrintValue(Int_t l) const
00111 {
00112 // Prints leaf value
00113 
00114    Float_t *value = (Float_t *)GetValuePointer();
00115    printf("%g",value[l]);
00116 }
00117 
00118 //______________________________________________________________________________
00119 void TLeafF::ReadBasket(TBuffer &b)
00120 {
00121 //*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
00122 //*-*                  ===========================================
00123 
00124    if (!fLeafCount && fNdata == 1) {
00125       b >> fValue[0];
00126    }else {
00127       if (fLeafCount) {
00128          Long64_t entry = fBranch->GetReadEntry();
00129          if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
00130             fLeafCount->GetBranch()->GetEntry(entry);
00131          }
00132          Int_t len = Int_t(fLeafCount->GetValue());
00133          if (len > fLeafCount->GetMaximum()) {
00134             printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
00135             len = fLeafCount->GetMaximum();
00136          }
00137          fNdata = len*fLen;
00138          b.ReadFastArray(fValue,len*fLen);
00139       } else {
00140          b.ReadFastArray(fValue,fLen);
00141       }
00142    }
00143 }
00144 
00145 //______________________________________________________________________________
00146 void TLeafF::ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
00147 {
00148 //*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
00149 //  and export buffer to TClonesArray objects
00150 
00151    if (n*fLen == 1) {
00152       b >> fValue[0];
00153    } else {
00154       b.ReadFastArray(fValue,n*fLen);
00155    }
00156 
00157    Float_t *value = fValue;
00158    for (Int_t i=0;i<n;i++) {
00159       char *first = (char*)list->UncheckedAt(i);
00160       Float_t *ff = (Float_t*)&first[fOffset];
00161       for (Int_t j=0;j<fLen;j++) {
00162          ff[j] = value[j];
00163       }
00164       value += fLen;
00165    }
00166 }
00167 
00168 //______________________________________________________________________________
00169 void TLeafF::ReadValue(istream &s)
00170 {
00171 // read a float from istream s and store it into the branch buffer
00172    Float_t *value = (Float_t*)GetValuePointer();
00173    for (Int_t i=0;i<fLen;i++) s >> value[i];
00174 }
00175 
00176 //______________________________________________________________________________
00177 void TLeafF::SetAddress(void *add)
00178 {
00179 //*-*-*-*-*-*-*-*-*-*-*Set leaf buffer data address*-*-*-*-*-*
00180 //*-*                  ============================
00181 
00182    if (ResetAddress(add) && (add!= fValue)) {
00183       delete [] fValue;
00184    }
00185 
00186    if (add) {
00187       if (TestBit(kIndirectAddress)) {
00188          fPointer = (Float_t**) add;
00189          Int_t ncountmax = fLen;
00190          if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
00191          if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
00192              ncountmax > fNdata || *fPointer == 0) {
00193             if (*fPointer) delete [] *fPointer;
00194             if (ncountmax > fNdata) fNdata = ncountmax;
00195             *fPointer = new Float_t[fNdata];
00196          }
00197          fValue = *fPointer;
00198       } else {
00199          fValue = (Float_t*)add;
00200       }
00201    } else {
00202       fValue = new Float_t[fNdata];
00203       fValue[0] = 0;
00204    }
00205 }

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