From 1527bf46ad73de5b3166e6d41df705ce4f465bb0 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Mon, 1 Apr 2019 17:59:36 +0200
Subject: [PATCH] Fix factory errors

---
 DDCore/src/DetectorImp.cpp   | 5 +++--
 DDG4/src/Geant4Converter.cpp | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/DDCore/src/DetectorImp.cpp b/DDCore/src/DetectorImp.cpp
index 1192a8f56..5015d7240 100644
--- a/DDCore/src/DetectorImp.cpp
+++ b/DDCore/src/DetectorImp.cpp
@@ -701,10 +701,11 @@ void DetectorImp::dump() const {
 long DetectorImp::apply(const char* factory_type, int argc, char** argv)   const   {
   string fac = factory_type;
   try {
-    long result = PluginService::Create<long>(fac, (Detector*) this, argc, argv);
+    Detector* thisPtr = const_cast<DetectorImp*>(this);
+    long result = PluginService::Create<long>(fac, thisPtr, argc, argv);
     if (0 == result) {
       PluginDebug dbg;
-      result = PluginService::Create<long>(fac, (Detector*) this, argc, argv);
+      result = PluginService::Create<long>(fac, thisPtr, argc, argv);
       if ( 0 == result )  {
         throw runtime_error("dd4hep: apply-plugin: Failed to locate plugin " +
                             fac + ". " + dbg.missingFactory(fac));
diff --git a/DDG4/src/Geant4Converter.cpp b/DDG4/src/Geant4Converter.cpp
index fcfba4fbb..739c17956 100644
--- a/DDG4/src/Geant4Converter.cpp
+++ b/DDG4/src/Geant4Converter.cpp
@@ -1042,7 +1042,8 @@ void Geant4Converter::handleProperties(Detector::Properties& prp) const {
     const Detector::PropertyValues& vals = prp[nam];
     string type = vals.find("type")->second;
     string tag = type + "_Geant4_action";
-    long result = PluginService::Create<long>(tag, &m_detDesc, hdlr, &vals);
+    Detector* detPtr = const_cast<Detector*>(&m_detDesc);
+    long result = PluginService::Create<long>(tag, detPtr, hdlr, &vals);
     if (0 == result) {
       throw runtime_error("Failed to locate plugin to interprete files of type"
                           " \"" + tag + "\" - no factory:" + type);
-- 
GitLab