From e1400f724f9501a7bbcc99b82ffd83f453ccc712 Mon Sep 17 00:00:00 2001
From: Johannes Josef Junggeburth <johannes.josef.junggeburth@cern.ch>
Date: Thu, 9 Jan 2025 11:59:38 +0100
Subject: [PATCH] Minor clean up of the cut volume action. Use PVLinks and make
 intrusive

---
 .../GeoModelKernel/GeoCutVolAction.h          |  8 +++---
 .../GeoModelKernel/src/GeoCutVolAction.cxx    | 28 +++++++++----------
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h
index 95d0ad375..85129e66d 100644
--- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h
+++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCutVolAction.h
@@ -63,16 +63,16 @@ class GeoCutVolAction : public GeoVolumeAction
   virtual void handleVPhysVol (const GeoVPhysVol* vPV);
   
   // Get the cutoff result
-  GeoPhysVol* getPV();
-  GeoFullPhysVol* getFPV();
+  GeoIntrusivePtr<GeoPhysVol> getPV();
+  GeoIntrusivePtr<GeoFullPhysVol> getFPV();
 
  private: 
-  GeoVPhysVol*               m_physVol{nullptr};
+  PVLink m_physVol{nullptr};
 
   const GeoShape&            m_shape;
   const GeoTrf::Transform3D& m_transform;
 
-  std::stack<GeoVPhysVol*>   m_copyStack;
+  std::stack<PVLink>   m_copyStack;
 };
 
 #endif
diff --git a/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx b/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx
index 8f4e43578..806b31604 100755
--- a/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx
+++ b/GeoModelCore/GeoModelKernel/src/GeoCutVolAction.cxx
@@ -27,7 +27,7 @@ void GeoCutVolAction::handleVPhysVol(const GeoVPhysVol *vPV)
   unsigned int pathLen = this->getState()->getPath()->getLength();
 
   // Get Logical Volume details
-  const GeoLogVol* lvOriginal = vPV->getLogVol();
+  GeoIntrusivePtr<const GeoLogVol> lvOriginal = vPV->getLogVol();
   const std::string& lvNameOriginal = lvOriginal->getName();
   const GeoMaterial* lvMatOriginal = lvOriginal->getMaterial();
   const GeoShape* lvShapeOriginal = lvOriginal->getShape();
@@ -35,13 +35,13 @@ void GeoCutVolAction::handleVPhysVol(const GeoVPhysVol *vPV)
   if(pathLen==0) {
     // We are at the first PV. Create the resulting PV
     const GeoShape& cutShape = lvShapeOriginal->subtract(m_shape << m_transform);
-    GeoLogVol* lvNew = new GeoLogVol(lvNameOriginal,&cutShape,lvMatOriginal);
+    GeoIntrusivePtr<GeoLogVol> lvNew = make_intrusive<GeoLogVol>(lvNameOriginal,&cutShape,lvMatOriginal);
 
     if(dynamic_cast<const GeoFullPhysVol*>(vPV)) {
-      m_physVol = new GeoFullPhysVol(lvNew);
+      m_physVol = make_intrusive<GeoFullPhysVol>(lvNew);
     }
     else {
-      m_physVol = new GeoPhysVol(lvNew);
+      m_physVol = make_intrusive<GeoPhysVol>(lvNew);
     }
     
     // Save the new PV in the copy stack
@@ -57,17 +57,17 @@ void GeoCutVolAction::handleVPhysVol(const GeoVPhysVol *vPV)
 
     // Construct new PV
     const GeoShape& cutShape = lvShapeOriginal->subtract(m_shape << cutTransform);
-    GeoLogVol* lvNew = new GeoLogVol(lvNameOriginal,&cutShape,lvMatOriginal);
-    GeoPhysVol* pvNew = new GeoPhysVol(lvNew);
+    GeoIntrusivePtr<GeoLogVol> lvNew = make_intrusive<GeoLogVol>(lvNameOriginal,&cutShape,lvMatOriginal);
+    PVLink pvNew = make_intrusive<GeoPhysVol>(lvNew);
 
     // Get its characteristics (name, id, transform to parent)
     std::string pvName = getState()->getName();
-    if(!pvName.empty()) copyParent->add(new GeoNameTag(pvName));
+    if(!pvName.empty()) copyParent->add(make_intrusive<GeoNameTag>(pvName));
 
     const Query<int> pvId = getState()->getId();
-    if(pvId.isValid()) copyParent->add(new GeoIdentifierTag(pvId));
+    if(pvId.isValid()) copyParent->add(make_intrusive<GeoIdentifierTag>(pvId));
 
-    copyParent->add(new GeoTransform(getState()->getTransform()));
+    copyParent->add(make_intrusive<GeoTransform>(getState()->getTransform()));
     copyParent->add(pvNew);
 
     // Save new PV in the copy stack
@@ -75,13 +75,11 @@ void GeoCutVolAction::handleVPhysVol(const GeoVPhysVol *vPV)
   }
 }
 
-GeoPhysVol* GeoCutVolAction::getPV()
-{
-  return dynamic_cast<GeoPhysVol*>(m_physVol);
+GeoIntrusivePtr<GeoPhysVol> GeoCutVolAction::getPV() {
+  return dynamic_pointer_cast<GeoPhysVol>(m_physVol);
 }
 
-GeoFullPhysVol* GeoCutVolAction::getFPV()
-{
-  return dynamic_cast<GeoFullPhysVol*>(m_physVol);
+GeoIntrusivePtr<GeoFullPhysVol> GeoCutVolAction::getFPV() {
+  return dynamic_pointer_cast<GeoFullPhysVol>(m_physVol);
 }
 
-- 
GitLab