Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:00

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2021 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Utilities/Any.hpp"
0013 #include "Acts/Utilities/Delegate.hpp"
0014 #include "Acts/Utilities/TypeTraits.hpp"
0015 
0016 #include <cassert>
0017 #include <iostream>
0018 #include <type_traits>
0019 #include <utility>
0020 
0021 #if !defined(ACTS_SOURCELINK_SBO_SIZE)
0022 // Do not set this in code, use CMake!
0023 #define ACTS_SOURCELINK_SBO_SIZE 16
0024 #endif
0025 
0026 namespace Acts {
0027 
0028 class SourceLink final {
0029   using any_type = AnyBase<ACTS_SOURCELINK_SBO_SIZE>;
0030 
0031  public:
0032   SourceLink(const SourceLink& other) = default;
0033   SourceLink(SourceLink&& other) = default;
0034   SourceLink& operator=(const SourceLink& other) = default;
0035   SourceLink& operator=(SourceLink&& other) = default;
0036 
0037   /// Constructor from concrete sourcelink
0038   /// @tparam T The source link type
0039   /// @param upstream The upstream source link to store
0040   template <typename T, typename = std::enable_if_t<
0041                             !std::is_same_v<std::decay_t<T>, SourceLink>>>
0042   explicit SourceLink(T&& upstream) {
0043     static_assert(!std::is_same_v<std::decay_t<T>, SourceLink>,
0044                   "Cannot wrap SourceLink in SourceLink");
0045 
0046     if constexpr (std::is_same_v<T, std::decay_t<T>>) {
0047       m_upstream = any_type{std::move(upstream)};
0048     } else {
0049       m_upstream = any_type{static_cast<std::decay_t<T>>(upstream)};
0050     }
0051   }
0052 
0053   /// Concrete source link class getter
0054   /// @tparam T The source link type to retrieve
0055   /// @return Reference to the stored source link
0056   template <typename T>
0057   T& get() {
0058     return m_upstream.as<T>();
0059   }
0060 
0061   /// Concrete source link class getter, const version
0062   /// @tparam T The source link type to retrieve
0063   /// @return Const reference to the stored source link
0064   template <typename T>
0065   const T& get() const {
0066     return m_upstream.as<T>();
0067   }
0068 
0069  private:
0070   any_type m_upstream{};
0071 };
0072 
0073 template <typename T>
0074 struct SourceLinkAdapterIterator {
0075   using BaseIterator = T;
0076 
0077   using iterator_category = typename BaseIterator::iterator_category;
0078   using value_type = typename BaseIterator::value_type;
0079   using difference_type = typename BaseIterator::difference_type;
0080   using pointer = typename BaseIterator::pointer;
0081   using reference = typename BaseIterator::reference;
0082 
0083   explicit SourceLinkAdapterIterator(T iterator) : m_iterator{iterator} {}
0084 
0085   SourceLinkAdapterIterator& operator++() {
0086     ++m_iterator;
0087     return *this;
0088   }
0089 
0090   bool operator==(const SourceLinkAdapterIterator& other) const {
0091     return m_iterator == other.m_iterator;
0092   }
0093 
0094   bool operator!=(const SourceLinkAdapterIterator& other) const {
0095     return !(*this == other);
0096   }
0097 
0098   Acts::SourceLink operator*() const { return Acts::SourceLink{*m_iterator}; }
0099 
0100   auto operator-(const SourceLinkAdapterIterator& other) const {
0101     return m_iterator - other.m_iterator;
0102   }
0103 
0104   BaseIterator m_iterator;
0105 };
0106 
0107 /// Delegate to unpack the surface associated with a source link
0108 using SourceLinkSurfaceAccessor = Delegate<const Surface*(const SourceLink&)>;
0109 
0110 }  // namespace Acts