File indexing completed on 2025-01-18 09:10:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <cstdint>
0012 #include <functional>
0013 #include <iosfwd>
0014
0015 namespace Acts {
0016
0017 class Surface;
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 class GeometryIdentifier {
0031 public:
0032 using Value = std::uint64_t;
0033
0034
0035 constexpr GeometryIdentifier(Value encoded) : m_value(encoded) {}
0036
0037 GeometryIdentifier() = default;
0038 GeometryIdentifier(GeometryIdentifier&&) = default;
0039 GeometryIdentifier(const GeometryIdentifier&) = default;
0040 ~GeometryIdentifier() = default;
0041 GeometryIdentifier& operator=(GeometryIdentifier&&) = default;
0042 GeometryIdentifier& operator=(const GeometryIdentifier&) = default;
0043
0044
0045 constexpr Value value() const { return m_value; }
0046
0047
0048 constexpr Value volume() const { return getBits(kVolumeMask); }
0049
0050 constexpr Value boundary() const { return getBits(kBoundaryMask); }
0051
0052 constexpr Value layer() const { return getBits(kLayerMask); }
0053
0054 constexpr Value approach() const { return getBits(kApproachMask); }
0055
0056 constexpr Value passive() const { return getBits(kApproachMask); }
0057
0058 constexpr Value sensitive() const { return getBits(kSensitiveMask); }
0059
0060
0061
0062 constexpr Value extra() const { return getBits(kExtraMask); }
0063
0064
0065 constexpr GeometryIdentifier& setVolume(Value volume) {
0066 return setBits(kVolumeMask, volume);
0067 }
0068
0069 constexpr GeometryIdentifier& setBoundary(Value boundary) {
0070 return setBits(kBoundaryMask, boundary);
0071 }
0072
0073 constexpr GeometryIdentifier& setLayer(Value layer) {
0074 return setBits(kLayerMask, layer);
0075 }
0076
0077 constexpr GeometryIdentifier& setApproach(Value approach) {
0078 return setBits(kApproachMask, approach);
0079 }
0080
0081 constexpr GeometryIdentifier& setPassive(Value approach) {
0082 return setBits(kApproachMask, approach);
0083 }
0084
0085 constexpr GeometryIdentifier& setSensitive(Value sensitive) {
0086 return setBits(kSensitiveMask, sensitive);
0087 }
0088
0089 constexpr GeometryIdentifier& setExtra(Value extra) {
0090 return setBits(kExtraMask, extra);
0091 }
0092
0093 private:
0094
0095
0096 static constexpr Value kVolumeMask = 0xff00000000000000;
0097
0098 static constexpr Value kBoundaryMask = 0x00ff000000000000;
0099
0100 static constexpr Value kLayerMask = 0x0000fff000000000;
0101
0102 static constexpr Value kApproachMask = 0x0000000ff0000000;
0103 static constexpr Value kPassiveMask = kApproachMask;
0104
0105 static constexpr Value kSensitiveMask = 0x000000000fffff00;
0106
0107 static constexpr Value kExtraMask = 0x00000000000000ff;
0108
0109
0110 Value m_value = 0;
0111
0112
0113 static constexpr int extractShift(Value mask) {
0114
0115
0116
0117
0118
0119 return __builtin_ctzll(mask);
0120 }
0121
0122 constexpr Value getBits(Value mask) const {
0123 return (m_value & mask) >> extractShift(mask);
0124 }
0125
0126 constexpr GeometryIdentifier& setBits(Value mask, Value id) {
0127 m_value = (m_value & ~mask) | ((id << extractShift(mask)) & mask);
0128
0129 return *this;
0130 }
0131
0132 friend constexpr bool operator==(GeometryIdentifier lhs,
0133 GeometryIdentifier rhs) {
0134 return lhs.m_value == rhs.m_value;
0135 }
0136
0137 friend constexpr bool operator<(GeometryIdentifier lhs,
0138 GeometryIdentifier rhs) {
0139 return lhs.m_value < rhs.m_value;
0140 }
0141 };
0142
0143 std::ostream& operator<<(std::ostream& os, GeometryIdentifier id);
0144
0145
0146
0147 struct GeometryIdentifierHook {
0148 virtual ~GeometryIdentifierHook() = default;
0149 virtual Acts::GeometryIdentifier decorateIdentifier(
0150 Acts::GeometryIdentifier identifier, const Acts::Surface& surface) const;
0151 };
0152
0153 }
0154
0155
0156
0157 namespace std {
0158 template <>
0159 struct hash<Acts::GeometryIdentifier> {
0160 auto operator()(Acts::GeometryIdentifier gid) const noexcept {
0161 return std::hash<Acts::GeometryIdentifier::Value>()(gid.value());
0162 }
0163 };
0164 }