Skip to content

Commit

Permalink
Add new class TLeafL to support Long64_t, ULong64_t data types in a T…
Browse files Browse the repository at this point in the history
…Branch

git-svn-id: http://root.cern.ch/svn/root/trunk@7786 27541ba8-7e3a-0410-8455-c3a389f83636
  • Loading branch information
Rene Brun authored and Rene Brun committed Dec 19, 2003
1 parent 7d8533f commit 57b449d
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tree/inc/LinkDef.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @(#)root/tree:$Name: $:$Id: LinkDef.h,v 1.14 2003/03/19 13:07:59 brun Exp $ */
/* @(#)root/tree:$Name: $:$Id: LinkDef.h,v 1.15 2003/11/13 15:15:11 rdm Exp $ */

/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
Expand Down Expand Up @@ -34,6 +34,7 @@
#pragma link C++ class TLeafF+;
#pragma link C++ class TLeafI+;
#pragma link C++ class TLeafS+;
#pragma link C++ class TLeafL+;
#pragma link C++ class TNtuple-;
#pragma link C++ class TNtupleD-;
#pragma link C++ class+protected TSelector+;
Expand Down
60 changes: 60 additions & 0 deletions tree/inc/TLeafL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// @(#)root/tree:$Name: $:$Id: TLeafL.h,v 1.6 2003/06/04 05:59:17 brun Exp $
// Author: Rene Brun 19/12/2003

/*************************************************************************
* 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. *
*************************************************************************/

#ifndef ROOT_TLeafL
#define ROOT_TLeafL


//////////////////////////////////////////////////////////////////////////
// //
// TLeafL //
// //
// A TLeaf for a 64 bit integer data type. //
// //
//////////////////////////////////////////////////////////////////////////


#ifndef ROOT_TLeaf
#include "TLeaf.h"
#endif

class TLeafL : public TLeaf {

protected:
Long64_t fMinimum; //Minimum value if leaf range is specified
Long64_t fMaximum; //Maximum value if leaf range is specified
Long64_t *fValue; //!Pointer to data buffer
Long64_t **fPointer; //!Address of pointer to data buffer

public:
TLeafL();
TLeafL(const char *name, const char *type);
virtual ~TLeafL();

virtual void Export(TClonesArray *list, Int_t n);
virtual void FillBasket(TBuffer &b);
const char *GetTypeName() const;
virtual Int_t GetMaximum() const {return (Int_t)fMaximum;}
virtual Int_t GetMinimum() const {return (Int_t)fMinimum;}
Double_t GetValue(Int_t i=0) const;
virtual void *GetValuePointer() const {return fValue;}
virtual void Import(TClonesArray *list, Int_t n);
virtual void PrintValue(Int_t i=0) const;
virtual void ReadBasket(TBuffer &b);
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n);
virtual void SetAddress(void *add=0);
virtual void SetMaximum(Long64_t max) {fMaximum = max;}
virtual void SetMinimum(Long64_t min) {fMinimum = min;}

ClassDef(TLeafL,1) //A TLeaf for a 64 bit Integer data type.
};

#endif
10 changes: 9 additions & 1 deletion tree/src/TBranch.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @(#)root/tree:$Name: $:$Id: TBranch.cxx,v 1.62 2003/11/12 09:06:11 brun Exp $
// @(#)root/tree:$Name: $:$Id: TBranch.cxx,v 1.63 2003/12/08 15:55:24 brun Exp $
// Author: Rene Brun 12/01/96

/*************************************************************************
Expand Down Expand Up @@ -26,6 +26,7 @@
#include "TLeafF.h"
#include "TLeafS.h"
#include "TLeafD.h"
#include "TLeafL.h"
#include "TMessage.h"
#include "TClonesArray.h"
#include "TVirtualPad.h"
Expand Down Expand Up @@ -116,6 +117,8 @@ TBranch::TBranch(const char *name, void *address, const char *leaflist, Int_t ba
// - i : a 32 bit unsigned integer (UInt_t)
// - F : a 32 bit floating point (Float_t)
// - D : a 64 bit floating point (Double_t)
// - L : a 64 bit signed integer (Long64_t)
// - l : a 64 bit unsigned integer (ULong64_t)
//
// By default, a variable will be copied to the buffer with the number of
// bytes specified in the type descriptor character. However, if the type
Expand Down Expand Up @@ -205,6 +208,11 @@ TBranch::TBranch(const char *name, void *address, const char *leaflist, Int_t ba
leaf->SetUnsigned();
} else if (*leaftype == 'F') {
leaf = new TLeafF(leafname,leaftype);
} else if (*leaftype == 'L') {
leaf = new TLeafL(leafname,leaftype);
} else if (*leaftype == 'l') {
leaf = new TLeafL(leafname,leaftype);
leaf->SetUnsigned();
} else if (*leaftype == 'D') {
leaf = new TLeafD(leafname,leaftype);
}
Expand Down
216 changes: 216 additions & 0 deletions tree/src/TLeafL.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// @(#)root/tree:$Name: $:$Id: TLeafL.cxx,v 1.15 2002/09/09 19:52:11 brun Exp $
// 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"

ClassImp(TLeafL)

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

fValue = 0;
fPointer = 0;
}

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

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

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

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 (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

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 >> 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 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::SetAddress(void *add)
{
//*-*-*-*-*-*-*-*-*-*-*Set leaf buffer data address*-*-*-*-*-*
//*-* ============================

if (ResetAddress(add)) {
delete [] fValue;
}
if (add) {
if (TestBit(kIndirectAddress)) {
fPointer = (Long64_t**) add;
Int_t ncountmax = fLen;
if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
if (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;
}
}

5 changes: 4 additions & 1 deletion tree/src/TTree.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @(#)root/tree:$Name: $:$Id: TTree.cxx,v 1.170 2003/12/16 17:02:48 brun Exp $
// @(#)root/tree:$Name: $:$Id: TTree.cxx,v 1.171 2003/12/18 13:21:33 brun Exp $
// Author: Rene Brun 12/01/96

/*************************************************************************
Expand Down Expand Up @@ -71,6 +71,8 @@
// - i : a 32 bit unsigned integer (UInt_t)
// - F : a 32 bit floating point (Float_t)
// - D : a 64 bit floating point (Double_t)
// - L : a 64 bit signed integer (Long64_t)
// - l : a 64 bit unsigned integer (ULong64_t)
//
// ==> Case B
// ======
Expand Down Expand Up @@ -272,6 +274,7 @@
#include "TLeafF.h"
#include "TLeafS.h"
#include "TLeafD.h"
#include "TLeafL.h"
#include "TLeafElement.h"
#include "TBasket.h"
#include "TMath.h"
Expand Down

0 comments on commit 57b449d

Please sign in to comment.