Skip to content

k4bench.geometry.scanner

k4bench.geometry.scanner

Public discovery façade over :class:~k4bench.geometry.index.GeometryIndex.

get_detector_names

get_detector_names(xml_path: Path) -> list[str]

Return the names of all <detector> elements in the geometry.

Recursively follows DD4hep document references starting from xml_path, including both <include ref="..."/> and <includes><file ref="..."/></includes>, collecting every <detector name="..."> attribute found across all reachable files. Order is encounter order; duplicates are suppressed.

Parameters:

Name Type Description Default
xml_path Path

Path to the top-level compact XML file.

required

Returns:

Type Description
list[str]

Detector names in the order they are first encountered.

Source code in k4bench/geometry/scanner.py
def get_detector_names(xml_path: Path) -> list[str]:
    """Return the names of all ``<detector>`` elements in the geometry.

    Recursively follows DD4hep document references starting from *xml_path*,
    including both ``<include ref="..."/>`` and ``<includes><file
    ref="..."/></includes>``, collecting every ``<detector name="...">``
    attribute found across all reachable files. Order is encounter order;
    duplicates are suppressed.

    Parameters
    ----------
    xml_path:
        Path to the top-level compact XML file.

    Returns
    -------
    list[str]
        Detector names in the order they are first encountered.
    """
    return list(GeometryIndex.load(xml_path, strict=False).detector_names)

resolve_includes

resolve_includes(xml_path: Path) -> list[Path]

Return all XML files reachable from xml_path via includes.

Follows DD4hep document references recursively. The returned list is in encounter order and contains no duplicates. xml_path itself is always the first element.

Includes whose ref attribute contains an unresolved environment variable (e.g. ${DD4hepINSTALL}/...) are skipped silently — ddsim resolves these at runtime using its own search path.

Parameters:

Name Type Description Default
xml_path Path

Absolute or relative path to a DD4hep compact XML file.

required

Returns:

Type Description
list[Path]

Resolved, deduplicated paths in encounter order.

Source code in k4bench/geometry/scanner.py
def resolve_includes(xml_path: Path) -> list[Path]:
    """Return all XML files reachable from *xml_path* via includes.

    Follows DD4hep document references recursively. The returned list is in
    encounter order and contains no duplicates. *xml_path* itself is always
    the first element.

    Includes whose ``ref`` attribute contains an unresolved environment
    variable (e.g. ``${DD4hepINSTALL}/...``) are skipped silently —
    ddsim resolves these at runtime using its own search path.

    Parameters
    ----------
    xml_path:
        Absolute or relative path to a DD4hep compact XML file.

    Returns
    -------
    list[Path]
        Resolved, deduplicated paths in encounter order.
    """
    return list(GeometryIndex.load(xml_path, strict=False).files)