File indexing completed on 2025-01-30 10:30:21
0001
0002
0003
0004 #include "GeoSvc.h"
0005 #include "GaudiKernel/Service.h"
0006 #include "TGeoManager.h"
0007
0008 #include "DD4hep/Printout.h"
0009
0010 using namespace Gaudi;
0011
0012
0013 DECLARE_COMPONENT(GeoSvc)
0014
0015 GeoSvc::GeoSvc(const std::string& name, ISvcLocator* svc)
0016 : base_class(name, svc)
0017 , m_log(msgSvc(), name) {}
0018
0019 GeoSvc::~GeoSvc() {
0020 if (m_dd4hepGeo != nullptr) {
0021 try {
0022 m_dd4hepGeo->destroyInstance();
0023 m_dd4hepGeo = nullptr;
0024 } catch (...) {
0025 }
0026 }
0027 }
0028
0029 StatusCode GeoSvc::initialize() {
0030 StatusCode sc = Service::initialize();
0031 if (!sc.isSuccess()) {
0032 return sc;
0033 }
0034
0035 if (msgLevel() >= MSG::INFO) {
0036 TGeoManager::SetVerboseLevel(0);
0037 }
0038 uint printoutLevel = msgLevel();
0039 dd4hep::setPrintLevel(dd4hep::PrintLevel(printoutLevel));
0040 if (buildDD4HepGeo().isFailure()) {
0041 m_log << MSG::ERROR << "Could not build DD4Hep geometry" << endmsg;
0042 } else {
0043 m_log << MSG::INFO << "DD4Hep geometry SUCCESSFULLY built" << endmsg;
0044 }
0045
0046 return StatusCode::SUCCESS;
0047 }
0048
0049 StatusCode GeoSvc::finalize() { return StatusCode::SUCCESS; }
0050
0051 StatusCode GeoSvc::buildDD4HepGeo() {
0052
0053 m_dd4hepGeo = &(dd4hep::Detector::getInstance());
0054 m_dd4hepGeo->addExtension<IGeoSvc>(this);
0055
0056
0057 for (auto& filename : m_xmlFileNames) {
0058 m_log << MSG::INFO << "loading geometry from file: '" << filename << "'" << endmsg;
0059 m_dd4hepGeo->fromCompact(filename);
0060 }
0061 m_dd4hepGeo->volumeManager();
0062 m_dd4hepGeo->apply("DD4hepVolumeManager", 0, nullptr);
0063 return StatusCode::SUCCESS;
0064 }
0065
0066 dd4hep::Detector* GeoSvc::getDetector() { return (m_dd4hepGeo); }
0067
0068 dd4hep::DetElement GeoSvc::getDD4HepGeo() { return (getDetector()->world()); }