Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:41

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 #ifndef XML_HELPER_H
0014 #define XML_HELPER_H
0015 
0016 // Framework include files
0017 #include <XML/XML.h>
0018 #include <DD4hep/Detector.h>
0019 #include <DD4hep/DD4hepUnits.h>
0020 
0021 /// Namespace for the AIDA detector description toolkit
0022 namespace dd4hep {
0023 
0024   /** Helper function to get attribute or return the default.
0025    *  If the hasAttr does not return true then the supplied default value is returned.
0026    *  This is useful when building a detector and you want to supply a default value.
0027    */
0028   template <typename T>
0029     T getAttrOrDefault(const dd4hep::xml::Element& e, const dd4hep::xml::XmlChar* attr_name, T default_value)
0030     {
0031       return (e.hasAttr(attr_name)) ? e.attr<T>(attr_name) : std::move(default_value);
0032     }
0033 
0034   /// Namespace for implementation details of the AIDA detector description toolkit
0035   namespace detail {
0036 
0037     /// std::string conversion of XML strings (e.g. Unicode for Xerces-C)
0038     static inline std::string _toString(const dd4hep::xml::XmlChar* value) {
0039       return xml::_toString(value);
0040     }
0041 
0042     /// std::string conversion of arbitrary entities including user defined formatting.
0043     template <typename T> inline std::string _toString(T value, const char* fmt) {
0044       return xml::_toString(value, fmt);
0045     }
0046   }
0047 }
0048 
0049 #endif // XML_HELPER_H