From f591adccb8f388a9ee4d937e2b3ff35346f2842f Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 18 Apr 2019 09:33:14 +0200 Subject: [PATCH] added getPatternLoop --- .../include/multiSlsDetector.h | 6 +- slsDetectorSoftware/include/slsDetector.h | 5 +- slsDetectorSoftware/src/multiSlsDetector.cpp | 10 ++- slsDetectorSoftware/src/slsDetector.cpp | 43 ++++++++-- .../src/slsDetectorCommand.cpp | 85 +++++++++++-------- slsSupportLib/include/container_utils.h | 13 +++ slsSupportLib/include/sls_detector_defs.h | 3 - slsSupportLib/tests/test-container_utils.cpp | 12 +++ 8 files changed, 127 insertions(+), 50 deletions(-) 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