diff --git a/k4ActsTracking/src/components/ActsGeoSvc.cpp b/k4ActsTracking/src/components/ActsGeoSvc.cpp index c6f618f..2be77ac 100644 --- a/k4ActsTracking/src/components/ActsGeoSvc.cpp +++ b/k4ActsTracking/src/components/ActsGeoSvc.cpp @@ -28,6 +28,7 @@ #include "DD4hep/Printout.h" #include "GaudiKernel/Service.h" #include "TGeoManager.h" +#include "k4Interface/IGeoSvc.h" using namespace Gaudi; @@ -35,31 +36,12 @@ DECLARE_COMPONENT(ActsGeoSvc) ActsGeoSvc::ActsGeoSvc(const std::string& name, ISvcLocator* svc) : base_class(name, svc), m_log(msgSvc(), name) {} -ActsGeoSvc::~ActsGeoSvc() { - if (m_dd4hepGeo != nullptr) { - try { - m_dd4hepGeo->destroyInstance(); - m_dd4hepGeo = nullptr; - } catch (...) { - } - } -} +ActsGeoSvc::~ActsGeoSvc(){}; StatusCode ActsGeoSvc::initialize() { - if (m_xmlFileNames.size() > 0) { - m_log << MSG::INFO << "Loading xml files from: '" << m_xmlFileNames << "'" << endmsg; - } else { - m_log << MSG::ERROR << "No xml file!" << endmsg; - return StatusCode::FAILURE; - } - - /// Check if the DD4Hep Geometry is built successfully - if (buildDD4HepGeo().isFailure()) { - m_log << MSG::ERROR << "Could not build DD4Hep geometry" << endmsg; - return StatusCode::FAILURE; - } else { - m_log << MSG::INFO << "DD4Hep geometry SUCCESSFULLY built" << endmsg; - } + m_dd4hepGeo = svcLocator()->service(m_geoSvcName)->getDetector(); + // necessary? + // m_dd4hepGeo->addExtension(this); Acts::BinningType bTypePhi = Acts::equidistant; Acts::BinningType bTypeR = Acts::equidistant; @@ -96,21 +78,6 @@ StatusCode ActsGeoSvc::execute() { return StatusCode::SUCCESS; } StatusCode ActsGeoSvc::finalize() { return StatusCode::SUCCESS; } -StatusCode ActsGeoSvc::buildDD4HepGeo() { - m_dd4hepGeo = &(dd4hep::Detector::getInstance()); - m_dd4hepGeo->addExtension(this); - - /// Load geometry - for (auto& filename : m_xmlFileNames) { - m_log << MSG::INFO << "Loading geometry from file: '" << filename << "'" << endmsg; - m_dd4hepGeo->fromCompact(filename); - } - m_dd4hepGeo->volumeManager(); - m_dd4hepGeo->apply("DD4hepVolumeManager", 0, nullptr); - - return StatusCode::SUCCESS; -} - /// Create a geometry OBJ file StatusCode ActsGeoSvc::createGeoObj() { // Convert DD4Hep geometry to acts diff --git a/k4ActsTracking/src/components/ActsGeoSvc.h b/k4ActsTracking/src/components/ActsGeoSvc.h index 3e895ee..ff3e852 100644 --- a/k4ActsTracking/src/components/ActsGeoSvc.h +++ b/k4ActsTracking/src/components/ActsGeoSvc.h @@ -17,8 +17,8 @@ * limitations under the License. */ -#ifndef GEOSVC_H -#define GEOSVC_H +#ifndef ACTSGEOSVC_H +#define ACTSGEOSVC_H #include #include "Acts/Definitions/Common.hpp" @@ -62,8 +62,7 @@ class ActsGeoSvc : public extends { /// ACTS surface lookup container for hit surfaces that generate smeared hits VolumeSurfaceMap m_surfaces; - /// XML-files with the detector description - Gaudi::Property> m_xmlFileNames{this, "detectors", {}, "Detector descriptions XML-files"}; + Gaudi::Property m_geoSvcName{this, "GeoSvcName", "GeoSvc", "The name of the GeoSvc instance"}; /// Option for the Debug Geometry Gaudi::Property m_debugGeometry{this, "debugGeometry", false, "Option for geometry debugging"}; @@ -84,8 +83,6 @@ class ActsGeoSvc : public extends { virtual StatusCode finalize() final; - StatusCode buildDD4HepGeo(); - StatusCode createGeoObj(); virtual const Acts::TrackingGeometry& trackingGeometry() const; diff --git a/k4ActsTracking/src/components/IActsGeoSvc.h b/k4ActsTracking/src/components/IActsGeoSvc.h index cbebf8b..deb5be4 100644 --- a/k4ActsTracking/src/components/IActsGeoSvc.h +++ b/k4ActsTracking/src/components/IActsGeoSvc.h @@ -17,8 +17,8 @@ * limitations under the License. */ -#ifndef IGEOSVC_H -#define IGEOSVC_H +#ifndef IACTSGEOSVC_H +#define IACTSGEOSVC_H #include #include @@ -46,4 +46,4 @@ class GAUDI_API IActsGeoSvc : virtual public IService { virtual ~IActsGeoSvc() {} }; -#endif // IGEOSVC_H +#endif // IACTSGEOSVC_H diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f0e499..b31871d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,3 +35,9 @@ add_test(NAME LoadODD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND k4run options/geosvc.py) set_test_env(LoadODD) + +add_test(NAME CheckODDObjFile + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND test -s MyObjFile.mtl) +set_test_env(CheckODDObjFile) +set_tests_properties(CheckODDObjFile PROPERTIES DEPENDS LoadODD) diff --git a/test/options/geosvc.py b/test/options/geosvc.py index fe259eb..56b0127 100644 --- a/test/options/geosvc.py +++ b/test/options/geosvc.py @@ -17,19 +17,26 @@ # limitations under the License. # import os -from pprint import pprint -from Gaudi.Configuration import * +from Gaudi.Configuration import INFO -from Configurables import ActsGeoSvc +from Configurables import ActsGeoSvc, ApplicationMgr, GeoSvc algList = [] -a = ActsGeoSvc("ActsGeoSvc") -a.detectors = [f"{os.environ['OPENDATADETECTOR']}/xml/OpenDataDetector.xml"] -a.debugGeometry = True -a.outputFileName = "MyObjFile" -from Configurables import ApplicationMgr +dd4hep_geo = GeoSvc("GeoSvc") +dd4hep_geo.detectors = [f"{os.environ['OPENDATADETECTOR']}/xml/OpenDataDetector.xml"] +dd4hep_geo.EnableGeant4Geo = False -ApplicationMgr(TopAlg=algList, EvtSel="NONE", EvtMax=2, ExtSvc=[ -a -], OutputLevel=INFO) +acts_geo = ActsGeoSvc("ActsGeoSvc") +acts_geo.GeoSvcName = dd4hep_geo.name() +acts_geo.debugGeometry = True +acts_geo.outputFileName = "MyObjFile" + +ApplicationMgr( + TopAlg=algList, + EvtSel="NONE", + EvtMax=2, + # order dependent... + ExtSvc=[dd4hep_geo, acts_geo], + OutputLevel=INFO, +)