From b9a346a396205e51dcc100cf4213e9b2eb9c3816 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 31 May 2023 21:07:07 +0200 Subject: [PATCH] ctb adc names (#757) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * first draft of adc names * fixed tests * formatting * added python functions in src --------- Co-authored-by: Erik Fröjdh --- python/slsdet/detector.py | 16 +- python/src/detector.cpp | 23 ++ slsDetectorSoftware/include/sls/Detector.h | 21 ++ slsDetectorSoftware/src/CmdProxy.cpp | 216 ++++++++++++++++--- slsDetectorSoftware/src/CmdProxy.h | 17 +- slsDetectorSoftware/src/CtbConfig.cpp | 56 ++++- slsDetectorSoftware/src/CtbConfig.h | 11 +- slsDetectorSoftware/src/Detector.cpp | 40 ++++ slsDetectorSoftware/src/DetectorImpl.cpp | 20 ++ slsDetectorSoftware/src/DetectorImpl.h | 6 + slsDetectorSoftware/tests/test-CmdProxy.cpp | 184 +++++++++++++++- slsDetectorSoftware/tests/test-CtbConfig.cpp | 4 +- 12 files changed, 564 insertions(+), 50 deletions(-) diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 427077bec..75bd6538d 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -1766,7 +1766,7 @@ class Detector(CppDetectorApi): @property def daclist(self): """ - List of enums for every dac for this detector. + List of enums/names for every dac for this detector. :setter: Only implemented for Chiptestboard """ @@ -1776,6 +1776,20 @@ class Detector(CppDetectorApi): def daclist(self, value): self.setDacNames(value) + @property + def adclist(self): + """ + List of names for every adc for this detector. + :setter: Only implemented for Chiptestboard + + """ + return self.getAdcNames() + + @adclist.setter + def adclist(self, value): + self.setAdcNames(value) + + @property def dacvalues(self): """Gets the dac values for every dac for this detector.""" diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 9d7fba35e..57dd585db 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -1647,10 +1647,33 @@ void init_det(py::module &m) { (defs::dacIndex(Detector::*)(const std::string &)) & Detector::getDacIndex, py::arg()); + CppDetectorApi.def( + "setDacName", + (void (Detector::*)(defs::dacIndex, const std::string &)) & + Detector::setDacName, + py::arg(), py::arg()); CppDetectorApi.def("getDacName", (std::string(Detector::*)(defs::dacIndex)) & Detector::getDacName, py::arg()); + CppDetectorApi.def("setAdcNames", + (void (Detector::*)(const std::vector)) & + Detector::setAdcNames, + py::arg()); + CppDetectorApi.def("getAdcNames", + (std::vector(Detector::*)() const) & + Detector::getAdcNames); + CppDetectorApi.def("getAdcIndex", + (int (Detector::*)(const std::string &)) & + Detector::getAdcIndex, + py::arg()); + CppDetectorApi.def("setAdcName", + (void (Detector::*)(const int, const std::string &)) & + Detector::setAdcName, + py::arg(), py::arg()); + CppDetectorApi.def("getAdcName", + (std::string(Detector::*)(int)) & Detector::getAdcName, + py::arg()); CppDetectorApi.def( "setPattern", (void (Detector::*)(const std::string &, sls::Positions)) & diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 68ffb5f0e..237bfa5a6 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1721,12 +1721,33 @@ class Detector { /** [CTB] Default is enabled. */ void setLEDEnable(bool enable, Positions pos = {}); + /** [CTB] */ void setDacNames(const std::vector names); std::vector getDacNames() const; defs::dacIndex getDacIndex(const std::string &name); + + /** [CTB] */ + void setDacName(defs::dacIndex i, const std::string &name); + std::string getDacName(defs::dacIndex i); + + /** [CTB] */ + void setAdcNames(const std::vector names); + + /** [CTB] */ + std::vector getAdcNames() const; + + /** [CTB] */ + int getAdcIndex(const std::string &name); + + /** [CTB] */ + void setAdcName(const int i, const std::string &name); + + /** [CTB] */ + std::string getAdcName(int i); + ///@} /** @name Pattern */ diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index e05f9d900..ec78a3981 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1127,6 +1127,187 @@ std::string CmdProxy::TemperatureValues(int action) { return os.str(); } +/* list */ +std::string CmdProxy::DacList(const int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == slsDetectorDefs::HELP_ACTION) { + os << "\n\t[dacname1 dacname2 .. dacname18] \n\t\t[ChipTestBoard] Set " + "the list of dac names for this detector.\n\t\t[All] Gets the " + "list of dac names for every dac for this detector." + << '\n'; + } else if (action == slsDetectorDefs::GET_ACTION) { + if (!args.empty()) { + WrongNumberOfParameters(0); + } + auto t = det->getDacNames(); + os << ToString(t) << '\n'; + } else if (action == slsDetectorDefs::PUT_ACTION) { + if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { + throw RuntimeError("This detector already has fixed dac " + "names. Cannot change them."); + } + if (det_id != -1) { + throw RuntimeError("Cannot configure dacnames at module level"); + } + det->setDacNames(args); + os << ToString(args) << '\n'; + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::DacName(const int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == slsDetectorDefs::HELP_ACTION) { + os << "\n\t[0-18][name] \n\t\t[ChipTestBoard] Set " + "the dac at the given position to the given name." + << '\n'; + return os.str(); + } + if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { + throw RuntimeError("Named Dacs only allowed for CTB."); + } + defs::dacIndex index = static_cast(StringTo(args[0])); + if (action == slsDetectorDefs::GET_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + auto t = det->getDacName(index); + os << args[0] << ' ' << ToString(t) << '\n'; + } else if (action == slsDetectorDefs::PUT_ACTION) { + if (det_id != -1) { + throw RuntimeError("Cannot configure dacnames at module level"); + } + if (args.size() != 2) { + WrongNumberOfParameters(2); + } + det->setDacName(index, args[1]); + os << ToString(args) << '\n'; + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::DacIndex(const int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == slsDetectorDefs::HELP_ACTION) { + os << "\n\t[name] \n\t\t[ChipTestBoard] Get " + "the dac index for the given name." + << '\n'; + return os.str(); + } + if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { + throw RuntimeError("Named Dacs only allowed for CTB."); + } + if (action == slsDetectorDefs::GET_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + auto t = det->getDacIndex(args[0]); + os << ToString(static_cast(t)) << '\n'; + } else if (action == slsDetectorDefs::PUT_ACTION) { + throw RuntimeError("Cannot set dac index"); + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::AdcList(const int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == slsDetectorDefs::HELP_ACTION) { + os << "\n\t[adcname1 adcname2 .. adcname32] \n\t\t[ChipTestBoard] Set " + "the list of adc names for this board." + << '\n'; + return os.str(); + } + if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { + throw RuntimeError("Named Adcs only allowed for CTB."); + } + if (action == slsDetectorDefs::GET_ACTION) { + if (!args.empty()) { + WrongNumberOfParameters(0); + } + auto t = det->getAdcNames(); + os << ToString(t) << '\n'; + } else if (action == slsDetectorDefs::PUT_ACTION) { + if (det_id != -1) { + throw RuntimeError("Cannot configure adcnames at module level"); + } + det->setAdcNames(args); + os << ToString(args) << '\n'; + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::AdcName(const int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == slsDetectorDefs::HELP_ACTION) { + os << "\n\t[0-31][name] \n\t\t[ChipTestBoard] Set " + "the adc at the given position to the given name." + << '\n'; + return os.str(); + } + if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { + throw RuntimeError("Named Adcs only allowed for CTB."); + } + int index = StringTo(args[0]); + if (action == slsDetectorDefs::GET_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + auto t = det->getAdcName(index); + os << args[0] << ' ' << ToString(t) << '\n'; + } else if (action == slsDetectorDefs::PUT_ACTION) { + if (det_id != -1) { + throw RuntimeError("Cannot configure adcnames at module level"); + } + if (args.size() != 2) { + WrongNumberOfParameters(2); + } + det->setAdcName(index, args[1]); + os << ToString(args) << '\n'; + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + +std::string CmdProxy::AdcIndex(const int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == slsDetectorDefs::HELP_ACTION) { + os << "\n\t[name] \n\t\t[ChipTestBoard] Get " + "the adc index for the given name." + << '\n'; + return os.str(); + } + if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { + throw RuntimeError("Named Adcs only allowed for CTB."); + } + if (action == slsDetectorDefs::GET_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + auto t = det->getAdcIndex(args[0]); + os << ToString(t) << '\n'; + } else if (action == slsDetectorDefs::PUT_ACTION) { + throw RuntimeError("Cannot set adc index"); + } else { + throw RuntimeError("Unknown action"); + } + return os.str(); +} + /* dacs */ std::string CmdProxy::Dac(int action) { std::ostringstream os; @@ -1205,41 +1386,6 @@ std::string CmdProxy::Dac(int action) { return os.str(); } -std::string CmdProxy::DacList(const int action) { - std::ostringstream os; - os << cmd << ' '; - if (action == slsDetectorDefs::HELP_ACTION) { - os << "\n\t[dacname1 dacname2 .. dacname18] \n\t\t[ChipTestBoard] Set " - "the list of dac names for this detector.\n\t\t[All] Gets the " - "list " - "of " - "dac names for every dac for this detector." - << '\n'; - } else if (action == slsDetectorDefs::GET_ACTION) { - if (!args.empty()) { - WrongNumberOfParameters(0); - } - auto t = det->getDacNames(); - os << ToString(t) << '\n'; - } else if (action == slsDetectorDefs::PUT_ACTION) { - if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { - throw RuntimeError("This detector already has fixed dac " - "names. Cannot change them."); - } - if (det_id != -1) { - throw RuntimeError("Cannot configure dacnames at module level"); - } - if (args.size() != 18) { - WrongNumberOfParameters(18); - } - det->setDacNames(args); - os << ToString(args) << '\n'; - } else { - throw RuntimeError("Unknown action"); - } - return os.str(); -} - std::string CmdProxy::DacValues(int action) { std::ostringstream os; os << cmd << ' '; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index e378753f1..21d63c0d8 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -842,9 +842,16 @@ class CmdProxy { {"temp_fpgafr", &CmdProxy::temp_fpgafr}, {"temp_slowadc", &CmdProxy::temp_slowadc}, + /* lists */ + {"daclist", &CmdProxy::DacList}, + {"dacname", &CmdProxy::DacName}, + {"dacindex", &CmdProxy::DacIndex}, + {"adclist", &CmdProxy::AdcList}, + {"adcname", &CmdProxy::AdcName}, + {"adcindex", &CmdProxy::AdcIndex}, + /* dacs */ {"dac", &CmdProxy::Dac}, - {"daclist", &CmdProxy::DacList}, {"dacvalues", &CmdProxy::DacValues}, {"resetdacs", &CmdProxy::ResetDacs}, {"defaultdac", &CmdProxy::DefaultDac}, @@ -1142,9 +1149,15 @@ class CmdProxy { std::string CurrentSource(int action); /** temperature */ std::string TemperatureValues(int action); + /* list */ + std::string DacList(int action); + std::string DacName(int action); + std::string DacIndex(int action); + std::string AdcList(int action); + std::string AdcName(int action); + std::string AdcIndex(int action); /* dacs */ std::string Dac(int action); - std::string DacList(int action); std::string DacValues(int action); std::string ResetDacs(int action); std::string DefaultDac(int action); diff --git a/slsDetectorSoftware/src/CtbConfig.cpp b/slsDetectorSoftware/src/CtbConfig.cpp index f5ee27d0e..57d61ce7b 100644 --- a/slsDetectorSoftware/src/CtbConfig.cpp +++ b/slsDetectorSoftware/src/CtbConfig.cpp @@ -14,12 +14,23 @@ CtbConfig::CtbConfig() { for (size_t i = 0; i != num_dacs; ++i) { setDacName(i, "dac" + ToString(i)); } + for (size_t i = 0; i != num_adcs; ++i) { + setAdcName(i, "adc" + ToString(i)); + } } -void CtbConfig::check_index(size_t i) const { +void CtbConfig::check_dac_index(size_t i) const { if (!(i < num_dacs)) { std::ostringstream oss; - oss << "DAC index is too large needs to be below " << num_dacs; + oss << "DAC index is too large. Needs to be below " << num_dacs; + throw RuntimeError(oss.str()); + } +} + +void CtbConfig::check_adc_index(size_t i) const { + if (!(i < num_adcs)) { + std::ostringstream oss; + oss << "ADC index is too large.Needs to be below " << num_adcs; throw RuntimeError(oss.str()); } } @@ -29,7 +40,7 @@ void CtbConfig::check_size(const std::string &name) const { if (name.empty()) throw RuntimeError("Name needs to be at least one character"); - // dacname_length -1 to account for \0 termination + // dac/adc name_length -1 to account for \0 termination if (!(name.size() < (name_length - 1))) { std::ostringstream oss; oss << "Length of name needs to be less than " << name_length - 1 @@ -39,22 +50,25 @@ void CtbConfig::check_size(const std::string &name) const { } void CtbConfig::setDacName(size_t index, const std::string &name) { - - check_index(index); + check_dac_index(index); check_size(name); - char *dst = &dacnames[index * name_length]; memset(dst, '\0', name_length); memcpy(dst, &name[0], name.size()); } void CtbConfig::setDacNames(const std::vector &names) { + if (names.size() != num_dacs) { + throw RuntimeError("Dac names need to be of size " + + std::to_string(num_dacs)); + } for (size_t i = 0; i != num_dacs; ++i) { setDacName(i, names[i]); } } std::string CtbConfig::getDacName(size_t index) const { + check_dac_index(index); return dacnames + index * name_length; } @@ -65,6 +79,36 @@ std::vector CtbConfig::getDacNames() const { return names; } +void CtbConfig::setAdcName(size_t index, const std::string &name) { + check_adc_index(index); + check_size(name); + char *dst = &adcnames[index * name_length]; + memset(dst, '\0', name_length); + memcpy(dst, &name[0], name.size()); +} + +void CtbConfig::setAdcNames(const std::vector &names) { + if (names.size() != num_adcs) { + throw RuntimeError("Adc names need to be of size " + + std::to_string(num_adcs)); + } + for (size_t i = 0; i != num_adcs; ++i) { + setAdcName(i, names[i]); + } +} + +std::string CtbConfig::getAdcName(size_t index) const { + check_adc_index(index); + return adcnames + index * name_length; +} + +std::vector CtbConfig::getAdcNames() const { + std::vector names; + for (size_t i = 0; i != num_adcs; ++i) + names.push_back(getAdcName(i)); + return names; +} + const char *CtbConfig::shm_tag() { return shm_tag_; } } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/CtbConfig.h b/slsDetectorSoftware/src/CtbConfig.h index 3de6dd128..505a55b96 100644 --- a/slsDetectorSoftware/src/CtbConfig.h +++ b/slsDetectorSoftware/src/CtbConfig.h @@ -6,10 +6,13 @@ namespace sls { class CtbConfig { static constexpr size_t name_length = 20; static constexpr size_t num_dacs = 18; + static constexpr size_t num_adcs = 32; static constexpr const char *shm_tag_ = "ctbdacs"; char dacnames[name_length * num_dacs]{}; + char adcnames[name_length * num_adcs]{}; - void check_index(size_t i) const; + void check_dac_index(size_t i) const; + void check_adc_index(size_t i) const; void check_size(const std::string &name) const; public: @@ -23,6 +26,12 @@ class CtbConfig { void setDacName(size_t index, const std::string &name); std::string getDacName(size_t index) const; std::vector getDacNames() const; + + void setAdcNames(const std::vector &names); + void setAdcName(size_t index, const std::string &name); + std::string getAdcName(size_t index) const; + std::vector getAdcNames() const; + static const char *shm_tag(); }; diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 39277b11e..4731f1b0d 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2231,6 +2231,12 @@ defs::dacIndex Detector::getDacIndex(const std::string &name) { return StringTo(name); } +void Detector::setDacName(defs::dacIndex i, const std::string &name) { + if (getDetectorType().squash() != defs::CHIPTESTBOARD) + throw RuntimeError("Named dacs only for CTB"); + pimpl->setCtbDacName(i, name); +} + std::string Detector::getDacName(defs::dacIndex i) { auto type = getDetectorType().squash(); if (type == defs::CHIPTESTBOARD) @@ -2238,6 +2244,40 @@ std::string Detector::getDacName(defs::dacIndex i) { return ToString(i); } +void Detector::setAdcNames(const std::vector names) { + if (getDetectorType().squash() != defs::CHIPTESTBOARD) + throw RuntimeError("Named adcs only for CTB"); + pimpl->setCtbAdcNames(names); +} + +std::vector Detector::getAdcNames() const { + if (getDetectorType().squash() != defs::CHIPTESTBOARD) + throw RuntimeError("Named adcs only for CTB"); + return pimpl->getCtbAdcNames(); +} + +int Detector::getAdcIndex(const std::string &name) { + if (getDetectorType().squash() != defs::CHIPTESTBOARD) + throw RuntimeError("Named adcs only for CTB"); + auto names = getAdcNames(); + auto it = std::find(names.begin(), names.end(), name); + if (it == names.end()) + throw RuntimeError("Adcname not found"); + return (it - names.begin()); +} + +void Detector::setAdcName(const int index, const std::string &name) { + if (getDetectorType().squash() != defs::CHIPTESTBOARD) + throw RuntimeError("Named adcs only for CTB"); + pimpl->setCtbAdcName(index, name); +} + +std::string Detector::getAdcName(int i) { + if (getDetectorType().squash() != defs::CHIPTESTBOARD) + throw RuntimeError("Named adcs only for CTB"); + return pimpl->getCtbAdcName(i); +} + // Pattern void Detector::setPattern(const std::string &fname, Positions pos) { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 27e779ad4..f4d80eaac 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -2001,4 +2001,24 @@ std::string DetectorImpl::getCtbDacName(defs::dacIndex i) const { return ctb_shm()->getDacName(static_cast(i)); } +void DetectorImpl::setCtbDacName(const int index, const std::string &name) { + ctb_shm()->setDacName(index, name); +} + +std::vector DetectorImpl::getCtbAdcNames() const { + return ctb_shm()->getAdcNames(); +} + +void DetectorImpl::setCtbAdcNames(const std::vector &names) { + ctb_shm()->setAdcNames(names); +} + +std::string DetectorImpl::getCtbAdcName(int i) const { + return ctb_shm()->getAdcName(i); +} + +void DetectorImpl::setCtbAdcName(const int index, const std::string &name) { + ctb_shm()->setAdcName(index, name); +} + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index 53d2d9a63..2d51f75b4 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -328,6 +328,12 @@ class DetectorImpl : public virtual slsDetectorDefs { std::vector getCtbDacNames() const; std::string getCtbDacName(defs::dacIndex i) const; void setCtbDacNames(const std::vector &names); + void setCtbDacName(const int index, const std::string &name); + + std::vector getCtbAdcNames() const; + std::string getCtbAdcName(int i) const; + void setCtbAdcNames(const std::vector &names); + void setCtbAdcName(const int index, const std::string &name); private: /** diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 9734fe292..74b9312cc 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -1929,15 +1929,193 @@ TEST_CASE("temp_fpga", "[.cmd]") { } } -/* dacs */ +/* list */ TEST_CASE("daclist", "[.cmd]") { Detector det; CmdProxy proxy(&det); - REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET)); - REQUIRE_THROWS(proxy.Call("daclist", {}, -1, PUT)); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::CHIPTESTBOARD) { + REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET)); + + auto prev = det.getDacNames(); + REQUIRE_THROWS(proxy.Call("daclist", {"a", "s", "d"}, -1, PUT)); + + std::vector names; + for (int iarg = 0; iarg != 18; ++iarg) { + names.push_back("a"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(proxy.Call("daclist", names, -1, PUT, oss)); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET, oss)); + REQUIRE(oss.str() == + std::string("daclist ") + ToString(names) + '\n'); + } + det.setDacNames(prev); + + } else { + REQUIRE_THROWS(proxy.Call("daclist", {"a", "b"}, -1, PUT)); + REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET)); + } } +TEST_CASE("adclist", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::CHIPTESTBOARD) { + auto prev = det.getAdcNames(); + + REQUIRE_THROWS(proxy.Call("adclist", {"a", "s", "d"}, -1, PUT)); + + std::vector names; + for (int iarg = 0; iarg != 32; ++iarg) { + names.push_back("a"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(proxy.Call("adclist", names, -1, PUT, oss)); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(proxy.Call("adclist", {}, -1, GET, oss)); + REQUIRE(oss.str() == + std::string("adclist ") + ToString(names) + '\n'); + } + det.setAdcNames(prev); + + } else { + REQUIRE_THROWS(proxy.Call("adclist", {"a", "b"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("adclist", {}, -1, GET)); + } +} + +TEST_CASE("dacname", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::CHIPTESTBOARD) { + defs::dacIndex ind = static_cast(2); + std::string str_dac_index = "2"; + auto prev = det.getDacName(ind); + + // 1 arg throw + REQUIRE_THROWS(proxy.Call("dacname", {"2", "3", "bname"}, -1, PUT)); + // invalid index + REQUIRE_THROWS(proxy.Call("dacname", {"18", "bname"}, -1, PUT)); + { + std::ostringstream oss; + REQUIRE_NOTHROW( + proxy.Call("dacname", {str_dac_index, "bname"}, -1, PUT, oss)); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW( + proxy.Call("dacname", {str_dac_index}, -1, GET, oss)); + REQUIRE(oss.str() == + std::string("dacname ") + str_dac_index + " bname\n"); + } + det.setDacName(ind, prev); + + } else { + REQUIRE_THROWS(proxy.Call("dacname", {"2", "b"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("dacname", {"2"}, -1, GET)); + } +} + +TEST_CASE("adcname", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::CHIPTESTBOARD) { + int ind = 2; + std::string str_adc_index = "2"; + auto prev = det.getAdcName(ind); + + // 1 arg throw + REQUIRE_THROWS(proxy.Call("adcname", {"2", "3", "bname"}, -1, PUT)); + // invalid index + REQUIRE_THROWS(proxy.Call("adcname", {"32", "bname"}, -1, PUT)); + { + std::ostringstream oss; + REQUIRE_NOTHROW( + proxy.Call("adcname", {str_adc_index, "bname"}, -1, PUT, oss)); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW( + proxy.Call("adcname", {str_adc_index}, -1, GET, oss)); + REQUIRE(oss.str() == + std::string("adcname ") + str_adc_index + " bname\n"); + } + det.setAdcName(ind, prev); + + } else { + REQUIRE_THROWS(proxy.Call("adcname", {"2", "b"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("adcname", {"2"}, -1, GET)); + } +} + +TEST_CASE("dacindex", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::CHIPTESTBOARD) { + defs::dacIndex ind = static_cast(2); + std::string str_dac_index = "2"; + + // 1 arg throw + REQUIRE_THROWS(proxy.Call("dacindex", {"2", "2"}, -1, PUT)); + // invalid index + REQUIRE_THROWS(proxy.Call("dacindex", {"18"}, -1, PUT)); + auto dacname = det.getDacName(ind); + { + std::ostringstream oss; + REQUIRE_NOTHROW(proxy.Call("dacindex", {dacname}, -1, GET, oss)); + REQUIRE(oss.str() == + std::string("dacindex ") + str_dac_index + '\n'); + } + } else { + REQUIRE_THROWS(proxy.Call("dacindex", {"2"}, -1, GET)); + } +} + +TEST_CASE("adcindex", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + + if (det_type == defs::CHIPTESTBOARD) { + int ind = 2; + std::string str_adc_index = "2"; + + // 1 arg throw + REQUIRE_THROWS(proxy.Call("adcindex", {"2", "2"}, -1, PUT)); + // invalid index + REQUIRE_THROWS(proxy.Call("adcindex", {"32"}, -1, PUT)); + auto adcname = det.getAdcName(ind); + { + std::ostringstream oss; + REQUIRE_NOTHROW(proxy.Call("adcindex", {adcname}, -1, GET, oss)); + REQUIRE(oss.str() == + std::string("adcindex ") + str_adc_index + '\n'); + } + } else { + REQUIRE_THROWS(proxy.Call("adcindex", {"2"}, -1, GET)); + } +} + +/* dacs */ + TEST_CASE("dacvalues", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsDetectorSoftware/tests/test-CtbConfig.cpp b/slsDetectorSoftware/tests/test-CtbConfig.cpp index 391a37565..85799c4b4 100644 --- a/slsDetectorSoftware/tests/test-CtbConfig.cpp +++ b/slsDetectorSoftware/tests/test-CtbConfig.cpp @@ -10,8 +10,8 @@ namespace sls { TEST_CASE("Default construction") { - static_assert(sizeof(CtbConfig) == 360, - "Size of CtbConfig does not match"); // 18*20 + static_assert(sizeof(CtbConfig) == ((18 + 32) * 20), + "Size of CtbConfig does not match"); CtbConfig c; auto names = c.getDacNames();