more const more python

This commit is contained in:
Erik Frojdh 2019-03-18 17:38:44 +01:00
parent 98655ee7e3
commit 43012e4f28
9 changed files with 65 additions and 297 deletions

View File

@ -63,7 +63,6 @@ class Detector:
@property @property
@error_handling
def busy(self): def busy(self):
""" """
Checks the detector is acquiring. Can also be set but should only be used if the acquire fails and Checks the detector is acquiring. Can also be set but should only be used if the acquire fails and
@ -94,7 +93,6 @@ class Detector:
return self._api.getAcquiringFlag() return self._api.getAcquiringFlag()
@busy.setter @busy.setter
@error_handling
def busy(self, value): def busy(self, value):
self._api.setAcquiringFlag(value) self._api.setAcquiringFlag(value)
@ -103,7 +101,6 @@ class Detector:
self._api.clearErrorMask() self._api.clearErrorMask()
@property @property
@error_handling
def client_version(self): def client_version(self):
""" """
:py:obj:`str` The date of commit for the client API version :py:obj:`str` The date of commit for the client API version
@ -121,8 +118,7 @@ class Detector:
return v[2:] return v[2:]
@property @property
@error_handling def detectornumber(self):
def detector_number(self):
""" """
Get all detector numbers as a list. For Eiger the detector numbers Get all detector numbers as a list. For Eiger the detector numbers
correspond to the beb numbers. correspond to the beb numbers.
@ -137,7 +133,7 @@ class Detector:
>> [83, 98] >> [83, 98]
""" """
return [self._api.getDetectorNumber(i) for i in range(self.n_modules)] return self._api.getDetectorNumber()
@property @property
def detector_type(self): def detector_type(self):
@ -163,7 +159,6 @@ class Detector:
return element_if_equal(self._api.getDetectorType()) return element_if_equal(self._api.getDetectorType())
@property @property
@error_handling
def dynamic_range(self): def dynamic_range(self):
""" """
:obj:`int`: Dynamic range of the detector. :obj:`int`: Dynamic range of the detector.
@ -190,7 +185,6 @@ class Detector:
return self._api.getDynamicRange() return self._api.getDynamicRange()
@dynamic_range.setter @dynamic_range.setter
@error_handling
def dynamic_range(self, dr): def dynamic_range(self, dr):
if dr in self._detector_dynamic_range: if dr in self._detector_dynamic_range:
self._api.setDynamicRange(dr) self._api.setDynamicRange(dr)
@ -199,18 +193,8 @@ class Detector:
raise DetectorValueError('Cannot set dynamic range to: {:d} availble options: '.format(dr), raise DetectorValueError('Cannot set dynamic range to: {:d} availble options: '.format(dr),
self._detector_dynamic_range) self._detector_dynamic_range)
@property
def error_mask(self):
"""Read the error mask from the slsDetectorSoftware"""
return self._api.getErrorMask()
@property @property
def error_message(self):
"""Read the error message from the slsDetectorSoftware"""
return self._api.getErrorMessage()
@property
@error_handling
def exposure_time(self): def exposure_time(self):
""" """
:obj:`double` Exposure time in [s] of a single frame. :obj:`double` Exposure time in [s] of a single frame.
@ -218,7 +202,6 @@ class Detector:
return self._api.getExposureTime() / 1e9 return self._api.getExposureTime() / 1e9
@exposure_time.setter @exposure_time.setter
@error_handling
def exposure_time(self, t): def exposure_time(self, t):
ns_time = int(t * 1e9) ns_time = int(t * 1e9)
if ns_time <= 0: if ns_time <= 0:
@ -226,7 +209,6 @@ class Detector:
self._api.setExposureTime(ns_time) self._api.setExposureTime(ns_time)
@property @property
@error_handling
def file_index(self): def file_index(self):
""" """
:obj:`int` Index for frames and file names :obj:`int` Index for frames and file names
@ -252,14 +234,12 @@ class Detector:
return self._api.getFileIndex() return self._api.getFileIndex()
@file_index.setter @file_index.setter
@error_handling
def file_index(self, i): def file_index(self, i):
if i < 0: if i < 0:
raise ValueError('Index needs to be positive') raise ValueError('Index needs to be positive')
self._api.setFileIndex(i) self._api.setFileIndex(i)
@property @property
@error_handling
def file_name(self): def file_name(self):
""" """
:obj:`str`: Base file name for writing images :obj:`str`: Base file name for writing images
@ -285,12 +265,10 @@ class Detector:
return self._api.getFileName() return self._api.getFileName()
@file_name.setter @file_name.setter
@error_handling
def file_name(self, fname): def file_name(self, fname):
self._api.setFileName(fname) self._api.setFileName(fname)
@property @property
@error_handling
def file_path(self): def file_path(self):
""" """
:obj:`str`: Path where images are written :obj:`str`: Path where images are written
@ -318,7 +296,6 @@ class Detector:
return fp return fp
@file_path.setter @file_path.setter
@error_handling
def file_path(self, path): def file_path(self, path):
if os.path.exists(path) is True: if os.path.exists(path) is True:
self._api.setFilePath(path) self._api.setFilePath(path)
@ -326,7 +303,6 @@ class Detector:
raise FileNotFoundError('File path does not exists') raise FileNotFoundError('File path does not exists')
@property @property
@error_handling
def file_write(self): def file_write(self):
""" """
:obj:`bool` If True write files to disk :obj:`bool` If True write files to disk
@ -334,13 +310,11 @@ class Detector:
return self._api.getFileWrite() return self._api.getFileWrite()
@file_write.setter @file_write.setter
@error_handling
def file_write(self, fwrite): def file_write(self, fwrite):
self._api.setFileWrite(fwrite) self._api.setFileWrite(fwrite)
@property @property
@error_handling
def file_overwrite(self): def file_overwrite(self):
""" """
:obj:`bool` If true overwrite files on disk :obj:`bool` If true overwrite files on disk
@ -348,12 +322,10 @@ class Detector:
return self._api.getFileOverWrite() return self._api.getFileOverWrite()
@file_overwrite.setter @file_overwrite.setter
@error_handling
def file_overwrite(self, value): def file_overwrite(self, value):
self._api.setFileOverWrite(value) self._api.setFileOverWrite(value)
@property @property
@error_handling
def file_padding(self): def file_padding(self):
""" """
Pad files in the receiver Pad files in the receiver
@ -362,12 +334,10 @@ class Detector:
return self._api.getReceiverPartialFramesPadding() return self._api.getReceiverPartialFramesPadding()
@file_padding.setter @file_padding.setter
@error_handling
def file_padding(self, value): def file_padding(self, value):
self._api.getReceiverPartialFramesPadding(value) self._api.getReceiverPartialFramesPadding(value)
@property @property
@error_handling
def firmware_version(self): def firmware_version(self):
""" """
:py:obj:`int` Firmware version of the detector :py:obj:`int` Firmware version of the detector
@ -422,7 +392,6 @@ class Detector:
@property @property
@error_handling
def frame_discard_policy(self): def frame_discard_policy(self):
""" """
Decides what the receiver does when packet loss occurs. Decides what the receiver does when packet loss occurs.
@ -433,7 +402,6 @@ class Detector:
return self._api.getReceiverFrameDiscardPolicy() return self._api.getReceiverFrameDiscardPolicy()
@frame_discard_policy.setter @frame_discard_policy.setter
@error_handling
def frame_discard_policy(self, policy): def frame_discard_policy(self, policy):
self._api.setReceiverFramesDiscardPolicy(policy) self._api.setReceiverFramesDiscardPolicy(policy)
@ -476,7 +444,6 @@ class Detector:
return self._flippeddatax return self._flippeddatax
@property @property
@error_handling
def high_voltage(self): def high_voltage(self):
""" """
High voltage applied to the sensor High voltage applied to the sensor
@ -484,7 +451,6 @@ class Detector:
return self._api.getDac('vhighvoltage', -1) return self._api.getDac('vhighvoltage', -1)
@high_voltage.setter @high_voltage.setter
@error_handling
def high_voltage(self, voltage): def high_voltage(self, voltage):
voltage = int(voltage) voltage = int(voltage)
if voltage < 0 or voltage > 200: if voltage < 0 or voltage > 200:
@ -493,7 +459,6 @@ class Detector:
@property @property
@error_handling
def hostname(self): def hostname(self):
""" """
:obj:`list` of :obj:`str`: hostnames of all connected detectors :obj:`list` of :obj:`str`: hostnames of all connected detectors
@ -514,7 +479,6 @@ class Detector:
@hostname.setter @hostname.setter
@error_handling
def hostname(self, hn): def hostname(self, hn):
if isinstance(hn, str): if isinstance(hn, str):
self._api.setHostname(hn) self._api.setHostname(hn)
@ -553,11 +517,10 @@ class Detector:
return size(*self._api.getImageSize()) return size(*self._api.getImageSize())
@image_size.setter @image_size.setter
@error_handling
def image_size(self, size): def image_size(self, size):
self._api.setImageSize(*size) self._api.setImageSize(*size)
@error_handling
def load_config(self, fname): def load_config(self, fname):
""" """
Load detector configuration from a configuration file Load detector configuration from a configuration file
@ -573,7 +536,7 @@ class Detector:
else: else:
raise FileNotFoundError('Cannot find configuration file') raise FileNotFoundError('Cannot find configuration file')
@error_handling
def load_parameters(self, fname): def load_parameters(self, fname):
""" """
Setup detector by executing commands in a parameters file Setup detector by executing commands in a parameters file
@ -596,7 +559,7 @@ class Detector:
else: else:
raise FileNotFoundError('Cannot find parameters file') raise FileNotFoundError('Cannot find parameters file')
@error_handling
def load_trimbits(self, fname, idet=-1): def load_trimbits(self, fname, idet=-1):
""" """
Load trimbit file or files. Either called with detector number or -1 Load trimbit file or files. Either called with detector number or -1
@ -628,7 +591,6 @@ class Detector:
@property @property
@error_handling
def lock(self): def lock(self):
"""Lock the detector to this client """Lock the detector to this client
@ -644,7 +606,6 @@ class Detector:
self._api.setServerLock(value) self._api.setServerLock(value)
@property @property
@error_handling
def lock_receiver(self): def lock_receiver(self):
"""Lock the receivers to this client """Lock the receivers to this client
@ -661,7 +622,6 @@ class Detector:
self._api.setReceiverLock(value) self._api.setReceiverLock(value)
@property @property
@error_handling
def module_geometry(self): def module_geometry(self):
""" """
:obj:`namedtuple` Geometry(horizontal=nx, vertical=ny) :obj:`namedtuple` Geometry(horizontal=nx, vertical=ny)
@ -687,7 +647,6 @@ class Detector:
return Geometry(horizontal=_t[0], vertical=_t[1]) return Geometry(horizontal=_t[0], vertical=_t[1])
@property @property
@error_handling
def n_frames(self): def n_frames(self):
""" """
:obj:`int` Number of frames per acquisition :obj:`int` Number of frames per acquisition
@ -695,7 +654,6 @@ class Detector:
return self._api.getNumberOfFrames() return self._api.getNumberOfFrames()
@n_frames.setter @n_frames.setter
@error_handling
def n_frames(self, n): def n_frames(self, n):
if n >= 1: if n >= 1:
self._api.setNumberOfFrames(n) self._api.setNumberOfFrames(n)
@ -704,23 +662,19 @@ class Detector:
' frames should be an integer greater than 0'.format(n)) ' frames should be an integer greater than 0'.format(n))
@property @property
@error_handling
def frames_per_file(self): def frames_per_file(self):
return self._api.getReceiverFramesPerFile() return self._api.getReceiverFramesPerFile()
@frames_per_file.setter @frames_per_file.setter
@error_handling
def frames_per_file(self, n): def frames_per_file(self, n):
self._api.setReceiverFramesPerFile(n) self._api.setReceiverFramesPerFile(n)
@property @property
@error_handling
def n_cycles(self): def n_cycles(self):
"""Number of cycles for the measurement (exp*n_frames)*n_cycles""" """Number of cycles for the measurement (exp*n_frames)*n_cycles"""
return self._api.getCycles() return self._api.getCycles()
@n_cycles.setter @n_cycles.setter
@error_handling
def n_cycles(self, n_cycles): def n_cycles(self, n_cycles):
if n_cycles > 0: if n_cycles > 0:
self._api.setCycles(n_cycles) self._api.setCycles(n_cycles)
@ -728,7 +682,6 @@ class Detector:
raise DetectorValueError('Number of cycles must be positive') raise DetectorValueError('Number of cycles must be positive')
@property @property
@error_handling
def n_measurements(self): def n_measurements(self):
""" """
Number of times to repeat the programmed measurement. Number of times to repeat the programmed measurement.
@ -756,7 +709,6 @@ class Detector:
return self._api.getNumberOfMeasurements() return self._api.getNumberOfMeasurements()
@n_measurements.setter @n_measurements.setter
@error_handling
def n_measurements(self, value): def n_measurements(self, value):
if value > 0: if value > 0:
self._api.setNumberOfMeasurements(value) self._api.setNumberOfMeasurements(value)
@ -764,7 +716,6 @@ class Detector:
raise DetectorValueError('Number of measurements must be positive') raise DetectorValueError('Number of measurements must be positive')
@property @property
@error_handling
def n_modules(self): def n_modules(self):
""" """
:obj:`int` Number of (half)modules in the detector :obj:`int` Number of (half)modules in the detector
@ -781,7 +732,6 @@ class Detector:
return self._api.getNumberOfDetectors() return self._api.getNumberOfDetectors()
@property @property
@error_handling
def online(self): def online(self):
"""Online flag for the detector """Online flag for the detector
@ -799,13 +749,11 @@ class Detector:
return self._api.getOnline() return self._api.getOnline()
@online.setter @online.setter
@error_handling
def online(self, value): def online(self, value):
self._api.setOnline(value) self._api.setOnline(value)
@property @property
@error_handling
def last_client_ip(self): def last_client_ip(self):
"""Returns the ip address of the last client """Returns the ip address of the last client
that accessed the detector that accessed the detector
@ -832,7 +780,6 @@ class Detector:
return self._api.getReceiverLastClientIP() return self._api.getReceiverLastClientIP()
@property @property
@error_handling
def receiver_online(self): def receiver_online(self):
""" """
Online flag for the receiver. Is set together with detector.online when creating the detector object Online flag for the receiver. Is set together with detector.online when creating the detector object
@ -851,12 +798,10 @@ class Detector:
return self._api.getReceiverOnline() return self._api.getReceiverOnline()
@receiver_online.setter @receiver_online.setter
@error_handling
def receiver_online(self, value): def receiver_online(self, value):
self._api.setReceiverOnline(value) self._api.setReceiverOnline(value)
@property @property
@error_handling
def receiver_version(self): def receiver_version(self):
""" """
:py:obj:`str` Receiver version as a string. [yearmonthday] :py:obj:`str` Receiver version as a string. [yearmonthday]
@ -901,7 +846,6 @@ class Detector:
self._api.resetFramesCaught() self._api.resetFramesCaught()
@property @property
@error_handling
def period(self): def period(self):
""" """
:obj:`double` Period between start of frames. Set to 0 for the detector :obj:`double` Period between start of frames. Set to 0 for the detector
@ -911,7 +855,6 @@ class Detector:
return _t / 1e9 return _t / 1e9
@period.setter @period.setter
@error_handling
def period(self, t): def period(self, t):
ns_time = int(t * 1e9) ns_time = int(t * 1e9)
if ns_time < 0: if ns_time < 0:
@ -919,7 +862,6 @@ class Detector:
self._api.setPeriod(ns_time) self._api.setPeriod(ns_time)
@property @property
@error_handling
def rate_correction(self): def rate_correction(self):
""" """
:obj:`list` of :obj:`double` Rate correction for all modules. :obj:`list` of :obj:`double` Rate correction for all modules.
@ -950,7 +892,6 @@ class Detector:
return self._api.getRateCorrection() return self._api.getRateCorrection()
@rate_correction.setter @rate_correction.setter
@error_handling
def rate_correction(self, tau_list): def rate_correction(self, tau_list):
if len(tau_list) != self.n_modules: if len(tau_list) != self.n_modules:
raise ValueError('List of tau needs the same length') raise ValueError('List of tau needs the same length')
@ -958,7 +899,6 @@ class Detector:
@property @property
@error_handling
def readout_clock(self): def readout_clock(self):
""" """
Speed of the readout clock relative to the full speed Speed of the readout clock relative to the full speed
@ -984,7 +924,6 @@ class Detector:
return self._speed_names[speed] return self._speed_names[speed]
@readout_clock.setter @readout_clock.setter
@error_handling
def readout_clock(self, value): def readout_clock(self, value):
speed = self._speed_int[value] speed = self._speed_int[value]
self._api.setReadoutClockSpeed(speed) self._api.setReadoutClockSpeed(speed)
@ -994,7 +933,6 @@ class Detector:
return self._api.getReceiverCurrentFrameIndex() return self._api.getReceiverCurrentFrameIndex()
@property @property
@error_handling
def rx_datastream(self): def rx_datastream(self):
""" """
Zmq datastream from receiver. :py:obj:`True` if enabled and :py:obj:`False` Zmq datastream from receiver. :py:obj:`True` if enabled and :py:obj:`False`
@ -1018,7 +956,6 @@ class Detector:
@property @property
@error_handling
def rx_hostname(self): def rx_hostname(self):
""" """
Receiver hostname Receiver hostname
@ -1028,13 +965,11 @@ class Detector:
@rx_hostname.setter @rx_hostname.setter
@error_handling
def rx_hostname(self, name): def rx_hostname(self, name):
self._api.setReceiverHostname(name) self._api.setReceiverHostname(name)
@property @property
@error_handling
def rx_udpip(self): def rx_udpip(self):
""" """
Receiver UDP ip Receiver UDP ip
@ -1064,12 +999,10 @@ class Detector:
self._api.setReceiverUDPMAC(mac, -1) self._api.setReceiverUDPMAC(mac, -1)
@property @property
@error_handling
def rx_tcpport(self): def rx_tcpport(self):
return self._api.getReceiverPort() return self._api.getReceiverPort()
@rx_tcpport.setter @rx_tcpport.setter
@error_handling
def rx_tcpport(self, ports): def rx_tcpport(self, ports):
if len(ports) != len(self): if len(ports) != len(self):
raise ValueError('Number of ports: {} not equal to number of ' raise ValueError('Number of ports: {} not equal to number of '
@ -1079,7 +1012,6 @@ class Detector:
self._api.setReceiverPort(i, p) self._api.setReceiverPort(i, p)
@property @property
@error_handling
def rx_zmqip(self): def rx_zmqip(self):
""" """
ip where the receiver streams data ip where the receiver streams data
@ -1093,8 +1025,7 @@ class Detector:
@property @property
@error_handling def detectormac(self):
def detector_mac(self):
""" """
Read detector mac address Read detector mac address
""" """
@ -1102,16 +1033,18 @@ class Detector:
return element_if_equal(mac) return element_if_equal(mac)
@property @property
@error_handling def detectorip(self):
def detector_ip(self):
""" """
Read detector ip address Read detector ip address
""" """
ip = self._api.getNetworkParameter('detectorip') return self._api.getDetectorIp(-1)
return element_if_equal(ip)
# @detectorip.setter
# def detectorip(self, ip):
@property @property
@error_handling
def client_zmqip(self): def client_zmqip(self):
""" """
Ip address where the client listens to zmq stream Ip address where the client listens to zmq stream
@ -1120,14 +1053,13 @@ class Detector:
return element_if_equal(ip) return element_if_equal(ip)
@client_zmqip.setter @client_zmqip.setter
@error_handling
def client_zmqip(self, ip): def client_zmqip(self, ip):
self._api.setNetworkParameter('client_zmqip', ip, -1) self._api.setNetworkParameter('client_zmqip', ip, -1)
@property @property
@error_handling
def rx_fifodepth(self): def rx_fifodepth(self):
""" """
Fifo depth of receiver in number of frames Fifo depth of receiver in number of frames
@ -1135,13 +1067,11 @@ class Detector:
return self._api.getReceiverFifoDepth() return self._api.getReceiverFifoDepth()
@rx_fifodepth.setter @rx_fifodepth.setter
@error_handling
def rx_fifodepth(self, n_frames): def rx_fifodepth(self, n_frames):
self._api.setReceiverFifoDepth(n_frames) self._api.setReceiverFifoDepth(n_frames)
@property @property
@error_handling
def rx_udpsocksize(self): def rx_udpsocksize(self):
""" """
UDP buffer size UDP buffer size
@ -1150,7 +1080,6 @@ class Detector:
return element_if_equal(buffer_size) return element_if_equal(buffer_size)
@property @property
@error_handling
def rx_jsonaddheader(self): def rx_jsonaddheader(self):
""" """
UDP buffer size UDP buffer size
@ -1159,20 +1088,17 @@ class Detector:
return element_if_equal(header) return element_if_equal(header)
@rx_jsonaddheader.setter @rx_jsonaddheader.setter
@error_handling
def rx_jsonaddheader(self, header): def rx_jsonaddheader(self, header):
self._api.setNetworkParameter('rx_jsonaddheader', header, -1) self._api.setNetworkParameter('rx_jsonaddheader', header, -1)
@rx_udpsocksize.setter @rx_udpsocksize.setter
@error_handling
def rx_udpsocksize(self, buffer_size): def rx_udpsocksize(self, buffer_size):
self._api.setNetworkParameter('rx_udpsocksize', str(buffer_size), -1) self._api.setNetworkParameter('rx_udpsocksize', str(buffer_size), -1)
@property @property
@error_handling
def rx_realudpsocksize(self): def rx_realudpsocksize(self):
""" """
UDP buffer size UDP buffer size
@ -1182,7 +1108,6 @@ class Detector:
@property @property
@error_handling
def rx_zmqport(self): def rx_zmqport(self):
""" """
Return the receiver zmq ports. Return the receiver zmq ports.
@ -1200,7 +1125,6 @@ class Detector:
return [int(_p) for _p in _s] return [int(_p) for _p in _s]
@rx_zmqport.setter @rx_zmqport.setter
@error_handling
def rx_zmqport(self, port): def rx_zmqport(self, port):
if isinstance(port, Iterable): if isinstance(port, Iterable):
for i, p in enumerate(port): for i, p in enumerate(port):
@ -1219,7 +1143,6 @@ class Detector:
return self._api.getUserDetails() return self._api.getUserDetails()
@property @property
@error_handling
def server_version(self): def server_version(self):
""" """
:py:obj:`int` On-board server version of the detector :py:obj:`int` On-board server version of the detector
@ -1227,7 +1150,6 @@ class Detector:
return hex(self._api.getServerVersion()) return hex(self._api.getServerVersion())
@property @property
@error_handling
def settings(self): def settings(self):
""" """
Detector settings used to control for example calibration or gain Detector settings used to control for example calibration or gain
@ -1243,7 +1165,6 @@ class Detector:
return self._api.getSettings() return self._api.getSettings()
@settings.setter @settings.setter
@error_handling
def settings(self, s): def settings(self, s):
if s in self._settings: if s in self._settings:
self._api.setSettings(s) self._api.setSettings(s)
@ -1253,7 +1174,6 @@ class Detector:
@property @property
@error_handling
def settings_path(self): def settings_path(self):
""" """
The path where the slsDetectorSoftware looks for settings/trimbit files The path where the slsDetectorSoftware looks for settings/trimbit files
@ -1261,7 +1181,6 @@ class Detector:
return self._api.getSettingsDir() return self._api.getSettingsDir()
@settings_path.setter @settings_path.setter
@error_handling
def settings_path(self, path): def settings_path(self, path):
if os.path.isdir(path): if os.path.isdir(path):
self._api.setSettingsDir(path) self._api.setSettingsDir(path)
@ -1269,7 +1188,6 @@ class Detector:
raise FileNotFoundError('Settings path does not exist') raise FileNotFoundError('Settings path does not exist')
@property @property
@error_handling
def status(self): def status(self):
""" """
:py:obj:`str` Status of the detector: idle, running, :py:obj:`str` Status of the detector: idle, running,
@ -1324,7 +1242,6 @@ class Detector:
self._api.setThreadedProcessing(value) self._api.setThreadedProcessing(value)
@property @property
@error_handling
def threshold(self): def threshold(self):
""" """
Detector threshold in eV Detector threshold in eV
@ -1332,7 +1249,6 @@ class Detector:
return self._api.getThresholdEnergy() return self._api.getThresholdEnergy()
@threshold.setter @threshold.setter
@error_handling
def threshold(self, eV): def threshold(self, eV):
self._api.setThresholdEnergy(eV) self._api.setThresholdEnergy(eV)
@ -1426,7 +1342,7 @@ class Detector:
return [] return []
return [int(_p)+i for _p in _s for i in range(2)] return [int(_p)+i for _p in _s for i in range(2)]
@error_handling
def _provoke_error(self): def _provoke_error(self):
self._api.setErrorMask(1) self._api.setErrorMask(1)
@ -1438,6 +1354,7 @@ class Detector:
""" """
self._api.configureNetworkParameters() self._api.configureNetworkParameters()
def free_shared_memory(multi_id=0): def free_shared_memory(multi_id=0):
""" """
Function to free the shared memory but do not initialize with new Function to free the shared memory but do not initialize with new

View File

@ -4,6 +4,7 @@ import numpy as np
class DetectorProperty: class DetectorProperty:
""" """
Base class for a detector property that should be accessed by name and index Base class for a detector property that should be accessed by name and index
TODO! Calls are not in parallel and exposes object that can be passes around
""" """
def __init__(self, get_func, set_func, nmod_func, name): def __init__(self, get_func, set_func, nmod_func, name):
self.get = get_func self.get = get_func

View File

@ -5,7 +5,12 @@ class ExperimentalDetector(multiDetectorApi):
def __init__(self): def __init__(self):
super().__init__(0) super().__init__(0)
# @rx_udpip.setter
# def rx_udpip(self, ip): @property
# self._setReceiverUDPIP(ip, -1) def rx_udpip(self):
return self._getReceiverUDPIP(-1)
@rx_udpip.setter
def rx_udpip(self, ip):
self._setReceiverUDPIP(ip, -1)

View File

@ -130,23 +130,6 @@ class Detector {
return det.checkOnline(); return det.checkOnline();
} }
void clearErrorMask() {
det.clearAllErrorMask();
}
int64_t getErrorMask() {
return det.getErrorMask();
}
void setErrorMask(const int64_t i) {
det.setErrorMask(i);
}
std::string getErrorMessage() {
//tmp would hold the number of critical errors, is and should this be used?
int tmp = 0;
return det.getErrorMessage(tmp);
}
bool getReceiverOnline() { bool getReceiverOnline() {
return det.setReceiverOnline(); return det.setReceiverOnline();
} }
@ -253,8 +236,8 @@ class Detector {
int64_t getClientVersion() { return det.getId(slsDetectorDefs::THIS_SOFTWARE_VERSION); } int64_t getClientVersion() { return det.getId(slsDetectorDefs::THIS_SOFTWARE_VERSION); }
int64_t getReceiverVersion() { return det.getId(slsDetectorDefs::RECEIVER_VERSION); } int64_t getReceiverVersion() { return det.getId(slsDetectorDefs::RECEIVER_VERSION); }
int getDetectorNumber(int i) { std::vector<int64_t> getDetectorNumber() {
return det.getId(slsDetectorDefs::DETECTOR_SERIAL_NUMBER, i); return det.getDetectorNumber();
} }
int getReadoutClockSpeed() { int getReadoutClockSpeed() {

View File

@ -239,12 +239,6 @@ PYBIND11_MODULE(_sls_detector, m)
.def("getReceiverCurrentFrameIndex", &Detector::getReceiverCurrentFrameIndex) .def("getReceiverCurrentFrameIndex", &Detector::getReceiverCurrentFrameIndex)
.def("getGapPixels", &Detector::getGapPixels) .def("getGapPixels", &Detector::getGapPixels)
.def("setGapPixels", &Detector::setGapPixels) .def("setGapPixels", &Detector::setGapPixels)
.def("clearErrorMask", &Detector::clearErrorMask)
.def("getErrorMask", &Detector::getErrorMask)
.def("setErrorMask", &Detector::setErrorMask)
.def("getErrorMessage", &Detector::getErrorMessage)
.def("getFlippedDataX", &Detector::getFlippedDataX) .def("getFlippedDataX", &Detector::getFlippedDataX)
.def("getFlippedDataY", &Detector::getFlippedDataY) .def("getFlippedDataY", &Detector::getFlippedDataY)
.def("setFlippedDataX", &Detector::setFlippedDataX) .def("setFlippedDataX", &Detector::setFlippedDataX)
@ -284,9 +278,10 @@ py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
py::cpp_function(&multiSlsDetector::setAcquiringFlag)) py::cpp_function(&multiSlsDetector::setAcquiringFlag))
.def_property_readonly("rx_tcpport", .def_property_readonly("rx_tcpport",
py::cpp_function(&multiSlsDetector::getReceiverPort)) py::cpp_function(&multiSlsDetector::getReceiverPort))
// .def_property_readonly("rx_udpip", .def_property_readonly("detectornumber",
// py::cpp_function(&multiSlsDetector::getReceiverUDPIP), py::arg("det_id")=1) py::cpp_function(&multiSlsDetector::getDetectorNumber))
// .def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP) .def("_getReceiverUDPIP", &multiSlsDetector::getReceiverUDPIP)
.def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP)
; ;

View File

@ -83,7 +83,6 @@ multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...), typename NonD
return result; return result;
} }
//Const qualified version
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> std::vector<RT>
multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...) const, typename NonDeduced<CT>::type... Args) const { multiSlsDetector::parallelCall(RT (slsDetector::*somefunc)(CT...) const, typename NonDeduced<CT>::type... Args) const {
@ -131,100 +130,8 @@ int multiSlsDetector::decodeNChannel(int offsetX, int offsetY, int &channelX,
return -1; return -1;
} }
std::string multiSlsDetector::getErrorMessage(int &critical, int detPos) { void multiSlsDetector::setAcquiringFlag(bool flag) {
int64_t multiMask = 0, slsMask = 0; multi_shm()->acquiringFlag = flag;
std::string retval = "";
critical = 0;
size_t posmin = 0, posmax = detectors.size();
// single
if (detPos >= 0) {
slsMask = detectors[detPos]->getErrorMask();
posmin = (size_t)detPos;
posmax = posmin + 1;
}
multiMask = getErrorMask();
if (multiMask || slsMask) {
if (multiMask & MULTI_DETECTORS_NOT_ADDED) {
retval.append("Detectors not added:\n" +
std::string(getNotAddedList()) + std::string("\n"));
critical = 1;
}
if (multiMask & MULTI_HAVE_DIFFERENT_VALUES) {
retval.append(
"A previous multi detector command gave different values\n"
"Please check the console\n");
critical = 0;
}
if (multiMask & MULTI_CONFIG_FILE_ERROR) {
retval.append("Could not load Config File\n");
critical = 1;
}
if (multiMask & MULTI_POS_EXCEEDS_LIST) {
retval.append("Position exceeds multi detector list\n");
critical = 0;
}
if (multiMask & MUST_BE_MULTI_CMD) {
retval.append("Must be a multi detector level command.\n");
critical = 0;
}
if (multiMask & MULTI_OTHER_ERROR) {
retval.append("Some error occured from multi level.\n");
critical =
0; // FIXME: with exceptions/appropriate errors wherever used
}
for (size_t idet = posmin; idet < posmax; ++idet) {
// if the detector has error
if ((multiMask & (1 << idet)) || (detPos >= 0)) {
// append detector id
retval.append("Detector " + std::to_string(idet) +
std::string(":\n"));
// get sls det error mask
slsMask = detectors[idet]->getErrorMask();
// get the error critical level
if ((slsMask > 0xFFFFFFFF) | critical) {
critical = 1;
}
// append error message
retval.append(errorDefs::getErrorMessage(slsMask));
}
}
}
return retval;
}
int64_t multiSlsDetector::clearAllErrorMask(int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->clearErrorMask();
}
// multi
clearErrorMask();
clearNotAddedList();
for (auto &d : detectors) {
d->clearErrorMask();
}
return getErrorMask();
}
void multiSlsDetector::setErrorMaskFromAllDetectors() {
for (size_t idet = 0; idet < detectors.size(); ++idet) {
if (detectors[idet]->getErrorMask()) {
setErrorMask(getErrorMask() | (1 << idet));
}
}
}
void multiSlsDetector::setAcquiringFlag(bool b) {
multi_shm()->acquiringFlag = b;
} }
bool multiSlsDetector::getAcquiringFlag() const { bool multiSlsDetector::getAcquiringFlag() const {
@ -269,6 +176,10 @@ int64_t multiSlsDetector::getId(idMode mode, int detPos) {
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
std::vector<int64_t> multiSlsDetector::getDetectorNumber(){
return parallelCall(&slsDetector::getId, slsDetectorDefs::DETECTOR_SERIAL_NUMBER);
}
void multiSlsDetector::freeSharedMemory(int multiId, int detPos) { void multiSlsDetector::freeSharedMemory(int multiId, int detPos) {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
@ -301,7 +212,6 @@ void multiSlsDetector::freeSharedMemory(int detPos) {
// multi // multi
zmqSocket.clear(); zmqSocket.clear();
clearAllErrorMask();
for (auto &d : detectors) { for (auto &d : detectors) {
d->freeSharedMemory(); d->freeSharedMemory();
} }
@ -444,7 +354,7 @@ void multiSlsDetector::setHostname(const char *name, int detPos) {
addMultipleDetectors(name); addMultipleDetectors(name);
} }
std::string multiSlsDetector::getHostname(int detPos) { std::string multiSlsDetector::getHostname(int detPos) const {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->getHostname(); return detectors[detPos]->getHostname();
@ -781,45 +691,33 @@ std::vector<int> multiSlsDetector::getReceiverPort() const {
} }
int multiSlsDetector::lockServer(int p, int detPos) { int multiSlsDetector::lockServer(int p, int detPos) {
// single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->lockServer(p); return detectors[detPos]->lockServer(p);
} }
// multi
auto r = parallelCall(&slsDetector::lockServer, p); auto r = parallelCall(&slsDetector::lockServer, p);
return sls::minusOneIfDifferent(r); return sls::minusOneIfDifferent(r);
} }
std::string multiSlsDetector::getLastClientIP(int detPos) { std::string multiSlsDetector::getLastClientIP(int detPos) {
// single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->getLastClientIP(); return detectors[detPos]->getLastClientIP();
} }
// multi
auto r = parallelCall(&slsDetector::getLastClientIP); auto r = parallelCall(&slsDetector::getLastClientIP);
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
int multiSlsDetector::exitServer(int detPos) { int multiSlsDetector::exitServer(int detPos) {
// single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->exitServer(); return detectors[detPos]->exitServer();
} }
// multi
auto r = parallelCall(&slsDetector::exitServer); auto r = parallelCall(&slsDetector::exitServer);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
int multiSlsDetector::execCommand(const std::string &cmd, int detPos) { int multiSlsDetector::execCommand(const std::string &cmd, int detPos) {
// single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->execCommand(cmd); return detectors[detPos]->execCommand(cmd);
} }
// multi
auto r = parallelCall(&slsDetector::execCommand, cmd); auto r = parallelCall(&slsDetector::execCommand, cmd);
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL; return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
} }
@ -846,14 +744,6 @@ int multiSlsDetector::readConfigurationFile(const std::string &fname) {
input_file.close(); input_file.close();
} else { } else {
FILE_LOG(logERROR) << "Could not openconfiguration file " << fname << " for reading"; FILE_LOG(logERROR) << "Could not openconfiguration file " << fname << " for reading";
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);
return FAIL;
}
if (getErrorMask()) {
int c;
FILE_LOG(logERROR) << "----------------\n Error Messages\n----------------";
FILE_LOG(logERROR) << getErrorMessage(c);
return FAIL; return FAIL;
} }
return OK; return OK;
@ -1624,7 +1514,7 @@ std::string multiSlsDetector::setDetectorIP(const std::string &detectorIP, int d
return sls::concatenateIfDifferent(r); return sls::concatenateIfDifferent(r);
} }
std::string multiSlsDetector::getDetectorIP(int detPos) { std::string multiSlsDetector::getDetectorIP(int detPos) const {
// single // single
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->getDetectorIP(); return detectors[detPos]->getDetectorIP();

View File

@ -120,7 +120,9 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* one * one
* @param update true to update last user pid, date etc * @param update true to update last user pid, date etc
*/ */
explicit multiSlsDetector(int multi_id = 0, bool verify = true, bool update = true); explicit multiSlsDetector(int multi_id = 0,
bool verify = true,
bool update = true);
/** /**
* Destructor * Destructor
@ -134,11 +136,11 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* one * one
* @param update true to update last user pid, date etc * @param update true to update last user pid, date etc
*/ */
void setupMultiDetector(bool verify = true, bool update = true); void setupMultiDetector(bool verify = true,
bool update = true);
/** /**
* Loop through the detectors serially * Loop through the detectors serially and return the result as a vector
* and return a vector of results
*/ */
template <class CT> template <class CT>
struct NonDeduced { using type = CT; }; struct NonDeduced { using type = CT; };
@ -146,20 +148,25 @@ class multiSlsDetector : public virtual slsDetectorDefs,
std::vector<RT> serialCall(RT (slsDetector::*somefunc)(CT...), std::vector<RT> serialCall(RT (slsDetector::*somefunc)(CT...),
typename NonDeduced<CT>::type... Args); typename NonDeduced<CT>::type... Args);
//Const qualified version should be preferred for calling get methods /**
* Loop through the detectors serially and return the result as a vector
* Const qualified version
*/
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> serialCall(RT (slsDetector::*somefunc)(CT...) const, std::vector<RT> serialCall(RT (slsDetector::*somefunc)(CT...) const,
typename NonDeduced<CT>::type... Args) const; typename NonDeduced<CT>::type... Args) const;
/** /**
* Loop through the detectors in parallel threads * Loop through the detectors in parallel and return the result as a vector
* and return a vector of results
*/ */
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...), std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...),
typename NonDeduced<CT>::type... Args); typename NonDeduced<CT>::type... Args);
//Const qualified version should be preferred for calling get methods /**
* Loop through the detectors in parallel and return the result as a vector
* Const qualified version
*/
template <typename RT, typename... CT> template <typename RT, typename... CT>
std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...) const, std::vector<RT> parallelCall(RT (slsDetector::*somefunc)(CT...) const,
typename NonDeduced<CT>::type... Args) const; typename NonDeduced<CT>::type... Args) const;
@ -175,32 +182,11 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/ */
int decodeNChannel(int offsetX, int offsetY, int &channelX, int &channelY); int decodeNChannel(int offsetX, int offsetY, int &channelX, int &channelY);
/**
* Checks error mask and returns error message and its severity if it exists
* @param critical is 1 if any of the messages is critical
* @param detPos -1 for all detectors in list or specific detector position
* @returns error message else an empty std::string
*/
std::string getErrorMessage(int &critical, int detPos = -1);
/**
* Clears error mask of both multi and sls
* @param detPos -1 for all detectors in list or specific detector position
* @returns error mask
*/
int64_t clearAllErrorMask(int detPos = -1);
/**
* Set Error Mask from all detectors
* if each had errors in the mask already
*/
void setErrorMaskFromAllDetectors();
/** /**
* Set acquiring flag in shared memory * Set acquiring flag in shared memory
* @param b acquiring flag * @param b acquiring flag
*/ */
void setAcquiringFlag(bool b = false); void setAcquiringFlag(bool flag);
/** /**
* Get acquiring flag from shared memory * Get acquiring flag from shared memory
@ -239,6 +225,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
*/ */
int64_t getId(idMode mode, int detPos = -1); int64_t getId(idMode mode, int detPos = -1);
std::vector<int64_t> getDetectorNumber();
/** /**
* Free shared memory from the command line * Free shared memory from the command line
* avoiding creating the constructor classes and mapping * avoiding creating the constructor classes and mapping
@ -277,7 +264,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* @returns concatenated hostnames of all detectors or hostname of specific * @returns concatenated hostnames of all detectors or hostname of specific
* one * one
*/ */
std::string getHostname(int detPos = -1); std::string getHostname(int detPos = -1) const;
/** /**
* Appends detectors to the end of the list in shared memory * Appends detectors to the end of the list in shared memory
@ -890,7 +877,7 @@ class multiSlsDetector : public virtual slsDetectorDefs,
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns the detector IP address * @returns the detector IP address
*/ */
std::string getDetectorIP(int detPos = -1); std::string getDetectorIP(int detPos = -1) const;
/** /**
* Validates and sets the receiver. * Validates and sets the receiver.

View File

@ -166,9 +166,6 @@ int64_t slsDetector::getId(idMode mode) {
int fnum = F_GET_RECEIVER_ID; int fnum = F_GET_RECEIVER_ID;
auto receiver = sls::ClientSocket(true, detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort); auto receiver = sls::ClientSocket(true, detector_shm()->receiver_hostname, detector_shm()->receiverTCPPort);
ret = receiver.sendCommandThenRead(fnum, nullptr, 0, &retval, sizeof(retval)); ret = receiver.sendCommandThenRead(fnum, nullptr, 0, &retval, sizeof(retval));
if (ret == FAIL) {
setErrorMask((getErrorMask()) | (OTHER_ERROR_CODE));
}
} }
if (ret == FORCE_UPDATE) { if (ret == FORCE_UPDATE) {
ret = updateReceiver(); ret = updateReceiver();
@ -180,13 +177,7 @@ int64_t slsDetector::getId(idMode mode) {
if (detector_shm()->onlineFlag == ONLINE_FLAG) { if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = sls::ClientSocket(false, detector_shm()->hostname, detector_shm()->controlPort); auto client = sls::ClientSocket(false, detector_shm()->hostname, detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
// handle ret
if (ret == FAIL) {
setErrorMask((getErrorMask()) | (OTHER_ERROR_CODE));
} }
}
if (ret != FAIL) { if (ret != FAIL) {
FILE_LOG(logDEBUG1) << "Id (" << mode << "): 0x" << std::hex << retval << std::dec; FILE_LOG(logDEBUG1) << "Id (" << mode << "): 0x" << std::hex << retval << std::dec;
} }
@ -215,7 +206,7 @@ void slsDetector::setHostname(const std::string &hostname) {
updateDetector(); updateDetector();
} }
std::string slsDetector::getHostname() { std::string slsDetector::getHostname() const {
return detector_shm()->hostname; return detector_shm()->hostname;
} }
@ -920,8 +911,8 @@ int slsDetector::exitServer() {
int slsDetector::execCommand(const std::string &cmd) { int slsDetector::execCommand(const std::string &cmd) {
int fnum = F_EXEC_COMMAND; int fnum = F_EXEC_COMMAND;
int ret = FAIL; int ret = FAIL;
char arg[MAX_STR_LENGTH] = {0}; char arg[MAX_STR_LENGTH] = {};
char retval[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {};
sls::strcpy_safe(arg, cmd.c_str()); sls::strcpy_safe(arg, cmd.c_str());
FILE_LOG(logDEBUG1) << "Sending command to detector " << arg; FILE_LOG(logDEBUG1) << "Sending command to detector " << arg;
@ -942,7 +933,6 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
int n = 0, i32 = 0; int n = 0, i32 = 0;
int64_t i64 = 0; int64_t i64 = 0;
char lastClientIP[INET_ADDRSTRLEN] = {0}; char lastClientIP[INET_ADDRSTRLEN] = {0};
// auto client = sls::ClientSocket(false, detector_shm()->hostname, detector_shm()->controlPort);
n += client.receiveData(lastClientIP, sizeof(lastClientIP)); n += client.receiveData(lastClientIP, sizeof(lastClientIP));
FILE_LOG(logDEBUG1) << "Updating detector last modified by " << lastClientIP; FILE_LOG(logDEBUG1) << "Updating detector last modified by " << lastClientIP;
@ -2341,7 +2331,7 @@ std::string slsDetector::setDetectorIP(const std::string &detectorIP) {
return std::string(detector_shm()->detectorIP); return std::string(detector_shm()->detectorIP);
} }
std::string slsDetector::getDetectorIP() { std::string slsDetector::getDetectorIP() const {
return std::string(detector_shm()->detectorIP); return std::string(detector_shm()->detectorIP);
} }

View File

@ -323,7 +323,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* Gets the hostname of detector * Gets the hostname of detector
* @returns hostname * @returns hostname
*/ */
std::string getHostname(); std::string getHostname() const;
/** /**
* Could not connect to receiver, log error * Could not connect to receiver, log error
@ -810,7 +810,7 @@ class slsDetector : public virtual slsDetectorDefs, public virtual errorDefs {
* Returns the detector IP address\sa sharedSlsDetector * Returns the detector IP address\sa sharedSlsDetector
* @returns the detector IP address * @returns the detector IP address
*/ */
std::string getDetectorIP(); std::string getDetectorIP() const;
/** /**
* Validates and sets the receiver. * Validates and sets the receiver.