Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:16:48

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     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework includes
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 // C/C++ include files
0023 #include <stdexcept>
0024 
0025 /// Namespace for the AIDA detector description toolkit
0026 namespace dd4hep  {
0027 
0028   namespace   {
0029     /// Some utility class to specialize the converters:
0030     class include_file;
0031     class plugins;
0032     class plugin;
0033     class arg;
0034   }
0035 
0036 
0037   // Converters re-used from compact:
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   // Converters implemented here:
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 /** Convert arg objects
0052  *
0053  *  @author  M.Frank
0054  *  @version 1.0
0055  *  @date    01/04/2014
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 /** Convert plugin objects
0065  *
0066  *  @author  M.Frank
0067  *  @version 1.0
0068  *  @date    01/04/2014
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   //args.emplace_back("plugin:"+nam);
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 /** Convert include_file objects
0085  *
0086  *  @author  M.Frank
0087  *  @version 1.0
0088  *  @date    01/04/2014
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 /** Convert plugins objects
0103  *
0104  *  \author  M.Frank
0105  *  \version 1.0
0106  *  \date    01/04/2014
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