From 19b85b8e407d9998bd2dbee1a7760b511528dd67 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 28 Oct 2019 11:56:15 +0100 Subject: [PATCH] WIP --- slsDetectorSoftware/include/CmdProxy.h | 8 +- .../include/slsDetectorCommand.h | 2 - slsDetectorSoftware/src/Detector.cpp | 8 +- slsDetectorSoftware/src/multiSlsDetector.cpp | 8 +- .../src/slsDetectorCommand.cpp | 60 --------------- .../tests/test-multiSlsDetectorClient.cpp | 45 +++++++++++ slsSupportLib/include/ToString.h | 53 ++++++++++++- slsSupportLib/include/sls_detector_defs.h | 74 ------------------- 8 files changed, 112 insertions(+), 146 deletions(-) diff --git a/slsDetectorSoftware/include/CmdProxy.h b/slsDetectorSoftware/include/CmdProxy.h index 06c741e40..287109dbf 100644 --- a/slsDetectorSoftware/include/CmdProxy.h +++ b/slsDetectorSoftware/include/CmdProxy.h @@ -736,7 +736,8 @@ class CmdProxy { {"rx_jsonpara", &CmdProxy::JsonParameter}, {"emin", &CmdProxy::MinMaxEnergyThreshold}, {"emax", &CmdProxy::MinMaxEnergyThreshold}, - + {"framemode", &CmdProxy::framemode}, + {"detectormode", &CmdProxy::detectormode}, @@ -1276,6 +1277,11 @@ class CmdProxy { STRING_COMMAND(rx_jsonaddheader, getAdditionalJsonHeader, setAdditionalJsonHeader, "[\"label1\":\"value1\"], [\"label2\":\"value2\"]\n\tAdditional json header to be streamd out from receiver via zmq. Default is empty. Use only if to be processed by an intermediate user process listening to receiver zmq packets."); + INTEGER_COMMAND(framemode, getFrameMode, setFrameMode, sls::StringTo, + "[pedestal|newpedestal|flatfield|newflatfield]\n\t[Moench] Frame mode (soft setting) in processor."); + + INTEGER_COMMAND(detectormode, getDetectorMode, setDetectorMode, sls::StringTo, + "[counting|interpolating|analog]\n\t[Moench] Detector mode (soft setting) in processor."); diff --git a/slsDetectorSoftware/include/slsDetectorCommand.h b/slsDetectorSoftware/include/slsDetectorCommand.h index 0feb441ef..982339968 100755 --- a/slsDetectorSoftware/include/slsDetectorCommand.h +++ b/slsDetectorSoftware/include/slsDetectorCommand.h @@ -57,7 +57,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs { static std::string helpAdvanced(int action); static std::string helpConfiguration(int action); static std::string helpReceiver(int action); - static std::string helpProcessor(int action); private: multiSlsDetector *myDet; @@ -81,7 +80,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdAdvanced(int narg, const char * const args[], int action, int detPos = -1); std::string cmdConfiguration(int narg, const char * const args[], int action, int detPos = -1); std::string cmdReceiver(int narg, const char * const args[], int action, int detPos = -1); - std::string cmdProcessor(int narg, const char * const args[], int action, int detPos = -1); int numberOfCommands; std::string cmd; diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0746bb4ef..91e1db2fc 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1426,7 +1426,7 @@ Result Detector::getFrameMode(Positions pos) const { Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { - intResult[i] = defs::getFrameModeType(res[i]); + intResult[i] = sls::StringTo(res[i]); } } catch (...) { throw RuntimeError( @@ -1437,7 +1437,7 @@ Result Detector::getFrameMode(Positions pos) const { void Detector::setFrameMode(defs::frameModeType value, Positions pos) { pimpl->Parallel(&slsDetector::setAdditionalJsonParameter, pos, "frameMode", - defs::getFrameModeType(value)); + sls::ToString(value)); } Result Detector::getDetectorMode(Positions pos) const { @@ -1446,7 +1446,7 @@ Result Detector::getDetectorMode(Positions pos) const { Result intResult(res.size()); try { for (unsigned int i = 0; i < res.size(); ++i) { - intResult[i] = defs::getDetectorModeType(res[i]); + intResult[i] = sls::StringTo(res[i]); } } catch (...) { throw RuntimeError( @@ -1457,7 +1457,7 @@ Result Detector::getDetectorMode(Positions pos) const { void Detector::setDetectorMode(defs::detectorModeType value, Positions pos) { pimpl->Parallel(&slsDetector::setAdditionalJsonParameter, pos, - "detectorMode", defs::getDetectorModeType(value)); + "detectorMode", sls::ToString(value)); } // Advanced diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index e6acb9e9b..4dfd84ba9 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -1406,11 +1406,11 @@ int multiSlsDetector::setFrameMode(frameModeType value, int detPos) { if (value == GET_FRAME_MODE) { result = getAdditionalJsonParameter(parameter, detPos); } else { - result = setAdditionalJsonParameter(parameter, getFrameModeType(value), + result = setAdditionalJsonParameter(parameter, sls::ToString(value), detPos); } - return getFrameModeType(result); + return sls::StringTo(result); } int multiSlsDetector::setDetectorMode(detectorModeType value, int detPos) { @@ -1421,10 +1421,10 @@ int multiSlsDetector::setDetectorMode(detectorModeType value, int detPos) { result = getAdditionalJsonParameter(parameter, detPos); } else { result = setAdditionalJsonParameter(parameter, - getDetectorModeType(value), detPos); + sls::ToString(value), detPos); } - return getDetectorModeType(result); + return sls::StringTo(result); } int64_t multiSlsDetector::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize, diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index a89f95fa7..85cd2b2b8 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -932,23 +932,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { /* pattern generator */ - /*! \page prototype Chip Test Board / Moench - Commands specific for the chiptest board or moench - */ - - /*! \page prototype - - framemode [i] Sets/gets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield - */ - descrToFuncMap[i].m_pFuncName = "framemode"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; - ++i; - - /*! \page prototype - - detectormode [i] Sets/gets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog - */ - descrToFuncMap[i].m_pFuncName = "detectormode"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; - ++i; numberOfCommands = i; @@ -2065,47 +2048,4 @@ std::string slsDetectorCommand::helpReceiver(int action) { -std::string slsDetectorCommand::helpProcessor(int action) { - - std::ostringstream os; - if (action == PUT_ACTION || action == HELP_ACTION) { - os << "framemode [n] \t Sets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield" << std::endl; - os << "detectormode [n] \t Sets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog" << std::endl; - } - if (action == GET_ACTION || action == HELP_ACTION) { - os << "framemode [n] \t Gets frame mode for Moench (soft setting in processor). Options: pedestal, newpedestal, flatfield, newflatfield" << std::endl; - os << "detectormode [n] \t Gets detector mode for Moench (soft setting in processor). Options: counting, interpolating, analog" << std::endl; - } - return os.str(); -} - -std::string slsDetectorCommand::cmdProcessor(int narg, const char * const args[], int action, int detPos) { - if (action == HELP_ACTION) - return helpProcessor(action); - - - - if (cmd == "framemode") { - if (action == PUT_ACTION) { - frameModeType ival = getFrameModeType(args[1]); - if (ival == GET_FRAME_MODE) - return std::string("cannot parse frame mode value"); - myDet->setFrameMode(ival, detPos); - } - return getFrameModeType(frameModeType(myDet->setFrameMode(GET_FRAME_MODE, detPos))); - } - - else if (cmd == "detectormode") { - if (action == PUT_ACTION) { - detectorModeType ival = getDetectorModeType(args[1]); - if (ival == GET_DETECTOR_MODE) - return std::string("cannot parse detector mode value"); - myDet->setDetectorMode(ival, detPos); - } - return getDetectorModeType(detectorModeType(myDet->setDetectorMode(GET_DETECTOR_MODE, detPos))); - } - return std::string("unknown command"); -} - - diff --git a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp index b659e9b0a..438139b75 100644 --- a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp @@ -9,6 +9,51 @@ auto GET = slsDetectorDefs::GET_ACTION; auto PUT = slsDetectorDefs::PUT_ACTION; +TEST_CASE("detectormode", "[.cmd][.moench]") { + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("detectormode counting", PUT, nullptr, oss)); + REQUIRE(oss.str() == "detectormode counting\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("detectormode interpolating", PUT, nullptr, oss)); + REQUIRE(oss.str() == "detectormode interpolating\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("detectormode analog", PUT, nullptr, oss)); + REQUIRE(oss.str() == "detectormode analog\n"); + } + REQUIRE_NOTHROW(multiSlsDetectorClient("detectormode counting", PUT)); + REQUIRE_THROWS(multiSlsDetectorClient("detectormode pedestal", PUT)); +} + +TEST_CASE("framemode", "[.cmd][.moench]") { + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("framemode pedestal", PUT, nullptr, oss)); + REQUIRE(oss.str() == "framemode pedestal\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("framemode newpedestal", PUT, nullptr, oss)); + REQUIRE(oss.str() == "framemode newpedestal\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("framemode flatfield", PUT, nullptr, oss)); + REQUIRE(oss.str() == "framemode flatfield\n"); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("framemode newflatfield", PUT, nullptr, oss)); + REQUIRE(oss.str() == "framemode newflatfield\n"); + } + REQUIRE_NOTHROW(multiSlsDetectorClient("framemode pedestal", PUT)); + REQUIRE_THROWS(multiSlsDetectorClient("framemode counting", PUT)); +} + TEST_CASE("emin", "[.cmd][.moench]") { { std::ostringstream oss; diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index 00d671d5d..6b6ff5aa7 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -176,6 +176,34 @@ inline std::string ToString(const defs::readoutMode s){ } } +inline std::string ToString(const defs::frameModeType s){ + switch (s) { + case defs::PEDESTAL: + return std::string("pedestal"); + case defs::NEW_PEDESTAL: + return std::string("newpedestal"); + case defs::FLATFIELD: + return std::string("flatfield"); + case defs::NEW_FLATFIELD: + return std::string("newflatfield"); + default: + return std::string("Unknown"); + } +} + +inline std::string ToString(const defs::detectorModeType s){ + switch (s) { + case defs::COUNTING: + return std::string("counting"); + case defs::INTERPOLATING: + return std::string("interpolating"); + case defs::ANALOG: + return std::string("analog"); + default: + return std::string("Unknown"); + } +} + // in case we already have a string // causes a copy but might be needed in generic code inline std::string ToString(const std::string& s){ @@ -468,11 +496,34 @@ inline defs::readoutMode StringTo(const std::string& s) { return defs::ANALOG_ONLY; if (s == "digital") return defs::DIGITAL_ONLY; - if (s == "analog_digital") + if (s == "analog_digital") return defs::ANALOG_AND_DIGITAL; throw sls::RuntimeError("Unknown readout mode " + s); } +template <> +inline defs::frameModeType StringTo(const std::string& s) { + if (s == "pedestal") + return defs::PEDESTAL; + if (s == "newpedestal") + return defs::NEW_PEDESTAL; + if (s == "flatfield") + return defs::FLATFIELD; + if (s == "newflatfield") + return defs::NEW_FLATFIELD; + throw sls::RuntimeError("Unknown frame mode " + s); +} + +template <> +inline defs::detectorModeType StringTo(const std::string& s) { + if (s == "counting") + return defs::COUNTING; + if (s == "interpolating") + return defs::INTERPOLATING; + if (s == "analog") + return defs::ANALOG; + throw sls::RuntimeError("Unknown detector mode " + s); +} /** For types with a .str() method use this for conversion */ template diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 313347209..36ef8fb94 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -662,80 +662,6 @@ format }; - /** - * returns frameModeType as enum - * @param s pedestal, newpedestal, flatfield, newflatfield - * @returns PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD, GET_FRAME_MODE - * (if unknown) - */ - static frameModeType getFrameModeType(std::string s) { - for (auto &c : s) - c = std::tolower(c); - if (s == "pedestal") - return PEDESTAL; - if (s == "newpedestal") - return NEW_PEDESTAL; - if (s == "flatfield") - return FLATFIELD; - if (s == "newflatfield") - return NEW_FLATFIELD; - return GET_FRAME_MODE; - } - - /** - * returns frameModeType as string - * @param f PEDESTAL, NEW_PEDESTAL, FLATFIELD, NEW_FLATFIELD - * @return string pedestal, newpedestal, flatfield, newflatfield, unknown - */ - static std::string getFrameModeType(frameModeType f) { - switch (f) { - case PEDESTAL: - return std::string("pedestal"); - case NEW_PEDESTAL: - return std::string("newPedestal"); - case FLATFIELD: - return std::string("flatfield"); - case NEW_FLATFIELD: - return std::string("newFlatfield"); - default: - return std::string("unknown"); - } - } - - /** - * returns detectorModeType as enum - * @param s counting, interpolating, analog - * @returns COUNTING, INTERPOLATING, ANALOG, GET_DETECTOR_MODE (if unknown) - */ - static detectorModeType getDetectorModeType(std::string s) { - for (auto &c : s) - c = std::tolower(c); - if (s == "counting") - return COUNTING; - if (s == "interpolating") - return INTERPOLATING; - if (s == "analog") - return ANALOG; - return GET_DETECTOR_MODE; - } - - /** - * returns frameModeType as string - * @param f COUNTING, INTERPOLATING, ANALOG - * @return string counting, interpolating, analog, unknown - */ - static std::string getDetectorModeType(detectorModeType f) { - switch (f) { - case COUNTING: - return std::string("counting"); - case INTERPOLATING: - return std::string("interpolating"); - case ANALOG: - return std::string("analog"); - default: - return std::string("unknown"); - } - } #endif