|
Celeritas 0.7+cf8d83d
|
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 ¶ms, 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. | |
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.
|
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.