TL;DR¶
Two ways to use Mosca to start an acquisition:
Mosca parameters vs Controller parameters
Remember that acquisition parameters set through the Mosca instance (direct or DS) are only sent to controller when the method apply_mosca
is called.
It's the controller responsibility to translate Mosca parameters to controller parameters. See the controller documentation (Controllers section) for details.
Direct access¶
If you are not interested in using the Tango DS, you can instantiate yourself the controller and mosca objects.
Note
The Mosca instance is NOT mandatory. It is just there to provide a standard API for controllers, poll the controller once the acquisition is started and provide various services (buffering, rois, saving, ...).
You could easily configure, start an acquisition and do the polling yourself. Have a look at the Controller class documentation, especially the methods apply_mosca, start_acq, poll_acq.
from mosca.control.mosca import Mosca
from mosca.devices.simulation.xia.simfalconxhw import SimFalconXHW
# 1. instantiate the controller
simfx = SimFalconXHW(simu_data="/data/id00/inhouse/damien/spectra_18_elem.h5")
# 2. instantiate Mosca (poller and data handler)
mosca = Mosca(simfx)
# 3. configure the controller (same as doing simfx.ini_file = "...")
mosca.controller.ini_file = "dn/mosca/tests/data/falconx_18ch.ini"
# 4. add a roi on all detector modules
mosca.data.rois.add_roi(name="sca01", bin_start=1750, bin_end=1775)
# add a roi on selected detector modules
mosca.data.rois.add_roi(name="sca02", bin_start=2610, bin_end=2650, channels=(5, 9, 14))
# 5. set acquisition parameters
mosca.acq_realtime = 6.66
mosca.run_mode = "REALTIME"
# 6. run
mosca.start_mosca(wait=True)
# this is equivalent to doing:
# mosca.apply_mosca()
# mosca.prepare()
# mosca.start_acq(wait=True)
# 7. get the data
# IMPORTANT: this is a circular buffer, see the documentation <TDB>
spectra = mosca.data.spectra[:]
stats = mosca.data.stats[:]
rois = mosca.data.rois[:]
You can also directly set the controller acquisition parameters, but be careful not to call the apply_mosca method, as it will overwrite those parameters. For instance you would get the same result as the previous example with the following code:
# 5. set acquisition parameters
# ATTENTION! These are XIA specific parameters. Other controllers won't have the same.
mosca.controller.preset_mode = 1
mosca.controller.preset_value = 6.66
# 6. apply and run
# --> Dont call mosca.apply_mosca() !
mosca.prepare()
mosca.start_acq(wait=True)
To learn about know how the mosca parameters (acq_realtime, acq_nb_points, run_mode, ...) translates to the specific controller parameters (e.g: preset_mode for Xia, gating_mode for Dante, ...) please have a look at their respective documentation.
Tango¶
A tango device server (DS) can be run on top on the Mosca and Controller classes to allow remote access to the hardware.
Mosca devices are started with the mosca script that is available once mosca is installed.
(mosca) user@host:~$ mosca -h
usage: mosca [-h] [--register prefix mca_type] instance
Mosca DS.
positional arguments:
instance Instance name.
optional arguments:
-h, --help show this help message and exit
--register prefix mca_type
registers a new DS
Device registration
To register a new device just run the mosca command with the --register optional argument:
(mosca) user@host:~$ mosca simfx18 --register id00 simfalconx
Added the following properties to id00/simfalconx/simfx18:
- config_dir = c:/blissadm/falconx/config
- default_config = falconx.ini
- lib_dir =
You will probably need to edit them.
The previous command registered three device servers:
- the Mosca DS (here id00/mosca/simfx)
- the controller DS (here id00/simfalconx/simfx)
- the MoscaV1 DS, used by the bliss Mosca client (here id00/simfalconx/simfx).
After editing the mandatory and optional properties, your servers are ready to be started.
Running the DS
(mosca) user@host:~$ mosca simfx
[2025-03-03 16:20:07.356] INFO [mosca.SimFalconX] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.362] INFO [mosca.Handel] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.362] INFO [mosca.XiaHardware] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.654] INFO [mosca.Handel] Using a data file: /data/id00/inhouse/damien/spectra_18_elem.h5. (simfalconxhw.py:387)
[2025-03-03 16:20:07.655] INFO [mosca.SimFalconXHW] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.655] INFO [mosca.SimFalconXHW] lib_path=<mosca.devices.simulation.xia.simfalconxhw.Handel object at 0x7f5b0db04910> (xia.py:178)
[2025-03-03 16:20:07.655] INFO [mosca.SimFalconXHW] Loading library [<mosca.devices.simulation.xia.simfalconxhw.Handel object at 0x7f5b0db04910>]. (xia.py:184)
[2025-03-03 16:20:07.655] WARNING [mosca.SimFalconX] ==========================
==== USING SIMooLATOR ====
========================== (simfalconx.py:14)
[2025-03-03 16:20:07.656] INFO [mosca.SimFalconXHW] Loading file /data/id00/inhouse/damien/fx_ini/falconx_18ch.ini. (xia.py:196)
[2025-03-03 16:20:07.656] INFO [mosca.XiaHardware] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.686] INFO [mosca.XiaHardware] Loading XIA ini file b'/data/id00/inhouse/damien/fx_ini/falconx_18ch.ini' (simfalconxhw.py:164)
[2025-03-03 16:20:10.643] INFO [mosca.XiaHardware] Ini file loaded. (simfalconxhw.py:166)
[2025-03-03 16:20:10.643] INFO [mosca.SimFalconXHW] File loaded (/data/id00/inhouse/damien/fx_ini/falconx_18ch.ini). (xia.py:202)
[2025-03-03 16:20:10.647] INFO [mosca.SimFalconXHW] Channels declared in the ini: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]. (xia.py:219)
[2025-03-03 16:20:10.665] INFO [mosca.Mosca] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.665] INFO [mosca.Mosca] Mosca __init__ (mosca.py:30)
[2025-03-03 16:20:10.667] INFO [mosca.Mosca] in init_device() (mosca.py:38)
[2025-03-03 16:20:10.686] INFO [mosca.Mosca] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.686] INFO [mosca.DataHandler] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.686] INFO [mosca.Rois] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.686] INFO [mosca.SpectraSums] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.687] INFO [mosca.SaveManager] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.690] INFO [mosca.MoscaV1] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.690] INFO [mosca.MoscaV1] Mosca __init__ (moscav1.py:33)
[2025-03-03 16:20:10.693] INFO [mosca.MoscaV1] in init_device() (moscav1.py:43)
Ready to accept request
From there you can use the DS pretty much like you would use the Mosca and your controller instance with the "direct access" method.
(mosca) user@host:~$ mosca simfx
[2025-03-03 16:20:07.356] INFO [mosca.SimFalconX] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.362] INFO [mosca.Handel] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.362] INFO [mosca.XiaHardware] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.654] INFO [mosca.Handel] Using a data file: /data/id00/inhouse/damien/spectra_18_elem.h5. (simfalconxhw.py:387)
[2025-03-03 16:20:07.655] INFO [mosca.SimFalconXHW] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.655] INFO [mosca.SimFalconXHW] lib_path=<mosca.devices.simulation.xia.simfalconxhw.Handel object at 0x7f5b0db04910> (xia.py:178)
[2025-03-03 16:20:07.655] INFO [mosca.SimFalconXHW] Loading library [<mosca.devices.simulation.xia.simfalconxhw.Handel object at 0x7f5b0db04910>]. (xia.py:184)
[2025-03-03 16:20:07.655] WARNING [mosca.SimFalconX] ==========================
==== USING SIMooLATOR ====
========================== (simfalconx.py:14)
[2025-03-03 16:20:07.656] INFO [mosca.SimFalconXHW] Loading file /data/id00/inhouse/damien/fx_ini/falconx_18ch.ini. (xia.py:196)
[2025-03-03 16:20:07.656] INFO [mosca.XiaHardware] Log initialized. (logger.py:68)
[2025-03-03 16:20:07.686] INFO [mosca.XiaHardware] Loading XIA ini file b'/data/id00/inhouse/damien/fx_ini/falconx_18ch.ini' (simfalconxhw.py:164)
[2025-03-03 16:20:10.643] INFO [mosca.XiaHardware] Ini file loaded. (simfalconxhw.py:166)
[2025-03-03 16:20:10.643] INFO [mosca.SimFalconXHW] File loaded (/data/id00/inhouse/damien/fx_ini/falconx_18ch.ini). (xia.py:202)
[2025-03-03 16:20:10.647] INFO [mosca.SimFalconXHW] Channels declared in the ini: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]. (xia.py:219)
[2025-03-03 16:20:10.665] INFO [mosca.Mosca] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.665] INFO [mosca.Mosca] Mosca __init__ (mosca.py:30)
[2025-03-03 16:20:10.667] INFO [mosca.Mosca] in init_device() (mosca.py:38)
[2025-03-03 16:20:10.686] INFO [mosca.Mosca] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.686] INFO [mosca.DataHandler] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.686] INFO [mosca.Rois] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.686] INFO [mosca.SpectraSums] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.687] INFO [mosca.SaveManager] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.690] INFO [mosca.MoscaV1] Log initialized. (logger.py:68)
[2025-03-03 16:20:10.690] INFO [mosca.MoscaV1] Mosca __init__ (moscav1.py:33)
[2025-03-03 16:20:10.693] INFO [mosca.MoscaV1] in init_device() (moscav1.py:43)
Ready to accept request
Setting up an acquisition
import time
from tango import DeviceProxy
mosca = DeviceProxy("id00/mosca/simfx")
simfx = DeviceProxy("id00/simfalconx/simfx")
# set the timeout high enough
# this usually depends on the model, number of detectors, ...
mosca.set_timeout_millis(10000)
simfx.set_timeout_millis(10000)
# note that there are optional properties that you can set on the DS:
# timeout_start, timeout_apply, timeout_prepare, timeout_stop
# start_timeout = self.proxy.start_timeout
# mosca.set_timeout_millis(start_timeout)
# simfx.set_timeout_millis(start_timeout)
# 3. configure the controller if necessary
# (make sure that this path is valid on the remote host)
simfx.ini_file = "/data/id00/inhouse/damien/fx_ini/falconx_18ch.ini"
# 4. add a roi on all detector modules
mosca.add_roi(["sca01", "1750", "1775"])
# add a roi on selected detector modules (5, 9, 14)
mosca.add_roi(["sca01", "2610", "2650", "5", "9", "14"])
# 5. set acquisition parameters
mosca.acq_realtime = 6.66
mosca.run_mode = "REALTIME"
# 6. apply and run
mosca.start_mosca()
# again, this is equivalent to doing:
# mosca.apply_mosca()
# mosca.prepare()
# mosca.start_acq()
# wait ...
while mosca.acq_status == "RUNNING":
print("wait")
time.sleep(0.5)
# 7. get the data
# IMPORTANT: this is a circular buffer, see the documentation <TDB>
spectra = mosca.read_spectra([])
stats = mosca.read_stats([])
# TODO: rois = mosca.get_rois([])
# 5. set acquisition parameters
# ATTENTION! These are XIA specific parameters. Other controllers won't have the same.
simfx.preset_value = 6.66
simfx.preset_mode = 1.
# 6. apply and run
# --> Dont call mosca.apply_mosca() !
mosca.prepare()
mosca.start_acq()