Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-26 08:21:58

0001 /** TRACCC library, part of the ACTS project (R&D line)
0002  *
0003  * (c) 2021-2022 CERN for the benefit of the ACTS project
0004  *
0005  * Mozilla Public License Version 2.0
0006  */
0007 
0008 #pragma once
0009 
0010 // Project include(s).
0011 #include "traccc/definitions/qualifiers.hpp"
0012 #include "traccc/edm/details/device_container.hpp"
0013 #include "traccc/edm/details/host_container.hpp"
0014 #include "traccc/utils/type_traits.hpp"
0015 
0016 // VecMem include(s).
0017 #include <vecmem/containers/data/jagged_vector_buffer.hpp>
0018 #include <vecmem/containers/data/jagged_vector_data.hpp>
0019 #include <vecmem/containers/data/jagged_vector_view.hpp>
0020 #include <vecmem/containers/data/vector_buffer.hpp>
0021 #include <vecmem/containers/data/vector_view.hpp>
0022 #include <vecmem/containers/device_vector.hpp>
0023 #include <vecmem/containers/vector.hpp>
0024 
0025 // System include(s).
0026 #include <type_traits>
0027 
0028 namespace traccc {
0029 
0030 /// @name Types used to send data back and forth between host and device code
0031 /// @{
0032 
0033 /// Structure holding (some of the) data about the container in host code
0034 template <typename header_t, typename item_t>
0035 struct container_data {
0036   using header_vector = vecmem::data::vector_view<header_t>;
0037   using item_vector = vecmem::data::jagged_vector_data<item_t>;
0038   header_vector headers;
0039   item_vector items;
0040 };
0041 
0042 /// Structure holding (all of the) data about the container in host code
0043 template <typename header_t, typename item_t>
0044 struct container_buffer {
0045   using header_vector = vecmem::data::vector_buffer<header_t>;
0046   using item_vector = vecmem::data::jagged_vector_buffer<item_t>;
0047   header_vector headers;
0048   item_vector items;
0049 };
0050 
0051 /// Structure used to send the data about the container to device code
0052 ///
0053 /// This is the type that can be passed to device code as-is. But since in
0054 /// host code one needs to manage the data describing a
0055 /// @c traccc::container either using @c traccc::container_data or
0056 /// @c traccc::container_buffer, it needs to have constructors from
0057 /// both of those types.
0058 ///
0059 /// In fact it needs to be created from one of those types, as such an
0060 /// object can only function if an instance of one of those types exists
0061 /// alongside it as well.
0062 ///
0063 template <typename header_t, typename item_t>
0064 struct container_view {
0065   /// Type for the header vector (view)
0066   using header_vector = vecmem::data::vector_view<header_t>;
0067   /// Type for the item vector (view)
0068   using item_vector = vecmem::data::jagged_vector_view<item_t>;
0069 
0070   /// Constructor from a @c container_data object
0071   template <
0072       typename other_header_t, typename other_item_t,
0073       std::enable_if_t<details::is_same_nc<header_t, other_header_t>::value,
0074                        bool> = true,
0075       std::enable_if_t<details::is_same_nc<item_t, other_item_t>::value, bool> =
0076           true>
0077   container_view(const container_data<other_header_t, other_item_t>& data)
0078       : headers(data.headers), items(data.items) {}
0079 
0080   /// Constructor from a @c container_buffer object
0081   template <
0082       typename other_header_t, typename other_item_t,
0083       std::enable_if_t<details::is_same_nc<header_t, other_header_t>::value,
0084                        bool> = true,
0085       std::enable_if_t<details::is_same_nc<item_t, other_item_t>::value, bool> =
0086           true>
0087   container_view(const container_buffer<other_header_t, other_item_t>& buffer)
0088       : headers(buffer.headers), items(buffer.items) {}
0089 
0090   /// Constructor from a non-const view
0091   template <
0092       typename other_header_t, typename other_item_t,
0093       std::enable_if_t<details::is_same_nc<header_t, other_header_t>::value,
0094                        bool> = true,
0095       std::enable_if_t<details::is_same_nc<item_t, other_item_t>::value, bool> =
0096           true>
0097   container_view(const container_view<other_header_t, other_item_t>& parent)
0098       : headers(parent.headers), items(parent.items) {}
0099 
0100   /// View of the data describing the headers
0101   header_vector headers;
0102 
0103   /// View of the data describing the items
0104   item_vector items;
0105 };
0106 
0107 /// Helper function for making a "simple" object out of the container
0108 /// (non-const)
0109 template <typename header_t, typename item_t>
0110 inline container_data<header_t, item_t> get_data(
0111     host_container<header_t, item_t>& cc,
0112     vecmem::memory_resource* resource = nullptr) {
0113   return {{vecmem::get_data(cc.get_headers())},
0114           {vecmem::get_data(cc.get_items(), resource)}};
0115 }
0116 
0117 /// Helper function for making a "simple" object out of the container (const)
0118 template <typename header_t, typename item_t>
0119 inline container_data<const header_t, const item_t> get_data(
0120     const host_container<header_t, item_t>& cc,
0121     vecmem::memory_resource* resource = nullptr) {
0122   return {{vecmem::get_data(cc.get_headers())},
0123           {vecmem::get_data(cc.get_items(), resource)}};
0124 }
0125 
0126 /// Type trait defining all "collection types" for an EDM class
0127 template <typename item_t>
0128 struct collection_types {
0129   /// @c item_t must not be a constant type
0130   static_assert(std::is_const<item_t>::value == false,
0131                 "The template parameter must not be a constant type");
0132 
0133   /// Host collection for @c item_t
0134   using host = vecmem::vector<item_t>;
0135   /// Non-const device collection for @c item_t
0136   using device = vecmem::device_vector<item_t>;
0137   /// Constant device collection for @c item_t
0138   using const_device = vecmem::device_vector<const item_t>;
0139 
0140   /// Non-constant view of an @c item_t collection
0141   using view = vecmem::data::vector_view<item_t>;
0142   /// Constant view of an @c item_t collection
0143   using const_view = vecmem::data::vector_view<const item_t>;
0144 
0145   /// Buffer for an @c item_t collection
0146   using buffer = vecmem::data::vector_buffer<item_t>;
0147 
0148 };  // struct collection_types
0149 
0150 /// Type trait defining all "container types" for an EDM class pair
0151 template <typename header_t, typename item_t>
0152 struct container_types {
0153   /// @c header_t must not be a constant type
0154   static_assert(std::is_const<header_t>::value == false,
0155                 "The header type must not be constant");
0156   /// @c item_t must not be a constant type
0157   static_assert(std::is_const<item_t>::value == false,
0158                 "The item type must not be constant");
0159 
0160   /// Host container for @c header_t and @c item_t
0161   using host = host_container<header_t, item_t>;
0162   /// Non-const device container for @c header_t and @c item_t
0163   using device = device_container<header_t, item_t>;
0164   /// Constant device container for @c header_t and @c item_t
0165   using const_device = device_container<const header_t, const item_t>;
0166 
0167   /// Non-constant view of an @c header_t / @c item_t container
0168   using view = container_view<header_t, item_t>;
0169   /// Constant view of an @c header_t / @c item_t container
0170   using const_view = container_view<const header_t, const item_t>;
0171 
0172   /// Non-constant data for an @c header_t / @c item_t container
0173   using data = container_data<header_t, item_t>;
0174   /// Constant data for an @c header_t / @c item_t container
0175   using const_data = container_data<const header_t, const item_t>;
0176 
0177   /// Buffer for an @c header_t / @c item_t container
0178   using buffer = container_buffer<header_t, item_t>;
0179 
0180 };  // struct container_types
0181 
0182 }  // namespace traccc