9 #include <geometry/modules/ExportGeometryModule.h>
11 #include <framework/utilities/FileSystem.h>
12 #include <geometry/GeometryManager.h>
13 #include <TGeoManager.h>
15 #include <G4GDMLParser.hh>
33 setDescription(
"Saves the Belle II detector geometry to a root or GDML file. "
34 "GDML support is only available if Geant4 has been compiled with "
35 "GDML enabled. This requires the xerces XML parser headers to "
36 "be installed when compiling the externals");
39 addParam(
"Filename", m_filenameROOT,
"The filename of the output file.",
string(
"Belle2.root"));
40 addParam(
"asGDML", m_exportAsGDML,
"If True export as Geant4 GDML format, "
41 "otherwise export as ROOT file", m_exportAsGDML);
42 addParam(
"addAddresses", m_gdmlAdresses,
"If True the names in the GDML file "
43 "will be unique by adding their pointer address. This makes checking "
44 "for differences problematic but would allow to use the Geometry directly",
49 ExportGeometryModule::~ExportGeometryModule() =
default;
52 void ExportGeometryModule::initialize()
55 if (!FileSystem::fileDirExists(m_filenameROOT)) {
56 B2ERROR(
"Parameter <Filename>: The path of the filename " << m_filenameROOT <<
" does not exist !");
60 B2ERROR(
"This Geant4 version does not have GDML support, please recompile the externals with the xerces headers installed");
66 void ExportGeometryModule::beginRun()
68 if (!geometry::GeometryManager::getInstance().getTopVolume()) {
69 B2ERROR(
"No Geometry found, cannot export anything");
75 if (FileSystem::fileExists(m_filenameROOT)) {
76 B2ERROR(
"Cannot export Geometry to GDML: file '" << m_filenameROOT <<
"' already exists");
78 parser.Write(m_filenameROOT, geometry::GeometryManager::getInstance().getTopVolume(), m_gdmlAdresses);
83 B2FATAL(
"This Geant4 version does not have GDML support, please recompile the externals with the xerces headers installed");
86 geometry::GeometryManager::getInstance().createTGeoRepresentation();
87 gGeoManager->Export(m_filenameROOT.c_str());
The ExportGeometry module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.