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/Types.hpp"
0012 #include "Acts/Utilities/TypeTraits.hpp"
0013 
0014 #include <cassert>
0015 #include <span>
0016 #include <vector>
0017 
0018 namespace Acts::Experimental {
0019 
0020 template <bool read_only>
0021 class SeedProxy2;
0022 
0023 using MutableSeedProxy2 = SeedProxy2<false>;
0024 using ConstSeedProxy2 = SeedProxy2<true>;
0025 
0026 /// A container of seeds. Individual seeds are modeled as a sequence of N space
0027 /// points which are addressed via an index into the space point container.
0028 /// Individual seeds are addressed via index. A proxy object simplifies the
0029 /// handling.
0030 class SeedContainer2 {
0031  public:
0032   using IndexType = SeedIndex2;
0033   using MutableProxyType = MutableSeedProxy2;
0034   using ConstProxyType = ConstSeedProxy2;
0035 
0036   /// Returns the size of the seed container, i.e., the number of seeds
0037   /// contained in it.
0038   /// @return The number of seeds in the container.
0039   std::size_t size() const noexcept { return m_sizes.size(); }
0040   /// Checks if the seed container is empty.
0041   /// @return True if the container is empty, false otherwise.
0042   bool empty() const noexcept { return size() == 0; }
0043 
0044   /// Reserves space for the given number of seeds.
0045   /// @param size The number of seeds to reserve space for.
0046   /// @param averageSpacePoints The average number of space points per seed.
0047   void reserve(std::size_t size, float averageSpacePoints = 3) noexcept;
0048 
0049   /// Clears the seed container, removing all seeds and space points.
0050   void clear() noexcept;
0051 
0052   /// Creates a new seed with the given space points.
0053   /// @param spacePoints The space points that make up the seed.
0054   /// @return A mutable proxy to the newly created seed.
0055   MutableProxyType createSeed(
0056       std::span<const SpacePointIndex2> spacePoints) noexcept;
0057 
0058   /// Returns a mutable proxy to the seed at the given index.
0059   /// If the index is out of range, an exception is thrown.
0060   /// @param index The index of the seed to access.
0061   /// @return A mutable proxy to the seed at the given index.
0062   /// @throws std::out_of_range if the index is out of range.
0063   MutableProxyType at(IndexType index);
0064   /// Returns a const proxy to the seed at the given index.
0065   /// If the index is out of range, an exception is thrown.
0066   /// @param index The index of the seed to access.
0067   /// @return A const proxy to the seed at the given index.
0068   /// @throws std::out_of_range if the index is out of range.
0069   ConstProxyType at(IndexType index) const;
0070 
0071   /// Mutable access to the space point indices of the seed at the given index.
0072   /// @param index The index of the seed.
0073   /// @return A span of space point indices associated with the seed at the given
0074   ///         index.
0075   std::span<SpacePointIndex2> spacePointIndices(IndexType index) noexcept {
0076     assert(index < m_sizes.size() && "Index out of bounds");
0077     assert(index < m_spacePointOffsets.size() && "Index out of bounds");
0078     return std::span<SpacePointIndex2>(
0079         m_spacePoints.data() + m_spacePointOffsets[index],
0080         m_spacePoints.data() + m_spacePointOffsets[index] + m_sizes[index]);
0081   }
0082 
0083   /// Mutable access to the quality of the seed at the given index.
0084   /// @param index The index of the seed.
0085   /// @return A mutable reference to the quality of the seed at the given index.
0086   float &quality(IndexType index) noexcept {
0087     assert(index < m_qualities.size() && "Index out of bounds");
0088     return m_qualities[index];
0089   }
0090   /// Mutable access to the vertex Z coordinate of the seed at the given index.
0091   /// @param index The index of the seed.
0092   /// @return A mutable reference to the vertex Z coordinate of the seed at the
0093   float &vertexZ(IndexType index) noexcept {
0094     assert(index < m_vertexZs.size() && "Index out of bounds");
0095     return m_vertexZs[index];
0096   }
0097 
0098   /// Const access to the space point indices of the seed at the given index.
0099   /// @param index The index of the seed.
0100   /// @return A span of space point indices associated with the seed at the given
0101   ///         index.
0102   std::span<const SpacePointIndex2> spacePointIndices(
0103       IndexType index) const noexcept {
0104     assert(index < m_sizes.size() && "Index out of bounds");
0105     assert(index < m_spacePointOffsets.size() && "Index out of bounds");
0106     return std::span<const SpacePointIndex2>(
0107         m_spacePoints.data() + m_spacePointOffsets[index],
0108         m_spacePoints.data() + m_spacePointOffsets[index] + m_sizes[index]);
0109   }
0110 
0111   /// Const access to the quality of the seed at the given index.
0112   /// @param index The index of the seed.
0113   /// @return A const reference to the quality of the seed at the given index.
0114   float quality(IndexType index) const noexcept {
0115     assert(index < m_qualities.size() && "Index out of bounds");
0116     return m_qualities[index];
0117   }
0118   /// Const access to the vertex Z coordinate of the seed at the given index.
0119   /// @param index The index of the seed.
0120   /// @return A const reference to the vertex Z coordinate of the seed at the
0121   ///         given index.
0122   float vertexZ(IndexType index) const noexcept {
0123     assert(index < m_vertexZs.size() && "Index out of bounds");
0124     return m_vertexZs[index];
0125   }
0126 
0127   template <bool read_only>
0128   class SeedIterator {
0129    public:
0130     static constexpr bool ReadOnly = read_only;
0131 
0132     using ContainerType = const_if_t<ReadOnly, SeedContainer2>;
0133 
0134     using iterator_category = std::forward_iterator_tag;
0135     using value_type = SeedProxy2<ReadOnly>;
0136     using difference_type = std::ptrdiff_t;
0137 
0138     SeedIterator() = default;
0139     SeedIterator(ContainerType &container, IndexType index)
0140         : m_container(&container), m_index(index) {}
0141 
0142     SeedIterator &operator++() {
0143       ++m_index;
0144       return *this;
0145     }
0146     SeedIterator operator++(int) {
0147       SeedIterator tmp(*this);
0148       ++(*this);
0149       return tmp;
0150     }
0151 
0152     value_type operator*() const { return value_type(*m_container, m_index); }
0153 
0154    private:
0155     ContainerType *m_container{};
0156     IndexType m_index{};
0157 
0158     friend bool operator==(const SeedIterator &a, const SeedIterator &b) {
0159       return a.m_index == b.m_index && a.m_container == b.m_container;
0160     }
0161   };
0162   using iterator = SeedIterator<false>;
0163   using const_iterator = SeedIterator<true>;
0164 
0165   iterator begin() noexcept { return iterator(*this, 0); }
0166   iterator end() noexcept { return iterator(*this, size()); }
0167 
0168   const_iterator begin() const noexcept { return const_iterator(*this, 0); }
0169   const_iterator end() const noexcept { return const_iterator(*this, size()); }
0170 
0171  private:
0172   std::vector<std::uint8_t> m_sizes;
0173   std::vector<std::size_t> m_spacePointOffsets;
0174   std::vector<float> m_qualities;
0175   std::vector<float> m_vertexZs;
0176   std::vector<SpacePointIndex2> m_spacePoints;
0177 };
0178 
0179 }  // namespace Acts::Experimental
0180 
0181 #include "Acts/EventData/SeedContainer2.ipp"