#include "TLeaf.h"
#include "TBranch.h"
#include "TTree.h"
#include "TVirtualPad.h"
#include "TBrowser.h"
#include "TClass.h"
#include <ctype.h>
R__EXTERN TTree *gTree;
R__EXTERN TBranch *gBranch;
ClassImp(TLeaf)
TLeaf::TLeaf(): TNamed()
{
fLen = 0;
fBranch = gBranch;
fLeafCount = 0;
fNdata = 0;
fOffset = 0;
}
TLeaf::TLeaf(const char *name, const char *)
:TNamed(name,name)
{
fBranch = 0;
fIsRange = 0;
fIsUnsigned = 0;
fLenType = 4;
fNdata = 0;
fOffset = 0;
fLeafCount = GetLeafCounter(fLen);
if (fLen == -1) {
MakeZombie();
return;
}
if (fLeafCount || strchr(name,'[')) {
char newname[64];
strcpy(newname,name);
char *bracket = strchr(newname,'[');
*bracket = 0;
SetName(newname);
}
fBranch = gBranch;
}
TLeaf::TLeaf(const TLeaf& lf) :
TNamed(lf),
fNdata(lf.fNdata),
fLen(lf.fLen),
fLenType(lf.fLenType),
fOffset(lf.fOffset),
fIsRange(lf.fIsRange),
fIsUnsigned(lf.fIsUnsigned),
fLeafCount(lf.fLeafCount),
fBranch(lf.fBranch)
{
}
TLeaf& TLeaf::operator=(const TLeaf& lf)
{
if(this!=&lf) {
TNamed::operator=(lf);
fNdata=lf.fNdata;
fLen=lf.fLen;
fLenType=lf.fLenType;
fOffset=lf.fOffset;
fIsRange=lf.fIsRange;
fIsUnsigned=lf.fIsUnsigned;
fLeafCount=lf.fLeafCount;
fBranch=lf.fBranch;
}
return *this;
}
TLeaf::~TLeaf()
{
if (!fBranch) return;
TTree *tree = fBranch->GetTree();
fBranch = 0;
if (!tree) return;
tree->GetListOfLeaves()->Remove(this);
}
void TLeaf::Browse(TBrowser *b)
{
char name[64];
if (strchr(GetName(),'.')) {
fBranch->GetTree()->Draw(GetName(), "", b ? b->GetDrawOption() : "");
} else {
if (fBranch->GetListOfLeaves()->GetEntries()>1 ||
strcmp(fBranch->GetName(),GetName()) != 0 ) {
sprintf(name,"%s.%s",fBranch->GetName(),GetName());
fBranch->GetTree()->Draw(name, "", b ? b->GetDrawOption() : "");
} else {
fBranch->GetTree()->Draw(GetName(), "", b ? b->GetDrawOption() : "");
}
}
if (gPad) gPad->Update();
}
void TLeaf::FillBasket(TBuffer &)
{
}
TLeaf *TLeaf::GetLeafCounter(Int_t &countval) const
{
countval = 1;
const char *name = GetTitle();
char *bleft = (char*)strchr(name,'[');
if (!bleft) return 0;
bleft++;
Int_t nch = strlen(bleft);
char *countname = new char[nch+1];
strcpy(countname,bleft);
char *bright = (char*)strchr(countname,']');
if (!bright) { delete [] countname; return 0;}
char *bleft2 = (char*)strchr(countname,'[');
*bright = 0; nch = strlen(countname);
TTree* pTree = fBranch ? fBranch->GetTree() : gTree;
if (!pTree) pTree = gTree;
TLeaf *leaf = (TLeaf*) pTree->GetListOfLeaves()->FindObject(countname);
if (!leaf && strchr(GetName(),'.')) {
char *withdot = new char[1000];
strcpy(withdot,GetName());
char *lastdot = strrchr(withdot,'.');
strcpy(lastdot,countname);
leaf = (TLeaf*) pTree->GetListOfLeaves()->FindObject(countname);
delete [] withdot;
}
Int_t i;
if (leaf) {
countval = 1;
leaf->SetRange();
if (bleft2) {
sscanf(bleft2,"[%d]",&i);
countval *= i;
}
bleft = bleft2;
while(bleft) {
bleft2++;
bleft = (char*)strchr(bleft2,'[');
if (!bleft) break;
sscanf(bleft,"[%d]",&i);
countval *= i;
bleft2 = bleft;
}
delete [] countname;
return leaf;
}
for (i=0;i<nch;i++) {
if (!isdigit(countname[i])) {
delete [] countname;
countval = -1;
return 0;
}
}
sscanf(countname,"%d",&countval);
if (bleft2) {
sscanf(bleft2,"[%d]",&i);
countval *= i;
}
bleft = bleft2;
while(bleft) {
bleft2++;
bleft = (char*)strchr(bleft2,'[');
if (!bleft) break;
sscanf(bleft,"[%d]",&i);
countval *= i;
bleft2 = bleft;
}
delete [] countname;
return 0;
}
Int_t TLeaf::GetLen() const
{
Int_t len;
if (fLeafCount) {
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();
}
return len*fLen;
} else {
return fLen;
}
}
Int_t TLeaf::ResetAddress(void *add, Bool_t destructor)
{
Int_t todelete = 0;
if (TestBit(kNewValue)) todelete = 1;
if (destructor) return todelete;
if (fLeafCount) fNdata = fLen*(fLeafCount->GetMaximum() + 1);
else fNdata = fLen;
ResetBit(kNewValue);
if (!add) SetBit(kNewValue);
return todelete;
}
void TLeaf::SetLeafCount(TLeaf *leaf)
{
if (IsZombie() && fLen==-1 && leaf) {
ResetBit(kZombie);
fLen = 1;
}
fLeafCount=leaf;
}
void TLeaf::Streamer(TBuffer &b)
{
if (b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = b.ReadVersion(&R__s, &R__c);
if (R__v > 1) {
TLeaf::Class()->ReadBuffer(b, this, R__v, R__s, R__c);
} else {
TNamed::Streamer(b);
b >> fLen;
b >> fLenType;
b >> fOffset;
b >> fIsRange;
b >> fIsUnsigned;
b >> fLeafCount;
b.CheckByteCount(R__s, R__c, TLeaf::IsA());
}
if (fLen == 0) fLen = 1;
ResetBit(kNewValue);
SetAddress();
} else {
TLeaf::Class()->WriteBuffer(b,this);
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.