Skip to content

Commit

Permalink
fix: Output ROOT file closing on destruct (#1296)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paulgessinger committed Jul 4, 2022
1 parent 5ad6aa7 commit 83880e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Examples/Io/Root/src/RootTrajectoryStatesWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,18 @@ ActsExamples::RootTrajectoryStatesWriter::RootTrajectoryStatesWriter(
}
}

ActsExamples::RootTrajectoryStatesWriter::~RootTrajectoryStatesWriter() {}
ActsExamples::RootTrajectoryStatesWriter::~RootTrajectoryStatesWriter() {
if (m_outputFile) {
m_outputFile->Close();
}
}

ActsExamples::ProcessCode ActsExamples::RootTrajectoryStatesWriter::endRun() {
if (m_outputFile) {
m_outputFile->cd();
m_outputTree->Write();
ACTS_INFO("Write states of trajectories to tree '"
<< m_cfg.treeName << "' in '" << m_cfg.treeName << "'");
m_outputFile->Close();
}
return ProcessCode::SUCCESS;
}
Expand Down
7 changes: 5 additions & 2 deletions Examples/Io/Root/src/RootTrajectorySummaryWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,18 @@ ActsExamples::RootTrajectorySummaryWriter::RootTrajectorySummaryWriter(
}
}

ActsExamples::RootTrajectorySummaryWriter::~RootTrajectorySummaryWriter() {}
ActsExamples::RootTrajectorySummaryWriter::~RootTrajectorySummaryWriter() {
if (m_outputFile) {
m_outputFile->Close();
}
}

ActsExamples::ProcessCode ActsExamples::RootTrajectorySummaryWriter::endRun() {
if (m_outputFile) {
m_outputFile->cd();
m_outputTree->Write();
ACTS_INFO("Write parameters of trajectories to tree '"
<< m_cfg.treeName << "' in '" << m_cfg.filePath << "'");
m_outputFile->Close();
}
return ProcessCode::SUCCESS;
}
Expand Down

0 comments on commit 83880e0

Please sign in to comment.