From 7eafceb0f9c8239ae08845f1865833ffa64a5d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Thu, 27 Aug 2020 16:17:56 +0200 Subject: [PATCH 1/3] Exposing vector of strings for loading parameters (#147) --- python/slsdet/detector.py | 7 ++--- python/src/detector.cpp | 4 +++ slsDetectorSoftware/include/Detector.h | 2 ++ slsDetectorSoftware/src/Detector.cpp | 36 ++++++++++++++------------ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index de2010e4e..7e489e303 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -119,9 +119,10 @@ class Detector(CppDetectorApi): return NotImplementedError("parameters is set only") @parameters.setter - def parameters(self, fname): - fname = ut.make_string_path(fname) - self.loadParameters(fname) + def parameters(self, value): + if isinstance(value, str): + value = ut.make_string_path(value) + self.loadParameters(value) @property def hostname(self): diff --git a/python/src/detector.cpp b/python/src/detector.cpp index ac9c736c8..64548f808 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -36,6 +36,10 @@ void init_det(py::module &m) { (void (Detector::*)(const std::string &)) & Detector::loadParameters, py::arg()) + .def("loadParameters", + (void (Detector::*)(const std::vector &)) & + Detector::loadParameters, + py::arg()) .def("getHostname", (Result(Detector::*)(sls::Positions) const) & Detector::getHostname, diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 8374b29cf..d54eeb042 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -53,6 +53,8 @@ class Detector { /** Shared memory not freed prior. Set up per measurement. */ void loadParameters(const std::string &fname); + void loadParameters(const std::vector& parameters); + Result getHostname(Positions pos = {}) const; /* Frees shared memory, adds detectors to the list */ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 5a02a29a5..91f5001b3 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -60,29 +60,31 @@ void Detector::loadConfig(const std::string &fname) { } void Detector::loadParameters(const std::string &fname) { - CmdProxy proxy(this); - CmdParser parser; - std::ifstream input_file; - input_file.open(fname.c_str(), std::ios_base::in); - if (!input_file.is_open()) { + std::ifstream input_file(fname); + if (!input_file) { throw RuntimeError("Could not open configuration file " + fname + " for reading"); } - std::string current_line; - while (input_file.good()) { - getline(input_file, current_line); - if (current_line.find('#') != std::string::npos) { - current_line.erase(current_line.find('#')); + std::vector parameters; + for (std::string line; std::getline(input_file, line);) { + if (line.find('#') != std::string::npos) { + line.erase(line.find('#')); } - LOG(logDEBUG1) << "current_line after removing comments:\n\t" - << current_line; - if (current_line.length() > 1) { - parser.Parse(current_line); - proxy.Call(parser.command(), parser.arguments(), - parser.detector_id(), defs::PUT_ACTION); + if (line.length() > 1) { + parameters.push_back(line); } } - input_file.close(); + loadParameters(parameters); +} + +void Detector::loadParameters(const std::vector ¶meters) { + CmdProxy proxy(this); + CmdParser parser; + for (const auto ¤t_line : parameters) { + parser.Parse(current_line); + proxy.Call(parser.command(), parser.arguments(), parser.detector_id(), + defs::PUT_ACTION); + } } Result Detector::getHostname(Positions pos) const { From 3954913661a406b733705b1792e41604915a7a90 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 27 Aug 2020 16:45:14 +0200 Subject: [PATCH 2/3] fixed ratecorr 0 in python --- python/slsdet/detector.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 7e489e303..404f4cb38 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -868,6 +868,8 @@ class Detector(CppDetectorApi): @ratecorr.setter def ratecorr(self, tau): + if isinstance(tau, int): + tau = float(tau) self.setRateCorrection(tau) @property From 2e4783f2966ee4ce0d1855ecb70559497b2a8221 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 27 Aug 2020 17:08:53 +0200 Subject: [PATCH 3/3] sort and remove duplicates before sending rxdbitlist --- slsDetectorSoftware/src/Module.cpp | 6 +++++- slsDetectorSoftware/src/Module.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 18ecf7fd5..79e407812 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1863,7 +1863,7 @@ std::vector Module::getReceiverDbitList() const { F_GET_RECEIVER_DBIT_LIST); } -void Module::setReceiverDbitList(const std::vector &list) { +void Module::setReceiverDbitList(std::vector list) { LOG(logDEBUG1) << "Setting Receiver Dbit List"; if (list.size() > 64) { throw sls::RuntimeError("Dbit list size cannot be greater than 64\n"); @@ -1874,6 +1874,10 @@ void Module::setReceiverDbitList(const std::vector &list) { "Dbit list value must be between 0 and 63\n"); } } + std::sort(begin(list), end(list)); + auto last = std::unique(begin(list), end(list)); + list.erase(last, list.end()); + sls::StaticVector arg = list; sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index bc4a36d16..db392fac1 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -442,7 +442,7 @@ class Module : public virtual slsDetectorDefs { bool getExternalSampling() const; void setExternalSampling(bool value); std::vector getReceiverDbitList() const; - void setReceiverDbitList(const std::vector &list); + void setReceiverDbitList(std::vector list); int getReceiverDbitOffset() const; void setReceiverDbitOffset(int value); void setDigitalIODelay(uint64_t pinMask, int delay);