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

Make Geant4Output2ROOT more robust.

parent 8a42ec73
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <TFile.h> #include <TFile.h>
#include <TTree.h> #include <TTree.h>
#include <TBranch.h> #include <TBranch.h>
#include <TSystem.h>
using namespace dd4hep::sim; using namespace dd4hep::sim;
using namespace dd4hep; using namespace dd4hep;
...@@ -94,7 +96,13 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) { ...@@ -94,7 +96,13 @@ 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());
if ( !gSystem->AccessPathName(fname.c_str()) ) {
gSystem->Unlink(fname.c_str());
}
std::unique_ptr<TFile> 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 ( !file ) {
file.reset(TFile::Open((fname+".1").c_str(), "RECREATE", "dd4hep Simulation data"));
}
if ( !file ) { if ( !file ) {
except("Failed to create ROOT output file:'%s'", fname.c_str()); except("Failed to create ROOT output file:'%s'", fname.c_str());
} }
......
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