File indexing completed on 2025-01-18 09:14:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include "DDDB/DDDBTags.h"
0022 #include "DDDB/DDDBDimension.h"
0023 #include "DDDB/DDDBHelper.h"
0024
0025
0026 #include <set>
0027
0028 using namespace std;
0029 using namespace dd4hep;
0030 using namespace dd4hep::DDDB;
0031
0032
0033 namespace dd4hep {
0034
0035
0036 namespace {
0037 struct dddb_vis {};
0038 struct vis {};
0039 struct display {};
0040 struct volume {};
0041 struct include {};
0042 }
0043 template <> void Converter<dddb_vis>::operator()(xml_h element) const;
0044 template <> void Converter<vis>::operator()(xml_h element) const;
0045 template <> void Converter<display>::operator()(xml_h element) const;
0046 template <> void Converter<volume>::operator()(xml_h element) const;
0047 template <> void Converter<include>::operator()(xml_h element) const;
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 template <> void Converter<vis>::operator()(xml_h e) const {
0058 VisAttr attr(e.attr<string>(_U(name)));
0059 float red = e.hasAttr(_U(r)) ? e.attr<float>(_U(r)) : 1.0f;
0060 float green = e.hasAttr(_U(g)) ? e.attr<float>(_U(g)) : 1.0f;
0061 float blue = e.hasAttr(_U(b)) ? e.attr<float>(_U(b)) : 1.0f;
0062
0063 printout(DEBUG, "Compact", "++ Converting VisAttr structure: %s.",attr.name());
0064 attr.setColor(red, green, blue);
0065 if (e.hasAttr(_U(alpha)))
0066 attr.setAlpha(e.attr<float>(_U(alpha)));
0067 if (e.hasAttr(_U(visible)))
0068 attr.setVisible(e.attr<bool>(_U(visible)));
0069 if (e.hasAttr(_U(lineStyle))) {
0070 string ls = e.attr<string>(_U(lineStyle));
0071 if (ls == "unbroken")
0072 attr.setLineStyle(VisAttr::SOLID);
0073 else if (ls == "broken")
0074 attr.setLineStyle(VisAttr::DASHED);
0075 }
0076 else {
0077 attr.setLineStyle(VisAttr::SOLID);
0078 }
0079 if (e.hasAttr(_U(drawingStyle))) {
0080 string ds = e.attr<string>(_U(drawingStyle));
0081 if (ds == "wireframe")
0082 attr.setDrawingStyle(VisAttr::WIREFRAME);
0083 else if (ds == "solid")
0084 attr.setDrawingStyle(VisAttr::SOLID);
0085 }
0086 else {
0087 attr.setDrawingStyle(VisAttr::SOLID);
0088 }
0089 if (e.hasAttr(_U(showDaughters)))
0090 attr.setShowDaughters(e.attr<bool>(_U(showDaughters)));
0091 else
0092 attr.setShowDaughters(true);
0093 description.addVisAttribute(attr);
0094 }
0095
0096 template <> void Converter<include>::operator()(xml_h e) const {
0097 xml::DocumentHolder doc(xml::DocumentHandler().load(e, e.attr_value(_U(ref))));
0098 xml_h node = doc.root();
0099 string tag = node.tag();
0100
0101 if ( tag == "display" )
0102 xml_coll_t(node,_U(vis)).for_each(Converter<vis>(this->description,param));
0103 else if ( tag == "vismapping" )
0104 xml_coll_t(node,_U(volume)).for_each(Converter<volume>(this->description,param));
0105 else if ( tag == "DDDB_VIS" )
0106 Converter<dddb_vis>(description,param)(node);
0107 else if ( tag == "dddb_vis" )
0108 Converter<dddb_vis>(description,param)(node);
0109 }
0110
0111 template <> void Converter<volume>::operator()(xml_h e) const {
0112 dddb_dim_t dim = e;
0113 string path = dim.nameStr();
0114 string attr = dim.visStr();
0115 DDDBHelper* helper = _param<DDDBHelper>();
0116 helper->addVisAttr(path, attr);
0117 }
0118
0119 template <> void Converter<dddb_vis>::operator()(xml_h e) const {
0120 xml_coll_t(e, _U(include)).for_each( Converter<include>(description,param));
0121 xml_coll_t(e, _U(display)).for_each(_U(include), Converter<include>(description,param));
0122 xml_coll_t(e, _LBU(vismapping)).for_each(_U(include), Converter<include>(description,param));
0123 xml_coll_t(e, _U(display)).for_each(_U(vis), Converter<vis> (description,param));
0124 xml_coll_t(e, _LBU(vismapping)).for_each(_U(volume), Converter<volume> (description,param));
0125 }
0126 }
0127
0128
0129 static long load_dddb_vis(Detector& description, xml_h element) {
0130 DDDBHelper* helper = description.extension<DDDBHelper>(false);
0131 if ( helper ) {
0132 dd4hep::Converter<dddb_vis> cnv(description,helper);
0133 cnv(element);
0134 return 1;
0135 }
0136 except("DDDB","+++ Failed to access cool. No DDDBHelper object defined. Run plugin DDDBInstallHelper.");
0137 return 0;
0138 }
0139 DECLARE_XML_DOC_READER(DDDB_VIS,load_dddb_vis)