niess.dispatch¶
The registry mechanism both conversion targets share: three-tier resolution over the assembled instance tree, keyed on niess provenance or the McStas component type.
dispatch
¶
Target-neutral registry dispatch over the assembled Instance tree.
Conversion targets (STEP/CAD geometry in :mod:niess.brep, NeXus Structure JSON
in :mod:niess.nexus) resolve a builder for each mccode_antlr Instance
using three tiers, most specific first:
- the niess
source_typerecorded in the instance's provenance metadata, - the niess
rolerecorded there, - the raw McCode component-type name, which every
Instancecarries whether or not niess produced it.
The registry only resolves builders; each target invokes them with whatever
signature it needs. Keeping resolution and invocation separate lets a caller
distinguish "no builder registered" from "a builder ran and declined to emit
anything" -- a distinction :mod:niess.nexus depends on for group suppression.
Classes:
-
NiessRegistry–Three-tier builder lookup keyed on provenance metadata or component type.
Functions:
-
expr_float–A plain float out of a McCode
Expr, orValueErrorif it is not one. -
merged_params–Instance parameters evaluated to floats, layered over
params.
NiessRegistry
¶
Bases: Generic[B]
Three-tier builder lookup keyed on provenance metadata or component type.
A registry may extend another by naming it as parent: lookups that find
nothing locally fall through to the parent's own three tiers. That is how an
instrument-specific registry adds its translators without touching the shared
default one, so which translators apply is a property of a single conversion
rather than of whatever the process happened to import.
Methods:
-
register–Register against a niess class (or its dotted
source_typename). -
register_role–Register against a provenance
role. -
register_component_type–Register against one or more raw McCode component-type names.
-
resolve_builder–Return the builder for
instance, orNoneif none is registered. -
registered_component_types–Component-type names this registry handles, inherited ones included.
Source code in src/niess/dispatch.py
register
¶
Register against a niess class (or its dotted source_type name).
Source code in src/niess/dispatch.py
register_component_type
¶
register_component_type(*comp_type_names: str)
Register against one or more raw McCode component-type names.
Source code in src/niess/dispatch.py
resolve_builder
¶
Return the builder for instance, or None if none is registered.
This registry's own three tiers are tried first, in full, before any parent is consulted: the more specific registry wins outright.
None means unhandled -- it never means "handled, emit nothing".
Callers that need that distinction must invoke the returned builder
themselves and interpret its return value.
Source code in src/niess/dispatch.py
registered_component_types
¶
Component-type names this registry handles, inherited ones included.
Source code in src/niess/dispatch.py
expr_float
¶
A plain float out of a McCode Expr, or ValueError if it is not one.
hasattr(expr, 'value') is not the test it looks like: Expr.value is a property
that raises for anything not constant, and hasattr only swallows
AttributeError, so asking whether an expression has a value used to raise
NotImplementedError straight through every caller. Every caller catches
TypeError/ValueError -- that is what "this names a run-time parameter, skip it"
is spelled as throughout niess -- so an expression that does not reduce says so that
way.
Source code in src/niess/dispatch.py
merged_params
¶
Instance parameters evaluated to floats, layered over params.
Parameters that cannot be reduced to a float (they depend on a runtime instrument parameter, say) are skipped rather than raising.