From 8755e30d3d2a71096709b3ff9746bc26757ef444 Mon Sep 17 00:00:00 2001 From: appel_c Date: Tue, 19 Mar 2024 10:20:50 +0100 Subject: [PATCH] Initial commit --- README.md | 3 + bec_plugins/__init__.py | 0 bec_plugins/bec_client/__init__.py | 0 .../high_level_interface/__init__.py | 0 bec_plugins/bec_client/plugins/__init__.py | 0 bec_plugins/bec_client/startup/__init__.py | 0 .../bec_client/startup/post_startup.py | 63 +++++++++++++++++++ bec_plugins/bec_client/startup/pre_startup.py | 25 ++++++++ bec_plugins/dap_services/__init__.py | 0 bec_plugins/device_configs/__init__.py | 0 bec_plugins/device_server/__init__.py | 0 bec_plugins/devices/__init__.py | 0 bec_plugins/scan_server/__init__.py | 0 .../scan_server/scan_plugins/__init__.py | 0 .../scan_plugins/scan_plugin_template.py | 32 ++++++++++ setup.cfg | 21 +++++++ setup.py | 9 +++ 17 files changed, 153 insertions(+) create mode 100644 README.md create mode 100644 bec_plugins/__init__.py create mode 100644 bec_plugins/bec_client/__init__.py create mode 100644 bec_plugins/bec_client/high_level_interface/__init__.py create mode 100644 bec_plugins/bec_client/plugins/__init__.py create mode 100644 bec_plugins/bec_client/startup/__init__.py create mode 100644 bec_plugins/bec_client/startup/post_startup.py create mode 100644 bec_plugins/bec_client/startup/pre_startup.py create mode 100644 bec_plugins/dap_services/__init__.py create mode 100644 bec_plugins/device_configs/__init__.py create mode 100644 bec_plugins/device_server/__init__.py create mode 100644 bec_plugins/devices/__init__.py create mode 100644 bec_plugins/scan_server/__init__.py create mode 100644 bec_plugins/scan_server/scan_plugins/__init__.py create mode 100644 bec_plugins/scan_server/scan_plugins/scan_plugin_template.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..229ceec --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# TOMCAT BEC + +Tomcat specific plugins and configs for BEC \ No newline at end of file diff --git a/bec_plugins/__init__.py b/bec_plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/bec_client/__init__.py b/bec_plugins/bec_client/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/bec_client/high_level_interface/__init__.py b/bec_plugins/bec_client/high_level_interface/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/bec_client/plugins/__init__.py b/bec_plugins/bec_client/plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/bec_client/startup/__init__.py b/bec_plugins/bec_client/startup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/bec_client/startup/post_startup.py b/bec_plugins/bec_client/startup/post_startup.py new file mode 100644 index 0000000..129c3d4 --- /dev/null +++ b/bec_plugins/bec_client/startup/post_startup.py @@ -0,0 +1,63 @@ +""" +Post startup script for the BEC client. This script is executed after the +IPython shell is started. It is used to load the beamline specific +information and to setup the prompts. + +The script is executed in the global namespace of the IPython shell. This +means that all variables defined here are available in the shell. + +If needed, bec command-line arguments can be parsed here. For example, to +parse the --session argument, add the following lines to the script: + + import argparse + parser = argparse.ArgumentParser() + parser.add_argument("--session", help="Session name", type=str, default="my_default_session") + args = parser.parse_args() + + if args.session == "my_session": + print("Loading my_session session") + from bec_plugins.bec_client.plugins.my_session import * + else: + print("Loading default session") + from bec_plugins.bec_client.plugins.default_session import * +""" + +# pylint: disable=invalid-name, unused-import, import-error, undefined-variable, unused-variable, unused-argument, no-name-in-module + +# import argparse +# parser = argparse.ArgumentParser() +# parser.add_argument("--session", help="Session name", type=str, default="my_default_session") +# args = parser.parse_args() + +# if args.session == "my_session": +# print("Loading my_session session") +# from bec_plugins.bec_client.plugins.my_session import * +# else: +# print("Loading default session") +# from bec_plugins.bec_client.plugins.default_session import * + + +# SETUP BEAMLINE INFO +# from bec_client.plugins.SLS.sls_info import OperatorInfo, SLSInfo + +# from bec_plugins.bec_client.plugins.MyBeamline.beamline_info import BeamlineInfo + +# bec._beamline_mixin._bl_info_register(BeamlineInfo) +# bec._beamline_mixin._bl_info_register(SLSInfo) +# bec._beamline_mixin._bl_info_register(OperatorInfo) + +# SETUP PROMPTS +# bec._ip.prompts.username = args.session +# bec._ip.prompts.status = 1 + + +# REGISTER BEAMLINE CHECKS +# from bec_lib.bl_conditions import ( +# LightAvailableCondition, +# ShutterCondition, +# ) + +# _light_available_condition = LightAvailableCondition(dev.sls_machine_status) +# _shutter_condition = ShutterCondition(dev.x12sa_es1_shutter_status) +# bec.bl_checks.register(_light_available_condition) +# bec.bl_checks.register(_shutter_condition) diff --git a/bec_plugins/bec_client/startup/pre_startup.py b/bec_plugins/bec_client/startup/pre_startup.py new file mode 100644 index 0000000..dcfa194 --- /dev/null +++ b/bec_plugins/bec_client/startup/pre_startup.py @@ -0,0 +1,25 @@ +""" +Pre-startup script for BEC client. This script is executed before the BEC client +is started. It can be used to set up the BEC client configuration. The script is +executed in the global namespace of the BEC client. This means that all +variables defined here are available in the BEC client. + +To set up the BEC client configuration, use the ServiceConfig class. For example, +to set the configuration file path, add the following lines to the script: + + import pathlib + from bec_lib.core import ServiceConfig + + current_path = pathlib.Path(__file__).parent.resolve() + CONFIG_PATH = f"{current_path}/" + + config = ServiceConfig(CONFIG_PATH) + +If this startup script defined a ServiceConfig object, the BEC client will use +it to configure itself. Otherwise, the BEC client will use the default config. +""" + +# example: +# current_path = pathlib.Path(__file__).parent.resolve() +# CONFIG_PATH = f"{current_path}/../../../bec_config.yaml" +# config = ServiceConfig(CONFIG_PATH) diff --git a/bec_plugins/dap_services/__init__.py b/bec_plugins/dap_services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/device_configs/__init__.py b/bec_plugins/device_configs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/device_server/__init__.py b/bec_plugins/device_server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/devices/__init__.py b/bec_plugins/devices/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/scan_server/__init__.py b/bec_plugins/scan_server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/scan_server/scan_plugins/__init__.py b/bec_plugins/scan_server/scan_plugins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bec_plugins/scan_server/scan_plugins/scan_plugin_template.py b/bec_plugins/scan_server/scan_plugins/scan_plugin_template.py new file mode 100644 index 0000000..5dbbd7e --- /dev/null +++ b/bec_plugins/scan_server/scan_plugins/scan_plugin_template.py @@ -0,0 +1,32 @@ +""" +SCAN PLUGINS + +All new scans should be derived from ScanBase. ScanBase provides various methods that can be customized and overriden +but they are executed in a specific order: + +- self.initialize # initialize the class if needed +- self.read_scan_motors # used to retrieve the start position (and the relative position shift if needed) +- self.prepare_positions # prepare the positions for the scan. The preparation is split into multiple sub fuctions: + - self._calculate_positions # calculate the positions + - self._set_positions_offset # apply the previously retrieved scan position shift (if needed) + - self._check_limits # tests to ensure the limits won't be reached +- self.open_scan # send an open_scan message including the scan name, the number of points and the scan motor names +- self.stage # stage all devices for the upcoming acquisiton +- self.run_baseline_readings # read all devices to get a baseline for the upcoming scan +- self.pre_scan # perform additional actions before the scan starts +- self.scan_core # run a loop over all position + - self._at_each_point(ind, pos) # called at each position with the current index and the target positions as arguments +- self.finalize # clean up the scan, e.g. move back to the start position; wait everything to finish +- self.unstage # unstage all devices that have been staged before +- self.cleanup # send a close scan message and perform additional cleanups if needed +""" + +# import time + +# import numpy as np + +# from bec_lib import MessageEndpoints, bec_logger, messages +# from scan_server.errors import ScanAbortion +# from scan_server.scans import FlyScanBase, RequestBase, ScanArgType, ScanBase + +# logger = bec_logger.logger diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a5ae6c0 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,21 @@ +[metadata] +name = bec_plugins +description = BEC plugins to modify the behaviour of services within the BEC framework +long_description = file: README.md +long_description_content_type = text/markdown +url = https://gitlab.psi.ch/bec/bec +project_urls = + Bug Tracker = https://gitlab.psi.ch/bec/bec/issues +classifiers = + Programming Language :: Python :: 3 + Development Status :: 3 - Alpha + Topic :: Scientific/Engineering + +[options] +package_dir = + = . +packages = find: +python_requires = >=3.10 + +[options.packages.find] +where = . diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c6d8a91 --- /dev/null +++ b/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup + +if __name__ == "__main__": + setup( + # specify the additional dependencies + install_requires=[], + # if you have additional dependencies for development, specify them here + extras_require={"dev": ["pytest", "pytest-random-order", "coverage"]}, + )