From f71a5632c0c9cb3cc766e0d4fa71c9dfe59d1eb7 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Tue, 9 Apr 2019 19:34:10 +0200
Subject: [PATCH] Give access to Geant4 world volume to Geant4Actions. Add
 plugin action to write Geant4 GDML files

---
 DDG4/plugins/Geant4GDMLWriteAction.cpp | 13 ++++++++-----
 examples/CLICSiD/scripts/CLIC_GDML.py  |  3 +--
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/DDG4/plugins/Geant4GDMLWriteAction.cpp b/DDG4/plugins/Geant4GDMLWriteAction.cpp
index e1209a466..ffb5ca174 100644
--- a/DDG4/plugins/Geant4GDMLWriteAction.cpp
+++ b/DDG4/plugins/Geant4GDMLWriteAction.cpp
@@ -74,6 +74,12 @@ namespace dd4hep {
 // Geant 4 includes
 #include "G4GDMLParser.hh"
 
+// C/C++ include files
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <memory>
+
 using namespace std;
 using namespace dd4hep;
 using namespace dd4hep::sim;
@@ -98,9 +104,6 @@ void Geant4GDMLWriteAction::installCommandMessenger()   {
   Callback cb = Callback(this).make(&Geant4GDMLWriteAction::writeGDML);
   m_control->addCall("write", "Write geometry to GDML file",cb);
 }
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
 
 /// Write geometry to GDML
 void Geant4GDMLWriteAction::writeGDML()   {
@@ -117,9 +120,9 @@ void Geant4GDMLWriteAction::writeGDML()   {
     warning("+++ GDML file %s already exists. Overwriting existing file.", m_output.c_str());
     ::unlink(m_output.c_str());
   }
-  G4GDMLParser parser;
+  unique_ptr<G4GDMLParser> parser(new G4GDMLParser());
   info("+++ Writing GDML file: %s", m_output.c_str());
-  parser.Write(m_output, context()->world());
+  parser->Write(m_output, context()->world());
 }
 
 #include "DDG4/Factories.h"
diff --git a/examples/CLICSiD/scripts/CLIC_GDML.py b/examples/CLICSiD/scripts/CLIC_GDML.py
index fbcf9581c..69a007e83 100644
--- a/examples/CLICSiD/scripts/CLIC_GDML.py
+++ b/examples/CLICSiD/scripts/CLIC_GDML.py
@@ -29,8 +29,7 @@ def run():
   ui.Commands = [
     '/ddg4/Writer/Output CLICSiD.gdml',
     '/ddg4/Writer/OverWrite 1',
-    '/ddg4/Writer/write',
-    'exit'
+    '/ddg4/Writer/write'
     ]
   kernel.configure()
   kernel.initialize()
-- 
GitLab