mosca 2.0.2__py3-none-any.whl
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.
- mosca/__init__.py +11 -0
- mosca/common/__init__.py +9 -0
- mosca/common/enums.py +79 -0
- mosca/common/logger.py +139 -0
- mosca/common/threads.py +199 -0
- mosca/common/utils.py +70 -0
- mosca/control/__init__.py +4 -0
- mosca/control/buffer.py +526 -0
- mosca/control/controller.py +278 -0
- mosca/control/datahandler.py +261 -0
- mosca/control/detectors.py +116 -0
- mosca/control/mosca.py +693 -0
- mosca/control/spectra.py +36 -0
- mosca/control/stats.py +43 -0
- mosca/control/tasks/__init__.py +3 -0
- mosca/control/tasks/background.py +118 -0
- mosca/control/tasks/rois.py +466 -0
- mosca/control/tasks/saving.py +391 -0
- mosca/control/tasks/spectrasums.py +185 -0
- mosca/control/tasks/task.py +201 -0
- mosca/control/tasks/taskmanager.py +133 -0
- mosca/devices/__init__.py +28 -0
- mosca/devices/hamamatsu/__init__.py +0 -0
- mosca/devices/hamamatsu/hamamatsu.py +88 -0
- mosca/devices/hamamatsu/hamamatsuhw.py +1298 -0
- mosca/devices/oceanoptics/__init__.py +0 -0
- mosca/devices/oceanoptics/oceanoptics.py +59 -0
- mosca/devices/oceanoptics/oceanopticshw.py +379 -0
- mosca/devices/simulation/__init__.py +0 -0
- mosca/devices/simulation/dante/__init__.py +1 -0
- mosca/devices/simulation/dante/simdante.py +33 -0
- mosca/devices/simulation/dante/simdantehw.py +506 -0
- mosca/devices/simulation/dummy/__init__.py +1 -0
- mosca/devices/simulation/dummy/dummy.py +299 -0
- mosca/devices/simulation/generator.py +607 -0
- mosca/devices/simulation/xia/__init__.py +1 -0
- mosca/devices/simulation/xia/iniparser.py +99 -0
- mosca/devices/simulation/xia/simfalconx.py +26 -0
- mosca/devices/simulation/xia/simfalconxhw.py +599 -0
- mosca/devices/xglab/__init__.py +0 -0
- mosca/devices/xglab/dante.py +126 -0
- mosca/devices/xglab/dantehw.py +1178 -0
- mosca/devices/xia/__init__.py +0 -0
- mosca/devices/xia/falconx.py +232 -0
- mosca/devices/xia/handel/__init__.py +14 -0
- mosca/devices/xia/handel/_cffi.py +62 -0
- mosca/devices/xia/handel/error.py +272 -0
- mosca/devices/xia/handel/handel_inc/handel_constants.h +127 -0
- mosca/devices/xia/handel/handel_inc/handel_errors.h +254 -0
- mosca/devices/xia/handel/handel_inc/handel_generic.h +66 -0
- mosca/devices/xia/handel/interface.py +1025 -0
- mosca/devices/xia/handel/mapping.py +107 -0
- mosca/devices/xia/handel/parser.py +62 -0
- mosca/devices/xia/handel/stats.py +85 -0
- mosca/devices/xia/mercury.py +160 -0
- mosca/devices/xia/utils.py +47 -0
- mosca/devices/xia/xia.py +575 -0
- mosca/devices/xia/xiads.py +161 -0
- mosca/mosca.py +0 -0
- mosca/tango/__init__.py +2 -0
- mosca/tango/controller.py +80 -0
- mosca/tango/main.py +163 -0
- mosca/tango/mosca.py +513 -0
- mosca/tango/moscav1.py +408 -0
- mosca/tango/shared.py +23 -0
- mosca/tango/tasks/__init__.py +0 -0
- mosca/tango/tasks/background.py +55 -0
- mosca/tango/utils.py +109 -0
- mosca-2.0.2.dist-info/METADATA +32 -0
- mosca-2.0.2.dist-info/RECORD +73 -0
- mosca-2.0.2.dist-info/WHEEL +4 -0
- mosca-2.0.2.dist-info/entry_points.txt +2 -0
- mosca-2.0.2.dist-info/licenses/LICENSE +166 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
logger = logging.getLogger(__name__)
|
|
3
|
+
|
|
4
|
+
from tango.server import device_property, attribute, command
|
|
5
|
+
from ....tango import TangoDevInfo
|
|
6
|
+
|
|
7
|
+
from ...xia.falconx import FalconX as FXDS
|
|
8
|
+
from .simfalconxhw import SimFalconXHW
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SimFalconX(FXDS):
|
|
12
|
+
def _create_control(self, *args, **kwargs):
|
|
13
|
+
control = SimFalconXHW(*args, **kwargs)
|
|
14
|
+
logger.warning(
|
|
15
|
+
"==========================\n"
|
|
16
|
+
"==== USING SIMooLATOR ====\n"
|
|
17
|
+
"==========================\n"
|
|
18
|
+
)
|
|
19
|
+
return control
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
SIMFALCONX_DEVINFO = TangoDevInfo(
|
|
23
|
+
klass=SimFalconX,
|
|
24
|
+
properties={"default_ini_dir": "c:/blissadm/falconx/config",
|
|
25
|
+
"default_ini_file": "falconx.ini",
|
|
26
|
+
"lib_path": ""})
|
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Simulator for the FalconX.
|
|
3
|
+
|
|
4
|
+
To use set the PyHandel's lib attribute to the Simulator library.
|
|
5
|
+
|
|
6
|
+
Example:
|
|
7
|
+
|
|
8
|
+
f = "/home/blissadm/dev/mosca/mosca.git/tests/test.ini"
|
|
9
|
+
from mosca.devices.falconx.pyhandel import Handel as Pyh, DetectorMode
|
|
10
|
+
from mosca.devices.simulation.simu_falconx import Handel as SimH
|
|
11
|
+
hi = Pyh()
|
|
12
|
+
hi.lib = SimH()
|
|
13
|
+
hi.load_config(f)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# simulating 1kHz mapping
|
|
17
|
+
hi.lib._acq_time = 0.001
|
|
18
|
+
|
|
19
|
+
# 3000 points, 500 pixels per buffer
|
|
20
|
+
hi.set_map_acq_pars(False, 3000, 500)
|
|
21
|
+
hi.set_detector_mode(DetectorMode.MAP)
|
|
22
|
+
hi.xia_start()
|
|
23
|
+
while hi.xia_is_running():
|
|
24
|
+
time.sleep(1)
|
|
25
|
+
print("waiting for data")
|
|
26
|
+
time.sleep(2)
|
|
27
|
+
print(hi.data_handler.no_pixels)
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import logging
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
import configparser
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
Parser
|
|
37
|
+
"""
|
|
38
|
+
import os
|
|
39
|
+
import sys
|
|
40
|
+
import copy
|
|
41
|
+
import time
|
|
42
|
+
import ctypes
|
|
43
|
+
import traceback
|
|
44
|
+
import threading
|
|
45
|
+
import queue
|
|
46
|
+
from enum import Enum
|
|
47
|
+
from collections import deque
|
|
48
|
+
from ...xia.falconx import FalconXHW
|
|
49
|
+
|
|
50
|
+
import cffi
|
|
51
|
+
import numpy as np
|
|
52
|
+
|
|
53
|
+
from ..generator import DataGenerator
|
|
54
|
+
|
|
55
|
+
ffi = cffi.FFI()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class XIA_CODES:
|
|
59
|
+
XIA_SUCCESS = 0
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def map_buffer(
|
|
63
|
+
data,
|
|
64
|
+
stats,
|
|
65
|
+
channel,
|
|
66
|
+
n_pixels,
|
|
67
|
+
pixels_per_buffer,
|
|
68
|
+
spectrum_size,
|
|
69
|
+
buf_id,
|
|
70
|
+
from_pix=0,
|
|
71
|
+
from_buf=0,
|
|
72
|
+
):
|
|
73
|
+
# word = 32 bits
|
|
74
|
+
# buf_header * n_pixels * (pix_header + spectrum_size)
|
|
75
|
+
# each item in the header is 16 bits wide
|
|
76
|
+
# each spectrum is 1 words wide
|
|
77
|
+
pix_buf_size = pixels_per_buffer * (128 + spectrum_size)
|
|
78
|
+
buffer_size_w = 128 + pix_buf_size
|
|
79
|
+
buffer = np.zeros((buffer_size_w,), dtype=np.uint32)
|
|
80
|
+
|
|
81
|
+
header = buffer[0:128]
|
|
82
|
+
|
|
83
|
+
header.dtype = np.uint16
|
|
84
|
+
header[0] = 0x55AA
|
|
85
|
+
header[1] = 0xAA55
|
|
86
|
+
header[2] = 256
|
|
87
|
+
header[3] = 1
|
|
88
|
+
# header[4] = 0xFFFF & from_run
|
|
89
|
+
header[5] = 0xFFFF & from_buf
|
|
90
|
+
header[6] = 0xFFFF & (from_buf >> 16)
|
|
91
|
+
header[7] = buf_id
|
|
92
|
+
header[8] = n_pixels
|
|
93
|
+
header[9] = 0xFFFF & from_pix
|
|
94
|
+
header[10] = 0xFFFF & (from_pix >> 16)
|
|
95
|
+
header[12] = channel
|
|
96
|
+
header[26] = 0xFFFF & pix_buf_size
|
|
97
|
+
header[27] = 0xFFFF & (pix_buf_size >> 16)
|
|
98
|
+
|
|
99
|
+
# data = buffer[123:]
|
|
100
|
+
|
|
101
|
+
first = 128
|
|
102
|
+
try:
|
|
103
|
+
for i_pix in range(n_pixels):
|
|
104
|
+
header = buffer[first : first + 128]
|
|
105
|
+
header.dtype = np.uint16
|
|
106
|
+
header[0] = 0x33CC
|
|
107
|
+
header[1] = 0xCC33
|
|
108
|
+
header[2] = 256
|
|
109
|
+
header[3] = 1
|
|
110
|
+
header[4] = 0xFFFF & from_pix
|
|
111
|
+
header[5] = 0xFFFF & from_pix >> 16
|
|
112
|
+
header[6] = 0xFFFF & n_pixels
|
|
113
|
+
header[7] = 0xFFFF & n_pixels >> 16
|
|
114
|
+
header[8] = spectrum_size * 2 # in 16b words!
|
|
115
|
+
pstats = stats[i_pix]
|
|
116
|
+
header[32:34] = 0xFFFF & pstats[0], 0xFFFF & pstats[0] >> 16
|
|
117
|
+
header[34:36] = 0xFFFF & pstats[1], 0xFFFF & pstats[1] >> 16
|
|
118
|
+
header[36:38] = 0xFFFF & pstats[2], 0xFFFF & pstats[2] >> 16
|
|
119
|
+
header[38:40] = 0xFFFF & pstats[3], 0xFFFF & pstats[3] >> 16
|
|
120
|
+
|
|
121
|
+
first += 128
|
|
122
|
+
buffer[first : first + spectrum_size] = data[i_pix, :]
|
|
123
|
+
first += spectrum_size
|
|
124
|
+
except:
|
|
125
|
+
print(channel,
|
|
126
|
+
n_pixels,
|
|
127
|
+
pixels_per_buffer,
|
|
128
|
+
spectrum_size,
|
|
129
|
+
buf_id,
|
|
130
|
+
from_pix,
|
|
131
|
+
from_buf,
|
|
132
|
+
first)
|
|
133
|
+
raise
|
|
134
|
+
|
|
135
|
+
buffer.dtype = np.uint16
|
|
136
|
+
return buffer
|
|
137
|
+
# return buffer.astype(np.uint16)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class XiaHardware:
|
|
141
|
+
detectors = property(lambda self: self._detectors)
|
|
142
|
+
firmwares = property(lambda self: self._firmwares)
|
|
143
|
+
default = property(lambda self: self._default)
|
|
144
|
+
modules = property(lambda self: self._modules)
|
|
145
|
+
channels = property(lambda self: self._chan_aliases)
|
|
146
|
+
|
|
147
|
+
modules_num = property(lambda self: list(self._modules.keys()))
|
|
148
|
+
|
|
149
|
+
def __init__(self, filename=None):
|
|
150
|
+
super().__init__()
|
|
151
|
+
self._detectors = {}
|
|
152
|
+
self._firmwares = {}
|
|
153
|
+
self._default = {}
|
|
154
|
+
self._modules = {}
|
|
155
|
+
self._chan_data = {}
|
|
156
|
+
self._chan_aliases = {}
|
|
157
|
+
if filename:
|
|
158
|
+
self.load_ini(filename)
|
|
159
|
+
|
|
160
|
+
def load_ini(self, filename):
|
|
161
|
+
# import here so that the dependance to lark is optional
|
|
162
|
+
# when importing mosca.
|
|
163
|
+
from .iniparser import load_xia_ini
|
|
164
|
+
|
|
165
|
+
logger.info("Loading XIA ini file %s", filename)
|
|
166
|
+
data = load_xia_ini(filename)
|
|
167
|
+
logger.info("Ini file loaded.")
|
|
168
|
+
self._detectors = data["detector"]
|
|
169
|
+
self._firmwares = data["firmware"]
|
|
170
|
+
self._default = data["default"]
|
|
171
|
+
self._modules = data["module"]
|
|
172
|
+
self._chan_data = data.get("module_channel_data", {})
|
|
173
|
+
self._chan_aliases = {}
|
|
174
|
+
self._chan2mod = {}
|
|
175
|
+
|
|
176
|
+
for imod, module in enumerate(self._modules.values()):
|
|
177
|
+
for ichan in range(module["number_of_channels"]):
|
|
178
|
+
alias = module[f"channel{ichan}_alias"]
|
|
179
|
+
if alias in self._chan_aliases:
|
|
180
|
+
raise RuntimeError("error in ini, duplicate aliases?")
|
|
181
|
+
self._chan_aliases[alias] = self._default[alias]
|
|
182
|
+
self._chan2mod[alias] = imod
|
|
183
|
+
|
|
184
|
+
def channel_param(self, chan_num, param):
|
|
185
|
+
return self._default[chan_num][param]
|
|
186
|
+
|
|
187
|
+
def set_channel_param(self, chan_num, param, value):
|
|
188
|
+
self._default[chan_num][param] = value
|
|
189
|
+
|
|
190
|
+
def module(self, alias):
|
|
191
|
+
for module in self._modules.values():
|
|
192
|
+
if module["alias"] == alias:
|
|
193
|
+
return module
|
|
194
|
+
raise ValueError("Alias not found.")
|
|
195
|
+
|
|
196
|
+
def n_channels(self, module=None):
|
|
197
|
+
if module is not None:
|
|
198
|
+
modules = [module]
|
|
199
|
+
else:
|
|
200
|
+
modules = self._modules.keys()
|
|
201
|
+
|
|
202
|
+
nchans = 0
|
|
203
|
+
for module in modules:
|
|
204
|
+
nchans += self._modules[module]["number_of_channels"]
|
|
205
|
+
return nchans
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class XiaDataGenerator(DataGenerator):
|
|
209
|
+
xia_mapping = property(lambda self: self._xia_mapping)
|
|
210
|
+
channels_per_mod = property(lambda self: self._channels_per_mod)
|
|
211
|
+
|
|
212
|
+
def __init__(self, *args, **kwargs):
|
|
213
|
+
super().__init__(*args, **kwargs)
|
|
214
|
+
self._channels_per_mod = None
|
|
215
|
+
self._xia_mapping = None
|
|
216
|
+
|
|
217
|
+
@channels_per_mod.setter
|
|
218
|
+
def channels_per_mod(self, channels_per_mod):
|
|
219
|
+
self._channels_per_mod = channels_per_mod
|
|
220
|
+
|
|
221
|
+
@xia_mapping.setter
|
|
222
|
+
def xia_mapping(self, xia_mapping):
|
|
223
|
+
self._xia_mapping = xia_mapping
|
|
224
|
+
|
|
225
|
+
def _prepare_task(self, *args, **kwargs):
|
|
226
|
+
super()._prepare_task(*args, **kwargs)
|
|
227
|
+
self._current_buffer = {chan: "buffer_a" for chan in range(self.n_detectors)}
|
|
228
|
+
self._buffers = {
|
|
229
|
+
"buffer_a": {chan: None for chan in range(self.n_detectors)},
|
|
230
|
+
"buffer_b": {chan: None for chan in range(self.n_detectors)},
|
|
231
|
+
}
|
|
232
|
+
self._xia_data = {}
|
|
233
|
+
self._xia_stats = {}
|
|
234
|
+
self._mod_channels_map = {}
|
|
235
|
+
f_idx = 0
|
|
236
|
+
for i_mod, n_chans in enumerate(self._channels_per_mod):
|
|
237
|
+
self._mod_channels_map[i_mod] = list(range(f_idx, f_idx + n_chans))
|
|
238
|
+
f_idx += n_chans
|
|
239
|
+
|
|
240
|
+
def prepare_data(self, spectra, stats):
|
|
241
|
+
if not self.xia_mapping:
|
|
242
|
+
for k, v in stats.items():
|
|
243
|
+
stats[k] = np.hstack([v, np.zeros(shape=(v.shape[0], 9 - v.shape[1]))])
|
|
244
|
+
return spectra, stats
|
|
245
|
+
|
|
246
|
+
def update(self, channel, data, stats, f_pix, l_pix):
|
|
247
|
+
logger.debug("Update! %s, %s, %s, %s, %s", channel, data.shape, stats.shape, f_pix, l_pix)
|
|
248
|
+
if self.xia_mapping:
|
|
249
|
+
self._set_buffer_data(channel, data, stats, f_pix, l_pix)
|
|
250
|
+
else:
|
|
251
|
+
self._xia_data[channel] = data[0]
|
|
252
|
+
self._xia_stats[channel] = stats[0]
|
|
253
|
+
|
|
254
|
+
def buffer_full(self, channel, buf_id):
|
|
255
|
+
return self._buffers[buf_id][channel] is not None
|
|
256
|
+
|
|
257
|
+
def set_buffer_done(self, channel, buf_id):
|
|
258
|
+
if not self.buffer_full(channel, buf_id):
|
|
259
|
+
raise RuntimeError(
|
|
260
|
+
f"Buffer {buf_id} {channel} has not been flagged as ready!"
|
|
261
|
+
)
|
|
262
|
+
self._buffers[buf_id][channel] = None
|
|
263
|
+
|
|
264
|
+
def _set_buffer_data(self, channel, data, stats, f_pix, l_pix):
|
|
265
|
+
buf_id = self._current_buffer[channel]
|
|
266
|
+
if self.buffer_full(channel, buf_id):
|
|
267
|
+
raise RuntimeError(f"buffer {buf_id} {channel} overflow!")
|
|
268
|
+
buf_num = 0 if buf_id == "buffer_a" else 1
|
|
269
|
+
data = map_buffer(
|
|
270
|
+
data,
|
|
271
|
+
stats,
|
|
272
|
+
channel,
|
|
273
|
+
l_pix - f_pix + 1,
|
|
274
|
+
self.block_size,
|
|
275
|
+
self.spectrum_size,
|
|
276
|
+
buf_num,
|
|
277
|
+
f_pix,
|
|
278
|
+
f_pix // self.block_size,
|
|
279
|
+
)
|
|
280
|
+
self._buffers[buf_id][channel] = data
|
|
281
|
+
self._current_buffer[channel] = (
|
|
282
|
+
"buffer_a" if self._current_buffer[channel] == "buffer_b" else "buffer_b"
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
def buffer_data(self, channel, buf_id):
|
|
286
|
+
if not self.buffer_full(channel, buf_id):
|
|
287
|
+
raise RuntimeError(f"Buffer {buf_id} {channel} is not ready!")
|
|
288
|
+
return self._buffers[buf_id][channel]
|
|
289
|
+
|
|
290
|
+
def get_step_data(self, channel):
|
|
291
|
+
return self._xia_data[channel]
|
|
292
|
+
|
|
293
|
+
def get_step_stats(self, channel):
|
|
294
|
+
channels = self._mod_channels_map[channel]
|
|
295
|
+
stats = np.zeros(
|
|
296
|
+
(
|
|
297
|
+
9
|
|
298
|
+
* len(
|
|
299
|
+
channels,
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
)
|
|
303
|
+
for i_chan, chan in enumerate(channels):
|
|
304
|
+
stats[i_chan * 9 : (i_chan + 1) * 9] = self._xia_stats[chan]
|
|
305
|
+
return stats
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
# https://numpy.org/doc/stable/user/basics.types.html
|
|
309
|
+
CTYPES2NP = {
|
|
310
|
+
"char *": np.byte,
|
|
311
|
+
"char[]": np.byte,
|
|
312
|
+
"short *": np.short,
|
|
313
|
+
"unsigned short *": np.ushort,
|
|
314
|
+
"int16_t *": np.int16,
|
|
315
|
+
"uint16_t *": np.uint16,
|
|
316
|
+
"uint32_t *": np.uint32,
|
|
317
|
+
"int *": np.intc,
|
|
318
|
+
"unsigned int *": np.uintc,
|
|
319
|
+
"unsigned long *": np.uint,
|
|
320
|
+
"long *": np.int_,
|
|
321
|
+
"double *": np.double,
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def value_to_cffi(dst, src, desc, repointer=False):
|
|
326
|
+
# expecting np array if src is an array
|
|
327
|
+
|
|
328
|
+
v_type = ffi.typeof(dst).cname
|
|
329
|
+
if v_type == "char[]":
|
|
330
|
+
v_type = "char *"
|
|
331
|
+
|
|
332
|
+
try:
|
|
333
|
+
dtype = CTYPES2NP[v_type]
|
|
334
|
+
except KeyError:
|
|
335
|
+
raise TypeError(f"unhandled type {v_type} for value {desc}.")
|
|
336
|
+
|
|
337
|
+
# itemsize = dtype().itemsize()
|
|
338
|
+
# mask = 2**(itemsize*8) - 1
|
|
339
|
+
if isinstance(src, (str,)):
|
|
340
|
+
src = np.array(list(src.encode()), dtype=np.uint8)
|
|
341
|
+
else:
|
|
342
|
+
try:
|
|
343
|
+
len(src)
|
|
344
|
+
except TypeError:
|
|
345
|
+
src = np.array([src])
|
|
346
|
+
|
|
347
|
+
if src.dtype != dtype:
|
|
348
|
+
if repointer:
|
|
349
|
+
src.dtype = dtype
|
|
350
|
+
else:
|
|
351
|
+
src = src.astype(dtype)
|
|
352
|
+
|
|
353
|
+
ffi.memmove(dst, ffi.cast(v_type, src.ctypes.data), src.nbytes)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
class Handel:
|
|
357
|
+
def __init__(self):
|
|
358
|
+
super().__init__()
|
|
359
|
+
self._ini_file = None
|
|
360
|
+
self._is_init = False
|
|
361
|
+
self._hardware = XiaHardware()
|
|
362
|
+
self._sys_started = False
|
|
363
|
+
|
|
364
|
+
self._generator = XiaDataGenerator()
|
|
365
|
+
|
|
366
|
+
def generator(self):
|
|
367
|
+
return self._generator
|
|
368
|
+
|
|
369
|
+
def xiaInitHandel(self):
|
|
370
|
+
self._is_init = True
|
|
371
|
+
|
|
372
|
+
def xiaInit(self, config_file):
|
|
373
|
+
self._hardware = XiaHardware(config_file)
|
|
374
|
+
return XIA_CODES.XIA_SUCCESS
|
|
375
|
+
|
|
376
|
+
def xiaLoadSystem(self, cfg_type, config_file):
|
|
377
|
+
raise NotImplementedError()
|
|
378
|
+
|
|
379
|
+
def xiaStartSystem(self):
|
|
380
|
+
self._sys_started = True
|
|
381
|
+
return XIA_CODES.XIA_SUCCESS
|
|
382
|
+
|
|
383
|
+
def xiaExit(self):
|
|
384
|
+
self._is_init = False
|
|
385
|
+
return XIA_CODES.XIA_SUCCESS
|
|
386
|
+
|
|
387
|
+
# def xiaEndSystem(self):
|
|
388
|
+
# raise NotImplementedError()
|
|
389
|
+
|
|
390
|
+
def xiaGetNumFirmwareSets(self, num):
|
|
391
|
+
raise NotImplementedError()
|
|
392
|
+
|
|
393
|
+
def xiaGetFirmwareSets_VB(self, no, arg):
|
|
394
|
+
raise NotImplementedError()
|
|
395
|
+
|
|
396
|
+
def xiaGetNumPTRRs(self, alias, num):
|
|
397
|
+
raise NotImplementedError()
|
|
398
|
+
|
|
399
|
+
def xiaGetFirmwareItem(self, alias, decimation, filename, arg):
|
|
400
|
+
raise NotImplementedError()
|
|
401
|
+
|
|
402
|
+
def xiaGetNumDetectors(self, num):
|
|
403
|
+
num[0] = len(self._hardware.detectors)
|
|
404
|
+
return XIA_CODES.XIA_SUCCESS
|
|
405
|
+
|
|
406
|
+
def xiaGetNumModules(self, num):
|
|
407
|
+
num[0] = len(self._hardware.modules)
|
|
408
|
+
return XIA_CODES.XIA_SUCCESS
|
|
409
|
+
|
|
410
|
+
def xiaGetModules_VB(self, modno, arg):
|
|
411
|
+
alias = self._hardware.modules[modno]["alias"].encode()
|
|
412
|
+
arg[0 : len(alias)] = alias
|
|
413
|
+
return XIA_CODES.XIA_SUCCESS
|
|
414
|
+
|
|
415
|
+
def xiaGetModules(self, arg):
|
|
416
|
+
modules = [module["alias"].encode()
|
|
417
|
+
for module in self._hardware.modules.values()]
|
|
418
|
+
for i, mod in enumerate(modules):
|
|
419
|
+
arg[i][0:len(mod)] = mod
|
|
420
|
+
return XIA_CODES.XIA_SUCCESS
|
|
421
|
+
|
|
422
|
+
def xiaGetModuleItem(self, modalias, item, value):
|
|
423
|
+
module = self._hardware.module(modalias.decode())
|
|
424
|
+
item_value = module[item.decode()]
|
|
425
|
+
value_to_cffi(value, item_value, item)
|
|
426
|
+
return XIA_CODES.XIA_SUCCESS
|
|
427
|
+
|
|
428
|
+
def xiaGetAcquisitionValues(self, channel, item, value):
|
|
429
|
+
channel = self._hardware.channels[channel]
|
|
430
|
+
item_value = channel[item.decode()]
|
|
431
|
+
value_to_cffi(value, item_value, item)
|
|
432
|
+
return XIA_CODES.XIA_SUCCESS
|
|
433
|
+
|
|
434
|
+
def xiaSetAcquisitionValues(self, channel, item, ptr):
|
|
435
|
+
item = item.decode()
|
|
436
|
+
if channel == -1:
|
|
437
|
+
for channel in self._hardware.channels.values():
|
|
438
|
+
channel[item] = ptr[0]
|
|
439
|
+
else:
|
|
440
|
+
channel = self._hardware.channels[channel]
|
|
441
|
+
channel[item] = ptr[0]
|
|
442
|
+
return XIA_CODES.XIA_SUCCESS
|
|
443
|
+
|
|
444
|
+
def xiaGetParameter(self, channel, parname, value):
|
|
445
|
+
raise NotImplementedError()
|
|
446
|
+
|
|
447
|
+
def xiaGetNumParams(self, channel, value):
|
|
448
|
+
raise NotImplementedError()
|
|
449
|
+
|
|
450
|
+
def xiaGetParamName(self, channel, idx, arg):
|
|
451
|
+
raise NotImplementedError()
|
|
452
|
+
|
|
453
|
+
def xiaGetParamData(self, channel, parname, value):
|
|
454
|
+
raise NotImplementedError()
|
|
455
|
+
|
|
456
|
+
def xiaBoardOperation(self, channum, op, value):
|
|
457
|
+
op = op.decode()
|
|
458
|
+
if op == "apply":
|
|
459
|
+
pass
|
|
460
|
+
elif op == "buffer_done":
|
|
461
|
+
if self._generator:
|
|
462
|
+
value = value.decode()
|
|
463
|
+
self._generator.set_buffer_done(channum, f"buffer_{value}")
|
|
464
|
+
else:
|
|
465
|
+
raise NotImplementedError(
|
|
466
|
+
f"Board operation {op} ({value}) not implemented."
|
|
467
|
+
)
|
|
468
|
+
return XIA_CODES.XIA_SUCCESS
|
|
469
|
+
|
|
470
|
+
def xiaGetRunData(self, channel, cmd, data):
|
|
471
|
+
cmd = cmd.decode()
|
|
472
|
+
if cmd == "run_active":
|
|
473
|
+
if self._generator is None or self._generator.finished:
|
|
474
|
+
item_value = 0
|
|
475
|
+
else:
|
|
476
|
+
item_value = 1 if self._generator.detector_running(channel) else 0
|
|
477
|
+
elif cmd == "mca":
|
|
478
|
+
if not self._generator:
|
|
479
|
+
chan_dict = self._hardware.channels[0]
|
|
480
|
+
item_value = np.random.randint(
|
|
481
|
+
1,
|
|
482
|
+
1000000,
|
|
483
|
+
size=(int(chan_dict["number_mca_channels"])),
|
|
484
|
+
dtype=np.uint32,
|
|
485
|
+
)
|
|
486
|
+
else:
|
|
487
|
+
item_value = self._generator.get_step_data(channel)
|
|
488
|
+
elif cmd == "module_statistics_2":
|
|
489
|
+
module = self._hardware._chan2mod[channel]
|
|
490
|
+
if not self._generator:
|
|
491
|
+
n_channels = self._hardware.n_channels(module)
|
|
492
|
+
nb_stats = 9 * n_channels
|
|
493
|
+
item_value = np.random.rand(nb_stats).astype(np.double)
|
|
494
|
+
else:
|
|
495
|
+
item_value = self._generator.get_step_stats(module)
|
|
496
|
+
elif cmd == "current_pixel":
|
|
497
|
+
if not self._generator:
|
|
498
|
+
item_value = 0
|
|
499
|
+
else:
|
|
500
|
+
item_value = self._generator.current_pixel(channel)
|
|
501
|
+
elif cmd == "buffer_full_a":
|
|
502
|
+
item_value = int(
|
|
503
|
+
self._generator is not None
|
|
504
|
+
and self._generator.buffer_full(channel, "buffer_a")
|
|
505
|
+
)
|
|
506
|
+
elif cmd == "buffer_full_b":
|
|
507
|
+
item_value = int(
|
|
508
|
+
self._generator is not None
|
|
509
|
+
and self._generator.buffer_full(channel, "buffer_b")
|
|
510
|
+
)
|
|
511
|
+
elif cmd == "buffer_a":
|
|
512
|
+
if not self._generator:
|
|
513
|
+
raise RuntimeError("Simulator: no acquisition running.")
|
|
514
|
+
item_value = self._generator.buffer_data(channel, "buffer_a")
|
|
515
|
+
item_value.dtype = np.uint16
|
|
516
|
+
elif cmd == "buffer_b":
|
|
517
|
+
if not self._generator:
|
|
518
|
+
raise RuntimeError("Simulator: no acquisition running.")
|
|
519
|
+
item_value = self._generator.buffer_data(channel, "buffer_b")
|
|
520
|
+
item_value.dtype = np.uint16
|
|
521
|
+
elif cmd == "buffer_len":
|
|
522
|
+
channel = self._hardware.channels[channel]
|
|
523
|
+
block_size = channel["num_map_pixels_per_buffer"]
|
|
524
|
+
spectrum_size = channel["number_mca_channels"]
|
|
525
|
+
item_value = int(256 + block_size * (256 + spectrum_size * 2))
|
|
526
|
+
else:
|
|
527
|
+
channel = self._hardware.channels[channel]
|
|
528
|
+
if cmd == "mca_length":
|
|
529
|
+
cmd = "number_mca_channels"
|
|
530
|
+
item_value = channel[cmd]
|
|
531
|
+
|
|
532
|
+
value_to_cffi(data, item_value, cmd)
|
|
533
|
+
return XIA_CODES.XIA_SUCCESS
|
|
534
|
+
|
|
535
|
+
def xiaStartRun(self, channel, resume):
|
|
536
|
+
logger.info("Starting channel %s.", channel)
|
|
537
|
+
if channel == -1:
|
|
538
|
+
channels = range(self._hardware.n_channels())
|
|
539
|
+
else:
|
|
540
|
+
channels = [channel]
|
|
541
|
+
|
|
542
|
+
generator = self.generator()
|
|
543
|
+
|
|
544
|
+
# TODO: test on real hardware what happens is start is called twice
|
|
545
|
+
for channel in channels:
|
|
546
|
+
self._generator.start_detector(channel)
|
|
547
|
+
return XIA_CODES.XIA_SUCCESS
|
|
548
|
+
|
|
549
|
+
def xiaStopRun(self, channel):
|
|
550
|
+
# if channel == -1:
|
|
551
|
+
# self._generator.stop()
|
|
552
|
+
# else:
|
|
553
|
+
# raise NotImplementedError(
|
|
554
|
+
# "Simulator: stopping run on invidual " "channels not implemented."
|
|
555
|
+
# )
|
|
556
|
+
# TODO: individual stops
|
|
557
|
+
if self._generator:
|
|
558
|
+
self._generator.stop()
|
|
559
|
+
# self._generator = None
|
|
560
|
+
return XIA_CODES.XIA_SUCCESS
|
|
561
|
+
|
|
562
|
+
def xiaEnableLogOutput(self):
|
|
563
|
+
pass
|
|
564
|
+
# raise NotImplementedError()
|
|
565
|
+
|
|
566
|
+
def xiaSuppressLogOutput(self):
|
|
567
|
+
raise NotImplementedError()
|
|
568
|
+
|
|
569
|
+
def xiaSetLogFile(self, logfile):
|
|
570
|
+
raise NotImplementedError()
|
|
571
|
+
|
|
572
|
+
def xiaSetLogLevel(self, lvl):
|
|
573
|
+
raise NotImplementedError()
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
class SimFalconXHW(FalconXHW):
|
|
577
|
+
def __init__(self, *args, lib_path=None, **kwargs):
|
|
578
|
+
from .simfalconxhw import Handel as SimHandel
|
|
579
|
+
sim_lib = SimHandel()
|
|
580
|
+
super().__init__(*args, lib_path=sim_lib, **kwargs)
|
|
581
|
+
|
|
582
|
+
def apply_mosca(self,
|
|
583
|
+
*args,
|
|
584
|
+
**kwargs):
|
|
585
|
+
super().apply_mosca(*args, **kwargs)
|
|
586
|
+
self.generator().apply_mosca(*args, **kwargs)
|
|
587
|
+
|
|
588
|
+
def prepare_acq(self, *args, **kwargs):
|
|
589
|
+
super().prepare_acq()
|
|
590
|
+
hi = self.hi
|
|
591
|
+
generator = self.generator()
|
|
592
|
+
generator.channels_per_mod = [hi.get_module_number_of_channels(mod)
|
|
593
|
+
for mod in hi.get_modules()]
|
|
594
|
+
generator.xia_mapping = self.mapping_mode == 1.0
|
|
595
|
+
generator.start_delay = 0.015
|
|
596
|
+
self.generator().prepare(self.available_detectors(), self.spectrum_size())
|
|
597
|
+
|
|
598
|
+
def generator(self):
|
|
599
|
+
return self.hi.handel.generator()
|
|
File without changes
|