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  class DDParsingContext;
14  using DDVectorsMap = std::unordered_map<std::string, std::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 
54 
55  dd4hep::Solid solid(const std::string& name) const;
56  dd4hep::Solid addSolid(const std::string& name, dd4hep::Solid solid) const;
57  dd4hep::Solid addSolidNS(const std::string& name, dd4hep::Solid solid) const;
58 
59  dd4hep::Assembly assembly(const std::string& name) const;
60  dd4hep::Assembly addAssembly(dd4hep::Assembly asmb) const;
61 
62  dd4hep::Volume volume(const std::string& name, bool exc = true) const;
65 
66  const dd4hep::Rotation3D& rotation(const std::string& name) const;
67  void addRotation(const std::string& name, const dd4hep::Rotation3D& rot) const;
68 
69  DDParsingContext* const context() const { return m_context; }
71 
72  std::string_view name() const { return m_name; }
73  std::string noNamespace(const std::string&) const;
74 
75  std::vector<double> vecDbl(const std::string& name) const;
76  std::vector<float> vecFloat(const std::string& name) const;
77 
78  private:
81  bool m_pop = false;
82  };
83 } // namespace cms
84 
85 #define NAMESPACE_SEP ':'
86 
87 #endif
cms::DDNamespace::~DDNamespace
~DDNamespace()
Definition: DDNamespace.cc:50
cms::DDNamespace::realName
std::string realName(const std::string &) const
Definition: DDNamespace.cc:67
cms::DDNamespace::m_context
DDParsingContext * m_context
Definition: DDNamespace.h:79
g4SimHits_cfi.Material
Material
Definition: g4SimHits_cfi.py:560
cms::DDNamespace::addRotation
void addRotation(const std::string &name, const dd4hep::Rotation3D &rot) const
Definition: DDNamespace.cc:120
cms::DDNamespace::addConstant
void addConstant(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:97
cms::DDNamespace::solid
dd4hep::Solid solid(const std::string &name) const
Definition: DDNamespace.cc:240
cms::DDNamespace::attr
T attr(xml_elt_t element, const xml_tag_t &name) const
Definition: DDNamespace.h:34
cms::DDNamespace::material
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:116
cms::DDNamespace::noNamespace
std::string noNamespace(const std::string &) const
Definition: DDNamespace.cc:282
cms::DDNamespace::vecFloat
std::vector< float > vecFloat(const std::string &name) const
Definition: DDNamespace.cc:270
cms::DDNamespace::m_pop
bool m_pop
Definition: DDNamespace.h:81
cms::DDParsingContext
Definition: DDParsingContext.h:13
cms::DDNamespace
Definition: DDNamespace.h:16
cms::DDNamespace::addConstantNS
void addConstantNS(const std::string &name, const std::string &value, const std::string &type) const
Definition: DDNamespace.cc:101
cms::DDNamespace::objName
static std::string objName(const std::string &)
Definition: DDNamespace.cc:90
cms::DDNamespace::assembly
dd4hep::Assembly assembly(const std::string &name) const
Definition: DDNamespace.cc:192
cms::DDNamespace::prepend
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:60
cms::DDNamespace::addAssembly
dd4hep::Assembly addAssembly(dd4hep::Assembly asmb) const
Definition: DDNamespace.cc:184
cms::DDNamespace::rotation
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:125
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cms::Volume
dd4hep::Volume Volume
Definition: DDFilteredView.h:47
cms::DDNamespace::attr
T attr(xml_elt_t element, const xml_tag_t &name, T defaultValue) const
Definition: DDNamespace.h:41
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
value
Definition: value.py:1
cms::DDNamespace::addVolume
dd4hep::Volume addVolume(dd4hep::Volume vol) const
Add rotation matrix to current namespace.
Definition: DDNamespace.cc:165
cms::DDNamespace::DDNamespace
DDNamespace()=delete
cms::DDNamespace::addSolidNS
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:221
cms::DDNamespace::operator=
DDNamespace & operator=(const DDNamespace &)=delete
cms::DDNamespace::addSolid
dd4hep::Solid addSolid(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:236
cms::DDNamespace::addVolumeNS
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:145
cms::DDNamespace::setContext
DDParsingContext * setContext()
Definition: DDNamespace.h:70
cms::DDNamespace::nsName
static std::string nsName(const std::string &)
Definition: DDNamespace.cc:83
heppy_batch.val
val
Definition: heppy_batch.py:351
T
long double T
Definition: Basic3DVectorLD.h:48
cms::DDNamespace::context
DDParsingContext *const context() const
Definition: DDNamespace.h:69
cms::DDVectorsMap
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:14
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
cms::DDNamespace::vecDbl
std::vector< double > vecDbl(const std::string &name) const
Definition: DDNamespace.cc:261
cms::DDNamespace::m_name
std::string m_name
Definition: DDNamespace.h:80
cms::DDNamespace::name
std::string_view name() const
Definition: DDNamespace.h:72
cms::DDNamespace::volume
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:205
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21