ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
surface_grid_writer.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/core/concepts.hpp"
13#include "detray/definitions/indexing.hpp"
14#include "detray/io/backend/detail/grid_writer.hpp"
15#include "detray/io/frontend/payloads.hpp"
16
17// System include(s)
18#include <string_view>
19
20namespace detray::io {
21
25class surface_grid_writer : public detail::grid_writer {
26 using base_type = detail::grid_writer;
27 using grid_writer_t = base_type;
28
29 public:
31 static constexpr std::string_view tag = "surface_grids";
32
35
37 using base_type::base_type;
38
44 template <detray::concepts::detector detector_t>
45 static auto header_to_payload(const detector_t& det,
46 const std::string_view det_name) {
47 return grid_writer_t::header_to_payload(tag, det.accelerator_store(),
48 det_name);
49 }
50
56 template <detray::concepts::detector detector_t>
58 const detector_t& det, const typename detector_t::name_map& /*unused*/) {
59 using surface_desc_t = typename detector_t::surface_type;
60
61 payload_type grids_data;
62
63 for (const auto& vol_desc : det.volumes()) {
64 // Links to all acceleration data structures in the volume
65 const auto& multi_link = vol_desc.accel_link();
66
67 // How to convert the surface descriptors in the grid
68 auto sf_converter =
69 [&vol_desc = std::as_const(vol_desc)](const surface_desc_t& sf_desc) {
70 return vol_desc.to_local_sf_index(sf_desc.index());
71 };
72
73 // Start a 1, because the first acceleration structure is always
74 // the brute force method
75 for (dindex i = 1u; i < multi_link.size(); ++i) {
76 const auto& acc_link = multi_link[i];
77 // Don't look at empty links
78 if (acc_link.is_invalid()) {
79 continue;
80 }
81
82 // Generate the payload
83 grid_writer_t::to_payload(det.accelerator_store(), acc_link,
84 vol_desc.index(), vol_desc.index(),
85 grids_data, sf_converter);
86 }
87 }
88
89 return grids_data;
90 }
91};
92
93} // namespace detray::io
Surface grid writer backend.
Definition surface_grid_writer.hpp:25
detector_grids_payload< std::size_t, io::accel_id > payload_type
Payload type that the reader processes.
Definition surface_grid_writer.hpp:34
static constexpr std::string_view tag
Tag the writer as "surface_grids".
Definition surface_grid_writer.hpp:31
static auto header_to_payload(const detector_t &det, const std::string_view det_name)
Convert the header information into its payload.
Definition surface_grid_writer.hpp:45
static payload_type to_payload(const detector_t &det, const typename detector_t::name_map &)
Convert the grid collections of a detector det into their io payload.
Definition surface_grid_writer.hpp:57
The following enums are global for all detectors.
Definition concepts.hpp:18
unsigned int dindex
Default index type.
Definition indexing.hpp:18
A payload for the grid collections of a detector.
Definition payloads.hpp:344