Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:07:27

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/EventData/Types.hpp"
0013 #include "Acts/Utilities/detail/ContainerIterator.hpp"
0014 
0015 #include <cassert>
0016 #include <span>
0017 #include <vector>
0018 
0019 namespace Acts {
0020 
0021 template <bool read_only>
0022 class SeedProxy2;
0023 
0024 using MutableSeedProxy2 = SeedProxy2<false>;
0025 using ConstSeedProxy2 = SeedProxy2<true>;
0026 
0027 /// A container of seeds. Individual seeds are modeled as a sequence of N space
0028 /// points which are addressed via an index into the space point container.
0029 /// Individual seeds are addressed via index. A proxy object simplifies the
0030 /// handling.
0031 class SeedContainer2 {
0032  public:
0033   /// Type alias for seed index type
0034   using Index = SeedIndex2;
0035   /// Type alias for mutable seed proxy
0036   using MutableProxy = MutableSeedProxy2;
0037   /// Type alias for const seed proxy
0038   using ConstProxy = ConstSeedProxy2;
0039 
0040   /// Constructs and empty seed container.
0041   SeedContainer2() noexcept;
0042 
0043   /// Constructs a copy of the given seed container.
0044   /// @param other The seed container to copy.
0045   SeedContainer2(const SeedContainer2 &other) noexcept;
0046 
0047   /// Move constructs a seed container.
0048   /// @param other The seed container to move.
0049   SeedContainer2(SeedContainer2 &&other) noexcept;
0050 
0051   /// Detructs the seed container.
0052   ~SeedContainer2() noexcept = default;
0053 
0054   /// Assignment operator for copying a seed container.
0055   /// @param other The seed container to copy.
0056   /// @return A reference to this seed container.
0057   SeedContainer2 &operator=(const SeedContainer2 &other) noexcept;
0058 
0059   /// Move assignment operator for a seed container.
0060   /// @param other The seed container to move.
0061   /// @return A reference to this seed container.
0062   SeedContainer2 &operator=(SeedContainer2 &&other) noexcept;
0063 
0064   /// Returns the size of the seed container, i.e., the number of seeds
0065   /// contained in it.
0066   /// @return The number of seeds in the container.
0067   std::size_t size() const noexcept { return m_size; }
0068 
0069   /// Checks if the seed container is empty.
0070   /// @return True if the container is empty, false otherwise.
0071   bool empty() const noexcept { return size() == 0; }
0072 
0073   /// Reserves space for the given number of seeds.
0074   /// @param size The number of seeds to reserve space for.
0075   /// @param averageSpacePoints The average number of space points per seed.
0076   void reserve(std::size_t size, float averageSpacePoints = 3) noexcept;
0077 
0078   /// Clears the seed container, removing all seeds and space points.
0079   void clear() noexcept;
0080 
0081   /// Assigns the mutable space point container to be used by this seed
0082   /// container by value. This can be used to either copy or move-assign a
0083   /// container. The ownership of the space point container is transferred to
0084   /// this seed container.
0085   /// @param spacePointContainer The space point container to assign.
0086   void assignSpacePointContainer(
0087       SpacePointContainer2 spacePointContainer) noexcept;
0088 
0089   /// Assigns the mutable space point container to be used by this seed
0090   /// container by reference. Note that the ownership of the space point
0091   /// container is not transferred and the user must ensure that the space point
0092   /// container remains valid for the lifetime of this seed container.
0093   /// @param spacePointContainer The space point container to assign.
0094   void assignSpacePointContainer(
0095       SpacePointContainer2 &spacePointContainer) noexcept;
0096 
0097   /// Assigns the const space point container to be used by this seed container
0098   /// by const reference. Note that the ownership of the space point container
0099   /// is not transferred and the user must ensure that the space point container
0100   /// remains valid for the lifetime of this seed container.
0101   /// @param spacePointContainer The space point container to assign.
0102   void assignSpacePointContainer(
0103       const SpacePointContainer2 &spacePointContainer) noexcept;
0104 
0105   /// Assigns the mutable space point container to be used by this seed
0106   /// container by shared pointer. The ownership of the space point container is
0107   /// shared between this seed container and the user.
0108   /// @param spacePointContainer The space point container to assign.
0109   void assignSpacePointContainer(const std::shared_ptr<SpacePointContainer2>
0110                                      &spacePointContainer) noexcept;
0111 
0112   /// Assigns the const space point container to be used by this seed container
0113   /// by shared pointer. The ownership of the space point container is shared
0114   /// between this seed container and the user.
0115   /// @param spacePointContainer The space point container to assign.
0116   void assignSpacePointContainer(
0117       const std::shared_ptr<const SpacePointContainer2>
0118           &spacePointContainer) noexcept;
0119 
0120   /// Checks if a space point container has been assigned to this seed
0121   /// container.
0122   /// @return True if a space point container has been assigned.
0123   bool hasSpacePointContainer() const noexcept;
0124 
0125   /// Checks if a mutable space point container has been assigned to this seed
0126   /// container.
0127   /// @return True if a mutable space point container has been assigned.
0128   bool hasMutableSpacePointContainer() const noexcept;
0129 
0130   /// Returns a const reference to the assigned space point container.
0131   /// @return A const reference to the assigned space point container.
0132   /// @throws std::logic_error if no space point container has been assigned.
0133   const SpacePointContainer2 &spacePointContainer() const;
0134 
0135   /// Returns a mutable reference to the assigned space point container.
0136   /// @return A mutable reference to the assigned space point container.
0137   /// @throws std::logic_error if no mutable space point container has been assigned.
0138   SpacePointContainer2 &mutableSpacePointContainer();
0139 
0140   /// Creates a new seed.
0141   /// @return A mutable proxy to the newly created seed.
0142   MutableProxy createSeed() noexcept;
0143 
0144   /// Returns a mutable proxy to the seed at the given index.
0145   /// If the index is out of range, an exception is thrown.
0146   /// @param index The index of the seed to access.
0147   /// @return A mutable proxy to the seed at the given index.
0148   /// @throws std::out_of_range if the index is out of range.
0149   MutableProxy at(Index index);
0150 
0151   /// Returns a const proxy to the seed at the given index.
0152   /// If the index is out of range, an exception is thrown.
0153   /// @param index The index of the seed to access.
0154   /// @return A const proxy to the seed at the given index.
0155   /// @throws std::out_of_range if the index is out of range.
0156   ConstProxy at(Index index) const;
0157 
0158   /// Returns a mutable proxy to the seed at the given index.
0159   /// @param index The index of the seed to access.
0160   /// @return A mutable proxy to the seed at the given index.
0161   MutableProxy operator[](Index index) noexcept;
0162 
0163   /// Returns a const proxy to the seed at the given index.
0164   /// @param index The index of the seed to access.
0165   /// @return A const proxy to the seed at the given index.
0166   ConstProxy operator[](Index index) const noexcept;
0167 
0168   /// Assigns space point indices to the seed at the given index.
0169   /// @param index The index of the seed to assign space point indices to.
0170   /// @param spacePointIndices A span of space point indices to assign to the seed.
0171   /// @throws std::out_of_range if the index is out of range.
0172   /// @throws std::logic_error if space point indices are already assigned to the seed.
0173   void assignSpacePointIndices(
0174       Index index, std::span<const SpacePointIndex2> spacePointIndices);
0175 
0176   /// Mutable access to the space point indices of the seed at the given index.
0177   /// @param index The index of the seed.
0178   /// @return A span of space point indices associated with the seed at the given
0179   ///         index.
0180   std::span<SpacePointIndex2> spacePointIndices(Index index) noexcept {
0181     assert(index < m_spacePointCounts.size() && "Index out of bounds");
0182     assert(index < m_spacePointOffsets.size() && "Index out of bounds");
0183     return std::span<SpacePointIndex2>(
0184         m_spacePoints.data() + m_spacePointOffsets[index],
0185         m_spacePoints.data() + m_spacePointOffsets[index] +
0186             m_spacePointCounts[index]);
0187   }
0188 
0189   /// Mutable access to the quality of the seed at the given index.
0190   /// @param index The index of the seed.
0191   /// @return A mutable reference to the quality of the seed at the given index.
0192   float &quality(Index index) noexcept {
0193     assert(index < m_qualities.size() && "Index out of bounds");
0194     return m_qualities[index];
0195   }
0196 
0197   /// Mutable access to the vertex Z coordinate of the seed at the given index.
0198   /// @param index The index of the seed.
0199   /// @return A mutable reference to the vertex Z coordinate of the seed at the
0200   float &vertexZ(Index index) noexcept {
0201     assert(index < m_vertexZs.size() && "Index out of bounds");
0202     return m_vertexZs[index];
0203   }
0204 
0205   /// Const access to the space point indices of the seed at the given index.
0206   /// @param index The index of the seed.
0207   /// @return A span of space point indices associated with the seed at the given
0208   ///         index.
0209   std::span<const SpacePointIndex2> spacePointIndices(
0210       Index index) const noexcept {
0211     assert(index < m_spacePointCounts.size() && "Index out of bounds");
0212     assert(index < m_spacePointOffsets.size() && "Index out of bounds");
0213     return std::span<const SpacePointIndex2>(
0214         m_spacePoints.data() + m_spacePointOffsets[index],
0215         m_spacePoints.data() + m_spacePointOffsets[index] +
0216             m_spacePointCounts[index]);
0217   }
0218 
0219   /// Const access to the quality of the seed at the given index.
0220   /// @param index The index of the seed.
0221   /// @return A const reference to the quality of the seed at the given index.
0222   float quality(Index index) const noexcept {
0223     assert(index < m_qualities.size() && "Index out of bounds");
0224     return m_qualities[index];
0225   }
0226 
0227   /// Const access to the vertex Z coordinate of the seed at the given index.
0228   /// @param index The index of the seed.
0229   /// @return A const reference to the vertex Z coordinate of the seed at the
0230   ///         given index.
0231   float vertexZ(Index index) const noexcept {
0232     assert(index < m_vertexZs.size() && "Index out of bounds");
0233     return m_vertexZs[index];
0234   }
0235 
0236   /// Type alias for iterator template over seed container
0237   template <bool read_only>
0238   using Iterator = detail::ContainerIterator<
0239       SeedContainer2,
0240       std::conditional_t<read_only, ConstSeedProxy2, MutableSeedProxy2>, Index,
0241       read_only>;
0242 
0243   /// Type alias for mutable iterator over seeds
0244   using iterator = Iterator<false>;
0245   /// Type alias for const iterator over seeds
0246   using const_iterator = Iterator<true>;
0247 
0248   /// Get mutable iterator to the beginning of seeds
0249   /// @return Mutable iterator to the first seed
0250   iterator begin() noexcept { return iterator(*this, 0); }
0251   /// Get mutable iterator to the end of seeds
0252   /// @return Mutable iterator past the last seed
0253   iterator end() noexcept { return iterator(*this, size()); }
0254 
0255   /// Get const iterator to the beginning of seeds
0256   /// @return Const iterator to the first seed
0257   const_iterator begin() const noexcept { return const_iterator(*this, 0); }
0258   /// Get const iterator to the end of seeds
0259   /// @return Const iterator past the last seed
0260   const_iterator end() const noexcept { return const_iterator(*this, size()); }
0261 
0262  private:
0263   std::uint32_t m_size{0};
0264   std::vector<std::size_t> m_spacePointOffsets;
0265   std::vector<std::uint8_t> m_spacePointCounts;
0266   std::vector<float> m_qualities;
0267   std::vector<float> m_vertexZs;
0268   std::vector<SpacePointIndex2> m_spacePoints;
0269 
0270   std::shared_ptr<const SpacePointContainer2> m_sharedConstSpacePointContainer;
0271   SpacePointContainer2 *m_mutableSpacePointContainer{nullptr};
0272   const SpacePointContainer2 *m_constSpacePointContainer{nullptr};
0273 
0274   auto knownColumns() & noexcept {
0275     return std::tie(m_spacePointOffsets, m_spacePointCounts, m_qualities,
0276                     m_vertexZs, m_spacePoints);
0277   }
0278   auto knownColumns() const & noexcept {
0279     return std::tie(m_spacePointOffsets, m_spacePointCounts, m_qualities,
0280                     m_vertexZs, m_spacePoints);
0281   }
0282   auto knownColumns() && noexcept {
0283     return std::tuple(std::move(m_spacePointOffsets),
0284                       std::move(m_spacePointCounts), std::move(m_qualities),
0285                       std::move(m_vertexZs), std::move(m_spacePoints));
0286   }
0287 };
0288 
0289 }  // namespace Acts
0290 
0291 #include "Acts/EventData/SeedContainer2.ipp"