mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-22 01:27:59 +02:00
can get individual rois, but not connected to command yet
This commit is contained in:
@ -989,15 +989,17 @@ class Detector {
|
|||||||
* every minute. Useful in 10G mode. */
|
* every minute. Useful in 10G mode. */
|
||||||
void setRxArping(bool value, Positions pos = {});
|
void setRxArping(bool value, Positions pos = {});
|
||||||
|
|
||||||
|
/** Returns multi level ROIs */
|
||||||
std::vector<defs::ROI> getRxROI() const;
|
std::vector<defs::ROI> getRxROI() const;
|
||||||
|
|
||||||
/** only at multi module level without gap pixels */
|
/** 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;
|
||||||
|
|
||||||
|
/** only at multi module level without gap pixels. At most, 1 ROI per UDP port */
|
||||||
void setRxROI(const std::vector<defs::ROI> &args);
|
void setRxROI(const std::vector<defs::ROI> &args);
|
||||||
|
|
||||||
void clearRxROI();
|
void clearRxROI();
|
||||||
|
|
||||||
int getNumberOfUdpPortsInRxROI() const;
|
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/** @name File */
|
/** @name File */
|
||||||
|
@ -739,14 +739,7 @@ std::string Caller::rx_roi(int action) {
|
|||||||
throw RuntimeError("Cannot execute receiver ROI at module level");
|
throw RuntimeError("Cannot execute receiver ROI at module level");
|
||||||
} else {
|
} else {
|
||||||
auto t = det->getRxROI();
|
auto t = det->getRxROI();
|
||||||
// os << ToString(t) << '\n';
|
os << ToString(t) << '\n';
|
||||||
for (const auto &r : t) {
|
|
||||||
os << r << ';';
|
|
||||||
}
|
|
||||||
if (!t.empty()) {
|
|
||||||
os.seekp(-1, std::ios_base::end); // remove trailing ;
|
|
||||||
}
|
|
||||||
os << '\n';
|
|
||||||
}
|
}
|
||||||
} else if (action == defs::PUT_ACTION) {
|
} else if (action == defs::PUT_ACTION) {
|
||||||
std::vector<defs::ROI> rois;
|
std::vector<defs::ROI> rois;
|
||||||
@ -789,14 +782,7 @@ std::string Caller::rx_roi(int action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
det->setRxROI(rois);
|
det->setRxROI(rois);
|
||||||
// os << ToString(rois) << '\n';
|
os << ToString(rois) << '\n';
|
||||||
for (const auto &r : rois) {
|
|
||||||
os << r << ';';
|
|
||||||
}
|
|
||||||
//if (!rois.empty()) {
|
|
||||||
// os.seekp(-1, std::ios_base::end); // remove trailing ;
|
|
||||||
//}
|
|
||||||
os << '\n';
|
|
||||||
} else {
|
} else {
|
||||||
throw RuntimeError("Unknown action");
|
throw RuntimeError("Unknown action");
|
||||||
}
|
}
|
||||||
|
@ -1383,7 +1383,13 @@ void Detector::setRxArping(bool value, Positions pos) {
|
|||||||
pimpl->Parallel(&Module::setRxArping, pos, value);
|
pimpl->Parallel(&Module::setRxArping, pos, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<defs::ROI> Detector::getRxROI() const { return pimpl->getRxROI(); }
|
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});
|
||||||
|
}
|
||||||
|
|
||||||
// RxROIs can be set for all types except CTB. At multi level without gap pixels
|
// RxROIs can be set for all types except CTB. At multi level without gap pixels
|
||||||
void Detector::setRxROI(const std::vector<defs::ROI> &args) {
|
void Detector::setRxROI(const std::vector<defs::ROI> &args) {
|
||||||
@ -1392,9 +1398,6 @@ void Detector::setRxROI(const std::vector<defs::ROI> &args) {
|
|||||||
|
|
||||||
void Detector::clearRxROI() { pimpl->clearRxROI(); }
|
void Detector::clearRxROI() { pimpl->clearRxROI(); }
|
||||||
|
|
||||||
int Detector::getNumberOfUdpPortsInRxROI() const {
|
|
||||||
return pimpl->getNumberOfUdpPortsInRxROI();
|
|
||||||
}
|
|
||||||
|
|
||||||
// File
|
// File
|
||||||
|
|
||||||
|
@ -1791,7 +1791,7 @@ defs::ROI DetectorImpl::getModuleROI(int moduleIndex) const {
|
|||||||
|
|
||||||
void DetectorImpl::convertGlobalRoiToPortLevel(
|
void DetectorImpl::convertGlobalRoiToPortLevel(
|
||||||
const defs::ROI &userRoi, const defs::ROI &moduleRoi,
|
const defs::ROI &userRoi, const defs::ROI &moduleRoi,
|
||||||
std::vector<std::map<int, defs::ROI>> &portRois) const {
|
std::array<defs::ROI, 2> &portRois) const {
|
||||||
const defs::xy modSize = modules[0]->getNumberOfChannels();
|
const defs::xy modSize = modules[0]->getNumberOfChannels();
|
||||||
const defs::xy geometry = getPortGeometry();
|
const defs::xy geometry = getPortGeometry();
|
||||||
const int numPorts = geometry.x * geometry.y;
|
const int numPorts = geometry.x * geometry.y;
|
||||||
@ -1827,16 +1827,13 @@ void DetectorImpl::convertGlobalRoiToPortLevel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if port ROI already exists for this port
|
// Check if port ROI already exists for this port
|
||||||
for (const auto &m : portRois) {
|
if (!portRois[port].completeRoi()) {
|
||||||
if (m.find(port) != m.end()) {
|
throw RuntimeError(
|
||||||
throw RuntimeError(
|
"Multiple ROIs specified for the same port " +
|
||||||
"Multiple ROIs specified for the same port " +
|
std::to_string(port) +
|
||||||
std::to_string(port) +
|
" with ROI: " + ToString(userRoi));
|
||||||
" with ROI: " + ToString(userRoi));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
portRois[port] = clipped;
|
||||||
portRois.push_back({{port, clipped}});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1856,7 +1853,7 @@ void DetectorImpl::setRxROI(const std::vector<defs::ROI> &args) {
|
|||||||
auto moduleGlobalRoi = getModuleROI(iModule);
|
auto moduleGlobalRoi = getModuleROI(iModule);
|
||||||
|
|
||||||
// at most 2 rois per module (for each port)
|
// at most 2 rois per module (for each port)
|
||||||
std::vector<std::map<int, defs::ROI>> portRois;
|
std::array<defs::ROI, 2> portRois{};
|
||||||
|
|
||||||
for (const auto &arg : args) {
|
for (const auto &arg : args) {
|
||||||
if (roisOverlap(arg, moduleGlobalRoi)) {
|
if (roisOverlap(arg, moduleGlobalRoi)) {
|
||||||
@ -1865,18 +1862,23 @@ void DetectorImpl::setRxROI(const std::vector<defs::ROI> &args) {
|
|||||||
}
|
}
|
||||||
// print the rois for debugging
|
// print the rois for debugging
|
||||||
LOG(logINFOBLUE) << "Module " << iModule << " RxROIs:";
|
LOG(logINFOBLUE) << "Module " << iModule << " RxROIs:";
|
||||||
for (const auto &portRoi : portRois) {
|
for (size_t iPort = 0; iPort != 2; iPort++) {
|
||||||
for (const auto &roi : portRoi) {
|
LOG(logINFOBLUE)
|
||||||
LOG(logINFOBLUE)
|
<< " Port " << iPort << ": " << ToString(portRois[iPort]);
|
||||||
<< " Port " << roi.first << ": " << ToString(roi.second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// modules[iModule]->setRxROIs(portRois); TODO
|
modules[iModule]->setRxROI(portRois);
|
||||||
}
|
}
|
||||||
rxRoiTemp = args;
|
rxRoiTemp = args;
|
||||||
|
// metadata
|
||||||
|
modules[0]->setRxROIMetadata(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetectorImpl::clearRxROI() { rxRoiTemp.clear(); }
|
void DetectorImpl::clearRxROI() {
|
||||||
|
rxRoiTemp.clear();
|
||||||
|
for (size_t iModule = 0; iModule < modules.size(); ++iModule) {
|
||||||
|
modules[iModule]->setRxROI(std::array<defs::ROI, 2>{});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int DetectorImpl::getNumberOfUdpPortsInRxROI() const {
|
int DetectorImpl::getNumberOfUdpPortsInRxROI() const {
|
||||||
return 0; // TODO
|
return 0; // TODO
|
||||||
|
@ -433,7 +433,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
|||||||
defs::ROI getModuleROI(int moduleIndex) const;
|
defs::ROI getModuleROI(int moduleIndex) const;
|
||||||
void convertGlobalRoiToPortLevel(
|
void convertGlobalRoiToPortLevel(
|
||||||
const defs::ROI &userRoi, const defs::ROI &moduleRoi,
|
const defs::ROI &userRoi, const defs::ROI &moduleRoi,
|
||||||
std::vector<std::map<int, defs::ROI>> &portRois) const;
|
std::array<defs::ROI, 2> &portRois) const;
|
||||||
|
|
||||||
const int detectorIndex{0};
|
const int detectorIndex{0};
|
||||||
SharedMemory<sharedDetector> shm{0, -1};
|
SharedMemory<sharedDetector> shm{0, -1};
|
||||||
|
@ -1520,20 +1520,29 @@ bool Module::getRxArping() const {
|
|||||||
void Module::setRxArping(bool enable) {
|
void Module::setRxArping(bool enable) {
|
||||||
sendToReceiver(F_SET_RECEIVER_ARPING, static_cast<int>(enable), nullptr);
|
sendToReceiver(F_SET_RECEIVER_ARPING, static_cast<int>(enable), nullptr);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
defs::ROI Module::getRxROI() const {
|
std::array<defs::ROI, 2> Module::getRxROI() const {
|
||||||
return sendToReceiver<slsDetectorDefs::ROI>(F_RECEIVER_GET_RECEIVER_ROI);
|
return sendToReceiver<std::array<slsDetectorDefs::ROI, 2>>(F_RECEIVER_GET_RECEIVER_ROI);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::setRxROI(const slsDetectorDefs::ROI arg) {
|
void Module::setRxROI(std::array<defs::ROI, 2> portRois) {
|
||||||
LOG(logDEBUG) << moduleIndex << ": " << arg;
|
/*LOG(logDEBUG) << "Sending to receiver " << moduleIndex << " [rx roi: " << ToString(portRois)
|
||||||
sendToReceiver(F_RECEIVER_SET_RECEIVER_ROI, arg, nullptr);
|
<< ']';
|
||||||
|
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
|
||||||
|
receiver.Send(F_RECEIVER_SET_RECEIVER_ROI);
|
||||||
|
receiver.setFnum(F_RECEIVER_SET_RECEIVER_ROI);
|
||||||
|
receiver.Send(portRois);
|
||||||
|
if (receiver.Receive<int>() == FAIL) {
|
||||||
|
throw ReceiverError("Receiver " + std::to_string(moduleIndex) +
|
||||||
|
" returned error: " + receiver.readErrorMessage());
|
||||||
|
}*/
|
||||||
|
sendToReceiver(F_RECEIVER_SET_RECEIVER_ROI, portRois, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::setRxROIMetadata(const slsDetectorDefs::ROI arg) {
|
void Module::setRxROIMetadata(const std::vector<slsDetectorDefs::ROI> &arg) {
|
||||||
sendToReceiver(F_RECEIVER_SET_RECEIVER_ROI_METADATA, arg, nullptr);
|
sendToReceiver(F_RECEIVER_SET_RECEIVER_ROI_METADATA, arg, nullptr);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
// File
|
// File
|
||||||
slsDetectorDefs::fileFormat Module::getFileFormat() const {
|
slsDetectorDefs::fileFormat Module::getFileFormat() const {
|
||||||
return sendToReceiver<fileFormat>(F_GET_RECEIVER_FILE_FORMAT);
|
return sendToReceiver<fileFormat>(F_GET_RECEIVER_FILE_FORMAT);
|
||||||
|
@ -301,9 +301,9 @@ class Module : public virtual slsDetectorDefs {
|
|||||||
std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const;
|
std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const;
|
||||||
bool getRxArping() const;
|
bool getRxArping() const;
|
||||||
void setRxArping(bool enable);
|
void setRxArping(bool enable);
|
||||||
// defs::ROI getRxROI() const;
|
std::array<defs::ROI, 2> getRxROI() const;
|
||||||
// void setRxROI(const slsDetectorDefs::ROI arg);
|
void setRxROI(const std::array<slsDetectorDefs::ROI, 2> portRois);
|
||||||
// void setRxROIMetadata(const slsDetectorDefs::ROI arg);
|
void setRxROIMetadata(const std::vector<slsDetectorDefs::ROI> &args);
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
* *
|
* *
|
||||||
|
@ -482,12 +482,12 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
caller.call("rx_roi", {"5", "10"}, -1, PUT, oss);
|
caller.call("rx_roi", {"5", "10"}, -1, PUT, oss);
|
||||||
REQUIRE(oss.str() == "rx_roi [5, 10]\n");
|
REQUIRE(oss.str() == "rx_roi [[5, 10]]\n");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
caller.call("rx_roi", {"10", "15"}, -1, PUT, oss);
|
caller.call("rx_roi", {"10", "15"}, -1, PUT, oss);
|
||||||
REQUIRE(oss.str() == "rx_roi [10, 15]\n");
|
REQUIRE(oss.str() == "rx_roi [[10, 15]]\n");
|
||||||
}
|
}
|
||||||
REQUIRE_THROWS(caller.call("rx_roi", {"0", "0"}, -1, PUT));
|
REQUIRE_THROWS(caller.call("rx_roi", {"0", "0"}, -1, PUT));
|
||||||
REQUIRE_THROWS(caller.call("rx_roi", {"-1", "-1"}, -1, PUT));
|
REQUIRE_THROWS(caller.call("rx_roi", {"-1", "-1"}, -1, PUT));
|
||||||
@ -526,7 +526,7 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
REQUIRE_NOTHROW(caller.call(
|
REQUIRE_NOTHROW(caller.call(
|
||||||
"rx_roi", {"[5, 10, -1, -1];[" + stringMin + ", " + stringMax + ", -1, -1]"}, -1, PUT, oss));
|
"rx_roi", {"[5, 10, -1, -1];[" + stringMin + ", " + stringMax + ", -1, -1]"}, -1, PUT, oss));
|
||||||
REQUIRE(oss.str() ==
|
REQUIRE(oss.str() ==
|
||||||
"rx_roi [5, 10];[" + stringMin + ", " + stringMax + "]\n");
|
"rx_roi [[5, 10], [" + stringMin + ", " + stringMax + "]]\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -535,12 +535,12 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
caller.call("rx_roi", {"10", "15", "1", "5"}, -1, PUT, oss);
|
caller.call("rx_roi", {"10", "15", "1", "5"}, -1, PUT, oss);
|
||||||
REQUIRE(oss.str() == "rx_roi [10, 15, 1, 5]\n");
|
REQUIRE(oss.str() == "rx_roi [[10, 15, 1, 5]]\n");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
caller.call("rx_roi", {"10", "22", "18", "19"}, -1, PUT, oss);
|
caller.call("rx_roi", {"10", "22", "18", "19"}, -1, PUT, oss);
|
||||||
REQUIRE(oss.str() == "rx_roi [10, 22, 18, 19]\n");
|
REQUIRE(oss.str() == "rx_roi [[10, 22, 18, 19]]\n");
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -548,11 +548,11 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
{"1", std::to_string(detsize.x - 5), "1",
|
{"1", std::to_string(detsize.x - 5), "1",
|
||||||
std::to_string(detsize.y - 5)},
|
std::to_string(detsize.y - 5)},
|
||||||
-1, PUT, oss);
|
-1, PUT, oss);
|
||||||
REQUIRE(oss.str() == std::string("rx_roi [1, ") +
|
REQUIRE(oss.str() == std::string("rx_roi [[1, ") +
|
||||||
std::to_string(detsize.x - 5) +
|
std::to_string(detsize.x - 5) +
|
||||||
std::string(", 1, ") +
|
std::string(", 1, ") +
|
||||||
std::to_string(detsize.y - 5) +
|
std::to_string(detsize.y - 5) +
|
||||||
std::string("]\n"));
|
std::string("]]\n"));
|
||||||
}
|
}
|
||||||
REQUIRE_THROWS(
|
REQUIRE_THROWS(
|
||||||
caller.call("rx_roi", {"0", "0", "0", "0"}, -1, PUT));
|
caller.call("rx_roi", {"0", "0", "0", "0"}, -1, PUT));
|
||||||
@ -600,7 +600,7 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
REQUIRE_NOTHROW(caller.call(
|
REQUIRE_NOTHROW(caller.call(
|
||||||
"rx_roi", {"[5, 10, 20, 30];[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1, PUT, oss));
|
"rx_roi", {"[5, 10, 20, 30];[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1, PUT, oss));
|
||||||
REQUIRE(oss.str() ==
|
REQUIRE(oss.str() ==
|
||||||
"rx_roi [5, 10, 20, 30];[" + stringMin + ", " + stringMax + ", 20, 30]\n");
|
"rx_roi [[5, 10, 20, 30], [" + stringMin + ", " + stringMax + ", 20, 30]]\n");
|
||||||
}
|
}
|
||||||
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
|
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
|
||||||
// 2 interfaces or 2 modules
|
// 2 interfaces or 2 modules
|
||||||
@ -622,7 +622,7 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
REQUIRE_NOTHROW(caller.call(
|
REQUIRE_NOTHROW(caller.call(
|
||||||
"rx_roi", {"[5, 10, 20, 30];[25, 28, " + stringMin + ", " + stringMax + "]"}, -1, PUT, oss));
|
"rx_roi", {"[5, 10, 20, 30];[25, 28, " + stringMin + ", " + stringMax + "]"}, -1, PUT, oss));
|
||||||
REQUIRE(oss.str() ==
|
REQUIRE(oss.str() ==
|
||||||
"rx_roi [5, 10, 20, 30];[25, 28, " + stringMin + ", " + stringMax + "]\n");
|
"rx_roi [[5, 10, 20, 30], [25, 28, " + stringMin + ", " + stringMax + "]]\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -348,23 +348,6 @@ std::vector<T> StringTo(const std::vector<std::string> &strings) {
|
|||||||
result.push_back(StringTo<T>(s));
|
result.push_back(StringTo<T>(s));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
template <typename T>
|
|
||||||
std::string ToString(const std::vector<T> &vec) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << "[";
|
|
||||||
for (size_t i = 0; i < vec.size(); ++i) {
|
|
||||||
oss << vec[i];
|
|
||||||
if (i != vec.size() - 1)
|
|
||||||
oss << ", ";
|
|
||||||
}
|
|
||||||
oss << "]";
|
|
||||||
return oss.str();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*template <typename T>
|
|
||||||
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
|
|
||||||
return os << ToString(v);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
||||||
|
Reference in New Issue
Block a user