Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:09:42

0001 #ifndef DETECTOR_DESCRIPTION_DD_NAMESPACE_H
0002 #define DETECTOR_DESCRIPTION_DD_NAMESPACE_H
0003 
0004 #include "XML/XML.h"
0005 #include "DD4hep/Objects.h"
0006 #include "DD4hep/Shapes.h"
0007 #include "DD4hep/Volumes.h"
0008 #include <unordered_map>
0009 #include <vector>
0010 
0011 namespace cms {
0012 
0013   namespace rotation_utils {
0014     std::string rotHash(const Double_t* rot);
0015     std::string rotHash(const dd4hep::Rotation3D& rot);
0016     double roundBinary(double value);
0017   }  // namespace rotation_utils
0018 
0019   class DDParsingContext;
0020   using DDVectorsMap = std::unordered_map<std::string, std::vector<double>>;
0021 
0022   class DDNamespace {
0023   public:
0024     DDNamespace(DDParsingContext*, xml_h);
0025     DDNamespace(DDParsingContext&, xml_h, bool);
0026     DDNamespace(DDParsingContext*);
0027     DDNamespace(DDParsingContext&);
0028     ~DDNamespace();
0029 
0030     DDNamespace() = delete;
0031     DDNamespace(const DDNamespace&) = delete;
0032     DDNamespace& operator=(const DDNamespace&) = delete;
0033 
0034     std::string prepend(const std::string&) const;
0035     std::string realName(const std::string&) const;
0036     static std::string objName(const std::string&);
0037     static std::string nsName(const std::string&);
0038 
0039     template <typename T>
0040     T attr(xml_elt_t element, const xml_tag_t& name) const {
0041       std::string val = realName(element.attr<std::string>(name));
0042       element.setAttr(name, val);
0043       return element.attr<T>(name);
0044     }
0045 
0046     template <typename T>
0047     T attr(xml_elt_t element, const xml_tag_t& name, T defaultValue) const {
0048       if (element.hasAttr(name)) {
0049         std::string val = realName(element.attr<std::string>(name));
0050         element.setAttr(name, val);
0051         return element.attr<T>(name);
0052       }
0053       return defaultValue;
0054     }
0055 
0056     void addConstant(const std::string& name, const std::string& value, const std::string& type) const;
0057     void addConstantNS(const std::string& name, const std::string& value, const std::string& type) const;
0058 
0059     dd4hep::Material material(const std::string& name) const;
0060 
0061     dd4hep::Solid solid(const std::string& name) const;
0062     dd4hep::Solid addSolid(const std::string& name, dd4hep::Solid solid) const;
0063     dd4hep::Solid addSolidNS(const std::string& name, dd4hep::Solid solid) const;
0064 
0065     dd4hep::Assembly assembly(const std::string& name, bool exception = true) const;
0066     dd4hep::Assembly addAssembly(dd4hep::Assembly asmb, bool addSolid = true) const;
0067     dd4hep::Assembly addAssemblySolid(dd4hep::Assembly assembly) const;
0068 
0069     dd4hep::Volume volume(const std::string& name, bool exc = true) const;
0070     dd4hep::Volume addVolume(dd4hep::Volume vol) const;
0071     dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const;
0072 
0073     const dd4hep::Rotation3D& rotation(const std::string& name) const;
0074     void addRotation(const std::string& name, const dd4hep::Rotation3D& rot) const;
0075 
0076     DDParsingContext* const context() const { return m_context; }
0077     DDParsingContext* setContext() { return m_context; }
0078 
0079     std::string_view name() const { return m_name; }
0080     std::string noNamespace(const std::string&) const;
0081 
0082     std::vector<double> vecDbl(const std::string& name) const;
0083     std::vector<float> vecFloat(const std::string& name) const;
0084 
0085   private:
0086     DDParsingContext* m_context = nullptr;
0087     std::string m_name;
0088     bool m_pop = false;
0089   };
0090 }  // namespace cms
0091 
0092 #define NAMESPACE_SEP ':'
0093 
0094 #endif