def __init__(self, config_fname, use_events=False, print_time=1, sleep_time=0, all_frames=False): self.m_cam = SlsDetector.Camera(config_fname) self.m_hw_inter = SlsDetector.Interface(self.m_cam) self.m_acq_state = Core.AcqState() self.m_corr = None if self.m_cam.getType() == SlsDetector.EigerDet: self.m_eiger = SlsDetector.Eiger(self.m_cam) self.m_corr = self.m_eiger.createCorrectionTask() else: deb.Warning("Non-supported type: %s" % self.m_cam.getType()) self.m_ct = Core.CtControl(self.m_hw_inter) self.m_ct_acq = self.m_ct.acquisition() self.m_ct_saving = self.m_ct.saving() self.m_ct_image = self.m_ct.image() self.m_ct_buffer = self.m_ct.buffer() self.m_use_events = use_events self.m_print_time = print_time self.m_sleep_time = sleep_time if self.m_corr: self.m_ct.setReconstructionTask(self.m_corr) if self.m_use_events: cb = ImageStatusCallback(self.m_ct, self.m_acq_state, print_time, sleep_time, all_frames) self.m_img_status_cb = cb self.m_ct.registerImageStatusCallback(self.m_img_status_cb)
def get_control(config_fname, full_config_fname=None, apply_corrections=None, **keys) : global _SlsDetectorCam, _SlsDetectorHwInter, _SlsDetectorEiger global _SlsDetectorCorrection, _SlsDetectorControl def to_bool(x, default_val=False): if x is None: return default_val elif type(x) is str: x = x.lower() if x == 'true': return True elif x == 'false': return False else: return bool(int(x)) else: return bool(x) apply_corrections = to_bool(apply_corrections, True) if _SlsDetectorControl is None: if full_config_fname: p = Process(target=setup_partial_config, args=(config_fname, full_config_fname)) p.start() p.join() det_id = 0 _SlsDetectorCam = SlsDetectorHw.Camera(config_fname, det_id) 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) if apply_corrections: _SlsDetectorCorrection = _SlsDetectorEiger.createCorrectionTask() else: raise ValueError("Unknown detector type: %s" % _SlsDetectorCam.getType()) _SlsDetectorControl = Core.CtControl(_SlsDetectorHwInter) if _SlsDetectorCorrection: _SlsDetectorControl.setReconstructionTask(_SlsDetectorCorrection) return _SlsDetectorControl
def get_control(config_fname, **keys) : global _SlsDetectorCam, _SlsDetectorHwInter, _SlsDetectorEiger global _SlsDetectorCorrection, _SlsDetectorControl if _SlsDetectorControl is None: _SlsDetectorCam = SlsDetectorHw.Camera(config_fname) _SlsDetectorHwInter = SlsDetectorHw.Interface(_SlsDetectorCam) if _SlsDetectorCam.getType() == SlsDetectorHw.EigerDet: _SlsDetectorEiger = SlsDetectorHw.Eiger(_SlsDetectorCam) _SlsDetectorCorrection = _SlsDetectorEiger.createCorrectionTask() else: raise ValueError("Unknown detector type: %s" % _SlsDetectorCam.getType()) _SlsDetectorControl = Core.CtControl(_SlsDetectorHwInter) if _SlsDetectorCorrection: _SlsDetectorControl.setReconstructionTask(_SlsDetectorCorrection) return _SlsDetectorControl
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!')
from Lima import Core, SlsDetector import os import time class DebTypeFlags: def __init__(self, flags): self.flags = flags self.orig = Core.DebParams.getTypeFlags() def __enter__(self): Core.DebParams.setTypeFlags(self.flags) def __exit__(self, *args): Core.DebParams.setTypeFlags(self.orig) config_file = os.environ['EIGER_CONFIG'] cam = SlsDetector.Camera(config_file) eiger = SlsDetector.Eiger(cam) hw_inter = SlsDetector.Interface(cam) ct = Core.CtControl(hw_inter) def do_acq(): acq = ct.acquisition() acq.setAcqExpoTime(0.1) ct.prepareAcq() ct.startAcq() while ct.getStatus().AcquisitionStatus == Core.AcqRunning: time.sleep(0.1) print "*** Acq finished ***" def test(cam): print "** Calling getPixelDepthCPUAffinityMap" m = cam.getPixelDepthCPUAffinityMap()
from Lima import Core, SlsDetector CPUAffinity = SlsDetector.CPUAffinity NetDevGroupCPUAffinity = SlsDetector.NetDevGroupCPUAffinity GlobalCPUAffinity = SlsDetector.GlobalCPUAffinity import os config_fname = os.environ['EIGER_CONFIG'] cam = SlsDetector.Camera(config_fname) try: print cam.getNetworkParameter(SlsDetector.Defs.FlowCtrl10G) print cam.setNetworkParameter(SlsDetector.Defs.FlowCtrl10G, "0") print cam.setNetworkParameter(SlsDetector.Defs.FlowCtrl10G, "1") except: print "Exception on NetworkParameter management" global_aff_map = cam.getPixelDepthCPUAffinityMap() if not global_aff_map: pixel_depth_list = [4, 8, 16, 32] for pixel_depth in pixel_depth_list: global_aff = GlobalCPUAffinity() global_aff.recv.listeners = CPUAffinity(0xf00) global_aff.recv.writers = CPUAffinity(0x0fc) global_aff.recv.lima = CPUAffinity(0x002) global_aff.recv.other = CPUAffinity(0x001) global_aff_map[pixel_depth] = global_aff all_netdev = [('eth%d' % i) for i in range(10)] data_netdev = ['eth3', 'eth5']
def get_slsdetector_hw_inter(config=None): config = config or os.environ['EIGER_CONFIG'] cam = SlsDetector.Camera(config) eiger = SlsDetector.Eiger(cam) hw_inter = SlsDetector.Interface(cam) return hw_inter, (cam, eiger)