Skip to content

Commit

Permalink
Merge pull request #99 from ZLLentz/platform-rework
Browse files Browse the repository at this point in the history
ENH: Daq Platform rework
  • Loading branch information
ZLLentz authored Apr 6, 2018
2 parents 6feef92 + ef9a8e4 commit acdc3ae
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 30 deletions.
7 changes: 2 additions & 5 deletions docs/source/environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ development purposes. This can be achieved trivially if your environment is in
highly suggest downloading `miniconda <https://conda.io/miniconda.html>`_
and giving it a try.

The requirements have not yet been consolidated into one conda channel, but we
plan to place everything in the ``pcds-tag`` channel in the future. Currently,
to pick up all dependencies, run this command:
To pick up all dependencies, run this command:

``conda install hutch-python -c pcds-tag -c pydm-tag -c lightsource2-tag
-c defaults -c conda-forge``
``conda install hutch-python -c pcds-tag -c defaults -c conda-forge``
24 changes: 22 additions & 2 deletions docs/source/yaml_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Yaml Files
==========

``hutch-python`` uses a ``conf.yml`` file for basic configuration. This is a
standard yaml file with four valid keys:
``hutch``, ``db``, ``load``, and ``experiment``.
standard yaml file with five valid keys:
``hutch``, ``db``, ``load``, ``experiment``, and ``daq_platform``.


hutch
Expand Down Expand Up @@ -86,6 +86,23 @@ This key is used to force the questionnaire and experiment file to be from a
particular experiment.


daq_platform
------------

The ``daq_platform`` is another optional key that can be used to configure
which ``platform`` your running daq uses on a per-hutch or per-host basis.
The default ``platform`` is zero, but you can set a different ``platform``
for your hutch by using the ``default`` key as shown below. You can set a
platform for a particular host by using that host's name as a key as shown
below.

.. code-block:: YMAL
daq_platform:
default: 4
cxi-control: 5
Full File Example
-----------------

Expand All @@ -97,3 +114,6 @@ Full File Example
load:
- xpp.beamline
daq_platform:
default: 1
11 changes: 1 addition & 10 deletions hutch_python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@

CLASS_SEARCH_PATH = ['pcdsdevices.device_types']

DAQ_MAP = dict(amo=0,
sxr=0,
xpp=1,
xcs=1,
mfx=4,
cxi=4,
mec=0,
tst=0)

DIR_MODULE = Path(__file__).resolve().parent

FILE_YAML = DIR_MODULE / 'logging.yml'
Expand All @@ -30,4 +21,4 @@

SUCCESS_LEVEL = 35

VALID_KEYS = ('hutch', 'db', 'load', 'experiment')
VALID_KEYS = ('hutch', 'db', 'load', 'experiment', 'daq_platform')
14 changes: 6 additions & 8 deletions hutch_python/daq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@

from pcdsdaq.daq import Daq

from .constants import DAQ_MAP

logger = logging.getLogger(__name__)


def get_daq_objs(hutch, RE):
def get_daq_objs(platform, RE):
"""
Create an instance of ``Daq`` for ``hutch``.
Create an instance of ``Daq``.
This makes sure that the ``Daq`` object is set up to connect to that
This makes sure that the ``Daq`` object is set up to connect to a
hutch's daq, and that it is ready to use in scans with ``RE``.
Parameters
----------
hutch: ``str``
The relevant hutch name
platform: ``int``
The daq platform variable associated with the hutch's daq.
RE: ``RunEngine``
The session's ``RE`` object
Expand All @@ -28,5 +26,5 @@ def get_daq_objs(hutch, RE):
A dictionary that contains a single key, ``daq``, and a ready instance
of the ``Daq`` class.
"""
daq = Daq(platform=DAQ_MAP[hutch], RE=RE)
daq = Daq(platform=platform, RE=RE)
return dict(daq=daq)
27 changes: 22 additions & 5 deletions hutch_python/load_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import yaml
from pathlib import Path
from socket import gethostname

from bluesky import RunEngine
from bluesky.callbacks.best_effort import BestEffortCallback
Expand Down Expand Up @@ -70,7 +71,9 @@ def load_conf(conf, hutch_dir=None):
not provided, or the hutch name e.g. ``mfx.db``.
- Create a ``RunEngine``, ``RE``
- Import ``plan_defaults`` and include as ``p``, ``plans``
- Use ``hutch`` key to create a ``daq`` object with ``RE`` registered
- Create a ``daq`` object with ``RE`` registered, using ``daq_platform``
to define the ``platform`` argument if provided. The default value if
``daq_platform`` was not defined is 0.
- Use ``db`` key to load devices from the ``happi`` beamline database
and create a ``hutch_beampath`` object from ``lightpath``
- Use ``load`` key to bring up the user's ``beamline`` modules
Expand Down Expand Up @@ -163,6 +166,21 @@ def load_conf(conf, hutch_dir=None):
'load objects from questionnaire or experiment '
'file.'))

try:
platform_info = conf['daq_platform']
hostname = gethostname()
try:
daq_platform = platform_info[hostname]
logger.info('Selected %s daq platform: %s',
hostname, daq_platform)
except KeyError:
daq_platform = platform_info['default']
logger.info('Selected default %s daq platform: %s',
hutch, daq_platform)
except KeyError:
daq_platform = 0
logger.info('Selected default hutch-python daq platform: 0')

# Display the banner
if hutch is None:
hutch_banner()
Expand All @@ -188,10 +206,9 @@ def load_conf(conf, hutch_dir=None):
cache(p=plan_defaults)

# Daq
if hutch is not None:
with safe_load('daq'):
daq_objs = get_daq_objs(hutch, RE)
cache(**daq_objs)
with safe_load('daq'):
daq_objs = get_daq_objs(daq_platform, RE)
cache(**daq_objs)

# Happi db and Lightpath
if db is not None:
Expand Down
22 changes: 22 additions & 0 deletions hutch_python/tests/test_load_conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
import os.path
from socket import gethostname
from types import SimpleNamespace

from pcdsdaq.sim import set_sim_mode
from pcdsdevices.mv_interface import Presets

import hutch_python.qs_load
Expand All @@ -14,6 +16,7 @@

def test_file_load():
logger.debug('test_file_load')
set_sim_mode(True)
objs = load(os.path.join(os.path.dirname(__file__), 'conf.yaml'))
should_have = ('x', 'unique_device', 'calc_thing', 'daq', 'tst_beampath')
err = '{} was overriden by a namespace'
Expand All @@ -35,6 +38,25 @@ def test_conf_empty():
assert len(objs) > 1


def test_conf_platform():
logger.debug('test_conf_platform')
set_sim_mode(True)
# No platform
objs = load_conf({})
assert objs['daq']._plat == 0
# Define default platform
objs = load_conf({'daq_platform': {'default': 1}})
assert objs['daq']._plat == 1
# Define host platform
hostname = gethostname()
objs = load_conf({'daq_platform': {hostname: 2}})
assert objs['daq']._plat == 2
# Define both
objs = load_conf({'daq_platform': {'default': 3,
hostname: 4}})
assert objs['daq']._plat == 4


def test_skip_failures():
logger.debug('test_skip_failures')
# Should not raise
Expand Down

0 comments on commit acdc3ae

Please sign in to comment.