Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10: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/Geometry/GeometryIdentifier.hpp"
0012 #include "Acts/Utilities/Any.hpp"
0013 #include "Acts/Utilities/Delegate.hpp"
0014 
0015 #include <cassert>
0016 #include <concepts>
0017 #include <type_traits>
0018 #include <utility>
0019 
0020 #if !defined(ACTS_SOURCELINK_SBO_SIZE)
0021 // Do not set this in code, use CMake!
0022 #define ACTS_SOURCELINK_SBO_SIZE 16
0023 #endif
0024 
0025 namespace Acts {
0026 
0027 class SourceLink final {
0028   using any_type = AnyBase<ACTS_SOURCELINK_SBO_SIZE>;
0029 
0030  public:
0031   SourceLink(const SourceLink& other) = default;
0032   SourceLink(SourceLink&& other) = default;
0033   SourceLink& operator=(const SourceLink& other) = default;
0034   SourceLink& operator=(SourceLink&& other) = default;
0035 
0036   /// Constructor from concrete source link
0037   /// @tparam T The source link type
0038   /// @param upstream The upstream source link to store
0039   template <typename T>
0040   explicit SourceLink(T&& upstream)
0041     requires(!std::same_as<std::decay_t<T>, SourceLink>)
0042       : m_upstream(std::forward<T>(upstream)) {
0043     static_assert(!std::is_same_v<std::decay_t<T>, SourceLink>,
0044                   "Cannot wrap SourceLink in SourceLink");
0045   }
0046 
0047   /// Concrete source link class getter
0048   /// @tparam T The source link type to retrieve
0049   /// @return Reference to the stored source link
0050   template <typename T>
0051   T& get() {
0052     return m_upstream.as<T>();
0053   }
0054 
0055   /// Concrete source link class getter, const version
0056   /// @tparam T The source link type to retrieve
0057   /// @return Const reference to the stored source link
0058   template <typename T>
0059   const T& get() const {
0060     return m_upstream.as<T>();
0061   }
0062 
0063  private:
0064   any_type m_upstream{};
0065 };
0066 
0067 template <typename T>
0068 struct SourceLinkAdapterIterator {
0069   using BaseIterator = T;
0070 
0071   using iterator_category = typename BaseIterator::iterator_category;
0072   using value_type = typename BaseIterator::value_type;
0073   using difference_type = typename BaseIterator::difference_type;
0074   using pointer = typename BaseIterator::pointer;
0075   using reference = typename BaseIterator::reference;
0076 
0077   explicit SourceLinkAdapterIterator(T iterator) : m_iterator{iterator} {}
0078 
0079   SourceLinkAdapterIterator& operator++() {
0080     ++m_iterator;
0081     return *this;
0082   }
0083 
0084   bool operator==(const SourceLinkAdapterIterator& other) const {
0085     return m_iterator == other.m_iterator;
0086   }
0087 
0088   Acts::SourceLink operator*() const { return Acts::SourceLink{*m_iterator}; }
0089 
0090   auto operator-(const SourceLinkAdapterIterator& other) const {
0091     return m_iterator - other.m_iterator;
0092   }
0093 
0094   BaseIterator m_iterator;
0095 };
0096 
0097 /// Delegate to unpack the surface associated with a source link
0098 using SourceLinkSurfaceAccessor = Delegate<const Surface*(const SourceLink&)>;
0099 
0100 }  // namespace Acts