ROOT logo
// @(#)root/tree:$Id: TLeafD.cxx 38801 2011-04-11 20:10:24Z pcanal $
// Author: Rene Brun   12/01/96

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// A TLeaf for a 64 bit floating point data type.                       //
//////////////////////////////////////////////////////////////////////////

#include "TLeafD.h"
#include "TBranch.h"
#include "TClonesArray.h"
#include "Riostream.h"

ClassImp(TLeafD)

//______________________________________________________________________________
TLeafD::TLeafD(): TLeaf()
{
//*-*-*-*-*-*Default constructor for LeafD*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ============================

   fLenType = 8;
   fMinimum = 0;
   fMaximum = 0;
   fValue   = 0;
   fPointer = 0;
}

//______________________________________________________________________________
TLeafD::TLeafD(TBranch *parent, const char *name, const char *type)
   :TLeaf(parent, name,type)
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Create a LeafD*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ==============
//*-*

   fLenType = 8;
   fMinimum = 0;
   fMaximum = 0;
   fValue   = 0;
   fPointer = 0;
}

//______________________________________________________________________________
TLeafD::~TLeafD()
{
//*-*-*-*-*-*Default destructor for a LeafD*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ===============================

   if (ResetAddress(0,kTRUE)) delete [] fValue;
}


//______________________________________________________________________________
void TLeafD::Export(TClonesArray *list, Int_t n)
{
//*-*-*-*-*-*Export element from local leaf buffer to ClonesArray*-*-*-*-*
//*-*        ====================================================

   Int_t j = 0;
   for (Int_t i=0;i<n;i++) {
      memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 8*fLen);
      j += fLen;
   }
}


//______________________________________________________________________________
void TLeafD::FillBasket(TBuffer &b)
{
//*-*-*-*-*-*-*-*-*-*-*Pack leaf elements in Basket output buffer*-*-*-*-*-*-*
//*-*                  ==========================================

   Int_t len = GetLen();
   if (fPointer) fValue = *fPointer;
   b.WriteFastArray(fValue,len);
}


//______________________________________________________________________________
void TLeafD::Import(TClonesArray *list, Int_t n)
{
//*-*-*-*-*-*Import element from ClonesArray into local leaf buffer*-*-*-*-*
//*-*        ======================================================

   const Double_t kDoubleUndefined = -9999.;
   Int_t j = 0;
   char *clone;
   for (Int_t i=0;i<n;i++) {
      clone = (char*)list->UncheckedAt(i);
      if (clone) memcpy(&fValue[j],clone + fOffset, 8*fLen);
      else       memcpy(&fValue[j],&kDoubleUndefined,  8*fLen);
      j += fLen;
   }
}

//______________________________________________________________________________
void TLeafD::PrintValue(Int_t l) const
{
// Prints leaf value

   Double_t *value = (Double_t *)GetValuePointer();
   printf("%g",value[l]);
}

//______________________________________________________________________________
void TLeafD::ReadBasket(TBuffer &b)
{
//*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
//*-*                  ===========================================

   if (!fLeafCount && fNdata == 1) {
      b.ReadDouble(fValue[0]);
   }else {
      if (fLeafCount) {
         Long64_t entry = fBranch->GetReadEntry();
         if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
            fLeafCount->GetBranch()->GetEntry(entry);
         }
         Int_t len = Int_t(fLeafCount->GetValue());
         if (len > fLeafCount->GetMaximum()) {
            printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
            len = fLeafCount->GetMaximum();
         }
         fNdata = len*fLen;
         b.ReadFastArray(fValue,len*fLen);
      } else {
         b.ReadFastArray(fValue,fLen);
      }
   }
}

//______________________________________________________________________________
void TLeafD::ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
{
//*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
//  and export buffer to TClonesArray objects

   b.ReadFastArray(fValue,n*fLen);

   Int_t j = 0;
   for (Int_t i=0;i<n;i++) {
      memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 8*fLen);
      j += fLen;
   }
}

//______________________________________________________________________________
void TLeafD::ReadValue(istream &s)
{
// read a double from istream s and store it into the branch buffer
   Double_t *value = (Double_t*)GetValuePointer();
   for (Int_t i=0;i<fLen;i++) s >> value[i];
}

//______________________________________________________________________________
void TLeafD::SetAddress(void *add)
{
//*-*-*-*-*-*-*-*-*-*-*Set leaf buffer data address*-*-*-*-*-*
//*-*                  ============================

   if (ResetAddress(add) && (add!= fValue)) {
      delete [] fValue;
   }
   if (add) {
      if (TestBit(kIndirectAddress)) {
         fPointer = (Double_t**) add;
         Int_t ncountmax = fLen;
         if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
         if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
             ncountmax > fNdata || *fPointer == 0) {
            if (*fPointer) delete [] *fPointer;
            if (ncountmax > fNdata) fNdata = ncountmax;
            *fPointer = new Double_t[fNdata];
         }
         fValue = *fPointer;
      } else {
         fValue = (Double_t*)add;
      }
   } else {
      fValue = new Double_t[fNdata];
      fValue[0] = 0;
   }
}
 TLeafD.cxx:1
 TLeafD.cxx:2
 TLeafD.cxx:3
 TLeafD.cxx:4
 TLeafD.cxx:5
 TLeafD.cxx:6
 TLeafD.cxx:7
 TLeafD.cxx:8
 TLeafD.cxx:9
 TLeafD.cxx:10
 TLeafD.cxx:11
 TLeafD.cxx:12
 TLeafD.cxx:13
 TLeafD.cxx:14
 TLeafD.cxx:15
 TLeafD.cxx:16
 TLeafD.cxx:17
 TLeafD.cxx:18
 TLeafD.cxx:19
 TLeafD.cxx:20
 TLeafD.cxx:21
 TLeafD.cxx:22
 TLeafD.cxx:23
 TLeafD.cxx:24
 TLeafD.cxx:25
 TLeafD.cxx:26
 TLeafD.cxx:27
 TLeafD.cxx:28
 TLeafD.cxx:29
 TLeafD.cxx:30
 TLeafD.cxx:31
 TLeafD.cxx:32
 TLeafD.cxx:33
 TLeafD.cxx:34
 TLeafD.cxx:35
 TLeafD.cxx:36
 TLeafD.cxx:37
 TLeafD.cxx:38
 TLeafD.cxx:39
 TLeafD.cxx:40
 TLeafD.cxx:41
 TLeafD.cxx:42
 TLeafD.cxx:43
 TLeafD.cxx:44
 TLeafD.cxx:45
 TLeafD.cxx:46
 TLeafD.cxx:47
 TLeafD.cxx:48
 TLeafD.cxx:49
 TLeafD.cxx:50
 TLeafD.cxx:51
 TLeafD.cxx:52
 TLeafD.cxx:53
 TLeafD.cxx:54
 TLeafD.cxx:55
 TLeafD.cxx:56
 TLeafD.cxx:57
 TLeafD.cxx:58
 TLeafD.cxx:59
 TLeafD.cxx:60
 TLeafD.cxx:61
 TLeafD.cxx:62
 TLeafD.cxx:63
 TLeafD.cxx:64
 TLeafD.cxx:65
 TLeafD.cxx:66
 TLeafD.cxx:67
 TLeafD.cxx:68
 TLeafD.cxx:69
 TLeafD.cxx:70
 TLeafD.cxx:71
 TLeafD.cxx:72
 TLeafD.cxx:73
 TLeafD.cxx:74
 TLeafD.cxx:75
 TLeafD.cxx:76
 TLeafD.cxx:77
 TLeafD.cxx:78
 TLeafD.cxx:79
 TLeafD.cxx:80
 TLeafD.cxx:81
 TLeafD.cxx:82
 TLeafD.cxx:83
 TLeafD.cxx:84
 TLeafD.cxx:85
 TLeafD.cxx:86
 TLeafD.cxx:87
 TLeafD.cxx:88
 TLeafD.cxx:89
 TLeafD.cxx:90
 TLeafD.cxx:91
 TLeafD.cxx:92
 TLeafD.cxx:93
 TLeafD.cxx:94
 TLeafD.cxx:95
 TLeafD.cxx:96
 TLeafD.cxx:97
 TLeafD.cxx:98
 TLeafD.cxx:99
 TLeafD.cxx:100
 TLeafD.cxx:101
 TLeafD.cxx:102
 TLeafD.cxx:103
 TLeafD.cxx:104
 TLeafD.cxx:105
 TLeafD.cxx:106
 TLeafD.cxx:107
 TLeafD.cxx:108
 TLeafD.cxx:109
 TLeafD.cxx:110
 TLeafD.cxx:111
 TLeafD.cxx:112
 TLeafD.cxx:113
 TLeafD.cxx:114
 TLeafD.cxx:115
 TLeafD.cxx:116
 TLeafD.cxx:117
 TLeafD.cxx:118
 TLeafD.cxx:119
 TLeafD.cxx:120
 TLeafD.cxx:121
 TLeafD.cxx:122
 TLeafD.cxx:123
 TLeafD.cxx:124
 TLeafD.cxx:125
 TLeafD.cxx:126
 TLeafD.cxx:127
 TLeafD.cxx:128
 TLeafD.cxx:129
 TLeafD.cxx:130
 TLeafD.cxx:131
 TLeafD.cxx:132
 TLeafD.cxx:133
 TLeafD.cxx:134
 TLeafD.cxx:135
 TLeafD.cxx:136
 TLeafD.cxx:137
 TLeafD.cxx:138
 TLeafD.cxx:139
 TLeafD.cxx:140
 TLeafD.cxx:141
 TLeafD.cxx:142
 TLeafD.cxx:143
 TLeafD.cxx:144
 TLeafD.cxx:145
 TLeafD.cxx:146
 TLeafD.cxx:147
 TLeafD.cxx:148
 TLeafD.cxx:149
 TLeafD.cxx:150
 TLeafD.cxx:151
 TLeafD.cxx:152
 TLeafD.cxx:153
 TLeafD.cxx:154
 TLeafD.cxx:155
 TLeafD.cxx:156
 TLeafD.cxx:157
 TLeafD.cxx:158
 TLeafD.cxx:159
 TLeafD.cxx:160
 TLeafD.cxx:161
 TLeafD.cxx:162
 TLeafD.cxx:163
 TLeafD.cxx:164
 TLeafD.cxx:165
 TLeafD.cxx:166
 TLeafD.cxx:167
 TLeafD.cxx:168
 TLeafD.cxx:169
 TLeafD.cxx:170
 TLeafD.cxx:171
 TLeafD.cxx:172
 TLeafD.cxx:173
 TLeafD.cxx:174
 TLeafD.cxx:175
 TLeafD.cxx:176
 TLeafD.cxx:177
 TLeafD.cxx:178
 TLeafD.cxx:179
 TLeafD.cxx:180
 TLeafD.cxx:181
 TLeafD.cxx:182
 TLeafD.cxx:183
 TLeafD.cxx:184
 TLeafD.cxx:185
 TLeafD.cxx:186
 TLeafD.cxx:187
 TLeafD.cxx:188
 TLeafD.cxx:189
 TLeafD.cxx:190
 TLeafD.cxx:191
 TLeafD.cxx:192