Belle II Software light-2406-ragdoll
ExportGeometryModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <geometry/modules/ExportGeometryModule.h>
10
11#include <framework/utilities/FileSystem.h>
12#include <geometry/GeometryManager.h>
13#include <TGeoManager.h>
14#ifdef HAS_GDML
15#include <G4GDMLParser.hh>
16#endif
17
18using namespace std;
19using namespace Belle2;
20
21//-----------------------------------------------------------------
22// Register the Module
23//-----------------------------------------------------------------
24REG_MODULE(ExportGeometry);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
31{
32 //Set module properties
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");
37
38 //Parameter definition
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",
46}
47
48
50
51
53{
54 //Check parameters
56 B2ERROR("Parameter <Filename>: The path of the filename " << m_filenameROOT << " does not exist !");
57 }
58#ifndef HAS_GDML
59 if (m_exportAsGDML) {
60 B2ERROR("This Geant4 version does not have GDML support, please recompile the externals with the xerces headers installed");
61 }
62#endif
63}
64
65
67{
68 if (!geometry::GeometryManager::getInstance().getTopVolume()) {
69 B2ERROR("No Geometry found, cannot export anything");
70 return;
71 }
72 if (m_exportAsGDML) {
73#ifdef HAS_GDML
74 G4GDMLParser parser;
76 B2ERROR("Cannot export Geometry to GDML: file '" << m_filenameROOT << "' already exists");
77 } else {
79 }
80 return;
81#else
82 // we should never come here as we checked in initialize but just in case ...
83 B2FATAL("This Geant4 version does not have GDML support, please recompile the externals with the xerces headers installed");
84#endif
85 }
87 gGeoManager->Export(m_filenameROOT.c_str());
88}
virtual void initialize() override
Checks the validity of the module parameters.
std::string m_filenameROOT
The filename of the ROOT file into which the geometry is saved.
bool m_exportAsGDML
Export the geometry as GDML format.
virtual void beginRun() override
Saves the geometry to a root file for every run.
bool m_gdmlAdresses
If true make the xml names unique by prepending the pointer address.
virtual ~ExportGeometryModule()
Destructor.
static bool fileDirExists(const std::string &filename)
Check if the dir containing the filename exists.
Definition: FileSystem.cc:38
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
static GeometryManager & getInstance()
Return a reference to the instance.
void createTGeoRepresentation()
Create a TGeo representation of the native geometry description.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.