EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fittable_type_generator.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file fittable_type_generator.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 
12 
13 #include <type_traits>
14 #include <variant>
15 
16 // clang-format off
17 #include <boost/hana/append.hpp>
18 #include <boost/hana/integral_constant.hpp>
19 #include <boost/hana/range.hpp>
20 #include <boost/hana/remove_at.hpp>
21 #include <boost/hana/transform.hpp>
22 #include <boost/hana/tuple.hpp>
23 #include <boost/hana/filter.hpp>
24 // This include is technically not needed for this file, but removing it
25 // introduces some form of order dependency on subsequent include.
26 #include <boost/hana/set.hpp>
27 #include <boost/hana/type.hpp>
28 // clang-format on
29 
30 namespace Acts {
31 
33 namespace detail {
34 
35 namespace hana = boost::hana;
36 
64 template <size_t W>
65 constexpr auto unique_ordered_sublists() {
66  using namespace hana::literals;
67  // generate an empty tuple to start off
68  constexpr auto combinations = hana::make_tuple(hana::make_tuple());
69  // generate range over which to fold
70  constexpr auto w_range =
71  hana::to_tuple(hana::make_range(0_c, hana::size_c<W>));
72  // main fold expression. This successively adds variations to `state` and
73  // then
74  // returns the result.
75  constexpr auto comb2 =
76  hana::fold_left(w_range, combinations, [](auto state, auto i) {
77  auto mapped = hana::transform(
78  state, [i](auto c_i) { return hana::append(c_i, i); });
79  return hana::concat(state, mapped);
80  });
81  // we need to pop off the initial empty tuple, which isn't really valid
82  return hana::remove_at(comb2, 0_c);
83 }
84 
91 template <typename parameter_indices_t,
92  template <parameter_indices_t...> class meas_meta>
93 constexpr auto type_generator() {
94  // generate sublists
95  constexpr size_t W = detail::kParametersSize<parameter_indices_t>;
96  constexpr auto sublists = unique_ordered_sublists<W>();
97  // map each sublist (tuple of paramater indices) into a measurement using
98  // the provided `meas_meta` metafunction.
99  constexpr auto measurements_h = hana::transform(sublists, [](auto s) {
100  return hana::unpack(s, [](auto... i) {
101  return hana::type_c<
102  typename meas_meta<parameter_indices_t(decltype(i)::value)...>::type>;
103  });
104  });
105  // return tuple of measurements
106  return measurements_h;
107 }
108 
115 template <typename parameter_indices_t,
116  template <parameter_indices_t...> class meas_meta>
117 using type_generator_t = typename decltype(
118  hana::unpack(type_generator<parameter_indices_t, meas_meta>(),
119  hana::template_<std::variant>))::type;
120 
122 } // namespace detail
124 } // namespace Acts