Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-13 09:38:48

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 "Acts/EventData/SpacePointContainer2.hpp"
0012 #include "Acts/Utilities/TypeTraits.hpp"
0013 
0014 #include <cassert>
0015 
0016 namespace Acts {
0017 
0018 class SeedContainer2;
0019 
0020 /// A proxy class for accessing individual seeds.
0021 template <bool read_only>
0022 class SeedProxy2 {
0023  public:
0024   /// Indicates whether this seed proxy is read-only or if it can be
0025   /// modified
0026   static constexpr bool ReadOnly = read_only;
0027 
0028   /// Type alias for seed index type
0029   using IndexType = SeedIndex2;
0030 
0031   /// Type alias for container type (const if read-only)
0032   using ContainerType = const_if_t<ReadOnly, SeedContainer2>;
0033 
0034   /// Constructs a seed proxy for the given container and index.
0035   /// @param container The container holding the seed.
0036   /// @param index The index of the seed in the container.
0037   SeedProxy2(ContainerType &container, IndexType index) noexcept
0038       : m_container{&container}, m_index{index} {}
0039 
0040   /// Copy construct a seed proxy.
0041   /// @param other The seed proxy to copy.
0042   SeedProxy2(const SeedProxy2 &other) noexcept = default;
0043 
0044   /// Copy construct a mutable seed proxy.
0045   /// @param other The mutable seed proxy to copy.
0046   explicit SeedProxy2(const SeedProxy2<false> &other) noexcept
0047     requires ReadOnly
0048       : m_container(&other.container()), m_index(other.index()) {}
0049 
0050   /// Gets the container holding the seed.
0051   /// @return A reference to the container holding the seed.
0052   SeedContainer2 &container() noexcept
0053     requires ReadOnly
0054   {
0055     return *m_container;
0056   }
0057   /// Gets the container holding the seed.
0058   /// @return A const reference to the container holding the seed.
0059   const SeedContainer2 &container() const noexcept { return *m_container; }
0060   /// Gets the index of the seed in the container.
0061   /// @return The index of the seed in the container.
0062   IndexType index() const noexcept { return m_index; }
0063 
0064   /// Assigns space point indices to the seed at the given index.
0065   /// @param spacePointIndices A span of space point indices to assign to the seed.
0066   /// @throws std::out_of_range if the index is out of range.
0067   /// @throws std::logic_error if space point indices are already assigned to the seed.
0068   void assignSpacePointIndices(
0069       std::span<const SpacePointIndex2> spacePointIndices)
0070     requires(!ReadOnly)
0071   {
0072     m_container->assignSpacePointIndices(m_index, spacePointIndices);
0073   }
0074 
0075   /// Returns the size of the seed, i.e., the number of space points
0076   /// associated with it.
0077   /// @return The number of space points in the seed.
0078   [[nodiscard]] std::size_t size() const noexcept {
0079     return m_container->spacePointIndices(m_index).size();
0080   }
0081   /// Checks if the seed is empty, i.e., has no space points associated with it.
0082   /// @return True if the seed is empty, false otherwise.
0083   [[nodiscard]]
0084   bool empty() const noexcept {
0085     return size() == 0;
0086   }
0087 
0088   /// Mutable access to the space point indices of the seed.
0089   /// @return A mutable span of space point indices associated with the seed.
0090   std::span<SpacePointIndex2> spacePointIndices() noexcept
0091     requires(!ReadOnly)
0092   {
0093     return m_container->spacePointIndices(m_index);
0094   }
0095   /// Mutable access to the quality of the seed.
0096   /// @return A mutable reference to the quality of the seed.
0097   float &quality() noexcept
0098     requires(!ReadOnly)
0099   {
0100     return m_container->quality(m_index);
0101   }
0102   /// Mutable access to the vertex Z coordinate of the seed.
0103   /// @return A mutable reference to the vertex Z coordinate of the seed.
0104   float &vertexZ() noexcept
0105     requires(!ReadOnly)
0106   {
0107     return m_container->vertexZ(m_index);
0108   }
0109 
0110   /// Const access to the space point indices of the seed.
0111   /// @return A span of space point indices associated with the seed.
0112   ///         This span is read-only and cannot be modified.
0113   std::span<const SpacePointIndex2> spacePointIndices() const noexcept {
0114     return m_container->spacePointIndices(m_index);
0115   }
0116   /// Const access to the quality of the seed.
0117   /// @return The quality of the seed.
0118   float quality() const noexcept { return m_container->quality(m_index); }
0119   /// Const access to the vertex Z coordinate of the seed.
0120   /// @return The vertex Z coordinate of the seed.
0121   float vertexZ() const noexcept { return m_container->vertexZ(m_index); }
0122 
0123   class SpacePointIterator {
0124    public:
0125     using value_type = ConstSpacePointProxy2;
0126     using difference_type = std::ptrdiff_t;
0127     using pointer = void;
0128     using reference = void;
0129 
0130     using iterator_category = std::random_access_iterator_tag;
0131     using iterator_concept = std::random_access_iterator_tag;
0132 
0133     SpacePointIterator() = default;
0134     SpacePointIterator(const SpacePointContainer2 &spacePointContainer,
0135                        const SpacePointIndex2 *indexPointer) noexcept
0136         : m_spacePointContainer{&spacePointContainer},
0137           m_indexPointer{indexPointer} {}
0138 
0139     value_type operator*() const noexcept {
0140       return (*m_spacePointContainer)[*m_indexPointer];
0141     }
0142     value_type operator[](difference_type n) const noexcept {
0143       return (*m_spacePointContainer)[m_indexPointer[n]];
0144     }
0145 
0146     constexpr SpacePointIterator &operator++() noexcept {
0147       ++m_indexPointer;
0148       return *this;
0149     }
0150     constexpr SpacePointIterator operator++(int) noexcept {
0151       auto tmp = *this;
0152       ++(*this);
0153       return tmp;
0154     }
0155     constexpr SpacePointIterator &operator--() noexcept {
0156       --m_indexPointer;
0157       return *this;
0158     }
0159     constexpr SpacePointIterator operator--(int) noexcept {
0160       auto tmp = *this;
0161       --(*this);
0162       return tmp;
0163     }
0164 
0165     constexpr SpacePointIterator &operator+=(difference_type n) noexcept {
0166       m_indexPointer += n;
0167       return *this;
0168     }
0169     constexpr SpacePointIterator &operator-=(difference_type n) noexcept {
0170       m_indexPointer -= n;
0171       return *this;
0172     }
0173 
0174    private:
0175     const SpacePointContainer2 *m_spacePointContainer{nullptr};
0176     const SpacePointIndex2 *m_indexPointer{nullptr};
0177 
0178     friend constexpr SpacePointIterator operator+(SpacePointIterator it,
0179                                                   difference_type n) noexcept {
0180       return it += n;
0181     }
0182 
0183     friend constexpr SpacePointIterator operator+(
0184         difference_type n, SpacePointIterator it) noexcept {
0185       return it += n;
0186     }
0187 
0188     friend constexpr SpacePointIterator operator-(SpacePointIterator it,
0189                                                   difference_type n) noexcept {
0190       return it -= n;
0191     }
0192 
0193     friend constexpr difference_type operator-(
0194         const SpacePointIterator &lhs, const SpacePointIterator &rhs) noexcept {
0195       return lhs.m_indexPointer - rhs.m_indexPointer;
0196     }
0197 
0198     friend constexpr auto operator<=>(const SpacePointIterator &a,
0199                                       const SpacePointIterator &b) noexcept {
0200       return a.m_indexPointer <=> b.m_indexPointer;
0201     }
0202     friend constexpr bool operator==(const SpacePointIterator &a,
0203                                      const SpacePointIterator &b) noexcept {
0204       return a.m_indexPointer == b.m_indexPointer;
0205     }
0206   };
0207 
0208   class SpacePointRange {
0209    public:
0210     SpacePointRange(
0211         const SpacePointContainer2 &spacePointContainer,
0212         std::span<const SpacePointIndex2> spacePointIndices) noexcept
0213         : m_spacePointContainer{&spacePointContainer},
0214           m_spacePointIndices{spacePointIndices} {}
0215 
0216     std::size_t size() const noexcept { return m_spacePointIndices.size(); }
0217     bool empty() const noexcept { return size() == 0; }
0218 
0219     ConstSpacePointProxy2 operator[](std::size_t index) const noexcept {
0220       return (*m_spacePointContainer)[m_spacePointIndices[index]];
0221     }
0222 
0223     SpacePointIterator begin() const noexcept {
0224       return SpacePointIterator(*m_spacePointContainer,
0225                                 m_spacePointIndices.data());
0226     }
0227     SpacePointIterator end() const noexcept {
0228       return SpacePointIterator(
0229           *m_spacePointContainer,
0230           m_spacePointIndices.data() + m_spacePointIndices.size());
0231     }
0232 
0233    private:
0234     const SpacePointContainer2 *m_spacePointContainer{nullptr};
0235     std::span<const SpacePointIndex2> m_spacePointIndices;
0236   };
0237 
0238   /// Get the space points associated with this seed.
0239   /// @param spacePointContainer Container holding all space points
0240   /// @return Range of space points for this seed
0241   SpacePointRange spacePoints(
0242       const SpacePointContainer2 &spacePointContainer) const noexcept {
0243     return SpacePointRange(spacePointContainer,
0244                            m_container->spacePointIndices(m_index));
0245   }
0246 
0247  private:
0248   ContainerType *m_container{nullptr};
0249   IndexType m_index{0};
0250 };
0251 
0252 }  // namespace Acts