Skip to content

k4bench.geometry.references

k4bench.geometry.references

Shared rules for DD4hep filesystem and document references.

resolve_local_ref

resolve_local_ref(ref: str, base: Path) -> Path | None

Return where a local filesystem ref points, or None if unresolved.

An empty ref or one carrying $ is deliberately left to ddsim. Checking the raw value makes indexing deterministic regardless of the environment.

Source code in k4bench/geometry/references.py
def resolve_local_ref(ref: str, base: Path) -> Path | None:
    """Return where a local filesystem ref points, or ``None`` if unresolved.

    An empty ref or one carrying ``$`` is deliberately left to ddsim. Checking
    the raw value makes indexing deterministic regardless of the environment.
    """
    if not ref or "$" in ref:
        return None
    path = Path(ref)
    return (path if path.is_absolute() else base / path).resolve()

is_geometry_document_ref

is_geometry_document_ref(node: Element) -> bool

Whether DD4hep recursively loads node as a geometry document.

<include> is a document edge wherever DD4hep accepts it. <includes><file> is also loaded through Detector.fromXML when its root is not a materials/elements collection.

Source code in k4bench/geometry/references.py
def is_geometry_document_ref(node: minidom.Element) -> bool:
    """Whether DD4hep recursively loads *node* as a geometry document.

    ``<include>`` is a document edge wherever DD4hep accepts it.
    ``<includes><file>`` is also loaded through ``Detector.fromXML`` when its
    root is not a materials/elements collection.
    """
    if node.tagName == "include":
        return True
    parent = node.parentNode
    return (
        node.tagName == "file"
        and parent is not None
        and parent.nodeType == parent.ELEMENT_NODE
        and parent.tagName == "includes"
    )