LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GridContainerIndices.h
Go to the documentation of this file.
1 
18 #ifndef LARDATA_UTILITIES_GRIDCONTAINERINDICES_H
19 #define LARDATA_UTILITIES_GRIDCONTAINERINDICES_H
20 
21 // LArSoft libraries
23 
24 // C/C++ standard libraries
25 #include <array>
26 #include <cstddef> // std::ptrdiff_t
27 
28 namespace util {
29 
30  namespace details {
31 
33  template <unsigned int DIMS>
36 
37  public:
39  static constexpr unsigned int dims() { return DIMS; }
40 
43 
45  using CellIndexOffset_t = std::ptrdiff_t;
46 
49 
51  using CellID_t = std::array<CellDimIndex_t, dims()>;
52 
54  GridContainerIndicesBase(std::array<size_t, dims()> const& new_dims)
55  : indices(new_dims.begin())
56  {}
57 
60 
62  bool has(CellIndexOffset_t index) const { return indices.hasLinIndex(index); }
63 
65  size_t size() const { return indices.size(); }
66 
68 
71 
73  CellIndex_t operator[](CellID_t id) const { return index(id); }
74 
76  CellIndexOffset_t offset(CellID_t const& origin, CellID_t const& cellID) const
77  {
78  return index(cellID) - index(origin);
79  }
80 
82 
83  protected:
85 
87  CellIndex_t index(CellID_t id) const { return indices(id.begin()); }
88 
89  }; // GridContainerIndicesBase
90 
91  } // namespace details
92 
94  template <unsigned int DIMS = 1U>
96  static_assert(DIMS >= 1U, "Dimensions for GridContainerIndicesBase1D must be at least 1");
98 
99  public:
100  using Base_t::GridContainerIndicesBase;
101 
104 
106  bool hasX(typename Base_t::CellDimIndex_t index) const
107  {
108  return Base_t::indices.template hasIndex<0>(index);
109  }
110 
112  size_t sizeX() const { return Base_t::indices.template dim<0>(); }
113 
115 
116  }; // GridContainerIndicesBase1D
117 
119  template <unsigned int DIMS = 2U>
121  static_assert(DIMS >= 2U, "Dimensions for GridContainerIndicesBase2D must be at least 2");
122 
124 
125  public:
126  using Base_t::GridContainerIndicesBase1D;
127 
130 
132  bool hasY(typename Base_t::CellDimIndex_t index) const
133  {
134  return Base_t::indices.template hasIndex<1>(index);
135  }
136 
138  size_t sizeY() const { return Base_t::indices.template dim<1>(); }
139 
141 
142  }; // GridContainerIndicesBase2D
143 
145  template <unsigned int DIMS = 3U>
147  static_assert(DIMS >= 3U, "Dimensions for GridContainerIndicesBase3D must be at least 3");
149 
150  public:
151  using Base_t::GridContainerIndicesBase2D;
152 
155 
157  bool hasZ(typename Base_t::CellDimIndex_t index) const
158  {
159  return Base_t::indices.template hasIndex<2>(index);
160  }
161 
163  size_t sizeZ() const { return Base_t::indices.template dim<2>(); }
164 
166 
167  }; // GridContainerIndicesBase3D
168 
171 
174 
175 } // namespace util
176 
177 #endif // LARDATA_UTILITIES_GRIDCONTAINERINDICES_H
static constexpr unsigned int dims()
Returns the number of dimensions in this object.
std::ptrdiff_t CellIndexOffset_t
type of difference between indices
size_t size() const
Returns the number of cells in the grid.
Base_t::LinIndex_t LinIndex_t
Type of the linear index.
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
CellIndexOffset_t CellDimIndex_t
type of difference between indices along a dimension
Index manager for a container of data arranged on a >=2-dim grid.
CellIndex_t index(CellID_t id) const
Returns the index of the element from its cell coordinates (no check!)
IndexManager_t indices
the actual worker
typename IndexManager_t::LinIndex_t CellIndex_t
type of index for direct access to the cell
TensorIndices class to flatten multi-dimension indices into linear.
std::array< CellDimIndex_t, dims()> CellID_t
type of cell coordinate (x, y, z)
size_t sizeZ() const
Returns the number of cells on the z axis of the grid.
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:250
Index manager for a container of data arranged on a DIMS-dimension grid.
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
bool hasZ(typename Base_t::CellDimIndex_t index) const
Returns whether the specified z index is valid.
bool hasX(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
Index manager for a container of data arranged on a >=3-dim grid.
CellIndexOffset_t offset(CellID_t const &origin, CellID_t const &cellID) const
Returns the difference in index of cellID respect to origin.
size_t sizeY() const
Returns the number of cells on the y axis of the grid.
bool hasLinIndex(LinIndex_t linIndex) const
Returns whether the specified linear index is valid in this tensor.
GridContainerIndicesBase(std::array< size_t, dims()> const &new_dims)
Constructor: specifies the size of the container and allocates it.
Index manager for a container of data arranged on a >=1-dim grid.
bool has(CellIndexOffset_t index) const
Returns whether the specified index is valid.
CellIndex_t operator[](CellID_t id) const
Returns the index of the element from its cell coordinates (no check!)
DimSize_t size() const
Returns the size of the minor tensor.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
bool hasY(typename Base_t::CellDimIndex_t index) const
Returns whether the specified y index is valid.
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:229
size_t sizeX() const
Returns the number of cells on the x axis of the grid.