Skip to content

Commit a776301

Browse files
ferdymercurypcanalvepadulano
authored
[nfc][io] clarify how to check for health status of TFile (#22477)
Co-authored-by: Philippe Canal <pcanal@fnal.gov> Co-authored-by: Vincenzo Eduardo Padulano <vincenzo.eduardo.padulano@cern.ch>
1 parent aeefe7c commit a776301

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

io/io/src/TFile.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit
362362
/// ~~~{.cpp}
363363
/// TFile *f = TFile::Open("tmpname.root?reproducible=fixedname","RECREATE","File title");
364364
/// ~~~
365+
///
366+
/// To check for the health status of a TFile and detect corruption, you can perform the following checks after opening it:
367+
/// ~~~{.cpp}
368+
/// std::unique_ptr<TFile> f{TFile::Open("name.root", "READ")};
369+
/// auto bad_input = (f == nullptr); // File could not be open, e.g. if input url was incorrect or incorrect permissions.
370+
/// auto bad_initalization = (f && f->IsZombie()); // something went wrong in the constructor, for example when TFile is corrupt
371+
/// auto bad_storage = (f && f->TestBit(TFile::kRecovered)); // The TFile had to run the recovery mechanism when opening the file; often due to the file being incorrectly closed.
372+
/// ~~~
365373

366374
TFile::TFile(const char *fname1, Option_t *option, const char *ftitle, Int_t compress)
367375
: TDirectoryFile(), fCompress(compress), fUrl(fname1,kTRUE)

0 commit comments

Comments
 (0)