mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-13 20:08:41 +01:00
wip to parse vector of rois at command line
This commit is contained in:
@@ -10594,7 +10594,7 @@ std::string Caller::rx_arping(int action) {
|
||||
|
||||
return os.str();
|
||||
}
|
||||
/*
|
||||
|
||||
std::string Caller::rx_clearroi(int action) {
|
||||
|
||||
std::ostringstream os;
|
||||
@@ -10637,7 +10637,7 @@ std::string Caller::rx_clearroi(int action) {
|
||||
|
||||
return os.str();
|
||||
}
|
||||
*/
|
||||
|
||||
std::string Caller::rx_dbitoffset(int action) {
|
||||
|
||||
std::ostringstream os;
|
||||
|
||||
@@ -21,6 +21,7 @@ class Caller {
|
||||
UdpDestination getUdpEntry();
|
||||
int GetLevelAndInsertIntoArgs(std::string levelSeparatedCommand);
|
||||
void WrongNumberOfParameters(size_t expected);
|
||||
std::vector<defs::ROI> parseRoiVector(const std::string &input);
|
||||
|
||||
template <typename V> std::string OutStringHex(const V &value) {
|
||||
if (value.equal())
|
||||
@@ -233,7 +234,7 @@ class Caller {
|
||||
std::string runclk(int action);
|
||||
std::string runtime(int action);
|
||||
std::string rx_arping(int action);
|
||||
//std::string rx_clearroi(int action);
|
||||
std::string rx_clearroi(int action);
|
||||
std::string rx_dbitlist(int action);
|
||||
std::string rx_dbitoffset(int action);
|
||||
std::string rx_dbitreorder(int action);
|
||||
@@ -251,7 +252,7 @@ class Caller {
|
||||
std::string rx_padding(int action);
|
||||
std::string rx_printconfig(int action);
|
||||
std::string rx_realudpsocksize(int action);
|
||||
//std::string rx_roi(int action);
|
||||
std::string rx_roi(int action);
|
||||
std::string rx_silent(int action);
|
||||
std::string rx_start(int action);
|
||||
std::string rx_status(int action);
|
||||
@@ -580,7 +581,7 @@ class Caller {
|
||||
{"runclk", &Caller::runclk},
|
||||
{"runtime", &Caller::runtime},
|
||||
{"rx_arping", &Caller::rx_arping},
|
||||
//{"rx_clearroi", &Caller::rx_clearroi},
|
||||
{"rx_clearroi", &Caller::rx_clearroi},
|
||||
{"rx_dbitlist", &Caller::rx_dbitlist},
|
||||
{"rx_dbitoffset", &Caller::rx_dbitoffset},
|
||||
{"rx_dbitreorder", &Caller::rx_dbitreorder},
|
||||
@@ -598,7 +599,7 @@ class Caller {
|
||||
{"rx_padding", &Caller::rx_padding},
|
||||
{"rx_printconfig", &Caller::rx_printconfig},
|
||||
{"rx_realudpsocksize", &Caller::rx_realudpsocksize},
|
||||
//{"rx_roi", &Caller::rx_roi},
|
||||
{"rx_roi", &Caller::rx_roi},
|
||||
{"rx_silent", &Caller::rx_silent},
|
||||
{"rx_start", &Caller::rx_start},
|
||||
{"rx_status", &Caller::rx_status},
|
||||
|
||||
@@ -719,50 +719,124 @@ std::string Caller::rx_zmqip(int action) {
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
/* TODO
|
||||
|
||||
std::string Caller::rx_roi(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[xmin] [xmax] [ymin] [ymax]\n\tRegion of interest in "
|
||||
"receiver.\n\tOnly allowed at multi module level and without gap "
|
||||
"receiver.\n\t"
|
||||
<< "For a list of rois, use '[' and '];' to distinguish between "
|
||||
"rois and use comma inside the square brackets.\n\t"
|
||||
<< "For example: [0, 100, 0, 100];[200, 300, 0, 100] will set two "
|
||||
"rois.\n\t"
|
||||
<< "Only allowed at multi module level and without gap "
|
||||
"pixels."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (!args.empty()) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
if (det_id == -1) {
|
||||
auto t = det->getRxROI();
|
||||
os << t << '\n';
|
||||
if (det_id != -1) {
|
||||
throw RuntimeError("Cannot execute receiver ROI at module level");
|
||||
} else {
|
||||
auto t = det->getIndividualRxROIs(std::vector<int>{det_id});
|
||||
os << t << '\n';
|
||||
auto t = det->getRxROI();
|
||||
// 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) {
|
||||
defs::ROI t;
|
||||
// 2 or 4 arguments
|
||||
if (args.size() != 2 && args.size() != 4) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
if (args.size() == 2 || args.size() == 4) {
|
||||
std::vector<defs::ROI> rois;
|
||||
|
||||
// Support multiple args with bracketed ROIs, or single arg with
|
||||
// semicolon-separated vector
|
||||
bool isVectorInput =
|
||||
std::all_of(args.begin(), args.end(), [](const std::string &a) {
|
||||
return a.find('[') != std::string::npos &&
|
||||
a.find(']') != std::string::npos;
|
||||
});
|
||||
|
||||
// previous format: 2 or 4 separate args
|
||||
if ((args.size() == 2 || args.size() == 4) && !isVectorInput) {
|
||||
defs::ROI t;
|
||||
t.xmin = StringTo<int>(args[0]);
|
||||
t.xmax = StringTo<int>(args[1]);
|
||||
if (args.size() == 4) {
|
||||
t.ymin = StringTo<int>(args[2]);
|
||||
t.ymax = StringTo<int>(args[3]);
|
||||
}
|
||||
rois.emplace_back(t);
|
||||
} else {
|
||||
if (!isVectorInput)
|
||||
WrongNumberOfParameters(2);
|
||||
else {
|
||||
for (const auto &arg : args) {
|
||||
auto subRois = parseRoiVector(arg);
|
||||
rois.insert(rois.end(), subRois.begin(), subRois.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args.size() == 4) {
|
||||
t.ymin = StringTo<int>(args[2]);
|
||||
t.ymax = StringTo<int>(args[3]);
|
||||
}
|
||||
|
||||
// only multi level
|
||||
if (det_id != -1) {
|
||||
throw RuntimeError("Cannot execute receiver ROI at module level");
|
||||
}
|
||||
det->setRxROI(t);
|
||||
os << t << '\n';
|
||||
|
||||
det->setRxROI(rois);
|
||||
// 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 {
|
||||
throw RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}*/
|
||||
}
|
||||
|
||||
std::vector<defs::ROI> Caller::parseRoiVector(const std::string &input) {
|
||||
std::vector<defs::ROI> rois;
|
||||
std::stringstream ss(input);
|
||||
std::string token;
|
||||
|
||||
while (std::getline(ss, token, ';')) {
|
||||
token.erase(std::remove_if(token.begin(), token.end(), ::isspace),
|
||||
token.end());
|
||||
if (token.empty())
|
||||
continue;
|
||||
if (token.front() != '[' || token.back() != ']') {
|
||||
throw RuntimeError("Each ROI must be enclosed in square brackets: "
|
||||
"[xmin,xmax,ymin,ymax]");
|
||||
}
|
||||
token = token.substr(1, token.size() - 2); // remove brackets
|
||||
std::vector<std::string> parts;
|
||||
std::stringstream inner(token);
|
||||
std::string num;
|
||||
while (std::getline(inner, num, ',')) {
|
||||
parts.push_back(num);
|
||||
}
|
||||
|
||||
if (parts.size() != 4) {
|
||||
throw RuntimeError("ROI must have 4 comma-separated integers");
|
||||
}
|
||||
|
||||
defs::ROI roi;
|
||||
roi.xmin = StringTo<int>(parts[0]);
|
||||
roi.xmax = StringTo<int>(parts[1]);
|
||||
roi.ymin = StringTo<int>(parts[2]);
|
||||
roi.ymax = StringTo<int>(parts[3]);
|
||||
rois.emplace_back(roi);
|
||||
}
|
||||
return rois;
|
||||
}
|
||||
|
||||
std::string Caller::ratecorr(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == defs::HELP_ACTION) {
|
||||
|
||||
@@ -1367,12 +1367,10 @@ void Detector::setRxArping(bool value, Positions pos) {
|
||||
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(); }
|
||||
|
||||
// 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) {
|
||||
pimpl->setRxROI(args);
|
||||
}
|
||||
|
||||
@@ -1380,7 +1378,6 @@ void Detector::clearRxROI() { pimpl->clearRxROI(); }
|
||||
|
||||
int Detector::getNumberOfUdpPortsInRxROI() const {
|
||||
return pimpl->getNumberOfUdpPortsInRxROI();
|
||||
|
||||
}
|
||||
|
||||
// File
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
|
||||
DetectorImpl::DetectorImpl(int detector_index, bool verify, bool update)
|
||||
: detectorIndex(detector_index), shm(detector_index, -1),
|
||||
ctb_shm(detector_index, -1, CtbConfig::shm_tag()) {
|
||||
@@ -536,7 +535,7 @@ void DetectorImpl::readFrameFromReceiver() {
|
||||
bool quadEnable = false;
|
||||
// to flip image
|
||||
bool eiger = false;
|
||||
std::array<int, 4> rxRoi {};//TODO: get roi from json header
|
||||
std::array<int, 4> rxRoi{}; // TODO: get roi from json header
|
||||
|
||||
std::vector<bool> runningList(zmqSocket.size());
|
||||
std::vector<bool> connectList(zmqSocket.size());
|
||||
@@ -1703,44 +1702,53 @@ std::vector<defs::ROI> DetectorImpl::getRxROI() const {
|
||||
throw RuntimeError("No Modules added");
|
||||
}
|
||||
|
||||
return std::vector<defs::ROI>{};
|
||||
//TODO
|
||||
// return std::vector<defs::ROI>{};
|
||||
return rxRoiTemp;
|
||||
// TODO
|
||||
}
|
||||
|
||||
bool DetectorImpl::roisOverlap(const defs::ROI& a, const defs::ROI& b) {
|
||||
return !(a.xmax < b.xmin || a.xmin > b.xmax ||
|
||||
a.ymax < b.ymin || a.ymin > b.ymax);
|
||||
|
||||
bool DetectorImpl::roisOverlap(const defs::ROI &a, const defs::ROI &b) {
|
||||
return !(a.xmax < b.xmin || a.xmin > b.xmax || a.ymax < b.ymin ||
|
||||
a.ymin > b.ymax);
|
||||
}
|
||||
|
||||
void DetectorImpl::validateROIs(const std::vector<defs::ROI>& rois) {
|
||||
void DetectorImpl::validateROIs(const std::vector<defs::ROI> &rois) {
|
||||
for (size_t i = 0; i < rois.size(); ++i) {
|
||||
const auto& roi = rois[i];
|
||||
const auto &roi = rois[i];
|
||||
|
||||
if (roi.noRoi()) {
|
||||
throw RuntimeError("Invalid Roi of size 0. Roi: " + ToString(roi));
|
||||
}
|
||||
if (roi.completeRoi()) {
|
||||
throw RuntimeError("Did you mean the clear roi command (API: "
|
||||
"clearRxROI, cmd: rx_clearroi) Roi: " + ToString(roi) + "?");
|
||||
"clearRxROI, cmd: rx_clearroi) Roi: " +
|
||||
ToString(roi) + "?");
|
||||
}
|
||||
if (roi.xmin > roi.xmax || roi.ymin > roi.ymax) {
|
||||
throw RuntimeError(
|
||||
"Invalid Roi. xmin/ymin exceeds xmax/ymax. Roi: " + ToString(roi));
|
||||
"Invalid Roi. xmin/ymin exceeds xmax/ymax. Roi: " +
|
||||
ToString(roi));
|
||||
}
|
||||
|
||||
if (roi.xmin < 0 || roi.xmax >= shm()->numberOfChannels.x) {
|
||||
throw RuntimeError("ROI x-dimension outside detector bounds. Roi: " + ToString(roi));
|
||||
throw RuntimeError(
|
||||
"ROI x-dimension outside detector bounds. Roi: " +
|
||||
ToString(roi));
|
||||
}
|
||||
|
||||
bool is2D = (modules[0]->getNumberOfChannels().y > 1 ? true : false);
|
||||
if (is2D) {
|
||||
if (roi.ymin < 0 || roi.ymax >= shm()->numberOfChannels.y) {
|
||||
throw RuntimeError("ROI y-dimension outside detector bounds. Roi: " + ToString(roi));
|
||||
throw RuntimeError(
|
||||
"ROI y-dimension outside detector bounds. Roi: " +
|
||||
ToString(roi));
|
||||
}
|
||||
} else {
|
||||
if ((roi.ymin != -1 && roi.ymin != 0) || (roi.ymax != -1 && roi.ymax != 0)) {
|
||||
throw RuntimeError("Invalid Y range for 1D detector: should be -1. Roi: " + ToString(roi));
|
||||
if ((roi.ymin != -1 && roi.ymin != 0) ||
|
||||
(roi.ymax != -1 && roi.ymax != 0)) {
|
||||
throw RuntimeError(
|
||||
"Invalid Y range for 1D detector: should be -1. Roi: " +
|
||||
ToString(roi));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1753,7 +1761,7 @@ void DetectorImpl::validateROIs(const std::vector<defs::ROI>& rois) {
|
||||
}
|
||||
}
|
||||
|
||||
void DetectorImpl::setRxROI(const std::vector<defs::ROI>& args) {
|
||||
void DetectorImpl::setRxROI(const std::vector<defs::ROI> &args) {
|
||||
if (shm()->detType == CHIPTESTBOARD ||
|
||||
shm()->detType == defs::XILINX_CHIPTESTBOARD) {
|
||||
throw RuntimeError("RxRoi not implemented for this Detector");
|
||||
@@ -1761,18 +1769,18 @@ void DetectorImpl::setRxROI(const std::vector<defs::ROI>& args) {
|
||||
if (modules.size() == 0) {
|
||||
throw RuntimeError("No Modules added");
|
||||
}
|
||||
|
||||
|
||||
validateROIs(args);
|
||||
|
||||
//TODO
|
||||
rxRoiTemp = args;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
void DetectorImpl::clearRxROI() {
|
||||
;// TODO: clear roi
|
||||
}
|
||||
void DetectorImpl::clearRxROI() { rxRoiTemp.clear(); }
|
||||
|
||||
int DetectorImpl::getNumberOfUdpPortsInRxROI() const {
|
||||
return 0;// TODO
|
||||
return 0; // TODO
|
||||
}
|
||||
|
||||
void DetectorImpl::getBadChannels(const std::string &fname,
|
||||
|
||||
@@ -302,7 +302,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
verifyUniqueRxHost(const std::vector<std::string> &names) const;
|
||||
|
||||
std::vector<defs::ROI> getRxROI() const;
|
||||
void setRxROI(const std::vector<defs::ROI>& args);
|
||||
void setRxROI(const std::vector<defs::ROI> &args);
|
||||
void clearRxROI();
|
||||
int getNumberOfUdpPortsInRxROI() const;
|
||||
|
||||
@@ -427,8 +427,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
void verifyUniqueHost(
|
||||
bool isDet, std::vector<std::pair<std::string, uint16_t>> &hosts) const;
|
||||
|
||||
bool roisOverlap(const defs::ROI& a, const defs::ROI& b);
|
||||
void validateROIs(const std::vector<defs::ROI>& rois);
|
||||
bool roisOverlap(const defs::ROI &a, const defs::ROI &b);
|
||||
void validateROIs(const std::vector<defs::ROI> &rois);
|
||||
|
||||
const int detectorIndex{0};
|
||||
SharedMemory<sharedDetector> shm{0, -1};
|
||||
@@ -457,6 +457,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
|
||||
void (*dataReady)(detectorData *, uint64_t, uint32_t, void *){nullptr};
|
||||
void *pCallbackArg{nullptr};
|
||||
|
||||
std::vector<defs::ROI> rxRoiTemp;
|
||||
};
|
||||
|
||||
} // namespace sls
|
||||
@@ -301,9 +301,9 @@ class Module : public virtual slsDetectorDefs {
|
||||
std::array<pid_t, NUM_RX_THREAD_IDS> getReceiverThreadIds() const;
|
||||
bool getRxArping() const;
|
||||
void setRxArping(bool enable);
|
||||
//defs::ROI getRxROI() const;
|
||||
//void setRxROI(const slsDetectorDefs::ROI arg);
|
||||
//void setRxROIMetadata(const slsDetectorDefs::ROI arg);
|
||||
// defs::ROI getRxROI() const;
|
||||
// void setRxROI(const slsDetectorDefs::ROI arg);
|
||||
// void setRxROIMetadata(const slsDetectorDefs::ROI arg);
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
|
||||
Reference in New Issue
Block a user