diff --git a/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx b/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx index 0e0aba4cf4b0ae2f95cbf8b01e6766e38c07c7eb..dff9d876784bf56c095abecddd497c4f6ec209e0 100644 --- a/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx +++ b/GeoModelCore/GeoModelHelpers/src/GeoDeDuplicator.cxx @@ -12,6 +12,12 @@ GeoDeDuplicator::GeoIdMap GeoDeDuplicator::s_geoIds{}; namespace { std::mutex s_mutex{}; + ///typeis function uses simple arguments to typeid (not an expression) to avoid warnings + template<class A, class B> + bool + typeis(B && b){ + return typeid(A) == typeid(b); + } } void GeoDeDuplicator::setShapeDeDuplication(bool enable){ @@ -124,10 +130,10 @@ PVLink GeoDeDuplicator::clone(PVConstLink cloneMe) const { for(unsigned int chNode =0; chNode < cloneMe->getNChildNodes(); ++chNode) { GeoIntrusivePtr<const GeoGraphNode>node{*cloneMe->getChildNode(chNode)}; /** transform nodes */ - if (typeid(*node) == typeid(GeoAlignableTransform)) { + if (typeis<GeoAlignableTransform>(*node)) { const auto geoTrf = dynamic_pointer_cast<const GeoAlignableTransform>(node); newVol->add(make_intrusive<GeoAlignableTransform>(geoTrf->getDefTransform())); - } else if (typeid(*node) == typeid(GeoTransform)) { + } else if (typeis<GeoTransform>(*node)) { const auto geoTrf = dynamic_pointer_cast<const GeoTransform>(node); auto geoTrfNonConst = const_pointer_cast(geoTrf); newVol->add(cacheTransform(geoTrfNonConst)); diff --git a/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx b/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx index 6177229d4eca7b978af1bde3e25aed6491c7abfb..f214a36e027de86d9c03d671e9bc819513ae7067 100644 --- a/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx +++ b/GeoModelCore/GeoModelHelpers/src/cloneVolume.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ #include "GeoModelHelpers/cloneVolume.h" #include "GeoModelHelpers/getChildNodesWithTrf.h" @@ -7,18 +7,27 @@ #include "GeoModelKernel/GeoFullPhysVol.h" #include "GeoModelKernel/GeoPhysVol.h" +namespace{ + ///typeis function uses simple arguments to typeid (not an expression) to avoid warnings + template<class A, class B> + bool + typeis(B && b){ + return typeid(A) == typeid(b); + } +} + PVLink cloneVolume(const PVLink& volume, bool allowShared) { PVLink newVolume{volume}; if (!allowShared || hasFullPhysVolInTree(volume)) { - if (typeid(*volume) == typeid(GeoPhysVol)) { + if (typeis<GeoPhysVol>(*volume)) { newVolume = make_intrusive<GeoPhysVol>(volume->getLogVol()); - } else if (typeid(*volume) == typeid(GeoFullPhysVol)) { + } else if (typeis<GeoFullPhysVol>(*volume)) { newVolume = make_intrusive<GeoFullPhysVol>(volume->getLogVol()); } for (unsigned int ch = 0; ch < volume->getNChildNodes(); ++ch){ const GeoGraphNode* node = (*volume->getChildNode(ch)); - if (typeid(*node) == typeid(GeoPhysVol) || typeid(*node) == typeid(GeoFullPhysVol)) { + if (typeis<GeoPhysVol>(*node) || typeis<GeoFullPhysVol>(*node)) { const GeoVPhysVol* childConstVol{static_cast<const GeoVPhysVol*>(node)}; GeoVPhysVol* childVol{const_cast<GeoVPhysVol*>(childConstVol)}; newVolume->add(cloneVolume(childVol, allowShared)); diff --git a/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx b/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx index f1d8fec4b97f47e3b5367a6fe4c1b1c5a1026980..11314ae364c7f08cdf26c929cc1df1152d29d976 100644 --- a/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx +++ b/GeoModelCore/GeoModelHelpers/src/getChildNodesWithTrf.cxx @@ -12,6 +12,12 @@ namespace { constexpr std::string_view dummyNodeName{"ANON"}; + ///typeis function uses simple arguments to typeid (not an expression) to avoid warnings + template<class A, class B> + bool + typeis(B && b){ + return typeid(A) == typeid(b); + } } @@ -20,7 +26,7 @@ namespace { volume{curs.getVolume()}, nodeName{curs.getName()}, isAlignable{curs.hasAlignableTransform()}, - isSensitive{typeid(*volume) == typeid(GeoFullPhysVol)}, + isSensitive{typeis<GeoFullPhysVol>(*volume)}, volumeId{static_cast<const std::optional<int>&>(curs.getId())} { //// Do not specify a node name if it's a dummy one if (nodeName == dummyNodeName) { @@ -95,8 +101,8 @@ std::vector<GeoChildNodeWithTrf> getAllSubVolumes(PVConstLink physVol) { } bool hasFullPhysVolInTree(const PVConstLink& physVol) { - if (typeid(*physVol) == typeid(GeoFullPhysVol) || - typeid(*physVol) == typeid(GeoVFullPhysVol)){ + if (typeis<GeoFullPhysVol>(*physVol) || + typeis<GeoVFullPhysVol>(*physVol)){ return true; } for (unsigned int ch = 0; ch < physVol->getNChildVols(); ++ch) { diff --git a/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx b/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx index b834b3018fe28e9602fc701a18cbf73f8a5eff76..35f7f6a153a758f0922de4548949e8e05bb24350 100644 --- a/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx +++ b/GeoModelCore/GeoModelHelpers/tests/testFullPhysVol.cxx @@ -13,6 +13,15 @@ #include <GeoModelHelpers/getChildNodesWithTrf.h> #include <iostream> +namespace{ + ///typeis function uses simple arguments to typeid (not an expression) to avoid warnings + template<class A> + const char* + safeTypeIdName(A && a){ + return typeid(A).name(); + } +} + int main(int argc, char *argv[]){ GeoIntrusivePtr<GeoMaterial> material = make_intrusive<GeoMaterial>("Snow", 1.45); @@ -90,7 +99,7 @@ int main(int argc, char *argv[]){ std::optional<int> query = cParent->getIdOfChildVol(0); if (!query) { std::cerr<<__FILE__<<":"<<__LINE__<<" Failed to obtain a valid child volume ID. Expected "<<currentK - <<" "<<typeid(*cParent->getChildVol(0)).name()<<std::endl; + <<" "<<safeTypeIdName(*cParent->getChildVol(0))<<std::endl; return EXIT_FAILURE; } unsigned int parentID = *query; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h index 7dc31d3dc5e8e89b4be556755f90111b3d2f2a67..b2f05a2041cb3dff0c393df6b509a9e40c1ccccc 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoAnnulusSurface.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ /* @@ -66,11 +66,11 @@ class GeoAnnulusSurface : public GeoVSurfaceShape // coming soon! //bool isInside(double x, double y) const; - virtual const std::string & type() const{ + virtual const std::string & type() const override final{ return s_classType; } - virtual ShapeType typeID() const{ + virtual ShapeType typeID() const override final{ return s_classTypeID; } diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h index 0dbf060587431cecb1cfeb89050a159615f6d8f0..5d04c4931e54500c7591950e0ac378e303c6e415 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoCountVolAction.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ #ifndef GEOMODELKERNEL_GEOCOUNTVOLACTION_H @@ -14,13 +14,13 @@ class GeoCountVolAction : public GeoNodeAction virtual ~GeoCountVolAction() = default; // Handles a physical volume. - virtual void handlePhysVol (const GeoPhysVol *); + virtual void handlePhysVol (const GeoPhysVol *) override; // Handles a physical volume. - virtual void handleFullPhysVol (const GeoFullPhysVol *); + virtual void handleFullPhysVol (const GeoFullPhysVol *) override; // Handles a Serial Transformer - virtual void handleSerialTransformer (const GeoSerialTransformer *st); + virtual void handleSerialTransformer (const GeoSerialTransformer *st) override; // Handles a virtual surface. virtual void handleVSurface (const GeoVSurface *) override; diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h index bcf1b62cd6a63083768e28610e05b4aa76b9d9d3..d3b55e9c944273b9b0b77b7035218afca1003775 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoDiamondSurface.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ /* @@ -54,11 +54,11 @@ class GeoDiamondSurface : public GeoVSurfaceShape return m_YtopHalf; } - virtual const std::string & type () const{ + virtual const std::string & type () const override final{ return s_classType; } - virtual ShapeType typeID () const{ + virtual ShapeType typeID () const override final{ return s_classTypeID; } diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h index c5a9935c961c2f8d412c0e43279f18995ba9d1ca..1e95164c180e18da82854fa3c50942bc02373f48 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoRectSurface.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ /* @@ -36,11 +36,11 @@ class GeoRectSurface : public GeoVSurfaceShape return m_yHalfLength; } - virtual const std::string & type () const{ + virtual const std::string & type () const override final{ return s_classType; } - virtual ShapeType typeID () const{ + virtual ShapeType typeID () const override final{ return s_classTypeID; } diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h index 91a16c8dc2804c2fb2d84d0e07368693872999bc..8dc31bd88b953296807e5cda6e9681a73de68453 100644 --- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h +++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoTrapezoidSurface.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ /* @@ -42,11 +42,11 @@ class GeoTrapezoidSurface : public GeoVSurfaceShape return m_yHalfLength; } - virtual const std::string & type () const{ + virtual const std::string & type () const override final{ return s_classType; } - virtual ShapeType typeID () const{ + virtual ShapeType typeID () const override final{ return s_classTypeID; }