Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:47

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/SpacePointContainer.hpp"
0012 #include "Acts/Utilities/Holders.hpp"
0013 #include "ActsExamples/EventData/SimSpacePoint.hpp"
0014 
0015 #include <any>
0016 
0017 namespace ActsExamples {
0018 
0019 template <typename collection_t>
0020 class SpacePointContainer {
0021  public:
0022   using CollectionType = collection_t;
0023   using ValueType = typename CollectionType::value_type;
0024 
0025   friend Acts::SpacePointContainer<
0026       ActsExamples::SpacePointContainer<collection_t>, Acts::detail::RefHolder>;
0027 
0028   // default constructor is of no use. It cannot be used, so why bother?
0029   SpacePointContainer() = delete;
0030   // we never get the ownership. In both read-only and read-and-write mode
0031   // the memory backend is independetly handled. This is only interfacing it to
0032   // ACTS
0033   SpacePointContainer(CollectionType&& container) = delete;
0034   explicit SpacePointContainer(CollectionType& container)
0035       : m_storage(container) {}
0036   explicit SpacePointContainer(CollectionType* container)
0037       : m_storage(container) {}
0038 
0039   // No copy constructor or copy operation allowed
0040   SpacePointContainer(const SpacePointContainer<collection_t>&) = delete;
0041   SpacePointContainer<collection_t>& operator=(
0042       const SpacePointContainer<collection_t>&) = delete;
0043 
0044   // only move operation allowed
0045   SpacePointContainer(SpacePointContainer<collection_t>&& other) noexcept
0046       : m_storage(std::exchange(other.m_storage.ptr, nullptr)) {}
0047   SpacePointContainer<collection_t>& operator=(
0048       SpacePointContainer<collection_t>&& other) noexcept {
0049     m_storage = std::exchange(other.m_storage.ptr, nullptr);
0050     return *this;
0051   }
0052 
0053   ~SpacePointContainer() = default;
0054 
0055  private:
0056   std::size_t size_impl() const;
0057 
0058   float x_impl(std::size_t idx) const;
0059   float y_impl(std::size_t idx) const;
0060   float z_impl(std::size_t idx) const;
0061   float varianceR_impl(std::size_t idx) const;
0062   float varianceZ_impl(std::size_t idx) const;
0063 
0064   const ValueType& get_impl(std::size_t idx) const { return storage()[idx]; }
0065 
0066   std::any component_impl(Acts::HashedString key, std::size_t /*n*/) const {
0067     using namespace Acts::HashedStringLiteral;
0068     switch (key) {
0069       case "TopStripVector"_hash:
0070       case "BottomStripVector"_hash:
0071       case "StripCenterDistance"_hash:
0072       case "TopStripCenterPosition"_hash:
0073         return Acts::Vector3(0, 0, 0);
0074       default:
0075         throw std::runtime_error("no such component " + std::to_string(key));
0076     }
0077   }
0078 
0079  private:
0080   const CollectionType& storage() const;
0081 
0082  private:
0083   Acts::detail::RefHolder<CollectionType> m_storage;
0084 };
0085 
0086 template <typename collection_t>
0087 inline std::size_t SpacePointContainer<collection_t>::size_impl() const {
0088   return storage().size();
0089 }
0090 
0091 template <typename collection_t>
0092 inline float SpacePointContainer<collection_t>::x_impl(std::size_t idx) const {
0093   return storage()[idx]->x();
0094 }
0095 
0096 template <typename collection_t>
0097 inline float SpacePointContainer<collection_t>::y_impl(std::size_t idx) const {
0098   return storage()[idx]->y();
0099 }
0100 
0101 template <typename collection_t>
0102 inline float SpacePointContainer<collection_t>::z_impl(std::size_t idx) const {
0103   return storage()[idx]->z();
0104 }
0105 
0106 template <typename collection_t>
0107 inline float SpacePointContainer<collection_t>::varianceR_impl(
0108     std::size_t idx) const {
0109   return storage()[idx]->varianceR();
0110 }
0111 
0112 template <typename collection_t>
0113 inline float SpacePointContainer<collection_t>::varianceZ_impl(
0114     std::size_t idx) const {
0115   return storage()[idx]->varianceZ();
0116 }
0117 
0118 template <typename collection_t>
0119 const typename SpacePointContainer<collection_t>::CollectionType&
0120 SpacePointContainer<collection_t>::storage() const {
0121   return *m_storage;
0122 }
0123 
0124 }  // namespace ActsExamples