LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 
22 // LArSoft libraries
24 
25 // C/C++ standard libraries
26 #include <cstddef> // std::ptrdiff_t
27 #include <array>
28 
29 
30 namespace util {
31 
32  namespace details {
33 
35  template <unsigned int DIMS>
38  public:
39 
41  static constexpr unsigned int dims() { return DIMS; }
42 
45 
47  using CellIndexOffset_t = std::ptrdiff_t;
48 
51 
53  using CellID_t = std::array<CellDimIndex_t, dims()>;
54 
56  GridContainerIndicesBase(std::array<size_t, dims()> const& new_dims)
57  : indices(new_dims.begin())
58  {}
59 
62 
65  { return indices.hasLinIndex(index); }
66 
68  size_t size() const { return indices.size(); }
69 
71 
74 
76  CellIndex_t operator[] (CellID_t id) const { return index(id); }
77 
80  (CellID_t const& origin, CellID_t const& cellID) const
81  { return index(cellID) - index(origin); }
82 
84 
85  protected:
87 
90  { return indices(id.begin()); }
91 
92  }; // GridContainerIndicesBase
93 
94  } // namespace details
95 
96 
97 
99  template <unsigned int DIMS = 1U>
102  {
103  static_assert(DIMS >= 1U,
104  "Dimensions for GridContainerIndicesBase1D must be at least 1");
106 
107  public:
108 
109  using Base_t::GridContainerIndicesBase;
110 
113 
115  bool hasX(typename Base_t::CellDimIndex_t index) const
116  { return Base_t::indices.template hasIndex<0>(index); }
117 
119  size_t sizeX() const { return Base_t::indices.template dim<0>(); }
120 
122 
123  }; // GridContainerIndicesBase1D
124 
125 
127  template <unsigned int DIMS = 2U>
129  static_assert(DIMS >= 2U,
130  "Dimensions for GridContainerIndicesBase2D must be at least 2");
131 
133 
134  public:
135 
136  using Base_t::GridContainerIndicesBase1D;
137 
140 
142  bool hasY(typename Base_t::CellDimIndex_t index) const
143  { return Base_t::indices.template hasIndex<1>(index); }
144 
146  size_t sizeY() const { return Base_t::indices.template dim<1>(); }
147 
149 
150  }; // GridContainerIndicesBase2D
151 
152 
154  template <unsigned int DIMS = 3U>
156  static_assert(DIMS >= 3U,
157  "Dimensions for GridContainerIndicesBase3D must be at least 3");
159 
160  public:
161 
162  using Base_t::GridContainerIndicesBase2D;
163 
166 
168  bool hasZ(typename Base_t::CellDimIndex_t index) const
169  { return Base_t::indices.template hasIndex<2>(index); }
170 
172  size_t sizeZ() const { return Base_t::indices.template dim<2>(); }
173 
175 
176  }; // GridContainerIndicesBase3D
177 
178 
179 
182 
185 
186 
187 } // namespace util
188 
189 
190 
191 #endif // LARDATA_UTILITIES_GRIDCONTAINERINDICES_H
192 
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:17
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:228
Index manager for a container of data arranged on a DIMS-dimension grid.
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
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.
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:230
size_t sizeX() const
Returns the number of cells on the x axis of the grid.