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