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 "tbb/concurrent_unordered_map.h"
9 #include "tbb/concurrent_vector.h"
10 
11 namespace cms {
12 
13  class DDParsingContext;
14  using DDVectorsMap = tbb::concurrent_unordered_map<std::string, tbb::concurrent_vector<double>>;
15 
16  class DDNamespace {
17  public:
19  DDNamespace(DDParsingContext&, xml_h, bool);
22  ~DDNamespace();
23 
24  DDNamespace() = delete;
25  DDNamespace(const DDNamespace&) = delete;
26  DDNamespace& operator=(const DDNamespace&) = delete;
27 
28  std::string prepend(const std::string&) const;
29  std::string realName(const std::string&) const;
30  static std::string objName(const std::string&);
31  static std::string nsName(const std::string&);
32 
33  template <typename T>
34  T attr(xml_elt_t element, const xml_tag_t& name) const {
35  std::string val = realName(element.attr<std::string>(name));
36  element.setAttr(name, val);
37  return element.attr<T>(name);
38  }
39 
40  template <typename T>
41  T attr(xml_elt_t element, const xml_tag_t& name, T defaultValue) const {
42  if (element.hasAttr(name)) {
43  std::string val = realName(element.attr<std::string>(name));
44  element.setAttr(name, val);
45  return element.attr<T>(name);
46  }
47  return defaultValue;
48  }
49 
50  void addConstant(const std::string& name, const std::string& value, const std::string& type) const;
51  void addConstantNS(const std::string& name, const std::string& value, const std::string& type) const;
52 
53  dd4hep::Material material(const std::string& name) const;
54  dd4hep::Solid solid(const std::string& name) const;
55  dd4hep::Solid addSolid(const std::string& name, dd4hep::Solid solid) const;
56  dd4hep::Solid addSolidNS(const std::string& name, dd4hep::Solid solid) const;
57 
58  dd4hep::Volume volume(const std::string& name, bool exc = true) const;
61 
62  const dd4hep::Rotation3D& rotation(const std::string& name) const;
63  void addRotation(const std::string& name, const dd4hep::Rotation3D& rot) const;
64 
65  DDParsingContext* const context() const { return m_context; }
67 
68  std::string_view name() const { return m_name; }
69 
70  std::vector<double> vecDbl(const std::string& name) const;
71 
72  private:
75  bool m_pop = false;
76  };
77 } // namespace cms
78 
79 #define NAMESPACE_SEP ':'
80 
81 #endif
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:200
type
Definition: HCALResponse.h:21
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:184
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:150
std::string m_name
Definition: DDNamespace.h:74
dd4hep::Volume addVolume(dd4hep::Volume vol) const
Add rotation matrix to current namespace.
Definition: DDNamespace.cc:167
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:219
DDParsingContext *const context() const
Definition: DDNamespace.h:65
std::string_view name() const
Definition: DDNamespace.h:68
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:107
static std::string nsName(const std::string &)
Definition: DDNamespace.cc:89
void addRotation(const std::string &name, const dd4hep::Rotation3D &rot) const
Definition: DDNamespace.cc:125
std::string realName(const std::string &) const
Definition: DDNamespace.cc:73
T attr(xml_elt_t element, const xml_tag_t &name) const
Definition: DDNamespace.h:34
static std::string objName(const std::string &)
Definition: DDNamespace.cc:96
tbb::concurrent_unordered_map< std::string, tbb::concurrent_vector< double >> DDVectorsMap
Definition: DDNamespace.h:14
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:121
DDNamespace & operator=(const DDNamespace &)=delete
std::vector< double > vecDbl(const std::string &name) const
Definition: DDNamespace.cc:240
Definition: value.py:1
DDParsingContext * m_context
Definition: DDNamespace.h:73
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:66
dd4hep::Volume Volume
T attr(xml_elt_t element, const xml_tag_t &name, T defaultValue) const
Definition: DDNamespace.h:41
Namespace of DDCMS conversion namespace.
dd4hep::Solid addSolid(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:215
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:130
DDNamespace()=delete
long double T
void addConstant(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:103
DDParsingContext * setContext()
Definition: DDNamespace.h:66