Skip to content

Commit f4ebddc

Browse files
maarten-icolivhoenen
authored andcommitted
Use datapath with UDA when fetching IDS properties
We request `ids_properties/homogeneous_time` and `ids_properties/version_put/data_dictionary` in two separate calls to the backend before actually getting all data. This is fine for local backends, but UDA would fetch the data three times: 1. When determining the DD version and if the IDS exists 2. When determining whether the IDS uses homogeneous time 3. When actually reading the data This commit adds a `datapath="ids_properties"` to the first two cases. This results in UDA only fetching the IDS properties in points 1 and 2. The full IDS is now requested once by UDA, in point 3.
1 parent 4e42d11 commit f4ebddc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

imas/backends/imas_core/al_context.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This file is part of IMAS-Python.
22
# You should have received the IMAS-Python LICENSE file with this project.
3-
"""Object-oriented interface to the IMAS lowlevel.
4-
"""
3+
"""Object-oriented interface to the IMAS lowlevel."""
54

65
import logging
76
import weakref
@@ -61,17 +60,21 @@ def __enter__(self) -> "ALContext":
6160
def __exit__(self, exc_type, exc_value, traceback) -> None:
6261
ll_interface.end_action(self.ctx)
6362

64-
def global_action(self, path: str, rwmode: int) -> "ALContext":
63+
def global_action(self, path: str, rwmode: int, datapath: str = "") -> "ALContext":
6564
"""Begin a new global action for use in a ``with`` context.
6665
6766
Args:
6867
path: access layer path for this global action: ``<idsname>[/<occurrence>]``
6968
rwmode: read-only or read-write operation mode: ``READ_OP``/``WRITE_OP``
69+
datapath: used by UDA backend to fetch only part of the data.
7070
7171
Returns:
7272
The created context.
7373
"""
74-
status, ctx = ll_interface.begin_global_action(self.ctx, path, rwmode)
74+
args = [self.ctx, path, rwmode]
75+
if datapath: # AL4 compatibility: datapath arg was added in AL5
76+
args.append(datapath)
77+
status, ctx = ll_interface.begin_global_action(*args)
7578
if status != 0:
7679
raise LowlevelError("global_action", status)
7780
return ALContext(ctx)

imas/backends/imas_core/db_entry_al.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ def get(
257257
if occurrence != 0:
258258
ll_path += f"/{occurrence}"
259259

260-
with self._db_ctx.global_action(ll_path, READ_OP) as read_ctx:
260+
datapath = "ids_properties" if self.backend == "uda" else ""
261+
with self._db_ctx.global_action(ll_path, READ_OP, datapath) as read_ctx:
261262
time_mode_path = "ids_properties/homogeneous_time"
262263
time_mode = read_ctx.read_data(time_mode_path, "", INTEGER_DATA, 0)
263264
# This is already checked by read_dd_version, but ensure:
@@ -314,7 +315,8 @@ def read_dd_version(self, ids_name: str, occurrence: int) -> str:
314315
if occurrence != 0:
315316
ll_path += f"/{occurrence}"
316317

317-
with self._db_ctx.global_action(ll_path, READ_OP) as read_ctx:
318+
datapath = "ids_properties" if self.backend == "uda" else ""
319+
with self._db_ctx.global_action(ll_path, READ_OP, datapath) as read_ctx:
318320
time_mode_path = "ids_properties/homogeneous_time"
319321
time_mode = read_ctx.read_data(time_mode_path, "", INTEGER_DATA, 0)
320322
dd_version_path = "ids_properties/version_put/data_dictionary"

0 commit comments

Comments
 (0)