All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
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 = std::size_t>
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 29 of file GeometryIDmapper.h.

Member Typedef Documentation

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

< Type of dimension sizes.

Definition at line 196 of file GeometryIDmapper.h.

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

Type used as ID for this mapping.

Definition at line 81 of file GeometryIDmapper.h.

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

Type of flat index.

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

433 {
434  fN.fill(0U);
435 }
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 441 of file GeometryIDmapper.h.

443 {
444  assert(dims.size() == dimensions()); // can't be static
445 }
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 = std::size_t>
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 247 of file GeometryIDmapper.h.

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

552  {
553  fN.fill(0U);
554 } // 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 600 of file GeometryIDmapper.h.

601  { return sizeLevel<0U>(fN); }
Dimensions_t fN
Number of maximum entries per ID level.
template<typename IDType , typename Index >
constexpr unsigned int geo::GeoIDmapper< IDType, Index >::dimensions ( )
static

Dimensions of the ID of this mapping.

Definition at line 471 of file GeometryIDmapper.h.

472  { return IDType::Level + 1; }
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 463 of file GeometryIDmapper.h.

463  {
464  if constexpr (Level >= dimensions()) return 0U; // technically it would be 1...
465  else return fN[Level];
466 } // geo::GeoIDmapper<>::dimSize()
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 456 of file GeometryIDmapper.h.

457  { return size() == index_type{ 0 }; }
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 574 of file GeometryIDmapper.h.

575 {
576  if constexpr (Level == 0) {
577  id.template writeIndex<0U>() = index;
578  id.setValidity(index < fN[0U]);
579  }
580  else {
581  id.template writeIndex<Level>() = index % fN[Level];
582  fillID<(Level-1U)>(id, index / fN[Level]);
583  }
584 } // geo::GeoIDmapper<>::fillID()
void fillID(GeoID &id, index_type index) const
Fills the specified ID with its index.
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 485 of file GeometryIDmapper.h.

485  {
486  if constexpr (GeoID::Level == 0) return GeoID(0U);
487  else return GeoID(firstID<typename GeoID::ParentID_t>(), 0U);
488 } // geo::GeoIDmapper<>::firstID()
GeoID firstID() const
Returns the ID of the first element with GeoID type.
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 478 of file GeometryIDmapper.h.

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

591 {
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);
595 } // geo::GeoIDmapper<>::hasElementLevel()
bool hasElementLevel(GeoID const &id) const
Returns whether all levels of id up to Level are within range.
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.
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true
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 509 of file GeometryIDmapper.h.

510 {
511  ID_t ID;
512  fillID<ID_t::Level>(ID, index);
513  return ID;
514 } // 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 503 of file GeometryIDmapper.h.

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

Definition at line 560 of file GeometryIDmapper.h.

562 {
563  if constexpr (Level == 0) return id.template getIndex<0U>();
564  else {
565  return
566  indexLevel<(Level-1U)>(id) * fN[Level] + id.template getIndex<Level>();
567  }
568 } // geo::GeoIDmapper<>::indexLevel()
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 494 of file GeometryIDmapper.h.

494  {
495  if constexpr (GeoID::Level == 0) return GeoID(fN[GeoID::Level] - 1U);
496  else
497  return GeoID(lastID<typename GeoID::ParentID_t>(), fN[GeoID::Level] - 1U);
498 } // geo::GeoIDmapper<>::lastID()
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 519 of file GeometryIDmapper.h.

521  { return index(id); }
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 526 of file GeometryIDmapper.h.

528  { return ID(index); }
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 534 of file GeometryIDmapper.h.

535 {
536  fN = details::initializerListToArray<dimensions()>(dims);
537 } // 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 544 of file GeometryIDmapper.h.

545 {
546  resizeAsImpl(other, std::make_index_sequence<dimensions()>{});
547 } // 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 607 of file GeometryIDmapper.h.

611 {
612  // Clang 5.0.1 does not understand `other.dimensions()` is constexpr
614  "Can't resize a deeper mapping to a shallower one.");
615  resize({ other.template dimSize<Indices>()... });
616 } // 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 450 of file GeometryIDmapper.h.

451  { return computeSize(); }
index_type computeSize() const
Computes the expected size of this mapping.
template<typename IDType, typename Index = std::size_t>
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 = std::size_t>
template<std::size_t Level, typename Dims >
auto geo::GeoIDmapper< IDType, Index >::sizeLevel ( Dims const &  dimSizes) -> index_type

Definition at line 622 of file GeometryIDmapper.h.

624 {
625  if constexpr (Level >= dimensions()) return 1U;
626  else return sizeLevel<(Level+1U)>(dimSizes) * dimSizes[Level];
627 } // geo::GeoIDmapper<>::sizeLevel()
static index_type sizeLevel(Dims const &dimSizes)
static constexpr unsigned int dimensions()
Dimensions of the ID of this mapping.
template<typename IDType, typename Index = std::size_t>
static Dimensions_t geo::GeoIDmapper< IDType, Index >::zeroDimensions ( )
inlinestaticprivate

Initializer with zero size for each of the dimensions.

Definition at line 242 of file GeometryIDmapper.h.

243  { Dimensions_t dims; dims.fill(0); return dims; }
std::array< unsigned int, dimensions()> Dimensions_t
&lt; Type of dimension sizes.

Member Data Documentation

template<typename IDType, typename Index = std::size_t>
Dimensions_t geo::GeoIDmapper< IDType, Index >::fN = zeroDimensions()
private

Number of maximum entries per ID level.

Definition at line 199 of file GeometryIDmapper.h.


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