TFile::Write() vs. Flush() -- which makes file more usable?

We write out fairly large ROOT files from simulation jobs. If the jobs end successfully, there’s no problem (obviously), but if a job crashes or is aborted early, quite often the ROOT file is unusable.

I thought that I could use TFile::Flush() at the end of each event to ensure that the the file on disk was as close to usable as possible. But if I end a job early, the resulting ROOT file is as empty as before I introduced the Flush() call.

Should I be using TFile::Write() for this purpose? If I do this on every event (essentially short-circuiting the buffers), should I call it with the kOverwrite or kWriteDelete option?

Hi @Michael_Kelsey,
Yes, TFile::Write() takes care of writing your object to a file. If you don’t care about keeping different versions of the objects, but just want to rewrite it up to the current state in the loop, you could use the kOverwrite option. If what you are trying to write to the file is a TTree, I suggest you take a look also at TTree::SetAutoSave. This section of the user guide will give you a broader context on the subject as well.
Hope this helps,
Vincenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.