#include "TBranch.h"
#include "TBasket.h"
#include "TBranchBrowsable.h"
#include "TBrowser.h"
#include "TClass.h"
#include "TBufferFile.h"
#include "TClonesArray.h"
#include "TFile.h"
#include "TLeaf.h"
#include "TLeafB.h"
#include "TLeafC.h"
#include "TLeafD.h"
#include "TLeafF.h"
#include "TLeafI.h"
#include "TLeafL.h"
#include "TLeafO.h"
#include "TLeafObject.h"
#include "TLeafS.h"
#include "TMessage.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TMath.h"
#include "TTree.h"
#include "TTreeCache.h"
#include "TTreeCacheUnzip.h"
#include "TVirtualPad.h"
#include <cstddef>
#include <string.h>
#include <stdio.h>
R__EXTERN TTree* gTree;
Int_t TBranch::fgCount = 0;
const Int_t kMaxRAM = 10;
ClassImp(TBranch)
TBranch::TBranch()
: TNamed()
, TAttFill(0, 1001)
, fCompress(0)
, fBasketSize(32000)
, fEntryOffsetLen(1000)
, fWriteBasket(0)
, fEntryNumber(0)
, fOffset(0)
, fMaxBaskets(10)
, fSplitLevel(0)
, fNleaves(0)
, fReadBasket(0)
, fReadEntry(-1)
, fEntries(0)
, fFirstEntry(0)
, fTotBytes(0)
, fZipBytes(0)
, fBranches()
, fLeaves()
, fBaskets(fMaxBaskets)
, fNBasketRAM(kMaxRAM+1)
, fBasketRAM(0)
, fBasketBytes(0)
, fBasketEntry(0)
, fBasketSeek(0)
, fTree(0)
, fMother(0)
, fParent(0)
, fAddress(0)
, fDirectory(0)
, fFileName("")
, fEntryBuffer(0)
, fBrowsables(0)
, fSkipZip(kFALSE)
{
fBasketRAM = new Int_t[kMaxRAM];
for (Int_t i = 0; i < kMaxRAM; ++i) {
fBasketRAM[i] = -1;
}
}
TBranch::TBranch(TTree *tree, const char* name, void* address, const char* leaflist, Int_t basketsize, Int_t compress)
: TNamed(name, leaflist)
, TAttFill(0, 1001)
, fCompress(compress)
, fBasketSize((basketsize < 100) ? 100 : basketsize)
, fEntryOffsetLen(0)
, fWriteBasket(0)
, fEntryNumber(0)
, fOffset(0)
, fMaxBaskets(10)
, fSplitLevel(0)
, fNleaves(0)
, fReadBasket(0)
, fReadEntry(-1)
, fEntries(0)
, fFirstEntry(0)
, fTotBytes(0)
, fZipBytes(0)
, fBranches()
, fLeaves()
, fBaskets(fMaxBaskets)
, fNBasketRAM(kMaxRAM+1)
, fBasketRAM(0)
, fBasketBytes(0)
, fBasketEntry(0)
, fBasketSeek(0)
, fTree(tree)
, fMother(0)
, fParent(0)
, fAddress((char*) address)
, fDirectory(fTree->GetDirectory())
, fFileName("")
, fEntryBuffer(0)
, fBrowsables(0)
, fSkipZip(kFALSE)
{
Init(name,leaflist,compress);
}
TBranch::TBranch(TBranch *parent, const char* name, void* address, const char* leaflist, Int_t basketsize, Int_t compress)
: TNamed(name, leaflist)
, TAttFill(0, 1001)
, fCompress(compress)
, fBasketSize((basketsize < 100) ? 100 : basketsize)
, fEntryOffsetLen(0)
, fWriteBasket(0)
, fEntryNumber(0)
, fOffset(0)
, fMaxBaskets(10)
, fSplitLevel(0)
, fNleaves(0)
, fReadBasket(0)
, fReadEntry(-1)
, fEntries(0)
, fFirstEntry(0)
, fTotBytes(0)
, fZipBytes(0)
, fBranches()
, fLeaves()
, fBaskets(fMaxBaskets)
, fNBasketRAM(kMaxRAM+1)
, fBasketRAM(0)
, fBasketBytes(0)
, fBasketEntry(0)
, fBasketSeek(0)
, fTree(parent ? parent->GetTree() : 0)
, fMother(parent ? parent->GetMother() : 0)
, fParent(parent)
, fAddress((char*) address)
, fDirectory(fTree->GetDirectory())
, fFileName("")
, fEntryBuffer(0)
, fBrowsables(0)
, fSkipZip(kFALSE)
{
Init(name,leaflist,compress);
}
void TBranch::Init(const char* name, const char* leaflist, Int_t compress)
{
if ((compress == -1) && fTree->GetDirectory()) {
TFile* bfile = fTree->GetDirectory()->GetFile();
if (bfile) {
fCompress = bfile->GetCompressionLevel();
}
}
fBasketRAM = new Int_t[kMaxRAM];
for (Int_t i = 0; i < kMaxRAM; ++i) {
fBasketRAM[i] = -1;
}
fBasketBytes = new Int_t[fMaxBaskets];
fBasketEntry = new Long64_t[fMaxBaskets];
fBasketSeek = new Long64_t[fMaxBaskets];
for (Int_t i = 0; i < fMaxBaskets; ++i) {
fBasketBytes[i] = 0;
fBasketEntry[i] = 0;
fBasketSeek[i] = 0;
}
char* nameBegin = const_cast<char*>(leaflist);
Int_t offset = 0;
char* leafname = new char[640];
char* leaftype = new char[320];
strcpy(leaftype, "F");
char* pos = const_cast<char*>(leaflist);
const char* leaflistEnd = leaflist + strlen(leaflist);
for (; pos <= leaflistEnd; ++pos) {
if ((*pos == ':') || (*pos == 0)) {
Int_t lenName = pos - nameBegin;
char* ctype = 0;
if (lenName) {
strncpy(leafname, nameBegin, lenName);
leafname[lenName] = 0;
ctype = strstr(leafname, "/");
if (ctype) {
*ctype = 0;
strcpy(leaftype, ctype + 1);
}
}
if (lenName == 0 || ctype == leafname) {
Warning("TBranch","No name was given to the leaf number '%d' in the leaflist of the branch '%s'.",fNleaves,name);
sprintf(leafname,"__noname%d",fNleaves);
}
TLeaf* leaf = 0;
if (*leaftype == 'C') {
leaf = new TLeafC(this, leafname, leaftype);
} else if (*leaftype == 'O') {
leaf = new TLeafO(this, leafname, leaftype);
} else if (*leaftype == 'B') {
leaf = new TLeafB(this, leafname, leaftype);
} else if (*leaftype == 'b') {
leaf = new TLeafB(this, leafname, leaftype);
leaf->SetUnsigned();
} else if (*leaftype == 'S') {
leaf = new TLeafS(this, leafname, leaftype);
} else if (*leaftype == 's') {
leaf = new TLeafS(this, leafname, leaftype);
leaf->SetUnsigned();
} else if (*leaftype == 'I') {
leaf = new TLeafI(this, leafname, leaftype);
} else if (*leaftype == 'i') {
leaf = new TLeafI(this, leafname, leaftype);
leaf->SetUnsigned();
} else if (*leaftype == 'F') {
leaf = new TLeafF(this, leafname, leaftype);
} else if (*leaftype == 'f') {
leaf = new TLeafF(this, leafname, leaftype);
} else if (*leaftype == 'L') {
leaf = new TLeafL(this, leafname, leaftype);
} else if (*leaftype == 'l') {
leaf = new TLeafL(this, leafname, leaftype);
leaf->SetUnsigned();
} else if (*leaftype == 'D') {
leaf = new TLeafD(this, leafname, leaftype);
} else if (*leaftype == 'd') {
leaf = new TLeafD(this, leafname, leaftype);
}
if (!leaf) {
Error("TLeaf", "Illegal data type for %s/%s", name, leaflist);
MakeZombie();
return;
}
if (leaf->IsZombie()) {
delete leaf;
leaf = 0;
Error("TBranch", "Illegal leaf: %s/%s", name, leaflist);
MakeZombie();
return;
}
leaf->SetBranch(this);
leaf->SetAddress((char*) (fAddress + offset));
leaf->SetOffset(offset);
if (leaf->GetLeafCount()) {
fEntryOffsetLen = 1000;
}
if (leaf->InheritsFrom("TLeafC")) {
fEntryOffsetLen = 1000;
}
++fNleaves;
fLeaves.Add(leaf);
fTree->GetListOfLeaves()->Add(leaf);
if (*pos == 0) {
break;
}
nameBegin = pos + 1;
offset += leaf->GetLenType() * leaf->GetLen();
}
}
delete[] leafname;
leafname = 0;
delete[] leaftype;
leaftype = 0;
}
TBranch::~TBranch()
{
delete fBrowsables;
fBrowsables = 0;
fEntryBuffer = 0;
delete [] fBasketSeek;
fBasketSeek = 0;
delete [] fBasketEntry;
fBasketEntry = 0;
delete [] fBasketBytes;
fBasketBytes = 0;
delete [] fBasketRAM;
fBasketRAM = 0;
fBaskets.Delete();
if (fTree) {
TObjArray* lst = fTree->GetListOfLeaves();
if (lst) {
lst->RemoveAll(&fLeaves);
}
}
fLeaves.Delete();
fBranches.Delete();
if (fDirectory && (fDirectory != fTree->GetDirectory())) {
TString bFileName( GetRealFileName() );
TFile* file = (TFile*)gROOT->GetListOfFiles()->FindObject(bFileName);
if (file){
file->Close();
delete file;
file = 0;
}
}
fTree = 0;
fDirectory = 0;
}
void TBranch::AddBasket(TBasket& b, Bool_t ondisk, Long64_t startEntry)
{
TBasket *basket = &b;
basket->SetBranch(this);
if (fWriteBasket >= fMaxBaskets) {
ExpandBasketArrays();
}
Int_t where = fWriteBasket;
if (where && startEntry < fBasketEntry[where-1]) {
if (!ondisk) {
Warning("AddBasket","The assumption that out-of-order basket only comes from disk based ntuple is false.");
}
if (startEntry < fBasketEntry[0]) {
where = 0;
} else {
for(Int_t i=fWriteBasket-1; i>=0; --i) {
if (fBasketEntry[i] < startEntry) {
where = i+1;
break;
} else if (fBasketEntry[i] == startEntry) {
Error("AddBasket","An out-of-order basket matches the entry number of an existing basket.");
}
}
}
if (where < fWriteBasket) {
for (Int_t j=fWriteBasket; j > where; --j) {
fBasketEntry[j] = fBasketEntry[j-1];
fBasketBytes[j] = fBasketBytes[j-1];
fBasketSeek[j] = fBasketSeek[j-1];
}
}
}
fBasketEntry[where] = startEntry;
if (ondisk) {
fBasketBytes[where] = basket->GetNbytes();
fBasketSeek[where] = basket->GetSeekKey();
fBaskets.AddAtAndExpand(0,fWriteBasket);
++fWriteBasket;
} else {
fBaskets.AddAtAndExpand(basket,fWriteBasket);
fTree->IncrementTotalBuffers(basket->GetBufferSize());
}
fEntries += basket->GetNevBuf();
fEntryNumber += basket->GetNevBuf();
if (ondisk) {
fTotBytes += basket->GetObjlen() + basket->GetKeylen() ;
fZipBytes += basket->GetNbytes();
fTree->AddTotBytes(basket->GetObjlen() + basket->GetKeylen());
fTree->AddZipBytes(basket->GetNbytes());
}
}
void TBranch::AddLastBasket(Long64_t startEntry)
{
if (fWriteBasket >= fMaxBaskets) {
ExpandBasketArrays();
}
Int_t where = fWriteBasket;
if (where && startEntry < fBasketEntry[where-1]) {
Fatal("AddBasket","The last basket must have the highest entry number (%s/%d/%d).",GetName(),startEntry,fWriteBasket);
}
fBasketEntry[where] = startEntry;
fBaskets.AddAtAndExpand(0,fWriteBasket);
}
void TBranch::Browse(TBrowser* b)
{
if (fNleaves > 1) {
fLeaves.Browse(b);
} else {
TString name = GetName();
Int_t pos = name.First('[');
if (pos!=kNPOS) name.Remove(pos);
GetTree()->Draw(name, "", b ? b->GetDrawOption() : "");
if (gPad) gPad->Update();
}
}
void TBranch::DeleteBaskets(Option_t* option)
{
TString opt = option;
opt.ToLower();
TFile *file = GetFile(0);
if(fDirectory && (fDirectory != gROOT) && fDirectory->IsWritable()) {
for(Int_t i=0; i<fWriteBasket; i++) {
if (fBasketSeek[i]) file->MakeFree(fBasketSeek[i],fBasketSeek[i]+fBasketBytes[i]-1);
}
}
if (opt.Contains("all")) {
TObjArray *lb = GetListOfBranches();
Int_t nb = lb->GetEntriesFast();
for (Int_t j = 0; j < nb; j++) {
TBranch* branch = (TBranch*) lb->UncheckedAt(j);
if (branch) branch->DeleteBaskets("all");
}
}
DropBaskets();
Reset();
}
void TBranch::DropBaskets(Option_t* option)
{
Bool_t all = kFALSE;
TString opt = option;
opt.ToLower();
if (opt.Contains("all"))
all = kTRUE;
Int_t i,j;
TBasket *basket;
if (fNBasketRAM < kMaxRAM) {
for (i=0;i<kMaxRAM;i++) {
j = fBasketRAM[i];
if (j < 0) continue;
if ((j == fReadBasket || j == fWriteBasket) && !all) continue;
basket = (TBasket*)fBaskets.UncheckedAt(j);
fBasketRAM[i] = -1;
fNBasketRAM--;
if (!basket) {
continue;
}
basket->DropBuffers();
GetListOfBaskets()->RemoveAt(j);
delete basket;
}
if (fNBasketRAM < 0) {
fNBasketRAM = 0;
}
i = 0;
for (j=0;j<kMaxRAM;j++) {
if (fBasketRAM[j] < 0) continue;
fBasketRAM[i] = fBasketRAM[j];
i++;
}
return;
}
Int_t nbaskets = GetListOfBaskets()->GetEntriesFast();
fNBasketRAM = 0;
for (j=0;j<nbaskets-1;j++) {
basket = (TBasket*)fBaskets.UncheckedAt(j);
if (!basket) continue;
if (fNBasketRAM < kMaxRAM) fBasketRAM[fNBasketRAM] = j;
fNBasketRAM++;
if ((j == fReadBasket || j == fWriteBasket) && !all) continue;
basket->DropBuffers();
GetListOfBaskets()->RemoveAt(j);
delete basket;
fNBasketRAM--;
fBasketRAM[fNBasketRAM] = -1;
if (!fTree->MemoryFull(0)) break;
}
if (all) {
TObjArray *lb = GetListOfBranches();
Int_t nb = lb->GetEntriesFast();
for (j = 0; j < nb; j++) {
TBranch* branch = (TBranch*) lb->UncheckedAt(j);
if (!branch) continue;
branch->DropBaskets("all");
}
}
}
void TBranch::ExpandBasketArrays()
{
Int_t newsize = TMath::Max(10,Int_t(1.5*fMaxBaskets));
fBasketBytes = TStorage::ReAllocInt(fBasketBytes, newsize, fMaxBaskets);
fBasketEntry = (Long64_t*)TStorage::ReAlloc(fBasketEntry,
newsize*sizeof(Long64_t),fMaxBaskets*sizeof(Long64_t));
fBasketSeek = (Long64_t*)TStorage::ReAlloc(fBasketSeek,
newsize*sizeof(Long64_t),fMaxBaskets*sizeof(Long64_t));
fMaxBaskets = newsize;
fBaskets.Expand(newsize);
for (Int_t i=fWriteBasket;i<fMaxBaskets;i++) {
fBasketBytes[i] = 0;
fBasketEntry[i] = 0;
fBasketSeek[i] = 0;
}
}
Int_t TBranch::Fill()
{
if (TestBit(kDoNotProcess)) {
return 0;
}
TBasket* basket = GetBasket(fWriteBasket);
if (!basket) {
basket = fTree->CreateBasket(this);
if (!basket) return 0;
fBaskets.AddAtAndExpand(basket,fWriteBasket);
}
TBuffer* buf = basket->GetBufferRef();
Int_t nsize = 0;
if (buf->IsReading()) {
basket->SetWriteMode();
}
buf->ResetMap();
Int_t lold = buf->Length();
Int_t objectStart = 0;
Int_t last = 0;
Int_t lnew = 0;
Int_t nbytes = 0;
if (fEntryBuffer) {
if (fEntryBuffer->IsA() == TMessage::Class()) {
objectStart = 8;
}
if (fEntryBuffer->TestBit(TBufferFile::kNotDecompressed)) {
if (basket->GetNevBuf()) {
WriteBasket(basket,fWriteBasket);
return Fill();
}
Int_t startpos = fEntryBuffer->Length();
fEntryBuffer->SetBufferOffset(0);
static TBasket toread_fLast;
fEntryBuffer->SetReadMode();
toread_fLast.Streamer(*fEntryBuffer);
fEntryBuffer->SetWriteMode();
last = toread_fLast.GetLast();
fEntryBuffer->SetBufferOffset(startpos);
buf->SetBufferOffset(0);
buf->SetBit(TBufferFile::kNotDecompressed);
basket->Update(lold);
} else {
const UInt_t kNewClassTag = 0xFFFFFFFF;
const UInt_t kByteCountMask = 0x40000000;
UInt_t tag = 0;
UInt_t startpos = fEntryBuffer->Length();
fEntryBuffer->SetBufferOffset(objectStart);
*fEntryBuffer >> tag;
if (tag & kByteCountMask) {
*fEntryBuffer >> tag;
}
if (tag == kNewClassTag) {
UInt_t maxsize = 256;
char* s = new char[maxsize];
Int_t name_start = fEntryBuffer->Length();
fEntryBuffer->ReadString(s, maxsize);
while (strlen(s) == (maxsize - 1)) {
fEntryBuffer->SetBufferOffset(name_start);
maxsize *= 2;
delete[] s;
s = new char[maxsize];
fEntryBuffer->ReadString(s, maxsize);
}
} else {
fEntryBuffer->SetBufferOffset(objectStart);
}
objectStart = fEntryBuffer->Length();
fEntryBuffer->SetBufferOffset(startpos);
basket->Update(lold, objectStart - fEntryBuffer->GetBufferDisplacement());
}
fEntries++;
fEntryNumber++;
UInt_t len = 0;
UInt_t startpos = fEntryBuffer->Length();
if (startpos > UInt_t(objectStart)) {
len = fEntryBuffer->Length() - objectStart;
} else {
len = fEntryBuffer->BufferSize() - objectStart;
}
buf->WriteBuf(fEntryBuffer->Buffer() + objectStart, len);
if (fEntryBuffer->TestBit(TBufferFile::kNotDecompressed)) {
nbytes = last;
lnew = last;
} else {
lnew = buf->Length();
nbytes = lnew - lold;
}
} else {
basket->Update(lold);
++fEntries;
++fEntryNumber;
FillLeaves(*buf);
lnew = buf->Length();
nbytes = lnew - lold;
}
if (fEntryOffsetLen) {
Int_t nevbuf = basket->GetNevBuf();
nsize = nevbuf * sizeof(Int_t);
} else {
if (!basket->GetNevBufSize()) {
basket->SetNevBufSize(nbytes);
}
}
if ((fSkipZip && (lnew >= TBuffer::kMinimalSize)) || (buf->TestBit(TBufferFile::kNotDecompressed)) || ((lnew + (2 * nsize) + nbytes) >= fBasketSize)) {
if (fTree->TestBit(TTree::kCircular)) {
return nbytes;
}
Int_t nout = WriteBasket(basket,fWriteBasket);
return (nout >= 0) ? nbytes : -1;
}
return nbytes;
}
void TBranch::FillLeaves(TBuffer& b)
{
for (Int_t i = 0; i < fNleaves; ++i) {
TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
leaf->FillBasket(b);
}
}
TBranch* TBranch::FindBranch(const char* name)
{
std::string longnm;
longnm.reserve(fName.Length()+strlen(name)+3);
longnm = fName.Data();
if (longnm[longnm.length()-1]==']') {
std::size_t dim = longnm.find_first_of("[");
if (dim != std::string::npos) {
longnm.erase(dim);
}
}
if (longnm[longnm.length()-1] != '.') {
longnm += '.';
}
longnm += name;
UInt_t namelen = strlen(name);
Int_t nbranches = fBranches.GetEntries();
TBranch* branch = 0;
for(Int_t i = 0; i < nbranches; ++i) {
branch = (TBranch*) fBranches.UncheckedAt(i);
const char *brname = branch->fName.Data();
UInt_t brlen = branch->fName.Length();
if (brname[brlen-1]==']') {
const char *dim = strchr(brname,'[');
if (dim) {
brlen = dim - brname;
}
}
if (namelen == brlen
&& strncmp(name,brname,brlen) == 0) {
return branch;
}
if (brlen == (size_t)longnm.length()
&& strncmp(longnm.c_str(),brname,brlen) == 0) {
return branch;
}
}
return 0;
}
TLeaf* TBranch::FindLeaf(const char* searchname)
{
TString leafname;
TString leaftitle;
TString longname;
TString longtitle;
TIter next(GetListOfLeaves());
TLeaf* leaf = 0;
while ((leaf = (TLeaf*) next())) {
leafname = leaf->GetName();
Ssiz_t dim = leafname.First('[');
if (dim >= 0) leafname.Remove(dim);
if (leafname == searchname) return leaf;
leaftitle = leaf->GetTitle();
dim = leaftitle.First('[');
if (dim >= 0) leaftitle.Remove(dim);
if (leaftitle == searchname) return leaf;
TBranch* branch = leaf->GetBranch();
if (branch) {
longname.Form("%s.%s",branch->GetName(),leafname.Data());
dim = longname.First('[');
if (dim>=0) longname.Remove(dim);
if (longname == searchname) return leaf;
longname.Form("%s.%s",branch->GetName(),searchname);
if (longname==leafname) return leaf;
longtitle.Form("%s.%s",branch->GetName(),leaftitle.Data());
dim = longtitle.First('[');
if (dim>=0) longtitle.Remove(dim);
if (longtitle == searchname) return leaf;
if (strstr(searchname, ".") && !strcmp(searchname, branch->GetName())) return leaf;
}
}
return 0;
}
Int_t TBranch::FlushBaskets()
{
UInt_t nerror = 0;
Int_t nbytes = 0;
for(Int_t i=0; i<=fWriteBasket; ++i) {
if (fBaskets.UncheckedAt(i)) {
Int_t nwrite = FlushOneBasket(i);
if (nwrite<0) {
++nerror;
} else {
nbytes += nwrite;
}
}
}
Int_t len = fBranches.GetEntriesFast();
for (Int_t i = 0; i < len; ++i) {
TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
if (!branch) {
continue;
}
Int_t nwrite = branch->FlushBaskets();
if (nwrite<0) {
++nerror;
} else {
nbytes += nwrite;
}
}
if (nerror) {
return -1;
} else {
return nbytes;
}
}
Int_t TBranch::FlushOneBasket(UInt_t ibasket)
{
Int_t nbytes = 0;
if (fDirectory && fBaskets.GetEntries()) {
TBasket *basket = (TBasket*)fBaskets.UncheckedAt(ibasket);
if (basket) {
if (basket->GetNevBuf()
&& fBasketSeek[ibasket]==0) {
if (basket->GetBufferRef()->IsReading()) {
basket->SetWriteMode();
}
nbytes = WriteBasket(basket,ibasket);
} else {
basket->DropBuffers();
delete basket;
fBaskets[ibasket] = 0;
}
}
}
return nbytes;
}
TBasket* TBranch::GetBasket(Int_t basketnumber)
{
static Int_t nerrors = 0;
if (basketnumber <0 || basketnumber > fWriteBasket) return 0;
TBasket *basket = (TBasket*)fBaskets.UncheckedAt(basketnumber);
if (basket) return basket;
if (basketnumber == fWriteBasket) return 0;
TFile *file = GetFile(0);
basket = new TBasket(file);
if (fSkipZip) basket->SetBit(TBufferFile::kNotDecompressed);
basket->SetBranch(this);
if (fBasketBytes[basketnumber] == 0) {
fBasketBytes[basketnumber] = basket->ReadBasketBytes(fBasketSeek[basketnumber],file);
}
TFileCacheRead *pf = file ? file->GetCacheRead() : 0;
if (pf && pf->InheritsFrom(TTreeCache::Class())){
TTreeCache *tpf = (TTreeCache*)pf;
tpf->AddBranch(this);
if (fSkipZip) tpf->SetSkipZip();
}
Int_t badread = basket->ReadBasketBuffers(fBasketSeek[basketnumber],fBasketBytes[basketnumber],file);
if (badread || basket->GetSeekKey() != fBasketSeek[basketnumber]) {
nerrors++;
if (nerrors > 10) return 0;
if (nerrors == 10) {
printf(" file probably overwritten: stopping reporting error messages\n");
if (fBasketSeek[basketnumber] > 2000000000) {
printf("===>File is more than 2 Gigabytes\n");
return 0;
}
if (fBasketSeek[basketnumber] > 1000000000) {
printf("===>Your file is may be bigger than the maximum file size allowed on your system\n");
printf(" Check your AFS maximum file size limit for example\n");
return 0;
}
}
Error("GetBasket","File: %s at byte:%lld, branch:%s, entry:%d, badread=%d, nerrors=%d, basketnumber=%d",file?file->GetName():"no file",basket->GetSeekKey(),GetName(),fReadEntry,badread,nerrors,basketnumber);
return 0;
}
fBaskets.AddAt(basket,basketnumber);
if (fNBasketRAM < kMaxRAM) fBasketRAM[fNBasketRAM] = basketnumber;
fNBasketRAM++;
return basket;
}
Long64_t TBranch::GetBasketSeek(Int_t basketnumber) const
{
if (basketnumber <0 || basketnumber > fWriteBasket) return 0;
return fBasketSeek[basketnumber];
}
TList* TBranch::GetBrowsables() {
if (fBrowsables) return fBrowsables;
fBrowsables=new TList();
TVirtualBranchBrowsable::FillListOfBrowsables(*fBrowsables, this);
return fBrowsables;
}
const char* TBranch::GetIconName() const
{
if (IsFolder())
return "TBranchElement-folder";
else
return "TBranchElement-leaf";
}
Int_t TBranch::GetEntry(Long64_t entry, Int_t getall)
{
if (TestBit(kDoNotProcess) && !getall) {
return 0;
}
if ((entry < fFirstEntry) || (entry >= fEntryNumber)) {
return 0;
}
Int_t nbytes = 0;
Long64_t first = fBasketEntry[fReadBasket];
Long64_t last = 0;
if (fReadBasket == fWriteBasket) {
last = fEntryNumber - 1;
} else {
last = fBasketEntry[fReadBasket+1] - 1;
}
if ((entry < first) || (entry > last)) {
fReadBasket = TMath::BinarySearch(fWriteBasket + 1, fBasketEntry, entry);
if (fReadBasket < 0) {
Error("In the branch %s, no basket contains the entry %d\n", GetName(), entry);
return -1;
}
first = fBasketEntry[fReadBasket];
}
TBasket* basket = (TBasket*) fBaskets.UncheckedAt(fReadBasket);
if (!basket) {
basket = GetBasket(fReadBasket);
if (!basket) {
return -1;
}
}
basket->PrepareBasket(entry);
TBuffer* buf = basket->GetBufferRef();
if (!buf) {
TFile* file = GetFile(0);
basket->ReadBasketBuffers(fBasketSeek[fReadBasket], fBasketBytes[fReadBasket], file);
buf = basket->GetBufferRef();
}
buf->ResetMap();
if (!buf->IsReading()) {
basket->SetReadMode();
}
Int_t* entryOffset = basket->GetEntryOffset();
Int_t bufbegin = 0;
if (entryOffset) {
bufbegin = entryOffset[entry-first];
} else {
bufbegin = basket->GetKeylen() + ((entry - first) * basket->GetNevBufSize());
}
buf->SetBufferOffset(bufbegin);
Int_t* displacement = basket->GetDisplacement();
if (displacement) {
buf->SetBufferDisplacement(displacement[entry-first]);
} else {
buf->SetBufferDisplacement();
}
fReadEntry = entry;
ReadLeaves(*buf);
nbytes = buf->Length() - bufbegin;
return nbytes;
}
Int_t TBranch::GetEntryExport(Long64_t entry, Int_t , TClonesArray* li, Int_t nentries)
{
if (TestBit(kDoNotProcess)) {
return 0;
}
if ((entry < 0) || (entry >= fEntryNumber)) {
return 0;
}
Int_t nbytes = 0;
Long64_t first = fBasketEntry[fReadBasket];
Long64_t last = 0;
if (fReadBasket == fWriteBasket) {
last = fEntryNumber - 1;
} else {
last = fBasketEntry[fReadBasket+1] - 1;
}
if ((entry < first) || (entry > last)) {
fReadBasket = TMath::BinarySearch(fWriteBasket + 1, fBasketEntry, entry);
first = fBasketEntry[fReadBasket];
}
TBasket* basket = GetBasket(fReadBasket);
if (!basket) {
return 0;
}
TBuffer* buf = basket->GetBufferRef();
if (!buf->IsReading()) {
basket->SetReadMode();
}
Int_t bufbegin = 0;
Int_t* entryOffset = basket->GetEntryOffset();
if (entryOffset) {
bufbegin = entryOffset[entry-first];
} else {
bufbegin = basket->GetKeylen() + ((entry - first) * basket->GetNevBufSize());
}
buf->SetBufferOffset(bufbegin);
Int_t* displacement = basket->GetDisplacement();
if (displacement) {
buf->SetBufferDisplacement(displacement[entry-first]);
} else {
buf->SetBufferDisplacement();
}
fReadEntry = entry;
TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(0);
leaf->ReadBasketExport(*buf, li, nentries);
nbytes = buf->Length() - bufbegin;
return nbytes;
}
TFile* TBranch::GetFile(Int_t mode)
{
if (fDirectory) return fDirectory->GetFile();
TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(fFileName.Data());
if (file) {
fDirectory = file;
return file;
}
if (fFileName.Length() == 0) return 0;
TString bFileName( GetRealFileName() );
{
TDirectory::TContext ctxt(0);
if (mode) file = TFile::Open(bFileName, "recreate");
else file = TFile::Open(bFileName);
}
if (!file) return 0;
if (file->IsZombie()) {delete file; return 0;}
fDirectory = (TDirectory*)file;
return file;
}
TLeaf* TBranch::GetLeaf(const char* name) const
{
Int_t i;
for (i=0;i<fNleaves;i++) {
TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
if (!strcmp(leaf->GetName(),name)) return leaf;
}
return 0;
}
TString TBranch::GetRealFileName() const
{
if (fFileName.Length()==0) {
return fFileName;
}
TString bFileName = fFileName;
char *bname = gSystem->ExpandPathName(fFileName.Data());
if (!gSystem->IsAbsoluteFileName(bname) && !strstr(bname, ":/") && fTree && fTree->GetCurrentFile()) {
const char *tfn = fTree->GetCurrentFile()->GetName();
TUrl arc(tfn);
if (strlen(arc.GetAnchor()) > 0) {
arc.SetAnchor(gSystem->BaseName(fFileName));
bFileName = arc.GetUrl();
} else {
char *tname = gSystem->ExpandPathName(tfn);
if (gSystem->IsAbsoluteFileName(tname) || strstr(tname, ":/")) {
bFileName = gSystem->DirName(tname);
bFileName += "/";
bFileName += fFileName;
}
delete [] tname;
}
}
delete [] bname;
return bFileName;
}
Int_t TBranch::GetRow(Int_t)
{
return 1;
}
TBranch* TBranch::GetMother() const
{
if (fMother) return fMother;
const TObjArray* array = fTree->GetListOfBranches();
Int_t n = array->GetEntriesFast();
for (Int_t i = 0; i < n; ++i) {
TBranch* branch = (TBranch*) array->UncheckedAt(i);
TBranch* parent = branch->GetSubBranch(this);
if (parent) {
const_cast<TBranch*>(this)->fMother = branch;
return branch;
}
}
return 0;
}
TBranch* TBranch::GetSubBranch(const TBranch* child) const
{
if (this == child) {
return (TBranch*) this;
}
if (child->fParent) {
return child->fParent;
}
Int_t len = fBranches.GetEntriesFast();
for (Int_t i = 0; i < len; ++i) {
TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
if (!branch) {
continue;
}
if (branch == child) {
return (TBranch*) this;
}
TBranch* parent = branch->GetSubBranch(child);
if (parent) {
return parent;
}
}
return 0;
}
Long64_t TBranch::GetTotalSize(Option_t * ) const
{
TBufferFile b(TBuffer::kWrite,10000);
TBranch::Class()->WriteBuffer(b,(TBranch*)this);
Long64_t totbytes = 0;
if (fZipBytes > 0) totbytes = fTotBytes;
return totbytes + b.Length();
}
Long64_t TBranch::GetTotBytes(Option_t *option) const
{
Long64_t totbytes = fTotBytes;
if (!option) return totbytes;
if (option[0] != '*') return totbytes;
Int_t len = fBranches.GetEntriesFast();
for (Int_t i = 0; i < len; ++i) {
TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
if (branch) totbytes += branch->GetTotBytes();
}
return totbytes;
}
Long64_t TBranch::GetZipBytes(Option_t *option) const
{
Long64_t zipbytes = fZipBytes;
if (!option) return zipbytes;
if (option[0] != '*') return zipbytes;
Int_t len = fBranches.GetEntriesFast();
for (Int_t i = 0; i < len; ++i) {
TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
if (branch) zipbytes += branch->GetZipBytes();
}
return zipbytes;
}
Bool_t TBranch::IsAutoDelete() const
{
return TestBit(kAutoDelete);
}
Bool_t TBranch::IsFolder() const
{
if (fNleaves > 1) {
return kTRUE;
}
TList* browsables = const_cast<TBranch*>(this)->GetBrowsables();
return browsables && browsables->GetSize();
}
void TBranch::KeepCircular(Long64_t maxEntries)
{
Int_t dentries = (Int_t) (fEntries - maxEntries);
TBasket* basket = (TBasket*) fBaskets.UncheckedAt(0);
basket->MoveEntries(dentries);
fEntries = maxEntries;
fEntryNumber = maxEntries;
Int_t nb = fBranches.GetEntriesFast();
for (Int_t i = 0; i < nb; ++i) {
TBranch* branch = (TBranch*) fBranches.UncheckedAt(i);
branch->KeepCircular(maxEntries);
}
}
Int_t TBranch::LoadBaskets()
{
Int_t nimported = 0;
Int_t nbaskets = fBaskets.GetEntriesFast();
TFile *file = GetFile(0);
TBasket *basket;
for (Int_t i=0;i<nbaskets;i++) {
basket = (TBasket*)fBaskets.UncheckedAt(i);
if (basket) continue;
basket = new TBasket(file);
basket->SetBranch(this);
if (fBasketBytes[i] == 0) {
fBasketBytes[i] = basket->ReadBasketBytes(fBasketSeek[i],file);
}
Int_t badread = basket->ReadBasketBuffers(fBasketSeek[i],fBasketBytes[i],file);
if (badread) {
Error("Loadbaskets","Error while reading basket buffer %d of branch %s",i,GetName());
return -1;
}
fBaskets.AddAt(basket,i);
nimported++;
}
fNBasketRAM = nimported;
return nimported;
}
void TBranch::Print(Option_t*) const
{
const int kLINEND = 77;
Float_t cx = 1;
Int_t titleLength = strlen (GetTitle());
if (strcmp(GetName(),GetTitle()) == 0) titleLength = 0;
Int_t aLength = titleLength + strlen(GetName());
aLength += (aLength / 54 + 1) * 80 + 100;
if (aLength < 200) aLength = 200;
char *bline = new char[aLength];
Long64_t totBytes = GetTotalSize();
if (fZipBytes) cx = (fTotBytes+0.00001)/fZipBytes;
if (titleLength) sprintf(bline,"*Br%5d :%-9s : %-54s *",fgCount,GetName(),GetTitle());
else sprintf(bline,"*Br%5d :%-9s : %-54s *",fgCount,GetName()," ");
if (strlen(bline) > UInt_t(kLINEND)) {
char *tmp = new char[strlen(bline)+1];
if (titleLength) strcpy(tmp, GetTitle());
sprintf(bline,"*Br%5d :%-9s : ",fgCount,GetName());
int pos = strlen (bline);
int npos = pos;
int beg=0, end;
while (beg < titleLength) {
for (end=beg+1; end < titleLength-1; end ++)
if (tmp[end] == ':') break;
if (npos + end-beg+1 >= 78) {
while (npos < kLINEND) {
bline[pos ++] = ' ';
npos ++;
}
bline[pos ++] = '*';
bline[pos ++] = '\n';
bline[pos ++] = '*';
npos = 1;
for (; npos < 12; npos ++)
bline[pos ++] = ' ';
bline[pos-2] = '|';
}
for (int n = beg; n <= end; n ++)
bline[pos+n-beg] = tmp[n];
pos += end-beg+1;
npos += end-beg+1;
beg = end+1;
}
while (npos < kLINEND) {
bline[pos ++] = ' ';
npos ++;
}
bline[pos ++] = '*';
bline[pos] = '\0';
delete[] tmp;
}
Printf(bline);
if (fTotBytes > 2000000000) {
Printf("*Entries :%lld : Total Size=%11lld bytes File Size = %lld *",fEntries,totBytes,fZipBytes);
} else {
if (fZipBytes > 0) {
Printf("*Entries :%9lld : Total Size=%11lld bytes File Size = %10lld *",fEntries,totBytes,fZipBytes);
} else {
if (fWriteBasket > 0) {
Printf("*Entries :%9lld : Total Size=%11lld bytes All baskets in memory *",fEntries,totBytes);
} else {
Printf("*Entries :%9lld : Total Size=%11lld bytes One basket in memory *",fEntries,totBytes);
}
}
}
Printf("*Baskets :%9d : Basket Size=%11d bytes Compression= %6.2f *",fWriteBasket,fBasketSize,cx);
Printf("*............................................................................*");
delete [] bline;
fgCount++;
}
void TBranch::ReadBasket(TBuffer&)
{
}
void TBranch::ReadLeaves(TBuffer& b)
{
for (Int_t i = 0; i < fNleaves; ++i) {
TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
leaf->ReadBasket(b);
}
}
void TBranch::Refresh(TBranch* b)
{
fEntryOffsetLen = b->fEntryOffsetLen;
fWriteBasket = b->fWriteBasket;
fEntryNumber = b->fEntryNumber;
fMaxBaskets = b->fMaxBaskets;
fEntries = b->fEntries;
fTotBytes = b->fTotBytes;
fZipBytes = b->fZipBytes;
fReadBasket = 0;
fNBasketRAM = 0;
delete [] fBasketBytes;
delete [] fBasketEntry;
delete [] fBasketSeek;
fBasketBytes = new Int_t[fMaxBaskets];
fBasketEntry = new Long64_t[fMaxBaskets];
fBasketSeek = new Long64_t[fMaxBaskets];
Int_t i;
for (i=0;i<fMaxBaskets;i++) {
fBasketBytes[i] = b->fBasketBytes[i];
fBasketEntry[i] = b->fBasketEntry[i];
fBasketSeek[i] = b->fBasketSeek[i];
}
fBaskets.Delete();
Int_t nbaskets = b->fBaskets.GetSize();
fBaskets.Expand(nbaskets);
TBasket *basket = (TBasket*)b->fBaskets.UncheckedAt(fWriteBasket);
fBaskets.AddAt(basket,fWriteBasket);
if (basket) {
b->fBaskets.RemoveAt(fWriteBasket);
basket->SetBranch(this);
}
}
void TBranch::Reset(Option_t*)
{
fReadBasket = 0;
fReadEntry = -1;
fWriteBasket = 0;
fEntries = 0;
fTotBytes = 0;
fZipBytes = 0;
fEntryNumber = 0;
if (fBasketBytes) {
for (Int_t i = 0; i < fMaxBaskets; ++i) {
fBasketBytes[i] = 0;
}
}
if (fBasketEntry) {
for (Int_t i = 0; i < fMaxBaskets; ++i) {
fBasketEntry[i] = 0;
}
}
if (fBasketSeek) {
for (Int_t i = 0; i < fMaxBaskets; ++i) {
fBasketSeek[i] = 0;
}
}
fBaskets.Delete();
}
void TBranch::ResetAddress()
{
fAddress = 0;
for (Int_t i = 0; i < fNleaves; ++i) {
TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
leaf->SetAddress(0);
}
Int_t nbranches = fBranches.GetEntriesFast();
for (Int_t i = 0; i < nbranches; ++i) {
TBranch* abranch = (TBranch*) fBranches[i];
abranch->ResetAddress();
}
}
void TBranch::ResetCount()
{
fgCount = 0;
}
void TBranch::SetAddress(void* addr)
{
if (TestBit(kDoNotProcess)) {
return;
}
fReadEntry = -1;
fAddress = (char*) addr;
for (Int_t i = 0; i < fNleaves; ++i) {
TLeaf* leaf = (TLeaf*) fLeaves.UncheckedAt(i);
Int_t offset = leaf->GetOffset();
if (TestBit(kIsClone)) {
offset = 0;
}
if (fAddress) leaf->SetAddress(fAddress + offset);
else leaf->SetAddress(0);
}
}
void TBranch::SetAutoDelete(Bool_t autodel)
{
if (autodel) {
SetBit(kAutoDelete, 1);
} else {
SetBit(kAutoDelete, 0);
}
}
void TBranch::SetBasketSize(Int_t buffsize)
{
if (buffsize < 100+fEntryOffsetLen) buffsize = 100+fEntryOffsetLen;
fBasketSize = buffsize;
}
void TBranch::SetBufferAddress(TBuffer* buf)
{
if ( (fNleaves != 1)
|| (strcmp("TLeafObject",fLeaves.UncheckedAt(0)->ClassName())!=0) ) {
Error("TBranch::SetAddress","Filling from a TBuffer can only be done with a not split object branch. Request ignored.");
} else {
fReadEntry = -1;
fEntryBuffer = buf;
}
}
void TBranch::SetCompressionLevel(Int_t level)
{
fCompress = level;
Int_t nb = fBranches.GetEntriesFast();
for (Int_t i=0;i<nb;i++) {
TBranch *branch = (TBranch*)fBranches.UncheckedAt(i);
branch->SetCompressionLevel(level);
}
}
void TBranch::SetEntries(Long64_t entries)
{
fEntries = entries;
fEntryNumber = entries;
}
void TBranch::SetFile(TFile* file)
{
if (file == 0) file = fTree->GetCurrentFile();
fDirectory = (TDirectory*)file;
if (file == fTree->GetCurrentFile()) fFileName = "";
else fFileName = file->GetName();
TIter nextb(GetListOfBaskets());
TBasket *basket;
while ((basket = (TBasket*)nextb())) {
basket->SetParent(file);
}
TIter next(GetListOfBranches());
TBranch *branch;
while ((branch = (TBranch*)next())) {
branch->SetFile(file);
}
}
void TBranch::SetFile(const char* fname)
{
fFileName = fname;
fDirectory = 0;
TIter next(GetListOfBranches());
TBranch *branch;
while ((branch = (TBranch*)next())) {
branch->SetFile(fname);
}
}
void TBranch::SetObject(void * )
{
if (TestBit(kDoNotProcess)) {
return;
}
Warning("SetObject","is not supported in TBranch objects");
}
void TBranch::Streamer(TBuffer& b)
{
if (b.IsReading()) {
UInt_t R__s, R__c;
fTree = gTree;
fAddress = 0;
gROOT->SetReadingObject(kTRUE);
Version_t v = b.ReadVersion(&R__s, &R__c);
if (v > 9) {
b.ReadClassBuffer(TBranch::Class(), this, v, R__s, R__c);
fDirectory = gDirectory;
if (fFileName.Length() != 0) fDirectory = 0;
fNleaves = fLeaves.GetEntriesFast();
for (Int_t i=0;i<fNleaves;i++) {
TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
leaf->SetBranch(this);
}
Int_t nbaskets = fBaskets.GetEntries();
for (Int_t j=fWriteBasket,n=0;j>=0 && n<nbaskets;--j) {
TBasket *bk = (TBasket*)fBaskets.UncheckedAt(j);
if (bk) {
bk->SetBranch(this);
GetTree()->IncrementTotalBuffers(bk->GetBufferSize());
++n;
}
}
if (!fSplitLevel && fBranches.GetEntriesFast()) fSplitLevel = 1;
gROOT->SetReadingObject(kFALSE);
return;
}
Int_t n,i,j,ijunk;
if (v > 5) {
Stat_t djunk;
TNamed::Streamer(b);
if (v > 7) TAttFill::Streamer(b);
b >> fCompress;
b >> fBasketSize;
b >> fEntryOffsetLen;
b >> fWriteBasket;
b >> ijunk; fEntryNumber = (Long64_t)ijunk;
b >> fOffset;
b >> fMaxBaskets;
if (v > 6) b >> fSplitLevel;
b >> djunk; fEntries = (Long64_t)djunk;
b >> djunk; fTotBytes = (Long64_t)djunk;
b >> djunk; fZipBytes = (Long64_t)djunk;
fBranches.Streamer(b);
fLeaves.Streamer(b);
fBaskets.Streamer(b);
fBasketBytes = new Int_t[fMaxBaskets];
fBasketEntry = new Long64_t[fMaxBaskets];
fBasketSeek = new Long64_t[fMaxBaskets];
Char_t isArray;
b >> isArray;
b.ReadFastArray(fBasketBytes,fMaxBaskets);
b >> isArray;
for (i=0;i<fMaxBaskets;i++) {b >> ijunk; fBasketEntry[i] = ijunk;}
b >> isArray;
for (i=0;i<fMaxBaskets;i++) {
if (isArray == 2) b >> fBasketSeek[i];
else {Int_t bsize; b >> bsize; fBasketSeek[i] = (Long64_t)bsize;};
}
fFileName.Streamer(b);
b.CheckByteCount(R__s, R__c, TBranch::IsA());
fDirectory = gDirectory;
if (fFileName.Length() != 0) fDirectory = 0;
fNleaves = fLeaves.GetEntriesFast();
for (i=0;i<fNleaves;i++) {
TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
leaf->SetBranch(this);
}
Int_t nbaskets = fBaskets.GetEntries();
for (j=fWriteBasket,n=0;j>0 && n<nbaskets;--j) {
TBasket *bk = (TBasket*)fBaskets.UncheckedAt(j);
if (bk) {
bk->SetBranch(this);
GetTree()->IncrementTotalBuffers(bk->GetBufferSize());
++n;
}
}
if (!fSplitLevel && fBranches.GetEntriesFast()) fSplitLevel = 1;
gROOT->SetReadingObject(kFALSE);
b.CheckByteCount(R__s, R__c, TBranch::IsA());
return;
}
Stat_t djunk;
TNamed::Streamer(b);
b >> fCompress;
b >> fBasketSize;
b >> fEntryOffsetLen;
b >> fMaxBaskets;
b >> fWriteBasket;
b >> ijunk; fEntryNumber = (Long64_t)ijunk;
b >> djunk; fEntries = (Long64_t)djunk;
b >> djunk; fTotBytes = (Long64_t)djunk;
b >> djunk; fZipBytes = (Long64_t)djunk;
b >> fOffset;
fBranches.Streamer(b);
fLeaves.Streamer(b);
fNleaves = fLeaves.GetEntriesFast();
for (i=0;i<fNleaves;i++) {
TLeaf *leaf = (TLeaf*)fLeaves.UncheckedAt(i);
leaf->SetBranch(this);
}
fBaskets.Streamer(b);
Int_t nbaskets = fBaskets.GetEntries();
for (j=fWriteBasket,n=0;j>0 && n<nbaskets;--j) {
TBasket *bk = (TBasket*)fBaskets.UncheckedAt(j);
if (bk) {
bk->SetBranch(this);
GetTree()->IncrementTotalBuffers(bk->GetBufferSize());
++n;
}
}
fBasketEntry = new Long64_t[fMaxBaskets];
b >> n;
for (i=0;i<n;i++) {b >> ijunk; fBasketEntry[i] = ijunk;}
fBasketBytes = new Int_t[fMaxBaskets];
if (v > 4) {
n = b.ReadArray(fBasketBytes);
} else {
for (n=0;n<fMaxBaskets;n++) fBasketBytes[n] = 0;
}
if (v < 2) {
fBasketSeek = new Long64_t[fMaxBaskets];
for (n=0;n<fWriteBasket;n++) {
fBasketSeek[n] = GetBasket(n)->GetSeekKey();
}
} else {
fBasketSeek = new Long64_t[fMaxBaskets];
b >> n;
for (n=0;n<fMaxBaskets;n++) {
Int_t aseek;
b >> aseek;
fBasketSeek[n] = Long64_t(aseek);
}
}
fDirectory = gDirectory;
if (v > 2) {
fFileName.Streamer(b);
if (fFileName.Length() != 0) fDirectory = 0;
}
if (v < 4) SetAutoDelete(kTRUE);
if (!fSplitLevel && fBranches.GetEntriesFast()) fSplitLevel = 1;
gROOT->SetReadingObject(kFALSE);
b.CheckByteCount(R__s, R__c, TBranch::IsA());
} else {
Int_t maxBaskets = fMaxBaskets;
fMaxBaskets = fWriteBasket+1;
if (fMaxBaskets < 10) fMaxBaskets=10;
b.WriteClassBuffer(TBranch::Class(),this);
fMaxBaskets = maxBaskets;
}
}
Int_t TBranch::WriteBasket(TBasket* basket, Int_t where)
{
Int_t nout = basket->WriteBuffer();
fBasketBytes[where] = basket->GetNbytes();
fBasketSeek[where] = basket->GetSeekKey();
Int_t addbytes = basket->GetObjlen() + basket->GetKeylen() ;
if (nout>0) {
basket->DropBuffers();
delete basket;
fBaskets[where] = 0;
}
fZipBytes += nout;
fTotBytes += addbytes;
fTree->AddTotBytes(addbytes);
fTree->AddZipBytes(nout);
if (where==fWriteBasket) {
++fWriteBasket;
if (fWriteBasket >= fMaxBaskets) {
ExpandBasketArrays();
}
fBaskets.AddAtAndExpand(0,fWriteBasket);
fBasketEntry[fWriteBasket] = fEntryNumber;
}
return nout;
}
void TBranch :: SetFirstEntry( Long64_t entry )
{
fFirstEntry = entry;
fEntries = 0;
fEntryNumber = entry;
if( fBasketEntry )
fBasketEntry[0] = entry;
for( Int_t i = 0; i < fBranches.GetEntriesFast(); ++i )
((TBranch*)fBranches[i])->SetFirstEntry( entry );
}
Last change: Tue Oct 28 16:13:05 2008
Last generated: 2008-10-28 16:13
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.