From 71678df795704485e60deea2eb9eeac408734c42 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 4 Jun 2026 10:11:50 +0200 Subject: [PATCH 1/6] [nfc][io] clarify how to check for health status of TFile Fixes https://github.com/root-project/root/issues/22464 --- io/io/src/TFile.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 4d71c78283592..0785bc52f9655 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -362,6 +362,15 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit /// ~~~{.cpp} /// TFile *f = TFile::Open("tmpname.root?reproducible=fixedname","RECREATE","File title"); /// ~~~ +/// +/// To check for the health status of a TFile and detect corruption, you can perform the following checks after opening it: +/// ~~~{.cpp} +/// TFile *f = TFile::Open("name.root", "READ"); +/// auto bad_input = (f == nullptr); // e.g. if input url was incorrect +/// auto bad_initalization = (f && f->IsZombie()); // something went wrong in the constructor, for example when TFile is corrupt +/// auto bad_storage = (f && f->TestBit(TFile::kRecovered)) // The TFile had to run the recovery mechanism when opening the file +/// ~~~ + TFile::TFile(const char *fname1, Option_t *option, const char *ftitle, Int_t compress) : TDirectoryFile(), fCompress(compress), fUrl(fname1,kTRUE) From f3ad1ce9460a85e8550e9164163d13dbea8115d0 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 4 Jun 2026 10:12:37 +0200 Subject: [PATCH 2/6] [nfc] missing semicolon --- io/io/src/TFile.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 0785bc52f9655..8847712d2d915 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -368,7 +368,7 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit /// TFile *f = TFile::Open("name.root", "READ"); /// auto bad_input = (f == nullptr); // e.g. if input url was incorrect /// auto bad_initalization = (f && f->IsZombie()); // something went wrong in the constructor, for example when TFile is corrupt -/// auto bad_storage = (f && f->TestBit(TFile::kRecovered)) // The TFile had to run the recovery mechanism when opening the file +/// auto bad_storage = (f && f->TestBit(TFile::kRecovered)); // The TFile had to run the recovery mechanism when opening the file /// ~~~ From 7e082562e38c0f92834d4a87b8e3df625ef8f82b Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 4 Jun 2026 10:13:45 +0200 Subject: [PATCH 3/6] Apply suggestion from @ferdymercury --- io/io/src/TFile.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 8847712d2d915..7a113a506fe24 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -371,7 +371,6 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit /// auto bad_storage = (f && f->TestBit(TFile::kRecovered)); // The TFile had to run the recovery mechanism when opening the file /// ~~~ - TFile::TFile(const char *fname1, Option_t *option, const char *ftitle, Int_t compress) : TDirectoryFile(), fCompress(compress), fUrl(fname1,kTRUE) { From 1e82544cfe2eadbfb93c6df303503a4ce7565e48 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 4 Jun 2026 23:09:48 +0200 Subject: [PATCH 4/6] Update io/io/src/TFile.cxx Co-authored-by: Philippe Canal --- io/io/src/TFile.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 7a113a506fe24..0ececf8251768 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -368,7 +368,7 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit /// TFile *f = TFile::Open("name.root", "READ"); /// auto bad_input = (f == nullptr); // e.g. if input url was incorrect /// auto bad_initalization = (f && f->IsZombie()); // something went wrong in the constructor, for example when TFile is corrupt -/// auto bad_storage = (f && f->TestBit(TFile::kRecovered)); // The TFile had to run the recovery mechanism when opening the file +/// 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. /// ~~~ TFile::TFile(const char *fname1, Option_t *option, const char *ftitle, Int_t compress) From 2f03964a2192f40ed54302420ac381efa5781d98 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Thu, 4 Jun 2026 23:10:10 +0200 Subject: [PATCH 5/6] Update io/io/src/TFile.cxx Co-authored-by: Philippe Canal --- io/io/src/TFile.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 0ececf8251768..683c0196c2d79 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -366,7 +366,7 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit /// To check for the health status of a TFile and detect corruption, you can perform the following checks after opening it: /// ~~~{.cpp} /// TFile *f = TFile::Open("name.root", "READ"); -/// auto bad_input = (f == nullptr); // e.g. if input url was incorrect +/// auto bad_input = (f == nullptr); // File could not be open, e.g. if input url was incorrect or incorrect permissions. /// auto bad_initalization = (f && f->IsZombie()); // something went wrong in the constructor, for example when TFile is corrupt /// 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. /// ~~~ From 0eb02a10d333c7d8cb619536dfbe0bc52bed74f3 Mon Sep 17 00:00:00 2001 From: ferdymercury Date: Fri, 5 Jun 2026 13:07:03 +0200 Subject: [PATCH 6/6] Update io/io/src/TFile.cxx Co-authored-by: Vincenzo Eduardo Padulano --- io/io/src/TFile.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 683c0196c2d79..bc94d64afc7ab 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -365,7 +365,7 @@ TFile::TFile() : TDirectoryFile(), fCompress(ROOT::RCompressionSetting::EAlgorit /// /// To check for the health status of a TFile and detect corruption, you can perform the following checks after opening it: /// ~~~{.cpp} -/// TFile *f = TFile::Open("name.root", "READ"); +/// std::unique_ptr f{TFile::Open("name.root", "READ")}; /// auto bad_input = (f == nullptr); // File could not be open, e.g. if input url was incorrect or incorrect permissions. /// auto bad_initalization = (f && f->IsZombie()); // something went wrong in the constructor, for example when TFile is corrupt /// 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.