11 #include <geometry/modules/ExportGeometryModule.h>
13 #include <framework/utilities/FileSystem.h>
14 #include <geometry/GeometryManager.h>
15 #include <TGeoManager.h>
17 #include <G4GDMLParser.hh>
35 setDescription(
"Saves the Belle II detector geometry to a root or GDML file. "
36 "GDML support is only available if Geant4 has been compiled with "
37 "GDML enabled. This requires the xerces XML parser headers to "
38 "be installed when compiling the externals");
41 addParam(
"Filename", m_filenameROOT,
"The filename of the output file.",
string(
"Belle2.root"));
42 addParam(
"asGDML", m_exportAsGDML,
"If True export as Geant4 GDML format, "
43 "otherwise export as ROOT file", m_exportAsGDML);
44 addParam(
"addAddresses", m_gdmlAdresses,
"If True the names in the GDML file "
45 "will be unique by adding their pointer address. This makes checking "
46 "for differences problematic but would allow to use the Geometry directly",
51 ExportGeometryModule::~ExportGeometryModule() =
default;
54 void ExportGeometryModule::initialize()
57 if (!FileSystem::fileDirExists(m_filenameROOT)) {
58 B2ERROR(
"Parameter <Filename>: The path of the filename " << m_filenameROOT <<
" does not exist !");
62 B2ERROR(
"This Geant4 version does not have GDML support, please recompile the externals with the xerces headers installed");
68 void ExportGeometryModule::beginRun()
70 if (!geometry::GeometryManager::getInstance().getTopVolume()) {
71 B2ERROR(
"No Geometry found, cannot export anything");
77 if (FileSystem::fileExists(m_filenameROOT)) {
78 B2ERROR(
"Cannot export Geometry to GDML: file '" << m_filenameROOT <<
"' already exists");
80 parser.Write(m_filenameROOT, geometry::GeometryManager::getInstance().getTopVolume(), m_gdmlAdresses);
85 B2FATAL(
"This Geant4 version does not have GDML support, please recompile the externals with the xerces headers installed");
88 geometry::GeometryManager::getInstance().createTGeoRepresentation();
89 gGeoManager->Export(m_filenameROOT.c_str());