From b8bac83bb3b80ff0a0fc8baba7454d776984fd45 Mon Sep 17 00:00:00 2001
From: Andre Sailer <andre.philippe.sailer@cern.ch>
Date: Mon, 26 Apr 2021 17:34:03 +0200
Subject: [PATCH] Segmentations: remove unused SegmentationFactory (there is
 another), remove REGISTER_SEGMENATION, re-arrange and fix segmentations

---
 DDCore/include/DD4hep/GridPhiEta.h            |  1 -
 DDCore/include/DD4hep/GridRPhiEta.h           |  1 -
 .../DD4hep/detail/SegmentationsInterna.h      |  8 +-
 DDCore/include/DDSegmentation/Segmentation.h  |  6 +-
 .../DDSegmentation/SegmentationFactory.h      | 88 -------------------
 DDCore/src/CartesianGridXY.cpp                |  1 -
 DDCore/src/CartesianGridXYZ.cpp               |  1 -
 DDCore/src/CartesianGridXZ.cpp                |  1 -
 DDCore/src/CartesianGridYZ.cpp                |  1 -
 DDCore/src/CartesianStripX.cpp                |  1 -
 DDCore/src/CartesianStripY.cpp                |  1 -
 DDCore/src/CartesianStripZ.cpp                |  1 -
 DDCore/src/MultiSegmentation.cpp              |  1 -
 DDCore/src/NoSegmentation.cpp                 |  1 -
 DDCore/src/PolarGridRPhi.cpp                  |  1 -
 DDCore/src/PolarGridRPhi2.cpp                 |  1 -
 DDCore/src/SegmentationsInterna.cpp           |  2 +
 DDCore/src/WaferGridXY.cpp                    |  1 -
 DDCore/src/plugins/ReadoutSegmentations.cpp   |  1 -
 DDCore/src/segmentations/CartesianGridXY.cpp  |  5 +-
 DDCore/src/segmentations/CartesianGridXYZ.cpp |  4 +-
 DDCore/src/segmentations/CartesianGridXZ.cpp  |  4 +-
 DDCore/src/segmentations/CartesianGridYZ.cpp  |  4 +-
 DDCore/src/segmentations/CartesianStripX.cpp  |  3 +-
 DDCore/src/segmentations/CartesianStripY.cpp  |  3 +-
 DDCore/src/segmentations/CartesianStripZ.cpp  |  3 +-
 DDCore/src/segmentations/GridPhiEta.cpp       |  3 +-
 DDCore/src/segmentations/GridRPhiEta.cpp      |  3 +-
 .../src/segmentations/MegatileLayerGridXY.cpp |  4 +-
 .../src/segmentations/MultiSegmentation.cpp   |  6 +-
 DDCore/src/segmentations/NoSegmentation.cpp   |  3 +-
 DDCore/src/segmentations/PolarGridRPhi.cpp    |  3 +-
 DDCore/src/segmentations/PolarGridRPhi2.cpp   |  3 +-
 .../src/segmentations/ProjectiveCylinder.cpp  |  4 +-
 .../src/segmentations/SegmentationFactory.cpp | 58 ------------
 DDCore/src/segmentations/TiledLayerGridXY.cpp |  4 +-
 DDCore/src/segmentations/WaferGridXY.cpp      |  5 +-
 37 files changed, 55 insertions(+), 186 deletions(-)
 delete mode 100644 DDCore/include/DDSegmentation/SegmentationFactory.h
 delete mode 100644 DDCore/src/segmentations/SegmentationFactory.cpp

diff --git a/DDCore/include/DD4hep/GridPhiEta.h b/DDCore/include/DD4hep/GridPhiEta.h
index ebf3a079a..67dab0f7b 100644
--- a/DDCore/include/DD4hep/GridPhiEta.h
+++ b/DDCore/include/DD4hep/GridPhiEta.h
@@ -18,7 +18,6 @@
 // Framework includes
 #include "DDSegmentation/GridPhiEta.h"
 #include "DD4hep/Segmentations.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 
 /// Namespace for the AIDA detector description toolkit
 namespace dd4hep {
diff --git a/DDCore/include/DD4hep/GridRPhiEta.h b/DDCore/include/DD4hep/GridRPhiEta.h
index 68761dfdb..c081bec79 100644
--- a/DDCore/include/DD4hep/GridRPhiEta.h
+++ b/DDCore/include/DD4hep/GridRPhiEta.h
@@ -18,7 +18,6 @@
 // Framework includes
 #include "DD4hep/Segmentations.h"
 #include "DDSegmentation/GridRPhiEta.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 
 /// Namespace for the AIDA detector description toolkit
 namespace dd4hep {
diff --git a/DDCore/include/DD4hep/detail/SegmentationsInterna.h b/DDCore/include/DD4hep/detail/SegmentationsInterna.h
index a3d35ef45..a43606b33 100644
--- a/DDCore/include/DD4hep/detail/SegmentationsInterna.h
+++ b/DDCore/include/DD4hep/detail/SegmentationsInterna.h
@@ -17,7 +17,6 @@
 #include "DD4hep/Handle.h"
 #include "DD4hep/Objects.h"
 #include "DD4hep/BitFieldCoder.h"
-#include "DDSegmentation/Segmentation.h"
 
 // C/C++ include files
 
@@ -29,6 +28,13 @@ namespace dd4hep {
   class SegmentationObject;
   class SensitiveDetectorObject;
 
+  namespace DDSegmentation {
+    class Segmentation;
+    class SegmentationParameter;
+    typedef SegmentationParameter* Parameter;
+    typedef std::vector<Parameter> Parameters;
+  }
+
   /// Implementation class supporting generic Segmentation of sensitive detectors
   /**
    *  The SegmentationObject wraps the functionality of the DDSegmentation base class.
diff --git a/DDCore/include/DDSegmentation/Segmentation.h b/DDCore/include/DDSegmentation/Segmentation.h
index 2d401d407..0c59d1fe1 100644
--- a/DDCore/include/DDSegmentation/Segmentation.h
+++ b/DDCore/include/DDSegmentation/Segmentation.h
@@ -19,8 +19,8 @@
 #ifndef DDSEGMENTATION_SEGMENTATION_H
 #define DDSEGMENTATION_SEGMENTATION_H
 
+#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/BitFieldCoder.h"
-#include "DDSegmentation/SegmentationFactory.h"
 #include "DDSegmentation/SegmentationParameter.h"
 
 #include <map>
@@ -177,10 +177,6 @@ namespace dd4hep {
       Segmentation(const Segmentation&);
     };
 
-    /// Macro to instantiate a new SegmentationCreator by its type name
-#define REGISTER_SEGMENTATION(classname)                                \
-    static const SegmentationCreator<classname> classname##_creator(#classname);
-
   } /* namespace DDSegmentation */
 } /* namespace dd4hep */
 #endif // DDSEGMENTATION_SEGMENTATION_H
diff --git a/DDCore/include/DDSegmentation/SegmentationFactory.h b/DDCore/include/DDSegmentation/SegmentationFactory.h
deleted file mode 100644
index 2e1dd1994..000000000
--- a/DDCore/include/DDSegmentation/SegmentationFactory.h
+++ /dev/null
@@ -1,88 +0,0 @@
-//==========================================================================
-//  AIDA Detector description implementation 
-//--------------------------------------------------------------------------
-// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
-// All rights reserved.
-//
-// For the licensing terms see $DD4hepINSTALL/LICENSE.
-// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
-//
-//==========================================================================
-
-/*
- * SegmentationFactory.h
- *
- * Factory and helper classes to allow instantiation of segmentations by name.
- *
- *  Created on: Dec 15, 2013
- *      Author: Christian Grefe, CERN
- */
-
-#ifndef DDSEGMENTATION_SEGMENTATIONFACTORY_H
-#define DDSEGMENTATION_SEGMENTATIONFACTORY_H
-
-#include "DDSegmentation/Segmentation.h"
-
-#include <map>
-#include <vector>
-#include <string>
-
-namespace dd4hep {
-  namespace DDSegmentation {
-
-    /// Forward declaration required because of circular dependency
-    class Segmentation;
-    class SegmentationCreatorBase;
-
-    /// Base class for the SegmentationCreator objects. Allows to use the factory without template.
-    class SegmentationCreatorBase {
-    public:
-      /// Default constructor. Takes the class name as argument and takes care of registration with the factory
-      SegmentationCreatorBase(const std::string& name);
-      /// Destructor
-      virtual ~SegmentationCreatorBase() {};
-      /// Create a new object
-      virtual Segmentation* create(const std::string& identifier) const = 0;
-    };
-
-    /// Concrete class to create segmentation objects. Every segmentation needs to instantiate a static instance of this.
-    template<class TYPE> class SegmentationCreator : public SegmentationCreatorBase {
-    public:
-      /// Default constructor. Takes the class name as argument which should match the class type
-      SegmentationCreator<TYPE>(const std::string& name) : SegmentationCreatorBase(name) {};
-      /// Destructor
-      virtual ~SegmentationCreator() {};
-      /// Create a new object of the given type.
-      Segmentation* create(const std::string& identifier) const {return new TYPE(identifier);};
-    };
-
-    /// Factory for creating segmentation objects by type name
-    class SegmentationFactory {
-      /// Allow SegmentationCreators to register themselves with the factory
-      friend class SegmentationCreatorBase;
-    public:
-      /// Access to the global factory instance
-      static SegmentationFactory* instance();
-      /// Create a new segmentation object with the given type name. Returns NULL if type name is unknown.
-      Segmentation* create(const std::string& name, const std::string& identifier = "") const;
-      /// Access to the list of registered segmentations
-      std::vector<std::string> registeredSegmentations() const;
-    protected:
-      /// Default constructor
-      SegmentationFactory() {};
-      /// Copy constructor
-      SegmentationFactory(const SegmentationFactory&) {};
-      /// Destructor
-      virtual ~SegmentationFactory() {};
-      /// Registers a new SegmentationCreator with the factory
-      void registerSegmentation(const std::string& name, SegmentationCreatorBase* creator);
-      /// Map to store SegmentationCreators by name
-      std::map<std::string, SegmentationCreatorBase*> _segmentations;
-    private:
-      /// The global factory instance
-      static SegmentationFactory* _instance;
-    };
-
-  } /* namespace DDSegmentation */
-} /* namespace dd4hep */
-#endif // DDSEGMENTATION_SEGMENTATIONFACTORY_H
diff --git a/DDCore/src/CartesianGridXY.cpp b/DDCore/src/CartesianGridXY.cpp
index d0f7b72b6..949aefba3 100644
--- a/DDCore/src/CartesianGridXY.cpp
+++ b/DDCore/src/CartesianGridXY.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianGridXY.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianGridXY.h"
 
 // C/C++ include files
diff --git a/DDCore/src/CartesianGridXYZ.cpp b/DDCore/src/CartesianGridXYZ.cpp
index 88c706a6f..ae4017c7a 100644
--- a/DDCore/src/CartesianGridXYZ.cpp
+++ b/DDCore/src/CartesianGridXYZ.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianGridXYZ.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianGridXYZ.h"
 
 // C/C++ include files
diff --git a/DDCore/src/CartesianGridXZ.cpp b/DDCore/src/CartesianGridXZ.cpp
index 431b06c4f..8bc00bd89 100644
--- a/DDCore/src/CartesianGridXZ.cpp
+++ b/DDCore/src/CartesianGridXZ.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianGridXZ.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianGridXZ.h"
 
 // C/C++ include files
diff --git a/DDCore/src/CartesianGridYZ.cpp b/DDCore/src/CartesianGridYZ.cpp
index ed045595c..a7fbc27a6 100644
--- a/DDCore/src/CartesianGridYZ.cpp
+++ b/DDCore/src/CartesianGridYZ.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianGridYZ.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianGridYZ.h"
 
 // C/C++ include files
diff --git a/DDCore/src/CartesianStripX.cpp b/DDCore/src/CartesianStripX.cpp
index 0987e4a90..413150051 100644
--- a/DDCore/src/CartesianStripX.cpp
+++ b/DDCore/src/CartesianStripX.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianStripX.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianStripX.h"
 
 using namespace std;
diff --git a/DDCore/src/CartesianStripY.cpp b/DDCore/src/CartesianStripY.cpp
index 5a4156163..91e38b48b 100644
--- a/DDCore/src/CartesianStripY.cpp
+++ b/DDCore/src/CartesianStripY.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianStripY.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianStripY.h"
 
 using namespace std;
diff --git a/DDCore/src/CartesianStripZ.cpp b/DDCore/src/CartesianStripZ.cpp
index ff564d3a4..8ea1333f2 100644
--- a/DDCore/src/CartesianStripZ.cpp
+++ b/DDCore/src/CartesianStripZ.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/CartesianStripZ.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/CartesianStripZ.h"
 
 using namespace std;
diff --git a/DDCore/src/MultiSegmentation.cpp b/DDCore/src/MultiSegmentation.cpp
index d293c7ed1..7cc357cdc 100644
--- a/DDCore/src/MultiSegmentation.cpp
+++ b/DDCore/src/MultiSegmentation.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/MultiSegmentation.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/MultiSegmentation.h"
 
 // C/C++ include files
diff --git a/DDCore/src/NoSegmentation.cpp b/DDCore/src/NoSegmentation.cpp
index f48afa0c0..7b226f90f 100644
--- a/DDCore/src/NoSegmentation.cpp
+++ b/DDCore/src/NoSegmentation.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/NoSegmentation.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/NoSegmentation.h"
 
 // C/C++ include files
diff --git a/DDCore/src/PolarGridRPhi.cpp b/DDCore/src/PolarGridRPhi.cpp
index 3cde97121..0bddb1fb2 100644
--- a/DDCore/src/PolarGridRPhi.cpp
+++ b/DDCore/src/PolarGridRPhi.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/PolarGridRPhi.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/PolarGridRPhi.h"
 
 // C/C++ include files
diff --git a/DDCore/src/PolarGridRPhi2.cpp b/DDCore/src/PolarGridRPhi2.cpp
index d3a527de0..b2976faba 100644
--- a/DDCore/src/PolarGridRPhi2.cpp
+++ b/DDCore/src/PolarGridRPhi2.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/PolarGridRPhi2.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/PolarGridRPhi2.h"
 
 // C/C++ include files
diff --git a/DDCore/src/SegmentationsInterna.cpp b/DDCore/src/SegmentationsInterna.cpp
index 53fbc6382..88edfed21 100644
--- a/DDCore/src/SegmentationsInterna.cpp
+++ b/DDCore/src/SegmentationsInterna.cpp
@@ -15,6 +15,8 @@
 #include "DD4hep/detail/SegmentationsInterna.h"
 #include "DD4hep/InstanceCount.h"
 
+#include "DDSegmentation/Segmentation.h"
+
 using namespace std;
 using namespace dd4hep;
 
diff --git a/DDCore/src/WaferGridXY.cpp b/DDCore/src/WaferGridXY.cpp
index e365bc202..a55585688 100644
--- a/DDCore/src/WaferGridXY.cpp
+++ b/DDCore/src/WaferGridXY.cpp
@@ -13,7 +13,6 @@
 
 // Framework include files
 #include "DD4hep/WaferGridXY.h"
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DDSegmentation/WaferGridXY.h"
 
 // C/C++ include files
diff --git a/DDCore/src/plugins/ReadoutSegmentations.cpp b/DDCore/src/plugins/ReadoutSegmentations.cpp
index 8da001cc7..8105d461c 100644
--- a/DDCore/src/plugins/ReadoutSegmentations.cpp
+++ b/DDCore/src/plugins/ReadoutSegmentations.cpp
@@ -12,7 +12,6 @@
 //==========================================================================
 
 // Framework includes
-#include "DD4hep/detail/SegmentationsInterna.h"
 #include "DD4hep/Factories.h"
 
 using namespace dd4hep;
diff --git a/DDCore/src/segmentations/CartesianGridXY.cpp b/DDCore/src/segmentations/CartesianGridXY.cpp
index dae82fb7d..88cce3e9e 100644
--- a/DDCore/src/segmentations/CartesianGridXY.cpp
+++ b/DDCore/src/segmentations/CartesianGridXY.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/CartesianGridXY.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -75,7 +76,9 @@ std::vector<double> CartesianGridXY::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianGridXY)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+
+DECLARE_SEGMENTATION(CartesianGridXY,dd4hep::create_segmentation<dd4hep::DDSegmentation::CartesianGridXY>)
diff --git a/DDCore/src/segmentations/CartesianGridXYZ.cpp b/DDCore/src/segmentations/CartesianGridXYZ.cpp
index 440981497..1f8d420a1 100644
--- a/DDCore/src/segmentations/CartesianGridXYZ.cpp
+++ b/DDCore/src/segmentations/CartesianGridXYZ.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/CartesianGridXYZ.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -71,7 +72,8 @@ std::vector<double> CartesianGridXYZ::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianGridXYZ)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(CartesianGridXYZ,create_segmentation<dd4hep::DDSegmentation::CartesianGridXYZ>)
diff --git a/DDCore/src/segmentations/CartesianGridXZ.cpp b/DDCore/src/segmentations/CartesianGridXZ.cpp
index 396dc2ec6..e89599ac6 100644
--- a/DDCore/src/segmentations/CartesianGridXZ.cpp
+++ b/DDCore/src/segmentations/CartesianGridXZ.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/CartesianGridXZ.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -78,7 +79,8 @@ std::vector<double> CartesianGridXZ::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianGridXZ)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(CartesianGridXZ,create_segmentation<dd4hep::DDSegmentation::CartesianGridXZ>)
diff --git a/DDCore/src/segmentations/CartesianGridYZ.cpp b/DDCore/src/segmentations/CartesianGridYZ.cpp
index 652506190..1ff9bb5c9 100644
--- a/DDCore/src/segmentations/CartesianGridYZ.cpp
+++ b/DDCore/src/segmentations/CartesianGridYZ.cpp
@@ -7,6 +7,7 @@
  *     by Christian Grefe, CERN
  */
 #include "DDSegmentation/CartesianGridYZ.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -76,7 +77,8 @@ std::vector<double> CartesianGridYZ::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianGridYZ)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(CartesianGridYZ,create_segmentation<dd4hep::DDSegmentation::CartesianGridYZ>)
diff --git a/DDCore/src/segmentations/CartesianStripX.cpp b/DDCore/src/segmentations/CartesianStripX.cpp
index 3ad573948..a105b9355 100644
--- a/DDCore/src/segmentations/CartesianStripX.cpp
+++ b/DDCore/src/segmentations/CartesianStripX.cpp
@@ -7,6 +7,7 @@
  */
 
 #include "DDSegmentation/CartesianStripX.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -62,6 +63,6 @@ std::vector<double> CartesianStripX::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianStripX)
 }  // namespace DDSegmentation
 } /* namespace dd4hep */
+DECLARE_SEGMENTATION(CartesianStripX,create_segmentation<dd4hep::DDSegmentation::CartesianStripX>)
diff --git a/DDCore/src/segmentations/CartesianStripY.cpp b/DDCore/src/segmentations/CartesianStripY.cpp
index 036597541..e2403f11e 100644
--- a/DDCore/src/segmentations/CartesianStripY.cpp
+++ b/DDCore/src/segmentations/CartesianStripY.cpp
@@ -7,6 +7,7 @@
  */
 
 #include "DDSegmentation/CartesianStripY.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -62,6 +63,6 @@ std::vector<double> CartesianStripY::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianStripY)
 }  // namespace DDSegmentation
 } /* namespace dd4hep */
+DECLARE_SEGMENTATION(CartesianStripY,create_segmentation<dd4hep::DDSegmentation::CartesianStripY>)
diff --git a/DDCore/src/segmentations/CartesianStripZ.cpp b/DDCore/src/segmentations/CartesianStripZ.cpp
index 8b7590108..d2e27ac6d 100644
--- a/DDCore/src/segmentations/CartesianStripZ.cpp
+++ b/DDCore/src/segmentations/CartesianStripZ.cpp
@@ -7,6 +7,7 @@
  */
 
 #include "DDSegmentation/CartesianStripZ.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -62,6 +63,6 @@ std::vector<double> CartesianStripZ::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(CartesianStripZ)
 }  // namespace DDSegmentation
 } /* namespace dd4hep */
+DECLARE_SEGMENTATION(CartesianStripZ,create_segmentation<dd4hep::DDSegmentation::CartesianStripZ>)
diff --git a/DDCore/src/segmentations/GridPhiEta.cpp b/DDCore/src/segmentations/GridPhiEta.cpp
index 0b4b64030..7a8b0e541 100644
--- a/DDCore/src/segmentations/GridPhiEta.cpp
+++ b/DDCore/src/segmentations/GridPhiEta.cpp
@@ -1,5 +1,6 @@
 #include "DDSegmentation/GridPhiEta.h"
 #include "DDSegmentation/SegmentationUtil.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -55,7 +56,7 @@ double GridPhiEta::phi(const CellID& cID) const {
   CellID phiValue = _decoder->get(cID, m_phiID);
   return binToPosition(phiValue, 2.*M_PI/(double)m_phiBins, m_offsetPhi);
 }
-REGISTER_SEGMENTATION(GridPhiEta)
 }
 }
 
+DECLARE_SEGMENTATION(GridPhiEta,create_segmentation<dd4hep::DDSegmentation::GridPhiEta>)
diff --git a/DDCore/src/segmentations/GridRPhiEta.cpp b/DDCore/src/segmentations/GridRPhiEta.cpp
index 00335d125..dafff9915 100644
--- a/DDCore/src/segmentations/GridRPhiEta.cpp
+++ b/DDCore/src/segmentations/GridRPhiEta.cpp
@@ -1,5 +1,6 @@
 #include "DDSegmentation/GridRPhiEta.h"
 #include "DDSegmentation/SegmentationUtil.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -47,7 +48,7 @@ double GridRPhiEta::r(const CellID& cID) const {
   CellID rValue = _decoder->get(cID, m_rID);
   return binToPosition(rValue, m_gridSizeR, m_offsetR);
 }
-REGISTER_SEGMENTATION(GridRPhiEta)
 }
 }
 
+DECLARE_SEGMENTATION(GridRPhiEta,create_segmentation<dd4hep::DDSegmentation::GridRPhiEta>)
diff --git a/DDCore/src/segmentations/MegatileLayerGridXY.cpp b/DDCore/src/segmentations/MegatileLayerGridXY.cpp
index 1bb022e00..bbe7c6c5a 100644
--- a/DDCore/src/segmentations/MegatileLayerGridXY.cpp
+++ b/DDCore/src/segmentations/MegatileLayerGridXY.cpp
@@ -7,6 +7,7 @@
  */
 
 #include "DDSegmentation/MegatileLayerGridXY.h"
+#include "DD4hep/Factories.h"
 
 #undef NDEBUG
 #include <cmath>
@@ -183,7 +184,8 @@ namespace dd4hep {
 #endif
     }
 
-    REGISTER_SEGMENTATION(MegatileLayerGridXY)
 
   } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(MegatileLayerGridXY,create_segmentation<dd4hep::DDSegmentation::MegatileLayerGridXY>)
diff --git a/DDCore/src/segmentations/MultiSegmentation.cpp b/DDCore/src/segmentations/MultiSegmentation.cpp
index 3c3241896..bdc3b93ee 100644
--- a/DDCore/src/segmentations/MultiSegmentation.cpp
+++ b/DDCore/src/segmentations/MultiSegmentation.cpp
@@ -6,6 +6,8 @@
  */
 
 #include "DDSegmentation/MultiSegmentation.h"
+#include "DD4hep/Factories.h"
+
 #include <iomanip>
 #include <stdexcept>
 #include <iostream>
@@ -98,7 +100,7 @@ namespace dd4hep {
       return subsegmentation(cID).cellDimensions(cID);
     }
 
-    REGISTER_SEGMENTATION(MultiSegmentation)
-
   } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(MultiSegmentation,create_segmentation<dd4hep::DDSegmentation::MultiSegmentation>)
diff --git a/DDCore/src/segmentations/NoSegmentation.cpp b/DDCore/src/segmentations/NoSegmentation.cpp
index ae3f50049..67ba05b69 100644
--- a/DDCore/src/segmentations/NoSegmentation.cpp
+++ b/DDCore/src/segmentations/NoSegmentation.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/NoSegmentation.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
   namespace DDSegmentation {
@@ -36,7 +37,7 @@ namespace dd4hep {
       return vID;
     }
 
-REGISTER_SEGMENTATION(NoSegmentation)
 
   } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+DECLARE_SEGMENTATION(NoSegmentation,create_segmentation<dd4hep::DDSegmentation::NoSegmentation>)
diff --git a/DDCore/src/segmentations/PolarGridRPhi.cpp b/DDCore/src/segmentations/PolarGridRPhi.cpp
index 782211945..112af39bd 100644
--- a/DDCore/src/segmentations/PolarGridRPhi.cpp
+++ b/DDCore/src/segmentations/PolarGridRPhi.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/PolarGridRPhi.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -81,7 +82,7 @@ std::vector<double> PolarGridRPhi::cellDimensions(const CellID& cID) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(PolarGridRPhi)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+DECLARE_SEGMENTATION(PolarGridRPhi,create_segmentation<dd4hep::DDSegmentation::PolarGridRPhi>)
diff --git a/DDCore/src/segmentations/PolarGridRPhi2.cpp b/DDCore/src/segmentations/PolarGridRPhi2.cpp
index 73c1d29e4..6bbf5aa71 100644
--- a/DDCore/src/segmentations/PolarGridRPhi2.cpp
+++ b/DDCore/src/segmentations/PolarGridRPhi2.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/PolarGridRPhi2.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -103,7 +104,7 @@ std::vector<double> PolarGridRPhi2::cellDimensions(const CellID& cID) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(PolarGridRPhi2)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+DECLARE_SEGMENTATION(PolarGridRPhi2,create_segmentation<dd4hep::DDSegmentation::PolarGridRPhi2>)
diff --git a/DDCore/src/segmentations/ProjectiveCylinder.cpp b/DDCore/src/segmentations/ProjectiveCylinder.cpp
index 37c5ce675..6a4e021d9 100644
--- a/DDCore/src/segmentations/ProjectiveCylinder.cpp
+++ b/DDCore/src/segmentations/ProjectiveCylinder.cpp
@@ -7,6 +7,7 @@
 
 #include "DDSegmentation/ProjectiveCylinder.h"
 #include "DDSegmentation/SegmentationUtil.h"
+#include "DD4hep/Factories.h"
 
 #define _USE_MATH_DEFINES
 #include <cmath>
@@ -80,7 +81,8 @@ double ProjectiveCylinder::phi(const CellID& cID) const {
 	return 2. * M_PI * ((double) phiIndex + 0.5) / (double) _phiBins;
 }
 
-REGISTER_SEGMENTATION(ProjectiveCylinder)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(ProjectiveCylinder,create_segmentation<dd4hep::DDSegmentation::ProjectiveCylinder>)
diff --git a/DDCore/src/segmentations/SegmentationFactory.cpp b/DDCore/src/segmentations/SegmentationFactory.cpp
deleted file mode 100644
index 4806a4475..000000000
--- a/DDCore/src/segmentations/SegmentationFactory.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * SegmentationFactory.cpp
- *
- *  Created on: Dec 15, 2013
- *      Author: Christian Grefe, CERN
- */
-
-#include "DDSegmentation/SegmentationFactory.h"
-
-namespace dd4hep {
-namespace DDSegmentation {
-
-using std::map;
-using std::vector;
-
-/// Default constructor. Takes the class name as argument and takes care of registration with the factory
-SegmentationCreatorBase::SegmentationCreatorBase(const std::string& name) {
-	SegmentationFactory::instance()->registerSegmentation(name, this);
-}
-
-/// Initialize the global factory instance
-SegmentationFactory* SegmentationFactory::_instance = 0;
-
-/// Access to the global factory instance
-SegmentationFactory* SegmentationFactory::instance() {
-	if (not _instance) {
-		_instance = new SegmentationFactory();
-	}
-	return _instance;
-}
-
-/// Create a new segmentation object with the given type name. Returns NULL if type name is unknown.
-Segmentation* SegmentationFactory::create(const std::string& name, const std::string& identifier) const {
-	map<std::string, SegmentationCreatorBase*>::const_iterator it;
-	it = _segmentations.find(name);
-	if (it != _segmentations.end()) {
-		return it->second->create(identifier);
-	}
-	return 0;
-}
-
-/// Access to the list of registered segmentations
-vector<std::string> SegmentationFactory::registeredSegmentations() const {
-	vector<std::string> segmentationNames;
-	map<std::string, SegmentationCreatorBase*>::const_iterator it;
-	for (it = _segmentations.begin(); it != _segmentations.end(); ++ it) {
-		segmentationNames.emplace_back(it->first);
-	}
-	return segmentationNames;
-}
-
-/// Registers a new SegmentationCreator with the factory
-void SegmentationFactory::registerSegmentation(const std::string& name, SegmentationCreatorBase* creator) {
-	_segmentations[name] = creator;
-}
-
-} /* namespace DDSegmentation */
-} /* namespace dd4hep */
diff --git a/DDCore/src/segmentations/TiledLayerGridXY.cpp b/DDCore/src/segmentations/TiledLayerGridXY.cpp
index aa46448d9..36ac18155 100644
--- a/DDCore/src/segmentations/TiledLayerGridXY.cpp
+++ b/DDCore/src/segmentations/TiledLayerGridXY.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/TiledLayerGridXY.h"
+#include "DD4hep/Factories.h"
 
 // C/C++ includes
 #include <algorithm>
@@ -122,7 +123,8 @@ std::vector<double> TiledLayerGridXY::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(TiledLayerGridXY)
 
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(TiledLayerGridXY,create_segmentation<dd4hep::DDSegmentation::TiledLayerGridXY>)
diff --git a/DDCore/src/segmentations/WaferGridXY.cpp b/DDCore/src/segmentations/WaferGridXY.cpp
index 5b7ad3848..52c9a4e08 100644
--- a/DDCore/src/segmentations/WaferGridXY.cpp
+++ b/DDCore/src/segmentations/WaferGridXY.cpp
@@ -6,6 +6,7 @@
  */
 
 #include "DDSegmentation/WaferGridXY.h"
+#include "DD4hep/Factories.h"
 
 namespace dd4hep {
 namespace DDSegmentation {
@@ -126,7 +127,7 @@ std::vector<double> WaferGridXY::cellDimensions(const CellID&) const {
 #endif
 }
 
-REGISTER_SEGMENTATION(WaferGridXY)
-
 } /* namespace DDSegmentation */
 } /* namespace dd4hep */
+
+DECLARE_SEGMENTATION(WaferGridXY,create_segmentation<dd4hep::DDSegmentation::WaferGridXY>)
-- 
GitLab