Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:07:59

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 <memory>
0012 #include <vector>
0013 
0014 namespace Acts::Experimental {
0015 
0016 class SpacePointContainer2;
0017 template <typename T, bool read_only>
0018 class SpacePointColumnProxy;
0019 template <typename T>
0020 using MutableSpacePointColumnProxy = SpacePointColumnProxy<T, false>;
0021 template <typename T>
0022 using ConstSpacePointColumnProxy = SpacePointColumnProxy<T, true>;
0023 
0024 namespace detail::sp {
0025 
0026 // These classes should have gone into `SpacePointContainer2` but a compiler bug
0027 // prevents that
0028 
0029 class ColumnHolderBase {
0030  public:
0031   virtual ~ColumnHolderBase() = default;
0032 
0033   virtual std::unique_ptr<ColumnHolderBase> copy() const = 0;
0034 
0035   virtual std::size_t size() const = 0;
0036   virtual void reserve(std::size_t size) = 0;
0037   virtual void resize(std::size_t size) = 0;
0038   virtual void clear() = 0;
0039   virtual void emplace_back() = 0;
0040 };
0041 
0042 template <typename T>
0043 class ColumnHolder final : public ColumnHolderBase {
0044  public:
0045   using Value = T;
0046   using Container = std::vector<Value>;
0047   using MutableProxy = MutableSpacePointColumnProxy<Value>;
0048   using ConstProxy = ConstSpacePointColumnProxy<Value>;
0049 
0050   ColumnHolder() = default;
0051   explicit ColumnHolder(Value defaultValue)
0052       : m_default(std::move(defaultValue)) {}
0053 
0054   MutableProxy proxy(SpacePointContainer2 &container) {
0055     return MutableProxy(container, m_data);
0056   }
0057   ConstProxy proxy(const SpacePointContainer2 &container) const {
0058     return ConstProxy(container, m_data);
0059   }
0060 
0061   std::unique_ptr<ColumnHolderBase> copy() const override {
0062     return std::make_unique<detail::sp::ColumnHolder<T>>(*this);
0063   }
0064 
0065   std::size_t size() const override { return m_data.size(); }
0066   void reserve(std::size_t size) override { m_data.reserve(size); }
0067   void clear() override { m_data.clear(); }
0068   void resize(std::size_t size) override { m_data.resize(size, m_default); }
0069   void emplace_back() override { m_data.emplace_back(m_default); }
0070 
0071  private:
0072   Value m_default{};
0073   Container m_data;
0074 };
0075 
0076 }  // namespace detail::sp
0077 }  // namespace Acts::Experimental