Belle II Software  release-05-02-19
LinearDivision.h
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2015 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Oliver Frost *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/utilities/Product.h>
13 
14 #include <utility>
15 #include <tuple>
16 #include <array>
17 #include <iterator>
18 #include <cassert>
19 
20 namespace Belle2 {
25  namespace TrackFindingCDC {
26 
32  template<class ABox, std::size_t... divisions>
33  class LinearDivision {
34 
35  public:
37  static const std::size_t s_nSubBoxes = Product<divisions...>::value;
38 
39  private:
41  static constexpr std::size_t s_divisions[sizeof...(divisions)] = {divisions...};
42 
43  public:
45  explicit LinearDivision(const typename ABox::Delta& overlaps = typename ABox::Delta())
46  : m_overlaps(overlaps)
47  {}
48 
49  public:
51  std::array<ABox, s_nSubBoxes> operator()(const ABox& box)
52  {
53  return makeSubBoxes(box, std::make_index_sequence<s_nSubBoxes>());
54  }
55 
57  template<std::size_t... Is>
58 
59  std::array<ABox, s_nSubBoxes>
60  makeSubBoxes(const ABox& box, std::index_sequence<Is...> /*globalSubBoxIndex*/)
61  {
62  return {{ makeSubBox(box, Is, std::make_index_sequence<sizeof...(divisions)>())... }};
63  }
64 
65 
67  template<std::size_t... Is>
68 
69  ABox makeSubBox(const ABox& box,
70  std::size_t globalISubBox,
71  std::index_sequence<Is...> /*coordinatesIndex*/)
72  {
73  std::array<std::size_t, sizeof...(divisions)> indices;
74  for (size_t c_Index = 0 ; c_Index < sizeof...(divisions); ++c_Index) {
75  indices[c_Index] = globalISubBox % s_divisions[c_Index];
76  globalISubBox /= s_divisions[c_Index];
77  }
78  assert(globalISubBox == 0);
79  return ABox(box.template getDivisionBoundsWithOverlap<Is>(std::get<Is>(m_overlaps),
80  s_divisions[Is],
81  indices[Is]) ...);
82  }
83 
84  private:
86  typename ABox::Delta m_overlaps;
87 
88  };
89 
90  // Extra mention of the constexpr such that it aquires external linkage.
91  template<class ABox, std::size_t... divisions>
92  constexpr std::size_t LinearDivision<ABox, divisions...>::s_divisions[sizeof...(divisions)];
93  }
95 }
Belle2::TrackFindingCDC::LinearDivision::m_overlaps
ABox::Delta m_overlaps
Custom overlaps of the bounds at each division for each dimension.
Definition: LinearDivision.h:94
Belle2::TrackFindingCDC::LinearDivision::makeSubBoxes
std::array< ABox, s_nSubBoxes > makeSubBoxes(const ABox &box, std::index_sequence< Is... >)
Make all subboxs with overlap of the given box.
Definition: LinearDivision.h:68
Belle2::TrackFindingCDC::LinearDivision::s_divisions
static constexpr std::size_t s_divisions[sizeof...(divisions)]
Array of the number of divisions for each dimension.
Definition: LinearDivision.h:49
Belle2::TrackFindingCDC::LinearDivision::LinearDivision
LinearDivision(const typename ABox::Delta &overlaps=typename ABox::Delta())
Initialise the sub box factory with specific overlaps.
Definition: LinearDivision.h:53
Belle2::TrackFindingCDC::LinearDivision::makeSubBox
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.
Definition: LinearDivision.h:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::LinearDivision::s_nSubBoxes
static const std::size_t s_nSubBoxes
Number of sub boxes produced by this factory facility.
Definition: LinearDivision.h:45
Belle2::TrackFindingCDC::LinearDivision::operator()
std::array< ABox, s_nSubBoxes > operator()(const ABox &box)
Factory method to construct the subboxes with overlap from the given box.
Definition: LinearDivision.h:59