ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
print.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/algebra/concepts.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14
15// System include(s).
16#include <iomanip>
17#include <iostream>
18
19namespace detray {
20
21namespace algebra {
26template <typename vector_t>
27 requires(concepts::vector<vector_t> || concepts::point<vector_t>)
28DETRAY_HOST std::ostream& operator<<(std::ostream& out, const vector_t& v) {
29 using index_t = detray::traits::index_t<vector_t>;
30
31 constexpr index_t size{detray::traits::size<vector_t>};
32
33 out << "[";
34 for (index_t i = 0; i < size; ++i) {
35 out << v[i];
36 if (i != size - 1) {
37 out << ", ";
38 }
39 }
40 out << "]";
41
42 return out;
43}
44
49template <concepts::column_matrix vector_t>
50DETRAY_HOST std::ostream& operator<<(std::ostream& out, const vector_t& v) {
51 using index_t = detray::traits::index_t<vector_t>;
52 using element_getter_t = detray::traits::element_getter_t<vector_t>;
53
54 constexpr index_t rows{detray::traits::rows<vector_t>};
55
56 out << "[";
57 for (index_t i = 0; i < rows; ++i) {
58 // Account for the sign of negative elements
59 out << std::setw(i == 0 ? 15 : 16) << element_getter_t{}(v, i, 0);
60 }
61 out << "]";
62
63 return out;
64}
65
70template <concepts::matrix matrix_t>
71DETRAY_HOST std::ostream& operator<<(std::ostream& out, const matrix_t& m) {
72 using index_t = detray::traits::index_t<matrix_t>;
73 using element_getter_t = detray::traits::element_getter_t<matrix_t>;
74
75 constexpr index_t rows{detray::traits::rows<matrix_t>};
76 constexpr index_t columns{detray::traits::columns<matrix_t>};
77
78 out << "[";
79 for (index_t i = 0; i < rows; ++i) {
80 out << (i == 0 ? "[" : " [");
81 for (index_t j = 0; j < columns; ++j) {
82 // Account for the sign of negative elements
83 out << std::setw(j == 0 ? 15 : 16) << element_getter_t{}(m, i, j);
84 }
85 out << "]";
86 if (i != rows - 1) {
87 out << "\n";
88 }
89 }
90 out << "]";
91
92 return out;
93}
94
99template <concepts::transform3D transform_t>
100DETRAY_HOST std::ostream& operator<<(std::ostream& out,
101 const transform_t& trf) {
102 out << trf.matrix();
103
104 return out;
105}
106
107} // namespace algebra
108
109// Pull in the print operator definitions for the algebra types
110using algebra::operator<<;
111
112} // namespace detray
constexpr double m
Meter.
Definition Units.hpp:97
Detray include(s).
Definition array_operators.hpp:18