From 9dade08cf0e56fd9e1ab3368bb2aadf5aea3a5d2 Mon Sep 17 00:00:00 2001 From: Matteo Vicenzi Date: Thu, 11 Sep 2025 10:29:39 -0400 Subject: [PATCH] delete and recreate GDML file each time --- include/DetectorConstruction.hh | 3 ++- src/DetectorConstruction.cc | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/DetectorConstruction.hh b/include/DetectorConstruction.hh index 2a4a2ff..5f8190d 100644 --- a/include/DetectorConstruction.hh +++ b/include/DetectorConstruction.hh @@ -8,6 +8,7 @@ #include #include "fields/BabyMINDMagneticField.hh" #include +#include class G4LogicalVolume; class DetectorConstructionMessenger; @@ -48,7 +49,7 @@ class DetectorConstruction : public G4VUserDetectorConstruction { DetectorConstructionMessenger* messenger; G4bool m_saveGdml; - G4String m_fileGdml; + std::string m_fileGdml; G4bool fCheckOverlap; G4bool m_addFLArE; G4bool m_useBabyMIND; diff --git a/src/DetectorConstruction.cc b/src/DetectorConstruction.cc index 6d11af7..5cb6427 100644 --- a/src/DetectorConstruction.cc +++ b/src/DetectorConstruction.cc @@ -39,7 +39,8 @@ #include #include -using namespace std; +#include +#include G4ThreadLocal G4UniformMagField* DetectorConstruction::magField = 0; G4ThreadLocal G4FieldManager* DetectorConstruction::fieldMgr = 0; @@ -272,6 +273,12 @@ G4VPhysicalVolume* DetectorConstruction::Construct() if (m_saveGdml) { G4GDMLParser fParser; G4cout << "Exporting geometry to " << m_fileGdml << G4endl; + + if(std::filesystem::exists(m_fileGdml)){ + G4cout << " File already exists. Deleting first..." << G4endl; + std::filesystem::remove(m_fileGdml); + } + fParser.Write(m_fileGdml, worldPV, false); }