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