Recreate a data root file in a newer root version format


I have several data root files created with root 5.22 that I would like to have recreated with root 5.26.

I did:

TFile f(“b0.root”)
TFile g(“new.root”, “RECREATE”)

Then, when I tried to read the new file I get a lot of warnings as this:
Warning in TBasket::ReadBasketBuffers: basket: has fNevBuf=0 but fEntryOffset=0, pos=54544099, len=6157, fNbytes=0, fObjlen=0, trying to repair

Could anyone help on this?

What you do cannot work because you write only the tree header on the new file but not the branch baskets.
I suggest the following procedure to take advantage of the optimisation facilities
introduced in version 5.26

void rewrite() { TFile *f = TFile::Open("b0.root"); T = (TTree*)f->Get("events"); T->OptimizeBaskets(40000000,1,"d"); TFile *f2 = new TFile("new.root","recreate"); TTree *T2 = T->CloneTree(0); T2->SetAutoSave(1000000000); Long64_t nentries = T->GetEntries(); for (Int_t i=0;i<nentries;i++) { if (i%100 == 0) printf("i=%d\n",i); T->GetEntry(i); T2->Fill(); } T2->Write(); T2->Print(); delete f2; }

Thanks, I will try it.


It works. Actually what I wanted was to take profit of the optimisation.

Thanks indeed,