11 #ifndef LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H 12 #define LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H 22 #include <initializer_list> 23 #include <type_traits> 27 template <
typename IDType,
typename Index = std::
size_t>
30 template <
typename Index = std::
size_t>
33 template <
typename Index = std::
size_t>
40 template <std::
size_t N,
typename T>
74 template <
typename IDType,
typename Index >
97 GeoIDmapper(std::initializer_list<unsigned int> dims);
110 template <std::
size_t Level>
111 unsigned int dimSize()
const;
114 static constexpr
unsigned int dimensions();
117 template <
typename GeoID = ID_t>
118 bool hasElement(GeoID
const&
id)
const;
121 template <
typename GeoID = ID_t>
122 GeoID firstID()
const;
125 template <
typename GeoID = ID_t>
126 GeoID lastID()
const;
162 void resize(std::initializer_list<unsigned int> dims);
170 template <
typename OIDType,
typename OIndex>
191 template <std::
size_t Level,
typename GeoID>
207 template <std::
size_t Level,
typename GeoID>
208 void fillID(GeoID&
id,
index_type index)
const;
211 template <std::
size_t Level,
typename GeoID>
212 bool hasElementLevel(GeoID
const&
id)
const;
218 template <
typename OIDType,
typename OIndex, std::size_t... Indices>
220 std::index_sequence<Indices...>);
224 template <std::
size_t Level,
typename Dims>
225 static index_type sizeLevel(Dims
const& dimSizes);
236 template <
typename Value,
typename Upper>
239 return (v >= 0) && (
static_cast<index_type>(v) < upper);
252 template <
typename Index >
264 using BaseMapper_t::BaseMapper_t;
279 using BaseMapper_t::resize;
289 void resize(
unsigned int nCryo,
unsigned int nTPCs) { BaseMapper_t::resize({nCryo, nTPCs}); }
317 template <
typename Index >
329 using BaseMapper_t::BaseMapper_t;
348 using BaseMapper_t::resize;
360 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
362 BaseMapper_t::resize({nCryo, nTPCs, nPlanes});
393 template <std::
size_t N,
typename T>
396 std::array<T, N> data;
397 std::copy(values.begin(), values.end(), data.begin());
404 template <
typename IDType,
typename Index>
411 template <
typename IDType,
typename Index>
419 template <
typename IDType,
typename Index>
426 template <
typename IDType,
typename Index>
433 template <
typename IDType,
typename Index>
434 template <std::
size_t Level>
444 template <
typename IDType,
typename Index>
451 template <
typename IDType,
typename Index>
452 template <
typename GeoID>
455 return hasElementLevel<GeoID::Level>(id);
459 template <
typename IDType,
typename Index>
460 template <
typename GeoID >
466 return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
470 template <
typename IDType,
typename Index>
471 template <
typename GeoID >
477 return GeoID(lastID<typename GeoID::ParentID_t>(),
fN[
GeoID::Level] - 1U);
481 template <
typename IDType,
typename Index>
484 return indexLevel<ID_t::Level>(id);
488 template <
typename IDType,
typename Index>
492 fillID<ID_t::Level>(
ID,
index);
497 template <
typename IDType,
typename Index>
504 template <
typename IDType,
typename Index>
511 template <
typename IDType,
typename Index>
514 fN = details::initializerListToArray<dimensions()>(dims);
518 template <
typename IDType,
typename Index>
519 template <
typename OIDType,
typename OIndex>
526 template <
typename IDType,
typename Index>
533 template <
typename IDType,
typename Index>
534 template <std::
size_t Level,
typename GeoID>
537 if constexpr (
Level == 0)
538 return id.template getIndex<0U>();
545 template <
typename IDType,
typename Index>
546 template <std::
size_t Level,
typename GeoID>
549 if constexpr (
Level == 0) {
550 id.template writeIndex<0U>() = index;
551 id.setValidity(index <
fN[0U]);
554 id.template writeIndex<Level>() = index %
fN[
Level];
560 template <
typename IDType,
typename Index>
561 template <std::
size_t Level,
typename GeoID>
564 if (!
bounded(
id.
template getIndex<Level>(),
fN[
Level]))
return false;
565 if constexpr (Level == 0U)
572 template <
typename IDType,
typename Index>
575 return sizeLevel<0U>(
fN);
579 template <
typename IDType,
typename Index>
580 template <
typename OIDType,
typename OIndex, std::size_t... Indices>
582 std::index_sequence<Indices...>)
586 "Can't resize a deeper mapping to a shallower one.");
587 resize({other.template dimSize<Indices>()...});
591 template <
typename IDType,
typename Index>
592 template <std::
size_t Level,
typename Dims>
598 return sizeLevel<(Level + 1U)>(dimSizes) * dimSizes[
Level];
603 #endif // LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H bool hasTPC(geo::TPCID const &tpcid) const
Returns whether this mapping covers the specified TPC.
void fillID(GeoID &id, index_type index) const
Fills the specified ID with its index.
void resize(unsigned int nCryo, unsigned int nTPCs)
Prepares the mapping for the specified sizes.
ID_t ID(index_type const index) const
Returns the ID corresponding to the specified linear index.
bool hasElementLevel(GeoID const &id) const
Returns whether all levels of id up to Level are within range.
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
index_type size() const
Returns the number of elements in the mapping.
index_type operator()(ID_t const &id) const
Returns the linear index corresponding to the specified ID.
void resizeAs(geo::GeoIDmapper< OIDType, OIndex > const &other)
Resizes the mapping to reflect the one from another mapping.
void resizeAsImpl(geo::GeoIDmapper< OIDType, OIndex > const &other, std::index_sequence< Indices... >)
Implementation for resizeAs().
GeoID firstID() const
Returns the ID of the first element with GeoID type.
The data type to uniquely identify a Plane.
void resize(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
Prepares the mapping for the specified sizes.
static bool bounded(Value v, Upper upper)
Returns whether the specified value is between 0 and the upper limit.
index_type computeSize() const
Computes the expected size of this mapping.
PlaneIDmapper(unsigned int nCryo, unsigned int nTPCs, unsigned int nPlanes)
Prepares the mapping with the specified sizes.
index_type indexLevel(GeoID const &id) const
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
Dimensions_t fN
Number of maximum entries per ID level.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
static index_type sizeLevel(Dims const &dimSizes)
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
TPCIDmapper(unsigned int nCryo, unsigned int nTPCs)
Prepares the mapping with the specified sizes.
unsigned int dimSize() const
Dimensions of the Level dimension of this mapping.
auto initializerListToArray(std::initializer_list< T > values)
Returns a STL array of size N filled with values from the argument.
The data type to uniquely identify a TPC.
GeoIDmapper()
Default constructor: all dimensions empty.
Definition of data types for geometry description.
Mapping for TPC identifiers.
GeoID lastID() const
Returns the ID of the last covered element with GeoID type.
bool hasElement(GeoID const &id) const
Returns whether this mapping hosts data for the specified ID.
bool empty() const
Returns whether the mapping has no elements (false by assumptions).
std::array< unsigned int, dimensions()> Dimensions_t
< Type of dimension sizes.
IDType ID_t
Type used as ID for this mapping.
static Dimensions_t zeroDimensions()
Initializer with zero size for each of the dimensions.
Index index_type
Type of flat index.
void resize(std::initializer_list< unsigned int > dims)
Resizes the mapping to accommodate the specified dimension sizes.
Mapping for sensitive plane identifiers.
index_type index(ID_t const &id) const
Returns the linear index corresponding to the specified ID.
bool hasPlane(geo::PlaneID const &planeid) const
Returns whether this mapping covers the specified plane.
Namespace collecting geometry-related classes utilities.
bool hasTPC(geo::TPCID const &tpcid) const
Returns whether this mapping covers the specified TPC.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
The data type to uniquely identify a cryostat.
void clear()
Sets all dimension sizes to 0.
Class managing the mapping between geometry/readout ID and flat index.