Celeritas 0.7+cf8d83d
Loading...
Searching...
No Matches
Public Member Functions | List of all members
celeritas::VolumePathFinder Class Reference

Reconstruct the volume-instance path for a VolumeUniqueInstanceId. More...

#include <VolumePathFinder.hh>

Public Types

Type aliases
using ParamsRef = NativeCRef< VolumeParamsData >
 
using SpanVI = Span< VolumeInstanceId >
 

Public Member Functions

 VolumePathFinder (ParamsRef const &params, SpanVI scratch)
 Construct from volume hierarchy data and a scratch buffer.
 
SpanVI operator() (VolumeUniqueInstanceId uid) const
 Reconstruct the path whose unique instance ID equals uid.
 

Detailed Description

Reconstruct the volume-instance path for a VolumeUniqueInstanceId.

Each VolumeUniqueInstanceId uniquely identifies a root-to-node path (i.e., a Geant4 "touchable") in the volume DAG. This class performs the inverse of VolumePathAccumulator: given an ID it fills a caller-supplied scratch buffer with the VolumeInstanceId sequence and returns a (possibly shorter) span of the result.

VolumeUniqueInstanceId{0} (or world_unique_instance ) always denotes the world volume itself (empty path), and VolumeUniqueInstanceId{} (null/invalid) is rejected with a precondition failure. The valid range is \([0,\, N_\text{unique})\).

The algorithm descends from the world volume level by level, always seeding from the world's direct children. At each level it scans the current volume's children to find the unique child whose subtree contains the remaining UID, exploiting the fact that sibling offsets are strictly increasing. The cost is \(O(D \log C)\) where \(D\) is the path depth and \(C\) is the maximum number of children of any volume.

The scratch buffer must be at least num_volume_levels - 1 long (the maximum possible path depth). Successive calls reuse the same buffer, so callers must consume the returned span before the next call.

Example:
std::vector<VolumeInstanceId> buf(params.num_volume_levels());
VolumePathFinder find_path{params.host_ref(), make_span(buf)};
auto path = find_path(uid); // [vi_0, vi_1, ..., vi_k]
constexpr Span< T, N > make_span(Array< T, N > &x)
Get a mutable fixed-size view to an array.
Definition Span.hh:339
Type-safe "optional" index for accessing an array or collection of data.
Definition OpaqueId.hh:123
Reconstruct the volume-instance path for a VolumeUniqueInstanceId.
Definition VolumePathFinder.hh:58

Member Function Documentation

◆ operator()()

auto celeritas::VolumePathFinder::operator() ( VolumeUniqueInstanceId  uid) const
inline

Reconstruct the path whose unique instance ID equals uid.

Returns an empty span for UID 0 (the world volume, before any instance is entered). Otherwise writes the sequence of VolumeInstanceId values from the world's first child down to the node identified by uid, and returns a sub-span of the scratch buffer containing exactly those entries.


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