From bd125de84bf0765a33f39bb31e076b6f9cc76c81 Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Fri, 17 Mar 2017 11:40:30 +0100
Subject: [PATCH] Cleanup in data parsers for XML/JSON

---
 DDCore/include/JSON/ChildValue.h         | 33 ++++++++++++++++++++++++
 DDCore/include/JSON/ChildValue.inl       | 24 +++++++++++++++++
 DDCore/include/JSON/Dimension.h          |  6 ++---
 DDCore/include/XML/detail/ChildValue.imp |  7 +++++
 DDCore/include/XML/detail/ChildValue.inl |  7 ++---
 DDCore/include/XML/detail/Detector.h     | 10 ++-----
 DDCore/include/XML/detail/Detector.imp   |  9 +++++++
 DDCore/include/XML/detail/Dimension.h    |  5 +---
 DDCore/include/XML/detail/Dimension.imp  |  8 +++++-
 DDCore/include/XML/detail/Dimension.inl  |  6 +----
 DDCore/include/XML/detail/README.txt     | 23 +++++++++++++++++
 DDCore/src/JSON/Helpers.cpp              |  4 ++-
 DDCore/src/XML/XMLHelpers.cpp            |  2 ++
 13 files changed, 119 insertions(+), 25 deletions(-)
 create mode 100644 DDCore/include/JSON/ChildValue.h
 create mode 100644 DDCore/include/JSON/ChildValue.inl
 create mode 100644 DDCore/include/XML/detail/README.txt

diff --git a/DDCore/include/JSON/ChildValue.h b/DDCore/include/JSON/ChildValue.h
new file mode 100644
index 000000000..794a6e89a
--- /dev/null
+++ b/DDCore/include/JSON/ChildValue.h
@@ -0,0 +1,33 @@
+//==========================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------------
+// 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.
+//
+// Author     : M.Frank
+//
+//==========================================================================
+#ifndef DD4HEP_JSON_CHILDVALUE_H
+#define DD4HEP_JSON_CHILDVALUE_H
+
+// Framework include files
+#include "JSON/Dimension.h"
+
+/// Namespace for the AIDA detector description toolkit
+namespace DD4hep {
+
+  // Forward declarations
+  class NamedObject;
+
+  /// Namespace for the AIDA detector description toolkit supporting JSON utilities
+  namespace JSON {
+
+    /// Include the implementation in the proper namespace
+#include "XML/detail/ChildValue.h"
+
+  }       /* End namespace JSON         */
+}         /* End namespace DD4hep       */
+#endif    /* DD4HEP_JSON_CHILDVALUE_H   */
diff --git a/DDCore/include/JSON/ChildValue.inl b/DDCore/include/JSON/ChildValue.inl
new file mode 100644
index 000000000..0b727b5de
--- /dev/null
+++ b/DDCore/include/JSON/ChildValue.inl
@@ -0,0 +1,24 @@
+//==========================================================================
+//  AIDA Detector description implementation for LCD
+//--------------------------------------------------------------------------
+// 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.
+//
+// Author     : M.Frank
+//
+//==========================================================================
+
+#ifndef DD4HEP_JSONCHILDVALUE_INL
+#define DD4HEP_JSONCHILDVALUE_INL
+
+// Configuration definitions
+#define CHILDVALUE_NS JSON
+
+// Framework include files
+#include "JSON/ChildValue.h"
+#include "XML/detail/ChildValue.inl"
+
+#endif /* DD4HEP_JSONCHILDVALUE_INL  */
diff --git a/DDCore/include/JSON/Dimension.h b/DDCore/include/JSON/Dimension.h
index c8e369618..2b8b06c6e 100644
--- a/DDCore/include/JSON/Dimension.h
+++ b/DDCore/include/JSON/Dimension.h
@@ -26,6 +26,6 @@ namespace DD4hep {
     /// Re-use the defined interface for the XML data access
 #include "XML/detail/Dimension.h"
 
-  }       /* End namespace JSON       */
-}         /* End namespace DD4hep     */
-#endif    /* DD4HEP_JSON_DIMENSION_H  */
+  }       /* End namespace JSON        */
+}         /* End namespace DD4hep      */
+#endif    /* DD4HEP_JSON_DIMENSION_H   */
diff --git a/DDCore/include/XML/detail/ChildValue.imp b/DDCore/include/XML/detail/ChildValue.imp
index 8d96518fd..d482a5880 100644
--- a/DDCore/include/XML/detail/ChildValue.imp
+++ b/DDCore/include/XML/detail/ChildValue.imp
@@ -11,6 +11,13 @@
 //
 //==========================================================================
 
+/** 
+ *  Note: Do NEVER include this file directly!
+ *
+ *  Use the specific include files in the XML or JSON directory!
+ *  Also NO header guards!
+ */
+
 XML_CHILDVALUE_ACCESSOR(int, id)
 XML_CHILDVALUE_ACCESSOR_INT(id)
 XML_CHILDVALUE_ACCESSOR(bool, combineHits)
diff --git a/DDCore/include/XML/detail/ChildValue.inl b/DDCore/include/XML/detail/ChildValue.inl
index 2c674ddbd..d7da2ac24 100644
--- a/DDCore/include/XML/detail/ChildValue.inl
+++ b/DDCore/include/XML/detail/ChildValue.inl
@@ -20,10 +20,11 @@
  */
 
 
-#define XML_CHILDVALUE_childValue(name,type)   m_element.child(Unicode_##name).attr<type>(_DD4hep_Unicode_Item(value))
+#define XML_CHILDVALUE_childValue(name,type)                            \
+  m_element.child(_DD4hep_Unicode_Item(name)).attr<type>(_DD4hep_Unicode_Item(value))
 
 #define XML_CHILDVALUE_childValueDefault(name,type,def)                 \
-  Handle_t __h = m_element.child(Unicode_##name,false);                 \
+  Handle_t __h = m_element.child(_DD4hep_Unicode_Item(name),false);     \
   if ( __h.ptr() && __h.hasAttr(_DD4hep_Unicode_Item(value)) ) return __h.attr < type > (_DD4hep_Unicode_Item(value)); \
   return def;
 
@@ -32,7 +33,7 @@
 
 #define XML_CHILDVALUE_ACCESSOR_DEFAULT(name,type,dressing)             \
   type ChildValue::name(type default_val) const {                       \
-    Handle_t __h = m_element.child(Unicode_##name,false);               \
+    Handle_t __h = m_element.child(_DD4hep_Unicode_Item(name),false);   \
     if ( __h.ptr() )  {                                                 \
       const XmlChar* val = __h.attr_value_nothrow(_DD4hep_Unicode_Item(value)); \
       return val ? dressing(val) : default_val; }                       \
diff --git a/DDCore/include/XML/detail/Detector.h b/DDCore/include/XML/detail/Detector.h
index a420dbd03..ccf4d9a69 100644
--- a/DDCore/include/XML/detail/Detector.h
+++ b/DDCore/include/XML/detail/Detector.h
@@ -10,19 +10,15 @@
 // Author     : M.Frank
 //
 //==========================================================================
-#ifndef DD4HEP_XML_DETAIL_DETECTOR_H
-#define DD4HEP_XML_DETAIL_DETECTOR_H
     
 /** 
  *  Note: Do NEVER include this file directly!
  *
+ *  Also NO header guards!
  *  Include XML/XMLDetector.h or JSON/Detector.h !
  */
 
-// Framework includes
-#include "XML/detail/Dimension.h"
-
-/// XML Handle class extending the XML handle Dimension
+/// Generic Handle class extending the generic handle Dimension
 /**
  *  Helper class to access any field in a xml tag.
  *  Specialized for attributes of a detector sub-element.
@@ -90,5 +86,3 @@ struct DetElement: public Dimension {
     return m_element.attr < T > (tag_value);
   }
 };
-
-#endif    /* DD4HEP_XML_DETAIL_DETECTOR_H    */
diff --git a/DDCore/include/XML/detail/Detector.imp b/DDCore/include/XML/detail/Detector.imp
index 8418b003c..524aba7fb 100644
--- a/DDCore/include/XML/detail/Detector.imp
+++ b/DDCore/include/XML/detail/Detector.imp
@@ -11,6 +11,15 @@
 //
 //==========================================================================
 
+
+/** 
+ *  Note: Do NEVER include this file directly!
+ *
+ *  Use the specific include files in the XML or JSON directory!
+ *  Also NO header guards!
+ */
+
+
 // Framework include files
 #include "DD4hep/Plugins.h"
 #include "DD4hep/LCDD.h"
diff --git a/DDCore/include/XML/detail/Dimension.h b/DDCore/include/XML/detail/Dimension.h
index d64042f73..09e524fdf 100644
--- a/DDCore/include/XML/detail/Dimension.h
+++ b/DDCore/include/XML/detail/Dimension.h
@@ -10,12 +10,11 @@
 // Author     : M.Frank
 //
 //==========================================================================
-#ifndef DD4HEP_XML_DETAIL_DIMENSION_H
-#define DD4HEP_XML_DETAIL_DIMENSION_H
 
 /** 
  *  Note: Do NEVER include this file directly!
  *
+ *  Also NO header guards!
  *  Include XML/XMLDimension.h or JSON/Dimension.h !
  */
 
@@ -564,5 +563,3 @@ struct Dimension: public Element {
   /// Access limits attribute as STL string. If not present empty return empty string
   std::string limitsStr() const;
 };
-
-#endif    /* DD4HEP_XML_DETAIL_DIMENSION_H   */
diff --git a/DDCore/include/XML/detail/Dimension.imp b/DDCore/include/XML/detail/Dimension.imp
index 9d7b7d705..ee263302a 100644
--- a/DDCore/include/XML/detail/Dimension.imp
+++ b/DDCore/include/XML/detail/Dimension.imp
@@ -11,7 +11,13 @@
 //
 //==========================================================================
 
-#include "XML/detail/Dimension.inl"
+
+/** 
+ *  Note: Do NEVER include this file directly!
+ *
+ *  Use the specific include files in the XML or JSON directory!
+ *  Also NO header guards!
+ */
 
 XML_ATTR_ACCESSOR(int, id)
 XML_ATTR_ACCESSOR_INT(id)
diff --git a/DDCore/include/XML/detail/Dimension.inl b/DDCore/include/XML/detail/Dimension.inl
index aeb2fc662..a41da30a5 100644
--- a/DDCore/include/XML/detail/Dimension.inl
+++ b/DDCore/include/XML/detail/Dimension.inl
@@ -11,12 +11,10 @@
 //
 //==========================================================================
 
-#ifndef DD4HEP_XML_DETAIL_DIMENSION_INL
-#define DD4HEP_XML_DETAIL_DIMENSION_INL
-
 /** 
  *  Note: Do NEVER include this file directly!
  *
+ *  Also NO header guards!
  *  Include XML/XMLDimension.h or JSON/Dimension.h !
  */
 
@@ -51,5 +49,3 @@
 #define XML_CHILD_ACCESSOR_XML_DIM(name)                        		\
     DD4hep::DIMENSION_NS::Dimension DD4hep::DIMENSION_NS::Dimension::name(bool throw_if_not_present) const {		\
     return m_element.child(_DD4hep_Unicode_Item(name),throw_if_not_present); }
-
-#endif /* DD4HEP_XML_DETAIL_DIMENSION_INL  */
diff --git a/DDCore/include/XML/detail/README.txt b/DDCore/include/XML/detail/README.txt
new file mode 100644
index 000000000..2aeecc4ec
--- /dev/null
+++ b/DDCore/include/XML/detail/README.txt
@@ -0,0 +1,23 @@
+
+XML/detail
+----------
+
+This directory is used to implement helpers to input parsers.
+These common implementation of the helpers should ensure that all
+dependent parsers offer a rather identical interface to users.
+
+The base interface is implemented in the Element header file,
+but all derived classes such as Dimension, Component or Detector
+have the identical interface and are supposed to ease the access
+to inditvidual attributes or child elements independent if the
+underlying implementation is based on:
+
+-- XercesC  --> uses the XML branch
+-- TinyXML  --> uses the XML branch
+-- JSON     --> Uses the JSON branch
+                with the implementation of boost::property_tree
+-- RapitXML --> Not implmented.
+                Would be a jiffy to implement using the JSON branch and
+                the implementation of boost::property_tree.
+                Only the document handling is different.
+
diff --git a/DDCore/src/JSON/Helpers.cpp b/DDCore/src/JSON/Helpers.cpp
index d6f197354..d8ae985d7 100644
--- a/DDCore/src/JSON/Helpers.cpp
+++ b/DDCore/src/JSON/Helpers.cpp
@@ -14,9 +14,11 @@
 // Framework include files
 #include "JSON/Detector.h"
 #include "JSON/Dimension.inl"
+#include "JSON/ChildValue.inl"
 
 using namespace DD4hep::JSON;
 
 // Instantiate here the concrete implementations
-#include "XML/detail/Dimension.imp"
 #include "XML/detail/Detector.imp"
+#include "XML/detail/Dimension.imp"
+#include "XML/detail/ChildValue.imp"
diff --git a/DDCore/src/XML/XMLHelpers.cpp b/DDCore/src/XML/XMLHelpers.cpp
index 387911b46..539005094 100644
--- a/DDCore/src/XML/XMLHelpers.cpp
+++ b/DDCore/src/XML/XMLHelpers.cpp
@@ -17,6 +17,8 @@
 #include "XML/XMLChildValue.inl"
 
 using namespace DD4hep::XML;
+
+// Instantiate here the concrete implementations
 #include "XML/detail/Detector.imp"
 #include "XML/detail/Dimension.imp"
 #include "XML/detail/ChildValue.imp"
-- 
GitLab