Recreate a data root file in a newer root version format

Hello,

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”)
((TTree*)f.Get(“events”))->Write()
g.Close();

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?
Thanks,
A.R.

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; }
Rene

Thanks, I will try it.

A.R.

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

Thanks indeed,
A.R.