mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-11-18 17:24:04 +01:00
Merge remote-tracking branch 'origin/developer' into dev/fix_udp_headerwriting
This commit is contained in:
commit
1eb8230e28
6 files changed
+189
-5
No files matched your search
@@ -1037,6 +1037,9 @@ class Detector {
|
||||
|
||||
void clearRxROI();
|
||||
|
||||
/** Returns true if the current ROI covers the complete detector (default)*/
|
||||
bool isCompleteRxRoi() const;
|
||||
|
||||
///@}
|
||||
|
||||
/** @name File */
|
||||
|
||||
@@ -1335,6 +1335,7 @@ Result<bool> 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<defs::ROI> &args) {
|
||||
|
||||
void Detector::clearRxROI() { pimpl->clearRxROI(); }
|
||||
|
||||
bool Detector::isCompleteRxRoi() const { return pimpl->isCompleteRxRoi(); }
|
||||
|
||||
// File
|
||||
|
||||
Result<defs::fileFormat> Detector::getFileFormat(Positions pos) const {
|
||||
|
||||
@@ -48,6 +48,15 @@ bool DetectorImpl::isAllPositions(Positions pos) const {
|
||||
(pos.size() == modules.size()));
|
||||
}
|
||||
|
||||
std::vector<int> DetectorImpl::fillInPositions(Positions pos) const {
|
||||
if (isAllPositions(pos)) {
|
||||
std::vector<int> 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<bool> 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<int> pos) const {
|
||||
if (isCompleteRxRoi())
|
||||
return;
|
||||
auto positions = fillInPositions(pos);
|
||||
for (int i : positions) {
|
||||
if (i < 0 || static_cast<size_t>(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<defs::ROI> &args) {
|
||||
if (shm()->detType == CHIPTESTBOARD ||
|
||||
shm()->detType == defs::XILINX_CHIPTESTBOARD) {
|
||||
@@ -1871,10 +1924,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");
|
||||
std::vector<std::vector<defs::ROI>> 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<defs::ROI> &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<defs::ROI>(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);
|
||||
|
||||
@@ -183,6 +183,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
|
||||
bool isAllPositions(Positions pos) const;
|
||||
|
||||
std::vector<int> 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<defs::ROI> getRxROI(int module_id = -1) const;
|
||||
void validatePortEnable(const defs::portPosition port, const bool enable,
|
||||
std::vector<int> pos) const;
|
||||
void validatePortEnableRoiState(const int moduleIndex,
|
||||
defs::portPosition changedPort,
|
||||
const defs::ROI &portRoi,
|
||||
bool enabled) const;
|
||||
|
||||
void setRxROI(const std::vector<defs::ROI> &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
|
||||
} // namespace sls
|
||||
@@ -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<defs::ROI> 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user