How to SetBit(TFile::k630forwardCompatibility)


Dear experts

I want to set the compatibility for a ROOT file, and I’m suggested to do it by TFile::SetBit(TFile::k630forwardCompatibility), but when I try to change it, I found I couldn’t:

root [0] TFile* f = TFile::Open("SimDetectorResponse/parameters/RECBE_response/response_RECBE002ch24_20241121.root", "Update")
(TFile *) 0x43b6870
root [1] f->TestBit(TFile::k630forwardCompatibility)
(bool) false
root [2] f->SetBit(TFile::k630forwardCompatibility)
root [3] f->TestBit(TFile::k630forwardCompatibility)
(bool) true
root [4] f->Write()
(int) 0
root [5] f->TestBit(TFile::k630forwardCompatibility)
(bool) true
root [6] f->Close()
root [7] delete f;
root [8] TFile* f = TFile::Open("SimDetectorResponse/parameters/RECBE_response/response_RECBE002ch24_20241121.root", "Update")
(TFile *) 0x43b6870
root [9] f->TestBit(TFile::k630forwardCompatibility)
(bool) false

How can I change it?

Maybe @pcanal can help

I think this was fixed some time ago, see the versions that include the fix here:

The meaning of the flag is to change the way object are stored in the file. It can not change the way object are already stored.

So you need to set the flag when creating the file before writing any objects in it.

In addition this bit is not a persistent property of the file. i.e. you need to set it whenever you want to update it (alternative you can use .rootrc setting to do so automatically for all files).

This means I need to SetBit right after I create the TFile?

yes, you are correct.