Hello everyone,
I’m new to root and I get an error when I try to add a Branch to my existing TTree.
Everything works fine, but the first Entries seem to be corrupted while writing.
I can’t figure out why.
Here is the very simple test code (based on ROOT Manual - Functional parts/Trees):
void TestFunc() {
TFile f("ntuples.root", "update");
Float_t new_v;
auto data = f.Get<TTree>("data");
auto newBranch = data->Branch("new_v", &new_v, "new_v/F");
Int_t entries = data->GetEntries();
for (int i = 0; i < entries; i++)
{
new_v = gRandom->Gaus(0, 1);
newBranch->Fill();
}
data->Write("", TObject::kOverwrite);
}
Here is the error when I perform data->TTree::Scan();
************************************************************************************************************
* Row * particleI * Ein.Ein * posX.posX * posY.posY * posZ.posZ * dirTheta. * dirPhi.di * s0.s0 *
************************************************************************************************************
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:0, badread=0, nerrors=1, basketnumber=0
* 0 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:1, badread=0, nerrors=2, basketnumber=0
* 1 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:2, badread=0, nerrors=3, basketnumber=0
* 2 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:3, badread=0, nerrors=4, basketnumber=0
* 3 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:4, badread=0, nerrors=5, basketnumber=0
* 4 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:5, badread=0, nerrors=6, basketnumber=0
* 5 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:6, badread=0, nerrors=7, basketnumber=0
* 6 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:7, badread=0, nerrors=8, basketnumber=0
* 7 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:8, badread=0, nerrors=9, basketnumber=0
* 8 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
file probably overwritten: stopping reporting error messages
Error in <TBranch::GetBasket>: File: ntuples.root at byte:0, branch:particleID, entry:9, badread=0, nerrors=10, basketnumber=0
* 9 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 10 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 11 * 0 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 12 * 16 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 13 * 17 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 14 * 36 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 15 * 37 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 16 * 72 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 17 * 73 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 18 * 84 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 19 * 85 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 20 * 4 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 21 * 5 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 22 * 32 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 23 * 33 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
* 24 * 54 * 2000 * 0 * 0 * -0.965 * 0.1684121 * 0 * 0 *
Type <CR> to continue or q to quit ==>
I don’t understand how to solve the problem. I understand there was a problem when writing the file, but I don’t know how to fix it.
Many thanks for your help,
Matthieu
ROOT Version: 6.22/06
Platform: Linux/Ubuntu