From 2ce34c1d966b8cb738b8d6fb1ebe067e33f55949 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 28 Jun 2022 13:22:44 +0200 Subject: [PATCH] fix: Output ROOT file closing on destruct While I believe the writing should happen in `endRun`, I've seen segfaults when ROOT's exit handler tries to close them and sees corrupted memory. This PR should fix that for these two classes. --- Examples/Io/Root/src/RootTrajectoryStatesWriter.cpp | 7 +++++-- Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Examples/Io/Root/src/RootTrajectoryStatesWriter.cpp b/Examples/Io/Root/src/RootTrajectoryStatesWriter.cpp index 51c579a1e43..d42366b9567 100644 --- a/Examples/Io/Root/src/RootTrajectoryStatesWriter.cpp +++ b/Examples/Io/Root/src/RootTrajectoryStatesWriter.cpp @@ -218,7 +218,11 @@ ActsExamples::RootTrajectoryStatesWriter::RootTrajectoryStatesWriter( } } -ActsExamples::RootTrajectoryStatesWriter::~RootTrajectoryStatesWriter() {} +ActsExamples::RootTrajectoryStatesWriter::~RootTrajectoryStatesWriter() { + if (m_outputFile) { + m_outputFile->Close(); + } +} ActsExamples::ProcessCode ActsExamples::RootTrajectoryStatesWriter::endRun() { if (m_outputFile) { @@ -226,7 +230,6 @@ ActsExamples::ProcessCode ActsExamples::RootTrajectoryStatesWriter::endRun() { m_outputTree->Write(); ACTS_INFO("Write states of trajectories to tree '" << m_cfg.treeName << "' in '" << m_cfg.treeName << "'"); - m_outputFile->Close(); } return ProcessCode::SUCCESS; } diff --git a/Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp b/Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp index 028499d5588..f299e7e89e2 100644 --- a/Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp +++ b/Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp @@ -128,7 +128,11 @@ ActsExamples::RootTrajectorySummaryWriter::RootTrajectorySummaryWriter( } } -ActsExamples::RootTrajectorySummaryWriter::~RootTrajectorySummaryWriter() {} +ActsExamples::RootTrajectorySummaryWriter::~RootTrajectorySummaryWriter() { + if (m_outputFile) { + m_outputFile->Close(); + } +} ActsExamples::ProcessCode ActsExamples::RootTrajectorySummaryWriter::endRun() { if (m_outputFile) { @@ -136,7 +140,6 @@ ActsExamples::ProcessCode ActsExamples::RootTrajectorySummaryWriter::endRun() { m_outputTree->Write(); ACTS_INFO("Write parameters of trajectories to tree '" << m_cfg.treeName << "' in '" << m_cfg.filePath << "'"); - m_outputFile->Close(); } return ProcessCode::SUCCESS; }