Commit 9a88145b authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

Merge branch 'slsdetector'

parents 24dc84b9 e75c1fb1
Pipeline #8458 passed with stages
in 2 minutes and 13 seconds
......@@ -44,6 +44,8 @@ import numpy as np
import PyTango
from collections import OrderedDict
from functools import partial
from itertools import chain
from multiprocessing import Process
from Lima import Core
from Lima import SlsDetector as SlsDetectorHw
......@@ -76,8 +78,12 @@ class SlsDetector(PyTango.Device_4Impl):
MilliVoltSuffix = '_mv'
ModelAttrs = ['parallel_mode', 'clock_div', 'high_voltage',
'threshold_energy']
ModelAttrs = ['parallel_mode',
'high_voltage',
'clock_div',
'fixed_clock_div',
'threshold_energy',
]
def __init__(self,*args) :
PyTango.Device_4Impl.__init__(self,*args)
......@@ -106,6 +112,13 @@ class SlsDetector(PyTango.Device_4Impl):
self.proc_finished = self.cam.getProcessingFinishedEvent()
self.proc_finished.registerStatusCallback(_SlsDetectorControl)
if self.high_voltage > 0:
self.model.setHighVoltage(self.high_voltage)
if self.fixed_clock_div > 0:
self.model.setFixedClockDiv(self.fixed_clock_div)
if self.threshold_energy > 0:
self.model.setThresholdEnergy(self.threshold_energy)
self.cam.setTolerateLostPackets(self.tolerate_lost_packets)
self.netdev_groups = [g.split(',') for g in self.netdev_groups]
aff_array = self.pixel_depth_cpu_affinity_map
......@@ -355,22 +368,64 @@ class SlsDetector(PyTango.Device_4Impl):
raise err
aff_map = {}
CPUAffinity = SlsDetectorHw.CPUAffinity
RecvCPUAffinity = SlsDetectorHw.RecvCPUAffinity
NetDevRxQueueCPUAffinity = SlsDetectorHw.NetDevRxQueueCPUAffinity
NetDevGroupCPUAffinity = SlsDetectorHw.NetDevGroupCPUAffinity
GlobalCPUAffinity = SlsDetectorHw.GlobalCPUAffinity
for aff_data in aff_array:
aff_data = map(int, aff_data)
pixel_depth, recv_l, recv_w, lima, other = aff_data[:5]
netdev_aff = aff_data[5:]
all_cpus = range(CPUAffinity.getNbSystemCPUs())
recv_lw = [[6, 7], [9, 10]]
indep_lw = True
if indep_lw:
recv_l = recv_lw
recv_w = [map(lambda x: x + 12, l) for l in recv_l]
else:
recv_l = [[(x, x + 12) for x in r] for r in recv_lw]
recv_w = recv_l
recv_pt = [(8, 20), (11, 23)]
recv_pt = zip(*([recv_pt] * 2))
lima = list(range(6))
lima += map(lambda x: x + 12, lima)
lima.remove(0)
other = [0]
irq_aff = [0, (8, 20), (11, 23)]
proc_aff = irq_aff
def Affinity(*x):
if type(x[0]) in [tuple, list]:
x = list(chain(*x))
m = reduce(lambda a, b: a | b, map(lambda a: 1 << a, x))
return CPUAffinity(m)
global_affinity = GlobalCPUAffinity()
global_affinity.recv.listeners = CPUAffinity(recv_l)
global_affinity.recv.writers = CPUAffinity(recv_w)
global_affinity.lima = CPUAffinity(lima)
global_affinity.other = CPUAffinity(other)
recv_list = []
for l, w, pt in zip(recv_l, recv_w, recv_pt):
recv = RecvCPUAffinity()
recv.listeners = map(Affinity, l)
recv.writers = map(Affinity, w)
recv.port_threads = map(Affinity, pt)
recv_list.append(recv)
global_affinity.recv = recv_list
for i, r in enumerate(global_affinity.recv):
s = "Recv[%d]:" % i
def A(x):
return hex(long(x))
s += " listeners=%s," % [A(x) for x in r.listeners]
s += " writers=%s," % [A(x) for x in r.writers]
s += " port_threads=%s" % [A(x) for x in r.port_threads]
print(s)
global_affinity.lima = Affinity(*lima)
global_affinity.other = Affinity(*other)
ng_aff_list = []
for name_list, a in zip(self.netdev_groups, netdev_aff):
for name_list, (irq, proc) in zip(self.netdev_groups,
zip(irq_aff, proc_aff)):
ng_aff = NetDevGroupCPUAffinity()
ng_aff.name_list = name_list
ng_aff.processing = CPUAffinity(a)
ng_aff_queue = NetDevRxQueueCPUAffinity()
ng_aff_queue.irq = Affinity(irq)
ng_aff_queue.processing = Affinity(proc)
ng_aff.queue_affinity = {-1: ng_aff_queue}
ng_aff_list.append(ng_aff)
global_affinity.netdev = ng_aff_list
aff_map[pixel_depth] = global_affinity
......@@ -411,6 +466,19 @@ class SlsDetectorClass(PyTango.DeviceClass):
'config_fname':
[PyTango.DevString,
"Path to the SlsDetector config file",[]],
'full_config_fname':
[PyTango.DevString,
"In case of partial configuration, path to the full config file",[]],
'high_voltage':
[PyTango.DevShort,
"Initial detector high voltage (V) "
"(set to 150 if already tested)", 0],
'fixed_clock_div':
[PyTango.DevShort,
"Initial detector fixed-clock-div (0, 1)", 0],
'threshold_energy':
[PyTango.DevLong,
"Initial detector threshold energy (eV)", 0],
'tolerate_lost_packets':
[PyTango.DevBoolean,
"Initial tolerance to lost packets", True],
......@@ -495,6 +563,10 @@ class SlsDetectorClass(PyTango.DeviceClass):
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ_WRITE]],
'fixed_clock_div':
[[PyTango.DevBoolean,
PyTango.SCALAR,
PyTango.READ_WRITE]],
'parallel_mode':
[[PyTango.DevString,
PyTango.SCALAR,
......@@ -519,6 +591,10 @@ class SlsDetectorClass(PyTango.DeviceClass):
[[PyTango.DevBoolean,
PyTango.SCALAR,
PyTango.READ_WRITE]],
'skip_frame_freq':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE]],
}
def __init__(self,name) :
......@@ -539,7 +615,18 @@ def get_control(config_fname, **keys) :
global _SlsDetectorCam, _SlsDetectorHwInter, _SlsDetectorEiger
global _SlsDetectorCorrection, _SlsDetectorControl
if _SlsDetectorControl is None:
full_config_fname = keys.pop('full_config_fname', None)
if full_config_fname:
p = Process(target=setup_partial_config,
args=(config_fname, full_config_fname))
p.start()
p.join()
_SlsDetectorCam = SlsDetectorHw.Camera(config_fname)
for i, n in enumerate(_SlsDetectorCam.getHostnameList()):
print('Enabling: %s (%d)' % (n, i))
_SlsDetectorCam.putCmd('activate 1', i)
_SlsDetectorHwInter = SlsDetectorHw.Interface(_SlsDetectorCam)
if _SlsDetectorCam.getType() == SlsDetectorHw.EigerDet:
_SlsDetectorEiger = SlsDetectorHw.Eiger(_SlsDetectorCam)
......@@ -555,3 +642,32 @@ def get_control(config_fname, **keys) :
def get_tango_specific_class_n_device():
return SlsDetectorClass, SlsDetector
#----------------------------------------------------------------------------
# Deactivate modules in partial config
#----------------------------------------------------------------------------
def setup_partial_config(config_fname, full_config_fname):
import re
cam = SlsDetectorHw.Camera(full_config_fname)
full_hostname_list = cam.getHostnameList()
print('Full config: %s' % ','.join(full_hostname_list))
host_re_str = '([A-Za-z0-9]+)+?'
host_re_obj = re.compile(host_re_str)
re_obj = re.compile('^[ \\t]*hostname[ \\t]+(%s[^# ]+)' % host_re_str)
partial_hostname_list = []
with open(config_fname) as f:
for l in f:
m = re_obj.match(l)
if m:
s = m.groups()[0]
partial_hostname_list = host_re_obj.findall(s)
break
print('Partial config: %s' % ','.join(partial_hostname_list))
for i, n in enumerate(full_hostname_list):
if n not in partial_hostname_list:
print('Disabling: %s (%d)' % (n, i))
cam.putCmd('activate 0', i)
print('Partial config: Done!')
......@@ -13,6 +13,10 @@ Properties
Property name Mandatory Default value Description
=============================== =============== =============== ==============================================================
config_fname Yes - Path to the SlsDetector config file
high_voltage No 0 Initial detector high voltage (V)
(set to 150 if already tested)
fixed_clock_div No 0 Initial detector fixed-clock-div
threshold_energy No 0 Initial detector threshold energy (eV)
tolerate_lost_packets No True Initial tolerance to lost packets
netdev_groups No [] List of network device groups, each group is a list of
comma-separated interface names: ["ethX,ethY", "ethZ,..."]
......@@ -42,12 +46,14 @@ pixel_depth rw DevString The image pixel bit-depth:
- **32**
raw_mode rw DevBoolean Publish image as given by the Receivers (no SW reconstruction)
threshold_energy rw DevLong The energy (in eV) the pixel discriminator thresholds (Vcmp & Trim bits) is set at
high_voltage rw DevShort The detector high voltage (in V)
all_trim_bits rw DevVarLongArray Array with the pixel trimming value [0-63] for each half-module, if all the pixels in the half-module have the same trimming value, -1 otherwise
clock_div rw DevString The readout clock divider:
- **FULL_SPEED**
- **HALF_SPEED**
- **QUARTER_SPEED**
- **SUPER_SLOW_SPEED**
fixed_clock_div rw DevBoolean If active, will try to keep the same clock_div when changing pixel_depth
readout_flags rw DevString The flags affecting the readout mode (Parallel|NonParallel|Safe + StoreInRAM|Continous):
- **PARALLEL + STORE_IN_RAM**
- **PARALLEL + CONTINUOUS**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment