TLeafD.cxx

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

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