mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-15 06:48:41 +01:00
minor fixes in command line and help
This commit is contained in:
@@ -723,19 +723,30 @@ std::string Caller::rx_zmqip(int action) {
|
|||||||
std::string Caller::rx_roi(int action) {
|
std::string Caller::rx_roi(int action) {
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
std::string helpMessage =
|
std::string helpMessage =
|
||||||
std::string("[xmin] [xmax] [ymin] [ymax]\n\tRegion of interest in "
|
std::string("[xmin] [xmax] [ymin] [ymax]\n") +
|
||||||
"receiver.\n\t") +
|
"\tDefines a single region of interest (ROI) in the receiver.\n"
|
||||||
"For a list of rois, use '[' and ']; ' to distinguish between "
|
"\tFor example, to set a single ROI: 0 100 20 30\n\n"
|
||||||
"rois and use comma inside the square brackets.\n\t If one fails to "
|
|
||||||
"use space after semicolon, please use quotes" +
|
"\tTo specify multiple ROIs, use square brackets between ROIs and "
|
||||||
"For example: [0,100,0,100]; [200,300,0,100] will set two "
|
"commas inside for each ROI. \n"
|
||||||
"rois.or '[0,100,0,100];[200,300,0,100]' when the vector is a single "
|
"\tInside each bracket, no spaces allowed.\n\n"
|
||||||
"string\n\n\t" +
|
|
||||||
"Only allowed to set at multi module level and without gap "
|
"\tIf you use semicolon (along with '['and ']' to separate rois), \n"
|
||||||
"ixels.\n\n\t" +
|
"\tenclose the entire list in quotes.\n"
|
||||||
"One can get rx_roi also at port level, by specifying the module id "
|
"\tExamples:\n"
|
||||||
"and it will return the roi for each port.\n"
|
"\t [0,100,0,100] [200,300,0,100]\n"
|
||||||
"Setting number of udp interfaces will clear the rx_roi\n";
|
"\t \"[0,100,0,100];[200,300,0,100]\"\n\n"
|
||||||
|
|
||||||
|
"\tNotes:\n"
|
||||||
|
"\t- ROIs can only be set at the multi-module level.\n"
|
||||||
|
"\t- ROIs coordinates assume no gap pixels, even if they are enabled "
|
||||||
|
"in gui.\n"
|
||||||
|
"\t- To retrieve ROIs per port, specify the module ID when using the "
|
||||||
|
"get command.\n"
|
||||||
|
"\t- Use the command 'rx_clearroi' to clear all ROIs.\n"
|
||||||
|
"\t- Changing the number of UDP interfaces will automatically clear "
|
||||||
|
"the current ROIs.\n";
|
||||||
|
|
||||||
if (action == defs::HELP_ACTION) {
|
if (action == defs::HELP_ACTION) {
|
||||||
os << helpMessage;
|
os << helpMessage;
|
||||||
} else if (action == defs::GET_ACTION) {
|
} else if (action == defs::GET_ACTION) {
|
||||||
@@ -751,9 +762,8 @@ std::string Caller::rx_roi(int action) {
|
|||||||
}
|
}
|
||||||
} else if (action == defs::PUT_ACTION) {
|
} else if (action == defs::PUT_ACTION) {
|
||||||
std::vector<defs::ROI> rois;
|
std::vector<defs::ROI> rois;
|
||||||
|
|
||||||
// Support multiple args with bracketed ROIs, or single arg with
|
// Support multiple args with bracketed ROIs, or single arg with
|
||||||
// semicolon-separated vector
|
// semicolon-separated vector in quotes
|
||||||
bool isVectorInput =
|
bool isVectorInput =
|
||||||
std::all_of(args.begin(), args.end(), [](const std::string &a) {
|
std::all_of(args.begin(), args.end(), [](const std::string &a) {
|
||||||
return a.find('[') != std::string::npos &&
|
return a.find('[') != std::string::npos &&
|
||||||
@@ -781,7 +791,9 @@ std::string Caller::rx_roi(int action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
throw RuntimeError("Could not parse ROI: " + helpMessage);
|
throw RuntimeError("Could not parse ROI: Did you use spaces inside "
|
||||||
|
"the brackets? Use sls_detector_help " +
|
||||||
|
cmd + " to get the right syntax expected.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// only multi level
|
// only multi level
|
||||||
@@ -802,16 +814,19 @@ std::vector<defs::ROI> Caller::parseRoiVector(const std::string &input) {
|
|||||||
std::stringstream ss(input);
|
std::stringstream ss(input);
|
||||||
std::string token;
|
std::string token;
|
||||||
|
|
||||||
while (std::getline(ss, token, ';')) {
|
while (std::getline(ss, token, ']')) {
|
||||||
token.erase(std::remove_if(token.begin(), token.end(), ::isspace),
|
// remove spaces and semicolons
|
||||||
|
token.erase(
|
||||||
|
std::remove_if(token.begin(), token.end(),
|
||||||
|
[](char c) { return std::isspace(c) || c == ';'; }),
|
||||||
token.end());
|
token.end());
|
||||||
if (token.empty())
|
if (token.empty())
|
||||||
continue;
|
continue;
|
||||||
if (token.front() != '[' || token.back() != ']') {
|
if (token.front() != '[') {
|
||||||
throw RuntimeError("Each ROI must be enclosed in square brackets: "
|
throw RuntimeError("Each ROI must be enclosed in square brackets: "
|
||||||
"[xmin,xmax,ymin,ymax]");
|
"[xmin,xmax,ymin,ymax]");
|
||||||
}
|
}
|
||||||
token = token.substr(1, token.size() - 2); // remove brackets
|
token = token.substr(1, token.size() - 1); // remove brackets
|
||||||
std::vector<std::string> parts;
|
std::vector<std::string> parts;
|
||||||
std::stringstream inner(token);
|
std::stringstream inner(token);
|
||||||
std::string num;
|
std::string num;
|
||||||
|
|||||||
@@ -507,13 +507,13 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
// vector of rois
|
// vector of rois
|
||||||
// square brackets missing
|
// square brackets missing
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[5, 20, -1, -1; 25, 30, -1, -1]"}, -1, PUT));
|
"rx_roi", {"[5, 20, -1, -1] 25, 30, -1, -1]"}, -1, PUT));
|
||||||
// invalid roi, 4 parts expected
|
// invalid roi, 4 parts expected
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[5, 20, -1]; [25, 30, -1, -1]"}, -1, PUT));
|
"rx_roi", {"[5, 20, -1] [25, 30, -1, -1]"}, -1, PUT));
|
||||||
// overlapping rois
|
// overlapping rois
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[0, 10,-1, -1];[5, 15, -1, -1]"}, -1, PUT));
|
"rx_roi", {"[0, 10,-1, -1] [5, 15, -1, -1]"}, -1, PUT));
|
||||||
|
|
||||||
if (det.size() == 2) {
|
if (det.size() == 2) {
|
||||||
auto moduleSize = det.getModuleSize()[0];
|
auto moduleSize = det.getModuleSize()[0];
|
||||||
@@ -527,7 +527,8 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
"[" + stringMin + ", " + stringMax + ", -1, -1]"},
|
"[" + stringMin + ", " + stringMax + ", -1, -1]"},
|
||||||
-1, PUT));
|
-1, PUT));
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
// separated by semicolon is allowed
|
// separated by semicolon with quotes is allowed (skips
|
||||||
|
// cmdParser)
|
||||||
REQUIRE_NOTHROW(caller.call("rx_roi",
|
REQUIRE_NOTHROW(caller.call("rx_roi",
|
||||||
{"[5, 10, -1, -1];[" + stringMin +
|
{"[5, 10, -1, -1];[" + stringMin +
|
||||||
", " + stringMax + ", -1, -1]"},
|
", " + stringMax + ", -1, -1]"},
|
||||||
@@ -598,15 +599,15 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
// vector of rois
|
// vector of rois
|
||||||
// square brackets missing
|
// square brackets missing
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[5, 20, 20, 30; 25, 30, 14, 15]"}, -1, PUT));
|
"rx_roi", {"[5, 20, 20, 30] 25, 30, 14, 15]"}, -1, PUT));
|
||||||
// invalid roi, 4 parts expected
|
// invalid roi, 4 parts expected
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[5, 20, 20]; [25, 30, 14, 15]"}, -1, PUT));
|
"rx_roi", {"[5, 20, 20] [25, 30, 14, 15]"}, -1, PUT));
|
||||||
// overlapping rois
|
// overlapping rois
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[0, 10, 0, 10];[5, 15, 0, 10]"}, -1, PUT));
|
"rx_roi", {"[0, 10, 0, 10] [5, 15, 0, 10]"}, -1, PUT));
|
||||||
REQUIRE_THROWS(caller.call(
|
REQUIRE_THROWS(caller.call(
|
||||||
"rx_roi", {"[0, 10, 0, 10];[0, 10, 9, 11]"}, -1, PUT));
|
"rx_roi", {"[0, 10, 0, 10] [0, 10, 9, 11]"}, -1, PUT));
|
||||||
|
|
||||||
int numinterfaces = det.getNumberofUDPInterfaces().tsquash(
|
int numinterfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||||
"inconsistent number of interfaces");
|
"inconsistent number of interfaces");
|
||||||
@@ -624,7 +625,8 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
"[" + stringMin + ", " + stringMax + ", 20, 30]"},
|
"[" + stringMin + ", " + stringMax + ", 20, 30]"},
|
||||||
-1, PUT));
|
-1, PUT));
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
// separated by semicolon is allowed
|
// separated by semicolon with quotes is allowed (skips
|
||||||
|
// cmdParser)
|
||||||
REQUIRE_NOTHROW(caller.call("rx_roi",
|
REQUIRE_NOTHROW(caller.call("rx_roi",
|
||||||
{"[5, 10, 20, 30];[" + stringMin +
|
{"[5, 10, 20, 30];[" + stringMin +
|
||||||
", " + stringMax + ", 20, 30]"},
|
", " + stringMax + ", 20, 30]"},
|
||||||
@@ -676,7 +678,8 @@ TEST_CASE("rx_roi", "[.cmdcall]") {
|
|||||||
", " + stringMax + "]"},
|
", " + stringMax + "]"},
|
||||||
-1, PUT));
|
-1, PUT));
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
// separated by semicolon is allowed
|
// separated by semicolon is allowed with quotes (skips
|
||||||
|
// cmdParser)
|
||||||
REQUIRE_NOTHROW(
|
REQUIRE_NOTHROW(
|
||||||
caller.call("rx_roi",
|
caller.call("rx_roi",
|
||||||
{"[5, 10, 20, 30];[25, 28, " + stringMin +
|
{"[5, 10, 20, 30];[25, 28, " + stringMin +
|
||||||
|
|||||||
Reference in New Issue
Block a user