-
Notifications
You must be signed in to change notification settings - Fork 0
/
queueserver_framework.py
114 lines (96 loc) · 2.78 KB
/
queueserver_framework.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Define RE for bluesky-queueserver.
"""
__all__ = """
cat
make_kv_table
print_instrument_configuration
print_RE_metadata
RE
sd
""".split()
import logging
logger = logging.getLogger(__name__)
logger.info(__file__)
print(__file__)
from . import iconfig
from .epics_signal_config import epics_scan_id_source
from .epics_signal_config import scan_id_epics
import apstools
import bluesky
import bluesky_queueserver
import databroker
import epics
import getpass
import h5py
import matplotlib
import numpy
import ophyd
import os
import pyRestTable
import socket
import spec2nexus
HOSTNAME = socket.gethostname() or "localhost"
USERNAME = getpass.getuser() or "queueserver user"
# useful diagnostic to record with all data
versions = dict(
apstools=apstools.__version__,
bluesky=bluesky.__version__,
bluesky_queueserver=bluesky_queueserver.__version__,
databroker=databroker.__version__,
epics=epics.__version__,
h5py=h5py.__version__,
matplotlib=matplotlib.__version__,
numpy=numpy.__version__,
ophyd=ophyd.__version__,
pyRestTable=pyRestTable.__version__,
spec2nexus=spec2nexus.__version__,
)
try:
cat = databroker.catalog[iconfig["DATABROKER_CATALOG"]]
logger.info("using databroker catalog '%s'", cat.name)
except KeyError:
cat = databroker.temp().v2
logger.info("using TEMPORARY databroker catalog '%s'", cat.name)
if scan_id_epics is None:
RE = bluesky.RunEngine({})
else:
RE = bluesky.RunEngine({}, scan_id_source=epics_scan_id_source)
logger.info(r"RE 'scan_id' uses EPICS PV: {scan_id_epics.pvname}")
RE.subscribe(cat.v1.insert)
RE.md["databroker_catalog"] = cat.name
RE.md["login_id"] = USERNAME + "@" + HOSTNAME
RE.md.update(iconfig.get("RUNENGINE_METADATA", {}))
RE.md["versions"] = versions
RE.md["pid"] = os.getpid()
if scan_id_epics is not None:
RE.md["scan_id"] = scan_id_epics.get()
# Set up SupplementalData.
sd = bluesky.SupplementalData()
RE.preprocessors.append(sd)
ophyd.set_cl(iconfig.get("OPHYD_CONTROL_LAYER", "PyEpics").lower())
logger.info(f"using ophyd control layer: {ophyd.cl.name}")
def make_kv_table(data):
table = pyRestTable.Table()
table.labels = "key value".split()
for k, v in sorted(data.items()):
if isinstance(v, dict):
table.addRow((k, make_kv_table(v)))
else:
table.addRow((k, v))
return table
def print_instrument_configuration():
if len(iconfig) > 0:
table = make_kv_table(iconfig)
print("")
print("Instrument configuration (iconfig):")
print(table)
def print_RE_metadata():
"""
Print a table (to the console) with the current RunEngine metadata.
"""
if len(RE.md) > 0:
table = make_kv_table(RE.md)
print("")
print("RunEngine metadata:")
print(table)