ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterTypes.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParameterTypes.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 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 #include <algorithm>
11 #include <cmath>
12 
13 namespace Acts {
18  static constexpr bool may_modify_value{
19  false};
20 
29  template <typename T>
30  static T getValue(const T& input) {
31  return input;
32  }
33 
34  template <typename T>
35  static T getDifference(const T& first, const T& second) {
36  return first - second;
37  }
38 };
39 
44 
57 template <typename T, T (*MIN)(), T (*MAX)()>
59  static constexpr bool may_modify_value{
60  true};
61  static constexpr T min{MIN()};
62  static constexpr T max{MAX()};
63 
74  template <typename U>
75  static U getValue(const U& input) {
76  return (input > max) ? max : ((input < min) ? min : input);
77  }
78 
79  template <typename U>
80  static U getDifference(const U& first, const U& second) {
81  return getValue(first) - getValue(second);
82  }
83 };
84 
96 template <typename T, T (*MIN)(), T (*MAX)()>
98  static constexpr bool may_modify_value{
99  true};
100  static constexpr T min{MIN()};
101  static constexpr T max{MAX()};
102 
114  template <typename U>
115  static U getValue(const U& input) {
116  if (min <= input && input < max) {
117  return input;
118  } else {
119  return input - (max - min) * std::floor((input - min) / (max - min));
120  }
121  }
122 
123  template <typename U>
124  static U getDifference(const U& first, const U& second) {
125  static constexpr U half_period = (max - min) / 2;
126  U tmp = getValue(first) - getValue(second);
127  return (tmp < -half_period
128  ? tmp + 2 * half_period
129  : (tmp > half_period ? tmp - 2 * half_period : tmp));
130  }
131 };
132 
156 // template<typename ParameterPolicy,typename ParameterPolicy::par_id_type
157 // parID>
158 // struct parameter_traits;
159 } // namespace Acts