From e02493d4e4e1eb671580ce44a479e474c5869791 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 20 Jul 2021 14:57:31 +0200 Subject: [PATCH] veotalg for g2 --- .../gotthard2DetectorServer/RegisterDefs.h | 6 ++ .../slsDetectorFunctionList.c | 30 ++++++++ .../include/slsDetectorFunctionList.h | 2 + .../include/slsDetectorServer_funcs.h | 4 +- .../src/slsDetectorServer_funcs.c | 69 +++++++++++++++++++ slsDetectorSoftware/src/CmdProxy.cpp | 56 +++++++-------- slsDetectorSoftware/src/CmdProxy.h | 1 - slsDetectorSoftware/src/Module.cpp | 10 +-- slsDetectorSoftware/src/Module.h | 3 +- .../tests/test-CmdProxy-gotthard2.cpp | 14 +--- .../include/sls/sls_detector_funcs.h | 5 +- 11 files changed, 152 insertions(+), 48 deletions(-) diff --git a/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h b/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h index 8f9204c3b..1d1274e5f 100644 --- a/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h +++ b/slsDetectorServers/gotthard2DetectorServer/RegisterDefs.h @@ -90,8 +90,14 @@ #define CONFIG_VETO_ENBL_OFST (0) #define CONFIG_VETO_ENBL_MSK (0x00000001 << CONFIG_VETO_ENBL_OFST) +#define CONFIG_VETO_CH_3GB_ALG_OFST (8) +#define CONFIG_VETO_CH_3GB_ALG_MSK (0x00000007 << CONFIG_VETO_CH_3GB_ALG_OFST) +#define CONFIG_VETO_CH_3GB_ALG_DEFAULT_VAL ((0x0 << CONFIG_VETO_CH_3GB_ALG_OFST) & CONFIG_VETO_CH_3GB_ALG_MSK) #define CONFIG_VETO_CH_3GB_ENBL_OFST (11) #define CONFIG_VETO_CH_3GB_ENBL_MSK (0x00000001 << CONFIG_VETO_CH_3GB_ENBL_OFST) +#define CONFIG_VETO_CH_10GB_ALG_OFST (12) +#define CONFIG_VETO_CH_10GB_ALG_MSK (0x00000007 << CONFIG_VETO_CH_10GB_ALG_OFST) +#define CONFIG_VETO_CH_10GB_ALG_DEFAULT_VAL ((0x0 << CONFIG_VETO_CH_10GB_ALG_OFST) & CONFIG_VETO_CH_10GB_ALG_MSK) #define CONFIG_VETO_CH_10GB_ENBL_OFST (15) #define CONFIG_VETO_CH_10GB_ENBL_MSK (0x00000001 << CONFIG_VETO_CH_10GB_ENBL_OFST) diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 2ecc00439..e09a53146 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -2595,6 +2595,36 @@ int getVetoStream() { return ((bus_r(CONFIG_REG) & CONFIG_VETO_CH_3GB_ENBL_MSK) ? 1 : 0); } +enum vetoAlgorithm getVetoAlgorithm(enum ethernetInterface interface) { + // 3gbe + if (interface == I3GBE) { + int retval = ((bus_r(CONFIG_REG) & CONFIG_VETO_CH_3GB_ALG_MSK) >> + CONFIG_VETO_CH_3GB_ALG_OFST); + switch (retval) { + // more to follow + case CONFIG_VETO_CH_3GB_ALG_DEFAULT_VAL: + return DEFAULT_ALGORITHM; + default: + LOG(logERROR, ("unknown algorithm %d for 3gbe\n", retval)); + return -1; + } + } + // 10gbe + int retval = ((bus_r(CONFIG_REG) & CONFIG_VETO_CH_10GB_ALG_MSK) >> + CONFIG_VETO_CH_10GB_ALG_OFST); + switch (retval) { + // more to follow + case CONFIG_VETO_CH_10GB_ALG_DEFAULT_VAL: + return DEFAULT_ALGORITHM; + default: + LOG(logERROR, ("unknown algorithm %d for 3gbe\n", retval)); + return -1; + } +} + +void setVetoAlgorithm(enum ethernetInterface interface, + enum vetoAlgorithm alg) {} + void setBadChannels(int nch, int *channels) { LOG(logINFO, ("Setting %d bad channels\n", nch)); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 72401feed..58090a24d 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -542,6 +542,8 @@ void setVeto(int enable); int getVeto(); void setVetoStream(int value); int getVetoStream(); +enum vetoAlgorithm getVetoAlgorithm(enum ethernetInterface interface); +void setVetoAlgorithm(enum ethernetInterface interface, enum vetoAlgorithm alg); void setBadChannels(int nch, int *channels); int *getBadChannels(int *nch); #endif diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 36a8c96b7..5cea24d8b 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -248,4 +248,6 @@ int load_default_pattern(int); int get_all_threshold_energy(int); int get_master(int); int get_veto_stream(int); -int set_veto_stream(int); \ No newline at end of file +int set_veto_stream(int); +int get_veto_algorithm(int); +int set_veto_algorithm(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index e6d8091eb..083bee508 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -371,6 +371,8 @@ void function_table() { flist[F_GET_MASTER] = &get_master; flist[F_GET_VETO_STREAM] = &get_veto_stream; flist[F_SET_VETO_STREAM] = &set_veto_stream; + flist[F_GET_VETO_ALGORITHM] = &get_veto_algorithm; + flist[F_SET_VETO_ALGORITHM] = &set_veto_algorithm; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -8456,4 +8458,71 @@ int set_veto_stream(int file_des) { } #endif return Server_SendResult(file_des, INT32, NULL, 0); +} + +int get_veto_algorithm(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + enum ethernetInterface arg = NONE; + enum vetoAlgorithm retval = DEFAULT_ALGORITHM; + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + + LOG(logDEBUG1, ("Getting veto algorithm for interface %d\n", arg)); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // get only + if (arg != I3GBE && arg != I10GBE) { + ret = FAIL; + sprintf(mess, "Could not get vetoalgorithm. Invalid interface %d.\n", + arg); + LOG(logERROR, (mess)); + } else { + retval = getVetoAlgorithm(arg); + LOG(logDEBUG1, ("vetoalgorithm retval: %u\n", retval)); + } +#endif + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_veto_algorithm(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int args[2] = {-1, -1}; + if (receiveData(file_des, args, sizeof(args), INT32) < 0) + return printSocketReadError(); + + enum vetoAlgorithm alg = args[0]; + enum ethernetInterface interface = args[1]; + LOG(logINFO, ("Setting vetoalgorithm (interface: %d): %u\n", (int)interface, + (int)alg)); + +#ifndef GOTTHARD2D + functionNotImplemented(); +#else + // only set + if (Server_VerifyLock() == OK) { + if (interface != I3GBE && interface != I10GBE) { + ret = FAIL; + sprintf(mess, + "Could not set vetoalgorithm. Invalid interface %d.\n", + interface); + LOG(logERROR, (mess)); + } else if (alg != DEFAULT_ALGORITHM) { + ret = FAIL; + sprintf(mess, + "Could not set vetoalgorithm. Invalid algorithm %d.\n", + alg); + LOG(logERROR, (mess)); + } else { + setVetoAlgorithm(alg, interface); + int retval = getVetoAlgorithm(interface); + LOG(logDEBUG1, ("vetoalgorithm retval: %u\n", retval)); + validate(alg, retval, "set veto algorithm", DEC); + } + } +#endif + return Server_SendResult(file_des, INT32, NULL, 0); } \ No newline at end of file diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 4e2efacec..f44885396 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1825,7 +1825,19 @@ std::string CmdProxy::VetoStreaming(int action) { if (args.empty()) { WrongNumberOfParameters(1); } - defs::ethernetInterface interface = GetVetoInterface(true); + defs::ethernetInterface interface = defs::ethernetInterface::NONE; + for (const auto &arg : args) { + if (arg == "none") { + if (args.size() > 1) { + throw sls::RuntimeError( + std::string( + "cannot have other arguments with 'none'. args: ") + + ToString(args)); + } + break; + } + interface = interface | (StringTo(arg)); + } det->setVetoStream(interface, std::vector{det_id}); os << ToString(interface) << '\n'; } else { @@ -1834,48 +1846,36 @@ 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 " + os << "[default] [3gbe|10gbe]\n\t[Gotthard2] Set the veto " "algorithm." << '\n'; } else if (action == defs::GET_ACTION) { - if (args.size() < 1) { + if (args.size() != 1) { WrongNumberOfParameters(1); } - defs::ethernetInterface interface = GetVetoInterface(false); + defs::ethernetInterface interface = + StringTo(args[0]); + if (interface == defs::ethernetInterface::NONE) { + throw sls::RuntimeError( + "Must specify an interface to set algorithm"); + } 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) { + if (args.size() != 2) { WrongNumberOfParameters(2); } defs::vetoAlgorithm alg = StringTo(args[0]); - args.erase(args.begin()); - defs::ethernetInterface interface = GetVetoInterface(false); + defs::ethernetInterface interface = + StringTo(args[1]); + if (interface == defs::ethernetInterface::NONE) { + throw sls::RuntimeError( + "Must specify an interface to set algorithm"); + } det->setVetoAlgorithm(alg, interface, std::vector{det_id}); os << ToString(alg) << ' ' << ToString(interface) << '\n'; } else { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index abe96765f..9c33f2775 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1135,7 +1135,6 @@ 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); diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 0de9af07f..2221092c3 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1878,15 +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_; +slsDetectorDefs::vetoAlgorithm Module::getVetoAlgorithm( + const slsDetectorDefs::ethernetInterface interface) const { + return sendToDetector(F_GET_VETO_ALGORITHM, + static_cast(interface)); } void Module::setVetoAlgorithm( const slsDetectorDefs::vetoAlgorithm alg, const slsDetectorDefs::ethernetInterface interface) { - alg_ = alg; + int args[]{static_cast(alg), static_cast(interface)}; + sendToDetector(F_SET_VETO_ALGORITHM, args, nullptr); } int Module::getADCConfiguration(const int chipIndex, const int adcIndex) const { diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f0ee9bc18..a05e49012 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -409,7 +409,7 @@ class Module : public virtual slsDetectorDefs { bool getVetoStream() const; void setVetoStream(const bool value); slsDetectorDefs::vetoAlgorithm - getVetoAlgorithm(const slsDetectorDefs::ethernetInterface) const; + getVetoAlgorithm(const slsDetectorDefs::ethernetInterface interface) const; void setVetoAlgorithm(const slsDetectorDefs::vetoAlgorithm alg, const slsDetectorDefs::ethernetInterface interface); int getADCConfiguration(const int chipIndex, const int adcIndex) const; @@ -725,7 +725,6 @@ 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 a71994b8f..089d8b68b 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-gotthard2.cpp @@ -714,17 +714,9 @@ TEST_CASE("vetoalg", "[.cmd]") { 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)); + REQUIRE_THROWS( + proxy.Call("vetoalg", {"default", "3gbe", "10gbe"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("vetoalg", {"default", "none"}, -1, PUT)); for (int i = 0; i != det.size(); ++i) { det.setVetoAlgorithm(prev_val_3g[i], defs::ethernetInterface::I3GBE, {i}); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 34a772671..93fc842b5 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -223,6 +223,8 @@ enum detFuncs { F_GET_MASTER, F_GET_VETO_STREAM, F_SET_VETO_STREAM, + F_GET_VETO_ALGORITHM, + F_SET_VETO_ALGORITHM, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -552,7 +554,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_GET_MASTER: return "F_GET_MASTER"; case F_GET_VETO_STREAM: return "F_GET_VETO_STREAM"; case F_SET_VETO_STREAM: return "F_SET_VETO_STREAM"; - + case F_GET_VETO_ALGORITHM: return "F_GET_VETO_ALGORITHM"; + case F_SET_VETO_ALGORITHM: return "F_SET_VETO_ALGORITHM"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";