File indexing completed on 2025-07-08 08:12:29
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 Position pos;
0074 RotationZYX rot;
0075 Translation3D piv;
0076 xml_h child_rot, child_pos, child_piv;
0077
0078 if ( (child_pos=e.child(_U(position),false)) )
0079 parse(child_pos, delta.translation);
0080 if ( (child_rot=e.child(_U(rotation),false)) ) {
0081 parse(child_rot, delta.rotation);
0082 if ( (child_piv=e.child(_U(pivot),false)) )
0083 parse(child_piv, delta.pivot);
0084 }
0085 if ( child_rot && child_pos && child_piv )
0086 delta.flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION;
0087 else if ( child_rot && child_pos )
0088 delta.flags |= Delta::HAVE_ROTATION|Delta::HAVE_TRANSLATION;
0089 else if ( child_rot && child_piv )
0090 delta.flags |= Delta::HAVE_ROTATION|Delta::HAVE_PIVOT;
0091 else if ( child_rot )
0092 delta.flags |= Delta::HAVE_ROTATION;
0093 else if ( child_pos )
0094 delta.flags |= Delta::HAVE_TRANSLATION;
0095 }
0096
0097
0098 void dd4hep::xml::parse_delta(Handle_t e, OpaqueDataBlock& block) {
0099 Delta& delta = block.bind<Delta>();
0100 parse(e, delta);
0101 }
0102
0103
0104 void dd4hep::xml::parse_mapping(xml_h e, OpaqueDataBlock& b) {
0105 string val_type = e.attr<string>(_U(value));
0106 string key_type = e.attr<string>(_U(key));
0107 detail::MapBinder binder;
0108
0109 detail::OpaqueDataBinder::bind_map(binder, b, key_type, val_type);
0110 for(xml_coll_t i(e,_U(item)); i; ++i) {
0111
0112 if ( i.hasAttr(_U(key)) && i.hasAttr(_U(value)) ) {
0113 string key = i.attr<string>(_U(key));
0114 string val = i.attr<string>(_U(value));
0115 detail::OpaqueDataBinder::insert_map(binder, b, key_type, key, val_type, val);
0116 continue;
0117 }
0118
0119 detail::OpaqueDataBinder::insert_map(binder, b, key_type, val_type, i.text());
0120 }
0121 }
0122
0123
0124 void dd4hep::xml::parse_sequence(xml_h e, OpaqueDataBlock& block) {
0125 xml_dim_t elt(e);
0126 string typ = elt.typeStr();
0127 string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text();
0128 if ( !detail::OpaqueDataBinder::bind_sequence(block, typ, val) ) {
0129 except("XMLParsers",
0130 "++ Failed to convert unknown sequence conditions type: %s",typ.c_str());
0131 }
0132 }
0133
0134 #endif