switched to vector instead of std::array<ROI, 2>>, which prints extra [-1, -1] when theres only 1 udp interface
All checks were successful
Build on RHEL9 / build (push) Successful in 2m49s
Build on RHEL8 / build (push) Successful in 4m48s

This commit is contained in:
2025-06-24 09:39:28 +02:00
parent 686eebd69b
commit 28792ea7e7
11 changed files with 127 additions and 45 deletions

View File

@ -993,7 +993,7 @@ class Detector {
std::vector<defs::ROI> getRxROI() const;
/** Returns port level ROIs. Max 2 ports and hence max 2 elements per readout */
Result<std::array<defs::ROI, 2>> getRxROI(int module_id) const;
std::vector<defs::ROI> getRxROI(int module_id) const;
/** only at multi module level without gap pixels. At most, 1 ROI per UDP port */
void setRxROI(const std::vector<defs::ROI> &args);

View File

@ -1387,8 +1387,8 @@ std::vector<defs::ROI> Detector::getRxROI() const {
return pimpl->getRxROI();
}
Result<std::array<defs::ROI, 2>> Detector::getRxROI(int module_id) const {
return pimpl->Parallel(&Module::getRxROI, {module_id});
std::vector<defs::ROI> Detector::getRxROI(int module_id) const {
return pimpl->getRxROI(module_id);
}
// RxROIs can be set for all types except CTB. At multi level without gap pixels

View File

@ -1667,8 +1667,7 @@ void DetectorImpl::verifyUniqueHost(
}
}
std::vector<defs::ROI> DetectorImpl::getRxROI() const {
std::vector<defs::ROI> DetectorImpl::getRxROI(int module_id) const {
if (shm()->detType == CHIPTESTBOARD ||
shm()->detType == defs::XILINX_CHIPTESTBOARD) {
throw RuntimeError("RxRoi not implemented for this Detector");
@ -1677,6 +1676,14 @@ std::vector<defs::ROI> DetectorImpl::getRxROI() const {
throw RuntimeError("No Modules added");
}
// individual module rois
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<defs::ROI>{};
return rxRoiTemp;
// TODO
@ -1792,13 +1799,18 @@ defs::ROI DetectorImpl::getModuleROI(int moduleIndex) const {
void DetectorImpl::convertGlobalRoiToPortLevel(
const defs::ROI &userRoi, const defs::ROI &moduleRoi,
std::array<defs::ROI, 2> &portRois) const {
std::vector<defs::ROI> &portRois) const {
const defs::xy modSize = modules[0]->getNumberOfChannels();
const defs::xy geometry = getPortGeometry();
const int numPorts = geometry.x * geometry.y;
if (numPorts > 2) {
throw RuntimeError("Only up to 2 ports per module supported.");
}
if (numPorts != (int)portRois.size()) {
throw RuntimeError("Number of port ROIs does not match number of ports in module. Expected: " +
std::to_string(numPorts) + ", got: " +
std::to_string(portRois.size()));
}
for (int port = 0; port < numPorts; ++port) {
defs::ROI portRoi = moduleRoi;
@ -1849,12 +1861,13 @@ void DetectorImpl::setRxROI(const std::vector<defs::ROI> &args) {
}
validateROIs(args);
int nPortsPerModule = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).tsquash("Inconsistent number of udp ports set up per module");
for (size_t iModule = 0; iModule < modules.size(); ++iModule) {
auto moduleGlobalRoi = getModuleROI(iModule);
// at most 2 rois per module (for each port)
std::array<defs::ROI, 2> portRois{};
std::vector<defs::ROI> portRois(nPortsPerModule);
for (const auto &arg : args) {
if (roisOverlap(arg, moduleGlobalRoi)) {
@ -1863,7 +1876,7 @@ void DetectorImpl::setRxROI(const std::vector<defs::ROI> &args) {
}
// print the rois for debugging
LOG(logINFOBLUE) << "Module " << iModule << " RxROIs:";
for (size_t iPort = 0; iPort != 2; iPort++) {
for (size_t iPort = 0; iPort != portRois.size(); iPort++) {
LOG(logINFOBLUE)
<< " Port " << iPort << ": " << ToString(portRois[iPort]);
}
@ -1876,15 +1889,12 @@ void DetectorImpl::setRxROI(const std::vector<defs::ROI> &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::array<defs::ROI, 2>{});
modules[iModule]->setRxROI(std::vector<defs::ROI>(nPortsPerModule));
}
}
int DetectorImpl::getNumberOfUdpPortsInRxROI() const {
return 0; // TODO
}
void DetectorImpl::getBadChannels(const std::string &fname,
Positions pos) const {
auto res = Parallel(&Module::getBadChannels, pos);

View File

@ -302,10 +302,9 @@ class DetectorImpl : public virtual slsDetectorDefs {
verifyUniqueRxHost(const std::vector<std::string> &names) const;
defs::xy getPortGeometry() const;
std::vector<defs::ROI> getRxROI() const;
std::vector<defs::ROI> getRxROI(int module_id = -1) const;
void setRxROI(const std::vector<defs::ROI> &args);
void clearRxROI();
int getNumberOfUdpPortsInRxROI() const;
void getBadChannels(const std::string &fname, Positions pos) const;
void setBadChannels(const std::string &fname, Positions pos);
@ -433,7 +432,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
defs::ROI getModuleROI(int moduleIndex) const;
void convertGlobalRoiToPortLevel(
const defs::ROI &userRoi, const defs::ROI &moduleRoi,
std::array<defs::ROI, 2> &portRois) const;
std::vector<defs::ROI> &portRois) const;
const int detectorIndex{0};
SharedMemory<sharedDetector> shm{0, -1};

View File

@ -1521,12 +1521,50 @@ void Module::setRxArping(bool enable) {
sendToReceiver(F_SET_RECEIVER_ARPING, static_cast<int>(enable), nullptr);
}
std::array<defs::ROI, 2> Module::getRxROI() const {
return sendToReceiver<std::array<slsDetectorDefs::ROI, 2>>(F_RECEIVER_GET_RECEIVER_ROI);
std::vector<defs::ROI> Module::getRxROI() const {
LOG(logDEBUG1) << "Getting receiver ROI for Module " << moduleIndex;
// check number of ports
if (!shm()->useReceiverFlag) {
throw RuntimeError("No receiver to get ROI.");
}
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_RECEIVER_GET_RECEIVER_ROI);
client.setFnum(F_RECEIVER_GET_RECEIVER_ROI);
auto nPorts = client.Receive<int>();
std::vector<ROI> retval(nPorts);
if (nPorts > 0)
client.Receive(retval);
if (nPorts > shm()->numUDPInterfaces) {
throw RuntimeError("Invalid number of rois: " + std::to_string(nPorts) + ". Max: " + std::to_string(shm()->numUDPInterfaces));
}
LOG(logDEBUG1) << "ROI of Receiver" << moduleIndex << ": "
<< ToString(retval);
return retval;
}
void Module::setRxROI(const std::array<defs::ROI, 2> &portRois) {
sendToReceiver(F_RECEIVER_SET_RECEIVER_ROI, portRois, nullptr);
void Module::setRxROI(const std::vector<defs::ROI> &portRois) {
LOG(logDEBUG) << "Sending to receiver " << moduleIndex
<< " [roi: " << ToString(portRois) << ']';
if (!shm()->useReceiverFlag) {
throw RuntimeError("No receiver to set ROI.");
}
if ((int)portRois.size() > shm()->numUDPInterfaces) {
throw RuntimeError("Invalid number of ROIs: " +
std::to_string(portRois.size()) +
". Max: " + std::to_string(shm()->numUDPInterfaces));
}
// check number of ports
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_RECEIVER_SET_RECEIVER_ROI);
client.setFnum(F_RECEIVER_SET_RECEIVER_ROI);
int size = static_cast<int>(portRois.size());
client.Send(size);
if (size > 0)
client.Send(portRois);
if (client.Receive<int>() == FAIL) {
throw ReceiverError("Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
}
void Module::setRxROIMetadata(const std::vector<slsDetectorDefs::ROI> &args) {
@ -1535,8 +1573,10 @@ void Module::setRxROIMetadata(const std::vector<slsDetectorDefs::ROI> &args) {
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.Send(F_RECEIVER_SET_RECEIVER_ROI_METADATA);
receiver.setFnum(F_RECEIVER_SET_RECEIVER_ROI_METADATA);
receiver.Send(static_cast<int>(args.size()));
receiver.Send(args);
int size = static_cast<int>(args.size());
receiver.Send(size);
if (size > 0)
receiver.Send(args);
if (receiver.Receive<int>() == FAIL) {
throw ReceiverError("Receiver " + std::to_string(moduleIndex) +
" returned error: " + receiver.readErrorMessage());

View File

@ -301,8 +301,8 @@ class Module : public virtual slsDetectorDefs {
std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const;
bool getRxArping() const;
void setRxArping(bool enable);
std::array<defs::ROI, 2> getRxROI() const;
void setRxROI(const std::array<slsDetectorDefs::ROI, 2> &portRois);
std::vector<defs::ROI> getRxROI() const;
void setRxROI(const std::vector<slsDetectorDefs::ROI> &portRois);
void setRxROIMetadata(const std::vector<slsDetectorDefs::ROI> &args);
/**************************************************

View File

@ -619,11 +619,11 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
caller.call("rx_roi", {}, 0, GET, oss1));
// eiger returns 2 values for 2 ports per module
if (det_type == defs::EIGER) {
REQUIRE(oss1.str() == "rx_roi [[[" + stringMin + ", " + std::to_string(portSize.x - 1) + ", 20, 30], [" + std::to_string(portSize.x) + ", " + stringMax + ", 20, 30]]]\n");
REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " + std::to_string(portSize.x - 1) + ", 20, 30], [" + std::to_string(portSize.x) + ", " + stringMax + ", 20, 30]]\n");
}
// others return only 1 roi per module (1 port per module)
else {
REQUIRE(oss1.str() == "rx_roi [[[" + stringMin + ", " + std::to_string(portSize.x - 1) + "20, 30]]]\n");
REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " + std::to_string(portSize.x - 1) + "20, 30]]\n");
}
}
}
@ -655,11 +655,11 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
caller.call("rx_roi", {}, 0, GET, oss1));
// non-eiger with 2 interfaces returns 2 values for 2 ports per module
if (numinterfaces == 2) {
REQUIRE(oss1.str() == "rx_roi [[[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "], [20, 30, " + std::to_string(portSize.y) + ", " + stringMax + "]]]\n");
REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "], [20, 30, " + std::to_string(portSize.y) + ", " + stringMax + "]]\n");
}
// others return only 1 roi per module (1 port per module)
else {
REQUIRE(oss1.str() == "rx_roi [[[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "], [-1, -1]]]\n");
REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "]]\n");
}
}
}