From 8a9c15e6cb3b370ecf9d5742b8b31121652abb5e Mon Sep 17 00:00:00 2001
From: Markus Frank <Markus.Frank@cern.ch>
Date: Fri, 31 Mar 2017 20:43:57 +0200
Subject: [PATCH] Fix bug in unicode tag macros

---
 DDAlign/src/AlignmentTags.cpp                    |  2 +-
 DDCond/include/DDCond/ConditionsTags.h           |  9 ++++++---
 DDCond/src/ConditionsTags.cpp                    |  4 +---
 DDCond/src/plugins/ConditionsParser.cpp          |  4 ++--
 .../src/plugins/ConditionsRepositoryParser.cpp   | 16 ++++++++--------
 .../src/plugins/ConditionsRepositoryWriter.cpp   |  2 +-
 DDDB/src/DDDBTags.cpp                            |  2 +-
 7 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/DDAlign/src/AlignmentTags.cpp b/DDAlign/src/AlignmentTags.cpp
index 23ade0de2..53f1f0bcc 100644
--- a/DDAlign/src/AlignmentTags.cpp
+++ b/DDAlign/src/AlignmentTags.cpp
@@ -16,6 +16,6 @@
 
 // Define unicode tags
 #ifndef UNICODE
-#define UNICODE(x)  extern const ::DD4hep::XML::Tag_t Unicode_##x
+#define UNICODE(x)  extern const ::DD4hep::XML::Tag_t Unicode_##x ( #x )
 #endif
 #include "DDAlign/AlignmentTags.h"
diff --git a/DDCond/include/DDCond/ConditionsTags.h b/DDCond/include/DDCond/ConditionsTags.h
index 704c856c9..ab2eaeadc 100644
--- a/DDCond/include/DDCond/ConditionsTags.h
+++ b/DDCond/include/DDCond/ConditionsTags.h
@@ -15,16 +15,20 @@
 
 // Framework include files
 #include "XML/XMLElements.h"
+
 #ifndef UNICODE 
 #define UNICODE(x)  extern const ::DD4hep::XML::Tag_t Unicode_##x 
 #endif
 
 /// Namespace for the AIDA detector description toolkit
 namespace DD4hep {
+
   /// Namespace for the AIDA detector description toolkit supporting XML utilities 
   namespace XML {
+    
     /// Namespace of conditions unicode tags
     namespace Conditions  {
+
       UNICODE(address);
       UNICODE(condition);
       UNICODE(conditions);
@@ -49,13 +53,12 @@ namespace DD4hep {
       UNICODE(repository);
     }
     // User must ensure there are no clashes. If yes, then the clashing entry is unnecessary.
-    using namespace ::DD4hep::XML::Conditions;
+    //using namespace ::DD4hep::XML::Conditions;
   }
 }
-
 #undef UNICODE // Do not miss this one!
-#include "XML/XMLTags.h"
 
+#include "XML/XMLTags.h"
 #define _UC(x) ::DD4hep::XML::Conditions::Unicode_##x
 
 #endif /* DD4HEP_CONDITIONS_CONDITIONSTAGS_H  */
diff --git a/DDCond/src/ConditionsTags.cpp b/DDCond/src/ConditionsTags.cpp
index 0056eff3d..9f52fc47c 100644
--- a/DDCond/src/ConditionsTags.cpp
+++ b/DDCond/src/ConditionsTags.cpp
@@ -15,7 +15,5 @@
 #include "XML/XMLTags.h"
 
 // Define unicode tags
-#ifndef UNICODE
-#define UNICODE(x)  extern const ::DD4hep::XML::Tag_t Unicode_##x
-#endif
+#define UNICODE(x)  const ::DD4hep::XML::Tag_t Unicode_##x ( #x )
 #include "DDCond/ConditionsTags.h"
diff --git a/DDCond/src/plugins/ConditionsParser.cpp b/DDCond/src/plugins/ConditionsParser.cpp
index 8f1bb82dd..a347e70e2 100644
--- a/DDCond/src/plugins/ConditionsParser.cpp
+++ b/DDCond/src/plugins/ConditionsParser.cpp
@@ -78,9 +78,9 @@ namespace DD4hep {
   string _getValidity(xml_h elt)  {
     if ( !elt.ptr() )
       return "Infinite";
-    else if ( !elt.hasAttr(_U(validity)) )
+    else if ( !elt.hasAttr(_UC(validity)) )
       return _getValidity(elt.parent());
-    return elt.attr<string>(_U(validity));
+    return elt.attr<string>(_UC(validity));
   }
 
   /// Helper: Extract the required detector element from the parsing information
diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp
index 8e0126197..9b710a812 100644
--- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp
+++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp
@@ -222,7 +222,7 @@ namespace DD4hep {
    */
   template <> void Converter<iov>::operator()(xml_h element) const {
     xml_dim_t e   = element;
-    string    val = e.attr<string>(_U(validity));
+    string    val = e.attr<string>(_UC(validity));
     ConversionArg* arg  = _param<ConversionArg>();
     CurrentPool pool(arg);
 
@@ -234,7 +234,7 @@ namespace DD4hep {
       Converter<conditions>(lcdd,param,optional)(doc.root());
       return;
     }
-    xml_coll_t(e,_U(detelement)).for_each(Converter<arbitrary>(lcdd,param,optional));
+    xml_coll_t(e,_UC(detelement)).for_each(Converter<arbitrary>(lcdd,param,optional));
   }
 
   /// Convert manager repository objects
@@ -249,7 +249,7 @@ namespace DD4hep {
       XML::DocumentHolder doc(XML::DocumentHandler().load(element, element.attr_value(_U(ref))));
       Converter<arbitrary>(lcdd,param,optional)(doc.root());
     }
-    for( xml_coll_t c(element,_U(property)); c; ++c)  {
+    for( xml_coll_t c(element,_UC(property)); c; ++c)  {
       xml_dim_t d = c;
       string nam = d.nameStr();
       string val = d.valueStr();
@@ -371,12 +371,12 @@ namespace DD4hep {
       (*this)(doc.root());
     }
     xml_coll_t(e,_U(value)).for_each(Converter<value>(lcdd,param,optional));
-    xml_coll_t(e,_U(mapping)).for_each(Converter<mapping>(lcdd,param,optional));
+    xml_coll_t(e,_UC(mapping)).for_each(Converter<mapping>(lcdd,param,optional));
     xml_coll_t(e,_U(sequence)).for_each(Converter<sequence>(lcdd,param,optional));
     xml_coll_t(e,_U(pressure)).for_each(Converter<pressure>(lcdd,param,optional));
     xml_coll_t(e,_U(alignment)).for_each(Converter<alignment>(lcdd,param,optional));
     xml_coll_t(e,_U(temperature)).for_each(Converter<temperature>(lcdd,param,optional));
-    xml_coll_t(e,_U(detelement)).for_each(Converter<detelement>(lcdd,param,optional));
+    xml_coll_t(e,_UC(detelement)).for_each(Converter<detelement>(lcdd,param,optional));
   }
 
   /// Convert repository objects
@@ -386,9 +386,9 @@ namespace DD4hep {
    *  \date    01/04/2014
    */
   template <> void Converter<repository>::operator()(xml_h element) const {
-    xml_coll_t(element,_U(manager)).for_each(Converter<manager>(lcdd,param,optional));
-    xml_coll_t(element,_U(iov_type)).for_each(Converter<iov_type>(lcdd,param,optional));
-    xml_coll_t(element,_U(iov)).for_each(Converter<iov>(lcdd,param,optional));
+    xml_coll_t(element,_UC(manager)).for_each(Converter<manager>(lcdd,param,optional));
+    xml_coll_t(element,_UC(iov_type)).for_each(Converter<iov_type>(lcdd,param,optional));
+    xml_coll_t(element,_UC(iov)).for_each(Converter<iov>(lcdd,param,optional));
   }
 
   /// Convert any top level tag in the XML file
diff --git a/DDCond/src/plugins/ConditionsRepositoryWriter.cpp b/DDCond/src/plugins/ConditionsRepositoryWriter.cpp
index 6cb994099..286a9756b 100644
--- a/DDCond/src/plugins/ConditionsRepositoryWriter.cpp
+++ b/DDCond/src/plugins/ConditionsRepositoryWriter.cpp
@@ -310,7 +310,7 @@ size_t ConditionsXMLRepositoryWriter::collect(XML::Element root,
       Container     cont = det.conditions();
       if ( cont.numKeys() > 0 )   {
         stringstream comment;
-        XML::Element conditions = XML::Element(root.document(),_U(detelement));
+        XML::Element conditions = XML::Element(root.document(),_UC(detelement));
         conditions.setAttr(_U(path),detector.path());
         printout(s_printLevel,"Writer","++ Conditions of DE %s [%d entries]",
                  detector.path().c_str(), int(cont.keys().size()));
diff --git a/DDDB/src/DDDBTags.cpp b/DDDB/src/DDDBTags.cpp
index 0519b7463..8a9546e0d 100644
--- a/DDDB/src/DDDBTags.cpp
+++ b/DDDB/src/DDDBTags.cpp
@@ -22,6 +22,6 @@
 
 // Define unicode tags
 #ifndef UNICODE
-#define UNICODE(x)  extern const ::DD4hep::XML::Tag_t Unicode_##x
+#define UNICODE(x)  extern const ::DD4hep::XML::Tag_t Unicode_##x ( #x )
 #endif
 #include "DDDB/DDDBTags.h"
-- 
GitLab