I have some strange error when reading and writing a TTree.
I have two macros:
one is creating a root-file “input.root” with a TTree,
another is reading this TTree from the file, creates another TTree,
and writes both to a new root-file “output.root”.
When I open output.root with TBrowser and draw the branch of the TTree read from input.root, I get an error:
========
(class TFile*)0x17ec810
Error R__unzip_header: error in header
Error in TBasket::ReadBasketBuffers: Inconsistency found in header (nin=0, nbuf=0)
Error in TBasket::ReadBasketBuffers: fNbytes = 0, fKeylen = 17999, fObjlen = 262144, noutot = 0, nout=0, nin=0, nbuf=0
Error in TBranch::GetBasket: File: output.root at byte:65536, branch:k, entry:-1, badread=1, nerrors=1, basketnumber=0
Error R__unzip_header: error in header
Error in TBasket::ReadBasketBuffers: Inconsistency found in header (nin=0, nbuf=0)
Error in TBasket::ReadBasketBuffers: fNbytes = 0, fKeylen = 17999, fObjlen = 262144, noutot = 0, nout=0, nin=0, nbuf=0
Error in TBranch::GetBasket: File: output.root at byte:65536, branch:k, entry:-1, badread=1, nerrors=2, basketnumber=0
Here are the two simple macros:
createFile()
{
TFile * f = new TFile(“input.root”,“RECREATE”);
double k;
TTree * myTree = new TTree("myTree", "myTree");
TBranch * kBranch = myTree->Branch("k",&k);
k = 1;
myTree->Fill();
k = 2;
myTree->Fill();
f->cd();
myTree->Write();
f->Close();
}
readFile()
{
TFile * output = new TFile(“output.root”,“RECREATE”);
TFile * input = new TFile("input.root","READ");
TTree * myTreeFromFile = (TTree*)input->Get("myTree;1");
TTree * myNewTree = new TTree("myNewTree", "myNewTree");
double d;
TBranch * dBranch = myNewTree->Branch("d",&d);
d = 4;
myNewTree->Fill();
d = 8;
myNewTree->Fill();
output->cd();
myNewTree->Write();
myTreeFromFile->Write();
output->Close();
}
I use:
ROOT 5.34/09
Scientific Linux release 6.6 (Carbon)
What can be the problem?
Thank you!