Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:49

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 
0014 #include <any>
0015 
0016 namespace ActsExamples {
0017 
0018 template <typename collection_t>
0019 class SpacePointContainer {
0020  public:
0021   using CollectionType = collection_t;
0022   using ValueType = typename CollectionType::value_type;
0023 
0024   friend Acts::SpacePointContainer<
0025       ActsExamples::SpacePointContainer<collection_t>, Acts::detail::RefHolder>;
0026 
0027   // default constructor is of no use. It cannot be used, so why bother?
0028   SpacePointContainer() = delete;
0029   // we never get the ownership. In both read-only and read-and-write mode
0030   // the memory backend is independetly handled. This is only interfacing it to
0031   // ACTS
0032   SpacePointContainer(CollectionType&& container) = delete;
0033   SpacePointContainer(CollectionType& container) : m_storage(container) {}
0034   SpacePointContainer(CollectionType* container) : m_storage(container) {}
0035 
0036   // No copy constructor or copy operation allowed
0037   SpacePointContainer(const SpacePointContainer<collection_t>&) = delete;
0038   SpacePointContainer<collection_t>& operator=(
0039       const SpacePointContainer<collection_t>&) = delete;
0040 
0041   // only move operation allowed
0042   SpacePointContainer(SpacePointContainer<collection_t>&& other) noexcept
0043       : m_storage(std::exchange(other.m_storage.ptr, nullptr)) {}
0044   SpacePointContainer<collection_t>& operator=(
0045       SpacePointContainer<collection_t>&& other) noexcept {
0046     m_storage = std::exchange(other.m_storage.ptr, nullptr);
0047     return *this;
0048   }
0049 
0050   ~SpacePointContainer() = default;
0051 
0052  private:
0053   std::size_t size_impl() const;
0054 
0055   float x_impl(std::size_t idx) const;
0056   float y_impl(std::size_t idx) const;
0057   float z_impl(std::size_t idx) const;
0058   float varianceR_impl(std::size_t idx) const;
0059   float varianceZ_impl(std::size_t idx) const;
0060 
0061   const ValueType& get_impl(std::size_t idx) const { return storage()[idx]; }
0062 
0063   std::any component_impl(Acts::HashedString key, std::size_t /*n*/) const {
0064     using namespace Acts::HashedStringLiteral;
0065     switch (key) {
0066       case "TopStripVector"_hash:
0067       case "BottomStripVector"_hash:
0068       case "StripCenterDistance"_hash:
0069       case "TopStripCenterPosition"_hash:
0070         return Acts::Vector3(0, 0, 0);
0071       default:
0072         throw std::runtime_error("no such component " + std::to_string(key));
0073     }
0074   }
0075 
0076  private:
0077   const CollectionType& storage() const;
0078 
0079  private:
0080   Acts::detail::RefHolder<CollectionType> m_storage;
0081 };
0082 
0083 template <typename collection_t>
0084 inline std::size_t SpacePointContainer<collection_t>::size_impl() const {
0085   return storage().size();
0086 }
0087 
0088 // TO-DO
0089 // Be smart here... collection_t can container values or pointers ...
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