DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
XMLTags.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <XML/XMLElements.h>
16 #ifndef __TIXML__
17 #include <xercesc/util/XMLString.hpp>
18 #include <xercesc/util/PlatformUtils.hpp>
19 #endif
20 
21 // C/C++ include files
22 #include <stdexcept>
23 #include <iostream>
24 #include <map>
25 
26 
27 namespace {
28  struct __Init {
29  typedef std::map<std::string,dd4hep::xml::Tag_t*> Inventory_t;
30  Inventory_t m_inventory;
31  __Init() {
32 #ifndef __TIXML__
33  try {
35  }
36  catch (const xercesc::XMLException& e) {
37  std::string xml_err = xercesc::XMLString::transcode(e.getMessage());
38  std::string err = "xercesc::XMLPlatformUtils: Xerces-c error in initialization:"+xml_err;
39  std::cout << err << std::endl;
40  throw std::runtime_error(err);
41  }
42 #endif
43  }
44  ~__Init() {
45 #ifndef __TIXML__
46  xercesc::XMLPlatformUtils::Terminate();
47 #endif
48  }
49  static void register_tag(const std::string& name, dd4hep::xml::Tag_t* tag);
50  };
51  __Init __In__;
52  void __Init::register_tag(const std::string& name, dd4hep::xml::Tag_t* tag) {
53  Inventory_t::const_iterator i = __In__.m_inventory.find(name);
54  if ( i != __In__.m_inventory.end() ) {
55  std::string err = "XMLTags: Failed to register XML tag: "+name+". [Tag already exists]";
56  std::cout << err << std::endl;
57  throw std::runtime_error(err);
58  }
59  __In__.m_inventory[name] = tag;
60  }
61 }
62 
63 #define UNICODE(x) extern const Tag_t Unicode_##x (#x, #x, __Init::register_tag)
64 namespace dd4hep {
66 
68  namespace xml {
69 #include <XML/UnicodeValues.h>
70  }
71 }
72 
73 namespace dd4hep {
74  namespace xml {
75 
76  extern const Tag_t Unicode_NULL("NULL", "0", __Init::register_tag);
77  extern const Tag_t Unicode_empty("", "", __Init::register_tag);
78  extern const Tag_t Unicode_star("star", "*", __Init::register_tag);
79  extern const Tag_t Unicode_PI("PI", "3.14159265358979323846", __Init::register_tag);
80  extern const Tag_t Unicode_TWOPI("TWOPI", "6.28318530717958647692", __Init::register_tag);
81 
82  void tags_init() {
83  static __Init i;
84  }
85 
86  }
87 }
dd4hep::xml::Unicode_empty
const Tag_t Unicode_empty("", "", __Init::register_tag)
dd4hep::xml::Unicode_TWOPI
const Tag_t Unicode_TWOPI("TWOPI", "6.28318530717958647692", __Init::register_tag)
dd4hep::xml::tags_init
void tags_init()
Definition: XMLTags.cpp:82
UnicodeValues.h
dd4hep::xml::Unicode_NULL
const Tag_t Unicode_NULL("NULL", "0", __Init::register_tag)
dd4hep::xml::Tag_t
Class to support both way translation between C++ and XML strings.
Definition: XMLElements.h:254
dd4hep::xml::Unicode_star
const Tag_t Unicode_star("star", "*", __Init::register_tag)
dd4hep::xml
Namespace for the AIDA detector description toolkit supporting XML utilities.
Definition: ConditionsTags.h:27
dd4hep::xml::Unicode_PI
const Tag_t Unicode_PI("PI", "3.14159265358979323846", __Init::register_tag)
XMLElements.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
Initialize
v Initialize()