diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index dafa661b9..3e707c630 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -2431,9 +2431,9 @@ class Detector(CppDetectorApi): @property def udp_datastream(self): """ - [Eiger] Enable or disable UDP data streaming from the left and/or right detector ports in 10 GbE mode. Options: LEFT, RIGHT. Both ports are enabled by default. + [Eiger] Enable or disable UDP data streaming from the left and/or right detector ports in 10 GbE mode. Both ports are enabled by default. Options: LEFT, RIGHT. - [Jungfrau][Moench] Enable or disable UDP data streaming from the top and/or bottom receiver interfaces. This option is available only when numinterfaces is set to 2. Options: TOP, BOTTOM. Both interfaces are enabled by default. + [Jungfrau][Moench] Enable or disable UDP data streaming from the top and/or bottom receiver interfaces. This option is available only when numinterfaces is set to 2. Both ports are enabled by default. Options: TOP, BOTTOM. Enum: portPosition """ diff --git a/python/slsdet/utils.py b/python/slsdet/utils.py index 4039119d4..a853d8370 100755 --- a/python/slsdet/utils.py +++ b/python/slsdet/utils.py @@ -60,7 +60,7 @@ def to_geo(value): def all_equal(mylist): """If all elements are equal return true otherwise false""" - return all(x == mylist[0] for x in mylist) + return all(x == list(mylist[0]) for x in mylist) def element_if_equal(mylist): diff --git a/python/tests/test_det_api.py b/python/tests/test_det_api.py index 232bda74c..cdda5b02c 100644 --- a/python/tests/test_det_api.py +++ b/python/tests/test_det_api.py @@ -11,9 +11,8 @@ from utils_for_test import ( LogLevel, ) from slsdet import Detector - from slsdet._slsdet import slsDetectorDefs - +from slsdet.utils import all_equal, element_if_equal detectorType = slsDetectorDefs.detectorType @@ -931,61 +930,72 @@ def test_udp_datastream(session_simulator, request): from slsdet import portPosition if det_type in ['eiger']: - prev = d.udp_datastream - assert all(isinstance(v, bool) for v in prev.values()) + ports = [portPosition.LEFT, portPosition.RIGHT] + prev = [d.getUDPDataStream(i) for i in ports] + # ensure all equal for each value in prev + assert all_equal(prev) + prev_val = [element_if_equal(v) for v in prev] + #list with pytest.raises(Exception) as exc_info: - d.udp_datastream = (portPosition.LEFT, [True, False]) #list - - with pytest.raises(Exception) as exc_info: - d.udp_datastream = (portPosition.TOP, True) # invalid port position + d.udp_datastream = (ports[0], [True, False]) + # invalid port position with pytest.raises(Exception) as exc_info: - d.udp_datastream = (portPosition.BOTTOM, True) # invalid port position - + d.udp_datastream = (portPosition.TOP, True) + with pytest.raises(Exception) as exc_info: - d.udp_datastream = True # without port position + d.udp_datastream = (portPosition.BOTTOM, True) - d.udp_datastream = (portPosition.LEFT, False) - assert d.udp_datastream[portPosition.LEFT] is False - d.udp_datastream = (portPosition.RIGHT, False) - assert d.udp_datastream[portPosition.RIGHT] is False - d.udp_datastream = (portPosition.LEFT, True) - assert d.udp_datastream[portPosition.LEFT] is True - d.udp_datastream = (portPosition.RIGHT, True) - assert d.udp_datastream[portPosition.RIGHT] is True + # without port position + with pytest.raises(Exception) as exc_info: + d.udp_datastream = True - d.setUDPDataStream(portPosition.LEFT, prev[portPosition.LEFT]) - d.setUDPDataStream(portPosition.RIGHT, prev[portPosition.RIGHT]) + d.udp_datastream = (ports[0], False) + assert d.udp_datastream[ports[0]] is False + d.udp_datastream = (ports[1], False) + assert d.udp_datastream[ports[1]] is False + d.udp_datastream = (ports[0], True) + assert d.udp_datastream[ports[0]] is True + d.udp_datastream = (ports[1], True) + assert d.udp_datastream[ports[1]] is True + + d.setUDPDataStream(ports[0], element_if_equal(prev[0])) + d.setUDPDataStream(ports[1], element_if_equal(prev[1])) elif det_type in ['jungfrau', 'moench'] and num_interfaces == 2: - prev = d.udp_datastream - assert all(isinstance(v, bool) for v in prev.values()) + ports = [portPosition.TOP, portPosition.BOTTOM] + prev = [d.getUDPDataStream(i) for i in ports] + # ensure all equal for each value in prev + assert all_equal(prev) + prev_val = [element_if_equal(v) for v in prev] - + #list with pytest.raises(Exception) as exc_info: - d.udp_datastream = (portPosition.TOP, [True, False]) #list - - with pytest.raises(Exception) as exc_info: - d.udp_datastream = (portPosition.LEFT, True) # invalid port position + d.udp_datastream = (ports[0], [True, False]) + # invalid port position with pytest.raises(Exception) as exc_info: - d.udp_datastream = (portPosition.RIGHT, True) # invalid port position - + d.udp_datastream = (portPosition.LEFT, True) + with pytest.raises(Exception) as exc_info: - d.udp_datastream = True # without port position + d.udp_datastream = (portPosition.RIGHT, True) - d.udp_datastream = (portPosition.TOP, False) - assert d.udp_datastream[portPosition.TOP] is False - d.udp_datastream = (portPosition.BOTTOM, False) - assert d.udp_datastream[portPosition.BOTTOM] is False - d.udp_datastream = (portPosition.TOP, True) - assert d.udp_datastream[portPosition.TOP] is True - d.udp_datastream = (portPosition.BOTTOM, True) - assert d.udp_datastream[portPosition.BOTTOM] is True + # without port position + with pytest.raises(Exception) as exc_info: + d.udp_datastream = True - d.setUDPDataStream(portPosition.TOP, prev[portPosition.TOP]) - d.setUDPDataStream(portPosition.BOTTOM, prev[portPosition.BOTTOM]) + d.udp_datastream = (ports[0], False) + assert d.udp_datastream[ports[0]] is False + d.udp_datastream = (ports[1], False) + assert d.udp_datastream[ports[1]] is False + d.udp_datastream = (ports[0], True) + assert d.udp_datastream[ports[0]] is True + d.udp_datastream = (ports[1], True) + assert d.udp_datastream[ports[1]] is True + + d.setUDPDataStream(ports[0], element_if_equal(prev[0])) + d.setUDPDataStream(ports[1], element_if_equal(prev[1])) else: with pytest.raises(Exception) as exc_info: diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 20e00423a..619afd1a8 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1644,7 +1644,7 @@ void DetectorImpl::verifyUniqueHost( } } -void DetectorImpl::assertTwoUDPInterfaces(const std::string &cmd) const { +void DetectorImpl::assertTwoUDPDataInterfaces(const std::string &cmd) const { // assert globally auto numInterfaces = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) @@ -1658,19 +1658,20 @@ void DetectorImpl::assertTwoUDPInterfaces(const std::string &cmd) const { Result DetectorImpl::getUDPDataStream(const defs::portPosition port, Positions pos) const { - assertTwoUDPInterfaces("get enable/disable UDP ports"); + assertTwoUDPDataInterfaces("get enable/disable UDP ports"); return Parallel(&Module::getUDPDataStream, pos, port); } void DetectorImpl::setUDPDataStream(const defs::portPosition port, const bool enable, Positions pos) { - assertTwoUDPInterfaces("set enable/disable UDP ports"); + assertTwoUDPDataInterfaces("set enable/disable UDP ports"); Parallel(&Module::setUDPDataStream, pos, port, enable); updateRxUDPDatastreamMetadata(); } void DetectorImpl::updateRxUDPDatastreamMetadata() { - assertTwoUDPInterfaces("update Disbaled UDP ports metadata in receiver"); + assertTwoUDPDataInterfaces( + "update Disbaled UDP ports metadata in receiver"); std::vector disable; auto portList = getPortPositionList(); @@ -1698,7 +1699,7 @@ void DetectorImpl::updateRxUDPDatastreamMetadata() { } std::vector DetectorImpl::getRxDisabledUDPPortIndices() const { - assertTwoUDPInterfaces("get Disbaled UDP ports metadata from receiver"); + assertTwoUDPDataInterfaces("get Disbaled UDP ports metadata from receiver"); return modules[0]->getRxUDPPortDisableMetadata(); } diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index 8ea915200..aad1b6b71 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -309,7 +309,7 @@ class DetectorImpl : public virtual slsDetectorDefs { std::vector> verifyUniqueRxHost(const std::vector &names) const; - void assertTwoUDPInterfaces(const std::string &cmd) const; + void assertTwoUDPDataInterfaces(const std::string &cmd) const; Result getUDPDataStream(const defs::portPosition port, Positions pos) const; void setUDPDataStream(const defs::portPosition port, const bool enable,