Celeritas  0.5.0-86+4a8eea4
Public Member Functions | List of all members
celeritas::LabelIdMultiMap< I > Class Template Reference

Map IDs to label+sublabel. More...

#include <LabelIdMultiMap.hh>

Public Types

Type aliases
using IdT = I
 
using SpanConstIdT = Span< IdT const >
 
using VecLabel = std::vector< Label >
 
using size_type = typename IdT::size_type
 

Public Member Functions

 LabelIdMultiMap (std::string &&label, VecLabel &&keys)
 Construct from a vector of label+sublabel pairs, with a type string.
 
 LabelIdMultiMap (VecLabel &&keys)
 Construct from a vector of label+sublabel pairs, with no type.
 
SpanConstIdT find_all (std::string const &name) const
 Access the range of IDs corresponding to a label. More...
 
IdT find_unique (std::string const &name) const
 Find the ID corresponding to a label if exactly one exists. More...
 
IdT find_exact (Label const &label) const
 Access an ID by exact label (name plus extension). More...
 
CELER_FORCEINLINE IdT find (Label const &label) const
 
CELER_FORCEINLINE Label const & get (IdT id) const
 
Label const & at (IdT id) const
 Access the label+sublabel pair for an Id. More...
 
CELER_FORCEINLINE size_type size () const
 Get the number of elements.
 
 operator bool () const
 Whether this map is initialized.
 
SpanConstIdT duplicates () const
 Get duplicate labels to warn about.
 

Detailed Description

template<class I>
class celeritas::LabelIdMultiMap< I >

Map IDs to label+sublabel.

Many Geant4 geometry definitions reuse a label for material or volume definitions, and we need to track the unique name across multiple codes (Geant4, VecGeom+GDML) to differentiate between materials or volumes. This class maps a "label" to a name plus a range of "extensions", each of which corresponds to a unique ID. It also provides the reverse mapping so that an ID can retrieve the corresponding name/extension pair.

There is no requirement that sublabels be ordered adjacent to each other: the IDs corresponding to a label may be noncontiguous.

Duplicate labels are allowed but will be added to a list of duplicate IDs that can be warned about downstream. Empty labels will be ignored.

If no sublabels or labels are available for a find_X call, an empty span or "false" OpaqueId will be returned.

The three kinds of find methods are named differently to avoid ambiguity:

Member Function Documentation

◆ at()

template<class I >
Label const & celeritas::LabelIdMultiMap< I >::at ( IdT  id) const
inline

Access the label+sublabel pair for an Id.

This raises an exception if the ID is outside of the valid range.

◆ find_all()

template<class I >
auto celeritas::LabelIdMultiMap< I >::find_all ( std::string const &  name) const
inline

Access the range of IDs corresponding to a label.

This is useful for identifiers that may be repeated in a problem definition with uniquifying "extensions", such as pointer addresses from Geant4.

◆ find_exact()

template<class I >
auto celeritas::LabelIdMultiMap< I >::find_exact ( Label const &  label_sub) const
inline

Access an ID by exact label (name plus extension).

This returns a false OpaqueId if no such label pair exists.

◆ find_unique()

template<class I >
auto celeritas::LabelIdMultiMap< I >::find_unique ( std::string const &  name) const
inline

Find the ID corresponding to a label if exactly one exists.

This will return an invalid ID if no labels match the given name, and it will raise an exception if multiple labels do.


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