Skip to content
Snippets Groups Projects
Commit 8a42ec73 authored by Markus Frank's avatar Markus Frank Committed by MarkusFrankATcernch
Browse files

Make Geant4Output2ROOT more robust.

parent 097a9955
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ using namespace std; ...@@ -36,7 +36,7 @@ using namespace std;
/// Standard constructor /// Standard constructor
Geant4Output2ROOT::Geant4Output2ROOT(Geant4Context* ctxt, const string& nam) 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("Section", m_section = "EVENT");
declareProperty("HandleMCTruth", m_handleMCTruth = true); declareProperty("HandleMCTruth", m_handleMCTruth = true);
declareProperty("DisabledCollections", m_disabledCollections); declareProperty("DisabledCollections", m_disabledCollections);
...@@ -94,11 +94,15 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) { ...@@ -94,11 +94,15 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) {
} }
if ( !m_file && !fname.empty() ) { if ( !m_file && !fname.empty() ) {
TDirectory::TContext ctxt(TDirectory::CurrentDirectory()); TDirectory::TContext ctxt(TDirectory::CurrentDirectory());
m_file = TFile::Open(fname.c_str(), "RECREATE", "dd4hep Simulation data"); std::unique_ptr<TFile> file(TFile::Open(fname.c_str(), "RECREATE", "dd4hep Simulation data"));
if (m_file->IsZombie()) { if ( !file ) {
except("Failed to create ROOT output file:'%s'", fname.c_str());
}
if (file->IsZombie()) {
detail::deletePtr (m_file); detail::deletePtr (m_file);
except("Failed to open ROOT output file:'%s'", fname.c_str()); except("Failed to open ROOT output file:'%s'", fname.c_str());
} }
m_file = file.release();
m_tree = section(m_section); m_tree = section(m_section);
} }
Geant4OutputAction::beginRun(run); Geant4OutputAction::beginRun(run);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment