Skip to content

Commit

Permalink
Make Geant4Output2ROOT more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch committed Jan 18, 2024
1 parent 097a995 commit 8a42ec7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions DDG4/src/Geant4Output2ROOT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace std;

/// Standard constructor
Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* ctxt, const string& nam)
: Geant4OutputAction(ctxt, nam), m_file(0), m_tree(0) {
: Geant4OutputAction(ctxt, nam), m_file(nullptr), m_tree(nullptr) {
declareProperty("Section", m_section = "EVENT");
declareProperty("HandleMCTruth", m_handleMCTruth = true);
declareProperty("DisabledCollections", m_disabledCollections);
Expand Down Expand Up @@ -94,11 +94,15 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) {
}
if ( !m_file && !fname.empty() ) {
TDirectory::TContext ctxt(TDirectory::CurrentDirectory());
m_file = TFile::Open(fname.c_str(), "RECREATE", "dd4hep Simulation data");
if (m_file->IsZombie()) {
std::unique_ptr<TFile> file(TFile::Open(fname.c_str(), "RECREATE", "dd4hep Simulation data"));
if ( !file ) {
except("Failed to create ROOT output file:'%s'", fname.c_str());
}
if (file->IsZombie()) {
detail::deletePtr (m_file);
except("Failed to open ROOT output file:'%s'", fname.c_str());
}
m_file = file.release();
m_tree = section(m_section);
}
Geant4OutputAction::beginRun(run);
Expand Down

0 comments on commit 8a42ec7

Please sign in to comment.