From 79b3ba83bb95a547f69431a29209988fcde27c4c Mon Sep 17 00:00:00 2001
From: Nicholas Styles <nicholas.styles@desy.de>
Date: Tue, 6 Sep 2022 18:15:00 +0200
Subject: [PATCH] Make add virtual and add to common base so that both
 GeoPhysVol and GeoFullPhysVol can be used as envelopes

---
 .../GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h     |  6 +++---
 .../GeoModelKernel/GeoModelKernel/GeoPhysVol.h         |  5 +++--
 .../GeoModelKernel/GeoModelKernel/GeoVPhysVol.h        |  5 ++++-
 GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx  | 10 ++++++----
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h
index 861cd14b4..99a977940 100644
--- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h
+++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoFullPhysVol.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef GEOMODELKERNEL_GEOFULLPHYSVOL_H
@@ -32,8 +32,8 @@ class GeoFullPhysVol final : public GeoVFullPhysVol
  public:
   GeoFullPhysVol (const GeoLogVol* LogVol);
 
-  /// Adds a Graph Node to the Geometry Graph.
-  void add(GeoGraphNode* graphNode);
+    /// Adds a Graph Node to the Geometry Graph
+  virtual void add(GeoGraphNode* graphNode) override final;
 
   /// Returns the number of child physical volumes.
   virtual unsigned int getNChildVols() const override;
diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h
index 1c35d4ad8..bd2ac00fd 100644
--- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h
+++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPhysVol.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef GEOMODELKERNEL_GEOPHYSVOL_H
@@ -36,7 +36,8 @@ class GeoPhysVol : public GeoVPhysVol
   GeoPhysVol(const GeoPhysVol &right) = delete;
   GeoPhysVol & operator=(const GeoPhysVol &right) = delete;
 
-  void add(GeoGraphNode* graphNode);
+  /// Adds a Graph Node to the Geometry Graph
+  virtual void add(GeoGraphNode* graphNode) override final;
 
   /// Returns the number of child physical volumes.
   virtual unsigned int getNChildVols() const override final;
diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h
index b8f9089a4..d90aefb16 100644
--- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h
+++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoVPhysVol.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef GEOMODELKERNEL_GEOVPHYSVOL_H
@@ -86,6 +86,9 @@ class GeoVPhysVol : public GeoGraphNode
   virtual const GeoGraphNode * const *getChildNode (unsigned int i) const=0;
   virtual const GeoGraphNode * const *findChildNode(const GeoGraphNode *n) const=0;
 
+  /// Adds a Graph Node to the Geometry Graph
+  virtual void add(GeoGraphNode* graphNode) = 0;
+
  protected:
   virtual ~GeoVPhysVol();
 
diff --git a/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx b/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx
index b30e41fb8..b89b976a2 100644
--- a/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx
+++ b/GeoModelTools/GeoModelXML/GeoModelXml/src/Gmx2Geo.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "GeoModelXml/Gmx2Geo.h"
@@ -16,6 +16,8 @@
 #include <xercesc/util/PlatformUtils.hpp>
 
 #include "GeoModelKernel/GeoPhysVol.h"
+#include "GeoModelKernel/GeoVPhysVol.h"
+
 #include "GeoModelKernel/GeoVolumeTagCatalog.h"
 
 #include "ExpressionEvaluator/IEvaluator.h"
@@ -105,17 +107,17 @@ Gmx2Geo::Gmx2Geo(const string& xmlFile, GeoPhysVol *addHere, GmxInterface &gmxIn
 //  ADA - check if an envelope is requested, in case we take is and fill it up with the addbranch's contents.
 
     XMLCh * envelope_tmp=XMLString::transcode("envelope");
-    GeoPhysVol* physVol=addHere;
+    GeoVPhysVol* physVol=addHere;
     if (addbranch->hasAttribute(envelope_tmp))
     {
         char *toRelease=XMLString::transcode(addbranch->getAttribute(envelope_tmp));
 	std::cout<<" envelope requested "<<toRelease<<std::endl;
         std::string envel=toRelease;
 	XMLString::release(&toRelease);
-	GeoPhysVol* tmpVol=dynamic_cast<GeoPhysVol*>(GeoVolumeTagCatalog::VolumeTagCatalog()->getTaggedVolume("Envelope",envel));
+	GeoVPhysVol* tmpVol=GeoVolumeTagCatalog::VolumeTagCatalog()->getTaggedVolume("Envelope",envel);
 	if (tmpVol) 
 	{
-		std::cout<< " volume "<<envel<<" found in the envelope catalog"<<std::endl;
+		std::cout<< " Volume "<<envel<<" found in the envelope catalog"<<std::endl;
 		physVol=tmpVol;
 	}
     }
-- 
GitLab