From 8a508781d9bbcecc6cb0fa3c7374b55d56464b76 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 3 Nov 2026 13:04:57 +0100 Subject: [PATCH 1/2] allowing to set all threshold in receiver when running acquiistion (#1648) --- slsReceiverSoftware/src/ClientInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 0e3663633..9cc70d535 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -1646,7 +1646,8 @@ int ClientInterface::set_all_threshold(Interface &socket) { LOG(logDEBUG) << "Threshold:" << ToString(eVs); if (detType != MYTHEN3) functionNotImplemented(); - verifyIdle(socket); + // allow setting threshold metadata on the fly + // without checking for idle state impl()->setThresholdEnergy(eVs); return socket.Send(OK); } From 8619578081cb035926f888a42542508a24c35375 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 3 Nov 2026 13:28:16 +0100 Subject: [PATCH 2/2] Dev/check overlap rxroi deactivate (#1580) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * wip * fixed * tests work for both roi and port disable, but only in 10g mode * minor * works for jungfrau * fixed test * renamed function to reflect rx roi * typo --------- Co-authored-by: Erik Fröjdh --- slsDetectorSoftware/include/sls/Detector.h | 3 + slsDetectorSoftware/src/Detector.cpp | 3 + slsDetectorSoftware/src/DetectorImpl.cpp | 85 +++++++++++++++++- slsDetectorSoftware/src/DetectorImpl.h | 12 ++- .../tests/Caller/test-Caller-rx.cpp | 88 +++++++++++++++++++ 5 files changed, 187 insertions(+), 4 deletions(-) diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index d55362359..1f1fee5a5 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1037,6 +1037,9 @@ class Detector { void clearRxROI(); + /** Returns true if the current ROI covers the complete detector (default)*/ + bool isCompleteRxRoi() const; + ///@} /** @name File */ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0e08ce5be..edcbb705d 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1335,6 +1335,7 @@ Result Detector::getUDPDataStream(const defs::portPosition port, void Detector::setUDPDataStream(const defs::portPosition port, const bool enable, Positions pos) { + pimpl->validatePortEnable(port, enable, pos); pimpl->setUDPDataStream(port, enable, pos); } @@ -1485,6 +1486,8 @@ void Detector::setRxROI(const std::vector &args) { void Detector::clearRxROI() { pimpl->clearRxROI(); } +bool Detector::isCompleteRxRoi() const { return pimpl->isCompleteRxRoi(); } + // File Result Detector::getFileFormat(Positions pos) const { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 6be175391..ce473ec7a 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -48,6 +48,15 @@ bool DetectorImpl::isAllPositions(Positions pos) const { (pos.size() == modules.size())); } +std::vector DetectorImpl::fillInPositions(Positions pos) const { + if (isAllPositions(pos)) { + std::vector positions(modules.size()); + std::iota(begin(positions), end(positions), 0); + return positions; + } + return pos; +} + void DetectorImpl::setAcquiringFlag(bool flag) { shm()->acquiringFlag = flag; } int DetectorImpl::getDetectorIndex() const { return detectorIndex; } @@ -1640,6 +1649,7 @@ Result DetectorImpl::getUDPDataStream(const defs::portPosition port, void DetectorImpl::setUDPDataStream(const defs::portPosition port, const bool enable, Positions pos) { assertTwoUDPDataInterfaces("set enable/disable UDP ports"); + validatePortEnable(port, enable, pos); Parallel(&Module::setUDPDataStream, pos, port, enable); updateRxUDPDatastreamMetadata(); } @@ -1857,6 +1867,49 @@ void DetectorImpl::convertGlobalRoiToPortLevel( } } +void DetectorImpl::validatePortEnable(const defs::portPosition port, + const bool enable, + std::vector pos) const { + if (isCompleteRxRoi()) + return; + auto positions = fillInPositions(pos); + for (int i : positions) { + if (i < 0 || static_cast(i) >= modules.size()) { + throw RuntimeError("Invalid module index: " + std::to_string(i)); + } + auto modRois = modules[i]->getRxROI(); + auto portList = getPortPositionList(); + int portIndex = 0; + for (auto p : portList) { + if (p == port) + break; + portIndex++; + } + validatePortEnableRoiState(i, port, modRois[portIndex], enable); + } +} + +/** Assumption: + * 1. Check only for Eiger because port disable is only for Eiger now + * 2. This function called only when an Roi being set (not complete detector) + * ie. complete ROI enabled and some ports disabled is allowed + */ +void DetectorImpl::validatePortEnableRoiState(const int moduleIndex, + defs::portPosition changedPort, + const defs::ROI &portRoi, + bool enabled) const { + // enabled or disabled and no roi + if (enabled || portRoi.noRoi()) + return; + // diabled but ROI specified + std::ostringstream oss; + oss << ToString(changedPort) << " port of module " << moduleIndex << " (" + << modules[moduleIndex]->getHostname() + << ") is not active but ROI is specified for it: " << ToString(portRoi) + << ". Please disable the ROI for this port or enable the port."; + throw RuntimeError(oss.str()); +} + void DetectorImpl::setRxROI(const std::vector &args) { if (shm()->detType == CHIPTESTBOARD || shm()->detType == defs::XILINX_CHIPTESTBOARD) { @@ -1871,10 +1924,13 @@ void DetectorImpl::setRxROI(const std::vector &args) { } validateROIs(args); + int nPortsPerModule = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) .tsquash("Inconsistent number of udp ports set up per module"); + std::vector> moduleRois; + // further validate and create port level rois for each module for (size_t iModule = 0; iModule < modules.size(); ++iModule) { auto moduleGlobalRoi = getModuleROI(iModule); // at most 2 rois per module (for each port) @@ -1886,15 +1942,30 @@ void DetectorImpl::setRxROI(const std::vector &args) { roi.ymax = -1; } } - - // check overlap with module + // check overlap of each roi with module for (const auto &arg : args) { if (arg.overlap(moduleGlobalRoi)) { convertGlobalRoiToPortLevel(arg, moduleGlobalRoi, portRois); } } - modules[iModule]->setRxROI(portRois); + // validate roi against port enables + if (nPortsPerModule == 2) { + auto ports = getPortPositionList(); + for (int iport = 0; iport != nPortsPerModule; ++iport) { + defs::portPosition port = ports[iport]; + auto enable = modules[iModule]->getUDPDataStream(port); + validatePortEnableRoiState(iModule, port, portRois[iport], + enable); + } + } + moduleRois.push_back(portRois); } + + // set rois for each module + for (size_t iModule = 0; iModule < modules.size(); ++iModule) { + modules[iModule]->setRxROI(moduleRois[iModule]); + } + // metadata modules[0]->setRxROIMetadata(args); } @@ -1909,6 +1980,14 @@ void DetectorImpl::clearRxROI() { modules[0]->setRxROIMetadata(std::vector(1)); } +bool DetectorImpl::isCompleteRxRoi() const { + const auto rois = getRxROI(); + if (rois.empty() || (rois.size() == 1 && rois[0].completeRoi())) { + return true; + } + return false; +} + void DetectorImpl::getBadChannels(const std::string &fname, Positions pos) const { auto res = Parallel(&Module::getBadChannels, pos); diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index b29dd7716..9df5c9222 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -183,6 +183,8 @@ class DetectorImpl : public virtual slsDetectorDefs { bool isAllPositions(Positions pos) const; + std::vector fillInPositions(Positions pos) const; + inline bool isChipTestBoard() const { return (shm()->detType == defs::CHIPTESTBOARD || shm()->detType == defs::XILINX_CHIPTESTBOARD); @@ -320,8 +322,16 @@ class DetectorImpl : public virtual slsDetectorDefs { defs::xy getPortGeometry() const; std::vector getRxROI(int module_id = -1) const; + void validatePortEnable(const defs::portPosition port, const bool enable, + std::vector pos) const; + void validatePortEnableRoiState(const int moduleIndex, + defs::portPosition changedPort, + const defs::ROI &portRoi, + bool enabled) const; + void setRxROI(const std::vector &args); void clearRxROI(); + bool isCompleteRxRoi() const; void getBadChannels(const std::string &fname, Positions pos) const; void setBadChannels(const std::string &fname, Positions pos); @@ -510,4 +520,4 @@ class DetectorImpl : public virtual slsDetectorDefs { void *pCallbackArg{nullptr}; }; -} // namespace sls \ No newline at end of file +} // namespace sls diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp index 9aceec20a..8a87dfc7c 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp @@ -855,6 +855,94 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") { } } +TEST_CASE("rx_roi_port_disabled", "[.detectorintegration]") { + Detector det; + auto det_type = det.getDetectorType().squash(); + auto two_ports = (det_type == defs::EIGER); + if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) { + int numinterfaces = det.getNumberofUDPInterfaces().tsquash( + "inconsistent number of interfaces"); + two_ports = (numinterfaces == 2); + } + + if (two_ports) { + auto prev_roi = det.getRxROI(); + auto ports = det.getPortPositionList(); + auto prev_port0 = det.getUDPDataStream(ports[0], {0})[0]; + auto prev_port1 = det.getUDPDataStream(ports[1], {0})[0]; + bool prev_tengiga = false; + if (det_type == defs::EIGER) { + prev_tengiga = det.getTenGiga().squash(false); + } + + std::vector rois(2); + switch (det_type) { + case defs::EIGER: + det.setTenGiga(true); + rois[0] = defs::ROI{0, 10, 0, 20}; + rois[1] = defs::ROI{600, 610, 0, 30}; + break; + case defs::JUNGFRAU: + rois[0] = defs::ROI{0, 10, 0, 10}; + rois[1] = defs::ROI{0, 20, 300, 310}; + break; + case defs::MOENCH: + rois[0] = defs::ROI{0, 10, 0, 10}; + rois[1] = defs::ROI{0, 20, 300, 310}; + break; + default: + REQUIRE(false); + break; + } + + det.clearRxROI(); + det.setUDPDataStream(ports[0], true, {0}); + det.setUDPDataStream(ports[1], true, {0}); + det.setRxROI(rois); + REQUIRE_THROWS(det.setUDPDataStream(ports[0], false)); + REQUIRE_THROWS(det.setUDPDataStream(ports[1], false)); + + det.clearRxROI(); + det.setUDPDataStream(ports[0], true, {0}); + det.setUDPDataStream(ports[1], true, {0}); + det.setRxROI({rois[0]}); + REQUIRE_THROWS(det.setUDPDataStream(ports[0], false)); + REQUIRE_NOTHROW(det.setUDPDataStream(ports[1], false)); + + det.clearRxROI(); + det.setUDPDataStream(ports[0], true, {0}); + det.setUDPDataStream(ports[1], true, {0}); + det.setRxROI({rois[1]}); + REQUIRE_NOTHROW(det.setUDPDataStream(ports[0], false)); + REQUIRE_THROWS(det.setUDPDataStream(ports[1], false)); + + det.clearRxROI(); + det.setUDPDataStream(ports[0], false, {0}); + det.setUDPDataStream(ports[1], true, {0}); + REQUIRE_THROWS(det.setRxROI({rois[0]})); + REQUIRE_NOTHROW(det.setRxROI({rois[1]})); + + det.clearRxROI(); + det.setUDPDataStream(ports[0], true, {0}); + det.setUDPDataStream(ports[1], false, {0}); + REQUIRE_NOTHROW(det.setRxROI({rois[0]})); + REQUIRE_THROWS(det.setRxROI({rois[1]})); + + /* eiger virtual detector doesnt understand it cant disable in 1g mode, + * so cant test in 1g mode */ + + if (prev_roi.size() == 1 && prev_roi[0].completeRoi()) + det.clearRxROI(); + else + det.setRxROI(prev_roi); + det.setUDPDataStream(ports[0], prev_port0, {0}); + det.setUDPDataStream(ports[1], prev_port1, {0}); + if (det_type == defs::EIGER) { + det.setTenGiga(prev_tengiga); + } + } +} + TEST_CASE("rx_clearroi", "[.detectorintegration]") { Detector det; Caller caller(&det);