DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
XMLParsers.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 Markus Frank
11 // \date 2017-03-15
12 // \version 1.0
13 //
14 //==========================================================================
15 #ifndef DD4HEP_NONE
16 
17 // Framework include files
18 #include <DD4hep/Objects.h>
19 #include <DD4hep/Printout.h>
20 #include <DD4hep/OpaqueData.h>
22 #include <XML/XMLParsers.h>
23 #include <XML/XMLDimension.h>
24 #include <XML/DocumentHandler.h>
25 
26 
27 // C/C++ include files
28 #include <stdexcept>
29 
30 using std::string;
31 using namespace dd4hep;
33 typedef dd4hep::xml::Dimension xml_dim_t;
35 
36 namespace {
37  PrintLevel s_print = DEBUG;
38 }
39 
42  bool old = s_print==ALWAYS;
43  s_print = value ? ALWAYS : DEBUG;
44  return old;
45 }
46 
49  xml_dim_t r(e);
50  rot.SetComponents(r.z(), r.y(), r.x());
51  printout(s_print,"<rotation>",
52  " Rotation: x=%9.3f y=%9.3f z=%9.3f phi=%7.4f psi=%7.4f theta=%7.4f",
53  r.x(), r.y(), r.z(), rot.Phi(), rot.Psi(), rot.Theta());
54 }
55 
58  xml_dim_t p(e);
59  pos.SetXYZ(p.x(), p.y(), p.z());
60  printout(s_print,"<position>"," Position: x=%9.3f y=%9.3f z=%9.3f",
61  pos.X(), pos.Y(), pos.Z());
62 }
63 
66  xml_dim_t p(e);
67  double x,y,z;
68  tr.SetXYZ(x=p.x(), y=p.y(), z=p.z());
69  printout(s_print,"<translation>"," Pivot: x=%9.3f y=%9.3f z=%9.3f",x,y,z);
70 }
71 
74  Position pos;
75  RotationZYX rot;
76  Translation3D piv;
77  xml_h child_rot, child_pos, child_piv;
78 
79  if ( (child_pos=e.child(_U(position),false)) )
80  parse(child_pos, delta.translation);
81  if ( (child_rot=e.child(_U(rotation),false)) ) {
82  parse(child_rot, delta.rotation);
83  if ( (child_piv=e.child(_U(pivot),false)) )
84  parse(child_piv, delta.pivot);
85  }
86  if ( child_rot && child_pos && child_piv )
88  else if ( child_rot && child_pos )
90  else if ( child_rot && child_piv )
92  else if ( child_rot )
94  else if ( child_pos )
96 }
97 
100  Delta& delta = block.bind<Delta>();
101  parse(e, delta);
102 }
103 
106  string val_type = e.attr<string>(_U(value));
107  string key_type = e.attr<string>(_U(key));
108  detail::MapBinder binder;
109 
110  detail::OpaqueDataBinder::bind_map(binder, b, key_type, val_type);
111  for(xml_coll_t i(e,_U(item)); i; ++i) {
112  // If explicit key, value data are present in attributes:
113  if ( i.hasAttr(_U(key)) && i.hasAttr(_U(value)) ) {
114  string key = i.attr<string>(_U(key));
115  string val = i.attr<string>(_U(value));
116  detail::OpaqueDataBinder::insert_map(binder, b, key_type, key, val_type, val);
117  continue;
118  }
119  // Otherwise interprete the data directly from the data content
120  detail::OpaqueDataBinder::insert_map(binder, b, key_type, val_type, i.text());
121  }
122 }
123 
126  xml_dim_t elt(e);
127  string typ = elt.typeStr();
128  string val = elt.hasAttr(_U(value)) ? elt.valueStr() : elt.text();
129  if ( !detail::OpaqueDataBinder::bind_sequence(block, typ, val) ) {
130  except("XMLParsers",
131  "++ Failed to convert unknown sequence conditions type: %s",typ.c_str());
132  }
133 }
134 
135 #endif
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::Delta::HAVE_TRANSLATION
@ HAVE_TRANSLATION
Definition: AlignmentData.h:48
Objects.h
dd4hep::detail::OpaqueDataBinder::bind_sequence
static bool bind_sequence(OBJECT &object, const std::string &typ, const std::string &val)
Binding function for sequences (unmapped STL containers)
dd4hep::Delta::HAVE_PIVOT
@ HAVE_PIVOT
Definition: AlignmentData.h:50
dd4hep::xml::parse_sequence
void parse_sequence(Handle_t e, OpaqueDataBlock &block)
Converts linear STL containers from their string representation.
Definition: XMLParsers.cpp:125
dd4hep::Delta::HAVE_ROTATION
@ HAVE_ROTATION
Definition: AlignmentData.h:49
dd4hep::Delta::rotation
RotationZYX rotation
Definition: AlignmentData.h:43
delta
const Delta * delta
Definition: AlignmentsCalculator.cpp:67
dd4hep::OpaqueDataBlock
Class describing an opaque conditions data block.
Definition: OpaqueData.h:92
dd4hep::Delta::flags
unsigned int flags
Definition: AlignmentData.h:44
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::xml::parse_delta
void parse_delta(Handle_t e, OpaqueDataBlock &block)
Parse delta into an opaque data block.
Definition: XMLParsers.cpp:99
dd4hep::Delta
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:38
dd4hep::xml::parse
void parse(Handle_t e, RotationZYX &rot)
Convert rotation XML objects to dd4hep::RotationZYX.
Definition: XMLParsers.cpp:48
dd4hep::OpaqueDataBlock::bind
void * bind(const BasicGrammar *grammar)
Bind data value.
Definition: OpaqueData.cpp:124
dd4hep::xml::setXMLParserDebug
bool setXMLParserDebug(bool new_value)
Set debug print level for this module. Default is OFF.
Definition: XMLParsers.cpp:41
DocumentHandler.h
dd4hep::Translation3D
ROOT::Math::Translation3D Translation3D
Definition: Objects.h:119
dd4hep::Delta::translation
Position translation
Definition: AlignmentData.h:41
XMLDimension.h
XMLParsers.h
dd4hep::Delta::pivot
Pivot pivot
Definition: AlignmentData.h:42
_U
#define _U(a)
Definition: Tags.h:23
xml_coll_t
dd4hep::xml::Collection_t xml_coll_t
Definition: XMLParsers.cpp:34
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:710
OpaqueData.h
dd4hep::detail::OpaqueDataBinder::insert_map
static bool insert_map(const BINDER &b, OBJECT &o, const std::string &key_type, const std::string &key, const std::string &val_type, const std::string &val)
Filling function for STL maps.
Definition: OpaqueDataBinder.cpp:302
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
xml_dim_t
dd4hep::xml::Dimension xml_dim_t
Definition: XMLParsers.cpp:33
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::xml::parse_mapping
void parse_mapping(Handle_t e, OpaqueDataBlock &block)
Converts opaque maps to OpaqueDataBlock objects.
Definition: XMLParsers.cpp:105
dd4hep::detail::OpaqueDataBinder::bind_map
static bool bind_map(const BINDER &b, OBJECT &o, const std::string &key_type, const std::string &val_type)
Binding function for STL maps. Does not fill data!
Definition: OpaqueDataBinder.cpp:272
dd4hep::RotationZYX
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:105
xml_h
dd4hep::xml::Handle_t xml_h
Definition: XMLParsers.cpp:32
dd4hep::detail::MapBinder
Helper class to bind STL map objects.
Definition: OpaqueDataBinder.h:66
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
Printout.h
OpaqueDataBinder.h
xml_dim_t
dd4hep::xml::Dimension xml_dim_t
Definition: XML.h:31