Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:51:25

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::Experimental {
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   using IndexType = SeedIndex2;
0029 
0030   using ContainerType = const_if_t<ReadOnly, SeedContainer2>;
0031 
0032   /// Constructs a seed proxy for the given container and index.
0033   /// @param container The container holding the seed.
0034   /// @param index The index of the seed in the container.
0035   SeedProxy2(ContainerType &container, IndexType index) noexcept
0036       : m_container{&container}, m_index{index} {}
0037 
0038   /// Copy construct a seed proxy.
0039   /// @param other The seed proxy to copy.
0040   SeedProxy2(const SeedProxy2 &other) noexcept = default;
0041 
0042   /// Copy construct a mutable seed proxy.
0043   /// @param other The mutable seed proxy to copy.
0044   explicit SeedProxy2(const SeedProxy2<false> &other) noexcept
0045     requires ReadOnly
0046       : m_container(&other.container()), m_index(other.index()) {}
0047 
0048   /// Gets the container holding the seed.
0049   /// @return A reference to the container holding the seed.
0050   SeedContainer2 &container() noexcept
0051     requires ReadOnly
0052   {
0053     return *m_container;
0054   }
0055   /// Gets the container holding the seed.
0056   /// @return A const reference to the container holding the seed.
0057   const SeedContainer2 &container() const noexcept { return *m_container; }
0058   /// Gets the index of the seed in the container.
0059   /// @return The index of the seed in the container.
0060   IndexType index() const noexcept { return m_index; }
0061 
0062   /// Returns the size of the seed, i.e., the number of space points
0063   /// associated with it.
0064   /// @return The number of space points in the seed.
0065   [[nodiscard]] std::size_t size() const noexcept {
0066     return m_container->spacePointIndices(m_index).size();
0067   }
0068   /// Checks if the seed is empty, i.e., has no space points associated with it.
0069   /// @return True if the seed is empty, false otherwise.
0070   [[nodiscard]]
0071   bool empty() const noexcept {
0072     return size() == 0;
0073   }
0074 
0075   /// Mutable access to the space point indices of the seed.
0076   /// @return A mutable span of space point indices associated with the seed.
0077   std::span<SpacePointIndex2> spacePointIndices() noexcept
0078     requires(!ReadOnly)
0079   {
0080     return m_container->spacePointIndices(m_index);
0081   }
0082   /// Mutable access to the quality of the seed.
0083   /// @return A mutable reference to the quality of the seed.
0084   float &quality() noexcept
0085     requires(!ReadOnly)
0086   {
0087     return m_container->quality(m_index);
0088   }
0089   /// Mutable access to the vertex Z coordinate of the seed.
0090   /// @return A mutable reference to the vertex Z coordinate of the seed.
0091   float &vertexZ() noexcept
0092     requires(!ReadOnly)
0093   {
0094     return m_container->vertexZ(m_index);
0095   }
0096 
0097   /// Const access to the space point indices of the seed.
0098   /// @return A span of space point indices associated with the seed.
0099   ///         This span is read-only and cannot be modified.
0100   std::span<const SpacePointIndex2> spacePointIndices() const noexcept {
0101     return m_container->spacePointIndices(m_index);
0102   }
0103   /// Const access to the quality of the seed.
0104   /// @return The quality of the seed.
0105   float quality() const noexcept { return m_container->quality(m_index); }
0106   /// Const access to the vertex Z coordinate of the seed.
0107   /// @return The vertex Z coordinate of the seed.
0108   float vertexZ() const noexcept { return m_container->vertexZ(m_index); }
0109 
0110   class SpacePointIterator {
0111    public:
0112     using iterator_category = std::forward_iterator_tag;
0113     using value_type = ConstSpacePointProxy2;
0114     using difference_type = std::ptrdiff_t;
0115 
0116     SpacePointIterator() = default;
0117     SpacePointIterator(const SpacePointContainer2 &spacePointContainer,
0118                        const SpacePointIndex2 *indexPointer) noexcept
0119         : m_spacePointContainer{&spacePointContainer},
0120           m_indexPointer{indexPointer} {}
0121 
0122     SpacePointIterator &operator++() noexcept {
0123       ++m_indexPointer;
0124       return *this;
0125     }
0126 
0127     SpacePointIterator operator++(int) noexcept {
0128       SpacePointIterator tmp = *this;
0129       ++(*this);
0130       return tmp;
0131     }
0132 
0133     value_type operator*() const noexcept {
0134       return (*m_spacePointContainer)[*m_indexPointer];
0135     }
0136 
0137    private:
0138     const SpacePointContainer2 *m_spacePointContainer{nullptr};
0139     const SpacePointIndex2 *m_indexPointer{nullptr};
0140 
0141     friend bool operator==(const SpacePointIterator &a,
0142                            const SpacePointIterator &b) noexcept {
0143       return a.m_indexPointer == b.m_indexPointer;
0144     }
0145   };
0146 
0147   class SpacePointRange {
0148    public:
0149     SpacePointRange(
0150         const SpacePointContainer2 &spacePointContainer,
0151         std::span<const SpacePointIndex2> spacePointIndices) noexcept
0152         : m_spacePointContainer{&spacePointContainer},
0153           m_spacePointIndices{spacePointIndices} {}
0154 
0155     std::size_t size() const noexcept { return m_spacePointIndices.size(); }
0156     bool empty() const noexcept { return size() == 0; }
0157 
0158     ConstSpacePointProxy2 operator[](std::size_t index) const noexcept {
0159       return (*m_spacePointContainer)[m_spacePointIndices[index]];
0160     }
0161 
0162     SpacePointIterator begin() const noexcept {
0163       return SpacePointIterator(*m_spacePointContainer,
0164                                 m_spacePointIndices.data());
0165     }
0166     SpacePointIterator end() const noexcept {
0167       return SpacePointIterator(
0168           *m_spacePointContainer,
0169           m_spacePointIndices.data() + m_spacePointIndices.size());
0170     }
0171 
0172    private:
0173     const SpacePointContainer2 *m_spacePointContainer{nullptr};
0174     std::span<const SpacePointIndex2> m_spacePointIndices;
0175   };
0176 
0177   SpacePointRange spacePoints(
0178       const SpacePointContainer2 &spacePointContainer) const noexcept {
0179     return SpacePointRange(spacePointContainer,
0180                            m_container->spacePointIndices(m_index));
0181   }
0182 
0183  private:
0184   ContainerType *m_container{nullptr};
0185   IndexType m_index{0};
0186 };
0187 
0188 }  // namespace Acts::Experimental