DDSolidShape

NameValuePair

ValuePair

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
#ifndef DETECTOR_DESCRIPTION_DDCMS_DD_SOLID_SHAPES_H
#define DETECTOR_DESCRIPTION_DDCMS_DD_SOLID_SHAPES_H

#include <algorithm>
#include <array>
#include <iterator>
#include <string>

#include "DetectorDescription/Core/interface/DDSolidShapes.h"

using LegacySolidShape = DDSolidShape;

namespace cms {
  namespace dd {
    template <class T>
    struct NameValuePair {
      using value_type = T;
      const T value;
      const char* const name;
    };

    template <class T, class U>
    struct ValuePair {
      using value_type = T;
      using name_type = U;
      const T value;
      const U name;
    };

    template <class Mapping, class V>
    std::string name(Mapping a, V value) {
      auto pos = std::find_if(
          std::begin(a), std::end(a), [&value](const typename Mapping::value_type& t) { return (t.value == value); });
      if (pos != std::end(a)) {
        return pos->name;
      }

      return std::begin(a)->name;
    }

    template <class Mapping>
    typename Mapping::value_type::value_type value(Mapping a, const std::string& name) {
      auto pos = std::find_if(
          std::begin(a), std::end(a), [&name](const typename Mapping::value_type& t) { return (t.name == name); });
      if (pos != std::end(a)) {
        return pos->value;
      }
      return std::begin(a)->value;
    }

    template <class Mapping, class N>
    typename Mapping::value_type::value_type value(Mapping a, N name) {
      auto pos = std::find_if(
          std::begin(a), std::end(a), [&name](const typename Mapping::value_type& t) { return (t.name == name); });
      if (pos != std::end(a)) {
        return pos->value;
      }
      return std::begin(a)->value;
    }

    template <class Mapping, class V>
    typename Mapping::value_type::name_type name_from_value(Mapping a, V value) {
      auto pos = std::find_if(
          std::begin(a), std::end(a), [&value](const typename Mapping::value_type& t) { return (t.value == value); });
      if (pos != std::end(a)) {
        return pos->name;
      }
      return std::begin(a)->name;
    }

  };  // namespace dd

  enum class DDSolidShape {
    dd_not_init = 0,
    ddbox = 1,
    ddtubs = 2,
    ddtrap = 3,
    ddcons = 4,
    ddpolycone = 5,
    ddpolyhedra = 6,
    ddunsupported1 = 7,
    ddunsupported2 = 8,
    ddtorus = 9,
    ddunion = 10,
    ddsubtraction = 11,
    ddintersection = 12,
    ddshapeless = 13,
    ddpseudotrap = 14,
    ddtrunctubs = 15,
    ddsphere = 16,
    ddellipticaltube = 17,
    ddcuttubs = 18,
    ddextrudedpolygon = 19,
    ddtrd1 = 20,
    ddtrd2 = 21,
    ddassembly = 22
  };

  const std::array<const cms::dd::NameValuePair<DDSolidShape>, 21> DDSolidShapeMap{
      {{DDSolidShape::dd_not_init, "Solid not initialized"},
       {DDSolidShape::ddbox, "Box"},
       {DDSolidShape::ddtubs, "Tube"},
       {DDSolidShape::ddtrap, "Trap"},
       {DDSolidShape::ddcons, "ConeSegment"},
       {DDSolidShape::ddpolycone, "Polycone"},
       {DDSolidShape::ddpolyhedra, "Polyhedra"},
       {DDSolidShape::ddtorus, "Torus"},
       {DDSolidShape::ddunion, "Union"},
       {DDSolidShape::ddsubtraction, "Subtraction"},
       {DDSolidShape::ddintersection, "Intersection"},
       {DDSolidShape::ddshapeless, "ShapelessSolid"},
       {DDSolidShape::ddpseudotrap, "PseudoTrap"},
       {DDSolidShape::ddtrunctubs, "TruncatedTube"},
       {DDSolidShape::ddsphere, "Sphere"},
       {DDSolidShape::ddellipticaltube, "EllipticalTube"},
       {DDSolidShape::ddcuttubs, "CutTube"},
       {DDSolidShape::ddextrudedpolygon, "ExtrudedPolygon"},
       {DDSolidShape::ddtrd1, "Trd1"},
       {DDSolidShape::ddtrd2, "Trd2"},
       {DDSolidShape::ddassembly, "Assembly"}}};

  const std::array<const cms::dd::ValuePair<LegacySolidShape, cms::DDSolidShape>, 21> LegacySolidShapeMap{
      {{LegacySolidShape::dd_not_init, cms::DDSolidShape::dd_not_init},
       {LegacySolidShape::ddbox, cms::DDSolidShape::ddbox},
       {LegacySolidShape::ddtubs, cms::DDSolidShape::ddtubs},
       {LegacySolidShape::ddtrap, cms::DDSolidShape::ddtrap},
       {LegacySolidShape::ddcons, cms::DDSolidShape::ddcons},
       {LegacySolidShape::ddpolycone_rz, cms::DDSolidShape::ddpolycone},
       {LegacySolidShape::ddpolycone_rrz, cms::DDSolidShape::ddpolycone},
       {LegacySolidShape::ddpolyhedra_rz, cms::DDSolidShape::ddpolyhedra},
       {LegacySolidShape::ddpolyhedra_rrz, cms::DDSolidShape::ddpolyhedra},
       {LegacySolidShape::ddtorus, cms::DDSolidShape::ddtorus},
       {LegacySolidShape::ddunion, cms::DDSolidShape::ddunion},
       {LegacySolidShape::ddsubtraction, cms::DDSolidShape::ddsubtraction},
       {LegacySolidShape::ddintersection, cms::DDSolidShape::ddintersection},
       {LegacySolidShape::ddshapeless, cms::DDSolidShape::ddshapeless},
       {LegacySolidShape::ddpseudotrap, cms::DDSolidShape::ddpseudotrap},
       {LegacySolidShape::ddtrunctubs, cms::DDSolidShape::ddtrunctubs},
       {LegacySolidShape::ddsphere, cms::DDSolidShape::ddsphere},
       {LegacySolidShape::ddellipticaltube, cms::DDSolidShape::ddellipticaltube},
       {LegacySolidShape::ddcuttubs, cms::DDSolidShape::ddcuttubs},
       {LegacySolidShape::ddextrudedpolygon, cms::DDSolidShape::ddextrudedpolygon},
       {LegacySolidShape::ddassembly, cms::DDSolidShape::ddassembly}}};

}  // namespace cms

#endif