ROOT logo
// @(#)root/tree:$Id: TLeafO.cxx 20882 2007-11-19 11:31:26Z rdm $
// Author: Philippe Canal  20/1/05

/*************************************************************************
 * Copyright (C) 1995-2005, 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 bool data type.                                        //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

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

ClassImp(TLeafO)

//______________________________________________________________________________
TLeafO::TLeafO(): TLeaf()
{
//*-*-*-*-*-*Default constructor for LeafB*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ============================

   fValue = 0;
   fPointer = 0;
}

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

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

//______________________________________________________________________________
TLeafO::~TLeafO()
{
//*-*-*-*-*-*Default destructor for a LeafB*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ===============================

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


//______________________________________________________________________________
void TLeafO::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], fLen);
      j += fLen;
   }
}


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

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

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

   return "Bool_t";
}


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

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

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

   char *value = (char*)GetValuePointer();
   printf("%d",(Int_t)value[l]);
}


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

   if (!fLeafCount && fNdata == 1) {
      b >> fValue[0];
   }else {
      if (fLeafCount) {
         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 TLeafO::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], fLen);
      j += fLen;
   }
}

//______________________________________________________________________________
void TLeafO::ReadValue(ifstream &s)
{
// read a string from ifstream s and store it into the branch buffer
   char *value = (char*)GetValuePointer();
   s >> value;
}

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

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