From a39c7fa343ed741bbb50bc20a993e43433121e88 Mon Sep 17 00:00:00 2001 From: Ernst Hellbar Date: Tue, 11 Nov 2025 14:32:35 +0100 Subject: [PATCH] Event Display: catch several filesystem exceptions --- .../Base/src/DirectoryLoader.cxx | 47 +++++++++++++------ .../src/VisualisationEventROOTSerializer.cxx | 4 ++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/EventVisualisation/Base/src/DirectoryLoader.cxx b/EventVisualisation/Base/src/DirectoryLoader.cxx index 1b0135428806f..f2f5a421c0ef9 100644 --- a/EventVisualisation/Base/src/DirectoryLoader.cxx +++ b/EventVisualisation/Base/src/DirectoryLoader.cxx @@ -29,10 +29,15 @@ using namespace o2::event_visualisation; deque DirectoryLoader::load(const std::string& path, const std::string& marker, const std::vector& ext) { deque result; - for (const auto& entry : std::filesystem::directory_iterator(path)) { - if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) { - result.push_back(entry.path().filename()); + try { + for (const auto& entry : std::filesystem::directory_iterator(path)) { + if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) { + result.push_back(entry.path().filename()); + } } + } catch (std::filesystem::filesystem_error const& ex) { + LOGF(error, "filesystem problem during DirectoryLoader::load: %s", ex.what()); + return result; } // comparison with safety if marker not in the filename (-1+1 gives 0) std::sort(result.begin(), result.end(), @@ -56,7 +61,8 @@ bool DirectoryLoader::canCreateNextFile(const std::vector& paths, c } } } catch (std::filesystem::filesystem_error const& ex) { - LOGF(info, "filesystem problem: %s", ex.what()); + LOGF(error, "filesystem problem during DirectoryLoader::canCreateNextFile: %s", ex.what()); + return false; } } @@ -87,12 +93,17 @@ bool DirectoryLoader::canCreateNextFile(const std::vector& paths, c deque DirectoryLoader::load(const std::vector& paths, const std::string& marker, const std::vector& ext) { deque result; - for (const auto& path : paths) { - for (const auto& entry : std::filesystem::directory_iterator(path)) { - if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) { - result.push_back(entry.path().filename()); + try { + for (const auto& path : paths) { + for (const auto& entry : std::filesystem::directory_iterator(path)) { + if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) { + result.push_back(entry.path().filename()); + } } } + } catch (std::filesystem::filesystem_error const& ex) { + LOGF(error, "filesystem problem during DirectoryLoader::load: %s", ex.what()); + return result; } // comparison with safety if marker not in the filename (-1+1 gives 0) std::sort(result.begin(), result.end(), @@ -135,10 +146,14 @@ std::time_t to_time_t(TP tp) int DirectoryLoader::getNumberOfFiles(const std::string& path, std::vector& ext) { int res = 0; - for (const auto& entry : std::filesystem::directory_iterator(path)) { - if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) { - res++; + try { + for (const auto& entry : std::filesystem::directory_iterator(path)) { + if (std::find(ext.begin(), ext.end(), entry.path().extension()) != ext.end()) { + res++; + } } + } catch (std::filesystem::filesystem_error const& ex) { + LOGF(error, "filesystem problem during DirectoryLoader::getNumberOfFiles: %s", ex.what()); } return res; } @@ -160,8 +175,12 @@ std::string DirectoryLoader::getLatestFile(const std::string& path, std::vector< void DirectoryLoader::removeOldestFiles(const std::string& path, std::vector& ext, const int remaining) { - while (getNumberOfFiles(path, ext) > remaining) { - LOGF(info, "removing oldest file in folder: %s : %s", path, getLatestFile(path, ext)); - filesystem::remove(path + "/" + getLatestFile(path, ext)); + try { + while (getNumberOfFiles(path, ext) > remaining) { + LOGF(info, "removing oldest file in folder: %s : %s", path, getLatestFile(path, ext)); + filesystem::remove(path + "/" + getLatestFile(path, ext)); + } + } catch (std::filesystem::filesystem_error const& ex) { + LOGF(error, "filesystem problem during DirectoryLoader::removeOldestFiles: %s", ex.what()); } } diff --git a/EventVisualisation/DataConverter/src/VisualisationEventROOTSerializer.cxx b/EventVisualisation/DataConverter/src/VisualisationEventROOTSerializer.cxx index 8c1a84c1bf85e..8480e15ee9772 100644 --- a/EventVisualisation/DataConverter/src/VisualisationEventROOTSerializer.cxx +++ b/EventVisualisation/DataConverter/src/VisualisationEventROOTSerializer.cxx @@ -97,6 +97,10 @@ void VisualisationEventROOTSerializer::toFile(const VisualisationEvent& event, L { std::string fileName = location.fileName(); TFile f(fileName.c_str(), "recreate"); + if (f.IsZombie()) { + LOGF(error, "Could not create output file %s", fileName.c_str()); + return; + } saveInt("runNumber", event.mRunNumber); saveInt("runType", event.mRunType);