From b775dd0efa70e5b600831210f06496cdd05c41cc Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Sun, 29 Jun 2025 18:56:07 +0200 Subject: [PATCH] get rx_roi from metadata from rxr, cant reconstruct. fixed clear roi should give 1 roi min --- slsDetectorSoftware/src/DetectorImpl.cpp | 15 ++++-------- slsDetectorSoftware/src/DetectorImpl.h | 2 -- slsDetectorSoftware/src/Module.cpp | 23 +++++++++++++++++++ slsDetectorSoftware/src/Module.h | 1 + .../tests/Caller/test-Caller-rx.cpp | 5 +++- slsReceiverSoftware/src/ClientInterface.cpp | 13 +++++++++++ slsReceiverSoftware/src/ClientInterface.h | 1 + slsReceiverSoftware/src/Implementation.cpp | 4 ++++ slsReceiverSoftware/src/Implementation.h | 1 + .../include/sls/sls_detector_funcs.h | 2 ++ 10 files changed, 54 insertions(+), 13 deletions(-) diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 06b37640a..35e0b4dd8 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1675,18 +1675,14 @@ std::vector DetectorImpl::getRxROI(int module_id) const { if (modules.size() == 0) { throw RuntimeError("No Modules added"); } - - // individual module rois + if (module_id >= (int)modules.size()) { + throw RuntimeError("Invalid module id: " + std::to_string(module_id)); + } if (module_id >= 0) { - if (module_id >= (int)modules.size()) - throw RuntimeError("Invalid module index " + std::to_string(module_id) + ". Out of bounds."); return modules[module_id]->getRxROI(); } - // multi roi - // return std::vector{}; - return rxRoiTemp; - // TODO + return modules[0]->getRxROIMetadata(); } void DetectorImpl::validateROIs(const std::vector &rois) { @@ -1875,17 +1871,16 @@ void DetectorImpl::setRxROI(const std::vector &args) { } modules[iModule]->setRxROI(portRois); } - rxRoiTemp = args; // metadata modules[0]->setRxROIMetadata(args); } void DetectorImpl::clearRxROI() { - rxRoiTemp.clear(); int nPortsPerModule = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).tsquash("Inconsistent number of udp ports set up per module"); for (size_t iModule = 0; iModule < modules.size(); ++iModule) { modules[iModule]->setRxROI(std::vector(nPortsPerModule)); } + modules[0]->setRxROIMetadata(std::vector(1)); } void DetectorImpl::getBadChannels(const std::string &fname, diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index d90c4c303..34f53e28a 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -459,8 +459,6 @@ class DetectorImpl : public virtual slsDetectorDefs { void (*dataReady)(detectorData *, uint64_t, uint32_t, void *){nullptr}; void *pCallbackArg{nullptr}; - - std::vector rxRoiTemp; }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index c1c65add3..6a3161928 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1569,6 +1569,29 @@ void Module::setRxROI(const std::vector &portRois) { } } +std::vector Module::getRxROIMetadata() const { + LOG(logDEBUG1) << "Getting receiver ROI metadata for Module " + << moduleIndex; + // check number of ports + if (!shm()->useReceiverFlag) { + throw RuntimeError("No receiver to get ROI metadata."); + } + auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); + client.Send(F_RECEIVER_GET_ROI_METADATA); + client.setFnum(F_RECEIVER_GET_ROI_METADATA); + auto size = client.Receive(); + std::vector retval(size); + if (size > 0) + client.Receive(retval); + if (size == 0) { + throw RuntimeError("Invalid number of ROI metadata: " + + std::to_string(size) + ". Min: 1."); + } + LOG(logDEBUG1) << "ROI metadata of Receiver: " + << ToString(retval); + return retval; +} + void Module::setRxROIMetadata(const std::vector &args) { LOG(logDEBUG) << "Sending to receiver " << moduleIndex << " [roi metadata: " << ToString(args) << ']'; diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 86516cbb5..4494383b0 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -304,6 +304,7 @@ class Module : public virtual slsDetectorDefs { std::vector getRxROI() const; void setRxROI(const std::vector &portRois); void setRxROIMetadata(const std::vector &args); + std::vector getRxROIMetadata() const; /************************************************** * * diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp index f89428553..4172f4559 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp @@ -728,7 +728,10 @@ TEST_CASE("rx_roi", "[.cmdcall]") { } for (int i = 0; i != det.size(); ++i) { - det.setRxROI(prev_val); + if (prev_val.size() == 1 && prev_val[0].completeRoi()) { + det.clearRxROI(); + } else + det.setRxROI(prev_val); } } } diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index d0336ba49..c05ee6245 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -220,6 +220,7 @@ int ClientInterface::functionTable(){ flist[F_RECEIVER_SET_COLUMN] = &ClientInterface::set_column; flist[F_GET_RECEIVER_DBIT_REORDER] = &ClientInterface::get_dbit_reorder; flist[F_SET_RECEIVER_DBIT_REORDER] = &ClientInterface::set_dbit_reorder; + flist[F_RECEIVER_GET_ROI_METADATA] = &ClientInterface::get_roi_metadata; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { @@ -1838,4 +1839,16 @@ int ClientInterface::set_dbit_reorder(Interface &socket) { return socket.Send(OK); } +int ClientInterface::get_roi_metadata(Interface &socket) { + if (detType == CHIPTESTBOARD || detType == XILINX_CHIPTESTBOARD) + functionNotImplemented(); + auto retvals = impl()->getMultiROIMetadata(); + LOG(logINFORED) << "Receiver ROI metadata retval:" << ToString(retvals); + auto size = static_cast(retvals.size()); + socket.Send(size); + if (size > 0) + socket.Send(retvals); + return OK; +} + } // namespace sls diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index 665e0f396..e17a3ab85 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -166,6 +166,7 @@ class ClientInterface : private virtual slsDetectorDefs { int set_column(ServerInterface &socket); int get_dbit_reorder(ServerInterface &socket); int set_dbit_reorder(ServerInterface &socket); + int get_roi_metadata(ServerInterface &socket); Implementation *impl() { if (receiver != nullptr) { diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index cf895c617..5e0940f4b 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -450,6 +450,10 @@ void Implementation::setMultiROIMetadata( LOG(logINFO) << "Multi ROI Metadata: " << ToString(multiRoiMetadata); } +std::vector Implementation::getMultiROIMetadata() const { + return multiRoiMetadata; +} + /************************************************** * * * File Parameters * diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 099454441..e83539304 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -61,6 +61,7 @@ class Implementation : private virtual slsDetectorDefs { std::vector getPortROIs() const; void setPortROIs(const std::vector &args); void setMultiROIMetadata(const std::vector &args); + std::vector getMultiROIMetadata() const; /************************************************** * * diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index ec1c6d2f1..20688941c 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -412,6 +412,7 @@ enum detFuncs { F_RECEIVER_SET_COLUMN, F_GET_RECEIVER_DBIT_REORDER, F_SET_RECEIVER_DBIT_REORDER, + F_RECEIVER_GET_ROI_METADATA, NUM_REC_FUNCTIONS }; @@ -820,6 +821,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RECEIVER_SET_COLUMN: return "F_RECEIVER_SET_COLUMN"; case F_GET_RECEIVER_DBIT_REORDER: return "F_GET_RECEIVER_DBIT_REORDER"; case F_SET_RECEIVER_DBIT_REORDER: return "F_SET_RECEIVER_DBIT_REORDER"; + case F_RECEIVER_GET_ROI_METADATA: return "F_RECEIVER_GET_ROI_METADATA"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS"; default: return "Unknown Function";