From 480ef37ec202acda95277402e8f3106850d27571 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Thu, 29 Sep 2016 17:02:51 +0200
Subject: [PATCH] Externalize properties

---
 DDCore/include/DD4hep/BasicGrammar_inl.h      | 15 ++++++++++---
 .../include/DD4hep/ComponentProperties_inl.h  |  8 ++++---
 DDCore/include/DD4hep/Plugins.h               |  9 +++++---
 DDCore/include/DD4hep/Plugins.inl             |  2 +-
 DDCore/src/ComponentProperties.cpp            | 12 +++++++----
 DDCore/src/Plugins.cpp                        | 21 ++++++++++++++-----
 DDCore/src/ToStream.cpp                       |  2 ++
 7 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/DDCore/include/DD4hep/BasicGrammar_inl.h b/DDCore/include/DD4hep/BasicGrammar_inl.h
index 4d9fba2c4..c63ec7056 100644
--- a/DDCore/include/DD4hep/BasicGrammar_inl.h
+++ b/DDCore/include/DD4hep/BasicGrammar_inl.h
@@ -26,14 +26,23 @@
 #include "DD4hep/Primitives.h"
 #include "DD4hep/BasicGrammar.h"
 
-#include "XML/Evaluator.h"
-
 #ifdef DD4HEP_USE_BOOST
+#if defined(DD4HEP_PARSER_HEADER)
+
+#define DD4HEP_NEED_EVALUATOR
+// This is the case, if the parsers are externalized
+// and the DD4hep namespace is renamed!
+#include DD4HEP_PARSER_HEADER
+
+#else
+
+#include "XML/Evaluator.h"
 #include "DD4hep/Parsers.h"
 #include "DD4hep/ToStream.h"
 namespace DD4hep { XmlTools::Evaluator& g4Evaluator();  }
-#endif
 namespace {  static XmlTools::Evaluator& s__eval(DD4hep::g4Evaluator());  }
+#endif
+#endif
 
 #ifndef DD4HEP_PARSERS_NO_ROOT
 #include "Math/Point3D.h"
diff --git a/DDCore/include/DD4hep/ComponentProperties_inl.h b/DDCore/include/DD4hep/ComponentProperties_inl.h
index c47ab782b..d9a5b547f 100644
--- a/DDCore/include/DD4hep/ComponentProperties_inl.h
+++ b/DDCore/include/DD4hep/ComponentProperties_inl.h
@@ -71,6 +71,7 @@ namespace DD4hep {
 
 }      // End namespace DD4hep
 
+#ifndef DD4HEP_PARSERS_NO_ROOT
 // These operators do not really belong here, but also nowhere else.....
 // ....except the proper ROOT headers perhaps?
 #include "Math/Point3D.h"
@@ -80,13 +81,14 @@ namespace DD4hep {
 namespace ROOT {
   namespace Math {
     /// Allow point insertion of a point in maps
-    bool operator<(const XYZPoint& a, const XYZPoint& b);
+    inline bool operator<(const XYZPoint& a, const XYZPoint& b);
     /// Allow 3-vector insertion of a  in maps
-    bool operator<(const XYZVector& a, const XYZVector& b);
+    inline bool operator<(const XYZVector& a, const XYZVector& b);
     /// Allow 4-vector insertion of a  in maps
-    bool operator<(const PxPyPzEVector& a, const PxPyPzEVector& b);
+    inline bool operator<(const PxPyPzEVector& a, const PxPyPzEVector& b);
   }
 }
+#endif
 
 // Instantiate single property
 #define DD4HEP_DEFINE_PROPERTY_TYPE(x)                    \
diff --git a/DDCore/include/DD4hep/Plugins.h b/DDCore/include/DD4hep/Plugins.h
index e5bb38b13..c96eb6f40 100644
--- a/DDCore/include/DD4hep/Plugins.h
+++ b/DDCore/include/DD4hep/Plugins.h
@@ -19,7 +19,10 @@
 #include <string>
 #include <vector>
 #include <typeinfo>
+
+#ifndef DD4HEP_PARSERS_NO_ROOT
 #include "RVersion.h"
+#endif
 
 /// Namespace for the AIDA detector description toolkit
 namespace DD4hep {
@@ -109,7 +112,7 @@ namespace DD4hep {
                             const std::type_info& signature_type,
                             const std::type_info& return_type);
 
-#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
+#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
     template <typename R> static R Create(const std::string& name);
 
     template <typename R, typename A0>
@@ -142,7 +145,7 @@ namespace DD4hep {
   public:
     typedef PluginService svc_t;
     typedef SIGNATURE signature_t;
-#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
+#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
     typedef void (*stub_t)(void *retaddr, void*, const std::vector<void*>& arg, void*);
     static void add(const char* name, stub_t stub);
 #else
@@ -153,7 +156,7 @@ namespace DD4hep {
   };
 } /* End namespace DD4hep      */
 
-#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
+#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
 #define DD4HEP_FACTORY_CALL(type,name,signature) DD4hep::PluginRegistry<signature>::add(name,Factory<type,signature>::wrapper);
 #else
 namespace DD4hep {
diff --git a/DDCore/include/DD4hep/Plugins.inl b/DDCore/include/DD4hep/Plugins.inl
index 6e2b94450..8b442ec27 100644
--- a/DDCore/include/DD4hep/Plugins.inl
+++ b/DDCore/include/DD4hep/Plugins.inl
@@ -17,7 +17,7 @@
 
 #include "DD4hep/Plugins.h"
 
-#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
+#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
 #include <set>
 #include <map>
 #include <list>
diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp
index 5dcdcb839..5236807c0 100644
--- a/DDCore/src/ComponentProperties.cpp
+++ b/DDCore/src/ComponentProperties.cpp
@@ -253,10 +253,6 @@ namespace DD4hep {
 #include <set>
 #include <map>
 
-#include "Math/Point3D.h"
-#include "Math/Vector3D.h"
-#include "Math/Vector4D.h"
-
 #include "DD4hep/BasicGrammar_inl.h"
 #include "DD4hep/ComponentProperties_inl.h"
 DD4HEP_DEFINE_PARSER_GRAMMAR_TYPE(Property)
@@ -290,9 +286,17 @@ namespace DD4hep {
 
   typedef map<string, string> map_string_string;
   DD4HEP_DEFINE_PROPERTY_TYPE(map_string_string);
+}
 
+#ifndef DD4HEP_PARSERS_NO_ROOT
+#include "Math/Point3D.h"
+#include "Math/Vector3D.h"
+#include "Math/Vector4D.h"
+
+namespace DD4hep {
   // ROOT::Math Object instances
   DD4HEP_DEFINE_PROPERTY_TYPE(ROOT::Math::XYZPoint);
   DD4HEP_DEFINE_PROPERTY_TYPE(ROOT::Math::XYZVector);
   DD4HEP_DEFINE_PROPERTY_TYPE(ROOT::Math::PxPyPzEVector);
 }
+#endif
diff --git a/DDCore/src/Plugins.cpp b/DDCore/src/Plugins.cpp
index 996b81e80..c6178fbee 100644
--- a/DDCore/src/Plugins.cpp
+++ b/DDCore/src/Plugins.cpp
@@ -13,11 +13,11 @@
 //==========================================================================
 
 // Framework include files
-#include "DD4hep/LCDD.h"
-#include "DD4hep/Handle.h"
+//#include "DD4hep/LCDD.h"
+//#include "DD4hep/Handle.h"
 #include "DD4hep/Plugins.inl"
-#include "DD4hep/GeoHandler.h"
-#include "XML/XMLElements.h"
+//#include "DD4hep/GeoHandler.h"
+//#include "XML/XMLElements.h"
 
 using namespace std;
 using namespace DD4hep;
@@ -40,7 +40,7 @@ bool PluginService::setDebug(bool new_value)   {
   return old_value;
 }
 
-#if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
+#if !defined(DD4HEP_PARSERS_NO_ROOT) && ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
 
 /// Default constructor
 PluginDebug::PluginDebug(int dbg)
@@ -68,7 +68,11 @@ void  PluginService::addFactory(const std::string&, void*, const std::type_info&
 
 #else   // ROOT 6
 #include "DD4hep/Printout.h"
+#if !defined(DD4HEP_PARSERS_NO_ROOT)
 #include "TSystem.h"
+#else
+#include <dlfcn.h>
+#endif
 
 namespace   {
   struct PluginInterface  {
@@ -88,7 +92,14 @@ namespace   {
 
   template <typename T> 
   static inline T get_func(const char* plugin, const char* entry)  {
+#if !defined(DD4HEP_PARSERS_NO_ROOT)
     PluginService::FuncPointer<Func_t> fun(gSystem->DynFindSymbol(plugin,entry));
+#else
+    PluginService::FuncPointer<Func_t> fun(0);
+    if ( 0 == fun.fun.ptr )    {
+    
+  }
+#endif
     PluginService::FuncPointer<T> fp(fun.fptr.ptr);
     if ( 0 == fp.fptr.ptr )      {
       string err = "DD4hep:PluginService: Failed to access symbol "
diff --git a/DDCore/src/ToStream.cpp b/DDCore/src/ToStream.cpp
index 65f1f2e4a..b1d0838cc 100644
--- a/DDCore/src/ToStream.cpp
+++ b/DDCore/src/ToStream.cpp
@@ -14,6 +14,8 @@
 
 // Framework include files
 #if defined(DD4HEP_PARSER_HEADER)
+
+#define DD4HEP_NEED_EVALUATOR
 // This is the case, if the parsers are externalized
 // and the DD4hep namespace is renamed!
 #include DD4HEP_PARSER_HEADER
-- 
GitLab