ECCE @ 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 
11 #include <variant>
13 
14 #include <type_traits>
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 <template <ParID_t...> class meas_meta, size_t W>
92 constexpr auto type_generator() {
93  // generate sublists
94  constexpr auto sublists = unique_ordered_sublists<W>();
95  // map each sublist (tuple of paramater indices) into a measurement using
96  // the provided `meas_meta` metafunction.
97  constexpr auto measurements_h = hana::transform(sublists, [](auto s) {
98  return hana::unpack(s, [](auto... i) {
99  return hana::type_c<
100  typename meas_meta<ParID_t(decltype(i)::value)...>::type>;
101  });
102  });
103  // return tuple of measurements
104  return measurements_h;
105 }
106 
113 template <template <ParID_t...> class meas_meta, size_t W>
114 using type_generator_t = typename decltype(hana::unpack(
115  type_generator<meas_meta, W>(), hana::template_<std::variant>))::type;
116 
118 } // namespace detail
120 } // namespace Acts