9 #ifndef LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H 10 #define LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H 20 #include <initializer_list> 21 #include <type_traits> 25 template <
typename IDType,
typename Index = std::
size_t>
28 template <
typename Index = std::
size_t>
31 template <
typename Index = std::
size_t>
38 template <std::
size_t N,
typename T>
72 template <
typename IDType,
typename Index >
95 GeoIDmapper(std::initializer_list<unsigned int> dims);
108 template <std::
size_t Level>
109 unsigned int dimSize()
const;
112 static constexpr
unsigned int dimensions();
115 template <
typename GeoID = ID_t>
116 bool hasElement(GeoID
const&
id)
const;
119 template <
typename GeoID = ID_t>
120 GeoID firstID()
const;
123 template <
typename GeoID = ID_t>
124 GeoID lastID()
const;
160 void resize(std::initializer_list<unsigned int> dims);
168 template <
typename OIDType,
typename OIndex>
189 template <std::
size_t Level,
typename GeoID>
205 template <std::
size_t Level, std::
size_t N>
206 void fillID(std::array<unsigned int, N>&
id,
index_type index)
const;
209 template <std::
size_t Level,
typename GeoID>
210 bool hasElementLevel(GeoID
const&
id)
const;
216 template <
typename OIDType,
typename OIndex, std::size_t... Indices>
221 template <std::
size_t Level,
typename Dims>
222 static index_type sizeLevel(Dims
const& dimSizes);
233 template <
typename Value,
typename Upper>
236 return (v >= 0) && (
static_cast<index_type>(v) < upper);
249 template <
typename Index >
261 using BaseMapper_t::BaseMapper_t;
276 using BaseMapper_t::resize;
286 void resize(
unsigned int nCryo,
unsigned int nTPCs) { BaseMapper_t::resize({nCryo, nTPCs}); }
299 bool hasTPC(
TPCID const& tpcid)
const {
return BaseMapper_t::hasElement(tpcid); }
314 template <
typename Index >
326 using BaseMapper_t::BaseMapper_t;
345 using BaseMapper_t::resize;
357 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
359 BaseMapper_t::resize({nCryo, nTPCs, nPlanes});
373 bool hasTPC(
TPCID const& tpcid)
const {
return BaseMapper_t::hasElement(tpcid); }
376 bool hasPlane(
PlaneID const& planeid)
const {
return BaseMapper_t::hasElement(planeid); }
390 template <std::
size_t N,
typename T>
393 std::array<T, N> data{};
394 std::copy(values.begin(), values.end(), data.begin());
401 template <
typename IDType,
typename Index>
408 template <
typename IDType,
typename Index>
416 template <
typename IDType,
typename Index>
423 template <
typename IDType,
typename Index>
430 template <
typename IDType,
typename Index>
431 template <std::
size_t Level>
441 template <
typename IDType,
typename Index>
448 template <
typename IDType,
typename Index>
449 template <
typename GeoID>
452 return hasElementLevel<GeoID::Level>(id);
456 template <
typename IDType,
typename Index>
457 template <
typename GeoID >
463 return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
467 template <
typename IDType,
typename Index>
468 template <
typename GeoID >
474 return GeoID(lastID<typename GeoID::ParentID_t>(),
fN[
GeoID::Level] - 1U);
478 template <
typename IDType,
typename Index>
481 return indexLevel<ID_t::Level>(id);
485 template <
typename IDType,
typename Index>
488 std::array<unsigned int, ID_t::Level + 1u> numbers;
489 fillID<ID_t::Level>(numbers,
index);
490 auto id = std::make_from_tuple<ID_t>(numbers);
491 id.setValidity(
id.Cryostat <
fN[0u]);
496 template <
typename IDType,
typename Index>
503 template <
typename IDType,
typename Index>
510 template <
typename IDType,
typename Index>
513 fN = details::initializerListToArray<dimensions()>(dims);
517 template <
typename IDType,
typename Index>
518 template <
typename OIDType,
typename OIndex>
525 template <
typename IDType,
typename Index>
532 template <
typename IDType,
typename Index>
533 template <std::
size_t Level,
typename GeoID>
536 if constexpr (
Level == 0)
537 return id.template getIndex<0U>();
544 template <
typename IDType,
typename Index>
545 template <std::
size_t Level, std::
size_t N>
549 if constexpr (
Level == 0) { numbers[0] =
index; }
557 template <
typename IDType,
typename Index>
558 template <std::
size_t Level,
typename GeoID>
561 if (!
bounded(
id.
template getIndex<Level>(),
fN[
Level]))
return false;
562 if constexpr (Level == 0U)
569 template <
typename IDType,
typename Index>
572 return sizeLevel<0U>(
fN);
576 template <
typename IDType,
typename Index>
577 template <
typename OIDType,
typename OIndex, std::size_t... Indices>
579 std::index_sequence<Indices...>)
583 "Can't resize a deeper mapping to a shallower one.");
584 resize({other.template dimSize<Indices>()...});
588 template <
typename IDType,
typename Index>
589 template <std::
size_t Level,
typename Dims>
595 return sizeLevel<(Level + 1U)>(dimSizes) * dimSizes[
Level];
600 #endif // LARCOREALG_GEOMETRY_GEOMETRYIDMAPPER_H void resizeAs(GeoIDmapper< OIDType, OIndex > const &other)
Resizes the mapping to reflect the one from another mapping.
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 hasTPC(TPCID const &tpcid) const
Returns whether this mapping covers the specified TPC.
void resizeAsImpl(GeoIDmapper< OIDType, OIndex > const &other, std::index_sequence< Indices... >)
Implementation for resizeAs().
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.
GeoID firstID() const
Returns the ID of the first element with GeoID type.
The data type to uniquely identify a Plane.
bool hasCryostat(CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
bool hasTPC(TPCID const &tpcid) const
Returns whether this mapping covers the specified TPC.
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 hasPlane(PlaneID const &planeid) const
Returns whether this mapping covers the specified plane.
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.
bool hasCryostat(CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
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.
void fillID(std::array< unsigned int, N > &id, index_type index) const
Fills the specified ID with its index.
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.