DD4hep  1.31.0
Detector Description Toolkit for High Energy Physics
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
XMLElements.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 #ifdef DD4HEP_USE_TINYXML
16 #include <XML/tinyxml.h>
17 #else
18 #include <xercesc/util/Xerces_autoconf_config.hpp>
19 #include <xercesc/util/XMLString.hpp>
20 #include <xercesc/dom/DOMElement.hpp>
21 #include <xercesc/dom/DOMDocument.hpp>
22 #include <xercesc/dom/DOMNodeList.hpp>
23 #include <xercesc/dom/DOM.hpp>
24 #include <XML/config.h>
25 #endif
26 
27 #include <XML/XMLElements.h>
28 #include <XML/Printout.h>
29 #include <XML/XMLTags.h>
30 
31 // C/C++ include files
32 #include <cstdio>
33 #include <iostream>
34 #include <map>
35 #include <stdexcept>
36 #include <string>
37 #include <utility>
38 #include <vector>
39 
40 using namespace dd4hep::xml;
41 static const size_t INVALID_NODE = ~0U;
42 static int s_float_precision = -1;
43 
44 // Forward declarations
45 namespace dd4hep {
46  std::pair<int, double> _toInteger(const std::string& value);
47  std::pair<int, double> _toFloatingPoint(const std::string& value);
48  void _toDictionary(const std::string& name, const std::string& value, const std::string& typ);
49  std::string _getEnviron(const std::string& env);
50 }
51 
52 // Static storage
53 namespace {
54  bool s_resolve_environment = true;
55  std::string _checkEnviron(const std::string& env) {
56  if ( s_resolve_environment ) {
57  std::string r = dd4hep::_getEnviron(env);
58  return r.empty() ? env : r;
59  }
60  return env;
61  }
62 }
63 
64 // Shortcuts
65 #define _D(x) Xml(x).d
66 #define _E(x) Xml(x).e
67 #define _N(x) Xml(x).n
68 #define _L(x) Xml(x).l
69 #define _XE(x) Xml(x).xe
70 
71 #ifdef DD4HEP_USE_TINYXML
72 #define ELEMENT_NODE_TYPE TiXmlNode::ELEMENT
73 #define getTagName Value
74 #define getTextContent GetText
75 #define getName Name
76 #define getValue Value
77 #define getNodeValue Value
78 #define getNodeType Type
79 #define setNodeValue SetValue
80 #define getParentNode Parent()->ToElement
81 #define getAttributeNode(x) AttributeNode(x)
82 #define appendChild LinkEndChild
83 #define getOwnerDocument GetDocument
84 #define getDocumentElement RootElement
85 #define getDocumentURI Value
86 
88 union Xml {
89  Xml(const void* ptr) : p(ptr) {}
90  const void* p;
91  TiXmlNode* n;
92  TiXmlElement* e;
93  TiXmlAttribute* a;
94  TiXmlDocument* d;
95  XmlElement* xe;
96 };
97 
98 namespace {
99  XmlElement* node_first(XmlElement* e, const Tag_t& t) {
100  if ( t.str()=="*" ) return e ? (XmlElement*)_E(e)->FirstChildElement() : 0;
101  return e ? (XmlElement*)_E(e)->FirstChildElement(t.str()) : 0;
102  }
103  size_t node_count(XmlElement* elt, const Tag_t& t) {
104  size_t cnt = 0;
105  TiXmlElement* e = Xml(elt).e;
106  if ( t.str()=="*" )
107  for(e=e->FirstChildElement();e; e=e->NextSiblingElement()) ++cnt;
108  else
109  for(e=e->FirstChildElement(t.str());e; e=e->NextSiblingElement(t.str())) ++cnt;
110  return cnt;
111  }
112 }
114  return c ? ::strdup(c) : 0;
115 }
116 XmlChar* dd4hep::xml::XmlString::transcode(const char* c) {return c ? ::strdup(c) : 0;
117 }
118 void dd4hep::xml::XmlString::release(char** p) {
119  if(p && *p) {::free(*p); *p=0;}
120 }
121 size_t dd4hep::xml::XmlString::length(const char* p) {
122  return p ? ::strlen(p) : 0;
123 }
124 
125 #else
126 #define ELEMENT_NODE_TYPE xercesc::DOMNode::ELEMENT_NODE
127 
129 union Xml {
130  Xml(const void* ptr)
131  : p(ptr) {
132  }
133  const void* p;
134  xercesc::DOMNode* n;
135  xercesc::DOMAttr* a;
136  xercesc::DOMElement* e;
137  xercesc::DOMDocument* d;
138  xercesc::DOMNodeList* l;
139  XmlElement* xe;
140 };
141 
143  return xercesc::XMLString::replicate(c);
144 }
146  return xercesc::XMLString::transcode(c);
147 }
149  return xercesc::XMLString::transcode(c);
150 }
152  return xercesc::XMLString::release(p);
153 }
155  return xercesc::XMLString::release(p);
156 }
157 size_t dd4hep::xml::XmlString::length(const char* p) {
158  return p ? xercesc::XMLString::stringLen(p) : 0;
159 }
161  return p ? xercesc::XMLString::stringLen(p) : 0;
162 }
163 
164 namespace {
165  size_t node_count(XmlElement* e, const Tag_t& t) {
166  size_t cnt = 0;
167  if ( e ) {
168  const std::string& tag = t;
169  xercesc::DOMElement *ee = Xml(e).e;
170  if ( ee ) {
171  for(xercesc::DOMElement* elt=ee->getFirstElementChild(); elt; elt=elt->getNextElementSibling()) {
172  if ( elt->getParentNode() == ee ) {
173  std::string child_tag = _toString(elt->getTagName());
174  if ( tag == "*" || child_tag == tag ) ++cnt;
175  }
176  }
177  }
178  }
179  return cnt;
180  }
181  XmlElement* node_first(XmlElement* e, const Tag_t& t) {
182  if ( e ) {
183  const std::string& tag = t;
184  xercesc::DOMElement* ee = Xml(e).e;
185  if ( ee ) {
186  for(xercesc::DOMElement* elt=ee->getFirstElementChild(); elt; elt=elt->getNextElementSibling()) {
187  if ( elt->getParentNode() == ee ) {
188  if ( tag == "*" ) return _XE(elt);
189  std::string child_tag = _toString(elt->getTagName());
190  if ( child_tag == tag ) return _XE(elt);
191  }
192  }
193  }
194  }
195  return 0;
196  }
197 }
198 
200 std::string dd4hep::xml::_toString(const XmlChar *toTranscode) {
201  char *buff = XmlString::transcode(toTranscode);
202  std::string tmp(buff == 0 ? "" : buff);
203  XmlString::release(&buff);
204  if ( tmp.length()<3 ) return tmp;
205  if ( !(tmp[0] == '$' && tmp[1] == '{') ) return tmp;
206  tmp = _checkEnviron(tmp);
207  return tmp;
208 }
209 #endif
210 
211 namespace {
212  Attribute attribute_node(XmlElement* n, const XmlChar* t) {
213  return Attribute(_E(n)->getAttributeNode(t));
214  }
215  const XmlChar* attribute_value(Attribute a) {
216  return Xml(a).a->getValue();
217  }
218 #if 0
219  int node_type(XmlNode* n) {return Xml(n).n->getNodeType();}
220  int node_type(Handle_t n) {return Xml(n.ptr()).n->getNodeType();}
221 #endif
222 }
223 
226  int tmp = s_float_precision;
227  s_float_precision = precision;
228  return tmp;
229 }
230 
233  return s_float_precision;
234 }
235 
238  if (attr)
239  return _toString(attribute_value(attr));
240  return "";
241 }
242 
243 template <typename T> static inline std::string __to_string(T value, const char* fmt) {
244  char text[128];
245  ::snprintf(text, sizeof(text), fmt, value);
246  return text;
247 }
248 
250 std::string dd4hep::xml::_toString(const char* s) {
251  if ( !s || *s == 0 ) return "";
252  else if ( !(*s == '$' && *(s+1) == '{') ) return s;
253  return _checkEnviron(s);
254 }
255 
257 std::string dd4hep::xml::_toString(const std::string& s) {
258  if ( s.length() < 3 || s[0] != '$' ) return s;
259  else if ( !(s[0] == '$' && s[1] == '{') ) return s;
260  return _checkEnviron(s);
261 }
262 
264 std::string dd4hep::xml::_toString(unsigned long v, const char* fmt) {
265  return __to_string(v, fmt);
266 }
267 
269 std::string dd4hep::xml::_toString(unsigned int v, const char* fmt) {
270  return __to_string(v, fmt);
271 }
272 
274 std::string dd4hep::xml::_toString(int v, const char* fmt) {
275  return __to_string(v, fmt);
276 }
277 
279 std::string dd4hep::xml::_toString(long v, const char* fmt) {
280  return __to_string(v, fmt);
281 }
282 
284 std::string dd4hep::xml::_toString(float v, const char* fmt) {
285  if ( s_float_precision >= 0 ) {
286  char format[32];
287  ::snprintf(format, sizeof(format), "%%.%de", s_float_precision);
288  return __to_string(v, format);
289  }
290  return __to_string(v, fmt);
291 }
292 
294 std::string dd4hep::xml::_toString(double v, const char* fmt) {
295  if ( s_float_precision >= 0 ) {
296  char format[32];
297  ::snprintf(format, sizeof(format), "%%.%de", s_float_precision);
298  return __to_string(v, format);
299  }
300  return __to_string(v, fmt);
301 }
302 
304 std::string dd4hep::xml::_toString(const Strng_t& s) {
305  return _toString(Tag_t(s));
306 }
307 
309 std::string dd4hep::xml::_toString(const Tag_t& s) {
310  return s.str();
311 }
312 
314 std::string dd4hep::xml::_ptrToString(const void* v, const char* fmt) {
315  return __to_string(v, fmt);
316 }
317 
318 long dd4hep::xml::_toLong(const XmlChar* value) {
319  if (value) {
320  std::string s = _toString(value);
321  return dd4hep::_toInteger(s).second;
322  }
323  return -1;
324 }
325 
326 unsigned long dd4hep::xml::_toULong(const XmlChar* value) {
327  long val = _toLong(value);
328  if ( val >= 0 ) return (unsigned long) val;
329  std::string s = _toString(value);
330  throw std::runtime_error("dd4hep: Severe error during expression evaluation of " + s);
331 }
332 
333 int dd4hep::xml::_toInt(const XmlChar* value) {
334  return (int)_toLong(value);
335 }
336 
337 unsigned int dd4hep::xml::_toUInt(const XmlChar* value) {
338  return (unsigned int)_toULong(value);
339 }
340 
341 bool dd4hep::xml::_toBool(const XmlChar* value) {
342  if (value) {
343  std::string s = _toString(value);
344  char c = ::toupper(s[0]);
345  if ( c == 'T' || c == '1' ) return true;
346  if ( c == 'F' || c == '0' ) return false;
347  return _toInt(value) != 0;
348  }
349  return false;
350 }
351 
352 float dd4hep::xml::_toFloat(const XmlChar* value) {
353  if (value) {
354  std::string s = _toString(value);
355  return (float) dd4hep::_toFloatingPoint(s).second;
356  }
357  return 0.0;
358 }
359 
360 double dd4hep::xml::_toDouble(const XmlChar* value) {
361  if (value) {
362  std::string s = _toString(value);
363  return dd4hep::_toFloatingPoint(s).second;
364  }
365  return 0.0;
366 }
367 
368 void dd4hep::xml::_toDictionary(const XmlChar* name, const XmlChar* value) {
369  std::string n = _toString(name).c_str(), v = _toString(value);
370  dd4hep::_toDictionary(n, v, "number");
371 }
372 
374 void dd4hep::xml::_toDictionary(const XmlChar* name, const Strng_t& s) {
375  return _toDictionary(name, s.ptr());
376 }
377 
379 void dd4hep::xml::_toDictionary(const XmlChar* name, const Tag_t& t) {
380  return _toDictionary(name, t.ptr());
381 }
382 
383 template <typename T>
384 void dd4hep::xml::_toDictionary(const XmlChar* name, T value) {
385  Strng_t item = _toString(value);
386  const XmlChar* item_value = item;
387  _toDictionary(name, item_value);
388 }
389 
390 #ifndef DD4HEP_USE_TINYXML
391 template void dd4hep::xml::_toDictionary(const XmlChar* name, const char* value);
392 #endif
393 template void dd4hep::xml::_toDictionary(const XmlChar* name, const Tag_t& value);
394 template void dd4hep::xml::_toDictionary(const XmlChar* name, const Strng_t& value);
395 template void dd4hep::xml::_toDictionary(const XmlChar* name, const std::string& value);
396 template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned long value);
397 template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned int value);
398 template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned short value);
399 template void dd4hep::xml::_toDictionary(const XmlChar* name, int value);
400 template void dd4hep::xml::_toDictionary(const XmlChar* name, long value);
401 template void dd4hep::xml::_toDictionary(const XmlChar* name, short value);
402 template void dd4hep::xml::_toDictionary(const XmlChar* name, float value);
403 template void dd4hep::xml::_toDictionary(const XmlChar* name, double value);
404 
406 std::string dd4hep::xml::getEnviron(const std::string& env) {
407  return dd4hep::_getEnviron(env);
408 }
409 
412  bool tmp = s_resolve_environment;
413  s_resolve_environment = new_value;
414  return tmp;
415 }
416 
417 template <typename B>
418 static inline std::string i_add(const std::string& a, B b) {
419  std::string r = a;
420  r += b;
421  return r;
422 }
423 
424 Strng_t dd4hep::xml::operator+(const Strng_t& a, const std::string& b) {
425  return _toString(a.ptr()) + b;
426 }
427 
428 Strng_t dd4hep::xml::operator+(const std::string& a, const Strng_t& b) {
429  return a + _toString(b.ptr());
430 }
431 
432 Strng_t dd4hep::xml::operator+(const Strng_t& a, const char* b) {
433  return _toString(a.ptr()) + b;
434 }
435 
436 Strng_t dd4hep::xml::operator+(const char* a, const Strng_t& b) {
437  return std::string(a) + _toString(b.ptr());
438 }
439 
441  return _toString(a.ptr()) + _toString(b.ptr());
442 }
443 
444 Tag_t dd4hep::xml::operator+(const Tag_t& a, const char* b) {
445  std::string res = a.str() + b;
446  return Tag_t(res);
447 }
448 
449 Tag_t dd4hep::xml::operator+(const char* a, const Tag_t& b) {
450  std::string res = a + b.str();
451  return Tag_t(res);
452 }
453 
455  std::string res = a.str() + _toString(b);
456  return Tag_t(res);
457 }
458 
459 Tag_t dd4hep::xml::operator+(const Tag_t& a, const std::string& b) {
460  std::string res = a.str() + b;
461  return Tag_t(res);
462 }
463 
464 #ifndef DD4HEP_USE_TINYXML
466  std::string res = _toString(a.ptr()) + _toString(b);
467  return Tag_t(res);
468 }
469 
471  std::string res = _toString(a) + _toString(b.ptr());
472  return Tag_t(res);
473 }
474 
475 Strng_t dd4hep::xml::operator+(const XmlChar* a, const std::string& b) {
476  std::string res = _toString(a) + b;
477  return Tag_t(res);
478 }
479 
480 Strng_t dd4hep::xml::operator+(const std::string& a, const XmlChar* b) {
481  std::string res = a + _toString(b);
482  return Tag_t(res);
483 }
484 
486  std::string res = a.str() + _toString(b);
487  return Tag_t(res);
488 }
489 
491  if (m_xml)
493  m_xml = s ? XmlString::replicate(s) : 0;
494  return *this;
495 }
496 #endif
497 
498 Strng_t& Strng_t::operator=(const char* s) {
499  if (m_xml)
501  m_xml = s ? XmlString::transcode(s) : 0;
502  return *this;
503 }
504 
506  if (this != &s) {
507  if (m_xml)
510  }
511  return *this;
512 }
513 
514 Strng_t& Strng_t::operator=(const std::string& s) {
515  if (m_xml)
517  m_xml = XmlString::transcode(s.c_str());
518  return *this;
519 }
520 
522  if (this != &s) {
523  m_str = s.m_str;
524  if (m_xml)
526  m_xml = XmlString::transcode(m_str.c_str());
527  }
528  return *this;
529 }
530 
531 Tag_t& Tag_t::operator=(const char* s) {
532  if (m_xml)
534  if (s) {
536  m_str = s;
537  }
538  else {
539  m_xml = 0;
540  m_str = "";
541  }
542  return *this;
543 }
544 
546  if (m_xml) {
548  }
549  char* ns = s.m_xml ? XmlString::transcode(s.m_xml) : 0;
550  m_str = ns ? ns : "";
551  m_xml = XmlString::transcode(m_str.c_str());
552  if (ns) {
554  }
555  return *this;
556 }
557 
558 Tag_t& Tag_t::operator=(const std::string& s) {
559  if (m_xml)
561  m_xml = XmlString::transcode(s.c_str());
562  m_str = s;
563  return *this;
564 }
565 
568  : m_tag(copy.m_tag), m_node(copy.m_node), m_ptr(0)
569 {
570  reset();
571 }
572 
574 NodeList::NodeList(XmlElement* node, const XmlChar* tag_value)
575  : m_tag(tag_value), m_node(node), m_ptr(0)
576 {
577  reset();
578 }
579 
582 }
583 
585 XmlElement* NodeList::reset() {
586  return m_ptr=node_first(m_node,m_tag);
587 }
588 
590 XmlElement* NodeList::next() const {
591 #ifdef DD4HEP_USE_TINYXML
592  if ( m_tag.str()=="*" )
593  return m_ptr =_XE(m_ptr ? _E(m_ptr)->NextSiblingElement() : 0);
594  return m_ptr = _XE(m_ptr ? _E(m_ptr)->NextSiblingElement(m_tag.str()) : 0);
595 #else
596  xercesc::DOMElement *elt = Xml(m_ptr).e;
597  for(elt=elt->getNextElementSibling(); elt; elt=elt->getNextElementSibling()) {
598  if ( m_tag.str() == "*" ) return m_ptr=Xml(elt).xe;
599  std::string child_tag = _toString(elt->getTagName());
600  if ( child_tag == m_tag ) return m_ptr=Xml(elt).xe;
601  }
602  return m_ptr=0;
603 #endif
604 }
605 
607 XmlElement* NodeList::previous() const {
608 #ifdef DD4HEP_USE_TINYXML
609  if ( m_tag.str()=="*" )
610  return m_ptr = _XE(m_ptr ? _E(m_ptr)->PreviousSiblingElement() : 0);
611  return m_ptr = _XE(m_ptr ? _E(m_ptr)->PreviousSiblingElement(m_tag) : 0);
612 #else
613  xercesc::DOMElement *elt = Xml(m_ptr).e;
614  for(elt=elt->getPreviousElementSibling(); elt; elt=elt->getPreviousElementSibling()) {
615  if ( m_tag.str()=="*" ) return m_ptr=Xml(elt).xe;
616  std::string child_tag = _toString(elt->getTagName());
617  if ( child_tag == m_tag ) return m_ptr=Xml(elt).xe;
618  }
619  return m_ptr=0;
620 #endif
621 }
622 
625  if (this != &l) {
626  m_tag = l.m_tag;
627  m_node = l.m_node;
628  reset();
629  }
630  return *this;
631 }
632 
634 const XmlChar* Handle_t::rawTag() const {
635  return _E(m_node)->getTagName();
636 }
637 
639 const XmlChar* Handle_t::rawText() const {
640  return _E(m_node)->getTextContent();
641 }
642 
644 const XmlChar* Handle_t::rawValue() const {
645  return _N(m_node)->getNodeValue();
646 }
647 
649 Handle_t Handle_t::clone(XmlDocument* new_doc) const {
650  if (m_node) {
651 #ifdef DD4HEP_USE_TINYXML
652  if ( new_doc ) {}
653  if ( _N(m_node)->Type() == ELEMENT_NODE_TYPE ) {
654  XmlElement* e = _XE(_N(m_node)->Clone()->ToElement());
655  if ( e ) return e;
656  }
657  throw std::runtime_error("TiXml: Handle_t::clone: Invalid source handle type [No element type].");
658 #else
659  return Elt_t(_D(new_doc)->importNode(_E(m_node), true));
660 #endif
661  }
662  throw std::runtime_error("Xml: Handle_t::clone: Invalid source handle.");
663 }
664 
667  return Elt_t(m_node ? _N(m_node)->getParentNode() : 0);
668 }
669 
671 Attribute Handle_t::attr_nothrow(const XmlChar* tag_value) const {
672  return attribute_node(m_node, tag_value);
673 }
674 
676 bool Handle_t::hasAttr(const XmlChar* tag_value) const {
677  return m_node && 0 != _E(m_node)->getAttributeNode(tag_value);
678 }
679 
681 std::vector<Attribute> Handle_t::attributes() const {
682  std::vector < Attribute > attrs;
683  if (m_node) {
684 #ifdef DD4HEP_USE_TINYXML
685  for(TiXmlAttribute* a=_E(m_node)->FirstAttribute(); a; a=a->Next())
686  attrs.emplace_back(Attribute(a));
687 #else
688  xercesc::DOMNamedNodeMap* l = _E(m_node)->getAttributes();
689  for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i) {
690  xercesc::DOMNode* attr_node = l->item(i);
691  attrs.emplace_back(Attribute(attr_node));
692  }
693 #endif
694  }
695  return attrs;
696 }
697 
698 size_t Handle_t::numChildren(const XmlChar* t, bool throw_exception) const {
699  size_t n = node_count(m_node, t);
700  if (n == INVALID_NODE && !throw_exception)
701  return 0;
702  else if (n != INVALID_NODE)
703  return n;
704  std::string msg = "Handle_t::numChildren: ";
705  if (m_node)
706  msg += "Element [" + tag() + "] has no children of type '" + _toString(t) + "'";
707  else
708  msg += "Element [INVALID] has no children of type '" + _toString(t) + "'";
709  throw std::runtime_error(msg);
710 }
711 
713 Handle_t Handle_t::child(const XmlChar* t, bool throw_exception) const {
714  Elt_t e = node_first(m_node, t);
715  if (e || !throw_exception)
716  return e;
717  std::string msg = "Handle_t::child: ";
718  if (m_node)
719  msg += "Element [" + tag() + "] has no child of type '" + _toString(t) + "'";
720  else
721  msg += "Element [INVALID]. Cannot remove child of type: '" + _toString(t) + "'";
722  throw std::runtime_error(msg);
723 }
724 
725 NodeList Handle_t::children(const XmlChar* tag_value) const {
726  return NodeList(m_node, tag_value);
727 }
728 
730 void Handle_t::append(Handle_t e) const {
731  _N(m_node)->appendChild(_N(e.ptr()));
732 }
733 
736 #ifdef DD4HEP_USE_TINYXML
737  bool e = (m_node && node.ptr() ? _N(m_node)->RemoveChild(_N(node.ptr())) : false);
738 #else
739  Elt_t e = Elt_t(m_node && node.ptr() ? _N(m_node)->removeChild(_N(node.ptr())) : 0);
740 #endif
741  if (e)
742  return node.ptr();
743  std::string msg = "Handle_t::remove: ";
744  if (m_node && node.ptr())
745  msg += "Element [" + tag() + "] has no child of type '" + node.tag() + "'";
746  else if (node)
747  msg += "Element [INVALID]. Cannot remove child of type: '" + node.tag() + "'";
748  else if (!node)
749  msg += "Element [INVALID]. Cannot remove [INVALID] child. Big Shit!!!!";
750 
751  throw std::runtime_error(msg);
752 }
753 
755 void Handle_t::removeChildren(const XmlChar* tag_value) const {
756 #ifdef DD4HEP_USE_TINYXML
757  for(TiXmlNode* n=_E(m_node)->FirstChildElement(tag_value);n;n=_E(m_node)->FirstChildElement(tag_value))
758  n->RemoveChild(n);
759 #else
760  xercesc::DOMElement* e = _E(m_node);
761  xercesc::DOMNodeList* l = e->getElementsByTagName(tag_value);
762  for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i)
763  e->removeChild(l->item(i));
764 #endif
765 }
766 
767 bool Handle_t::hasChild(const XmlChar* tag_value) const {
768  return node_first(m_node, tag_value) != 0;
769 }
770 
772 void Handle_t::setValue(const XmlChar* text_value) const {
773  _N(m_node)->setNodeValue(text_value);
774 }
775 
777 void Handle_t::setValue(const std::string& text_value) const {
778 #ifdef DD4HEP_USE_TINYXML
779  _N(m_node)->setNodeValue(text_value.c_str());
780 #else
781  _N(m_node)->setNodeValue(Strng_t(text_value));
782 #endif
783 }
784 
786 void Handle_t::setText(const XmlChar* text_value) const {
787 #ifdef DD4HEP_USE_TINYXML
788  _N(m_node)->LinkEndChild(new TiXmlText(text_value));
789 #else
790  _N(m_node)->setTextContent(text_value);
791 #endif
792 }
793 
795 void Handle_t::setText(const std::string& text_value) const {
796 #ifdef DD4HEP_USE_TINYXML
797  _N(m_node)->LinkEndChild(new TiXmlText(text_value.c_str()));
798 #else
799  _N(m_node)->setTextContent(Strng_t(text_value));
800 #endif
801 }
802 
804 void Handle_t::removeAttrs() const {
805 #ifdef DD4HEP_USE_TINYXML
806  _E(m_node)->ClearAttributes();
807 #else
808  xercesc::DOMElement* e = _E(m_node);
809  xercesc::DOMNamedNodeMap* l = e->getAttributes();
810  for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i) {
811  xercesc::DOMAttr* a = (xercesc::DOMAttr*) l->item(i);
812  e->removeAttributeNode(a);
813  }
814 #endif
815 }
816 
818 #ifdef DD4HEP_USE_TINYXML
819 void Handle_t::setAttrs(Handle_t elt) const {
820  removeAttrs();
821  TiXmlElement* e = Xml(elt).e;
822  for(TiXmlAttribute* a=e->FirstAttribute(); a; a=a->Next())
823  e->SetAttribute(a->Name(),a->Value());
824 }
825 #else
826 void Handle_t::setAttrs(Handle_t /* elt */) const {
827  removeAttrs();
828  xercesc::DOMElement* e = _E(m_node);
829  xercesc::DOMNamedNodeMap* l = e->getAttributes();
830  for (XmlSize_t i = 0, len = l->getLength(); i < len; ++i) {
831  xercesc::DOMNode* n = l->item(i);
832  if (n->getNodeType() == xercesc::DOMNode::ATTRIBUTE_NODE) {
833  xercesc::DOMAttr* a = (xercesc::DOMAttr*) n;
834  e->setAttribute(a->getName(), a->getValue());
835  }
836  }
837 }
838 #endif
839 
842  Attribute a = attribute_node(m_node, t);
843  if (0 != a)
844  return a;
845  std::string msg = "Handle_t::attr_ptr: ";
846  if (m_node)
847  msg += "Element [" + tag() + "] has no attribute of type '" + _toString(t) + "'";
848  else
849  msg += "Element [INVALID] has no attribute of type '" + _toString(t) + "'";
850  throw std::runtime_error(msg);
851 }
852 
854 const XmlChar* Handle_t::attr_name(const Attribute a) const {
855  if (a) {
856  return Xml(a).a->getName();
857  }
858  throw std::runtime_error("Attempt to access invalid XML attribute object!");
859 }
860 
862 const XmlChar* Handle_t::attr_value(const XmlChar* attr_tag) const {
863  return attribute_value(attr_ptr(attr_tag));
864 }
865 
867 const XmlChar* Handle_t::attr_value(const Attribute attr_val) const {
868  return attribute_value(attr_val);
869 }
870 
872 const XmlChar* Handle_t::attr_value_nothrow(const XmlChar* attr_tag) const {
873  Attribute a = attr_nothrow(attr_tag);
874  return a ? attribute_value(a) : 0;
875 }
876 
878 Attribute Handle_t::setAttr(const XmlChar* nam, int val) const {
879  char txt[32];
880  ::snprintf(txt, sizeof(txt), "%d", val);
881  return setAttr(nam, Strng_t(txt));
882 }
883 
885 Attribute Handle_t::setAttr(const XmlChar* name, bool val) const {
886  char txt[32];
887  ::snprintf(txt, sizeof(txt), "%s", val ? "true" : "false");
888  return setAttr(name, Strng_t(txt));
889 }
890 
892 Attribute Handle_t::setAttr(const XmlChar* name, float val) const {
893  char txt[32];
894  ::snprintf(txt, sizeof(txt), "%.8e", val);
895  return setAttr(name, Strng_t(txt));
896 }
897 
899 Attribute Handle_t::setAttr(const XmlChar* name, double val) const {
900  char txt[32];
901  ::snprintf(txt, sizeof(txt), "%.8e", val);
902  return setAttr(name, Strng_t(txt));
903 }
904 
906 Attribute Handle_t::setAttr(const XmlChar* name, const std::string& val) const {
907  return setAttr(name, Strng_t(val.c_str()));
908 }
909 
910 #ifndef DD4HEP_USE_TINYXML
911 Attribute Handle_t::setAttr(const XmlChar* name, const char* v) const {
912  return setAttr(name, Strng_t(v));
913 }
914 #endif
915 
917 Attribute Handle_t::setAttr(const XmlChar* nam, const Attribute v) const {
918  return v ? setAttr(nam, attribute_value(v)) : 0;
919 }
920 
922 Attribute Handle_t::setAttr(const XmlChar* nam, const XmlChar* val) const {
923 #ifdef DD4HEP_USE_TINYXML
924  TiXmlElement* e = Xml(m_node).e;
925  e->SetAttribute(nam,val);
926  return Attribute(e->AttributeNode(nam));
927 #else
928  xercesc::DOMElement* e = _E(m_node);
929  xercesc::DOMAttr* a = e->getAttributeNode(nam);
930  if (!a) {
931  a = e->getOwnerDocument()->createAttribute(nam);
932  e->setAttributeNode(a);
933  }
934  a->setValue(val);
935  return Attribute(a);
936 #endif
937 }
938 
940 Handle_t Handle_t::setRef(const XmlChar* tag_value, const XmlChar* ref_name) {
941  Element me(*this);
942  Element ref(me.document(), tag_value);
943  ref.setAttr(Unicode_ref, ref_name);
944  me.append(ref);
945  return ref;
946 }
947 
949 Handle_t Handle_t::setRef(const XmlChar* tag_value, const std::string& ref_name) {
950  return setRef(tag_value, Strng_t(ref_name).ptr());
951 }
952 
954 static unsigned int adler32(unsigned int adler, const XmlChar* xml_buff, size_t len) {
955 #define DO1(buf,i) {s1 +=(unsigned char)buf[i]; s2 += s1;}
956 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
957 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
958 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
959 #define DO16(buf) DO8(buf,0); DO8(buf,8);
960 
961  static const unsigned int BASE = 65521; /* largest prime smaller than 65536 */
962  /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
963  static const unsigned int NMAX = 5550;
964  unsigned int s1 = adler & 0xffff;
965  unsigned int s2 = (adler >> 16) & 0xffff;
966  const char* buf = (const char*)xml_buff;
967 
968  if (buf == NULL)
969  return 1;
970 
971  while (len > 0) {
972  int k = len < NMAX ? (int) len : NMAX;
973  len -= k;
974  while (k >= 16) {
975  DO16(buf);
976  buf += 16;
977  k -= 16;
978  }
979  if (k != 0)
980  do {
981  s1 += (unsigned char) *buf++;
982  s2 += s1;
983  } while (--k);
984  s1 %= BASE;
985  s2 %= BASE;
986  }
987  unsigned int result = (s2 << 16) | s1;
988  return result;
989 }
990 
992 typedef unsigned int (fcn_t)(unsigned int, const XmlChar*, size_t);
993 unsigned int Handle_t::checksum(unsigned int param, fcn_t fcn) const {
994 #ifdef DD4HEP_USE_TINYXML
995  typedef std::map<std::string, std::string> StringMap;
996  TiXmlNode* n = Xml(m_node).n;
997  if ( n ) {
998  if ( 0 == fcn ) fcn = adler32;
999  switch (n->Type()) {
1000  case TiXmlNode::ELEMENT: {
1001  std::map<std::string,std::string> m;
1002  TiXmlElement* e = n->ToElement();
1004  for(; p; p=p->Next()) m.emplace(p->Name(),p->Value());
1005  param = (*fcn)(param,e->Value(),::strlen(e->Value()));
1006  for(StringMap::const_iterator i=m.begin();i!=m.end();++i) {
1007  param = (*fcn)(param,(*i).first.c_str(),(*i).first.length());
1008  param = (*fcn)(param,(*i).second.c_str(),(*i).second.length());
1009  }
1010  break;
1011  }
1012  case TiXmlNode::TEXT:
1013  param = (*fcn)(param,n->ToText()->Value(),::strlen(n->ToText()->Value()));
1014  break;
1015  case TiXmlNode::UNKNOWN:
1016  case TiXmlNode::COMMENT:
1017  case TiXmlNode::DOCUMENT:
1019  default:
1020  break;
1021  }
1022  for(TiXmlNode* c=n->FirstChild(); c; c=c->NextSibling())
1023  param = Handle_t((XmlElement*)c->ToElement()).checksum(param,fcn);
1024  }
1025 #else
1026  if ( 0 == fcn ) fcn = adler32;
1027  if ( 0 == fcn ) {
1028  }
1029 #endif
1030  return param;
1031 }
1032 
1034 Handle_t Document::createElt(const XmlChar* tag_value) const {
1035 #ifdef DD4HEP_USE_TINYXML
1036  return _XE(new TiXmlElement(tag_value));
1037 #else
1038  return _XE(_D(m_doc)->createElement(tag_value));
1039 #endif
1040 }
1041 
1044  if (m_doc)
1045  return _XE(_D(m_doc)->getDocumentElement());
1046  throw std::runtime_error("Document::root: Invalid handle!");
1047 }
1048 
1050 std::string Document::uri() const {
1051  if (m_doc) {
1052  Tag_t val(_D(m_doc)->getDocumentURI());
1053  return val;
1054  }
1055  throw std::runtime_error("Document::uri: Invalid handle!");
1056 }
1057 
1060  if (m_doc) {
1061  printout(DEBUG,"DocumentHolder","+++ Release DOM document....");
1062 #ifdef DD4HEP_USE_TINYXML
1063  delete _D(m_doc);
1064 #else
1065  _D(m_doc)->release();
1066 #endif
1067  }
1068  m_doc = d;
1069  return *this;
1070 }
1071 
1074  assign(0);
1075 }
1076 
1078 Element::Element(const Document& doc, const XmlChar* type)
1079  : m_element(Xml(doc.createElt(type)).xe) {
1080 }
1081 
1084  Handle_t p = m_element.parent();
1085  if ( p && _N(p.ptr())->getNodeType() == ELEMENT_NODE_TYPE ) {
1086  return Elt_t(p);
1087  }
1088  return Elt_t(0);
1089 }
1090 
1093  return Document((XmlDocument*) (m_element ? _N(m_element)->getOwnerDocument() : 0));
1094 }
1095 
1098  if (m_element && h) {
1099  return h.clone(Document::DOC(document()));
1100  }
1101  throw std::runtime_error("Element::clone: Invalid element pointer -- unable to clone node!");
1102 }
1103 
1104 Attribute Element::getAttr(const XmlChar* name) const {
1105  return m_element ? attribute_node(m_element, name) : 0;
1106 }
1107 
1109 Attribute Element::setRef(const XmlChar* tag_value, const XmlChar* ref_name) const {
1110  return setChild(tag_value).setAttr(Unicode_ref, ref_name);
1111 }
1112 
1114 Attribute Element::setRef(const XmlChar* tag_value, const std::string& ref_name) const {
1115  return setRef(tag_value, Strng_t(ref_name).ptr());
1116 }
1117 
1119 const XmlChar* Element::getRef(const XmlChar* tag_value) const {
1120  return child(tag_value).attr < cpXmlChar > (Unicode_ref);
1121 }
1122 
1124 Handle_t Element::addChild(const XmlChar* tag_value) const {
1125  Handle_t e = document().createElt(tag_value);
1126  m_element.append(e);
1127  return e;
1128 }
1129 
1132  Elt_t e = m_element.child(t, false);
1133  return e ? Handle_t(e) : addChild(t);
1134 }
1135 
1136 #ifndef DD4HEP_USE_TINYXML
1137 void Element::addComment(const XmlChar* text_value) const {
1139  _N(m_element)->appendChild(_D(document().m_doc)->createComment(text_value));
1140 }
1141 #endif
1142 
1144 void Element::addComment(const char* text_value) const {
1145 #ifdef DD4HEP_USE_TINYXML
1146  _N(m_element)->appendChild(new TiXmlComment(text_value));
1147 #else
1148  _N(m_element)->appendChild(_D(document().m_doc)->createComment(Strng_t(text_value)));
1149 #endif
1150 }
1151 
1153 void Element::addComment(const std::string& text_value) const {
1154  addComment(text_value.c_str());
1155 }
1156 
1158 RefElement::RefElement(const Document& doc, const XmlChar* typ, const XmlChar* nam)
1159  : Element(doc, typ) {
1160  m_name = nam ? setAttr(_U(name), nam) : 0;
1161 }
1162 
1165  : Element(e) {
1166  m_name = m_element ? getAttr(_U(name)) : 0;
1167 }
1168 
1171  : Element(e), m_name(e.m_name) {
1172 }
1173 
1176  m_element = e.m_element;
1177  return *this;
1178 }
1179 
1180 const XmlChar* RefElement::name() const {
1181  if (0 == m_name)
1182  std::cout << "Error:tag=" << m_element.tag() << std::endl;
1183  return attribute_value(m_name);
1184 }
1185 
1187  if (0 == m_name)
1188  std::cout << "Error:tag=" << m_element.tag() << std::endl;
1189  return attribute_value(m_name);
1190 }
1191 
1192 void RefElement::setName(const XmlChar* new_name) {
1193  setAttr(_U(name), new_name);
1194 }
1195 
1196 #ifndef DD4HEP_USE_TINYXML
1197 Collection_t::Collection_t(Handle_t element, const XmlChar* tag_value)
1198  : m_children(element, tag_value) {
1199  m_node = m_children.reset();
1200 }
1201 #endif
1202 
1203 Collection_t::Collection_t(Handle_t element, const char* tag_value)
1204  : m_children(element, Strng_t(tag_value)) {
1205  m_node = m_children.reset();
1206 }
1207 
1210  : m_children(node_list) {
1211  m_node = m_children.reset();
1212 }
1213 
1216  m_node = m_children.reset();
1217  return *this;
1218 }
1219 
1221 size_t Collection_t::size() const {
1222  return Handle_t(m_children.m_node).numChildren(m_children.m_tag, false);
1223 }
1224 
1227  if (m_node) {
1228  throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting XML nodes of type <" + tag() + "/>");
1229  }
1230  throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting collections XML nodes.");
1231 }
1232 
1234  Elt_t e = this->parent();
1235  while (m_node) {
1236  m_node = m_children.next();
1237  if (m_node && _N(m_node)->getNodeType() == ELEMENT_NODE_TYPE) {
1238  if (this->parent() == e)
1239  return;
1240  }
1241  }
1242 }
1243 
1245  Elt_t e = this->parent();
1246  while (m_node) {
1248  if (m_node && _N(m_node)->getNodeType() == ELEMENT_NODE_TYPE) {
1249  if (this->parent() == e)
1250  return;
1251  }
1252  }
1253 }
1254 
1255 void Collection_t::operator++(int) const {
1256  ++(*this);
1257 }
1258 
1259 void Collection_t::operator--(int) const {
1260  --(*this);
1261 }
1262 
1264 #ifdef DD4HEP_USE_TINYXML
1265  return _XE(source.clone(0));
1266 #else
1267  return _XE(_D(m_doc)->importNode(_E(source.ptr()),true));
1268 #endif
1269 }
1270 
1271 #ifdef DD4HEP_USE_TINYXML
1272 //These files are located parallel to this one, we cannot use angle brackets for include
1273 #include "tinyxml_inl.h"
1274 #include "tinyxmlerror_inl.h"
1275 #include "tinyxmlparser_inl.h"
1276 #endif
dd4hep::xml::Collection_t::throw_loop_exception
void throw_loop_exception(const std::exception &e) const
Helper function to throw an exception.
Definition: XMLElements.cpp:1226
dd4hep::xml::Handle_t::setValue
void setValue(const XmlChar *text) const
Set the element's value.
Definition: XMLElements.cpp:772
dd4hep::xml::XmlString::replicate
static XmlChar * replicate(const XmlChar *c)
Replicate string: internally allocates new string, which must be free'ed with release.
Definition: XMLElements.cpp:142
TiXmlElement
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1069
dd4hep::xml::Element::document
Document document() const
Access the hosting document handle of this DOM element.
Definition: XMLElements.cpp:1092
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::xml::Element::setChild
Handle_t setChild(const XmlChar *tag) const
Check if a child with the required tag exists - if not create it and add it to the current node.
Definition: XMLElements.cpp:1131
dd4hep::xml::Tag_t::m_str
std::string m_str
STL string buffer.
Definition: XMLElements.h:257
TiXmlDocument
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1547
dd4hep::xml::Element::getRef
const XmlChar * getRef(const XmlChar *tag) const
Access the value of the reference attribute of the node (attribute ref="ref-name")
Definition: XMLElements.cpp:1119
dd4hep::xml::NodeList::next
XmlElement * next() const
Advance to next element.
Definition: XMLElements.cpp:590
DO16
#define DO16(buf)
dd4hep::xml::Handle_t::tag
std::string tag() const
Text access to the element's tag.
Definition: XMLElements.h:414
dd4hep::xml::Document::uri
std::string uri() const
Acces the document URI.
Definition: XMLElements.cpp:1050
_E
#define _E(x)
Definition: XMLElements.cpp:66
dd4hep::xml::_toDouble
double _toDouble(const XmlChar *value)
Conversion function from raw unicode string to double.
Definition: XMLElements.cpp:360
dd4hep::xml::RefElement::setName
void setName(const XmlChar *new_name)
Change/set the object's name.
Definition: XMLElements.cpp:1192
dd4hep::xml::cpXmlChar
const XmlChar * cpXmlChar
Definition: XMLElements.h:526
TiXmlNode::DECLARATION
@ DECLARATION
Definition: tinyxml.h:473
TiXmlNode::TEXT
@ TEXT
Definition: tinyxml.h:473
dd4hep::xml::Element::append
void append(Handle_t handle) const
Append a new element to the existing tree.
Definition: XMLElements.h:839
tinyxmlparser_inl.h
v
View * v
Definition: MultiView.cpp:28
dd4hep::xml::NodeList::operator=
NodeList & operator=(const NodeList &l)
Assignment operator.
Definition: XMLElements.cpp:624
ns
Helper structure to shortcut type definitions for the factories.
Definition: Factories.h:204
dd4hep::xml::NodeList
Class describing a list of XML nodes.
Definition: XMLElements.h:349
dd4hep::xml::Handle_t::clone
Handle_t clone(XmlDocument *new_doc) const
Clone the DOMelement - with the option of a deep copy.
Definition: XMLElements.cpp:649
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::xml::_toUInt
unsigned int _toUInt(const XmlChar *value)
Conversion function from raw unicode string to unsigned int.
Definition: XMLElements.cpp:337
dd4hep::xml::Handle_t::attr_value_nothrow
const XmlChar * attr_value_nothrow(const XmlChar *attr) const
Access attribute value by the attribute's unicode name (no exception thrown if not present)
Definition: XMLElements.cpp:872
dd4hep::xml::Element::m_element
Handle_t m_element
The underlying object holding the XmlElement pointer.
Definition: XMLElements.h:775
Xml::n
xercesc::DOMNode * n
Definition: XMLElements.cpp:134
dd4hep::xml::Attribute
const XmlAttr * Attribute
Definition: XMLElements.h:38
dd4hep::xml::NodeList::previous
XmlElement * previous() const
Go back to previous element.
Definition: XMLElements.cpp:607
tinyxml_inl.h
dd4hep::_toDictionary
void _toDictionary(const std::string &name, const std::string &value)
Enter name value pair to the dictionary. "value" must be a numerical expression, which is evaluated.
Definition: Handle.cpp:240
dd4hep::xml::Handle_t::setRef
Handle_t setRef(const XmlChar *tag, const XmlChar *ref)
Add reference child as a new child node. The obj must have the "name" attribute!
Definition: XMLElements.cpp:940
TiXmlNode::ELEMENT
@ ELEMENT
Definition: tinyxml.h:473
TiXmlNode::Type
int Type() const
Definition: tinyxml.h:758
dd4hep::xml::Document::DOC
XmlDocument * DOC
Definition: XMLElements.h:699
dd4hep::xml::Handle_t::append
void append(Handle_t e) const
Append a DOM element to the current node.
Definition: XMLElements.cpp:730
dd4hep::xml::Tag_t::operator=
Tag_t & operator=(const char *s)
Assignment of a normal ASCII string.
Definition: XMLElements.cpp:531
dd4hep::xml::Handle_t::parent
Handle_t parent() const
Access the element's parent element.
Definition: XMLElements.cpp:666
dd4hep::xml::_toLong
long _toLong(const XmlChar *value)
Conversion function from raw unicode string to long.
Definition: XMLElements.cpp:318
dd4hep::xml::Element::addChild
Handle_t addChild(const XmlChar *tag) const
Add a new child to the DOM node.
Definition: XMLElements.cpp:1124
Xml::e
xercesc::DOMElement * e
Definition: XMLElements.cpp:136
TiXmlNode::FirstChild
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:535
fcn_t
unsigned int() fcn_t(unsigned int, const XmlChar *, size_t)
Checksum (sub-)tree of a xml document/tree.
Definition: XMLElements.cpp:992
Xml::p
const void * p
Definition: XMLElements.cpp:133
TiXmlNode::ToElement
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:778
tinyxml.h
dd4hep::xml::Document::m_doc
DOC m_doc
Definition: XMLElements.h:700
dd4hep::xml::XmlString::length
static size_t length(const char *s)
String length in native representation.
Definition: XMLElements.cpp:157
dd4hep::xml::Document::createElt
Handle_t createElt(const XmlChar *tag) const
Create DOM element.
Definition: XMLElements.cpp:1034
dd4hep::xml::Handle_t::remove
Handle_t remove(Handle_t e) const
Remove a single child node identified by its handle from the tree of the element.
Definition: XMLElements.cpp:735
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
_D
#define _D(x)
Definition: XMLElements.cpp:65
dd4hep::xml::enableEnvironResolution
bool enableEnvironResolution(bool new_value)
Enable/disable environment resolution when parsing strings.
Definition: XMLElements.cpp:411
dd4hep::xml::Handle_t::setAttrs
void setAttrs(Handle_t e) const
Set attributes as in argument handle.
Definition: XMLElements.cpp:826
dd4hep::xml::Handle_t::Handle_t
Handle_t(Elt_t e=0)
Initializing constructor.
Definition: XMLElements.h:389
dd4hep::xml::NodeList::reset
XmlElement * reset()
Reset the nodelist - e.g. restart iteration from beginning.
Definition: XMLElements.cpp:585
TiXmlAttribute::Value
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:912
dd4hep::xml::_toDictionary
void _toDictionary(const XmlChar *name, const XmlChar *value)
Helper function to populate the evaluator dictionary.
Definition: XMLElements.cpp:368
dd4hep::xml::NodeList::~NodeList
~NodeList()
Default destructor.
Definition: XMLElements.cpp:581
dd4hep::xml::Handle_t::numChildren
size_t numChildren(const XmlChar *tag, bool throw_exception) const
Access the number of children of this DOM element with a given tag name.
Definition: XMLElements.cpp:698
dd4hep::xml::Element::Elt_t
Handle_t::Elt_t Elt_t
Simplification type declarations.
Definition: XMLElements.h:772
TiXmlNode::DOCUMENT
@ DOCUMENT
Definition: tinyxml.h:473
TiXmlComment
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1283
dd4hep::xml::Handle_t::attr_name
const XmlChar * attr_name(const Attribute attr) const
Access attribute name (throws exception if not present)
Definition: XMLElements.cpp:854
dd4hep::xml::NodeList::NodeList
NodeList(const NodeList &l)
Copy constructor.
Definition: XMLElements.cpp:567
dd4hep::xml::Handle_t::rawText
const XmlChar * rawText() const
Unicode text access to the element's text.
Definition: XMLElements.cpp:639
dd4hep::xml::Tag_t
Class to support both way translation between C++ and XML strings.
Definition: XMLElements.h:254
dd4hep::xml::Handle_t::hasChild
bool hasChild(const XmlChar *tag) const
Check the existence of a child with a given tag name.
Definition: XMLElements.cpp:767
dd4hep::xml::get_float_precision
int get_float_precision()
Access floating point precision on conversion to string.
Definition: XMLElements.cpp:232
TiXmlElement::FirstAttribute
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:1193
dd4hep::xml::NodeList::m_ptr
XmlElement * m_ptr
Definition: XMLElements.h:353
dd4hep::xml::RefElement::refName
const XmlChar * refName() const
Access the object's reference name in unicode (same as name)
Definition: XMLElements.cpp:1186
dd4hep::xml::NodeList::m_node
XmlElement * m_node
Definition: XMLElements.h:352
dd4hep::xml::Collection_t::reset
Collection_t & reset()
Reset the collection object to restart the iteration.
Definition: XMLElements.cpp:1215
Xml::l
xercesc::DOMNodeList * l
Definition: XMLElements.cpp:138
dd4hep::xml::Handle_t::removeChildren
void removeChildren(const XmlChar *tag) const
Remove children with a given tag name from the DOM node.
Definition: XMLElements.cpp:755
Xml::a
xercesc::DOMAttr * a
Definition: XMLElements.cpp:135
dd4hep::xml::Strng_t::m_xml
XmlChar * m_xml
Pointer to unicode string.
Definition: XMLElements.h:173
TiXmlAttribute
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:880
dd4hep::xml::Handle_t::attr_value
const XmlChar * attr_value(const Attribute attr) const
Access attribute value by the attribute (throws exception if not present)
Definition: XMLElements.cpp:867
TiXmlNode::NextSiblingElement
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml_inl.h:449
dd4hep::xml::Element::child
Handle_t child(const Strng_t &tag_value, bool except=true) const
Access child by tag name. Thow an exception if required in case the child is not present.
Definition: XMLElements.h:914
dd4hep::xml::set_float_precision
int set_float_precision(int precision)
Change floating point precision on conversion to string.
Definition: XMLElements.cpp:225
dd4hep::_toInteger
std::pair< int, double > _toInteger(const std::string &value)
Definition: Handle.cpp:69
dd4hep::xml::_toInt
int _toInt(const XmlChar *value)
Conversion function from raw unicode string to int.
Definition: XMLElements.cpp:333
config.h
dd4hep::xml::DocumentHolder::~DocumentHolder
virtual ~DocumentHolder()
Standard destructor - releases the document.
Definition: XMLElements.cpp:1073
dd4hep::xml
Namespace for the AIDA detector description toolkit supporting XML utilities.
Definition: ConditionsTags.h:27
dd4hep::xml::Element::setRef
Attribute setRef(const XmlChar *tag, const XmlChar *refname) const
Set the reference attribute to the node (adds attribute ref="ref-name")
Definition: XMLElements.cpp:1109
TiXmlElement::SetAttribute
void SetAttribute(const char *name, const char *_value)
Definition: tinyxml_inl.h:744
dd4hep::xml::RefElement::m_name
Attribute m_name
Attribute holding thre name.
Definition: XMLElements.h:956
ELEMENT_NODE_TYPE
#define ELEMENT_NODE_TYPE
Definition: XMLElements.cpp:126
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::xml::Handle_t::children
NodeList children(const XmlChar *tag) const
Access a group of children identified by the same tag name.
Definition: XMLElements.cpp:725
dd4hep::xml::RefElement::name
const XmlChar * name() const
Access the object's name in unicode.
Definition: XMLElements.cpp:1180
dd4hep::xml::XmlString::release
static void release(char **p)
Release string.
Definition: XMLElements.cpp:154
dd4hep::xml::Handle_t::attr_ptr
Attribute attr_ptr(const XmlChar *attr) const
Access attribute pointer by the attribute's unicode name (throws exception if not present)
Definition: XMLElements.cpp:841
dd4hep::xml::Element::ptr
Elt_t ptr() const
Access to XmlElement pointer.
Definition: XMLElements.h:813
dd4hep::xml::Element::Element
Element(const Handle_t &e)
Constructor from XmlElement handle.
Definition: XMLElements.h:778
dd4hep::xml::Element::getAttr
Attribute getAttr(const XmlChar *name) const
Access single attribute by its name.
Definition: XMLElements.cpp:1104
dd4hep::_toFloatingPoint
std::pair< int, double > _toFloatingPoint(const std::string &value)
Definition: Handle.cpp:62
dd4hep::xml::_toString
std::string _toString(const Attribute attr)
Convert xml attribute to STL string.
Definition: XMLElements.cpp:237
TiXmlAttribute::Next
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml_inl.h:1197
dd4hep::xml::XmlString::transcode
static XmlChar * transcode(const char *c)
Transcode string.
Definition: XMLElements.cpp:148
dd4hep::_getEnviron
std::string _getEnviron(const std::string &env)
Evaluate string constant using environment stored in the evaluator.
Definition: Handle.cpp:281
dd4hep::xml::Strng_t::operator=
Strng_t & operator=(const XmlChar *s)
Assignment opertor from unicode string.
Definition: XMLElements.cpp:490
TiXmlNode
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:434
Xml::xe
XmlElement * xe
Definition: XMLElements.cpp:139
dd4hep::xml::Strng_t
Helper class to encapsulate a unicode string.
Definition: XMLElements.h:170
Xml::d
xercesc::DOMDocument * d
Definition: XMLElements.cpp:137
dd4hep::xml::Handle_t::Elt_t
XmlElement * Elt_t
Definition: XMLElements.h:383
dd4hep::xml::DocumentHolder
Class supporting the basic functionality of an XML document including ownership.
Definition: XMLElements.h:741
dd4hep::xml::Handle_t::child
Handle_t child(const XmlChar *tag, bool throw_exception=true) const
Access a single child by its tag name (unicode)
Definition: XMLElements.cpp:713
dd4hep::xml::Element::clone
Handle_t clone(const Document &new_doc) const
Clone the DOMelement.
Definition: XMLElements.h:843
dd4hep::xml::Handle_t::setText
void setText(const XmlChar *text) const
Set the element's text.
Definition: XMLElements.cpp:786
TiXmlNode::UNKNOWN
@ UNKNOWN
Definition: tinyxml.h:473
dd4hep::xml::Document::clone
Handle_t clone(Handle_t source) const
Clone a DOM element / sub-tree.
Definition: XMLElements.cpp:1263
dd4hep::xml::DocumentHolder::assign
DocumentHolder & assign(DOC d)
Assign new document. Old document is dropped.
Definition: XMLElements.cpp:1059
dd4hep::xml::Document
Class supporting the basic functionality of an XML document.
Definition: XMLElements.h:697
TiXmlNode::FirstChildElement
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml_inl.h:419
dd4hep::xml::RefElement::RefElement
RefElement(const Handle_t &e)
Construction from existing object handle.
Definition: XMLElements.cpp:1164
dd4hep::xml::operator+
Strng_t operator+(const Strng_t &a, const char *b)
Unicode string concatenation of a normal ASCII string from right side.
Definition: XMLElements.cpp:432
dd4hep::xml::Element::parentElement
Elt_t parentElement() const
Access the XmlElements parent.
Definition: XMLElements.cpp:1083
dd4hep::xml::RefElement::operator=
RefElement & operator=(const RefElement &e)
Assignment operator.
Definition: XMLElements.cpp:1175
dd4hep::xml::Collection_t::size
size_t size() const
Access the collection size. Avoid this call – sloooow!
Definition: XMLElements.cpp:1221
tinyxmlerror_inl.h
dd4hep::xml::Handle_t::m_node
Elt_t m_node
The pointer to the XmlElement.
Definition: XMLElements.h:386
Xml::Xml
Xml(const void *ptr)
Definition: XMLElements.cpp:130
dd4hep::xml::RefElement
User abstraction class to manipulate named XML elements (references) within a document.
Definition: XMLElements.h:953
dd4hep::xml::Strng_t::ptr
const XmlChar * ptr() const
Accessor to unicode string.
Definition: XMLElements.h:204
dd4hep::xml::_toULong
unsigned long _toULong(const XmlChar *value)
Conversion function from raw unicode string to unsigned long.
Definition: XMLElements.cpp:326
TiXmlNode::Value
const char * Value() const
Definition: tinyxml.h:490
dd4hep::xml::Collection_t::Collection_t
Collection_t(Handle_t node, const XmlChar *tag)
Constructor over XmlElements with a given tag name.
Definition: XMLElements.cpp:1197
dd4hep::xml::Handle_t::rawTag
const XmlChar * rawTag() const
Unicode text access to the element's tag. Tis must be wrong ....
Definition: XMLElements.cpp:634
dd4hep::xml::_toFloat
float _toFloat(const XmlChar *value)
Conversion function from raw unicode string to float.
Definition: XMLElements.cpp:352
dd4hep::xml::XmlChar
XERCES_XMLCH_T XmlChar
Use the definition from the autoconf header of Xerces:
Definition: config.h:52
Xml
Union to ease castless object access when using XercesC.
Definition: XMLElements.cpp:129
XMLElements.h
dd4hep::xml::Element
User abstraction class to manipulate XML elements within a document.
Definition: XMLElements.h:769
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::xml::Tag_t::str
const std::string & str() const
Access writable STL string.
Definition: XMLElements.h:304
dd4hep::xml::Handle_t::attributes
std::vector< Attribute > attributes() const
Retrieve a collection of all attributes of this DOM element.
Definition: XMLElements.cpp:681
dd4hep::xml::Element::setAttr
Attribute setAttr(const XmlChar *nam, const T &val) const
Set single attribute.
Definition: XMLElements.h:900
dd4hep::xml::_ptrToString
std::string _ptrToString(const void *p, const char *fmt="%p")
Format void pointer (64 bits) to string with arbitrary format.
Definition: XMLElements.cpp:314
_XE
#define _XE(x)
Definition: XMLElements.cpp:69
dd4hep::xml::XmlSize_t
std::size_t XmlSize_t
Definition: config.h:46
dd4hep::xml::getEnviron
std::string getEnviron(const std::string &env)
Helper function to lookup environment from the expression evaluator.
Definition: XMLElements.cpp:406
dd4hep::xml::NodeList::m_tag
Tag_t m_tag
Definition: XMLElements.h:351
dd4hep::xml::Collection_t::m_children
NodeList m_children
Reference to the list of child nodes.
Definition: XMLElements.h:639
dd4hep::xml::Handle_t::setAttr
Attribute setAttr(const XmlChar *t, const XmlChar *v) const
Generic attribute setter with unicode value.
Definition: XMLElements.cpp:922
TiXmlElement::AttributeNode
const TiXmlAttribute * AttributeNode(const char *name) const
Definition: tinyxml.h:1088
TiXmlAttribute::Name
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:909
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::xml::Handle_t::checksum
unsigned int checksum(unsigned int param, unsigned int(fcn)(unsigned int param, const XmlChar *, size_t)=0) const
Checksum (sub-)tree of a xml document/tree. Default will pick up the adler32 checksum.
Definition: XMLElements.cpp:993
dd4hep::xml::Handle_t::hasAttr
bool hasAttr(const XmlChar *t) const
Check for the existence of a named attribute.
Definition: XMLElements.cpp:676
TiXmlNode::ToText
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:787
dd4hep::xml::Collection_t::operator++
void operator++() const
Operator to advance the collection (pre increment)
Definition: XMLElements.cpp:1233
XMLTags.h
TiXmlNode::NextSibling
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:666
dd4hep::xml::Handle_t::rawValue
const XmlChar * rawValue() const
Unicode text access to the element's value.
Definition: XMLElements.cpp:644
TiXmlNode::COMMENT
@ COMMENT
Definition: tinyxml.h:473
TiXmlText
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1339
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
_N
#define _N(x)
Definition: XMLElements.cpp:67
dd4hep::xml::_toBool
bool _toBool(const XmlChar *value)
Conversion function from raw unicode string to bool.
Definition: XMLElements.cpp:341
dd4hep::xml::Handle_t::ptr
Elt_t ptr() const
Direct access to the XmlElement by function.
Definition: XMLElements.h:401
dd4hep::xml::Collection_t::operator--
void operator--() const
Operator to advance the collection (pre decrement)
Definition: XMLElements.cpp:1244
dd4hep::xml::Handle_t::removeAttrs
void removeAttrs() const
Remove all attributes of this element.
Definition: XMLElements.cpp:804
dd4hep::xml::Element::addComment
void addComment(const XmlChar *text) const
Add comment node to the element.
Definition: XMLElements.cpp:1138
dd4hep::xml::Handle_t::attr_nothrow
Attribute attr_nothrow(const XmlChar *tag) const
Access attribute pointer by the attribute's unicode name (no exception thrown if not present)
Definition: XMLElements.cpp:671
dd4hep::xml::Document::root
Handle_t root() const
Access the ROOT eleemnt of the DOM document.
Definition: XMLElements.cpp:1043
Printout.h