11 #ifndef LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H
12 #define LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H
19 #include <initializer_list>
21 #include <type_traits>
28 template <
typename IDType,
typename Index = std::
size_t>
31 template <
typename Index = std::
size_t>
34 template <
typename Index = std::
size_t>
41 template <std::
size_t N,
typename T>
76 template <
typename IDType,
typename Index >
101 GeoIDmapper(std::initializer_list<unsigned int> dims);
115 template <std::
size_t Level>
122 template <
typename GeoID = ID_t>
126 template <
typename GeoID = ID_t>
130 template <
typename GeoID = ID_t>
169 void resize(std::initializer_list<unsigned int> dims);
177 template <
typename OIDType,
typename OIndex>
202 template <std::
size_t Level,
typename GeoID>
218 template <std::
size_t Level,
typename GeoID>
222 template <std::
size_t Level,
typename GeoID>
230 template<
typename OIDType,
typename OIndex, std::size_t... Indices>
233 std::index_sequence<Indices...>
238 template <std::
size_t Level,
typename Dims>
246 template <
typename Value,
typename Upper>
248 {
return (v >= 0) && (
static_cast<index_type>(v) < upper); }
261 template <
typename Index >
275 using BaseMapper_t::BaseMapper_t;
303 void resize(
unsigned int nCryo,
unsigned int nTPCs)
336 template <
typename Index >
350 using BaseMapper_t::BaseMapper_t;
382 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
420 template <std::
size_t N,
typename T>
422 std::array<T, N> data;
423 std::copy(values.begin(), values.end(), data.begin());
431 template <
typename IDType,
typename Index>
439 template <
typename IDType,
typename Index>
441 (std::initializer_list<unsigned int> dims)
449 template <
typename IDType,
typename Index>
451 {
return computeSize(); }
455 template <
typename IDType,
typename Index>
461 template <
typename IDType,
typename Index>
462 template <std::
size_t Level>
464 if constexpr (Level >=
dimensions())
return 0U;
465 else return fN[Level];
470 template <
typename IDType,
typename Index>
472 {
return IDType::Level + 1; }
476 template <
typename IDType,
typename Index>
477 template <
typename GeoID>
479 {
return hasElementLevel<GeoID::Level>(id); }
483 template <
typename IDType,
typename Index>
484 template <
typename GeoID >
486 if constexpr (GeoID::Level == 0)
return GeoID(0U);
487 else return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
492 template <
typename IDType,
typename Index>
493 template <
typename GeoID >
495 if constexpr (GeoID::Level == 0)
return GeoID(fN[GeoID::Level] - 1U);
497 return GeoID(lastID<typename GeoID::ParentID_t>(), fN[GeoID::Level] - 1U);
502 template <
typename IDType,
typename Index>
504 {
return indexLevel<ID_t::Level>(id); }
508 template <
typename IDType,
typename Index>
512 fillID<ID_t::Level>(ID, index);
518 template <
typename IDType,
typename Index>
521 {
return index(
id); }
525 template <
typename IDType,
typename Index>
528 {
return ID(index); }
532 template <
typename IDType,
typename Index>
534 (std::initializer_list<unsigned int> dims)
536 fN = details::initializerListToArray<dimensions()>(dims);
541 template <
typename IDType,
typename Index>
542 template <
typename OIDType,
typename OIndex>
546 resizeAsImpl(other, std::make_index_sequence<
dimensions()>{});
551 template <
typename IDType,
typename Index>
558 template <
typename IDType,
typename Index>
559 template <std::
size_t Level,
typename GeoID>
563 if constexpr (Level == 0)
return id.template getIndex<0U>();
566 indexLevel<(Level-1U)>(
id) * fN[Level] +
id.template getIndex<Level>();
572 template <
typename IDType,
typename Index>
573 template <std::
size_t Level,
typename GeoID>
576 if constexpr (Level == 0) {
577 id.template writeIndex<0U>() = index;
578 id.setValidity(index < fN[0U]);
581 id.template writeIndex<Level>() = index % fN[Level];
582 fillID<(Level-1U)>(
id, index / fN[Level]);
588 template <
typename IDType,
typename Index>
589 template <std::
size_t Level,
typename GeoID>
592 if (!bounded(
id.
template getIndex<Level>(), fN[Level]))
return false;
593 if constexpr (Level == 0U)
return true;
594 else return hasElementLevel<(Level-1U)>(
id);
599 template <
typename IDType,
typename Index>
601 {
return sizeLevel<0U>(fN); }
605 template <
typename IDType,
typename Index>
606 template<
typename OIDType,
typename OIndex, std::size_t... Indices>
609 std::index_sequence<Indices...>
614 "Can't resize a deeper mapping to a shallower one.");
615 resize({ other.template dimSize<Indices>()... });
620 template <
typename IDType,
typename Index>
621 template <std::
size_t Level,
typename Dims>
625 if constexpr (Level >=
dimensions())
return 1U;
626 else return sizeLevel<(Level+1U)>(dimSizes) * dimSizes[Level];
633 #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.
void resizeAsImpl(geo::GeoIDmapper< OIDType, OIndex > const &other, std::index_sequence< Indices...>)
Implementation for resizeAs().
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.
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.
std::size_t size(FixedBins< T, C > const &) noexcept
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.
static index_type sizeLevel(Dims const &dimSizes)
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.
geo::TPCID 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.
bool hasTPC(geo::TPCID const &tpcid) const
Returns whether this mapping covers the specified TPC.
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.