File indexing completed on 2024-04-06 12:05:27
0001 #ifndef DETECTOR_DESCRIPTION_DDCMS_DD_SOLID_SHAPES_H
0002 #define DETECTOR_DESCRIPTION_DDCMS_DD_SOLID_SHAPES_H
0003
0004 #include <algorithm>
0005 #include <array>
0006 #include <iterator>
0007 #include <string>
0008
0009 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
0010
0011 using LegacySolidShape = DDSolidShape;
0012
0013 namespace cms {
0014 namespace dd {
0015 template <class T>
0016 struct NameValuePair {
0017 using value_type = T;
0018 const T value;
0019 const char* const name;
0020 };
0021
0022 template <class T, class U>
0023 struct ValuePair {
0024 using value_type = T;
0025 using name_type = U;
0026 const T value;
0027 const U name;
0028 };
0029
0030 template <class Mapping, class V>
0031 std::string name(Mapping a, V value) {
0032 auto pos = std::find_if(
0033 std::begin(a), std::end(a), [&value](const typename Mapping::value_type& t) { return (t.value == value); });
0034 if (pos != std::end(a)) {
0035 return pos->name;
0036 }
0037
0038 return std::begin(a)->name;
0039 }
0040
0041 template <class Mapping>
0042 typename Mapping::value_type::value_type value(Mapping a, const std::string& name) {
0043 auto pos = std::find_if(
0044 std::begin(a), std::end(a), [&name](const typename Mapping::value_type& t) { return (t.name == name); });
0045 if (pos != std::end(a)) {
0046 return pos->value;
0047 }
0048 return std::begin(a)->value;
0049 }
0050
0051 template <class Mapping, class N>
0052 typename Mapping::value_type::value_type value(Mapping a, N name) {
0053 auto pos = std::find_if(
0054 std::begin(a), std::end(a), [&name](const typename Mapping::value_type& t) { return (t.name == name); });
0055 if (pos != std::end(a)) {
0056 return pos->value;
0057 }
0058 return std::begin(a)->value;
0059 }
0060
0061 template <class Mapping, class V>
0062 typename Mapping::value_type::name_type name_from_value(Mapping a, V value) {
0063 auto pos = std::find_if(
0064 std::begin(a), std::end(a), [&value](const typename Mapping::value_type& t) { return (t.value == value); });
0065 if (pos != std::end(a)) {
0066 return pos->name;
0067 }
0068 return std::begin(a)->name;
0069 }
0070
0071 };
0072
0073 enum class DDSolidShape {
0074 dd_not_init = 0,
0075 ddbox = 1,
0076 ddtubs = 2,
0077 ddtrap = 3,
0078 ddcons = 4,
0079 ddpolycone = 5,
0080 ddpolyhedra = 6,
0081 ddunsupported1 = 7,
0082 ddunsupported2 = 8,
0083 ddtorus = 9,
0084 ddunion = 10,
0085 ddsubtraction = 11,
0086 ddintersection = 12,
0087 ddshapeless = 13,
0088 ddpseudotrap = 14,
0089 ddtrunctubs = 15,
0090 ddsphere = 16,
0091 ddellipticaltube = 17,
0092 ddcuttubs = 18,
0093 ddextrudedpolygon = 19,
0094 ddtrd1 = 20,
0095 ddtrd2 = 21,
0096 ddassembly = 22
0097 };
0098
0099 const std::array<const cms::dd::NameValuePair<DDSolidShape>, 21> DDSolidShapeMap{
0100 {{DDSolidShape::dd_not_init, "Solid not initialized"},
0101 {DDSolidShape::ddbox, "Box"},
0102 {DDSolidShape::ddtubs, "Tube"},
0103 {DDSolidShape::ddtrap, "Trap"},
0104 {DDSolidShape::ddcons, "ConeSegment"},
0105 {DDSolidShape::ddpolycone, "Polycone"},
0106 {DDSolidShape::ddpolyhedra, "Polyhedra"},
0107 {DDSolidShape::ddtorus, "Torus"},
0108 {DDSolidShape::ddunion, "Union"},
0109 {DDSolidShape::ddsubtraction, "Subtraction"},
0110 {DDSolidShape::ddintersection, "Intersection"},
0111 {DDSolidShape::ddshapeless, "ShapelessSolid"},
0112 {DDSolidShape::ddpseudotrap, "PseudoTrap"},
0113 {DDSolidShape::ddtrunctubs, "TruncatedTube"},
0114 {DDSolidShape::ddsphere, "Sphere"},
0115 {DDSolidShape::ddellipticaltube, "EllipticalTube"},
0116 {DDSolidShape::ddcuttubs, "CutTube"},
0117 {DDSolidShape::ddextrudedpolygon, "ExtrudedPolygon"},
0118 {DDSolidShape::ddtrd1, "Trd1"},
0119 {DDSolidShape::ddtrd2, "Trd2"},
0120 {DDSolidShape::ddassembly, "Assembly"}}};
0121
0122 const std::array<const cms::dd::ValuePair<LegacySolidShape, cms::DDSolidShape>, 21> LegacySolidShapeMap{
0123 {{LegacySolidShape::dd_not_init, cms::DDSolidShape::dd_not_init},
0124 {LegacySolidShape::ddbox, cms::DDSolidShape::ddbox},
0125 {LegacySolidShape::ddtubs, cms::DDSolidShape::ddtubs},
0126 {LegacySolidShape::ddtrap, cms::DDSolidShape::ddtrap},
0127 {LegacySolidShape::ddcons, cms::DDSolidShape::ddcons},
0128 {LegacySolidShape::ddpolycone_rz, cms::DDSolidShape::ddpolycone},
0129 {LegacySolidShape::ddpolycone_rrz, cms::DDSolidShape::ddpolycone},
0130 {LegacySolidShape::ddpolyhedra_rz, cms::DDSolidShape::ddpolyhedra},
0131 {LegacySolidShape::ddpolyhedra_rrz, cms::DDSolidShape::ddpolyhedra},
0132 {LegacySolidShape::ddtorus, cms::DDSolidShape::ddtorus},
0133 {LegacySolidShape::ddunion, cms::DDSolidShape::ddunion},
0134 {LegacySolidShape::ddsubtraction, cms::DDSolidShape::ddsubtraction},
0135 {LegacySolidShape::ddintersection, cms::DDSolidShape::ddintersection},
0136 {LegacySolidShape::ddshapeless, cms::DDSolidShape::ddshapeless},
0137 {LegacySolidShape::ddpseudotrap, cms::DDSolidShape::ddpseudotrap},
0138 {LegacySolidShape::ddtrunctubs, cms::DDSolidShape::ddtrunctubs},
0139 {LegacySolidShape::ddsphere, cms::DDSolidShape::ddsphere},
0140 {LegacySolidShape::ddellipticaltube, cms::DDSolidShape::ddellipticaltube},
0141 {LegacySolidShape::ddcuttubs, cms::DDSolidShape::ddcuttubs},
0142 {LegacySolidShape::ddextrudedpolygon, cms::DDSolidShape::ddextrudedpolygon},
0143 {LegacySolidShape::ddassembly, cms::DDSolidShape::ddassembly}}};
0144
0145 }
0146
0147 #endif