File indexing completed on 2025-01-18 09:28:01
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <string>
0012 #include <utility>
0013
0014 #include "DD4hep/Detector.h"
0015
0016 namespace Acts {
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 class ActsExtension {
0030 public:
0031
0032
0033
0034 ActsExtension(const std::string& axes = "XYZ");
0035
0036
0037
0038
0039 ActsExtension(const ActsExtension& ext) = default;
0040
0041
0042
0043
0044
0045 ActsExtension(const ActsExtension& ext, const dd4hep::DetElement& elem);
0046
0047
0048 ~ActsExtension() = default;
0049
0050
0051
0052
0053
0054 double getValue(const std::string& tag,
0055 const std::string& category = "") const noexcept(false);
0056
0057
0058
0059
0060
0061
0062 void addValue(double value, const std::string& tag,
0063 const std::string& category = "");
0064
0065
0066
0067
0068
0069 bool hasValue(const std::string& tag, const std::string& category = "") const;
0070
0071
0072
0073
0074
0075 bool hasType(const std::string& type, const std::string& category = "") const;
0076
0077
0078
0079
0080 bool hasCategory(const std::string& category) const;
0081
0082
0083
0084
0085
0086
0087 void addType(const std::string& type, const std::string& category = "",
0088 const std::string& word = "");
0089
0090
0091
0092
0093
0094 const std::string getType(const std::string& type,
0095 const std::string& category = "") const
0096 noexcept(false);
0097
0098
0099 std::string toString() const;
0100
0101 private:
0102
0103 template <typename T>
0104 void addT(std::map<std::string, T>& map, const T& val, const std::string& tag,
0105 const std::string& category, const T& catDeco);
0106
0107
0108 template <typename T>
0109 const T getT(const std::map<std::string, T>& map, const std::string& tag,
0110 const std::string& category = "") const noexcept(false);
0111
0112
0113 template <typename T>
0114 bool hasT(const std::map<std::string, T>& map, const std::string& tag,
0115 const std::string& category = "") const;
0116
0117
0118 std::map<std::string, std::string> m_flagStore;
0119
0120
0121 std::map<std::string, double> m_values;
0122 };
0123
0124
0125 template <typename T>
0126 const T ActsExtension::getT(const std::map<std::string, T>& map,
0127 const std::string& tag,
0128 const std::string& category) const noexcept(false) {
0129 std::string ctag = "/";
0130 if (!category.empty()) {
0131 ctag += category;
0132 ctag += "/";
0133 }
0134 ctag += tag;
0135 auto search = map.find(ctag);
0136 if (search == map.end()) {
0137 std::string error_message = "Acts::ActsExtension does not contain: ";
0138 error_message += ctag;
0139 error_message += '\n';
0140 error_message += toString();
0141 throw std::runtime_error(error_message.c_str());
0142 }
0143 return search->second;
0144 }
0145
0146
0147 template <typename T>
0148 void ActsExtension::addT(std::map<std::string, T>& map, const T& val,
0149 const std::string& tag, const std::string& category,
0150 const T& catDeco) {
0151 std::string ctag = "/";
0152 if (!category.empty()) {
0153 ctag += category;
0154 map[ctag] = catDeco;
0155 ctag += "/";
0156 }
0157 ctag += tag;
0158 map[ctag] = val;
0159 }
0160
0161
0162 template <typename T>
0163 bool ActsExtension::hasT(const std::map<std::string, T>& map,
0164 const std::string& tag,
0165 const std::string& category) const {
0166 std::string ctag = "/";
0167 if (!category.empty()) {
0168 ctag += category;
0169 ctag += "/";
0170 }
0171 ctag += tag;
0172 auto search = map.find(ctag);
0173 return (search != map.end());
0174 }
0175
0176 }
0177
0178 #include "ActsExtension.ipp"