Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
selector_list_implementation.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file selector_list_implementation.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 namespace Fatras {
12 
13 namespace detail {
14 
15 namespace {
16 
17 template <typename... selectors> struct selector_list_impl;
18 
21 template <typename first, typename... others>
22 struct selector_list_impl<first, others...> {
23  template <typename T, typename detector_t, typename particle_t>
24  static bool select(const T &slector_tuple, const detector_t &detector,
25  const particle_t &particle, bool inclusive) {
26  // pick the first select
27  const auto &this_selector = std::get<first>(slector_tuple);
28  bool selected = this_selector(detector, particle);
29  // recursive call on the remaining ones, none of the selectors
30  // is allowed to fail - a single failed selector rejects the particle
31  // @todo check if rhs is actually evaluated if lhs fails (should not!)
32  if (inclusive)
33  return (selected || selector_list_impl<others...>::select(
34  slector_tuple, detector, particle, inclusive));
35  return (selected && selector_list_impl<others...>::select(
36  slector_tuple, detector, particle, inclusive));
37  }
38 };
39 
41 template <typename last> struct selector_list_impl<last> {
42  template <typename T, typename detector_t, typename particle_t>
43  static bool select(const T &slector_tuple, const detector_t &detector,
44  const particle_t &particle, bool) {
45  // this is the last select in the tuple
46  const auto &this_selector = std::get<last>(slector_tuple);
47  return this_selector(detector, particle);
48  }
49 };
50 
52 template <> struct selector_list_impl<> {
53  template <typename T, typename detector_t, typename particle_t>
54  static bool select(const T &, const detector_t &, const particle_t &, bool) {
55  return true;
56  }
57 };
58 
59 } // namespace
60 
61 } // namespace detail
62 
63 } // namespace Fatras