CMS 3D CMS Logo

DDSolidShapes.h
Go to the documentation of this file.
1 #ifndef DETECTOR_DESCRIPTION_DDCMS_DD_SOLID_SHAPES_H
2 #define DETECTOR_DESCRIPTION_DDCMS_DD_SOLID_SHAPES_H
3 
4 #include <algorithm>
5 #include <array>
6 #include <iterator>
7 #include <string>
8 
10 
12 
13 namespace cms {
14  namespace dd {
15  template <class T>
16  struct NameValuePair {
17  using value_type = T;
18  const T value;
19  const char* const name;
20  };
21 
22  template <class T, class U>
23  struct ValuePair {
24  using value_type = T;
25  using name_type = U;
26  const T value;
27  const U name;
28  };
29 
30  template <class Mapping, class V>
31  std::string name(Mapping a, V value) {
32  auto pos = std::find_if(
33  std::begin(a), std::end(a), [&value](const typename Mapping::value_type& t) { return (t.value == value); });
34  if (pos != std::end(a)) {
35  return pos->name;
36  }
37 
38  return std::begin(a)->name;
39  }
40 
41  template <class Mapping>
43  auto pos = std::find_if(
44  std::begin(a), std::end(a), [&name](const typename Mapping::value_type& t) { return (t.name == name); });
45  if (pos != std::end(a)) {
46  return pos->value;
47  }
48  return std::begin(a)->value;
49  }
50 
51  template <class Mapping, class N>
53  auto pos = std::find_if(
54  std::begin(a), std::end(a), [&name](const typename Mapping::value_type& t) { return (t.name == name); });
55  if (pos != std::end(a)) {
56  return pos->value;
57  }
58  return std::begin(a)->value;
59  }
60 
61  template <class Mapping, class V>
62  typename Mapping::value_type::name_type name_from_value(Mapping a, V value) {
63  auto pos = std::find_if(
64  std::begin(a), std::end(a), [&value](const typename Mapping::value_type& t) { return (t.value == value); });
65  if (pos != std::end(a)) {
66  return pos->name;
67  }
68  return std::begin(a)->name;
69  }
70 
71  }; // namespace dd
72 
73  enum class DDSolidShape {
74  dd_not_init = 0,
75  ddbox = 1,
76  ddtubs = 2,
77  ddtrap = 3,
78  ddcons = 4,
79  ddpolycone = 5,
80  ddpolyhedra = 6,
81  ddunsupported1 = 7,
82  ddunsupported2 = 8,
83  ddtorus = 9,
84  ddunion = 10,
85  ddsubtraction = 11,
86  ddintersection = 12,
87  ddshapeless = 13,
88  ddpseudotrap = 14,
89  ddtrunctubs = 15,
90  ddsphere = 16,
91  ddellipticaltube = 17,
92  ddcuttubs = 18,
93  ddextrudedpolygon = 19,
94  ddtrd1 = 20,
95  ddtrd2 = 21,
96  ddassembly = 22
97  };
98 
99  const std::array<const cms::dd::NameValuePair<DDSolidShape>, 21> DDSolidShapeMap{
100  {{DDSolidShape::dd_not_init, "Solid not initialized"},
101  {DDSolidShape::ddbox, "Box"},
102  {DDSolidShape::ddtubs, "Tube"},
103  {DDSolidShape::ddtrap, "Trap"},
104  {DDSolidShape::ddcons, "ConeSegment"},
105  {DDSolidShape::ddpolycone, "Polycone"},
106  {DDSolidShape::ddpolyhedra, "Polyhedra"},
107  {DDSolidShape::ddtorus, "Torus"},
108  {DDSolidShape::ddunion, "Union"},
109  {DDSolidShape::ddsubtraction, "Subtraction"},
110  {DDSolidShape::ddintersection, "Intersection"},
111  {DDSolidShape::ddshapeless, "ShapelessSolid"},
112  {DDSolidShape::ddpseudotrap, "PseudoTrap"},
113  {DDSolidShape::ddtrunctubs, "TruncatedTube"},
114  {DDSolidShape::ddsphere, "Sphere"},
115  {DDSolidShape::ddellipticaltube, "EllipticalTube"},
116  {DDSolidShape::ddcuttubs, "CutTube"},
117  {DDSolidShape::ddextrudedpolygon, "ExtrudedPolygon"},
118  {DDSolidShape::ddtrd1, "Trd1"},
119  {DDSolidShape::ddtrd2, "Trd2"},
120  {DDSolidShape::ddassembly, "Assembly"}}};
121 
122  const std::array<const cms::dd::ValuePair<LegacySolidShape, cms::DDSolidShape>, 21> LegacySolidShapeMap{
128  {LegacySolidShape::ddpolycone_rz, cms::DDSolidShape::ddpolycone},
129  {LegacySolidShape::ddpolycone_rrz, cms::DDSolidShape::ddpolycone},
130  {LegacySolidShape::ddpolyhedra_rz, cms::DDSolidShape::ddpolyhedra},
131  {LegacySolidShape::ddpolyhedra_rrz, cms::DDSolidShape::ddpolyhedra},
144 
145 } // namespace cms
146 
147 #endif
std::string name(Mapping a, V value)
Definition: DDSolidShapes.h:31
string dd
Definition: createTree.py:154
Mapping::value_type::value_type value(Mapping a, const std::string &name)
Definition: DDSolidShapes.h:42
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
const std::array< const cms::dd::NameValuePair< DDSolidShape >, 21 > DDSolidShapeMap
Definition: DDSolidShapes.h:99
Definition: value.py:1
const std::array< const cms::dd::ValuePair< LegacySolidShape, cms::DDSolidShape >, 21 > LegacySolidShapeMap
Namespace of DDCMS conversion namespace.
#define N
Definition: blowfish.cc:9
DDSolidShape
Definition: DDSolidShapes.h:6
double a
Definition: hdecay.h:121
Mapping::value_type::name_type name_from_value(Mapping a, V value)
Definition: DDSolidShapes.h:62
long double T
const char *const name
Definition: DDSolidShapes.h:19
DDSolidShape
Definition: DDSolidShapes.h:73