diff --git a/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoModelExperiment.h b/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoModelExperiment.h index 6c08f01b3cf24f2fa4065661cc931864a1c3ae64..aa4795f19cf5d1c1a6ed06b553695dcb72a91a0b 100755 --- a/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoModelExperiment.h +++ b/DetectorDescription/GeoModel/GeoModelUtilities/GeoModelUtilities/GeoModelExperiment.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ //-------------------------------------------------------------------------------------------// @@ -12,8 +12,8 @@ // // //-------------------------------------------------------------------------------------------// -#ifndef GEOMODELSVC_GEOMODELEXPERIMENT_H -#define GEOMODELSVC_GEOMODELEXPERIMENT_H +#ifndef GEOMODELUTILITIES_GEOMODELEXPERIMENT_H +#define GEOMODELUTILITIES_GEOMODELEXPERIMENT_H /// Ensure that the extensions for the Vector3D are properly loaded #include "GeoPrimitives/GeoPrimitives.h" @@ -89,7 +89,7 @@ public: ConstIterator beginManager() const; // ConstIterator endManager() const; // // Add temporary volumes created during Geo2G4 translation // - void addTmpVolume(GeoPhysVol* volume); // + void addTmpVolume(PVConstLink volume); // // // //-----------------------------------------------------------------------------------------// @@ -97,7 +97,7 @@ public: GeoPhysVol *m_physVol; collection_type m_managers; - std::vector<GeoPhysVol*> m_tmpVolumes; + std::vector<PVConstLink> m_tmpVolumes; }; diff --git a/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoModelExperiment.cxx b/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoModelExperiment.cxx index 0357f770867b9be992045fd3e7d9cc1c81d444ce..e0920e4a3d5bf7bd08c743c1a12b8d4e9a2e66b0 100755 --- a/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoModelExperiment.cxx +++ b/DetectorDescription/GeoModel/GeoModelUtilities/src/GeoModelExperiment.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelUtilities/GeoModelExperiment.h" @@ -21,11 +21,6 @@ GeoModelExperiment::GeoModelExperiment( GeoPhysVol * physVol ) ** Destructor **/ GeoModelExperiment::~GeoModelExperiment() { - // Unref all temporary volumes - std::vector<GeoPhysVol*>::iterator it = m_tmpVolumes.begin(); - for(; it!=m_tmpVolumes.end(); ++it) - (*it)->unref(); - m_physVol->unref(); } @@ -92,7 +87,7 @@ bool GeoModelExperiment::LexigraphicalOrder::operator () (const value_type & a, return a->getName()< b->getName(); } -void GeoModelExperiment::addTmpVolume(GeoPhysVol* volume) +void GeoModelExperiment::addTmpVolume(PVConstLink volume) { m_tmpVolumes.push_back(volume); } diff --git a/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx b/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx index 0436f93828fc737078f1eb4e7b90466b7eb117d0..c6458acd3feb2b0330600399e526c9da65e9396b 100644 --- a/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx +++ b/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "Geo2G4Builder.h" @@ -36,29 +36,32 @@ Geo2G4Builder::Geo2G4Builder(const std::string& detectorName) : AthMessaging("Geo2G4Builder") , m_detectorName(detectorName) , m_motherTransform(GeoTrf::Transform3D::Identity()) - , m_matAir(nullptr) - , m_pDetStore(nullptr) { ISvcLocator* svcLocator = Gaudi::svcLocator(); // from Bootstrap StatusCode sc=svcLocator->service("DetectorStore",m_pDetStore); if (sc.isFailure()) { - ATH_MSG_FATAL("Geo2G4Builder for detector "<<detectorName<<"could not access the detector store - PANIC!!!!"); - abort(); + std::string errorMessage{"ERROR: Geo2G4Builder for detector " + detectorName + " could not access the detector store."}; + ATH_MSG_FATAL(errorMessage); + throw std::runtime_error(errorMessage); } - const GeoModelExperiment* theExpt = nullptr; - sc = m_pDetStore->retrieve( theExpt, "ATLAS" ); + sc = m_pDetStore->retrieve( m_theExpt, "ATLAS" ); if(sc.isFailure()){ - ATH_MSG_ERROR("Detector "<< detectorName << "could not get GeoModelExperiment!"); - } else { - const GeoVDetectorManager *theManager = theExpt->getManager(detectorName); + std::string errorMessage{"ERROR: " + detectorName + " could not get GeoModelExperiment"}; + ATH_MSG_FATAL(errorMessage); + throw std::runtime_error(errorMessage); + } + else { + const GeoVDetectorManager *theManager = m_theExpt->getManager(detectorName); - for(unsigned int i=0; i<theManager->getNumTreeTops(); i++) + for(unsigned int i=0; i<theManager->getNumTreeTops(); ++i) { m_treeTops.push_back(theManager->getTreeTop(i)); + } ATH_MSG_INFO("Found detector: top volume(s)"); - for(unsigned int i=0; i<m_treeTops.size();i++) + for(unsigned int i=0; i<m_treeTops.size();++i) { ATH_MSG_INFO( " Tree Top " << i << " " << m_treeTops[i]->getLogVol()->getName() ); + } if(m_treeTops.size()>1) { // -------- -------- MATERIAL MANAGER -------- ---------- @@ -86,35 +89,36 @@ Geo2G4Builder::Geo2G4Builder(const std::string& detectorName) G4LogicalVolume* Geo2G4Builder::BuildTree() { ATH_MSG_DEBUG("Entering Geo2G4Builder::BuildTree()..."); - G4LogicalVolume* result = 0; - OpticalVolumesMap* optical_volumes = 0; - const GeoBorderSurfaceContainer* surface_container = 0; + G4LogicalVolume* result = nullptr; + OpticalVolumesMap* optical_volumes = nullptr; + const GeoBorderSurfaceContainer* surface_container = nullptr; // Check whether we have to deal with optical surfaces - if(m_pDetStore->contains<GeoBorderSurfaceContainer>(m_detectorName)) - { - StatusCode sc = m_pDetStore->retrieve(surface_container,m_detectorName); - if(sc.isSuccess() && surface_container!=0 && surface_container->size()>0) - optical_volumes = new OpticalVolumesMap(); + if(m_pDetStore->contains<GeoBorderSurfaceContainer>(m_detectorName)) { + StatusCode sc = m_pDetStore->retrieve(surface_container,m_detectorName); + if(sc.isSuccess() && surface_container->size()>0) { + optical_volumes = new OpticalVolumesMap(); } + } if(m_theBuilder) { if(m_treeTops.size()==1) { m_motherTransform = m_treeTops[0]->getX(); result = m_theBuilder->Build(m_treeTops[0],optical_volumes); - } else { + } + else { // Create temporary GeoModel physical volume // The shape is composed by TreeTop shapes + their transforms const GeoShape& shFirst = (*(m_treeTops[0]->getLogVol()->getShape()))<<(m_treeTops[0]->getX()); const GeoShape* shResult = &shFirst; - for(unsigned int i=1; i<m_treeTops.size(); i++){ + for(unsigned int i=1; i<m_treeTops.size(); i++) { shResult = & shResult->add((*(m_treeTops[i]->getLogVol()->getShape()))<<(m_treeTops[i]->getX())); } GeoLogVol* lvEnvelope = new GeoLogVol(m_detectorName,shResult,m_matAir); GeoPhysVol* pvEnvelope = new GeoPhysVol(lvEnvelope); - + m_theExpt->addTmpVolume(pvEnvelope); result = m_theBuilder->Build(pvEnvelope); // Get pointer to the World @@ -147,24 +151,19 @@ G4LogicalVolume* Geo2G4Builder::BuildTree() false, id); } - - // Add the temporary physical volume to the GeoModelExperiment - GeoModelExperiment * theExpt = nullptr; - StatusCode sc = m_pDetStore->retrieve(theExpt,"ATLAS"); - if(sc.isFailure()) - ATH_MSG_WARNING("Unable to retrieve GeoModelExperiment. Temporary volume cannot be released"); - else - theExpt->addTmpVolume(pvEnvelope); } } // build optical surfaces if necessary - if(optical_volumes!=0 && optical_volumes->size()>0){ - BuildOpticalSurfaces(surface_container,optical_volumes); - } else if (optical_volumes!=0){ - ATH_MSG_WARNING("Optical volumes apparently requested, but none found! Deleting temps"); + if(optical_volumes) { + if(optical_volumes->size()>0) { + BuildOpticalSurfaces(surface_container,optical_volumes); + } + else { + ATH_MSG_WARNING("Optical volumes apparently requested, but none found! Deleting temps"); + } + delete optical_volumes; } - if (optical_volumes!=0) delete optical_volumes; return result; } diff --git a/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.h b/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.h index 3cd7cbe0e717199ad64aa0699e7648221b4cfc10..bc9cf8f8c7d832bca7dfb872d914d0f964c010d3 100644 --- a/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.h +++ b/Simulation/G4Utilities/Geo2G4/src/Geo2G4Builder.h @@ -1,24 +1,22 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ -#ifndef GEO2G4_Geo2G4Builder_H -#define GEO2G4_Geo2G4Builder_H +#ifndef GEO2G4_GEO2G4BUILDER_H +#define GEO2G4_GEO2G4BUILDER_H -// main builder to create/position all volumes described in a GeoModel Tree +/** + * @class Geo2G4Builder + * @brief Main builder to create/position all volumes described in a GeoModel Tree + */ -// GeoVPhysVol #include "VolumeBuilder.h" #include "GeoModelKernel/GeoVPhysVol.h" #include "GeoModelKernel/GeoDefinitions.h" #include "G4LogicalVolume.hh" -//#include "Geo2G4/GenericVolumeBuilder.h" -// Typedef #include "GeoModelUtilities/GeoBorderSurfaceContainer.h" - #include "AthenaBaseComps/AthMessaging.h" - #include "GeoPrimitives/CLHEPtoEigenConverter.h" // STL includes @@ -27,6 +25,7 @@ class GeoMaterial; class StoreGateSvc; +class GeoModelExperiment; class Geo2G4Builder : public AthMessaging { @@ -34,7 +33,7 @@ public: // Constructor: Geo2G4Builder(const std::string& detectorName); // Destructor: - ~Geo2G4Builder() {;} + ~Geo2G4Builder() = default; // Build method - geometry G4LogicalVolume* BuildTree(); @@ -57,8 +56,9 @@ private: VolumeBuilder *m_theBuilder; // std::Air in the case when top boolean envelope has to be built - const GeoMaterial* m_matAir; - StoreGateSvc* m_pDetStore; + const GeoMaterial* m_matAir{nullptr}; + StoreGateSvc* m_pDetStore{nullptr}; + GeoModelExperiment* m_theExpt{nullptr}; }; #endif