File indexing completed on 2025-10-26 07:54:35
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 [[deprecated("Use withVolume() instead")]]
0091 constexpr GeometryIdentifier& setVolume(Value volume) {
0092 setBits(kVolumeMask, volume);
0093 return *this;
0094 }
0095
0096
0097
0098
0099 [[deprecated("Use withBoundary() instead")]]
0100 constexpr GeometryIdentifier& setBoundary(Value boundary) {
0101 setBits(kBoundaryMask, boundary);
0102 return *this;
0103 }
0104
0105
0106
0107
0108 [[deprecated("Use withLayer() instead")]]
0109 constexpr GeometryIdentifier& setLayer(Value layer) {
0110 setBits(kLayerMask, layer);
0111 return *this;
0112 }
0113
0114
0115
0116
0117 [[deprecated("Use withApproach() instead")]]
0118 constexpr GeometryIdentifier& setApproach(Value approach) {
0119 setBits(kApproachMask, approach);
0120 return *this;
0121 }
0122
0123
0124
0125
0126 [[deprecated("Use withPassive() instead")]]
0127 constexpr GeometryIdentifier& setPassive(Value approach) {
0128 setBits(kApproachMask, approach);
0129 return *this;
0130 }
0131
0132
0133
0134
0135 [[deprecated("Use withSensitive() instead")]]
0136 constexpr GeometryIdentifier& setSensitive(Value sensitive) {
0137 setBits(kSensitiveMask, sensitive);
0138 return *this;
0139 }
0140
0141
0142
0143
0144 [[deprecated("Use withExtra() instead")]]
0145 constexpr GeometryIdentifier& setExtra(Value extra) {
0146 return setBits(kExtraMask, extra);
0147 return *this;
0148 }
0149
0150
0151
0152
0153 [[nodiscard]]
0154 constexpr GeometryIdentifier withVolume(Value volume) const {
0155 GeometryIdentifier id = *this;
0156 id.setBits(kVolumeMask, volume);
0157 return id;
0158 }
0159
0160
0161
0162
0163 [[nodiscard]]
0164 constexpr GeometryIdentifier withBoundary(Value boundary) const {
0165 GeometryIdentifier id = *this;
0166 id.setBits(kBoundaryMask, boundary);
0167 return id;
0168 }
0169
0170
0171
0172
0173 [[nodiscard]]
0174 constexpr GeometryIdentifier withLayer(Value layer) const {
0175 GeometryIdentifier id = *this;
0176 id.setBits(kLayerMask, layer);
0177 return id;
0178 }
0179
0180
0181
0182
0183 [[nodiscard]]
0184 constexpr GeometryIdentifier withApproach(Value approach) const {
0185 GeometryIdentifier id = *this;
0186 id.setBits(kApproachMask, approach);
0187 return id;
0188 }
0189
0190
0191
0192
0193 [[nodiscard]]
0194 constexpr GeometryIdentifier withPassive(Value passive) const {
0195 GeometryIdentifier id = *this;
0196 id.setBits(kApproachMask, passive);
0197 return id;
0198 }
0199
0200
0201
0202
0203 [[nodiscard]]
0204 constexpr GeometryIdentifier withSensitive(Value sensitive) const {
0205 GeometryIdentifier id = *this;
0206 id.setBits(kSensitiveMask, sensitive);
0207 return id;
0208 }
0209
0210
0211
0212
0213 [[nodiscard]]
0214 constexpr GeometryIdentifier withExtra(Value extra) const {
0215 GeometryIdentifier id = *this;
0216 id.setBits(kExtraMask, extra);
0217 return id;
0218 }
0219
0220
0221
0222 static constexpr Value getMaxVolume() { return getMaxValue(kVolumeMask); }
0223
0224
0225
0226 static constexpr Value getMaxBoundary() { return getMaxValue(kBoundaryMask); }
0227
0228
0229
0230 static constexpr Value getMaxLayer() { return getMaxValue(kLayerMask); }
0231
0232
0233
0234 static constexpr Value getMaxApproach() { return getMaxValue(kApproachMask); }
0235
0236
0237
0238 static constexpr Value getMaxSensitive() {
0239 return getMaxValue(kSensitiveMask);
0240 }
0241
0242
0243
0244 static constexpr Value getMaxExtra() { return getMaxValue(kExtraMask); }
0245
0246 private:
0247
0248
0249 static constexpr Value kVolumeMask = 0xff00000000000000;
0250
0251 static constexpr Value kBoundaryMask = 0x00ff000000000000;
0252
0253 static constexpr Value kLayerMask = 0x0000fff000000000;
0254
0255 static constexpr Value kApproachMask = 0x0000000ff0000000;
0256
0257 static constexpr Value kSensitiveMask = 0x000000000fffff00;
0258
0259 static constexpr Value kExtraMask = 0x00000000000000ff;
0260
0261
0262 Value m_value = 0;
0263
0264
0265 static constexpr int extractShift(Value mask) {
0266
0267
0268
0269
0270
0271 return __builtin_ctzll(mask);
0272 }
0273
0274 constexpr static Value getMaxValue(Value mask) {
0275 return mask >> extractShift(mask);
0276 }
0277
0278
0279 constexpr Value getBits(Value mask) const {
0280 return (m_value & mask) >> extractShift(mask);
0281 }
0282
0283 constexpr GeometryIdentifier& setBits(Value mask, Value id) {
0284 if (id > getMaxValue(mask)) {
0285 throw std::invalid_argument(
0286 "Value " + std::to_string(id) + " exceeds maximum value " +
0287 std::to_string(getMaxValue(mask)) + " for this field");
0288 }
0289
0290 m_value = (m_value & ~mask) | ((id << extractShift(mask)) & mask);
0291
0292
0293 return *this;
0294 }
0295
0296 friend constexpr bool operator==(GeometryIdentifier lhs,
0297 GeometryIdentifier rhs) {
0298 return lhs.m_value == rhs.m_value;
0299 }
0300
0301 friend constexpr bool operator<(GeometryIdentifier lhs,
0302 GeometryIdentifier rhs) {
0303 return lhs.m_value < rhs.m_value;
0304 }
0305 };
0306
0307
0308
0309
0310
0311 std::ostream& operator<<(std::ostream& os, GeometryIdentifier id);
0312
0313
0314
0315 struct GeometryIdentifierHook {
0316 virtual ~GeometryIdentifierHook() = default;
0317
0318
0319
0320
0321 virtual Acts::GeometryIdentifier decorateIdentifier(
0322 Acts::GeometryIdentifier identifier, const Acts::Surface& surface) const;
0323 };
0324
0325 }
0326
0327
0328 namespace std {
0329 template <>
0330 struct hash<Acts::GeometryIdentifier> {
0331 auto operator()(Acts::GeometryIdentifier gid) const noexcept {
0332 return std::hash<Acts::GeometryIdentifier::Value>()(gid.value());
0333 }
0334 };
0335 }