LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
geo::GeoIDmapper< IDType, Index > Class Template Reference

Class managing the mapping between geometry/readout ID and flat index. More...

#include "GeometryIDmapper.h"

Public Types

using ID_t = IDType
 Type used as ID for this mapping. More...
 
using index_type = Index
 Type of flat index. More...
 

Public Member Functions

 GeoIDmapper ()
 Default constructor: all dimensions empty. More...
 
 GeoIDmapper (std::initializer_list< unsigned int > dims)
 Prepares the indexer. More...
 
template<std::size_t Level, typename GeoID >
auto indexLevel (GeoID const &id) const -> index_type
 
template<std::size_t Level, typename Dims >
auto sizeLevel (Dims const &dimSizes) -> index_type
 
Mapping transformations
index_type index (ID_t const &id) const
 Returns the linear index corresponding to the specified ID. More...
 
ID_t ID (index_type const index) const
 Returns the ID corresponding to the specified linear index. More...
 
index_type operator() (ID_t const &id) const
 Returns the linear index corresponding to the specified ID. More...
 
ID_t operator() (index_type const index) const
 Returns the ID corresponding to the specified linear index. More...
 
Mapping modification
void resize (std::initializer_list< unsigned int > dims)
 Resizes the mapping to accommodate the specified dimension sizes. More...
 
template<typename OIDType , typename OIndex >
void resizeAs (geo::GeoIDmapper< OIDType, OIndex > const &other)
 Resizes the mapping to reflect the one from another mapping. More...
 
void clear ()
 Sets all dimension sizes to 0. More...
 

Private Types

using Dimensions_t = std::array< unsigned int, dimensions()>
 < Type of dimension sizes. More...
 

Private Member Functions

template<std::size_t Level, typename GeoID >
index_type indexLevel (GeoID const &id) const
 
template<std::size_t Level, typename GeoID >
void fillID (GeoID &id, index_type index) const
 Fills the specified ID with its index. More...
 
template<std::size_t Level, typename GeoID >
bool hasElementLevel (GeoID const &id) const
 Returns whether all levels of id up to Level are within range. More...
 
index_type computeSize () const
 Computes the expected size of this mapping. More...
 
template<typename OIDType , typename OIndex , std::size_t... Indices>
void resizeAsImpl (geo::GeoIDmapper< OIDType, OIndex > const &other, std::index_sequence< Indices... >)
 Implementation for resizeAs(). More...
 

Static Private Member Functions

template<std::size_t Level, typename Dims >
static index_type sizeLevel (Dims const &dimSizes)
 
static Dimensions_t zeroDimensions ()
 Initializer with zero size for each of the dimensions. More...
 
template<typename Value , typename Upper >
static bool bounded (Value v, Upper upper)
 Returns whether the specified value is between 0 and the upper limit. More...
 

Private Attributes

Dimensions_t fN = zeroDimensions()
 Number of maximum entries per ID level. More...
 

Indexer status query

index_type size () const
 Returns the number of elements in the mapping. More...
 
bool empty () const
 Returns whether the mapping has no elements (false by assumptions). More...
 
template<std::size_t Level>
unsigned int dimSize () const
 Dimensions of the Level dimension of this mapping. More...
 
template<typename GeoID = ID_t>
bool hasElement (GeoID const &id) const
 Returns whether this mapping hosts data for the specified ID. More...
 
template<typename GeoID = ID_t>
GeoID firstID () const
 Returns the ID of the first element with GeoID type. More...
 
template<typename GeoID = ID_t>
GeoID lastID () const
 Returns the ID of the last covered element with GeoID type. More...
 
static constexpr unsigned int dimensions ()
 Dimensions of the ID of this mapping. More...
 

Detailed Description

template<typename IDType, typename Index>
class geo::GeoIDmapper< IDType, Index >

Class managing the mapping between geometry/readout ID and flat index.

Template Parameters
IDTypethe geometry or readout ID to be managed
Index(default: std::size_t) type of flat index

This class maps multi-level ID's (e.g. geo::WireID, readout::TPCsetID) into a single linear index.

The current implementation guarantees that the indices are ordered like their respective IDs, and that there are no gaps so that each index up to size() (excluded) corresponds to a "valid" ID. The range of valid IDs is a hyperbox so that all elements of a certain level have the same number of sub-elements (for examples, all planes have the same number of wires, all valid from the mapping point of view).

Note that this mapping is typically not suitable for channel mapping, since usually planes with different wire orientations may have different number of wires, making some of the indices that are valid from the point of view of this ID mapping invalid in that they match wires that do not exist and should not be assigned a channel number.

Definition at line 28 of file GeometryIDmapper.h.

Member Typedef Documentation

template<typename IDType, typename Index>
using geo::GeoIDmapper< IDType, Index >::Dimensions_t = std::array<unsigned int, dimensions()>
private

< Type of dimension sizes.

Definition at line 186 of file GeometryIDmapper.h.

template<typename IDType, typename Index>
using geo::GeoIDmapper< IDType, Index >::ID_t = IDType

Type used as ID for this mapping.

Definition at line 78 of file GeometryIDmapper.h.

template<typename IDType, typename Index>
using geo::GeoIDmapper< IDType, Index >::index_type = Index

Type of flat index.

Definition at line 79 of file GeometryIDmapper.h.

Constructor & Destructor Documentation

template<typename IDType , typename Index >
geo::GeoIDmapper< IDType, Index >::GeoIDmapper ( )

Default constructor: all dimensions empty.

See also
resize()

The indexer must be resized before being of any use.

Definition at line 405 of file GeometryIDmapper.h.

406 {
407  fN.fill(0U);
408 }
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
geo::GeoIDmapper< IDType, Index >::GeoIDmapper ( std::initializer_list< unsigned int >  dims)

Prepares the indexer.

Parameters
dimsnumber of elements on all levels of the mapping
See also
resize()

The size of each dimension is specified by the corresponding number, starting from the size of the outer dimension (cryostat).

Definition at line 412 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::dimensions().

414 {
415  assert(dims.size() == dimensions()); // can't be static
416 }
Dimensions_t fN
Number of maximum entries per ID level.
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
auto initializerListToArray(std::initializer_list< T > values)
Returns a STL array of size N filled with values from the argument.

Member Function Documentation

template<typename IDType, typename Index>
template<typename Value , typename Upper >
static bool geo::GeoIDmapper< IDType, Index >::bounded ( Value  v,
Upper  upper 
)
inlinestaticprivate

Returns whether the specified value is between 0 and the upper limit.

Definition at line 237 of file GeometryIDmapper.h.

Referenced by geo::GeoIDmapper< IDType, Index >::hasElementLevel().

238  {
239  return (v >= 0) && (static_cast<index_type>(v) < upper);
240  }
Index index_type
Type of flat index.
template<typename IDType , typename Index >
void geo::GeoIDmapper< IDType, Index >::clear ( )

Sets all dimension sizes to 0.

See also
resize()

The mapping needs to be resized before it is useful again.

Definition at line 527 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::fN.

528 {
529  fN.fill(0U);
530 } // geo::GeoIDmapper<>::clear()
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::computeSize ( ) const
private

Computes the expected size of this mapping.

Definition at line 573 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::fN.

Referenced by geo::GeoIDmapper< IDType, Index >::size().

574 {
575  return sizeLevel<0U>(fN);
576 }
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
constexpr unsigned int geo::GeoIDmapper< IDType, Index >::dimensions ( )
static
template<typename IDType , typename Index >
template<std::size_t Level>
unsigned int geo::GeoIDmapper< IDType, Index >::dimSize ( ) const

Dimensions of the Level dimension of this mapping.

Definition at line 435 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::dimensions(), and geo::GeoIDmapper< IDType, Index >::fN.

436 {
437  if constexpr (Level >= dimensions())
438  return 0U; // technically it would be 1...
439  else
440  return fN[Level];
441 } // geo::GeoIDmapper<>::dimSize()
Level
Definition: Level.h:13
Dimensions_t fN
Number of maximum entries per ID level.
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
template<typename IDType , typename Index >
bool geo::GeoIDmapper< IDType, Index >::empty ( ) const

Returns whether the mapping has no elements (false by assumptions).

Definition at line 427 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::size().

428 {
429  return size() == index_type{0};
430 }
index_type size() const
Returns the number of elements in the mapping.
Index index_type
Type of flat index.
template<typename IDType , typename Index >
template<std::size_t Level, typename GeoID >
void geo::GeoIDmapper< IDType, Index >::fillID ( GeoID &  id,
index_type  index 
) const
private

Fills the specified ID with its index.

Template Parameters
Levelthe level of the index to fill (0 for cryostat level, etc._
GeoIDtype of ID to be filled
Parameters
idthe ID to be filled
indexthe index corresponding to the ID
See also
indexLevel(), index()

Fills the specified ID with its index. This can be considered the inverse operation of the index() method. The index argument is local to the level to be filled, e.g. for cryostats it goes from 0 to the number of cryostats.

Definition at line 547 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::fN.

548 {
549  if constexpr (Level == 0) {
550  id.template writeIndex<0U>() = index;
551  id.setValidity(index < fN[0U]);
552  }
553  else {
554  id.template writeIndex<Level>() = index % fN[Level];
555  fillID<(Level - 1U)>(id, index / fN[Level]);
556  }
557 } // geo::GeoIDmapper<>::fillID()
void fillID(GeoID &id, index_type index) const
Fills the specified ID with its index.
Level
Definition: Level.h:13
Dimensions_t fN
Number of maximum entries per ID level.
index_type index(ID_t const &id) const
Returns the linear index corresponding to the specified ID.
template<typename IDType , typename Index >
template<typename GeoID >
GeoID geo::GeoIDmapper< IDType, Index >::firstID ( ) const

Returns the ID of the first element with GeoID type.

Definition at line 461 of file GeometryIDmapper.h.

462 {
463  if constexpr (GeoID::Level == 0)
464  return GeoID(0U);
465  else
466  return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
467 } // geo::GeoIDmapper<>::firstID()
GeoID firstID() const
Returns the ID of the first element with GeoID type.
Level
Definition: Level.h:13
template<typename IDType , typename Index >
template<typename GeoID >
bool geo::GeoIDmapper< IDType, Index >::hasElement ( GeoID const &  id) const

Returns whether this mapping hosts data for the specified ID.

Definition at line 453 of file GeometryIDmapper.h.

454 {
455  return hasElementLevel<GeoID::Level>(id);
456 }
template<typename IDType , typename Index >
template<std::size_t Level, typename GeoID >
bool geo::GeoIDmapper< IDType, Index >::hasElementLevel ( GeoID const &  id) const
private

Returns whether all levels of id up to Level are within range.

Definition at line 562 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::bounded(), and geo::GeoIDmapper< IDType, Index >::fN.

563 {
564  if (!bounded(id.template getIndex<Level>(), fN[Level])) return false;
565  if constexpr (Level == 0U)
566  return true;
567  else
568  return hasElementLevel<(Level - 1U)>(id);
569 } // geo::GeoIDmapper<>::hasElementLevel()
bool hasElementLevel(GeoID const &id) const
Returns whether all levels of id up to Level are within range.
Level
Definition: Level.h:13
static bool bounded(Value v, Upper upper)
Returns whether the specified value is between 0 and the upper limit.
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::ID ( index_type const  index) const

Returns the ID corresponding to the specified linear index.

Definition at line 489 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::index().

Referenced by geo::GeoIDmapper< IDType, Index >::operator()().

490 {
491  ID_t ID;
492  fillID<ID_t::Level>(ID, index);
493  return ID;
494 } // geo::GeoIDmapper<>::ID()
ID_t ID(index_type const index) const
Returns the ID corresponding to the specified linear index.
IDType ID_t
Type used as ID for this mapping.
index_type index(ID_t const &id) const
Returns the linear index corresponding to the specified ID.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::index ( ID_t const &  id) const

Returns the linear index corresponding to the specified ID.

Definition at line 482 of file GeometryIDmapper.h.

Referenced by geo::GeoIDmapper< IDType, Index >::ID(), and geo::GeoIDmapper< IDType, Index >::operator()().

483 {
484  return indexLevel<ID_t::Level>(id);
485 }
template<typename IDType, typename Index>
template<std::size_t Level, typename GeoID >
index_type geo::GeoIDmapper< IDType, Index >::indexLevel ( GeoID const &  id) const
private
template<typename IDType, typename Index>
template<std::size_t Level, typename GeoID >
auto geo::GeoIDmapper< IDType, Index >::indexLevel ( GeoID const &  id) const -> index_type

Definition at line 535 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::fN, and geo::GeoIDmapper< IDType, Index >::indexLevel().

536 {
537  if constexpr (Level == 0)
538  return id.template getIndex<0U>();
539  else {
540  return indexLevel<(Level - 1U)>(id) * fN[Level] + id.template getIndex<Level>();
541  }
542 } // geo::GeoIDmapper<>::indexLevel()
Level
Definition: Level.h:13
index_type indexLevel(GeoID const &id) const
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
template<typename GeoID >
GeoID geo::GeoIDmapper< IDType, Index >::lastID ( ) const

Returns the ID of the last covered element with GeoID type.

Definition at line 472 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::fN.

473 {
474  if constexpr (GeoID::Level == 0)
475  return GeoID(fN[GeoID::Level] - 1U);
476  else
477  return GeoID(lastID<typename GeoID::ParentID_t>(), fN[GeoID::Level] - 1U);
478 } // geo::GeoIDmapper<>::lastID()
Level
Definition: Level.h:13
Dimensions_t fN
Number of maximum entries per ID level.
GeoID lastID() const
Returns the ID of the last covered element with GeoID type.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::operator() ( ID_t const &  id) const

Returns the linear index corresponding to the specified ID.

Definition at line 498 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::index().

499 {
500  return index(id);
501 }
index_type index(ID_t const &id) const
Returns the linear index corresponding to the specified ID.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::operator() ( index_type const  index) const

Returns the ID corresponding to the specified linear index.

Definition at line 505 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::ID(), and geo::GeoIDmapper< IDType, Index >::index().

506 {
507  return ID(index);
508 }
ID_t ID(index_type const index) const
Returns the ID corresponding to the specified linear index.
index_type index(ID_t const &id) const
Returns the linear index corresponding to the specified ID.
template<typename IDType , typename Index >
void geo::GeoIDmapper< IDType, Index >::resize ( std::initializer_list< unsigned int >  dims)

Resizes the mapping to accommodate the specified dimension sizes.

Parameters
dimsnumber of elements on all levels of the mapping
See also
resizeAs()

The size of each dimension is specified by the corresponding number, starting from the size of the outer dimension (cryostat).

Definition at line 512 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::fN.

Referenced by geo::GeoIDmapper< IDType, Index >::resizeAsImpl().

513 {
514  fN = details::initializerListToArray<dimensions()>(dims);
515 } // geo::GeoIDmapper<>::resize()
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
template<typename OIDType , typename OIndex >
void geo::GeoIDmapper< IDType, Index >::resizeAs ( geo::GeoIDmapper< OIDType, OIndex > const &  other)

Resizes the mapping to reflect the one from another mapping.

Parameters
otherID mapping to take dimensions from

The size of each dimension is taken by the matching one in other.

Definition at line 520 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::dimensions(), and geo::GeoIDmapper< IDType, Index >::resizeAsImpl().

521 {
522  resizeAsImpl(other, std::make_index_sequence<dimensions()>{});
523 } // geo::GeoIDmapper<>::resizeAs()
void resizeAsImpl(geo::GeoIDmapper< OIDType, OIndex > const &other, std::index_sequence< Indices... >)
Implementation for resizeAs().
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
template<typename IDType , typename Index >
template<typename OIDType , typename OIndex , std::size_t... Indices>
void geo::GeoIDmapper< IDType, Index >::resizeAsImpl ( geo::GeoIDmapper< OIDType, OIndex > const &  other,
std::index_sequence< Indices... >   
)
private

Implementation for resizeAs().

Definition at line 581 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::dimensions(), and geo::GeoIDmapper< IDType, Index >::resize().

Referenced by geo::GeoIDmapper< IDType, Index >::resizeAs().

583 {
584  // Clang 5.0.1 does not understand `other.dimensions()` is constexpr
586  "Can't resize a deeper mapping to a shallower one.");
587  resize({other.template dimSize<Indices>()...});
588 } // geo::GeoIDmapper<>::resizeAsImpl()
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
void resize(std::initializer_list< unsigned int > dims)
Resizes the mapping to accommodate the specified dimension sizes.
Class managing the mapping between geometry/readout ID and flat index.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::size ( ) const

Returns the number of elements in the mapping.

Definition at line 420 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::computeSize().

Referenced by geo::GeoIDmapper< IDType, Index >::empty().

421 {
422  return computeSize();
423 }
index_type computeSize() const
Computes the expected size of this mapping.
template<typename IDType, typename Index>
template<std::size_t Level, typename Dims >
static index_type geo::GeoIDmapper< IDType, Index >::sizeLevel ( Dims const &  dimSizes)
staticprivate

Returns the number of elements at the specified Level.

Parameters
dimSizesthe sizes of each of the levels
template<typename IDType, typename Index>
template<std::size_t Level, typename Dims >
auto geo::GeoIDmapper< IDType, Index >::sizeLevel ( Dims const &  dimSizes) -> index_type

Definition at line 593 of file GeometryIDmapper.h.

References geo::GeoIDmapper< IDType, Index >::dimensions().

594 {
595  if constexpr (Level >= dimensions())
596  return 1U;
597  else
598  return sizeLevel<(Level + 1U)>(dimSizes) * dimSizes[Level];
599 } // geo::GeoIDmapper<>::sizeLevel()
Level
Definition: Level.h:13
static index_type sizeLevel(Dims const &dimSizes)
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
template<typename IDType, typename Index>
static Dimensions_t geo::GeoIDmapper< IDType, Index >::zeroDimensions ( )
inlinestaticprivate

Initializer with zero size for each of the dimensions.

Definition at line 228 of file GeometryIDmapper.h.

229  {
230  Dimensions_t dims;
231  dims.fill(0);
232  return dims;
233  }
std::array< unsigned int, dimensions()> Dimensions_t
< Type of dimension sizes.

Member Data Documentation


The documentation for this class was generated from the following file: