From af16ad4040f8a96851a548d5f24160640766404a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 20 Jul 2021 12:58:05 +0200 Subject: [PATCH] vetoalg: wip --- python/scripts/generate_enums.py | 6 +- python/src/detector.cpp | 4 +- python/src/enums.cpp | 18 +++--- .../src/slsDetectorServer_funcs.c | 4 +- slsDetectorSoftware/include/sls/Detector.h | 15 ++++- slsDetectorSoftware/src/CmdProxy.cpp | 64 +++++++++++++++---- slsDetectorSoftware/src/CmdProxy.h | 3 + slsDetectorSoftware/src/Detector.cpp | 34 +++++++--- slsDetectorSoftware/src/Module.cpp | 11 ++++ slsDetectorSoftware/src/Module.h | 5 ++ .../tests/test-CmdProxy-gotthard2.cpp | 52 +++++++++++++++ slsReceiverSoftware/src/ClientInterface.cpp | 6 +- slsReceiverSoftware/src/Implementation.cpp | 8 +-- slsReceiverSoftware/src/Implementation.h | 8 +-- slsSupportLib/include/sls/ToString.h | 6 +- slsSupportLib/include/sls/sls_detector_defs.h | 24 ++++--- slsSupportLib/src/ToString.cpp | 35 +++++++--- slsSupportLib/tests/test-ToString.cpp | 12 ++-- 18 files changed, 237 insertions(+), 78 deletions(-) diff --git a/python/scripts/generate_enums.py b/python/scripts/generate_enums.py index 7abb7cfc1..25769e429 100644 --- a/python/scripts/generate_enums.py +++ b/python/scripts/generate_enums.py @@ -11,7 +11,7 @@ import subprocess from parse import remove_comments -allow_bitwise_op = ["EthernetInterface"] +allow_bitwise_op = ["ethernetInterface"] op_key = {"operator|": "__or__", "operator&" : "__and__"} @@ -22,7 +22,7 @@ def single_line_enum(line): def extract_enums(lines): - # deal with enum class EthernetInterface : int32_t + # deal with enum class ethernetInterface : int32_t # and normal enum burstMode { line_iter = iter(lines) @@ -89,7 +89,7 @@ def generate_enum_string(enums): #Here add the operators for op in operators: - data.append(f"\n\t.def(\"{op_key[op]}\", py::overload_cast< const slsDetectorDefs::EthernetInterface&, const slsDetectorDefs::EthernetInterface&>(&{op}))") + data.append(f"\n\t.def(\"{op_key[op]}\", py::overload_cast< const slsDetectorDefs::ethernetInterface&, const slsDetectorDefs::ethernetInterface&>(&{op}))") data.append(';\n\n') diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 6ebae6255..f2f5cc07b 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -1075,12 +1075,12 @@ void init_det(py::module &m) { Detector::setVeto, py::arg(), py::arg() = Positions{}) .def("getVetoStream", - (Result(Detector::*)(sls::Positions) + (Result(Detector::*)(sls::Positions) const) & Detector::getVetoStream, py::arg() = Positions{}) .def("setVetoStream", - (void (Detector::*)(const defs::EthernetInterface, + (void (Detector::*)(const defs::ethernetInterface, sls::Positions)) & Detector::setVetoStream, py::arg(), py::arg() = Positions{}) diff --git a/python/src/enums.cpp b/python/src/enums.cpp index 7e2093224..5ce843b6f 100644 --- a/python/src/enums.cpp +++ b/python/src/enums.cpp @@ -278,19 +278,19 @@ void init_enums(py::module &m) { slsDetectorDefs::timingSourceType::TIMING_EXTERNAL) .export_values(); - py::enum_(Defs, "EthernetInterface", + py::enum_(Defs, "ethernetInterface", py::arithmetic()) - .value("NONE", slsDetectorDefs::EthernetInterface::NONE) - .value("I3GBE", slsDetectorDefs::EthernetInterface::I3GBE) - .value("I10GBE", slsDetectorDefs::EthernetInterface::I10GBE) - .value("ALL", slsDetectorDefs::EthernetInterface::ALL) + .value("NONE", slsDetectorDefs::ethernetInterface::NONE) + .value("I3GBE", slsDetectorDefs::ethernetInterface::I3GBE) + .value("I10GBE", slsDetectorDefs::ethernetInterface::I10GBE) + .value("ALL", slsDetectorDefs::ethernetInterface::ALL) .export_values() .def("__or__", - py::overload_cast( + py::overload_cast( &operator|)) .def("__and__", - py::overload_cast( + py::overload_cast( &operator&)); } diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 07abf900b..e6d8091eb 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -8412,7 +8412,7 @@ int get_master(int file_des){ int get_veto_stream(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - enum EthernetInterface retval = NONE; + enum ethernetInterface retval = NONE; LOG(logDEBUG1, ("Getting veto stream\n")); @@ -8429,7 +8429,7 @@ int get_veto_stream(int file_des) { int set_veto_stream(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - enum EthernetInterface arg = 0; + enum ethernetInterface arg = 0; if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) return printSocketReadError(); diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 1c582085e..c05ac6d04 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1248,7 +1248,7 @@ class Detector { void setVeto(const bool enable, Positions pos = {}); /** [Gotthard2] */ - Result getVetoStream(Positions pos = {}) const; + Result getVetoStream(Positions pos = {}) const; /** [Gotthard2] Options: NONE (Default), I3GBE, I10GBE (debugging), ALL * Enable or disable the 2 veto streaming interfaces available. Can @@ -1257,7 +1257,18 @@ class Detector { * interface in receiver for listening to veto packets (writes a separate * file if writing enabled). Also restarts client and receiver zmq sockets * if zmq streaming enabled.*/ - void setVetoStream(const defs::EthernetInterface value, Positions pos = {}); + void setVetoStream(const defs::ethernetInterface value, Positions pos = {}); + + /** [Gotthard2] */ + Result + getVetoAlgorithm(const defs::ethernetInterface value, + Positions pos = {}) const; + + /** [Gotthard2] Options(vetoAlgorithm): DEFAULT_ALGORITHM. + * Options(ethernetInterface): I3GBE, I10GBE */ + void setVetoAlgorithm(const defs::vetoAlgorithm alg, + const defs::ethernetInterface value, + Positions pos = {}); /** [Gotthard2] */ Result getADCConfiguration(const int chipIndex, const int adcIndex, diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 34dcc73db..4e2efacec 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1825,19 +1825,7 @@ std::string CmdProxy::VetoStreaming(int action) { if (args.empty()) { WrongNumberOfParameters(1); } - defs::EthernetInterface interface = defs::EthernetInterface::NONE; - for (const auto &arg : args) { - if (arg == "none") { - if (args.size() > 1) { - throw sls::RuntimeError( - "cannot have other arguments with 'none'. args: " + - ToString(args)); - } - break; - } - StringTo(arg); - interface = interface | (StringTo(arg)); - } + defs::ethernetInterface interface = GetVetoInterface(true); det->setVetoStream(interface, std::vector{det_id}); os << ToString(interface) << '\n'; } else { @@ -1846,6 +1834,56 @@ std::string CmdProxy::VetoStreaming(int action) { return os.str(); } +defs::ethernetInterface CmdProxy::GetVetoInterface(bool isNoneAllowed) { + defs::ethernetInterface interface = defs::ethernetInterface::NONE; + for (const auto &arg : args) { + if (arg == "none") { + if (!isNoneAllowed) { + throw sls::RuntimeError("Must specifiy an interface"); + } else { + if (args.size() > 1) { + throw sls::RuntimeError( + std::string( + "cannot have other arguments with 'none'. args: ") + + ToString(args)); + } + } + break; + } + interface = interface | (StringTo(arg)); + } + return interface; +} + +std::string CmdProxy::VetoAlgorithm(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "[default] [3gbe|10gbe|...]\n\t[Gotthard2] Set the veto " + "algorithm." + << '\n'; + } else if (action == defs::GET_ACTION) { + if (args.size() < 1) { + WrongNumberOfParameters(1); + } + defs::ethernetInterface interface = GetVetoInterface(false); + auto t = det->getVetoAlgorithm(interface, std::vector{det_id}); + os << OutString(t) << ' ' << ToString(interface) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() < 2) { + WrongNumberOfParameters(2); + } + defs::vetoAlgorithm alg = StringTo(args[0]); + args.erase(args.begin()); + defs::ethernetInterface interface = GetVetoInterface(false); + det->setVetoAlgorithm(alg, interface, std::vector{det_id}); + os << ToString(alg) << ' ' << ToString(interface) << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + std::string CmdProxy::ConfigureADC(int action) { std::ostringstream os; os << cmd << ' '; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 6af69775d..abe96765f 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -958,6 +958,7 @@ class CmdProxy { {"timingsource", &CmdProxy::timingsource}, {"veto", &CmdProxy::veto}, {"vetostream", &CmdProxy::VetoStreaming}, + {"vetoalg", &CmdProxy::VetoAlgorithm}, {"confadc", &CmdProxy::ConfigureADC}, {"badchannels", &CmdProxy::BadChannels}, @@ -1134,6 +1135,8 @@ class CmdProxy { std::string VetoFile(int action); std::string BurstMode(int action); std::string VetoStreaming(int action); + defs::ethernetInterface GetVetoInterface(bool isNoneAllowed); + std::string VetoAlgorithm(int action); std::string ConfigureADC(int action); std::string BadChannels(int action); /* Mythen3 Specific */ diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0106f2f1c..1a6bd84fc 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1565,36 +1565,52 @@ void Detector::setVeto(bool enable, Positions pos) { pimpl->Parallel(&Module::setVeto, pos, enable); } -Result Detector::getVetoStream(Positions pos) const { +Result Detector::getVetoStream(Positions pos) const { // 3gbe auto r3 = pimpl->Parallel(&Module::getVetoStream, pos); // 10gbe (debugging interface) opens 2nd udp interface in receiver auto r10 = getNumberofUDPInterfaces_(pos); - Result res(r3.size()); + Result res(r3.size()); for (unsigned int i = 0; i < res.size(); ++i) { - res[i] = (r3[i] ? defs::EthernetInterface::I3GBE - : defs::EthernetInterface::NONE); + res[i] = (r3[i] ? defs::ethernetInterface::I3GBE + : defs::ethernetInterface::NONE); if (r10[i] == 2) { - res[i] = res[i] | defs::EthernetInterface::I10GBE; + res[i] = res[i] | defs::ethernetInterface::I10GBE; } } return res; } -void Detector::setVetoStream(defs::EthernetInterface interface, Positions pos) { +void Detector::setVetoStream(defs::ethernetInterface interface, Positions pos) { // 3gbe - bool i3gbe = (interface & defs::EthernetInterface::I3GBE) == defs::EthernetInterface::I3GBE; + bool i3gbe = (interface & defs::ethernetInterface::I3GBE) == + defs::ethernetInterface::I3GBE; pimpl->Parallel(&Module::setVetoStream, pos, i3gbe); // 10gbe (debugging interface) opens 2nd udp interface in receiver int old_numinterfaces = getNumberofUDPInterfaces_(pos).tsquash( "retrieved inconsistent number of udp interfaces"); - int numinterfaces = ((interface & defs::EthernetInterface::I10GBE) == defs::EthernetInterface::I3GBE) ? 2 : 1; + int numinterfaces = ((interface & defs::ethernetInterface::I10GBE) == + defs::ethernetInterface::I3GBE) + ? 2 + : 1; if (numinterfaces != old_numinterfaces) { setNumberofUDPInterfaces_(numinterfaces, pos); } - } +} + +Result +Detector::getVetoAlgorithm(const defs::ethernetInterface interface, + Positions pos) const { + return pimpl->Parallel(&Module::getVetoAlgorithm, pos, interface); +} + +void Detector::setVetoAlgorithm(const defs::vetoAlgorithm alg, + defs::ethernetInterface interface, + Positions pos) { + pimpl->Parallel(&Module::setVetoAlgorithm, pos, alg, interface); +} Result Detector::getADCConfiguration(const int chipIndex, const int adcIndex, diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index c93fca57b..0de9af07f 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1878,6 +1878,17 @@ void Module::setVetoStream(const bool value) { sendToDetector(F_SET_VETO_STREAM, static_cast(value), nullptr); } +slsDetectorDefs::vetoAlgorithm +Module::getVetoAlgorithm(const slsDetectorDefs::ethernetInterface) const { + return alg_; +} + +void Module::setVetoAlgorithm( + const slsDetectorDefs::vetoAlgorithm alg, + const slsDetectorDefs::ethernetInterface interface) { + alg_ = alg; +} + int Module::getADCConfiguration(const int chipIndex, const int adcIndex) const { int args[]{chipIndex, adcIndex}; return sendToDetector(F_GET_ADC_CONFIGURATION, args); diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 81f6bfee1..f0ee9bc18 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -408,6 +408,10 @@ class Module : public virtual slsDetectorDefs { void setVeto(bool enable); bool getVetoStream() const; void setVetoStream(const bool value); + slsDetectorDefs::vetoAlgorithm + getVetoAlgorithm(const slsDetectorDefs::ethernetInterface) const; + void setVetoAlgorithm(const slsDetectorDefs::vetoAlgorithm alg, + const slsDetectorDefs::ethernetInterface interface); int getADCConfiguration(const int chipIndex, const int adcIndex) const; void setADCConfiguration(const int chipIndex, const int adcIndex, int value); @@ -721,6 +725,7 @@ class Module : public virtual slsDetectorDefs { const int moduleId; mutable sls::SharedMemory shm{0, 0}; + slsDetectorDefs::vetoAlgorithm alg_{slsDetectorDefs::DEFAULT_ALGORITHM}; }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp index a42de01a8..a71994b8f 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -686,6 +686,58 @@ TEST_CASE("vetostream", "[.cmd]") { REQUIRE_THROWS(proxy.Call("vetostream", {"dfgd"}, -1, GET)); } +TEST_CASE("vetoalg", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::GOTTHARD2) { + auto prev_val_3g = det.getVetoAlgorithm(defs::ethernetInterface::I3GBE); + auto prev_val_10g = + det.getVetoAlgorithm(defs::ethernetInterface::I10GBE); + { + std::ostringstream oss; + proxy.Call("vetoalg", {"default", "3gbe"}, -1, PUT, oss); + REQUIRE(oss.str() == "vetoalg default 3gbe\n"); + } + { + std::ostringstream oss; + proxy.Call("vetoalg", {"3gbe"}, -1, GET, oss); + REQUIRE(oss.str() == "vetoalg default 3gbe\n"); + } + { + std::ostringstream oss; + proxy.Call("vetoalg", {"default", "10gbe"}, -1, PUT, oss); + REQUIRE(oss.str() == "vetoalg default 10gbe\n"); + } + { + std::ostringstream oss; + proxy.Call("vetoalg", {"10gbe"}, -1, GET, oss); + REQUIRE(oss.str() == "vetoalg default 10gbe\n"); + } + { + std::ostringstream oss; + proxy.Call("vetoalg", {"default", "3gbe", "10gbe"}, -1, PUT, oss); + REQUIRE(oss.str() == "vetoalg default 3gbe, 10gbe\n"); + } + { + std::ostringstream oss; + proxy.Call("vetoalg", {"3gbe", "10gbe"}, -1, GET, oss); + REQUIRE(oss.str() == "vetoalg default 3gbe, 10gbe\n"); + } + REQUIRE_THROWS(proxy.Call("vetostream", {"3gbe", "none"}, -1, PUT)); + for (int i = 0; i != det.size(); ++i) { + det.setVetoAlgorithm(prev_val_3g[i], defs::ethernetInterface::I3GBE, + {i}); + det.setVetoAlgorithm(prev_val_10g[i], + defs::ethernetInterface::I10GBE, {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("vetoalg", {"3gbe"}, -1, GET)); + REQUIRE_THROWS(proxy.Call("vetoalg", {"none"}, -1, PUT)); + } + REQUIRE_THROWS(proxy.Call("vetoalg", {"dfgd"}, -1, GET)); +} + TEST_CASE("confadc", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 8f644000e..620a03026 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -1412,9 +1412,9 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) { LOG(logERROR) << "Failed to get udp ethernet interface from IP " << arg << ". Got " << eth; } - impl()->setEthernetInterface(eth); + impl()->setethernetInterface(eth); if (myDetectorType == EIGER) { - impl()->setEthernetInterface2(eth); + impl()->setethernetInterface2(eth); } // get mac address auto retval = sls::InterfaceNameToMac(eth); @@ -1446,7 +1446,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) { LOG(logERROR) << "Failed to get udp ethernet interface2 from IP " << arg << ". Got " << eth; } - impl()->setEthernetInterface2(eth); + impl()->setethernetInterface2(eth); // get mac address auto retval = sls::InterfaceNameToMac(eth); diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index daa5c14f3..903c6a66f 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -939,16 +939,16 @@ void Implementation::setNumberofUDPInterfaces(const int n) { LOG(logINFO) << "Number of Interfaces: " << numUDPInterfaces; } -std::string Implementation::getEthernetInterface() const { return eth[0]; } +std::string Implementation::getethernetInterface() const { return eth[0]; } -void Implementation::setEthernetInterface(const std::string &c) { +void Implementation::setethernetInterface(const std::string &c) { eth[0] = c; LOG(logINFO) << "Ethernet Interface: " << eth[0]; } -std::string Implementation::getEthernetInterface2() const { return eth[1]; } +std::string Implementation::getethernetInterface2() const { return eth[1]; } -void Implementation::setEthernetInterface2(const std::string &c) { +void Implementation::setethernetInterface2(const std::string &c) { eth[1] = c; LOG(logINFO) << "Ethernet Interface 2: " << eth[1]; } diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 1a82e1c03..b9663c530 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -98,11 +98,11 @@ class Implementation : private virtual slsDetectorDefs { int getNumberofUDPInterfaces() const; /* [Jungfrau] */ void setNumberofUDPInterfaces(const int n); - std::string getEthernetInterface() const; - void setEthernetInterface(const std::string &c); - std::string getEthernetInterface2() const; + std::string getethernetInterface() const; + void setethernetInterface(const std::string &c); + std::string getethernetInterface2() const; /* [Jungfrau] */ - void setEthernetInterface2(const std::string &c); + void setethernetInterface2(const std::string &c); uint32_t getUDPPortNumber() const; void setUDPPortNumber(const uint32_t i); uint32_t getUDPPortNumber2() const; diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index 65ace1e8c..868ac94ec 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -36,7 +36,8 @@ std::string ToString(const defs::dacIndex s); std::string ToString(const std::vector &vec); std::string ToString(const defs::burstMode s); std::string ToString(const defs::timingSourceType s); -std::string ToString(const defs::EthernetInterface s); +std::string ToString(const defs::ethernetInterface s); +std::string ToString(const defs::vetoAlgorithm s); std::string ToString(const slsDetectorDefs::xy &coord); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord); @@ -298,7 +299,8 @@ template <> defs::readoutMode StringTo(const std::string &s); template <> defs::dacIndex StringTo(const std::string &s); template <> defs::burstMode StringTo(const std::string &s); template <> defs::timingSourceType StringTo(const std::string &s); -template <> defs::EthernetInterface StringTo(const std::string &s); +template <> defs::ethernetInterface StringTo(const std::string &s); +template <> defs::vetoAlgorithm StringTo(const std::string &s); template <> uint32_t StringTo(const std::string &s); template <> uint64_t StringTo(const std::string &s); diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 13d7f89e2..52f022182 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -395,9 +395,9 @@ typedef struct { enum timingSourceType { TIMING_INTERNAL, TIMING_EXTERNAL }; #ifdef __cplusplus - enum class EthernetInterface { + enum class ethernetInterface { #else - enum EthernetInterface { + enum ethernetInterface { #endif NONE = 0, I3GBE = 1 << 1, @@ -405,6 +405,8 @@ typedef struct { ALL = I3GBE | I10GBE }; + enum vetoAlgorithm { DEFAULT_ALGORITHM }; + #ifdef __cplusplus /** scan structure */ @@ -496,16 +498,18 @@ typedef struct { #ifdef __cplusplus }; -inline slsDetectorDefs::EthernetInterface -operator|( const slsDetectorDefs::EthernetInterface &a, - const slsDetectorDefs::EthernetInterface &b) { - return slsDetectorDefs::EthernetInterface(static_cast(a) | +inline slsDetectorDefs::ethernetInterface +operator|(const slsDetectorDefs::ethernetInterface &a, + const slsDetectorDefs::ethernetInterface &b) { + return slsDetectorDefs::ethernetInterface(static_cast(a) | static_cast(b)); }; -inline slsDetectorDefs::EthernetInterface operator&( const slsDetectorDefs::EthernetInterface &a, - const slsDetectorDefs::EthernetInterface &b) { - return slsDetectorDefs::EthernetInterface(static_cast(a) & static_cast(b)); +inline slsDetectorDefs::ethernetInterface +operator&(const slsDetectorDefs::ethernetInterface &a, + const slsDetectorDefs::ethernetInterface &b) { + return slsDetectorDefs::ethernetInterface(static_cast(a) & + static_cast(b)); }; #endif @@ -583,7 +587,7 @@ struct detParameters { #ifdef __cplusplus struct sls_detector_module { #else -typedef struct { + typedef struct { #endif int serialnumber; /**< is the module serial number */ int nchan; /**< is the number of channels on the module*/ diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 4db40a60b..4c038541a 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -519,16 +519,18 @@ std::string ToString(const defs::timingSourceType s) { } } -std::string ToString(const defs::EthernetInterface s) { +std::string ToString(const defs::ethernetInterface s) { std::ostringstream os; std::string rs; switch (s) { - case defs::EthernetInterface::NONE: + case defs::ethernetInterface::NONE: return std::string("none"); default: - if ((s & defs::EthernetInterface::I3GBE)!=defs::EthernetInterface::NONE) + if ((s & defs::ethernetInterface::I3GBE) != + defs::ethernetInterface::NONE) os << "3gbe, "; - if ((s & defs::EthernetInterface::I10GBE)!=defs::EthernetInterface::NONE) + if ((s & defs::ethernetInterface::I10GBE) != + defs::ethernetInterface::NONE) os << "10gbe, "; auto rs = os.str(); rs.erase(rs.end() - 2, rs.end()); @@ -536,6 +538,15 @@ std::string ToString(const defs::EthernetInterface s) { } } +std::string ToString(const defs::vetoAlgorithm s) { + switch (s) { + case defs::DEFAULT_ALGORITHM: + return std::string("default"); + default: + return std::string("Unknown"); + } +} + const std::string &ToString(const std::string &s) { return s; } template <> defs::detectorType StringTo(const std::string &s) { @@ -876,17 +887,23 @@ template <> defs::timingSourceType StringTo(const std::string &s) { throw sls::RuntimeError("Unknown timing source type " + s); } -template <> defs::EthernetInterface StringTo(const std::string &s) { +template <> defs::ethernetInterface StringTo(const std::string &s) { std::string rs = s; if (s.find(',') != std::string::npos) rs.erase(rs.find(',')); if (rs == "none") - return defs::EthernetInterface::NONE; + return defs::ethernetInterface::NONE; if (rs == "3gbe") - return defs::EthernetInterface::I3GBE; + return defs::ethernetInterface::I3GBE; if (rs == "10gbe") - return defs::EthernetInterface::I10GBE; - throw sls::RuntimeError("Unknown EthernetInterface type " + s); + return defs::ethernetInterface::I10GBE; + throw sls::RuntimeError("Unknown ethernetInterface type " + s); +} + +template <> defs::vetoAlgorithm StringTo(const std::string &s) { + if (s == "default") + return defs::DEFAULT_ALGORITHM; + throw sls::RuntimeError("Unknown veto algorithm " + s); } template <> uint32_t StringTo(const std::string &s) { diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index e372f9336..c8e720734 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -324,10 +324,10 @@ TEST_CASE("Print a member of patternParameters") { REQUIRE(ToString(pat->limits) == "[4, 100]"); } -TEST_CASE("EthernetInterface") { - REQUIRE(ToString(sls::defs::EthernetInterface::NONE) == "none"); - REQUIRE(ToString(sls::defs::EthernetInterface::I10GBE) == "10gbe"); - REQUIRE(ToString(sls::defs::EthernetInterface::I3GBE) == "3gbe"); - REQUIRE(ToString(sls::defs::EthernetInterface::I3GBE | - sls::defs::EthernetInterface::I10GBE) == "3gbe, 10gbe"); +TEST_CASE("ethernetInterface") { + REQUIRE(ToString(sls::defs::ethernetInterface::NONE) == "none"); + REQUIRE(ToString(sls::defs::ethernetInterface::I10GBE) == "10gbe"); + REQUIRE(ToString(sls::defs::ethernetInterface::I3GBE) == "3gbe"); + REQUIRE(ToString(sls::defs::ethernetInterface::I3GBE | + sls::defs::ethernetInterface::I10GBE) == "3gbe, 10gbe"); } \ No newline at end of file