DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
PluginInvoker.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 : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework includes
15 #include <DD4hep/Detector.h>
16 #include <DD4hep/Printout.h>
17 #include <XML/Conversions.h>
18 #include <XML/XMLElements.h>
19 #include <XML/DocumentHandler.h>
21 
22 // C/C++ include files
23 #include <stdexcept>
24 
26 namespace dd4hep {
27 
28  namespace {
30  class include_file;
31  class plugins;
32  class plugin;
33  class arg;
34  }
35 
36 
37  // Converters re-used from compact:
38  template <> void Converter<Readout>::operator()(xml_h element) const;
39  template <> void Converter<LimitSet>::operator()(xml_h element) const;
40  template <> void Converter<Constant>::operator()(xml_h element) const;
41  template <> void Converter<VisAttr>::operator()(xml_h element) const;
42  // Converters implemented here:
43  template <> void Converter<include_file>::operator()(xml_h element) const;
44  template <> void Converter<plugins>::operator()(xml_h element) const;
45  template <> void Converter<plugin>::operator()(xml_h element) const;
46  template <> void Converter<dd4hep::arg>::operator()(xml_h element) const;
47 }
48 
49 using namespace dd4hep;
50 
57 template <> void Converter<dd4hep::arg>::operator()(xml_h e) const {
58  xml_comp_t c(e);
59  std::string val = c.valueStr();
60  std::vector<std::string>* args = (std::vector<std::string>*)param;
61  args->emplace_back(val);
62 }
63 
70 template <> void Converter<plugin>::operator()(xml_h e) const {
71  xml_comp_t c(e);
72  std::string nam = c.nameStr();
73  std::vector<std::string> args;
74  std::vector<const char*> cargs;
75  //args.emplace_back("plugin:"+nam);
76 
77  xml_coll_t(e,"arg").for_each(Converter<dd4hep::arg>(description,&args));
78  for(std::vector<std::string>::const_iterator i=args.begin(); i!=args.end();++i)
79  cargs.emplace_back((*i).c_str());
80  printout(INFO,"ConverterPlugin","+++ Now executing plugin:%s [%d args]",nam.c_str(),int(cargs.size()));
81  description.apply(nam.c_str(),int(cargs.size()),(char**)&cargs[0]);
82 }
83 
90 template <> void Converter<include_file>::operator()(xml_h element) const {
91  xml::DocumentHolder doc(xml::DocumentHandler().load(element, element.attr_value(_U(ref))));
92  xml_h node = doc.root();
93  std::string tag = node.tag();
94  if ( tag == "plugin" )
95  Converter<plugin>(description,param)(node);
96  else if ( tag == "plugins" )
97  Converter<plugins>(description,param)(node);
98  else
99  throw std::runtime_error("Undefined tag name in XML structure:"+tag+" XML parsing abandoned.");
100 }
101 
108 template <> void Converter<plugins>::operator()(xml_h e) const {
109  xml_coll_t(e, _U(define)).for_each(_U(constant), Converter<Constant>(description,param));
110  xml_coll_t(e, _U(display)).for_each(_U(vis), Converter<VisAttr>(description,param));
111  xml_coll_t(e, _U(include)).for_each( Converter<include_file>(description,param));
112  xml_coll_t(e, _U(includes)).for_each(_U(include), Converter<include_file>(description,param));
113  xml_coll_t(e, _U(limits)).for_each(_U(limitset), Converter<LimitSet>(description,param));
114  xml_coll_t(e, _U(readouts)).for_each(_U(readout), Converter<Readout>(description,param));
115  xml_coll_t(e, _U(plugin)).for_each( Converter<plugin>(description,param));
116 }
117 
118 static long handle_plugins(Detector& description, const xml_h& element) {
119  (dd4hep::Converter < plugins > (description))(element);
120  return 1;
121 }
122 DECLARE_XML_DOC_READER(plugins,handle_plugins)
123 
dd4hep::xml::Handle_t::tag
std::string tag() const
Text access to the element's tag.
Definition: XMLElements.h:414
Detector.h
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
xml_coll_t
dd4hep::xml::Collection_t xml_coll_t
Definition: ConditionsRepository.cpp:35
xml_comp_t
dd4hep::xml::Component xml_comp_t
Definition: XML.h:33
DocumentHandler.h
dd4hep::xml::Handle_t::attr_value
const XmlChar * attr_value(const Attribute attr) const
Access attribute value by the attribute (throws exception if not present)
Definition: XMLElements.cpp:864
dd4hep::xml::Collection_t::for_each
void for_each(T oper) const
Loop processor using function object.
Definition: XMLElements.h:667
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::xml::DocumentHolder
Class supporting the basic functionality of an XML document including ownership.
Definition: XMLElements.h:741
DECLARE_XML_DOC_READER
#define DECLARE_XML_DOC_READER(name, func)
Definition: Factories.h:316
DetFactoryHelper.h
dd4hep::xml::DocumentHandler
Class supporting to read and parse XML documents.
Definition: DocumentHandler.h:39
Conversions.h
XMLElements.h
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
Printout.h