Celeritas
0.5.0-56+6b053cd
|
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. | |
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:
find_all
returns the full set of IDs that match the given name;find_unique
is a convenience accessor for locating a volume by name, but it only works if there are no duplicates; andfind_exact
looks for the full label, both name and extension.
|
inline |
Access the label+sublabel pair for an Id.
This raises an exception if the ID is outside of the valid range.
|
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.
|
inline |
Access an ID by exact label (name plus extension).
This returns a false
OpaqueId if no such label pair exists.
|
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.