LArSoft  v10_04_05
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 (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, std::size_t N>
void fillID (std::array< unsigned int, N > &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 (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 26 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 184 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 76 of file GeometryIDmapper.h.

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

Type of flat index.

Definition at line 77 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 402 of file GeometryIDmapper.h.

403 {
404  fN.fill(0U);
405 }
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 409 of file GeometryIDmapper.h.

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

411 {
412  assert(dims.size() == dimensions()); // can't be static
413 }
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 234 of file GeometryIDmapper.h.

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

235  {
236  return (v >= 0) && (static_cast<index_type>(v) < upper);
237  }
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 526 of file GeometryIDmapper.h.

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

527 {
528  fN.fill(0U);
529 }
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 570 of file GeometryIDmapper.h.

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

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

571 {
572  return sizeLevel<0U>(fN);
573 }
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 432 of file GeometryIDmapper.h.

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

433 {
434  if constexpr (Level >= dimensions())
435  return 0U; // technically it would be 1...
436  else
437  return fN[Level];
438 }
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 424 of file GeometryIDmapper.h.

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

425 {
426  return size() == index_type{0};
427 }
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, std::size_t N>
void geo::GeoIDmapper< IDType, Index >::fillID ( std::array< unsigned int, N > &  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 546 of file GeometryIDmapper.h.

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

548 {
549  if constexpr (Level == 0) { numbers[0] = index; }
550  else {
551  numbers[Level] = index % fN[Level];
552  fillID<Level - 1U>(numbers, index / fN[Level]);
553  }
554 }
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.
void fillID(std::array< unsigned int, N > &id, index_type index) const
Fills the specified ID with its index.
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 458 of file GeometryIDmapper.h.

459 {
460  if constexpr (GeoID::Level == 0)
461  return GeoID(0U);
462  else
463  return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
464 }
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 450 of file GeometryIDmapper.h.

451 {
452  return hasElementLevel<GeoID::Level>(id);
453 }
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 559 of file GeometryIDmapper.h.

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

560 {
561  if (!bounded(id.template getIndex<Level>(), fN[Level])) return false;
562  if constexpr (Level == 0U)
563  return true;
564  else
565  return hasElementLevel<(Level - 1U)>(id);
566 }
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 486 of file GeometryIDmapper.h.

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

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

487 {
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]);
492  return id;
493 }
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 >
auto geo::GeoIDmapper< IDType, Index >::index ( ID_t const &  id) const

Returns the linear index corresponding to the specified ID.

Definition at line 479 of file GeometryIDmapper.h.

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

480 {
481  return indexLevel<ID_t::Level>(id);
482 }
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 534 of file GeometryIDmapper.h.

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

535 {
536  if constexpr (Level == 0)
537  return id.template getIndex<0U>();
538  else {
539  return indexLevel<(Level - 1U)>(id) * fN[Level] + id.template getIndex<Level>();
540  }
541 }
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 469 of file GeometryIDmapper.h.

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

470 {
471  if constexpr (GeoID::Level == 0)
472  return GeoID(fN[GeoID::Level] - 1U);
473  else
474  return GeoID(lastID<typename GeoID::ParentID_t>(), fN[GeoID::Level] - 1U);
475 }
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 497 of file GeometryIDmapper.h.

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

498 {
499  return index(id);
500 }
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 504 of file GeometryIDmapper.h.

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

505 {
506  return ID(index);
507 }
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 511 of file GeometryIDmapper.h.

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

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

512 {
513  fN = details::initializerListToArray<dimensions()>(dims);
514 }
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 ( 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 519 of file GeometryIDmapper.h.

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

520 {
521  resizeAsImpl(other, std::make_index_sequence<dimensions()>{});
522 }
void resizeAsImpl(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 ( GeoIDmapper< OIDType, OIndex > const &  other,
std::index_sequence< Indices... >   
)
private

Implementation for resizeAs().

Definition at line 578 of file GeometryIDmapper.h.

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

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

580 {
581  // Clang 5.0.1 does not understand `other.dimensions()` is constexpr
583  "Can't resize a deeper mapping to a shallower one.");
584  resize({other.template dimSize<Indices>()...});
585 }
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.
template<typename IDType , typename Index >
auto geo::GeoIDmapper< IDType, Index >::size ( ) const

Returns the number of elements in the mapping.

Definition at line 417 of file GeometryIDmapper.h.

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

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

418 {
419  return computeSize();
420 }
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 590 of file GeometryIDmapper.h.

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

591 {
592  if constexpr (Level >= dimensions())
593  return 1U;
594  else
595  return sizeLevel<(Level + 1U)>(dimSizes) * dimSizes[Level];
596 }
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 225 of file GeometryIDmapper.h.

226  {
227  Dimensions_t dims;
228  dims.fill(0);
229  return dims;
230  }
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: