Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Options.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Options.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2020 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 http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <array>
12 #include <cstddef>
13 #include <iosfwd>
14 #include <optional>
15 #include <vector>
16 
17 namespace ActsExamples {
18 namespace Options {
19 
30 
37 struct Interval {
38  std::optional<double> lower;
39  std::optional<double> upper;
40 };
41 
46 template <size_t kSize>
47 class Reals : public std::array<double, kSize> {};
48 
54 struct VariableReals {
55  std::vector<double> values;
56 };
57 
62 template <size_t kSize>
63 class Integers : public std::array<int, kSize> {};
64 
71  std::vector<int> values;
72 };
73 
75 
83 std::istream& operator>>(std::istream& is, Interval& interval);
84 
86 std::ostream& operator<<(std::ostream& os, const Interval& interval);
87 
88 namespace detail {
89 void parseDoublesFixed(std::istream& is, size_t size, double* values);
90 void parseDoublesVariable(std::istream& is, std::vector<double>& values);
91 void printDoubles(std::ostream& os, size_t size, const double* values);
92 } // namespace detail
93 
99 template <size_t kSize>
100 inline std::istream& operator>>(std::istream& is, Reals<kSize>& values) {
101  detail::parseDoublesFixed(is, kSize, values.data());
102  return is;
103 }
104 
110 inline std::istream& operator>>(std::istream& is, VariableReals& values) {
112  return is;
113 }
114 
116 template <size_t kSize>
117 inline std::ostream& operator<<(std::ostream& os, const Reals<kSize>& values) {
118  detail::printDoubles(os, kSize, values.data());
119  return os;
120 }
121 
123 inline std::ostream& operator<<(std::ostream& os, const VariableReals& values) {
124  detail::printDoubles(os, values.values.size(), values.values.data());
125  return os;
126 }
127 
128 namespace detail {
129 void parseIntegersFixed(std::istream& is, size_t size, int* values);
130 void parseIntegersVariable(std::istream& is, std::vector<int>& values);
131 void printIntegers(std::ostream& os, size_t size, const int* values);
132 } // namespace detail
133 
139 template <size_t kSize>
140 inline std::istream& operator>>(std::istream& is, Integers<kSize>& values) {
141  detail::parseIntegersFixed(is, kSize, values.data());
142  return is;
143 }
144 
150 inline std::istream& operator>>(std::istream& is, VariableIntegers& values) {
152  return is;
153 }
154 
156 template <size_t kSize>
157 inline std::ostream& operator<<(std::ostream& os,
158  const Integers<kSize>& values) {
159  detail::printIntegers(os, kSize, values.data());
160  return os;
161 }
162 
164 inline std::ostream& operator<<(std::ostream& os,
165  const VariableIntegers& values) {
166  detail::printIntegers(os, values.values.size(), values.values.data());
167  return os;
168 }
169 
170 } // namespace Options
171 } // namespace ActsExamples