Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-14 08:15:03

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   Markus Frank
0011 //  \date     2017-03-15
0012 //  \version  1.0
0013 //
0014 //==========================================================================
0015 #ifndef DD4HEP_NONE
0016 
0017 // Framework include files
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 // C/C++ include files
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 /// Set debug level for this module. Default is OFF
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 /// Convert rotation XML objects to dd4hep::RotationZYX
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 /// Convert XML position objects to dd4hep::Position
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 /// Convert XML pivot objects to dd4hep::Translation3D objects
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 /// Convert alignment delta objects to Delta
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 /// Parse delta into an opaque data block
0099 void dd4hep::xml::parse_delta(Handle_t e, OpaqueDataBlock& block)   {
0100   Delta& delta = block.bind<Delta>();
0101   parse(e, delta);
0102 }
0103 
0104 /// Converts opaque maps to OpaqueDataBlock objects
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     // If explicit key, value data are present in attributes:
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     // Otherwise interprete the data directly from the data content
0120     detail::OpaqueDataBinder::insert_map(binder, b, key_type, val_type, i.text());
0121   }
0122 }
0123 
0124 /// Converts linear STL containers from their string representation.
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