k4bench.geometry.patcher¶
k4bench.geometry.patcher ¶
Patch a DD4hep compact geometry to remove a single subdetector.
The patcher writes temporary XML files to the system temp directory so
that the original geometry (which may live on a read-only filesystem
such as CVMFS) is never modified. All relative <include ref="...">
paths in the patched XMLs are rewritten to absolute paths so that
ddsim can resolve them regardless of where the temp files land.
Temporary files are prefixed with _k4bench_tmp_ so they are easy
to identify and clean up. The recommended usage is via the
:func:patched_geometry context manager, which guarantees cleanup even
if the simulation run raises an exception.
DetectorNotFoundError ¶
Bases: ValueError
Raised when the requested detector name is not in the geometry.
patched_geometry_keep_only ¶
Context manager yielding a geometry with only keep_names detectors active.
All <detector> elements whose name attribute is not in keep_names
are removed from every file in the include tree. Temp files are written
to the system temp directory and deleted on exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_path
|
Path
|
Path to the original top-level compact XML. |
required |
keep_names
|
set[str]
|
Detector names to keep. All others are removed. |
required |
Yields:
| Type | Description |
|---|---|
Path
|
Path to the patched top-level XML file. |
Source code in k4bench/geometry/patcher.py
patched_geometry ¶
Context manager that yields a patched geometry path.
Creates temporary XML files with detector_name removed, yields the path to the patched top-level XML, then deletes the temp files on exit regardless of whether an exception was raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_path
|
Path
|
Path to the original top-level compact XML. |
required |
detector_name
|
str
|
Name of the |
required |
Yields:
| Type | Description |
|---|---|
Path
|
Path to the patched top-level XML file. |
Raises:
| Type | Description |
|---|---|
DetectorNotFoundError
|
If detector_name is not found in any reachable XML file. |
Example
::
with patched_geometry(Path("ALLEGRO.xml"), "EcalBarrel") as tmp_xml:
result = run_ddsim(xml_path=tmp_xml, ...)
Source code in k4bench/geometry/patcher.py
build_patched_xml ¶
Write patched XML files with detector_name removed.
Locates the file that owns detector_name, removes the
<detector> node from it, writes a temp copy, then writes a
patched top-level XML whose include ref points at the temp copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xml_path
|
Path
|
Path to the original top-level compact XML. |
required |
detector_name
|
str
|
Name of the |
required |
Returns:
| Type | Description |
|---|---|
tuple[Path, Path]
|
|
Raises:
| Type | Description |
|---|---|
DetectorNotFoundError
|
If detector_name is not found in any reachable XML file. |