CMS 3D CMS Logo

DDNamespace.h
Go to the documentation of this file.
1 #ifndef DETECTOR_DESCRIPTION_DD_NAMESPACE_H
2 #define DETECTOR_DESCRIPTION_DD_NAMESPACE_H
3 
4 #include "XML/XML.h"
5 #include "DD4hep/Objects.h"
6 #include "DD4hep/Shapes.h"
7 #include "DD4hep/Volumes.h"
8 #include <unordered_map>
9 #include <vector>
10 
11 namespace cms {
12 
13  namespace rotation_utils {
14  std::string rotHash(const Double_t* rot);
15  std::string rotHash(const dd4hep::Rotation3D& rot);
16  double roundBinary(double value);
17  } // namespace rotation_utils
18 
19  class DDParsingContext;
20  using DDVectorsMap = std::unordered_map<std::string, std::vector<double>>;
21 
22  class DDNamespace {
23  public:
25  DDNamespace(DDParsingContext&, xml_h, bool);
28  ~DDNamespace();
29 
30  DDNamespace() = delete;
31  DDNamespace(const DDNamespace&) = delete;
32  DDNamespace& operator=(const DDNamespace&) = delete;
33 
34  std::string prepend(const std::string&) const;
35  std::string realName(const std::string&) const;
36  static std::string objName(const std::string&);
37  static std::string nsName(const std::string&);
38 
39  template <typename T>
40  T attr(xml_elt_t element, const xml_tag_t& name) const {
41  std::string val = realName(element.attr<std::string>(name));
42  element.setAttr(name, val);
43  return element.attr<T>(name);
44  }
45 
46  template <typename T>
47  T attr(xml_elt_t element, const xml_tag_t& name, T defaultValue) const {
48  if (element.hasAttr(name)) {
49  std::string val = realName(element.attr<std::string>(name));
50  element.setAttr(name, val);
51  return element.attr<T>(name);
52  }
53  return defaultValue;
54  }
55 
56  void addConstant(const std::string& name, const std::string& value, const std::string& type) const;
57  void addConstantNS(const std::string& name, const std::string& value, const std::string& type) const;
58 
60 
61  dd4hep::Solid solid(const std::string& name) const;
62  dd4hep::Solid addSolid(const std::string& name, dd4hep::Solid solid) const;
63  dd4hep::Solid addSolidNS(const std::string& name, dd4hep::Solid solid) const;
64 
65  dd4hep::Assembly assembly(const std::string& name, bool exception = true) const;
66  dd4hep::Assembly addAssembly(dd4hep::Assembly asmb, bool addSolid = true) const;
67  dd4hep::Assembly addAssemblySolid(dd4hep::Assembly assembly) const;
68 
69  dd4hep::Volume volume(const std::string& name, bool exc = true) const;
72 
73  const dd4hep::Rotation3D& rotation(const std::string& name) const;
74  void addRotation(const std::string& name, const dd4hep::Rotation3D& rot) const;
75 
76  DDParsingContext* const context() const { return m_context; }
78 
79  std::string_view name() const { return m_name; }
80  std::string noNamespace(const std::string&) const;
81 
82  std::vector<double> vecDbl(const std::string& name) const;
83  std::vector<float> vecFloat(const std::string& name) const;
84 
85  private:
88  bool m_pop = false;
89  };
90 } // namespace cms
91 
92 #define NAMESPACE_SEP ':'
93 
94 #endif
T attr(xml_elt_t element, const xml_tag_t &name, T defaultValue) const
Definition: DDNamespace.h:47
std::string rotHash(const Double_t *rot)
Definition: DDNamespace.cc:26
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:182
dd4hep::Assembly addAssembly(dd4hep::Assembly asmb, bool addSolid=true) const
Definition: DDNamespace.cc:240
std::string realName(const std::string &) const
Definition: DDNamespace.cc:106
std::string m_name
Definition: DDNamespace.h:87
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:144
DDParsingContext *const context() const
Definition: DDNamespace.h:76
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
std::string noNamespace(const std::string &) const
Definition: DDNamespace.cc:353
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:20
static std::string nsName(const std::string &)
Definition: DDNamespace.cc:122
void addRotation(const std::string &name, const dd4hep::Rotation3D &rot) const
Definition: DDNamespace.cc:170
std::vector< float > vecFloat(const std::string &name) const
Definition: DDNamespace.cc:341
std::string_view name() const
Definition: DDNamespace.h:79
static std::string objName(const std::string &)
Definition: DDNamespace.cc:129
dd4hep::Volume addVolume(dd4hep::Volume vol) const
Definition: DDNamespace.cc:221
DDNamespace & operator=(const DDNamespace &)=delete
Definition: value.py:1
DDParsingContext * m_context
Definition: DDNamespace.h:86
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:311
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
double roundBinary(double value)
Definition: DDNamespace.cc:18
T attr(xml_elt_t element, const xml_tag_t &name) const
Definition: DDNamespace.h:40
dd4hep::Assembly addAssemblySolid(dd4hep::Assembly assembly) const
Definition: DDNamespace.cc:251
void addConstant(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:136
dd4hep::Solid addSolid(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:307
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
DDNamespace()=delete
long double T
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::vector< double > vecDbl(const std::string &name) const
Definition: DDNamespace.cc:332
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:292
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
DDParsingContext * setContext()
Definition: DDNamespace.h:77
dd4hep::Assembly assembly(const std::string &name, bool exception=true) const
Definition: DDNamespace.cc:259