File indexing completed on 2025-12-16 09:22:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <cstdint>
0012 #include <functional>
0013 #include <iosfwd>
0014 #include <stdexcept>
0015
0016 namespace Acts {
0017
0018 class Surface;
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 class GeometryIdentifier {
0032 public:
0033
0034 using Value = std::uint64_t;
0035
0036
0037
0038 explicit constexpr GeometryIdentifier(Value encoded) : m_value(encoded) {}
0039
0040 GeometryIdentifier() = default;
0041
0042 GeometryIdentifier(GeometryIdentifier&&) = default;
0043
0044 GeometryIdentifier(const GeometryIdentifier&) = default;
0045 ~GeometryIdentifier() = default;
0046
0047
0048 GeometryIdentifier& operator=(GeometryIdentifier&&) = default;
0049
0050
0051 GeometryIdentifier& operator=(const GeometryIdentifier&) = default;
0052
0053
0054
0055 constexpr Value value() const { return m_value; }
0056
0057
0058
0059 constexpr Value volume() const { return getBits(kVolumeMask); }
0060
0061
0062
0063 constexpr Value boundary() const { return getBits(kBoundaryMask); }
0064
0065
0066
0067 constexpr Value layer() const { return getBits(kLayerMask); }
0068
0069
0070
0071 constexpr Value approach() const { return getBits(kApproachMask); }
0072
0073
0074
0075 constexpr Value passive() const { return getBits(kApproachMask); }
0076
0077
0078
0079 constexpr Value sensitive() const { return getBits(kSensitiveMask); }
0080
0081
0082
0083
0084
0085 constexpr Value extra() const { return getBits(kExtraMask); }
0086
0087
0088
0089
0090 [[nodiscard]]
0091 constexpr GeometryIdentifier withVolume(Value volume) const {
0092 GeometryIdentifier id = *this;
0093 id.setBits(kVolumeMask, volume);
0094 return id;
0095 }
0096
0097
0098
0099
0100 [[nodiscard]]
0101 constexpr GeometryIdentifier withBoundary(Value boundary) const {
0102 GeometryIdentifier id = *this;
0103 id.setBits(kBoundaryMask, boundary);
0104 return id;
0105 }
0106
0107
0108
0109
0110 [[nodiscard]]
0111 constexpr GeometryIdentifier withLayer(Value layer) const {
0112 GeometryIdentifier id = *this;
0113 id.setBits(kLayerMask, layer);
0114 return id;
0115 }
0116
0117
0118
0119
0120 [[nodiscard]]
0121 constexpr GeometryIdentifier withApproach(Value approach) const {
0122 GeometryIdentifier id = *this;
0123 id.setBits(kApproachMask, approach);
0124 return id;
0125 }
0126
0127
0128
0129
0130 [[nodiscard]]
0131 constexpr GeometryIdentifier withPassive(Value passive) const {
0132 GeometryIdentifier id = *this;
0133 id.setBits(kApproachMask, passive);
0134 return id;
0135 }
0136
0137
0138
0139
0140 [[nodiscard]]
0141 constexpr GeometryIdentifier withSensitive(Value sensitive) const {
0142 GeometryIdentifier id = *this;
0143 id.setBits(kSensitiveMask, sensitive);
0144 return id;
0145 }
0146
0147
0148
0149
0150 [[nodiscard]]
0151 constexpr GeometryIdentifier withExtra(Value extra) const {
0152 GeometryIdentifier id = *this;
0153 id.setBits(kExtraMask, extra);
0154 return id;
0155 }
0156
0157
0158
0159 static constexpr Value getMaxVolume() { return getMaxValue(kVolumeMask); }
0160
0161
0162
0163 static constexpr Value getMaxBoundary() { return getMaxValue(kBoundaryMask); }
0164
0165
0166
0167 static constexpr Value getMaxLayer() { return getMaxValue(kLayerMask); }
0168
0169
0170
0171 static constexpr Value getMaxApproach() { return getMaxValue(kApproachMask); }
0172
0173
0174
0175 static constexpr Value getMaxSensitive() {
0176 return getMaxValue(kSensitiveMask);
0177 }
0178
0179
0180
0181 static constexpr Value getMaxExtra() { return getMaxValue(kExtraMask); }
0182
0183 private:
0184
0185
0186 static constexpr Value kVolumeMask = 0xff00000000000000;
0187
0188 static constexpr Value kBoundaryMask = 0x00ff000000000000;
0189
0190 static constexpr Value kLayerMask = 0x0000fff000000000;
0191
0192 static constexpr Value kApproachMask = 0x0000000ff0000000;
0193
0194 static constexpr Value kSensitiveMask = 0x000000000fffff00;
0195
0196 static constexpr Value kExtraMask = 0x00000000000000ff;
0197
0198
0199 Value m_value = 0;
0200
0201
0202 static constexpr int extractShift(Value mask) {
0203
0204
0205
0206
0207
0208 return __builtin_ctzll(mask);
0209 }
0210
0211 constexpr static Value getMaxValue(Value mask) {
0212 return mask >> extractShift(mask);
0213 }
0214
0215
0216 constexpr Value getBits(Value mask) const {
0217 return (m_value & mask) >> extractShift(mask);
0218 }
0219
0220 constexpr GeometryIdentifier& setBits(Value mask, Value id) {
0221 if (id > getMaxValue(mask)) {
0222 throw std::invalid_argument(
0223 "Value " + std::to_string(id) + " exceeds maximum value " +
0224 std::to_string(getMaxValue(mask)) + " for this field");
0225 }
0226
0227 m_value = (m_value & ~mask) | ((id << extractShift(mask)) & mask);
0228
0229
0230 return *this;
0231 }
0232
0233 friend constexpr bool operator==(GeometryIdentifier lhs,
0234 GeometryIdentifier rhs) {
0235 return lhs.m_value == rhs.m_value;
0236 }
0237
0238 friend constexpr bool operator<(GeometryIdentifier lhs,
0239 GeometryIdentifier rhs) {
0240 return lhs.m_value < rhs.m_value;
0241 }
0242 };
0243
0244
0245
0246
0247
0248 std::ostream& operator<<(std::ostream& os, GeometryIdentifier id);
0249
0250
0251
0252 struct GeometryIdentifierHook {
0253 virtual ~GeometryIdentifierHook() = default;
0254
0255
0256
0257
0258 virtual Acts::GeometryIdentifier decorateIdentifier(
0259 Acts::GeometryIdentifier identifier, const Acts::Surface& surface) const;
0260 };
0261
0262 }
0263
0264
0265 namespace std {
0266 template <>
0267 struct hash<Acts::GeometryIdentifier> {
0268 auto operator()(Acts::GeometryIdentifier gid) const noexcept {
0269 return std::hash<Acts::GeometryIdentifier::Value>()(gid.value());
0270 }
0271 };
0272 }