Omny fixes #346
No files matched your search
@@ -2788,7 +2788,7 @@ class Flomni(
|
||||
0,
|
||||
"started",
|
||||
datetime.date.today().strftime("%Y-%m"),
|
||||
owner_if_empty=bec.active_account or "",
|
||||
account=bec.active_account or "",
|
||||
)
|
||||
self.write_pdf_report()
|
||||
# estimated_remaining_time/estimated_finish_time/accumulated_idle_time/
|
||||
@@ -2988,7 +2988,7 @@ class Flomni(
|
||||
0,
|
||||
"completed",
|
||||
datetime.date.today().strftime("%Y-%m"),
|
||||
owner_if_empty=bec.active_account or "",
|
||||
account=bec.active_account or "",
|
||||
)
|
||||
timing_lines = self._build_timing_lines()
|
||||
for line in timing_lines[3:]:
|
||||
|
||||
@@ -1371,7 +1371,7 @@ class OMNY(
|
||||
0,
|
||||
"started",
|
||||
datetime.date.today().strftime("%Y-%m"),
|
||||
owner_if_empty=bec.active_account or "",
|
||||
account=bec.active_account or "",
|
||||
)
|
||||
self.progress["tomo_start_time"] = datetime.datetime.now().isoformat()
|
||||
# reset stale estimates from any previous scan, otherwise the GUI
|
||||
@@ -1565,7 +1565,7 @@ class OMNY(
|
||||
0,
|
||||
"completed",
|
||||
datetime.date.today().strftime("%Y-%m"),
|
||||
owner_if_empty=bec.active_account or "",
|
||||
account=bec.active_account or "",
|
||||
)
|
||||
|
||||
idle_s = self.progress.get("accumulated_idle_time", 0.0)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
import os
|
||||
import time
|
||||
import builtins
|
||||
@@ -1234,9 +1235,9 @@ class OMNYSampleTransferMixin:
|
||||
return dev.omny_samples.get_sample_name_and_owner(container, slot_nr)
|
||||
|
||||
def otransfer_set_sample_measured(
|
||||
self, container: str, slot_nr: int, status: str, meas_date: str, owner_if_empty: str = ""
|
||||
self, container: str, slot_nr: int, status: str, meas_date: str, account: str = ""
|
||||
):
|
||||
return dev.omny_samples.set_sample_measured(container, slot_nr, status, meas_date, owner_if_empty)
|
||||
return dev.omny_samples.set_sample_measured(container, slot_nr, status, meas_date, account)
|
||||
|
||||
def otransfer_get_sample_status(self, container: str, slot_nr: int) -> str:
|
||||
return dev.omny_samples.get_sample_status(container, slot_nr)
|
||||
@@ -1439,6 +1440,16 @@ class OMNYSampleTransferMixin:
|
||||
if dev.omny_samples.is_sample_in_samplestage():
|
||||
if _picked_it:
|
||||
dev.omny_samples.transfer_sample("STAGE", "GRIPPER")
|
||||
# leaving the sample stage without a tomoscan having been started on it:
|
||||
# "screened" (Mirko 2026-10-27); a started/completed status is kept
|
||||
if dev.omny_samples.get_sample_status("GRIPPER") == "none":
|
||||
dev.omny_samples.set_sample_measured(
|
||||
"GRIPPER",
|
||||
0,
|
||||
"screened",
|
||||
datetime.date.today().strftime("%Y-%m"),
|
||||
account=bec.active_account or "",
|
||||
)
|
||||
# FZP was picked
|
||||
# if (_osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100)
|
||||
# _otransfer_modify_sample("omny",110,2,samplename)
|
||||
|
||||
@@ -130,6 +130,8 @@ EMPTY_LABEL = "— empty —" # what an empty cell shows in the GUI
|
||||
# OMNY-specific layout
|
||||
OMNY_SHUTTLE_LETTERS = ("A", "B", "C")
|
||||
OMNY_SHUTTLE_SLOTS = tuple(range(1, 7))
|
||||
# places as on the real shuttle: 3 rows x 2 columns, 1 2 / 3 4 / 5 6 (Mirko 2026-10-27; was 2 x 3)
|
||||
OMNY_SHUTTLE_COLS = 2
|
||||
OMNY_FIXED_POSITIONS = (10, 11, 12, 13, 14, 32, 33, 34, 100, 101)
|
||||
OMNY_PARKING_SLOTS = tuple(range(1, 7))
|
||||
# OMNYSampleStorage.unset_shuttle_slot()'s own empty sentinel -- unlike sample
|
||||
@@ -329,7 +331,7 @@ class _SlotCell(QFrame):
|
||||
) -> None:
|
||||
"""Update the cell's displayed state (called by the poll/refresh).
|
||||
|
||||
`measured_status` is "started"/"completed" (FLOMNI-SAMPLE:<slot>:STATUS)
|
||||
`measured_status` is "started"/"completed" (OMNY also "screened") (FLOMNI-SAMPLE:<slot>:STATUS)
|
||||
(OMNY: OMNY-SAMPLE:<slot>:STATUS) or None if this slot's current
|
||||
occupant has no measured record, which the measured label below
|
||||
renders as blank.
|
||||
@@ -354,6 +356,10 @@ class _SlotCell(QFrame):
|
||||
# wording that implies live progress.
|
||||
self._lbl_measured.setText("◐ started")
|
||||
self._lbl_measured.setStyleSheet("font-size: 10px; color: #ef6c00;")
|
||||
elif measured_status == "screened":
|
||||
# OMNY only (2026-10-27): was on the sample stage, no tomoscan started
|
||||
self._lbl_measured.setText("○ screened")
|
||||
self._lbl_measured.setStyleSheet("font-size: 10px; color: #1565c0;")
|
||||
else:
|
||||
self._lbl_measured.setText("")
|
||||
else:
|
||||
@@ -446,7 +452,8 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
- Header: Stage and Gripper, right-click correctable
|
||||
- Grid: the 10 fixed O positions, right-click correctable
|
||||
- Three shuttle sections (A/B/C): installed/active status line
|
||||
(right-click to assign/clear a parking slot) + a 6-slot grid,
|
||||
(right-click to assign/clear a parking slot) + a 6-slot grid as on the
|
||||
real shuttle (3 rows x 2 columns: 1 2 / 3 4 / 5 6),
|
||||
right-click correctable
|
||||
- Caveat line: records only, not hardware
|
||||
|
||||
@@ -610,7 +617,12 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
owner = _val(f"omny_samples_sample_owners_{slot}", "") or ""
|
||||
raw = _val(f"omny_samples_sample_status_{slot}")
|
||||
status = str(raw) if raw is not None else ""
|
||||
return (used, str(name), str(owner), status if used and status in ("started", "completed") else None)
|
||||
return (
|
||||
used,
|
||||
str(name),
|
||||
str(owner),
|
||||
status if used and status in ("started", "completed", "screened") else None,
|
||||
)
|
||||
|
||||
state: dict[tuple, tuple[bool, str, str, Optional[str]]] = {}
|
||||
state[("stage",)] = _record("STAGE")
|
||||
@@ -690,7 +702,8 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
fields = {
|
||||
PTOUCH_FIELD_ACCOUNT: record["owner"],
|
||||
# account of the measurement (MEAS_ACCOUNT, 2026-10-27); older records: the owner
|
||||
PTOUCH_FIELD_ACCOUNT: record.get("meas_account") or record["owner"],
|
||||
PTOUCH_FIELD_DATE: record["meas_date"],
|
||||
PTOUCH_FIELD_SAMPLENAME: prev_name,
|
||||
}
|
||||
@@ -735,7 +748,8 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
|
||||
Status, owner and measurement date live on the slot record itself
|
||||
(OMNY-SAMPLE:<slot>:..., as FlOMNI), read fresh from the device right
|
||||
before the clear; the owner is printed as account, as on FlOMNI.
|
||||
before the clear; the account of the measurement (MEAS_ACCOUNT) is printed, the owner
|
||||
only for records without one.
|
||||
"""
|
||||
assert key[0] == "shuttle"
|
||||
_, letter, n = key
|
||||
@@ -760,7 +774,8 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
if reply != QMessageBox.StandardButton.Yes:
|
||||
return
|
||||
fields = {
|
||||
PTOUCH_FIELD_ACCOUNT: record["owner"],
|
||||
# account of the measurement (MEAS_ACCOUNT, 2026-10-27); older records: the owner
|
||||
PTOUCH_FIELD_ACCOUNT: record.get("meas_account") or record["owner"],
|
||||
PTOUCH_FIELD_DATE: record["meas_date"],
|
||||
PTOUCH_FIELD_SAMPLENAME: prev_name,
|
||||
}
|
||||
@@ -999,7 +1014,7 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
slot_grid = QGridLayout()
|
||||
slot_grid.setSpacing(4)
|
||||
for idx, n in enumerate(OMNY_SHUTTLE_SLOTS):
|
||||
r, c = divmod(idx, 3)
|
||||
r, c = divmod(idx, OMNY_SHUTTLE_COLS)
|
||||
key = ("shuttle", letter, n)
|
||||
cell = _SlotCell(key, self, COLOR_SLOT_BORDER, caption=f"{letter}-{n}")
|
||||
self._cells[key] = cell
|
||||
@@ -1403,7 +1418,7 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
usable_w = pdf.w - 2 * margin
|
||||
cell_h = 28
|
||||
|
||||
# shuttles A/B/C: status line + 3-wide slot grid, side by side
|
||||
# shuttles A/B/C: status line + slot grid as on the shuttle (3 rows x 2), side by side
|
||||
shuttle_y0 = pdf.get_y()
|
||||
shuttle_w = usable_w / 3
|
||||
for si, letter in enumerate(OMNY_SHUTTLE_LETTERS):
|
||||
@@ -1419,9 +1434,9 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
pdf.set_font("Helvetica", "B", 9)
|
||||
pdf.cell(shuttle_w, 5, status_text, align="L")
|
||||
|
||||
slot_w = shuttle_w / 3
|
||||
slot_w = shuttle_w / OMNY_SHUTTLE_COLS
|
||||
for idx, n in enumerate(OMNY_SHUTTLE_SLOTS):
|
||||
r, c = divmod(idx, 3)
|
||||
r, c = divmod(idx, OMNY_SHUTTLE_COLS)
|
||||
x = x0 + c * slot_w
|
||||
y = shuttle_y0 + 6 + r * cell_h
|
||||
key = ("shuttle", letter, n)
|
||||
@@ -1460,6 +1475,8 @@ class OMNY_SampleStorage(BECWidget, QWidget):
|
||||
marker = "measured"
|
||||
elif measured_status == "started":
|
||||
marker = "started"
|
||||
elif measured_status == "screened":
|
||||
marker = "screened"
|
||||
pdf.set_xy(x + 1, y + h - 6)
|
||||
pdf.set_font("Helvetica", "", 7)
|
||||
pdf.cell(w - 2, 4, marker, align="C")
|
||||
|
||||
@@ -4,9 +4,11 @@ One record per slot, all fields autosaved by the IOC::
|
||||
|
||||
FLOMNI-SAMPLE:<slot>:USED 0 = free, 1 = sample present
|
||||
FLOMNI-SAMPLE:<slot>:NAME sample name (long string, up to 256 chars)
|
||||
FLOMNI-SAMPLE:<slot>:OWNER e-account of the owner
|
||||
FLOMNI-SAMPLE:<slot>:OWNER owner of the sample (free text, not necessarily an e-account)
|
||||
FLOMNI-SAMPLE:<slot>:STATUS none / started / completed (measurement status)
|
||||
FLOMNI-SAMPLE:<slot>:MEAS_DATE date of the measurement
|
||||
FLOMNI-SAMPLE:<slot>:MEAS_ACCOUNT e-account active when the measurement status was last set
|
||||
(2026-10-27; before, it went into OWNER if that was empty)
|
||||
|
||||
<slot> = STAGE (slot 0, the flOMNI sample stage), T01 ... T20 (tray slots 1-20),
|
||||
GRIPPER (slot 100)
|
||||
@@ -72,6 +74,7 @@ class FlomniSampleStorage(Device):
|
||||
"get_sample_name_and_owner",
|
||||
"get_sample_status",
|
||||
"get_sample_meas_date",
|
||||
"get_sample_meas_account",
|
||||
"get_sample_record",
|
||||
"set_sample_measured",
|
||||
"transfer_sample",
|
||||
@@ -86,6 +89,7 @@ class FlomniSampleStorage(Device):
|
||||
sample_owners = Dcpt(_slot_signals("OWNER", string=True))
|
||||
sample_status = Dcpt(_slot_signals("STATUS", string=True))
|
||||
sample_meas_date = Dcpt(_slot_signals("MEAS_DATE", string=True))
|
||||
sample_meas_account = Dcpt(_slot_signals("MEAS_ACCOUNT", string=True))
|
||||
|
||||
# gripper (slot 100)
|
||||
sample_in_gripper = Cpt(EpicsSignal, read_pv=f"{PV_PREFIX}GRIPPER:USED", auto_monitor=True)
|
||||
@@ -101,6 +105,9 @@ class FlomniSampleStorage(Device):
|
||||
sample_in_gripper_meas_date = Cpt(
|
||||
EpicsSignal, read_pv=f"{PV_PREFIX}GRIPPER:MEAS_DATE", string=True, auto_monitor=True
|
||||
)
|
||||
sample_in_gripper_meas_account = Cpt(
|
||||
EpicsSignal, read_pv=f"{PV_PREFIX}GRIPPER:MEAS_ACCOUNT", string=True, auto_monitor=True
|
||||
)
|
||||
|
||||
def __init__(self, prefix="", *, name, **kwargs):
|
||||
super().__init__(prefix, name=name, **kwargs)
|
||||
@@ -130,6 +137,7 @@ class FlomniSampleStorage(Device):
|
||||
"owner": self.sample_in_gripper_owner,
|
||||
"status": self.sample_in_gripper_status,
|
||||
"meas_date": self.sample_in_gripper_meas_date,
|
||||
"meas_account": self.sample_in_gripper_meas_account,
|
||||
}[field]
|
||||
group = {
|
||||
"used": self.sample_placed,
|
||||
@@ -137,6 +145,7 @@ class FlomniSampleStorage(Device):
|
||||
"owner": self.sample_owners,
|
||||
"status": self.sample_status,
|
||||
"meas_date": self.sample_meas_date,
|
||||
"meas_account": self.sample_meas_account,
|
||||
}[field]
|
||||
return getattr(group, f"sample{slot_nr}")
|
||||
|
||||
@@ -145,7 +154,7 @@ class FlomniSampleStorage(Device):
|
||||
return "" if val is None else str(val)
|
||||
|
||||
# ── write ────────────────────────────────────────────────────────────────
|
||||
def _write(self, slot_nr: int, used: int, name: str, owner: str, status: str, meas_date: str):
|
||||
def _write(self, slot_nr: int, used: int, name: str, owner: str, status: str, meas_date: str, meas_account: str = ""):
|
||||
if status not in STATUS_VALUES:
|
||||
raise FlomniSampleStorageError(f"Invalid status {status!r}, expected one of {STATUS_VALUES}.")
|
||||
name = name if name else EMPTY_NAME
|
||||
@@ -154,13 +163,20 @@ class FlomniSampleStorage(Device):
|
||||
self._sig("owner", slot_nr).set(owner or "").wait(timeout=5)
|
||||
self._sig("status", slot_nr).set(status).wait(timeout=5)
|
||||
self._sig("meas_date", slot_nr).set(meas_date or "").wait(timeout=5)
|
||||
self._sig("meas_account", slot_nr).set(meas_account or "").wait(timeout=5)
|
||||
self._sig("used", slot_nr).set(int(used)).wait(timeout=5)
|
||||
|
||||
def set_sample_slot(
|
||||
self, slot_nr: int, name: str, owner: str = "", status: str = STATUS_NONE, meas_date: str = ""
|
||||
self,
|
||||
slot_nr: int,
|
||||
name: str,
|
||||
owner: str = "",
|
||||
status: str = STATUS_NONE,
|
||||
meas_date: str = "",
|
||||
meas_account: str = "",
|
||||
):
|
||||
"""Place a sample record in slot `slot_nr` (0-20, or 100 = gripper)."""
|
||||
self._write(slot_nr, 1, name, owner, status, meas_date)
|
||||
self._write(slot_nr, 1, name, owner, status, meas_date, meas_account)
|
||||
|
||||
def unset_sample_slot(self, slot_nr: int):
|
||||
"""Clear slot `slot_nr` (0-20, or 100 = gripper)."""
|
||||
@@ -172,25 +188,26 @@ class FlomniSampleStorage(Device):
|
||||
def unset_sample_in_gripper(self):
|
||||
self.unset_sample_slot(GRIPPER_SLOT)
|
||||
|
||||
def set_sample_measured(self, slot_nr: int, status: str, meas_date: str, owner_if_empty: str = ""):
|
||||
"""Record the measurement status/date of the sample in `slot_nr`.
|
||||
|
||||
If the sample has no owner yet, `owner_if_empty` (e.g. the active
|
||||
e-account) is stored as owner -- the label printed when a measured
|
||||
sample is cleared uses the owner as account.
|
||||
def set_sample_measured(self, slot_nr: int, status: str, meas_date: str, account: str = ""):
|
||||
"""Record the measurement status/date of the sample in `slot_nr` and the
|
||||
e-account it happened in (`account`, e.g. bec.active_account) in MEAS_ACCOUNT.
|
||||
The owner is not touched (2026-10-27: owner and measurement account are
|
||||
separate fields; before, the account was stored as owner when it was empty).
|
||||
"""
|
||||
if status not in STATUS_VALUES:
|
||||
raise FlomniSampleStorageError(f"Invalid status {status!r}, expected one of {STATUS_VALUES}.")
|
||||
if owner_if_empty and not self.get_sample_owner(slot_nr):
|
||||
self._sig("owner", slot_nr).set(owner_if_empty).wait(timeout=5)
|
||||
self._sig("status", slot_nr).set(status).wait(timeout=5)
|
||||
self._sig("meas_date", slot_nr).set(meas_date or "").wait(timeout=5)
|
||||
if account:
|
||||
self._sig("meas_account", slot_nr).set(account).wait(timeout=5)
|
||||
|
||||
def transfer_sample(self, from_slot: int, to_slot: int):
|
||||
"""Move the complete record (name, owner, status, date) from one slot to
|
||||
another (0-20, 100 = gripper) and clear the source slot."""
|
||||
"""Move the complete record (name, owner, status, date, account) from one slot
|
||||
to another (0-20, 100 = gripper) and clear the source slot."""
|
||||
rec = self.get_sample_record(from_slot)
|
||||
self.set_sample_slot(to_slot, rec["name"], rec["owner"], rec["status"], rec["meas_date"])
|
||||
self.set_sample_slot(
|
||||
to_slot, rec["name"], rec["owner"], rec["status"], rec["meas_date"], rec["meas_account"]
|
||||
)
|
||||
self.unset_sample_slot(from_slot)
|
||||
|
||||
# ── read ─────────────────────────────────────────────────────────────────
|
||||
@@ -217,6 +234,9 @@ class FlomniSampleStorage(Device):
|
||||
def get_sample_meas_date(self, slot_nr) -> str:
|
||||
return self._str(self._sig("meas_date", slot_nr).get())
|
||||
|
||||
def get_sample_meas_account(self, slot_nr) -> str:
|
||||
return self._str(self._sig("meas_account", slot_nr).get())
|
||||
|
||||
def get_sample_record(self, slot_nr) -> dict:
|
||||
return {
|
||||
"used": self.is_sample_slot_used(slot_nr),
|
||||
@@ -224,6 +244,7 @@ class FlomniSampleStorage(Device):
|
||||
"owner": self.get_sample_owner(slot_nr),
|
||||
"status": self.get_sample_status(slot_nr),
|
||||
"meas_date": self.get_sample_meas_date(slot_nr),
|
||||
"meas_account": self.get_sample_meas_account(slot_nr),
|
||||
}
|
||||
|
||||
def show_all(self):
|
||||
@@ -235,7 +256,8 @@ class FlomniSampleStorage(Device):
|
||||
text = f" (owner: {owner})" if owner else ""
|
||||
if status != STATUS_NONE:
|
||||
date = self.get_sample_meas_date(slot_nr)
|
||||
text += f" [measured: {status}{', ' + date if date else ''}]"
|
||||
account = self.get_sample_meas_account(slot_nr)
|
||||
text += f" [measured: {status}{', ' + date if date else ''}{', ' + account if account else ''}]"
|
||||
return text
|
||||
|
||||
t = PrettyTable()
|
||||
|
||||
@@ -5,9 +5,12 @@ One record per slot, all fields autosaved by the IOC (same layout as flOMNI's
|
||||
|
||||
OMNY-SAMPLE:<slot>:USED 0 = free, 1 = sample present
|
||||
OMNY-SAMPLE:<slot>:NAME sample name (long string, up to 256 chars)
|
||||
OMNY-SAMPLE:<slot>:OWNER e-account of the owner
|
||||
OMNY-SAMPLE:<slot>:STATUS none / started / completed (measurement status)
|
||||
OMNY-SAMPLE:<slot>:MEAS_DATE date of the measurement
|
||||
OMNY-SAMPLE:<slot>:OWNER owner of the sample (free text, not necessarily an e-account)
|
||||
OMNY-SAMPLE:<slot>:STATUS none / screened / started / completed (measurement status;
|
||||
screened = was on the sample stage, no tomoscan started)
|
||||
OMNY-SAMPLE:<slot>:MEAS_DATE date of the measurement (of the last status change)
|
||||
OMNY-SAMPLE:<slot>:MEAS_ACCOUNT e-account active when the status was last raised
|
||||
(2026-10-27; before, the account went into OWNER if it was empty)
|
||||
|
||||
<slot> (container, slot_nr of this device in brackets):
|
||||
A1..A6, B1..B6, C1..C6 shuttles ("A".."C", 1-6)
|
||||
@@ -47,8 +50,9 @@ NO_SHUTTLE = "none"
|
||||
STATUS_NONE = "none"
|
||||
STATUS_STARTED = "started"
|
||||
STATUS_COMPLETED = "completed"
|
||||
STATUS_VALUES = (STATUS_NONE, STATUS_STARTED, STATUS_COMPLETED)
|
||||
FIELDS = ("used", "name", "owner", "status", "meas_date")
|
||||
STATUS_SCREENED = "screened" # was on the sample stage, no tomoscan started (2026-10-27)
|
||||
STATUS_VALUES = (STATUS_NONE, STATUS_STARTED, STATUS_COMPLETED, STATUS_SCREENED)
|
||||
FIELDS = ("used", "name", "owner", "status", "meas_date", "meas_account")
|
||||
|
||||
# every sample slot of the IOC that this device handles, by PV slot name
|
||||
SAMPLE_SLOTS = (
|
||||
@@ -118,6 +122,7 @@ class OMNYSampleStorage(Device):
|
||||
"get_sample_name_and_owner",
|
||||
"get_sample_status",
|
||||
"get_sample_meas_date",
|
||||
"get_sample_meas_account",
|
||||
"get_sample_record",
|
||||
"set_sample_measured",
|
||||
"transfer_sample",
|
||||
@@ -139,6 +144,7 @@ class OMNYSampleStorage(Device):
|
||||
sample_owners = Dcpt(_sample_signals("owner"))
|
||||
sample_status = Dcpt(_sample_signals("status"))
|
||||
sample_meas_date = Dcpt(_sample_signals("meas_date"))
|
||||
sample_meas_account = Dcpt(_sample_signals("meas_account"))
|
||||
|
||||
# parking slots 1-6: which shuttle (letter in NAME) is docked
|
||||
parking_placed = Dcpt(_parking_signals("used"))
|
||||
@@ -161,6 +167,7 @@ class OMNYSampleStorage(Device):
|
||||
"owner": self.sample_owners,
|
||||
"status": self.sample_status,
|
||||
"meas_date": self.sample_meas_date,
|
||||
"meas_account": self.sample_meas_account,
|
||||
}[field]
|
||||
return getattr(group, slot)
|
||||
|
||||
@@ -176,7 +183,7 @@ class OMNYSampleStorage(Device):
|
||||
return "" if val is None else str(val)
|
||||
|
||||
# ── write ────────────────────────────────────────────────────────────────
|
||||
def _write(self, slot: str, used: int, name: str, owner: str, status: str, meas_date: str):
|
||||
def _write(self, slot: str, used: int, name: str, owner: str, status: str, meas_date: str, meas_account: str = ""):
|
||||
if status not in STATUS_VALUES:
|
||||
raise OMNYSampleStorageError(f"Invalid status {status!r}, expected one of {STATUS_VALUES}.")
|
||||
name = name if name else EMPTY_NAME
|
||||
@@ -185,6 +192,7 @@ class OMNYSampleStorage(Device):
|
||||
self._sig("owner", slot).set(owner or "").wait(timeout=5)
|
||||
self._sig("status", slot).set(status).wait(timeout=5)
|
||||
self._sig("meas_date", slot).set(meas_date or "").wait(timeout=5)
|
||||
self._sig("meas_account", slot).set(meas_account or "").wait(timeout=5)
|
||||
self._sig("used", slot).set(int(used)).wait(timeout=5)
|
||||
|
||||
def set_sample_slot(
|
||||
@@ -195,9 +203,10 @@ class OMNYSampleStorage(Device):
|
||||
owner: str = "",
|
||||
status: str = STATUS_NONE,
|
||||
meas_date: str = "",
|
||||
meas_account: str = "",
|
||||
):
|
||||
"""Place a sample record in (container, slot_nr): A/B/C 1-6, O 10-14/32-34/100/101."""
|
||||
self._write(slot_name(container, slot_nr), 1, name, owner, status, meas_date)
|
||||
self._write(slot_name(container, slot_nr), 1, name, owner, status, meas_date, meas_account)
|
||||
|
||||
def unset_sample_slot(self, container: str, slot_nr: int):
|
||||
"""Clear (container, slot_nr)."""
|
||||
@@ -217,30 +226,29 @@ class OMNYSampleStorage(Device):
|
||||
def unset_sample_in_samplestage(self):
|
||||
self.unset_sample_slot(STAGE, 0)
|
||||
|
||||
def set_sample_measured(self, container: str, slot_nr: int, status: str, meas_date: str, owner_if_empty: str = ""):
|
||||
def set_sample_measured(self, container: str, slot_nr: int, status: str, meas_date: str, account: str = ""):
|
||||
"""Record the measurement status/date of the sample in (container, slot_nr)
|
||||
(container "STAGE" for the sample stage).
|
||||
|
||||
If the sample has no owner yet, `owner_if_empty` (e.g. the active
|
||||
e-account) is stored as owner -- the label printed when a measured
|
||||
sample is cleared uses the owner as account.
|
||||
(container "STAGE" for the sample stage) and the e-account it happened in
|
||||
(`account`, e.g. bec.active_account) in MEAS_ACCOUNT. The owner is not
|
||||
touched (2026-10-27: owner and measurement account are separate fields;
|
||||
before, the account was stored as owner when the owner was empty).
|
||||
"""
|
||||
if status not in STATUS_VALUES:
|
||||
raise OMNYSampleStorageError(f"Invalid status {status!r}, expected one of {STATUS_VALUES}.")
|
||||
slot = slot_name(container, slot_nr)
|
||||
if owner_if_empty and not self._str(self._sig("owner", slot).get()):
|
||||
self._sig("owner", slot).set(owner_if_empty).wait(timeout=5)
|
||||
self._sig("status", slot).set(status).wait(timeout=5)
|
||||
self._sig("meas_date", slot).set(meas_date or "").wait(timeout=5)
|
||||
if account:
|
||||
self._sig("meas_account", slot).set(account).wait(timeout=5)
|
||||
|
||||
def transfer_sample(self, from_slot, to_slot):
|
||||
"""Move the complete record (name, owner, status, date) from one slot to
|
||||
"""Move the complete record (name, owner, status, date, account) from one slot to
|
||||
another and clear the source. Slots as (container, slot_nr) tuples or slot
|
||||
names: e.g. transfer_sample(("A", 3), "GRIPPER"), transfer_sample("GRIPPER", "STAGE")."""
|
||||
src = slot_name(*from_slot) if isinstance(from_slot, tuple) else slot_name(from_slot)
|
||||
dst = slot_name(*to_slot) if isinstance(to_slot, tuple) else slot_name(to_slot)
|
||||
rec = self.get_sample_record(src)
|
||||
self._write(dst, 1, rec["name"], rec["owner"], rec["status"], rec["meas_date"])
|
||||
self._write(dst, 1, rec["name"], rec["owner"], rec["status"], rec["meas_date"], rec["meas_account"])
|
||||
self._write(src, 0, EMPTY_NAME, "", STATUS_NONE, "")
|
||||
|
||||
def set_shuttle_slot(self, container: str, slot_nr: int):
|
||||
@@ -281,6 +289,9 @@ class OMNYSampleStorage(Device):
|
||||
def get_sample_meas_date(self, container: str, slot_nr: int = 0) -> str:
|
||||
return self._str(self._sig("meas_date", slot_name(container, slot_nr)).get())
|
||||
|
||||
def get_sample_meas_account(self, container: str, slot_nr: int = 0) -> str:
|
||||
return self._str(self._sig("meas_account", slot_name(container, slot_nr)).get())
|
||||
|
||||
def get_sample_record(self, container: str, slot_nr: int = 0) -> dict:
|
||||
return {
|
||||
"used": self.is_sample_slot_used(container, slot_nr),
|
||||
@@ -288,6 +299,7 @@ class OMNYSampleStorage(Device):
|
||||
"owner": self.get_sample_owner(container, slot_nr),
|
||||
"status": self.get_sample_status(container, slot_nr),
|
||||
"meas_date": self.get_sample_meas_date(container, slot_nr),
|
||||
"meas_account": self.get_sample_meas_account(container, slot_nr),
|
||||
}
|
||||
|
||||
def get_sample_name_in_gripper(self) -> str:
|
||||
@@ -332,11 +344,15 @@ class OMNYSampleStorage(Device):
|
||||
owner = self.get_sample_owner(container, slot_nr)
|
||||
status = self.get_sample_status(container, slot_nr)
|
||||
date = self.get_sample_meas_date(container, slot_nr)
|
||||
account = self.get_sample_meas_account(container, slot_nr)
|
||||
suffix = f" ({owner})" if owner else ""
|
||||
if status == STATUS_STARTED:
|
||||
suffix += " ◐ started" + (f" {date}" if date else "")
|
||||
when = (f" {date}" if date else "") + (f" [{account}]" if account else "")
|
||||
if status == STATUS_SCREENED:
|
||||
suffix += " ○ screened" + when
|
||||
elif status == STATUS_STARTED:
|
||||
suffix += " ◐ started" + when
|
||||
elif status == STATUS_COMPLETED:
|
||||
suffix += " ✓ completed" + (f" {date}" if date else "")
|
||||
suffix += " ✓ completed" + when
|
||||
return name + suffix
|
||||
|
||||
def show_all(self):
|
||||
|
||||
@@ -461,10 +461,13 @@ def main(): # noqa: C901
|
||||
"gripper -> slot move carries the status",
|
||||
)
|
||||
samples.unset_sample_slot(5)
|
||||
# set_sample_measured fills an empty owner (label printing uses the owner as account)
|
||||
samples.set_sample_slot(6, "no_owner_sample")
|
||||
samples.set_sample_measured(6, "started", "2026-10", owner_if_empty="e99999")
|
||||
check(samples.get_sample_owner(6) == "e99999", "owner_if_empty fills an empty owner")
|
||||
# set_sample_measured stores the measurement account separately, the owner is kept
|
||||
samples.set_sample_slot(6, "owned_sample", "Group XY")
|
||||
samples.set_sample_measured(6, "started", "2026-10", account="e99999")
|
||||
check(
|
||||
samples.get_sample_owner(6) == "Group XY" and samples.get_sample_meas_account(6) == "e99999",
|
||||
"set_sample_measured stores the account in MEAS_ACCOUNT, owner untouched",
|
||||
)
|
||||
samples.unset_sample_slot(6)
|
||||
|
||||
frame_a = ids_cam.cam.get_image_data()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""OMNYSampleStorage on the OMNY soft IOC records (OMNY-SAMPLE:<slot>:USED/NAME/OWNER/STATUS/MEAS_DATE)."""
|
||||
"""OMNYSampleStorage on the OMNY soft IOC records (OMNY-SAMPLE:<slot>:USED/NAME/OWNER/STATUS/MEAS_DATE/MEAS_ACCOUNT)."""
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -40,6 +40,7 @@ def test_pv_names_match_the_ioc():
|
||||
assert OMNYSampleStorage.sample_names.defn["P100"][1] == "OMNY-SAMPLE:P100:NAME"
|
||||
assert OMNYSampleStorage.sample_status.defn["STAGE"][1] == "OMNY-SAMPLE:STAGE:STATUS"
|
||||
assert OMNYSampleStorage.sample_meas_date.defn["GRIPPER"][1] == "OMNY-SAMPLE:GRIPPER:MEAS_DATE"
|
||||
assert OMNYSampleStorage.sample_meas_account.defn["A3"][1] == "OMNY-SAMPLE:A3:MEAS_ACCOUNT"
|
||||
assert OMNYSampleStorage.parking_names.defn["parking3"][1] == "OMNY-SAMPLE:PARK3:NAME"
|
||||
assert len(SAMPLE_SLOTS) == 18 + 10 + 2
|
||||
|
||||
@@ -47,7 +48,8 @@ def test_pv_names_match_the_ioc():
|
||||
def test_set_and_unset_slot(storage):
|
||||
storage.set_sample_slot("O", 32, "pin1", "e12345")
|
||||
assert storage.get_sample_record("O", 32) == {
|
||||
"used": True, "name": "pin1", "owner": "e12345", "status": "none", "meas_date": ""}
|
||||
"used": True, "name": "pin1", "owner": "e12345", "status": "none", "meas_date": "",
|
||||
"meas_account": ""}
|
||||
storage.unset_sample_slot("O", 32)
|
||||
rec = storage.get_sample_record("O", 32)
|
||||
assert rec["used"] is False and rec["name"] == "-" and rec["owner"] == ""
|
||||
@@ -55,23 +57,39 @@ def test_set_and_unset_slot(storage):
|
||||
|
||||
def test_status_travels_with_the_sample(storage):
|
||||
storage.set_sample_slot("B", 2, "pin2", "e11111")
|
||||
storage.set_sample_measured("B", 2, "completed", "2026-10")
|
||||
storage.set_sample_measured("B", 2, "completed", "2026-10", account="e20001")
|
||||
storage.transfer_sample(("B", 2), "GRIPPER")
|
||||
storage.transfer_sample("GRIPPER", "STAGE")
|
||||
assert not storage.is_sample_slot_used("B", 2)
|
||||
assert not storage.is_sample_in_gripper()
|
||||
assert storage.get_sample_record("STAGE") == {
|
||||
"used": True, "name": "pin2", "owner": "e11111", "status": "completed", "meas_date": "2026-10"}
|
||||
"used": True, "name": "pin2", "owner": "e11111", "status": "completed", "meas_date": "2026-10",
|
||||
"meas_account": "e20001"}
|
||||
|
||||
|
||||
def test_set_sample_measured_owner_if_empty(storage):
|
||||
storage.set_sample_in_samplestage("pin3")
|
||||
storage.set_sample_measured("STAGE", 0, "started", "2026-10", owner_if_empty="e22222")
|
||||
assert storage.get_sample_owner_in_samplestage() == "e22222"
|
||||
def test_set_sample_measured_stores_the_account_not_the_owner(storage):
|
||||
# owner (free text) and measurement account are separate fields (2026-10-27)
|
||||
storage.set_sample_in_samplestage("pin3", "Group XY")
|
||||
storage.set_sample_measured("STAGE", 0, "started", "2026-10", account="e22222")
|
||||
assert storage.get_sample_owner_in_samplestage() == "Group XY"
|
||||
assert storage.get_sample_status_in_samplestage() == "started"
|
||||
# an existing owner is kept
|
||||
storage.set_sample_measured("STAGE", 0, "completed", "2026-10", owner_if_empty="e33333")
|
||||
assert storage.get_sample_owner_in_samplestage() == "e22222"
|
||||
assert storage.get_sample_meas_account("STAGE") == "e22222"
|
||||
# the account of the latest status change is stored
|
||||
storage.set_sample_measured("STAGE", 0, "completed", "2026-10", account="e33333")
|
||||
assert storage.get_sample_meas_account("STAGE") == "e33333"
|
||||
# no account given: the stored one is kept
|
||||
storage.set_sample_measured("STAGE", 0, "completed", "2026-11")
|
||||
assert storage.get_sample_meas_account("STAGE") == "e33333"
|
||||
# loading a new sample resets status, date and account
|
||||
storage.set_sample_in_samplestage("pin3b", "Group XY")
|
||||
assert storage.get_sample_record("STAGE")["meas_account"] == ""
|
||||
|
||||
|
||||
def test_screened_status(storage):
|
||||
storage.set_sample_slot("C", 4, "pin5", "someone")
|
||||
storage.set_sample_measured("C", 4, "screened", "2026-10", account="e44444")
|
||||
assert storage.get_sample_status("C", 4) == "screened"
|
||||
assert storage.get_sample_meas_account("C", 4) == "e44444"
|
||||
|
||||
|
||||
def test_invalid_status_raises(storage):
|
||||
|
||||
@@ -33,6 +33,6 @@ def test_default_samples_still_seeded_in_shuttle_a(storage):
|
||||
|
||||
def test_untouched_slots_read_empty(storage):
|
||||
rec = storage.get_sample_record("O", 100)
|
||||
assert rec == {"used": False, "name": "-", "owner": "", "status": "none", "meas_date": ""}
|
||||
assert rec == {"used": False, "name": "-", "owner": "", "status": "none", "meas_date": "", "meas_account": ""}
|
||||
assert storage.get_sample_name_in_samplestage() == "sim_stage_sample"
|
||||
assert not storage.is_sample_in_gripper()
|
||||
Reference in new issue
Block a user