TLeafO.cxx

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

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