Open prjemian opened 4 weeks ago
Suggestion (from @keenanlang) when part of the PV name is different than convention:
cam = ADComponent(cam_class, "cam1:")
In some implementations, the "cam1:"
part of the detector's PV names could be different. Should be a configurable option in a detector factory function.
From XPCS:
use_image=True,
use_overlay=True,
use_process=True,
use_pva=True,
use_roi=True,
use_stats=True,
use_transform=True,
At HEXM, AD factory function does the following:
For detector specificity, the factory accepts a detector mixin that contains:
Additionally:
@cooleyv Is that function available on github or gitlab somewhere? I'd like to take a look if possible.
It sounds like a great idea, especially the part about detecting plugin versions since that is a constant pitfall for me in getting our AD support right.
However, if I understand that right, this means that the factory will fail if there's not an actual IOC running, right? Could the AD version or plugin version be an optional argument to the factory (e.g. plugin_version="34"
, or ad_core_version=...
) that then skips the part where it connects to a real IOC?
The use case here is that when I write tests I commonly use a pattern where I create a fake device using Ophyd's sim
module:
from ophyd.sim import instantiate_fake_device
from haven.instrument.area_detector import SPCAreaDetector # or whatever
def test_my_area_detector():
fake_ad = instantiate_fake_device(SPCAreaDetector, prefix="255ID:AD", name="fake_ad")
# Write some tests here to make sure the device works
# but since it's fake, no actual IOC is necessary
fake_ad.stage()
assert fake_ad.cam.acquire_time.get() == 2. # or whatever
...
with a factory, then the test becomes:
from ophyd.sim import instantiate_fake_device
from haven.instrument.area_detector import ad_factory # or whatever
def test_my_area_detector():
AD_Class = ad_factory(...)
fake_ad = instantiate_fake_device(AD_Class, prefix="255ID:AD", name="fake_ad")
# Write some tests here to make sure the device works
# but since it's fake, no actual IOC is necessary
fake_ad.stage()
assert fake_ad.cam.acquire_time.get() == 2. # or whatever
...
which is fine except that ad_factory(...)
will fail without an IOC present because the intermediate signal is a real ophyd Signal
object instead of a fake one. It's possible to mock area_detector.Signal
, but that can get a bit messy.
A factory function might make it easier to create area detector classes and instances. The factory would address common configurations (such as PVA, HDF5, ...) as options, triggered by keywords. Additional kwargs would describe supplemental options such as the file path seen by the IOC.