mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
vetoalg: wip
This commit is contained in:
@ -1248,7 +1248,7 @@ class Detector {
|
||||
void setVeto(const bool enable, Positions pos = {});
|
||||
|
||||
/** [Gotthard2] */
|
||||
Result<defs::EthernetInterface> getVetoStream(Positions pos = {}) const;
|
||||
Result<defs::ethernetInterface> 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<defs::vetoAlgorithm>
|
||||
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<int> getADCConfiguration(const int chipIndex, const int adcIndex,
|
||||
|
@ -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<defs::EthernetInterface>(arg);
|
||||
interface = interface | (StringTo<defs::EthernetInterface>(arg));
|
||||
}
|
||||
defs::ethernetInterface interface = GetVetoInterface(true);
|
||||
det->setVetoStream(interface, std::vector<int>{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<defs::ethernetInterface>(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<int>{det_id});
|
||||
os << OutString(t) << ' ' << ToString(interface) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() < 2) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
defs::vetoAlgorithm alg = StringTo<defs::vetoAlgorithm>(args[0]);
|
||||
args.erase(args.begin());
|
||||
defs::ethernetInterface interface = GetVetoInterface(false);
|
||||
det->setVetoAlgorithm(alg, interface, std::vector<int>{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 << ' ';
|
||||
|
@ -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 */
|
||||
|
@ -1565,36 +1565,52 @@ void Detector::setVeto(bool enable, Positions pos) {
|
||||
pimpl->Parallel(&Module::setVeto, pos, enable);
|
||||
}
|
||||
|
||||
Result<defs::EthernetInterface> Detector::getVetoStream(Positions pos) const {
|
||||
Result<defs::ethernetInterface> 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<defs::EthernetInterface> res(r3.size());
|
||||
Result<defs::ethernetInterface> 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<defs::vetoAlgorithm>
|
||||
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<int> Detector::getADCConfiguration(const int chipIndex,
|
||||
const int adcIndex,
|
||||
|
@ -1878,6 +1878,17 @@ void Module::setVetoStream(const bool value) {
|
||||
sendToDetector(F_SET_VETO_STREAM, static_cast<int>(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<int>(F_GET_ADC_CONFIGURATION, args);
|
||||
|
@ -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<sharedSlsDetector> shm{0, 0};
|
||||
slsDetectorDefs::vetoAlgorithm alg_{slsDetectorDefs::DEFAULT_ALGORITHM};
|
||||
};
|
||||
|
||||
} // namespace sls
|
@ -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);
|
||||
|
Reference in New Issue
Block a user