Skip to content
Snippets Groups Projects
Commit 6ddff28d authored by Vakhtang Tsulaia's avatar Vakhtang Tsulaia Committed by Melissa Yexley
Browse files

GeoModelExperiment: partially migrated to GeoIntrusivePtr

GeoModelExperiment modified to hold a vector of smart pointers to temporary
boolean envelope volumes instead of the vector of bare pointers.
More changes are expected in the code of GeoModelExperiment to complete the
migration to smart pointers
parent 179fc74d
No related branches found
No related tags found
No related merge requests found
/*
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;
};
......
/*
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);
}
/*
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;
}
......
/*
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment