Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:14:59

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <cstdint>
0012 #include <iosfwd>
0013 
0014 namespace Acts {
0015 
0016 /// Reimplementation of GeometryIdentifier du to the fact that the default Root
0017 /// C++ version is too old Identifier for geometry nodes.
0018 ///
0019 /// Each identifier can be split info the following components:
0020 ///
0021 /// - Volumes                 - uses counting given by TrackingGeometry
0022 /// - (Boundary)  Surfaces    - counts through boundary surfaces
0023 /// - (Layer)     Surfaces    - counts confined layers
0024 /// - (Approach)  Surfaces    - counts approach surfaces
0025 /// - (Sensitive) Surfaces    - counts through sensitive surfaces
0026 ///
0027 class GeometryIdentifier {
0028  public:
0029   using Value = std::uint64_t;
0030 
0031   /// Construct from an already encoded value.
0032   constexpr GeometryIdentifier(Value encoded) : m_value(encoded) {}
0033   /// Construct default GeometryIdentifier with all values set to zero.
0034   GeometryIdentifier() = default;
0035   GeometryIdentifier(GeometryIdentifier&&) = default;
0036   GeometryIdentifier(const GeometryIdentifier&) = default;
0037   ~GeometryIdentifier() = default;
0038   GeometryIdentifier& operator=(GeometryIdentifier&&) = default;
0039   GeometryIdentifier& operator=(const GeometryIdentifier&) = default;
0040 
0041   /// Return the encoded value.
0042   constexpr Value value() const { return m_value; }
0043 
0044   /// Return the volume identifier.
0045   constexpr Value volume() const { return getBits(volume_mask); }
0046   /// Return the boundary identifier.
0047   constexpr Value boundary() const { return getBits(boundary_mask); }
0048   /// Return the layer identifier.
0049   constexpr Value layer() const { return getBits(layer_mask); }
0050   /// Return the approach identifier.
0051   constexpr Value approach() const { return getBits(approach_mask); }
0052   /// Return the sensitive identifier.
0053   constexpr Value sensitive() const { return getBits(sensitive_mask); }
0054 
0055  private:
0056   // clang-format off
0057   static constexpr Value volume_mask    = 0xff00000000000000; // 255 volumes
0058   static constexpr Value boundary_mask  = 0x00ff000000000000; // 255 boundaries
0059   static constexpr Value layer_mask     = 0x0000fff000000000; // 4095 layers
0060   static constexpr Value approach_mask  = 0x0000000ff0000000; // 255 approach surfaces
0061   static constexpr Value sensitive_mask = 0x000000000fffffff; // (2^28)-1 sensitive surfaces
0062   // clang-format on
0063 
0064   Value m_value = 0;
0065 
0066   /// Extract the bit shift necessary to access the masked values.
0067   static constexpr int extractShift(Value mask) {
0068     // use compiler builtin to extract the number of trailing bits from the
0069     // mask. the builtin should be available on all supported compilers.
0070     // need unsigned long long version (...ll) to ensure std::uint64_t
0071     // compatibility.
0072     // WARNING undefined behaviour for mask == 0 which we should not have.
0073     return __builtin_ctzll(mask);
0074   }
0075   /// Extract the masked bits from the encoded value.
0076   constexpr Value getBits(Value mask) const {
0077     return (m_value & mask) >> extractShift(mask);
0078   }
0079 
0080   friend constexpr bool operator==(GeometryIdentifier lhs,
0081                                    GeometryIdentifier rhs) {
0082     return lhs.m_value == rhs.m_value;
0083   }
0084   friend constexpr bool operator<(GeometryIdentifier lhs,
0085                                   GeometryIdentifier rhs) {
0086     return lhs.m_value < rhs.m_value;
0087   }
0088 };
0089 
0090 std::ostream& operator<<(std::ostream& os, GeometryIdentifier id);
0091 
0092 }  // namespace Acts