APS-4ID-POLAR / polar_instrument

Bluesky setup for the POLAR beamline
0 stars 0 forks source link

Duplicated specwriter subscription #29

Open gfabbris opened 4 days ago

gfabbris commented 4 days ago

We have a duplicated specwriter RE subscription during startup:

https://github.com/APS-4ID-POLAR/polar_instrument/blob/19dad53865917db7f0526ec42823c97040078ac4/instrument/collection.py#L130

https://github.com/APS-4ID-POLAR/polar_instrument/blob/19dad53865917db7f0526ec42823c97040078ac4/instrument/framework/callbacks.py#L32

@prjemian: This is a detail, but is there any "standard practice" for where to have this?

prjemian commented 4 days ago

Funny. Was just looking at this situation today. Not sure if there is a standard way. Here's what I'd do. In short:

if iconfig.get("NEXUS_DATA_FILES", False):
    from .nexus_data_file_writer import *  # noqa

if iconfig.get("SPEC_DATA_FILES", False):
    from .spec_data_file_writer import *  # noqa

RE callback subscriptions require a bit of consideration. They need the RE object already defined, and they need the callback defined as configured by the instrument. Because of these factors, it seems easiest to import any configured callbacks from the instrument/callbacks/__init__.py file, as shown above.

BTW, we're working on an overhaul of the instrument template for APS beamlines. We have two propositions now:

prjemian commented 4 days ago

This demo uses a re-arranged iconfig.yml file.

Using a version number to keep track.

# identify the version of this iconfig.yml file
ICONFIG_VERSION: 2.0.0
prjemian commented 4 days ago

Summary recommendation

Don't subscribe callbacks in collection. Instead, do it in callbacks/__init__.py. If you have iconfig settings, apply them as shown above.

prjemian commented 4 days ago

With the new iconfig.yml keys, that code example (above) needs revision:

if iconfig.get("NEXUS_DATA_FILES") is not None:
    from .nexus_data_file_writer import *  # noqa

if iconfig.get("SPEC_DATA_FILES") is not None:
    from .spec_data_file_writer import *  # noqa
gfabbris commented 4 days ago

Sounds good. I like the organization of your prototype, will try to migrate it to that.