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 8a42ec7 commit ea7156a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DDG4/src/Geant4Output2ROOT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <TFile.h>
#include <TTree.h>
#include <TBranch.h>
#include <TSystem.h>


using namespace dd4hep::sim;
using namespace dd4hep;
Expand Down Expand Up @@ -94,7 +96,13 @@ void Geant4Output2ROOT::beginRun(const G4Run* run) {
}
if ( !m_file && !fname.empty() ) {
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"));
if ( !file ) {
file.reset(TFile::Open((fname+".1").c_str(), "RECREATE", "dd4hep Simulation data"));
}
if ( !file ) {
except("Failed to create ROOT output file:'%s'", fname.c_str());
}
Expand Down

0 comments on commit ea7156a

Please sign in to comment.