File indexing completed on 2026-09-17 08:25:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef DD4HEP_NONE
0016
0017
0018 #include <DD4hep/Objects.h>
0019 #include <DD4hep/Printout.h>
0020 #include <DD4hep/OpaqueData.h>
0021 #include <DD4hep/OpaqueDataBinder.h>
0022 #include <XML/XMLParsers.h>
0023 #include <XML/XMLDimension.h>
0024 #include <XML/DocumentHandler.h>
0025
0026
0027
0028
0029 using std::string;
0030 using namespace dd4hep;
0031 typedef dd4hep::xml::Handle_t xml_h;
0032 typedef dd4hep::xml::Dimension xml_dim_t;
0033 typedef dd4hep::xml::Collection_t xml_coll_t;
0034
0035 namespace {
0036 PrintLevel s_print = DEBUG;
0037 }
0038
0039
0040 bool dd4hep::xml::setXMLParserDebug(bool value) {
0041 bool old = s_print==ALWAYS;
0042 s_print = value ? ALWAYS : DEBUG;
0043 return old;
0044 }
0045
0046
0047 void dd4hep::xml::parse(xml_h e, RotationZYX& rot) {
0048 xml_dim_t r(e);
0049 rot.SetComponents(r.z(), r.y(), r.x());
0050 printout(s_print,"<rotation>",
0051 " Rotation: x=%9.3f y=%9.3f z=%9.3f phi=%7.4f psi=%7.4f theta=%7.4f",
0052 r.x(), r.y(), r.z(), rot.Phi(), rot.Psi(), rot.Theta());
0053 }
0054
0055
0056 void dd4hep::xml::parse(xml_h e, Position& pos) {
0057 xml_dim_t p(e);
0058 pos.SetXYZ(p.x(), p.y(), p.z());
0059 printout(s_print,"<position>"," Position: x=%9.3f y=%9.3f z=%9.3f",
0060 pos.X(), pos.Y(), pos.Z());
0061 }
0062
0063
0064 void dd4hep::xml::parse(xml_h e, Translation3D& tr) {
0065 xml_dim_t p(e);
0066 double x,y,z;
0067 tr.SetXYZ(x=p.x(), y=p.y(), z=p.z());
0068 printout(s_print,"<translation>"," Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z);
0069 }
0070
0071
0072 void dd4hep::xml::parse(xml_h e, Delta& delta) {
0073 RotationZYX rot;
0074 Translation3D piv;
0075 xml_h child_rot, child_pos, child_piv;
0076
0077 if ( (child_pos=e.child(_U(position),false)) )
0078 parse(child_pos, delta.translation);
0079 if ( (child_rot=e.child(_U(rotation),false)) ) {
0080 parse(child_rot, delta.rotation);
0081 if ( (child_piv=e.child(_U(pivot),false)) )
0082 parse(child_piv, delta.pivot);
0083 }
0084 if ( child_rot && child_pos && child_piv )
0085 delta.flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION;
0086 else if ( child_rot && child_pos )
0087 delta.flags |= Delta::HAVE_ROTATION|Delta::HAVE_TRANSLATION;
0088 else if ( child_rot && child_piv )
0089 delta.flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT;
0090 else if ( child_rot )
0091 delta.flags |= Delta::HAVE_ROTATION;
0092 else if ( child_pos )
0093 delta.flags |= Delta::HAVE_TRANSLATION;
0094 }
0095
0096
0097 void dd4hep::xml::parse_delta(Handle_t e, OpaqueDataBlock& block) {
0098 Delta& delta = block.bind<Delta>();
0099 parse(e, delta);
0100 }
0101
0102
0103 void dd4hep::xml::parse_mapping(xml_h e, OpaqueDataBlock& b) {
0104 string val_type = e.attr<string>(_U(value));
0105 string key_type = e.attr<string>(_U(key));
0106 detail::MapBinder binder;
0107
0108 detail::OpaqueDataBinder::bind_map(binder, b, key_type, val_type);
0109 for(xml_coll_t i(e,_U(item)); i; ++i) {
0110
0111 if ( i.hasAttr(_U(key)) && i.hasAttr(_U(value)) ) {
0112 string key = i.attr<string>(_U(key));
0113 string val = i.attr<string>(_U(value));
0114 detail::OpaqueDataBinder::insert_map(binder, b, key_type, key, val_type, val);
0115 continue;
0116 }
0117
0118 detail::OpaqueDataBinder::insert_map(binder, b, key_type, val_type, i.text());
0119 }
0120 }
0121
0122
0123 void dd4hep::xml::parse_sequence(xml_h e, OpaqueDataBlock& block) {
0124 xml_dim_t elt(e);
0125 string typ = elt.typeStr();
0126 string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text();
0127 if ( !detail::OpaqueDataBinder::bind_sequence(block, typ, val) ) {
0128 except("XMLParsers",
0129 "++ Failed to convert unknown sequence conditions type: %s",typ.c_str());
0130 }
0131 }
0132
0133 #endif