From de7f4489af1d2ade10742911c00d9b773952fb8c Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 28 Jul 2021 20:11:58 +0200 Subject: [PATCH] defaultdac upto detector side, settings is undefined when none given --- slsDetectorSoftware/include/sls/Detector.h | 19 +++++++ slsDetectorSoftware/src/CmdProxy.cpp | 41 +++++++++++++++ slsDetectorSoftware/src/CmdProxy.h | 2 + slsDetectorSoftware/src/Detector.cpp | 37 +++++++++++++ slsDetectorSoftware/src/Module.cpp | 10 ++++ slsDetectorSoftware/src/Module.h | 5 +- slsDetectorSoftware/tests/test-CmdProxy.cpp | 52 +++++++++++++++++++ .../include/sls/sls_detector_funcs.h | 4 ++ 8 files changed, 169 insertions(+), 1 deletion(-) diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 0ec970b34..81b7ea70d 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -412,6 +412,21 @@ class Detector { /** gets list of dac enums for this detector */ std::vector getDacList() const; + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + Result getDefaultDac(defs::dacIndex index, Positions pos = {}); + + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + void setDefaultDac(defs::dacIndex index, int defaultValue, + Positions pos = {}); + + /** [Jungfrau][Mythen3] */ + Result getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, + Positions pos = {}); + + /** [Jungfrau][Mythen3] */ + void setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos = {}); + /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ void setDefaultDacs(Positions pos = {}); @@ -1779,6 +1794,10 @@ class Detector { void updateRxRateCorrections(); void setNumberofUDPInterfaces_(int n, Positions pos); Result getNumberofUDPInterfaces_(Positions pos) const; + Result getDefaultDac_(defs::dacIndex index, + defs::detectorSettings sett, Positions pos = {}); + void setDefaultDac_(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos = {}); }; } // namespace sls diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 019019c42..502baaa3f 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1095,6 +1095,47 @@ std::string CmdProxy::DacValues(int action) { return os.str(); } +std::string CmdProxy::DefaultDac(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[dac name][value][(optional)setting]\n\tSets the default for " + "that dac to this value.\n\t[Jungfrau][Mythen3] When settings is " + "provided, it sets the default value only for that setting" + << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() < 1) { + WrongNumberOfParameters(1); + } + // optional settings + if (args.size() == 2) { + auto t = det->getDefaultDac( + StringTo(args[0]), + sls::StringTo(args[1])); + os << ToString(args) << ' ' << OutString(t) << '\n'; + } else { + auto t = det->getDefaultDac(StringTo(args[0])); + os << args[0] << ' ' << OutString(t) << '\n'; + } + } else if (action == defs::PUT_ACTION) { + if (args.size() < 2) { + WrongNumberOfParameters(2); + } + // optional settings + if (args.size() == 3) { + det->setDefaultDac( + StringTo(args[0]), StringTo(args[1]), + sls::StringTo(args[2])); + } else { + det->setDefaultDac(StringTo(args[0]), + StringTo(args[1])); + } + os << ToString(args) << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} /* acquisition */ std::string CmdProxy::ReceiverStatus(int action) { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 22618489b..ced9be101 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -817,6 +817,7 @@ class CmdProxy { {"daclist", &CmdProxy::daclist}, {"dacvalues", &CmdProxy::DacValues}, {"defaultdacs", &CmdProxy::defaultdacs}, + {"defaultdac", &CmdProxy::DefaultDac}, /* on chip dacs */ {"vchip_comp_fe", &CmdProxy::vchip_comp_fe}, @@ -1094,6 +1095,7 @@ class CmdProxy { /* dacs */ std::string Dac(int action); std::string DacValues(int action); + std::string DefaultDac(int action); /* acquisition */ std::string ReceiverStatus(int action); std::string DetectorStatus(int action); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index a865559bb..6d4d0462b 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -620,6 +620,43 @@ std::vector Detector::getDacList() const { return retval; } +Result Detector::getDefaultDac(defs::dacIndex index, Positions pos) { + return getDefaultDac_(index, defs::UNDEFINED, pos); +} + +void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, + Positions pos) { + setDefaultDac_(index, defaultValue, defs::UNDEFINED, pos); +} + +Result Detector::getDefaultDac(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos) { + if (sett == defs::UNDEFINED) { + throw RuntimeError("Invalid settings given for default dac"); + } + return getDefaultDac_(index, sett, pos); +} + +void Detector::setDefaultDac(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos) { + if (sett == defs::UNDEFINED) { + throw RuntimeError("Invalid settings given for default dac"); + } + setDefaultDac_(index, defaultValue, sett, pos); +} + +Result Detector::getDefaultDac_(defs::dacIndex index, + defs::detectorSettings sett, + Positions pos) { + return pimpl->Parallel(&Module::getDefaultDac, pos, index, sett); +} + +void Detector::setDefaultDac_(defs::dacIndex index, int defaultValue, + defs::detectorSettings sett, Positions pos) { + pimpl->Parallel(&Module::setDefaultDac, pos, index, defaultValue, sett); +} + void Detector::setDefaultDacs(Positions pos) { pimpl->Parallel(&Module::setDefaultDacs, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 03d67f030..e06775498 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -618,6 +618,16 @@ int Module::getDAC(dacIndex index, bool mV) const { int args[]{static_cast(index), static_cast(mV), GET_FLAG}; return sendToDetector(F_SET_DAC, args); } +int Module::getDefaultDac(slsDetectorDefs::dacIndex index, + slsDetectorDefs::detectorSettings sett) { + int args[]{static_cast(index), static_cast(sett)}; + return sendToDetector(F_GET_DEFAULT_DAC, args); +} +void Module::setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, + defs::detectorSettings sett) { + int args[]{static_cast(index), static_cast(sett), defaultValue}; + return sendToDetector(F_SET_DEFAULT_DAC, args, nullptr); +} void Module::setDefaultDacs() { sendToDetector(F_SET_DEFAULT_DACS); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index e9a5663a9..f3fda46a1 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -148,7 +148,10 @@ class Module : public virtual slsDetectorDefs { int getMaxClockPhaseShift(int clkIndex) const; int getClockFrequency(int clkIndex) const; void setClockFrequency(int clkIndex, int value); - /** [Eiger][Jungfrau][Moench][Gotthard][Gotthard2][Mythen3] */ + int getDefaultDac(slsDetectorDefs::dacIndex index, + slsDetectorDefs::detectorSettings sett); + void setDefaultDac(slsDetectorDefs::dacIndex index, int defaultValue, + defs::detectorSettings sett); void setDefaultDacs(); int getDAC(dacIndex index, bool mV) const; void setDAC(int val, dacIndex index, bool mV); diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 984a3fd51..03edb1c6c 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -1407,6 +1407,58 @@ TEST_CASE("dacvalues", "[.cmd]") { REQUIRE_THROWS(proxy.Call("dacvalues", {}, -1, PUT)); } +TEST_CASE("defaultdac", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + REQUIRE_THROWS(proxy.Call("defaultdac", {}, -1, GET)); + REQUIRE_THROWS(proxy.Call("defaultdac", {"blabla"}, -1, PUT)); + auto daclist = det.getDacList(); + for (auto it : daclist) { + auto dacname = sls::ToString(it); + auto prev_val = det.getDefaultDac(it); + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "1000"}, -1, PUT, oss); + REQUIRE(oss.str() == std::string("defaultdac [") + dacname + + std::string(", 1000]\n")); + } + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname}, -1, GET, oss); + REQUIRE(oss.str() == std::string("defaultdac ") + dacname + + std::string(" 1000\n")); + } + for (int i = 0; i != det.size(); ++i) { + det.setDefaultDac(it, prev_val[i], {i}); + } + } + auto det_type = det.getDetectorType().squash(); + if (det_type != defs::JUNGFRAU) { + std::vector daclist = {defs::VB_COMP, defs::VREF_DS, + defs::VREF_COMP}; + for (auto it : daclist) { + auto dacname = sls::ToString(it); + auto prev_val = det.getDefaultDac(it, defs::DYNAMICGAIN); + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname, "1000", "dynamicgain"}, -1, + PUT, oss); + REQUIRE(oss.str() == std::string("defaultdac [") + dacname + + std::string(", dynamicgain, 1000]\n")); + } + { + std::ostringstream oss; + proxy.Call("defaultdac", {dacname}, -1, GET, oss); + REQUIRE(oss.str() == std::string("defaultdac [") + dacname + + std::string(", dynamicgain] 1000\n")); + } + for (int i = 0; i != det.size(); ++i) { + det.setDefaultDac(it, prev_val[i], defs::DYNAMICGAIN, {i}); + } + } + } +} + TEST_CASE("defaultdacs", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index f517fd26a..27d783094 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -231,6 +231,8 @@ enum detFuncs { F_GET_VETO_ALGORITHM, F_SET_VETO_ALGORITHM, F_GET_CHIP_VERSION, + F_GET_DEFAULT_DAC, + F_SET_DEFAULT_DAC, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -568,6 +570,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_VETO_ALGORITHM: return "F_GET_VETO_ALGORITHM"; case F_SET_VETO_ALGORITHM: return "F_SET_VETO_ALGORITHM"; case F_GET_CHIP_VERSION: return "F_GET_CHIP_VERSION"; + case F_GET_DEFAULT_DAC: return "F_GET_DEFAULT_DAC"; + case F_SET_DEFAULT_DAC: return "F_SET_DEFAULT_DAC"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";