ROOT logo
// @(#)root/tree:$Id: TLeafL.cxx 40598 2011-08-15 15:28:32Z 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 Integer data type.                              //
//////////////////////////////////////////////////////////////////////////

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

ClassImp(TLeafL)

//______________________________________________________________________________
TLeafL::TLeafL(): TLeaf()
{
//*-*-*-*-*-*Default constructor for LeafI*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ============================

   fLenType = sizeof(Long64_t);
   fMinimum = 0;
   fMaximum = 0;
   fValue   = 0;
   fPointer = 0;
}

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

   fLenType = sizeof(Long64_t);
   fMinimum = 0;
   fMaximum = 0;
   fValue   = 0;
   fPointer = 0;
}

//______________________________________________________________________________
TLeafL::~TLeafL()
{
//*-*-*-*-*-*Default destructor for a LeafL*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ===============================

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


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

   Long64_t *value = fValue;
   for (Int_t i=0;i<n;i++) {
      char *first = (char*)list->UncheckedAt(i);
      Long64_t *ii = (Long64_t*)&first[fOffset];
      for (Int_t j=0;j<fLen;j++) {
         ii[j] = value[j];
      }
      value += fLen;
   }
}

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

   Int_t i;
   Int_t len = GetLen();
   if (fPointer) fValue = *fPointer;
   if (IsRange()) {
      if (fValue[0] > fMaximum) fMaximum = fValue[0];
   }
   if (IsUnsigned()) {
      for (i=0;i<len;i++) b << (ULong64_t)fValue[i];
   } else {
      b.WriteFastArray(fValue,len);
   }
}

//______________________________________________________________________________
const char *TLeafL::GetTypeName() const
{
//*-*-*-*-*-*-*-*Returns name of leaf type*-*-*-*-*-*-*-*-*-*-*-*
//*-*            =========================

   if (fIsUnsigned) return "ULong64_t";
   return "Long64_t";
}


//______________________________________________________________________________
Double_t TLeafL::GetValue(Int_t i) const
{
// Returns current value of leaf
// if leaf is a simple type, i must be set to 0
// if leaf is an array, i is the array element number to be returned

   if (fIsUnsigned) return (Double_t)((ULong64_t)fValue[i]);
   return fValue[i];
}



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

   const Int_t kIntUndefined = -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],&kIntUndefined,  8*fLen);
      j += fLen;
   }
}

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

   if (fIsUnsigned) {
      ULong64_t *uvalue = (ULong64_t*)GetValuePointer();
      printf("%llu",uvalue[l]);
   } else {
      Long64_t *value = (Long64_t*)GetValuePointer();
      printf("%lld",value[l]);
   }
}

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

   if (!fLeafCount && fNdata == 1) {
      b.ReadLong64(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 TLeafL::ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
{
//*-*-*-*-*-*-*-*-*-*-*Read leaf elements from Basket input buffer*-*-*-*-*-*
//  and export buffer to TClonesArray objects

   if (n*fLen == 1) {
      b >> fValue[0];
   } else {
      b.ReadFastArray(fValue,n*fLen);
   }
   Long64_t *value = fValue;
   for (Int_t i=0;i<n;i++) {
      char *first = (char*)list->UncheckedAt(i);
      Long64_t *ii = (Long64_t*)&first[fOffset];
      for (Int_t j=0;j<fLen;j++) {
         ii[j] = value[j];
      }
      value += fLen;
   }
}

//______________________________________________________________________________
void TLeafL::ReadValue(istream &s)
{
// read a long integer from istream s and store it into the branch buffer
#if defined(_MSC_VER) && (_MSC_VER<1300)
   printf("Due to a bug in VC++6, the function TLeafL::ReadValue is dummy\n");
#else
   if (fIsUnsigned) {
      ULong64_t *uvalue = (ULong64_t*)GetValuePointer();
      for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
   } else {
      Long64_t *value = (Long64_t*)GetValuePointer();
      for (Int_t i=0;i<fLen;i++) s >> value[i];
   }
#endif
}

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

   if (ResetAddress(add) && (add!=fValue)) {
      delete [] fValue;
   }
   if (add) {
      if (TestBit(kIndirectAddress)) {
         fPointer = (Long64_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 Long64_t[fNdata];
         }
         fValue = *fPointer;
      } else {
         fValue = (Long64_t*)add;
      }
   } else {
      fValue = new Long64_t[fNdata];
      fValue[0] = 0;
   }
}

 TLeafL.cxx:1
 TLeafL.cxx:2
 TLeafL.cxx:3
 TLeafL.cxx:4
 TLeafL.cxx:5
 TLeafL.cxx:6
 TLeafL.cxx:7
 TLeafL.cxx:8
 TLeafL.cxx:9
 TLeafL.cxx:10
 TLeafL.cxx:11
 TLeafL.cxx:12
 TLeafL.cxx:13
 TLeafL.cxx:14
 TLeafL.cxx:15
 TLeafL.cxx:16
 TLeafL.cxx:17
 TLeafL.cxx:18
 TLeafL.cxx:19
 TLeafL.cxx:20
 TLeafL.cxx:21
 TLeafL.cxx:22
 TLeafL.cxx:23
 TLeafL.cxx:24
 TLeafL.cxx:25
 TLeafL.cxx:26
 TLeafL.cxx:27
 TLeafL.cxx:28
 TLeafL.cxx:29
 TLeafL.cxx:30
 TLeafL.cxx:31
 TLeafL.cxx:32
 TLeafL.cxx:33
 TLeafL.cxx:34
 TLeafL.cxx:35
 TLeafL.cxx:36
 TLeafL.cxx:37
 TLeafL.cxx:38
 TLeafL.cxx:39
 TLeafL.cxx:40
 TLeafL.cxx:41
 TLeafL.cxx:42
 TLeafL.cxx:43
 TLeafL.cxx:44
 TLeafL.cxx:45
 TLeafL.cxx:46
 TLeafL.cxx:47
 TLeafL.cxx:48
 TLeafL.cxx:49
 TLeafL.cxx:50
 TLeafL.cxx:51
 TLeafL.cxx:52
 TLeafL.cxx:53
 TLeafL.cxx:54
 TLeafL.cxx:55
 TLeafL.cxx:56
 TLeafL.cxx:57
 TLeafL.cxx:58
 TLeafL.cxx:59
 TLeafL.cxx:60
 TLeafL.cxx:61
 TLeafL.cxx:62
 TLeafL.cxx:63
 TLeafL.cxx:64
 TLeafL.cxx:65
 TLeafL.cxx:66
 TLeafL.cxx:67
 TLeafL.cxx:68
 TLeafL.cxx:69
 TLeafL.cxx:70
 TLeafL.cxx:71
 TLeafL.cxx:72
 TLeafL.cxx:73
 TLeafL.cxx:74
 TLeafL.cxx:75
 TLeafL.cxx:76
 TLeafL.cxx:77
 TLeafL.cxx:78
 TLeafL.cxx:79
 TLeafL.cxx:80
 TLeafL.cxx:81
 TLeafL.cxx:82
 TLeafL.cxx:83
 TLeafL.cxx:84
 TLeafL.cxx:85
 TLeafL.cxx:86
 TLeafL.cxx:87
 TLeafL.cxx:88
 TLeafL.cxx:89
 TLeafL.cxx:90
 TLeafL.cxx:91
 TLeafL.cxx:92
 TLeafL.cxx:93
 TLeafL.cxx:94
 TLeafL.cxx:95
 TLeafL.cxx:96
 TLeafL.cxx:97
 TLeafL.cxx:98
 TLeafL.cxx:99
 TLeafL.cxx:100
 TLeafL.cxx:101
 TLeafL.cxx:102
 TLeafL.cxx:103
 TLeafL.cxx:104
 TLeafL.cxx:105
 TLeafL.cxx:106
 TLeafL.cxx:107
 TLeafL.cxx:108
 TLeafL.cxx:109
 TLeafL.cxx:110
 TLeafL.cxx:111
 TLeafL.cxx:112
 TLeafL.cxx:113
 TLeafL.cxx:114
 TLeafL.cxx:115
 TLeafL.cxx:116
 TLeafL.cxx:117
 TLeafL.cxx:118
 TLeafL.cxx:119
 TLeafL.cxx:120
 TLeafL.cxx:121
 TLeafL.cxx:122
 TLeafL.cxx:123
 TLeafL.cxx:124
 TLeafL.cxx:125
 TLeafL.cxx:126
 TLeafL.cxx:127
 TLeafL.cxx:128
 TLeafL.cxx:129
 TLeafL.cxx:130
 TLeafL.cxx:131
 TLeafL.cxx:132
 TLeafL.cxx:133
 TLeafL.cxx:134
 TLeafL.cxx:135
 TLeafL.cxx:136
 TLeafL.cxx:137
 TLeafL.cxx:138
 TLeafL.cxx:139
 TLeafL.cxx:140
 TLeafL.cxx:141
 TLeafL.cxx:142
 TLeafL.cxx:143
 TLeafL.cxx:144
 TLeafL.cxx:145
 TLeafL.cxx:146
 TLeafL.cxx:147
 TLeafL.cxx:148
 TLeafL.cxx:149
 TLeafL.cxx:150
 TLeafL.cxx:151
 TLeafL.cxx:152
 TLeafL.cxx:153
 TLeafL.cxx:154
 TLeafL.cxx:155
 TLeafL.cxx:156
 TLeafL.cxx:157
 TLeafL.cxx:158
 TLeafL.cxx:159
 TLeafL.cxx:160
 TLeafL.cxx:161
 TLeafL.cxx:162
 TLeafL.cxx:163
 TLeafL.cxx:164
 TLeafL.cxx:165
 TLeafL.cxx:166
 TLeafL.cxx:167
 TLeafL.cxx:168
 TLeafL.cxx:169
 TLeafL.cxx:170
 TLeafL.cxx:171
 TLeafL.cxx:172
 TLeafL.cxx:173
 TLeafL.cxx:174
 TLeafL.cxx:175
 TLeafL.cxx:176
 TLeafL.cxx:177
 TLeafL.cxx:178
 TLeafL.cxx:179
 TLeafL.cxx:180
 TLeafL.cxx:181
 TLeafL.cxx:182
 TLeafL.cxx:183
 TLeafL.cxx:184
 TLeafL.cxx:185
 TLeafL.cxx:186
 TLeafL.cxx:187
 TLeafL.cxx:188
 TLeafL.cxx:189
 TLeafL.cxx:190
 TLeafL.cxx:191
 TLeafL.cxx:192
 TLeafL.cxx:193
 TLeafL.cxx:194
 TLeafL.cxx:195
 TLeafL.cxx:196
 TLeafL.cxx:197
 TLeafL.cxx:198
 TLeafL.cxx:199
 TLeafL.cxx:200
 TLeafL.cxx:201
 TLeafL.cxx:202
 TLeafL.cxx:203
 TLeafL.cxx:204
 TLeafL.cxx:205
 TLeafL.cxx:206
 TLeafL.cxx:207
 TLeafL.cxx:208
 TLeafL.cxx:209
 TLeafL.cxx:210
 TLeafL.cxx:211
 TLeafL.cxx:212
 TLeafL.cxx:213
 TLeafL.cxx:214
 TLeafL.cxx:215
 TLeafL.cxx:216
 TLeafL.cxx:217
 TLeafL.cxx:218
 TLeafL.cxx:219
 TLeafL.cxx:220
 TLeafL.cxx:221
 TLeafL.cxx:222
 TLeafL.cxx:223
 TLeafL.cxx:224
 TLeafL.cxx:225
 TLeafL.cxx:226
 TLeafL.cxx:227
 TLeafL.cxx:228
 TLeafL.cxx:229
 TLeafL.cxx:230
 TLeafL.cxx:231
 TLeafL.cxx:232
 TLeafL.cxx:233
 TLeafL.cxx:234
 TLeafL.cxx:235
 TLeafL.cxx:236
 TLeafL.cxx:237
 TLeafL.cxx:238
 TLeafL.cxx:239
 TLeafL.cxx:240
 TLeafL.cxx:241
 TLeafL.cxx:242
 TLeafL.cxx:243
 TLeafL.cxx:244
 TLeafL.cxx:245
 TLeafL.cxx:246
 TLeafL.cxx:247
 TLeafL.cxx:248