From b8d0e02b32ff39ae085e3aa5e7acd8e1b46b332c Mon Sep 17 00:00:00 2001 From: cmargalejo Date: Fri, 17 Apr 2026 09:27:26 +0200 Subject: [PATCH 1/2] Prevent hanging when opening old REST files with schema mismatches --- macros/REST_OpenInputFile.C | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/macros/REST_OpenInputFile.C b/macros/REST_OpenInputFile.C index 0f1af5cd6..1c29bbff0 100644 --- a/macros/REST_OpenInputFile.C +++ b/macros/REST_OpenInputFile.C @@ -1,3 +1,16 @@ +bool gSchemaError = false; + +void SchemaErrorHandler(int level, Bool_t abort, const char* location, const char* msg) { + if (level >= kError) { + std::string loc(location); + if (loc.find("TBufferFile") != std::string::npos || + loc.find("TStreamerInfo") != std::string::npos) { + gSchemaError = true; + } + } + DefaultErrorHandler(level, abort, location, msg); +} + TRestRun* run = nullptr; TRestAnalysisTree* ana_tree = nullptr; TTree* ev_tree = nullptr; @@ -6,7 +19,10 @@ TRestDataSet* dSet = nullptr; void REST_OpenInputFile(const std::string& fileName) { if (TRestTools::isRunFile(fileName)) { printf("\n%s\n\n", "REST processed file identified. It contains a valid TRestRun."); + gSchemaError = false; + auto oldHandler = SetErrorHandler(SchemaErrorHandler); run = new TRestRun(fileName); + SetErrorHandler(oldHandler); // print number of entries in the run printf("\nThe run has %lld entries.\n", run->GetEntries()); printf("\nAttaching TRestRun %s as run...\n", fileName.c_str()); @@ -17,7 +33,12 @@ void REST_OpenInputFile(const std::string& fileName) { std::string eventType = run->GetInputEvent()->ClassName(); std::string evcmd = Form("%s* ev = (%s*)run->GetInputEvent();", eventType.c_str(), eventType.c_str()); gROOT->ProcessLine(evcmd.c_str()); - run->GetEntry(0); + if (gSchemaError) { + printf("\nWARNING: Schema errors were detected. This file was produced with an older REST version.\n"); + printf("Event browsing is disabled to prevent hanging. You can still use ana_tree and metadata.\n\n"); + } else { + run->GetEntry(0); + } printf("Attaching input event %s as ev...\n", eventType.c_str()); for (int n = 0; n < run->GetNumberOfMetadata(); n++) { if (n == 0) printf("Attaching Metadata classes:\n"); From 2b09916af6a3c771d318acb176d59a4bfbd3ce0d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Apr 2026 09:18:27 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- macros/REST_OpenInputFile.C | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/macros/REST_OpenInputFile.C b/macros/REST_OpenInputFile.C index 1c29bbff0..326a51772 100644 --- a/macros/REST_OpenInputFile.C +++ b/macros/REST_OpenInputFile.C @@ -3,8 +3,7 @@ bool gSchemaError = false; void SchemaErrorHandler(int level, Bool_t abort, const char* location, const char* msg) { if (level >= kError) { std::string loc(location); - if (loc.find("TBufferFile") != std::string::npos || - loc.find("TStreamerInfo") != std::string::npos) { + if (loc.find("TBufferFile") != std::string::npos || loc.find("TStreamerInfo") != std::string::npos) { gSchemaError = true; } } @@ -34,8 +33,12 @@ void REST_OpenInputFile(const std::string& fileName) { std::string evcmd = Form("%s* ev = (%s*)run->GetInputEvent();", eventType.c_str(), eventType.c_str()); gROOT->ProcessLine(evcmd.c_str()); if (gSchemaError) { - printf("\nWARNING: Schema errors were detected. This file was produced with an older REST version.\n"); - printf("Event browsing is disabled to prevent hanging. You can still use ana_tree and metadata.\n\n"); + printf( + "\nWARNING: Schema errors were detected. This file was produced with an older REST " + "version.\n"); + printf( + "Event browsing is disabled to prevent hanging. You can still use ana_tree and " + "metadata.\n\n"); } else { run->GetEntry(0); }