From 006e3cbd4758ef3fdd33d8a467b11a9143a1ee86 Mon Sep 17 00:00:00 2001
From: Johannes Junggeburth <johannes.josef.junggeburth@cern.ch>
Date: Fri, 15 Mar 2024 12:30:19 +0100
Subject: [PATCH] GeoPublisher - Compile time check on proper GeoObject type

---
 .../GeoModelKernel/GeoModelKernel/GeoPublisher.h         | 4 ++--
 .../GeoModelKernel/GeoModelKernel/GeoPublisher.tpp       | 7 ++-----
 GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp    | 9 +++------
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h
index 2a474a197..28ad17a2e 100644
--- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h
+++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.h
@@ -45,8 +45,8 @@ typedef std::unordered_map<std::string, std::vector<std::vector<std::variant<int
 class GeoPublisher
 {
  public:
-  GeoPublisher() {}
-  virtual ~GeoPublisher() {}
+  GeoPublisher() = default;
+  virtual ~GeoPublisher() = default;
 
   template<class N, typename T> void publishNode(N node,T keyT);
 
diff --git a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp
index f12b3d691..cd040dbea 100644
--- a/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp
+++ b/GeoModelCore/GeoModelKernel/GeoModelKernel/GeoPublisher.tpp
@@ -9,17 +9,14 @@ template<typename Iter> void GeoPublisher::printInsertionStatus(Iter it, bool su
 template<class N, typename T> void GeoPublisher::publishNode(N node,T keyT) 
 {
     std::any key = keyT;
+    static_assert(std::is_same_v<GeoVFullPhysVol*, N> || std::is_same_v<GeoAlignableTransform*, N>,
+                  "ERROR!!! The node type is not currently supported by 'GeoPublisher'.\n If in doubt, please ask to `geomodel-developers@cern.ch'.\n");
     if constexpr (std::is_same_v<GeoVFullPhysVol*, N>) {
         const auto [iter, success] = m_publishedFPV.insert( {node, key} );
         if(!success) printInsertionStatus(iter, success);
     } else if constexpr (std::is_same_v<GeoAlignableTransform*, N>) {
         const auto [iter, success] = m_publishedAXF.insert( {node, key} );
         if(!success) printInsertionStatus(iter, success);
-    } else {
-        std::cout << "ERROR!!! The node type '" << typeid(N).name() 
-                  << " is not currently supported by 'GeoPublisher'.\n"
-                  << "If in doubt, please ask to `geomodel-developers@cern.ch'.\n"
-                  << std::endl;
     }
 }
 
diff --git a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp
index 8c51af661..82d3f4a91 100644
--- a/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp
+++ b/GeoModelIO/GeoModelRead/GeoModelRead/ReadGeoModel.tpp
@@ -22,6 +22,9 @@ namespace GeoModelIO {
         std::string keyType = "";
 
         std::vector<std::vector<std::string>> vecRecords;
+        static_assert(std::is_same_v<GeoFullPhysVol*, N> || std::is_same_v<GeoAlignableTransform*, N> ,
+                    "ERROR! The node type is not currently supported. If in doubt, please ask to 'geomodel-developers@cern.ch'.\n");
+
         if constexpr ( std::is_same_v<GeoFullPhysVol*, N> ) {
             if(doCheckTable){ 
                 bool tableExists = m_dbManager->checkTable("PublishedFullPhysVols_"+publisherName);
@@ -34,12 +37,6 @@ namespace GeoModelIO {
                 if(!tableExists) return mapNodes;
             }
             vecRecords = m_dbManager->getPublishedAXFTable( publisherName );
-        } else {
-            std::cout << "ERROR! The node type '" << typeid(N).name() 
-                << "' is not currently supported.\n"
-                << "If in doubt, please ask to 'geomodel-developers@cern.ch'.\n"
-                << "Exiting...\n";
-            exit(EXIT_FAILURE);
         }
         unsigned ii = 0;
         for( auto const &record : vecRecords ) {
-- 
GitLab