Hi,
I am creating a TTree and filling it with branches (with names: “IDstr”, “consumption” and “statusTDC”).
This I write into a TFile, “TEST.root”. All of this works succesfully, and I can read the TFile with the command
"root -l TEST.root" and plot all contents without problem.
Now, I want to read in the TTree object, from the file, into a different program, add new values to the contents of the TTree, and again, save the file into a new TFile.
Below I included the summary of the code I use.
- I can read in the TTree succesfully
- I can draw the TTree succesfully before filling it with a new entry
- I can draw the TTree succesfully after filling it too
- I can write the TTree succesfully to the new TFile, “NEW_TEST.root”.
BUT: when I read in the new TFile in root: “root -l NEW_TEST.root” and then try to plot. e.g.
“mytree->Draw(“consumption”)”,
I get the folllowing errors:
[quote]Error in TBasket::Streamer: The value of fKeylen is incorrect (-28622) ; trying to recover by setting it to zero
Error in TBranch::GetBasket: File: NEW_ChipQualityTree.root at byte:-1073270420, branch:consumption, entry:-1, badread=1, nerrors=1, basketnumber=0
[/quote]
What am I doing wrong? And how could I update a TTree that has been read in from a TFile?
Cheers,
Machiel
TFile* hfile_OLD = TFile::Open( "TEST.root", "READ" );
TTree* tree = (TTree*) hfile_OLD->Get( "mytree" );
// Draw before filling again
mytree->Draw("consumption");
std::string* IDstr;
double consumption;
int statusTDC;
mytree->SetBranchAddress("IDstr", &IDstr);
mytree->SetBranchAddress("consumption", &consumption);
mytree->SetBranchAddress("statusTDC", &statusTDC);
// test filling
std::string tmp = "TEST";
IDstr = &tmp;
consumption = 200.0;
statusTDC = 0;
mytree->Fill();
// Draw again
mytree->Draw("consumption");
// end ntuple
TString newFileName = "NEW_TEST.root";
TFile hfile( "NEW_TEST.root", "RECREATE");
mytree->Write();
hfile.Close();