diff --git a/python/scripts/basic.py b/python/scripts/basic.py index b4808fb66..561ce38e4 100755 --- a/python/scripts/basic.py +++ b/python/scripts/basic.py @@ -17,7 +17,7 @@ e = ExperimentalDetector() -a = read_my302_file('/home/l_frojdh/Downloads/run_d0_5.raw', 104, 24) +# a = read_my302_file('/home/l_frojdh/Downloads/run_d0_5.raw', 104, 24) # ncols = 192 # start = 600 # end = 1800 diff --git a/python/sls_detector/detector.py b/python/sls_detector/detector.py index 3a6a7a366..389cb57ed 100755 --- a/python/sls_detector/detector.py +++ b/python/sls_detector/detector.py @@ -1355,6 +1355,38 @@ class Detector: self._api.configureNetworkParameters() + #TODO! can we make this one function? + @property + def patnloop0(self): + return self._api.getPatternLoops(0, -1) + + @patnloop0.setter + def patnloop0(self, n): + self._api.setPatternLoops(0, -1, -1, n, -1) + + @property + def patnloop1(self): + return self._api.getPatternLoops(1, -1) + + @patnloop1.setter + def patnloop1(self, n): + self._api.setPatternLoops(1, -1, -1, n, -1) + + @property + def patnloop2(self): + return self._api.getPatternLoops(2, -1) + + @patnloop2.setter + def patnloop2(self, n): + self._api.setPatternLoops(2, -1, -1, n, -1) + + def setPatternWord(self, addr, word, det_id = -1): + self._api.setPatternWord(addr, word, det_id) + + def setPatternLoops(self, level, start, stop, n, det_id=-1): + self._api.setPatternLoops(level, start, stop, n, det_id) + + def free_shared_memory(multi_id=0): """ Function to free the shared memory but do not initialize with new diff --git a/python/src/Detector.h b/python/src/Detector.h index 9dc574bc6..28fca8053 100755 --- a/python/src/Detector.h +++ b/python/src/Detector.h @@ -1,12 +1,12 @@ #ifndef DETECTOR_H #define DETECTOR_H +#include #include #include +#include #include #include -#include - #include "error_defs.h" #include "multiSlsDetector.h" #include "slsDetector.h" @@ -244,6 +244,21 @@ class Detector { std::vector getRateCorrection(); + + + void setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, + uint64_t n, int detPos) { + det.setPatternLoops(level, start, stop, n, detPos); + } + + std::array getPatternLoops(uint64_t level, int detPos) { + return det.getPatternLoops(level, detPos); + } + + void setPatternWord(int addr, uint64_t word, int detPos){ + det.setPatternWord(addr, word, detPos); + } + bool getFlippedDataX(int i) { return det.getFlippedData(slsDetectorDefs::dimension::X, i); } diff --git a/python/src/main.cpp b/python/src/main.cpp index f2a591c5e..0d8babd75 100755 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -262,6 +262,10 @@ PYBIND11_MODULE(_sls_detector, m) .def("getTenGigabitEthernet", &Detector::getTenGigabitEthernet) .def("setTenGigabitEthernet", &Detector::setTenGigabitEthernet) + .def("getPatternLoops", &Detector::getPatternLoops) + .def("setPatternLoops", &Detector::setPatternLoops) + .def("setPatternWord", &Detector::setPatternWord) + .def("getImageSize", &Detector::getImageSize) .def("setImageSize", &Detector::setImageSize) .def("getNumberOfDetectors", &Detector::getNumberOfDetectors) @@ -269,6 +273,7 @@ PYBIND11_MODULE(_sls_detector, m) + //Experimental API to use the multi directly and inherit from to reduce //code duplication need to investigate how to handle documentation py::class_ multiDetectorApi(m, "multiDetectorApi"); @@ -283,6 +288,9 @@ py::class_ multiDetectorApi(m, "multiDetectorApi"); py::cpp_function(&multiSlsDetector::getDetectorNumber)) .def("_getReceiverUDPIP", &multiSlsDetector::getReceiverUDPIP) .def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP) + .def("_getPatternLoops", &multiSlsDetector::getPatternLoops) + .def("_setPatternLoops", &multiSlsDetector::setPatternLoops) + .def("_setPatternWord", &multiSlsDetector::setPatternWord) ; py::module io = m.def_submodule("io", "Submodule for io"); diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 227d47b56..7b8b24bcd 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1824,9 +1824,13 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns OK/FAIL */ - int setPatternLoops(int level, int &start, int &stop, int &n, + int setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n, int detPos = -1); + + + std::array getPatternLoops(uint64_t level, int detPos = -1); + /** * Sets the wait address in the CTB * @param level 0,1,2, wait level diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 2d9f54289..5d5fa0467 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -10,6 +10,7 @@ class ClientInterface; #include #include +#include class multiSlsDetector; class ServerInterface; @@ -1657,7 +1658,9 @@ class slsDetector : public virtual slsDetectorDefs{ * @param n number of loops (if level >=0) * @returns OK/FAIL */ - int setPatternLoops(int level, int &start, int &stop, int &n); + int setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n); + + std::array getPatternLoops(uint64_t level); /** * Sets the wait address in the CTB diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index b4fcfefe5..11a819bd8 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -3602,7 +3602,7 @@ uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) { return sls::minusOneIfDifferent(r); } -int multiSlsDetector::setPatternLoops(int level, int &start, int &stop, int &n, int detPos) { +int multiSlsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n, int detPos) { // single if (detPos >= 0) { return detectors[detPos]->setPatternLoops(level, start, stop, n); @@ -3616,6 +3616,14 @@ int multiSlsDetector::setPatternLoops(int level, int &start, int &stop, int &n, return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; } +std::array multiSlsDetector::getPatternLoops(uint64_t level, int detPos){ + if (detPos >= 0) + return detectors[detPos]->getPatternLoops(level); + + auto r = parallelCall(&slsDetector::getPatternLoops, level); + return sls::minusOneIfDifferent(r); +} + int multiSlsDetector::setPatternWaitAddr(int level, int addr, int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 70e253ef3..6d60ebe30 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -4498,14 +4498,12 @@ uint64_t slsDetector::setPatternWord(uint64_t addr, uint64_t word) { return retval; } -int slsDetector::setPatternLoops(int level, int &start, int &stop, int &n) { - // TODO!(Erik) Should we change function signature to accept uint64_t? +int slsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, + uint64_t n) { int fnum = F_SET_PATTERN; int ret = FAIL; uint64_t mode = 1; // sets loop - uint64_t args[5]{mode, static_cast(level), - static_cast(start), static_cast(stop), - static_cast(n)}; + uint64_t args[]{mode, level, start, stop, n}; int retvals[3]{}; FILE_LOG(logDEBUG1) << "Setting Pat Loops, level: " << level << ", start: " << start << ", stop: " << stop @@ -4518,9 +4516,9 @@ int slsDetector::setPatternLoops(int level, int &start, int &stop, int &n) { sizeof(retvals)); FILE_LOG(logDEBUG1) << "Set Pat Loops: " << retvals[0] << ", " << retvals[1] << ", " << retvals[2]; - start = retvals[0]; - stop = retvals[1]; - n = retvals[2]; + assert(start == retvals[0]); + assert(stop == retvals[1]); + assert(n == retvals[2]); } if (ret == FORCE_UPDATE) { updateDetector(); @@ -4528,6 +4526,35 @@ int slsDetector::setPatternLoops(int level, int &start, int &stop, int &n) { return ret; } +std::array slsDetector::getPatternLoops(uint64_t level) { + int fnum = F_SET_PATTERN; + int ret = FAIL; + uint64_t mode = 1; // sets loop + uint64_t args[]{mode, level, static_cast(-1), + static_cast(-1), static_cast(-1)}; + int retvals[3]{}; + FILE_LOG(logDEBUG1) << "Setting Pat Loops, level: " << level + << ", start: " << -1 << ", stop: " << -1 + << ", n: " << -1; + + if (detector_shm()->onlineFlag == ONLINE_FLAG) { + auto client = DetectorSocket(detector_shm()->hostname, + detector_shm()->controlPort); + ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals, + sizeof(retvals)); + FILE_LOG(logDEBUG1) << "Get Pat Loops: " << retvals[0] << ", " + << retvals[1] << ", " << retvals[2]; + } + if (ret == FORCE_UPDATE) { + updateDetector(); + } + std::array r{}; + r[0] = retvals[0]; + r[1] = retvals[1]; + r[2] = retvals[2]; + return r; +} + int slsDetector::setPatternWaitAddr(uint64_t level, uint64_t addr) { int fnum = F_SET_PATTERN; int ret = FAIL; diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 21fd974fa..7cd5fcbb3 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -5295,11 +5295,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(-1, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(-1, start, stop, n, detPos); - os << std::hex << start << " " << stop; // << " "<< std::dec << n ; + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(-1, start, stop, n, detPos); + auto r = myDet->getPatternLoops(-1, detPos); + os << std::hex << r[0] << " " << r[1]; + // os << std::hex << start << " " << stop; // << " "<< std::dec << n ; } else if (cmd == "patloop0") { //get start, stop from stdin @@ -5321,11 +5323,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(0, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(0, start, stop, n, detPos); - os << std::hex << start << " " << stop; // << " "<< std::dec << n ; + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(0, start, stop, n, detPos); + // os << std::hex << start << " " << stop; // << " "<< std::dec << n ; + auto r = myDet->getPatternLoops(0, detPos); + os << std::hex << r[0] << " " << r[1]; } else if (cmd == "patloop1") { @@ -5347,11 +5351,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(1, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(1, start, stop, n, detPos); - os << std::hex << start << " " << stop; // << " "<< std::dec << n ; + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(1, start, stop, n, detPos); + // os << std::hex << start << " " << stop; // << " "<< std::dec << n ; + auto r = myDet->getPatternLoops(1, detPos); + os << std::hex << r[0] << " " << r[1]; } else if (cmd == "patloop2") { @@ -5373,12 +5379,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(2, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(2, start, stop, n, detPos); - os << std::hex << start << " " << stop << std::dec; // << " "<< std::dec << n ; - + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(2, start, stop, n, detPos); + // os << std::hex << start << " " << stop << std::dec; // << " "<< std::dec << n ; + auto r = myDet->getPatternLoops(2, detPos); + os << std::hex << r[0] << " " << r[1]; } else if (cmd == "patnloop0") { start = -1; stop = -1; @@ -5393,11 +5400,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(0, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(0, start, stop, n, detPos); - os << n; + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(0, start, stop, n, detPos); + // os << n; + auto r = myDet->getPatternLoops(0, detPos); + os << std::hex << r[2]; } else if (cmd == "patnloop1") { start = -1; @@ -5413,11 +5422,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(1, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(1, start, stop, n, detPos); - os << n; + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(1, start, stop, n, detPos); + // os << n; + auto r = myDet->getPatternLoops(1, detPos); + os << std::hex << r[2]; } else if (cmd == "patnloop2") { @@ -5434,11 +5445,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i myDet->setPatternLoops(2, start, stop, n, detPos); } - start = -1; - stop = -1; - n = -1; - myDet->setPatternLoops(2, start, stop, n, detPos); - os << n; + // start = -1; + // stop = -1; + // n = -1; + // myDet->setPatternLoops(2, start, stop, n, detPos); + // os << n; + auto r = myDet->getPatternLoops(2, detPos); + os << std::hex << r[2]; } else if (cmd == "patwait0") { diff --git a/slsSupportLib/include/container_utils.h b/slsSupportLib/include/container_utils.h index ede320f4e..0f325dd36 100755 --- a/slsSupportLib/include/container_utils.h +++ b/slsSupportLib/include/container_utils.h @@ -109,6 +109,19 @@ minusOneIfDifferent(const std::vector> &container) { return std::vector{-1}; } +template +std::array +minusOneIfDifferent(const std::vector> &container) { + if (allEqual(container)) + return container.front(); + + std::array arr; + arr.fill(static_cast(-1)); + return arr; +} + + + } // namespace sls #endif // CONTAINER_UTILS_H diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 88ed58e23..1c3e69552 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -1040,7 +1040,6 @@ typedef struct { int *chanregs; /**< is the pointer to the array of the channel registers */ #ifdef __cplusplus - sls_detector_module() : serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0), tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {} @@ -1049,8 +1048,6 @@ typedef struct { detParameters parameters{type}; int nch = parameters.nChanX * parameters.nChanY; int nc = parameters.nChipX * parameters.nChipY; - // int nd = parameters.nDacs; - ndac = parameters.nDacs; nchip = nc; nchan = nch * nc; diff --git a/slsSupportLib/tests/test-container_utils.cpp b/slsSupportLib/tests/test-container_utils.cpp index b2403d551..061f832f6 100755 --- a/slsSupportLib/tests/test-container_utils.cpp +++ b/slsSupportLib/tests/test-container_utils.cpp @@ -122,4 +122,16 @@ TEST_CASE("vector of bool", "[support]"){ CHECK(minusOneIfDifferent(a) == 1); CHECK(minusOneIfDifferent(b) == 0); CHECK(minusOneIfDifferent(c) == -1); +} + +TEST_CASE("compare a vector of arrays", "[support]"){ + + std::vector> vec0{{5,6,8},{5,6,8},{5,6,8}}; + CHECK(minusOneIfDifferent(vec0) == std::array{5,6,8}); + + std::array arr; + arr.fill(-1); + std::vector> vec1{{5,90,8},{5,6,8},{5,6,8}}; + CHECK(minusOneIfDifferent(vec1) == arr); + } \ No newline at end of file