LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
GridContainers.h
Go to the documentation of this file.
1 
16 #ifndef LARDATA_UTILITIES_GRIDCONTAINERS_H
17 #define LARDATA_UTILITIES_GRIDCONTAINERS_H
18 
19 // LArSoft libraries
21 
22 // C/C++ standard libraries
23 #include <vector>
24 #include <array>
25 
26 
27 namespace util {
28 
29  namespace details {
30 
41  template <typename DATUM, typename IXMAN>
43 
44  public:
45  using Datum_t = DATUM;
46  using Indexer_t = IXMAN;
47 
49 
50 
51  static constexpr unsigned int dims() { return IXMAN::dims(); }
52 
54  using CellIndex_t = typename Indexer_t::CellIndex_t;
55 
57  using CellIndexOffset_t = typename Indexer_t::CellIndexOffset_t;
58 
60  using CellDimIndex_t = typename Indexer_t::CellDimIndex_t;
61 
63  using CellID_t = typename Indexer_t::CellID_t;
64 
66  using Cell_t = std::vector<Datum_t>;
67 
69  using Cells_t = std::vector<Cell_t>;
70 
73 
76  : indices(dims)
77  , data(indices.size())
78  {}
79 
82 
84  size_t size() const { return indices.size(); }
85 
87  bool has(CellIndexOffset_t index) const { return indices.has(index); }
88 
90 
93 
95  CellIndex_t index(CellID_t const& id) const { return indices[id]; }
96 
99  (CellID_t const& origin, CellID_t const& cellID) const
100  { return indices.offset(origin, cellID); }
101 
103  Cell_t& operator[] (CellID_t const& id) { return cell(id); }
104 
106  Cell_t const& operator[] (CellID_t const& id) const { return cell(id); }
107 
110 
112  Cell_t const& operator[] (CellIndex_t index) const { return data[index]; }
113 
115 
118 
120  void insert(CellID_t const& cellID, Datum_t const& elem)
121  { cell(cellID).push_back(elem); }
122 
124  void insert(CellID_t const& cellID, Datum_t&& elem)
125  { cell(cellID).push_back(std::move(elem)); }
126 
128  void insert(CellIndex_t index, Datum_t const& elem)
129  { data[index].push_back(elem); }
130 
133  { data[index].push_back(std::move(elem)); }
134 
136 
138  Indexer_t const& indexManager() const { return indices; }
139 
140 
141  protected:
143 
145 
147  Cell_t& cell(CellID_t const& cellID)
148  { return data[index(cellID)]; }
149 
151  Cell_t const& cell(CellID_t const& cellID) const
152  { return data[index(cellID)]; }
153 
154  }; // GridContainerBase<>
155 
156  } // namespace details
157 
158 
166  template <typename DATUM, typename IXMAN>
167  class GridContainerBase1D: public details::GridContainerBase<DATUM, IXMAN> {
169  static_assert(Base_t::dims() >= 1,
170  "GridContainerBase1D must have dimensions 1 or larger.");
171 
172  public:
173 
174  using Base_t::GridContainerBase;
175 
178 
180  bool hasX(typename Base_t::CellDimIndex_t index) const
181  { return Base_t::indices.hasX(index); }
182 
184  size_t sizeX() const { return Base_t::indices.sizeX(); }
185 
187 
188  protected:
189  }; // GridContainerBase1D<>
190 
191 
199  template <typename DATUM, typename IXMAN>
200  class GridContainerBase2D: public GridContainerBase1D<DATUM, IXMAN> {
202  static_assert(Base_t::dims() >= 2,
203  "GridContainerBase2D must have dimensions 2 or larger.");
204 
205  public:
206 
207  using Base_t::GridContainerBase1D;
208 
211 
213  size_t sizeY() const { return Base_t::indices.sizeY(); }
214 
216  bool hasY(typename Base_t::CellDimIndex_t index) const
217  { return Base_t::indices.hasY(index); }
218 
220 
221  protected:
222  }; // GridContainerBase2D<>
223 
224 
232  template <typename DATUM, typename IXMAN>
233  class GridContainerBase3D: public GridContainerBase2D<DATUM, IXMAN> {
235  static_assert(Base_t::dims() >= 3,
236  "GridContainerBase3D must have dimensions 3 or larger.");
237 
238  public:
239 
240  using Base_t::GridContainerBase2D;
241 
244 
246  size_t sizeZ() const { return Base_t::indices.sizeZ(); }
247 
249  bool hasZ(typename Base_t::CellDimIndex_t index) const
250  { return Base_t::indices.hasZ(index); }
251 
253 
254  protected:
255  }; // GridContainerBase3D<>
256 
257 
266  template <typename DATUM>
268 
269 
278  template <typename DATUM>
280 
281 } // namespace util
282 
283 
284 #endif // LARDATA_UTILITIES_GRIDCONTAINERS_H
CellIndexOffset_t indexOffset(CellID_t const &origin, CellID_t const &cellID) const
Returns the difference in index from two cells.
static constexpr unsigned int dims()
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
Cells_t data
organised collection of points
bool hasX(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
bool hasZ(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
size_t sizeX() const
Returns the size of the container in the first dimension (x)
Cell_t & cell(CellID_t const &cellID)
Returns a reference to the specified cell.
Indexer_t const & indexManager() const
Returns the index manager of the grid.
std::vector< Datum_t > Cell_t
type of a single cell container
typename Cells_t::const_iterator const_iterator
type of iterator to all cells
size_t sizeY() const
Returns the size of the container in the second dimension (y)
size_t sizeZ() const
Returns the size of the container in the third dimension (z)
GridContainerBase(std::array< size_t, dims()> const &dims)
Constructor: specifies the size of the container and allocates it.
void insert(CellID_t const &cellID, Datum_t const &elem)
Copies an element into the specified cell.
std::vector< Cell_t > Cells_t
type of container holding all cells
Cell_t & operator[](CellID_t const &id)
Returns a reference to the specified cell.
typename Indexer_t::CellID_t CellID_t
type of cell coordinate (x, y, z)
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
intermediate_table::const_iterator const_iterator
Indexer_t indices
manager of the indices of the container
Base class for a container of data arranged on a grid.
typename Indexer_t::CellIndex_t CellIndex_t
type of index for direct access to the cell
Base class for a container of data arranged on a 2D-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.
typename Indexer_t::CellIndexOffset_t CellIndexOffset_t
type of difference between indices
Cell_t const & cell(CellID_t const &cellID) const
Returns a constant reference to the specified cell.
typename Indexer_t::CellDimIndex_t CellDimIndex_t
type of difference between indices
void insert(CellID_t const &cellID, Datum_t &&elem)
Moves an element into the specified cell.
bool has(CellIndexOffset_t index) const
Returns whether the specified index is valid.
void insert(CellIndex_t index, Datum_t &&elem)
Moves an element into the cell with the specified index.
CellIndex_t index(CellID_t const &id) const
Return the index of the element from its cell coordinates (no check!)
void insert(CellIndex_t index, Datum_t const &elem)
Copies an element into the cell with the specified index.
Base class for a container of data arranged on a 1D-grid.
bool hasY(typename Base_t::CellDimIndex_t index) const
Returns whether the specified x index is valid.
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:230
Base class for a container of data arranged on a 3D-grid.
Classes to manage containers with indices in 1, 2 and 3 dimensions.
size_t size() const
Returns the total size of the container.