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>
116 unsigned int dimSize()
const;
122 template <
typename GeoID = ID_t>
123 bool hasElement(GeoID
const&
id)
const;
126 template <
typename GeoID = ID_t>
127 GeoID firstID()
const;
130 template <
typename GeoID = ID_t>
131 GeoID lastID()
const;
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>
223 bool hasElementLevel(GeoID
const&
id)
const;
230 template<
typename OIDType,
typename OIndex, std::size_t... Indices>
233 std::index_sequence<Indices...>
238 template <std::
size_t Level,
typename Dims>
239 static index_type sizeLevel(Dims
const& dimSizes);
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)
316 {
return BaseMapper_t::hasElement(cryoid); }
320 {
return BaseMapper_t::hasElement(tpcid); }
336 template <
typename Index >
350 using BaseMapper_t::BaseMapper_t;
382 void resize(
unsigned int nCryo,
unsigned int nTPCs,
unsigned int nPlanes)
395 {
return BaseMapper_t::hasElement(cryoid); }
399 {
return BaseMapper_t::hasElement(tpcid); }
403 {
return BaseMapper_t::hasElement(planeid); }
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>
465 else return fN[
Level];
470 template <
typename IDType,
typename Index>
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 >
487 else return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
492 template <
typename IDType,
typename Index>
493 template <
typename GeoID >
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>
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];
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>
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.
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
void resize(Vector< T > &vec1, Index n1, const V &val)
bool hasCryostat(geo::CryostatID const &cryoid) const
Returns whether this mapping covers the specified cryostat.
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
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.
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.
vector< vector< double > > clear
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.
LArSoft geometry interface.
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.