File indexing completed on 2025-01-30 09:16:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Detector.h>
0016 #include <DD4hep/Printout.h>
0017 #include <XML/Conversions.h>
0018 #include <XML/XMLElements.h>
0019 #include <XML/DocumentHandler.h>
0020 #include <DD4hep/DetFactoryHelper.h>
0021
0022
0023 #include <stdexcept>
0024
0025
0026 namespace dd4hep {
0027
0028 namespace {
0029
0030 class include_file;
0031 class plugins;
0032 class plugin;
0033 class arg;
0034 }
0035
0036
0037
0038 template <> void Converter<Readout>::operator()(xml_h element) const;
0039 template <> void Converter<LimitSet>::operator()(xml_h element) const;
0040 template <> void Converter<Constant>::operator()(xml_h element) const;
0041 template <> void Converter<VisAttr>::operator()(xml_h element) const;
0042
0043 template <> void Converter<include_file>::operator()(xml_h element) const;
0044 template <> void Converter<plugins>::operator()(xml_h element) const;
0045 template <> void Converter<plugin>::operator()(xml_h element) const;
0046 template <> void Converter<dd4hep::arg>::operator()(xml_h element) const;
0047 }
0048
0049 using namespace dd4hep;
0050
0051
0052
0053
0054
0055
0056
0057 template <> void Converter<dd4hep::arg>::operator()(xml_h e) const {
0058 xml_comp_t c(e);
0059 std::string val = c.valueStr();
0060 std::vector<std::string>* args = (std::vector<std::string>*)param;
0061 args->emplace_back(val);
0062 }
0063
0064
0065
0066
0067
0068
0069
0070 template <> void Converter<plugin>::operator()(xml_h e) const {
0071 xml_comp_t c(e);
0072 std::string nam = c.nameStr();
0073 std::vector<std::string> args;
0074 std::vector<const char*> cargs;
0075
0076
0077 xml_coll_t(e,"arg").for_each(Converter<dd4hep::arg>(description,&args));
0078 for(std::vector<std::string>::const_iterator i=args.begin(); i!=args.end();++i)
0079 cargs.emplace_back((*i).c_str());
0080 printout(INFO,"ConverterPlugin","+++ Now executing plugin:%s [%d args]",nam.c_str(),int(cargs.size()));
0081 description.apply(nam.c_str(),int(cargs.size()),(char**)&cargs[0]);
0082 }
0083
0084
0085
0086
0087
0088
0089
0090 template <> void Converter<include_file>::operator()(xml_h element) const {
0091 xml::DocumentHolder doc(xml::DocumentHandler().load(element, element.attr_value(_U(ref))));
0092 xml_h node = doc.root();
0093 std::string tag = node.tag();
0094 if ( tag == "plugin" )
0095 Converter<plugin>(description,param)(node);
0096 else if ( tag == "plugins" )
0097 Converter<plugins>(description,param)(node);
0098 else
0099 throw std::runtime_error("Undefined tag name in XML structure:"+tag+" XML parsing abandoned.");
0100 }
0101
0102
0103
0104
0105
0106
0107
0108 template <> void Converter<plugins>::operator()(xml_h e) const {
0109 xml_coll_t(e, _U(define)).for_each(_U(constant), Converter<Constant>(description,param));
0110 xml_coll_t(e, _U(display)).for_each(_U(vis), Converter<VisAttr>(description,param));
0111 xml_coll_t(e, _U(include)).for_each( Converter<include_file>(description,param));
0112 xml_coll_t(e, _U(includes)).for_each(_U(include), Converter<include_file>(description,param));
0113 xml_coll_t(e, _U(limits)).for_each(_U(limitset), Converter<LimitSet>(description,param));
0114 xml_coll_t(e, _U(readouts)).for_each(_U(readout), Converter<Readout>(description,param));
0115 xml_coll_t(e, _U(plugin)).for_each( Converter<plugin>(description,param));
0116 }
0117
0118 static long handle_plugins(Detector& description, const xml_h& element) {
0119 (dd4hep::Converter < plugins > (description))(element);
0120 return 1;
0121 }
0122 DECLARE_XML_DOC_READER(plugins,handle_plugins)
0123