Belle II Software  release-08-01-10
LinearDivision.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #pragma once
9 
10 #include <tracking/trackFindingCDC/utilities/Product.h>
11 
12 #include <utility>
13 #include <tuple>
14 #include <array>
15 #include <iterator>
16 #include <cassert>
17 
18 namespace Belle2 {
23  namespace TrackFindingCDC {
24 
30  template<class ABox, std::size_t... divisions>
32 
33  public:
35  static const std::size_t s_nSubBoxes = Product<divisions...>::value;
36 
37  private:
39  static constexpr std::size_t s_divisions[sizeof...(divisions)] = {divisions...};
40 
41  public:
43  explicit LinearDivision(const typename ABox::Delta& overlaps = typename ABox::Delta())
44  : m_overlaps(overlaps)
45  {}
46 
47  public:
49  std::array<ABox, s_nSubBoxes> operator()(const ABox& box)
50  {
51  return makeSubBoxes(box, std::make_index_sequence<s_nSubBoxes>());
52  }
53 
55  template<std::size_t... Is>
56 
57  std::array<ABox, s_nSubBoxes>
58  makeSubBoxes(const ABox& box, std::index_sequence<Is...> /*globalSubBoxIndex*/)
59  {
60  return {{ makeSubBox(box, Is, std::make_index_sequence<sizeof...(divisions)>())... }};
61  }
62 
63 
65  template<std::size_t... Is>
66 
67  ABox makeSubBox(const ABox& box,
68  std::size_t globalISubBox,
69  std::index_sequence<Is...> /*coordinatesIndex*/)
70  {
71  std::array<std::size_t, sizeof...(divisions)> indices;
72  for (size_t c_Index = 0 ; c_Index < sizeof...(divisions); ++c_Index) {
73  indices[c_Index] = globalISubBox % s_divisions[c_Index];
74  globalISubBox /= s_divisions[c_Index];
75  }
76  assert(globalISubBox == 0);
77  return ABox(box.template getDivisionBoundsWithOverlap<Is>(std::get<Is>(m_overlaps),
78  s_divisions[Is],
79  indices[Is]) ...);
80  }
81 
82  private:
84  typename ABox::Delta m_overlaps;
85 
86  };
87 
88  // Extra mention of the constexpr such that it aquires external linkage.
89  template<class ABox, std::size_t... divisions>
90  constexpr std::size_t LinearDivision<ABox, divisions...>::s_divisions[sizeof...(divisions)];
91  }
93 }
Factory object that constructs sub boxes from a given box with optional overlaps.
std::array< ABox, s_nSubBoxes > makeSubBoxes(const ABox &box, std::index_sequence< Is... >)
Make all subboxs with overlap of the given box.
static constexpr std::size_t s_divisions[sizeof...(divisions)]
Array of the number of divisions for each dimension.
LinearDivision(const typename ABox::Delta &overlaps=typename ABox::Delta())
Initialise the sub box factory with specific overlaps.
ABox makeSubBox(const ABox &box, std::size_t globalISubBox, std::index_sequence< Is... >)
Make the subbox with overlaps of the given box at global index.
std::array< ABox, s_nSubBoxes > operator()(const ABox &box)
Factory method to construct the subboxes with overlap from the given box.
static const std::size_t s_nSubBoxes
Number of sub boxes produced by this factory facility.
ABox::Delta m_overlaps
Custom overlaps of the bounds at each division for each dimension.
Abstract base class for different kinds of events.
Template class for compile time computation of products.
Definition: Product.h:21