mosca-client 2.0.2__tar.gz → 2.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {mosca_client-2.0.2 → mosca_client-2.0.5}/PKG-INFO +1 -1
  2. {mosca_client-2.0.2 → mosca_client-2.0.5}/pyproject.toml +1 -1
  3. mosca_client-2.0.5/src/mosca_client/logging.py +111 -0
  4. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/dante.py +6 -1
  5. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/falconx.py +0 -5
  6. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/xia.py +4 -14
  7. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/mca.py +20 -6
  8. mosca_client-2.0.5/src/mosca_client/tango/mosca.py +367 -0
  9. mosca_client-2.0.5/src/mosca_client/tango/readers.py +564 -0
  10. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/rois.py +21 -21
  11. mosca_client-2.0.5/src/mosca_client/tango/saving.py +263 -0
  12. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/utils.py +18 -0
  13. mosca_client-2.0.2/src/mosca_client/tango/mosca.py +0 -639
  14. mosca_client-2.0.2/src/mosca_client/tango/saving.py +0 -135
  15. {mosca_client-2.0.2 → mosca_client-2.0.5}/.gitignore +0 -0
  16. {mosca_client-2.0.2 → mosca_client-2.0.5}/README.rst +0 -0
  17. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/__init__.py +0 -0
  18. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/__init__.py +0 -0
  19. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/__init__.py +0 -0
  20. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/danteplus.py +0 -0
  21. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/dummy.py +0 -0
  22. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/generator.py +0 -0
  23. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/simdante.py +0 -0
  24. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/simfalconx.py +0 -0
  25. {mosca_client-2.0.2 → mosca_client-2.0.5}/src/mosca_client/tango/devices/simulation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mosca-client
3
- Version: 2.0.2
3
+ Version: 2.0.5
4
4
  Requires-Python: <3.13,>=3.10
5
5
  Requires-Dist: numpy
6
6
  Requires-Dist: pytango
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "mosca-client"
3
3
  requires-python = ">=3.10,<3.13"
4
- version = "2.0.2"
4
+ version = "2.0.5"
5
5
 
6
6
  dependencies = [
7
7
  "pytango",
@@ -0,0 +1,111 @@
1
+ import logging
2
+
3
+
4
+
5
+ _CONSOLE_INFO = logging.INFO + 1
6
+ _CONSOLE_WARNING = logging.INFO + 2
7
+ _CONSOLE_ERROR = logging.INFO + 3
8
+ logging.addLevelName(_CONSOLE_INFO, "CONSOLE_INFO")
9
+ logging.addLevelName(_CONSOLE_ERROR, "CONSOLE_ERROR")
10
+ logging.addLevelName(_CONSOLE_WARNING, "CONSOLE_WARNING")
11
+
12
+
13
+ TRACE_LEVEL = 5 # Set TRACE level just below DEBUG
14
+ logging.addLevelName(TRACE_LEVEL, "TRACE")
15
+
16
+
17
+ LOG_FORMAT_INFO = (
18
+ "[Mosca] "
19
+ "%(message)s"
20
+ )
21
+
22
+ LOG_FORMAT = (
23
+ "[Mosca] "
24
+ "%(levelname)-8s "
25
+ #"[%(name)s] "
26
+ "%(message)s"
27
+ )
28
+
29
+ LOG_FORMAT_FULL = (
30
+ "[%(asctime)s.%(msecs)03d] "
31
+ "%(levelname)-8s "
32
+ "[%(name)s] "
33
+ "%(message)s (%(filename)s:%(lineno)d)"
34
+ )
35
+
36
+
37
+ ASC_TIME = "%Y-%m-%d %H:%M:%S"
38
+
39
+ import enum
40
+ class COLORS(enum.Enum):
41
+ GREY = "\x1b[38;21m"
42
+ BLUE = "\x1b[38;5;39m"
43
+ YELLOW = "\x1b[38;5;226m"
44
+ GREEN = "\x1b[32m"
45
+ RED = "\x1b[38;5;196m"
46
+ ORANGE = "\x1b[38;5;208m"
47
+ BOLD_RED = "\x1b[31;1m"
48
+ RESET = "\x1b[0m"
49
+ NONE = ""
50
+
51
+
52
+ FORMATS = {
53
+ logging.DEBUG: (COLORS.BLUE, LOG_FORMAT_FULL),
54
+ logging.INFO: (COLORS.GREEN, LOG_FORMAT_FULL),
55
+ logging.WARNING: (COLORS.YELLOW, LOG_FORMAT_FULL),
56
+ logging.ERROR: (COLORS.RED, LOG_FORMAT_FULL),
57
+ logging.CRITICAL: (COLORS.BOLD_RED, LOG_FORMAT_FULL),
58
+ _CONSOLE_INFO: (COLORS.GREEN, LOG_FORMAT_INFO),
59
+ _CONSOLE_WARNING: (COLORS.YELLOW, LOG_FORMAT),
60
+ _CONSOLE_ERROR: (COLORS.ORANGE, LOG_FORMAT),
61
+ }
62
+
63
+
64
+ class MoscaColorFormatter(logging.Formatter):
65
+ """
66
+ Color formatter
67
+ """
68
+
69
+ def __init__(self):
70
+ super().__init__()
71
+ self._color_formatters = {
72
+ level: logging.Formatter(color.value + format + COLORS.RESET.value, ASC_TIME)
73
+ for level, (color, format) in FORMATS.items()}
74
+ self._default = logging.Formatter(LOG_FORMAT, ASC_TIME)
75
+
76
+ def format(self, record):
77
+ formatter = self._color_formatters.get(record.levelno, self._default)
78
+ return formatter.format(record)
79
+
80
+
81
+ _handler = logging.StreamHandler()
82
+ _handler.setFormatter(MoscaColorFormatter())
83
+
84
+
85
+ class Logger(logging.Logger):
86
+ def __init__(self, name: str) -> None:
87
+ super().__init__(name)
88
+ self.setLevel(_CONSOLE_INFO)
89
+ self.propagate = False
90
+
91
+ def user_info(self, *args, **kwargs):
92
+ if self.isEnabledFor(_CONSOLE_INFO):
93
+ self.log(_CONSOLE_INFO, *args, **kwargs)
94
+
95
+ def user_warning(self, *args, **kwargs):
96
+ if self.isEnabledFor(_CONSOLE_WARNING):
97
+ self.log(_CONSOLE_WARNING, *args, **kwargs)
98
+
99
+ def user_error(self, *args, **kwargs):
100
+ if self.isEnabledFor(_CONSOLE_ERROR):
101
+ self.log(_CONSOLE_ERROR, *args, **kwargs)
102
+
103
+
104
+ def getLogger(name):
105
+ klass = logging.getLoggerClass()
106
+ logging.setLoggerClass(Logger)
107
+ logger = logging.getLogger(name)
108
+ logging.setLoggerClass(klass)
109
+ if not logger.handlers:
110
+ logger.addHandler(_handler)
111
+ return logger
@@ -57,9 +57,14 @@ class Dante(McaBase):
57
57
  # scheduling on the server side, which could otherwise let a stale
58
58
  # prior status (e.g. READY) slip past the checks below undetected.
59
59
  start_deadline = time.time() + self.CONFIG_LOAD_START_WAIT
60
- while proxy.mca_status != "UNINITIALIZED" and time.time() < start_deadline:
60
+ while proxy.mca_status not in ("UNINITIALIZED", "FAULT") and time.time() < start_deadline:
61
61
  time.sleep(0.1)
62
62
 
63
+ if proxy.mca_status == "FAULT":
64
+ raise RuntimeError(
65
+ f"Failed to load config [{configuration}]. Please check server logs."
66
+ )
67
+
63
68
  if proxy.mca_status != "UNINITIALIZED":
64
69
  raise RuntimeError(
65
70
  f"Server did not start processing config [{configuration}] "
@@ -9,11 +9,6 @@ class FalconX(Xia):
9
9
  txt += f" * mca_refresh: {self.proxy.mca_refresh:.4f} s\n"
10
10
  return txt
11
11
 
12
- def scan_metadata(self) -> dict:
13
- metadata = super().scan_metadata()
14
- metadata["mca_refresh"] = self.proxy.mca_refresh
15
- return metadata
16
-
17
12
  def filter_parameters(self,
18
13
  acq_realtime=None,
19
14
  block_size=None,
@@ -21,11 +21,6 @@ class Xia(McaBase):
21
21
  "deadtime_correction": "deadtime_correction",
22
22
  }
23
23
 
24
- # def _apply_settings(self, ini_file=None, **kwargs):
25
- # if ini_file:
26
- # self.configuration_file = ini_file
27
- # return super()._apply_settings(**kwargs)
28
-
29
24
  def __info__(self) -> str:
30
25
  txt = super().__info__()
31
26
  txt += f"\n * ini file: {self.proxy.ini_file}\n"
@@ -51,15 +46,10 @@ class Xia(McaBase):
51
46
  return self.proxy.available_ini_files()
52
47
 
53
48
  def _load_configuration(self, configuration: str | None = None) -> None:
54
- try:
55
- with ChangeTangoTimeout(self.proxy, 10):
56
- print(f"Loading {configuration}...")
57
- if configuration is None:
58
- configuration = ""
59
- self.proxy.ini_file = configuration
60
- except Exception as ex:
61
- # TODO: report server msg
62
- raise RuntimeError(f"Loading configuration file '{configuration}' has failed.") from ex
49
+ with ChangeTangoTimeout(self.proxy, 10):
50
+ if configuration is None:
51
+ configuration = ""
52
+ self.proxy.ini_file = configuration
63
53
  return self.current_configuration()
64
54
 
65
55
  def current_configuration(self):
@@ -1,6 +1,10 @@
1
- from tango import DeviceProxy
1
+ from .. import logging
2
2
 
3
- from .utils import is_ds_exported, Callback
3
+ from tango import DeviceProxy, DevFailed
4
+
5
+ from .utils import is_ds_exported, Callback, extract_exception_text
6
+
7
+ logger = logging.getLogger(__name__)
4
8
 
5
9
 
6
10
  class McaBase:
@@ -8,8 +12,6 @@ class McaBase:
8
12
  def __init__(self, name, tg_url, on_change_cb=None, **kwargs):
9
13
  self._name = name
10
14
 
11
- # settings_name = f"mosca:{name}:{self.__class__.__name__}"
12
- # self._settings2 = HashObjSetting(settings_name)
13
15
  self._settings = kwargs.get("settings", {})
14
16
 
15
17
  self._add_setting("configuration", None)
@@ -17,6 +19,7 @@ class McaBase:
17
19
  self._tg_url = tg_url
18
20
  self._proxy = None
19
21
  self._on_change_cb = Callback(on_change_cb, blocked=True)
22
+ self.initialize()
20
23
 
21
24
  @property
22
25
  def mca_status(self):
@@ -41,6 +44,8 @@ class McaBase:
41
44
  self._settings[key] = value
42
45
 
43
46
  def initialize(self, load_configuration=True):
47
+ #TODO: _apply_setting will call initialize if a new configuration is loaded...
48
+ # FIX THIS
44
49
  self._on_change_cb.blocked = True
45
50
  # iterating on KEYS, because ITEMS doesn't work (returns #ERR)
46
51
  settings = {key: (self._settings[key] if load_configuration or key != "configuration" else None)
@@ -60,6 +65,9 @@ class McaBase:
60
65
  if not is_ds_exported(self._tg_url):
61
66
  raise RuntimeError(f"Server {self._tg_url} doesn't seem to be running.")
62
67
  self._proxy = DeviceProxy(self._tg_url)
68
+ # TODO: this is only called the first time proxy is called
69
+ # this could be a problem when using Mosca
70
+ # self.initialize()
63
71
  return self._proxy
64
72
 
65
73
  # TODO: put this in bliss
@@ -69,13 +77,19 @@ class McaBase:
69
77
  def load_configuration(self, *args, **kwargs):
70
78
  reply = None
71
79
  try:
80
+ strargs = ", ".join(f"{arg}" for arg in args)
81
+ strargs += ", ".join(f"{key}={value}" for key, value in kwargs.items())
82
+ logger.user_info("Loading configuration (%s)", strargs)
72
83
  reply = self._load_configuration(*args, **kwargs)
73
84
  except NotImplementedError:
74
- print(f"MCA doesn't implement load_configuration.")
85
+ logger.user_warning(f"MCA doesn't implement load_configuration.")
86
+ except DevFailed as ex:
87
+ logger.user_error("%s - %s", self.tg_url, extract_exception_text(ex))
75
88
  else:
76
89
  self._set_settings(configuration=reply)
77
90
  self.initialize(load_configuration=False)
78
- self.changed()
91
+ logger.user_info("Done! Loaded configuration (%s)", reply)
92
+ self.changed()
79
93
  return reply
80
94
 
81
95
  # To be overridden, if necessary
@@ -0,0 +1,367 @@
1
+ import importlib
2
+
3
+ from ruamel.yaml import YAML
4
+ from tango import DeviceProxy
5
+
6
+ from .mca import McaBase
7
+ from .rois import Rois
8
+ from .saving import Saving
9
+ from .utils import is_ds_exported, to_enum, ChangeTangoTimeout, Callback
10
+ from .readers import Reader, Poller, MixedReader, get_remote_enum
11
+
12
+ from .. import logging
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class Mosca:
17
+ mca_type = property(lambda self: self.proxy.get_property("mca_type")["mca_type"][0])
18
+ start_epoch = property(lambda self: self.proxy.start_epoch)
19
+
20
+ def __init__(self, name, tango_url, on_change_cb=None, **kwargs):
21
+ self._name = name
22
+ self._settings = kwargs.get("settings",
23
+ {"mosca": {},
24
+ "mca": {},
25
+ "rois": {},
26
+ "saving": {},
27
+ "zarr_saving": {}})
28
+
29
+ self._tango_url = tango_url
30
+ self._proxy = None
31
+ self._saving_proxy = None
32
+ self._on_change_cb = Callback(on_change_cb, blocked=True)
33
+ self._mca = None
34
+ self._rois = None
35
+ self._saving = None
36
+ self._zarr_saving = None
37
+
38
+ self._TriggerMode = None
39
+ self._GateMode = None
40
+ self._McaStatus = None
41
+ self._DiscardMode = None
42
+ self._supported_trigger_modes = None
43
+ self._supported_gate_modes = None
44
+
45
+ self.initialize()
46
+
47
+ def changed(self):
48
+ self._on_change_cb()
49
+
50
+ def initialize(self):
51
+ self._on_change_cb.blocked = True
52
+ try:
53
+ # TODO IMPROVE
54
+ if self._mca:
55
+ self.mca.initialize()
56
+ else:
57
+ self.mca
58
+ if self._rois:
59
+ self.rois.initialize()
60
+ else:
61
+ self.rois
62
+ if self._saving:
63
+ self.saving.initialize()
64
+ else:
65
+ self.saving
66
+ settings = {name: self._settings[name]
67
+ for name in self._settings.keys()}
68
+ self._apply_settings(**settings["mosca"])
69
+ finally:
70
+ self._on_change_cb.blocked = False
71
+
72
+ self._TriggerMode = get_remote_enum(self.proxy, "TriggerMode")
73
+ self._GateMode = get_remote_enum(self.proxy, "GateMode")
74
+ self._McaStatus = get_remote_enum(self.proxy, "McaStatus")
75
+ self._DiscardMode =get_remote_enum(self.proxy, "DiscardMode")
76
+ self._supported_trigger_modes = tuple([self._TriggerMode(e.value)
77
+ for e in self.proxy.supported_trigger_modes])
78
+ self._supported_gate_modes = tuple([self._GateMode(e.value)
79
+ for e in self.proxy.supported_gate_modes])
80
+
81
+ self._start_epoch = self.proxy.start_epoch
82
+
83
+ def _check_restarted(self) -> bool:
84
+ """ Detects a server restart via start_epoch.
85
+
86
+ Returns True if a restart was detected, in which case this
87
+ client is re-initialized first so its caches stay consistent.
88
+ """
89
+ current_epoch = self.proxy.start_epoch
90
+ restarted = self._start_epoch is not None and current_epoch != self._start_epoch
91
+ if restarted:
92
+ logger.user_warning("Mosca server (%s) restart detected (start_epoch changed "
93
+ "from %s to %s); re-initializing.",
94
+ self._tango_url, self._start_epoch, current_epoch)
95
+ self.initialize()
96
+ return restarted
97
+
98
+ def _save_settings(self, **kwargs):
99
+ for key, value in kwargs.items():
100
+ self._settings["mosca"][key] = value
101
+
102
+ def _apply_settings(self, disabled_detectors=None, **kwargs):
103
+ if disabled_detectors:
104
+ self.proxy.disable_detectors(list(disabled_detectors))
105
+
106
+ @property
107
+ def proxy(self):
108
+ if self._proxy is None:
109
+ if not is_ds_exported(self._tango_url):
110
+ raise RuntimeError(f"Server {self._tango_url} doesn't seem to be running.")
111
+ self._proxy = DeviceProxy(self._tango_url)
112
+ return self._proxy
113
+
114
+ @property
115
+ def mca(self):
116
+ if self._mca is None:
117
+ mca_type = self.mca_type.casefold()
118
+ try:
119
+ mca_module = importlib.import_module(
120
+ f".devices.{mca_type}", __package__
121
+ )
122
+ except ModuleNotFoundError:
123
+ # No specificities
124
+ mca_class = McaBase
125
+ else:
126
+ mca_class = mca_module.Mca
127
+ self._mca = mca_class(self._name,
128
+ self.proxy.controller_name,
129
+ on_change_cb=self.changed,
130
+ settings=self._settings["mca"])
131
+ return self._mca
132
+
133
+ @property
134
+ def rois(self):
135
+ if self._rois is None:
136
+ self._rois = Rois(self._name,
137
+ self.proxy,
138
+ on_change_cb=self.changed,
139
+ settings=self._settings["rois"])
140
+ return self._rois
141
+
142
+ @property
143
+ def saving_proxy(self):
144
+ """ Proxy to the sibling 'Saving' Tango device (see main.py, which
145
+ registers it next to this Mosca device, replacing its Tango
146
+ family segment with 'Saving', e.g. id00/mosca/simfx ->
147
+ id00/Saving/simfx). """
148
+ if self._saving_proxy is None:
149
+ parts = self._tango_url.rstrip("/").split("/")
150
+ parts[-2] = "Saving"
151
+ self._saving_proxy = DeviceProxy("/".join(parts))
152
+ return self._saving_proxy
153
+
154
+ @property
155
+ def saving(self):
156
+ if self._saving is None:
157
+ self._saving = Saving(self._name,
158
+ self.proxy.saving_name,
159
+ # on_change_cb=self.changed,
160
+ settings=self._settings["saving"])
161
+ return self._saving
162
+
163
+ # @property
164
+ # def zarr_saving(self):
165
+ # if self._zarr_saving is None:
166
+ # self._zarr_saving = ZarrSaving(self._name, self.proxy)
167
+ # return self._zarr_saving
168
+
169
+ def __info__(self):
170
+ txt = f"Mosca ({self.proxy.name()})\n"
171
+ txt += " * detectors : " + ", ".join(str(ch) for ch in self.detectors) + "\n"
172
+ txt += f" * spectrum size : {self.spectrum_size}"
173
+ txt += "\n -- \n"
174
+ txt += self.mca.__info__()
175
+ return txt
176
+
177
+ @property
178
+ def GateMode(self):
179
+ return self._GateMode
180
+
181
+ @property
182
+ def TriggerMode(self):
183
+ return self._TriggerMode
184
+
185
+ @property
186
+ def McaStatus(self):
187
+ return self._McaStatus
188
+
189
+ @property
190
+ def DiscardMode(self):
191
+ return self._DiscardMode
192
+
193
+ @property
194
+ def supported_trigger_modes(self):
195
+ return self._supported_trigger_modes
196
+
197
+ @property
198
+ def supported_gate_modes(self):
199
+ return self._supported_gate_modes
200
+
201
+ @property
202
+ def detectors(self):
203
+ return tuple(self.proxy.detectors)
204
+
205
+ @property
206
+ def spectrum_size(self):
207
+ return self.proxy.spectrum_size
208
+
209
+ @property
210
+ def stats_names(self):
211
+ return tuple(self.proxy.stats_names)
212
+
213
+ @property
214
+ def acquisition_status(self):
215
+ return self.McaStatus(self.proxy.acquisition_status)
216
+
217
+ def disable_detectors(self, *detectors):
218
+ self.proxy.disable_detectors(detectors)
219
+ disabled = self._settings["mosca"].get("disabled_detectors", [])
220
+ disabled = set(disabled)
221
+ disabled.update(detectors)
222
+ self._save_settings(disabled_detectors=tuple(disabled))
223
+ self.changed()
224
+
225
+ def enable_detectors(self, *detectors):
226
+ self.proxy.enable_detectors(detectors)
227
+ disabled = self._settings["mosca"].get("disabled_detectors", [])
228
+ disabled = set(disabled)
229
+ disabled -= set(detectors)
230
+ self._save_settings(disabled_detectors=tuple(disabled))
231
+ self.changed()
232
+
233
+ def available_detectors(self):
234
+ return self.proxy.available_detectors
235
+
236
+ def load_configuration(self, *args, **kwargs):
237
+ return self.mca.load_configuration(*args, **kwargs)
238
+
239
+ def available_configurations(self, *args, **kwargs):
240
+ return self.mca.available_configurations(*args, **kwargs)
241
+
242
+ def current_configuration(self, *args, **kwargs):
243
+ return self.mca.current_configuration(*args, **kwargs)
244
+
245
+ # ====================
246
+
247
+ def set_parameters(self,
248
+ trigger_mode=None,
249
+ acq_nb_points=None,
250
+ acq_realtime=None,
251
+ gate_mode=None,
252
+ block_size=None,
253
+ discard_mode=None,
254
+ **kwargs):
255
+ # TODO: put these params in a dataclass or namedtuple to make things
256
+ # clearer (i.e: not obfuscated in kwargs)
257
+ """ Note: extra kwargs will be passed to this client's saving.set_parameters. """
258
+
259
+ params = {"trigger_mode": trigger_mode,
260
+ "acq_nb_points": acq_nb_points,
261
+ "acq_realtime": acq_realtime,
262
+ "gate_mode": gate_mode,
263
+ "block_size": block_size,
264
+ "discard_mode": discard_mode,
265
+ **kwargs}
266
+
267
+ mca_params = self.mca.filter_parameters(**params)
268
+ params.update(mca_params)
269
+
270
+ trigger_mode = params.get("trigger_mode")
271
+ acq_nb_points = params.get("acq_nb_points")
272
+ acq_realtime = params.get("acq_realtime")
273
+ gate_mode = params.get("gate_mode")
274
+ block_size = params.get("block_size")
275
+ discard_mode = params.get("discard_mode")
276
+
277
+ if trigger_mode is not None:
278
+ self.proxy.trigger_mode = to_enum(trigger_mode, self.TriggerMode).name
279
+ if acq_nb_points is not None:
280
+ self.proxy.acq_nb_points = acq_nb_points
281
+ if acq_realtime is not None:
282
+ self.proxy.acq_realtime = acq_realtime
283
+ if gate_mode is not None:
284
+ self.proxy.gate_mode = to_enum(gate_mode, self.GateMode).name
285
+ # elif self.proxy.trigger_mode != "FREERUN":
286
+ # self.proxy.gate_mode = "HIGH"
287
+ if block_size is not None:
288
+ self.proxy.block_size = block_size
289
+ if discard_mode is not None:
290
+ self.proxy.discard_mode = to_enum(discard_mode, self.DiscardMode).name
291
+
292
+ saving_keys = ["saving_mode",
293
+ "directory",
294
+ "file_prefix",
295
+ "points_per_file",
296
+ "data_path",
297
+ "remote_saving",
298
+ "endpoint",
299
+ "secure",
300
+ "bucket",
301
+ "prefix",
302
+ "access_key",
303
+ "secrete_key"]
304
+ saving_kwargs = {key:kwargs[key]
305
+ for key in saving_keys if key in kwargs}
306
+ self.saving.configure_saving(**saving_kwargs)
307
+
308
+ # applying default parameters
309
+ self.proxy.apply_mosca()
310
+
311
+ # then params can be modified by the device if necessary
312
+ self.mca.set_parameters(**params)
313
+
314
+ def prepare_acq(self):
315
+ self._check_restarted()
316
+ return self.proxy.prepare_acq()
317
+
318
+ def start_acq(self, acq_id=None):
319
+ if self._check_restarted():
320
+ raise RuntimeError(
321
+ "Mosca server restarted after prepare_acq() was called; "
322
+ "the acquisition was not started. Call prepare_acq() again."
323
+ )
324
+ with ChangeTangoTimeout(self.proxy, 5):
325
+ if acq_id:
326
+ return self.proxy.acqid_start_acq(acq_id)
327
+ else:
328
+ return self.proxy.start_acq()
329
+
330
+ def stop_acq(self):
331
+ with ChangeTangoTimeout(self.proxy, 5):
332
+ self.proxy.stop_acq()
333
+
334
+ def resume_acq(self, acq_id=None):
335
+ # TODO: acq_id
336
+ with ChangeTangoTimeout(self.proxy, 5):
337
+ if acq_id:
338
+ return self.proxy.acqid_resume_acq(acq_id)
339
+ else:
340
+ return self.proxy.resume_acq()
341
+
342
+ def metadata(self, acq_id=None):
343
+ if acq_id:
344
+ metadata = self.proxy.acqid_metadata(acq_id)
345
+ else:
346
+ metadata = self.proxy.metadata()
347
+ return YAML().load(metadata)
348
+
349
+ def reader(self, acq_id=None):
350
+ # TODO: weakref that is invalid the next time
351
+ # a prepare is done through this instance
352
+ return Reader(self._tango_url, acq_id=acq_id)
353
+
354
+ def mixed_reader(self, acq_id=None):
355
+ return MixedReader(self.reader(acq_id=acq_id))
356
+
357
+ def poller(self, acq_id=None):
358
+ return Poller(self.reader(acq_id=acq_id))
359
+
360
+ def read_spectra(self, first=0, last=None):
361
+ return self.reader().read_spectra(first=first, last=last)
362
+
363
+ def read_stats(self, first=0, last=None):
364
+ return self.reader().read_stats(first=first, last=last)
365
+
366
+ def read_rois(self, first=0, last=None):
367
+ return self.reader().read_rois(first=first, last=last)