WIP: some bug fixes and reducing redundant code

This commit is contained in:
maliakal_d 2020-04-16 18:07:11 +02:00
parent cd45f9d45b
commit 78fb8080ce
5 changed files with 136 additions and 141 deletions

View File

@ -508,31 +508,33 @@ class Detector {
/** true when slsReceiver is used */ /** true when slsReceiver is used */
Result<bool> getUseReceiverFlag(Positions pos = {}) const; Result<bool> getUseReceiverFlag(Positions pos = {}) const;
Result<std::string> getRxHostname(Positions pos = {}) const; /** interface is by 1 (primary udp interface),
Result<std::string> getRxHostname2(Positions pos = {}) const; * 2 for second udp interface [Eiger][Jungfrau]
*/
Result<std::string> getRxHostname(const int udpInterface, Positions pos = {}) const;
/** /**
* Validates and sets the receiver. * Validates and sets the receiver.
* Configures the detector to the receiver as UDP destination * Configures the detector to the receiver as UDP destination
* interface is by 1 (primary udp interface),
* 2 for second udp interface [Eiger][Jungfrau]
*/ */
void setRxHostname(const std::string &hostname, Positions pos = {}); void setRxHostname(const int udpInterface, const std::string &hostname,
/** receiver hostname for udp port 2 */ Positions pos = {});
void setRxHostname2(const std::string &hostname, Positions pos = {});
/** cannot be for multiple detectors as port is unique*/
void setRxHostname(const std::string &hostname, const int port,
int module_id);
void setRxHostname2(const std::string &hostname, const int port,
int module_id);
Result<int> getRxPort(Positions pos = {}) const; /** cannot be for multiple detectors as port is unique */
/** for 2nd udp port receiver */ void setRxHostname(const int udpInterface, const std::string &hostname,
Result<int> getRxPort2(Positions pos = {}) const; const int port, int module_id);
/** interface is by 1 (primary udp interface),
* 2 for second udp interface [Eiger][Jungfrau] */
Result<int> getRxPort(const int udpInterface, Positions pos = {}) const;
/** Receiver TCP port (for client communication with Receiver) /** Receiver TCP port (for client communication with Receiver)
* module_id is -1 for all detectors, ports for each module is calculated * module_id is -1 for all detectors, ports for each module is calculated
* (increments) */ * (increments)
void setRxPort(const int port, int module_id = -1); * interface is by 1 (primary udp interface),
void setRxPort2(const int port, int module_id = -1); * 2 for second udp interface [Eiger][Jungfrau] */
void setRxPort(const int udpInterface, const int port, int module_id = -1);
Result<int> getRxFifoDepth(Positions pos = {}) const; Result<int> getRxFifoDepth(Positions pos = {}) const;

View File

@ -124,8 +124,10 @@ std::pair<std::string, int>
if (res.size() > 1) { if (res.size() > 1) {
hostname = res[0]; hostname = res[0];
port = StringTo<int>(res[1]); port = StringTo<int>(res[1]);
} else {
hostname = host;
} }
return std::make_pair(host, port); return std::make_pair(hostname, port);
} }
@ -938,9 +940,18 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
/* Receiver Config */ /* Receiver Config */
std::string CmdProxy::ReceiverHostname(int action) { std::string CmdProxy::ReceiverHostname(int action) {
int udpInterface = 1;
if (cmd == "rx_hostname") {
udpInterface = 1;
} else if (cmd == "rx_hostname2") {
udpInterface = 2;
} else {
throw sls::RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os; std::ostringstream os;
os << cmd << ' '; os << cmd << ' ';
if (action == defs::HELP_ACTION) { if (action == defs::HELP_ACTION) {
if (cmd == "rx_hostname") {
os << "[hostname or ip address]\n\t" os << "[hostname or ip address]\n\t"
"[hostname or ip address]:[tcp port]\n\t" "[hostname or ip address]:[tcp port]\n\t"
"Receiver hostname or IP. Port is the receiver tcp port (optional).\n\t" "Receiver hostname or IP. Port is the receiver tcp port (optional).\n\t"
@ -951,11 +962,19 @@ std::string CmdProxy::ReceiverHostname(int action) {
" and calculates from there. \n\t" " and calculates from there. \n\t"
"[Eiger][Jungfrau] For the 2nd udp interface, use rx_hostname2." "[Eiger][Jungfrau] For the 2nd udp interface, use rx_hostname2."
<< '\n'; << '\n';
} else {
os << "[hostname or ip address]\n\t"
"[hostname or ip address]:[tcp port]\n\t"
"[Eiger][Jungfrau] Receiver hostname or IP for the second udp port. "
"Port is the receiver tcp port (optional).\n\t"
"Refer rx_hostname help for details"
<< '\n';
}
} else if (action == defs::GET_ACTION) { } else if (action == defs::GET_ACTION) {
if (!args.empty()) { if (!args.empty()) {
WrongNumberOfParameters(0); WrongNumberOfParameters(0);
} }
auto t = det->getRxHostname({det_id}); auto t = det->getRxHostname(udpInterface, {det_id});
os << OutString(t) << '\n'; os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) { } else if (action == defs::PUT_ACTION) {
if (args.size() != 1) { if (args.size() != 1) {
@ -968,15 +987,15 @@ std::string CmdProxy::ReceiverHostname(int action) {
std::string hostname = res.first; std::string hostname = res.first;
int port = res.second; int port = res.second;
if (port == 0) { if (port == 0) {
det->setRxHostname(hostname, {det_id}); det->setRxHostname(udpInterface, hostname, {det_id});
} else { } else {
if (det_id == -1) { if (det_id == -1 && det->size() > 1) {
throw sls::RuntimeError("Cannot set same tcp port " throw sls::RuntimeError("Cannot set same tcp port "
"for all receiver hostnames"); "for all receiver hostnames");
} }
det->setRxHostname(hostname, port, det_id); det->setRxHostname(udpInterface, hostname, port, det_id);
} }
auto t = det->getRxHostname({det_id}); auto t = det->getRxHostname(udpInterface, {det_id});
os << OutString(t) << '\n'; os << OutString(t) << '\n';
} else { } else {
throw sls::RuntimeError("Unknown action"); throw sls::RuntimeError("Unknown action");
@ -984,48 +1003,6 @@ std::string CmdProxy::ReceiverHostname(int action) {
return os.str(); return os.str();
} }
std::string CmdProxy::ReceiverHostname2(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[hostname or ip address]\n\t"
"[hostname or ip address]:[tcp port]\n\t"
"[Eiger][Jungfrau] Receiver hostname or IP for the second udp port. "
"Port is the receiver tcp port (optional).\n\t"
"Refer rx_hostname help for details"
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getRxHostname2({det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
if (args[0].find('+') != std::string::npos) {
throw sls::RuntimeError("Cannot concatenate receiver hostnames");
}
std::pair<std::string, int> res = parseHostnameAndPort(args[0]);
std::string hostname = res.first;
int port = res.second;
if (port == 0) {
det->setRxHostname2(hostname, {det_id});
} else {
if (det_id == -1) {
throw sls::RuntimeError("Cannot set same tcp port "
"for all receiver hostnames");
}
det->setRxHostname2(hostname, port, det_id);
}
auto t = det->getRxHostname2({det_id});
os << OutString(t) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* File */ /* File */
/* ZMQ Streaming Parameters (Receiver<->Client) */ /* ZMQ Streaming Parameters (Receiver<->Client) */
/* Eiger Specific */ /* Eiger Specific */

View File

@ -720,7 +720,7 @@ class CmdProxy {
/* Receiver Config */ /* Receiver Config */
{"rx_hostname", &CmdProxy::ReceiverHostname}, {"rx_hostname", &CmdProxy::ReceiverHostname},
{"rx_hostname2", &CmdProxy::ReceiverHostname2}, {"rx_hostname2", &CmdProxy::ReceiverHostname},
{"rx_tcpport", &CmdProxy::rx_tcpport}, {"rx_tcpport", &CmdProxy::rx_tcpport},
{"rx_tcpport2", &CmdProxy::rx_tcpport2}, {"rx_tcpport2", &CmdProxy::rx_tcpport2},
{"rx_fifodepth", &CmdProxy::rx_fifodepth}, {"rx_fifodepth", &CmdProxy::rx_fifodepth},
@ -944,7 +944,6 @@ class CmdProxy {
std::string UDPDestinationIP2(int action); std::string UDPDestinationIP2(int action);
/* Receiver Config */ /* Receiver Config */
std::string ReceiverHostname(int action); std::string ReceiverHostname(int action);
std::string ReceiverHostname2(int action);
/* File */ /* File */
/* ZMQ Streaming Parameters (Receiver<->Client) */ /* ZMQ Streaming Parameters (Receiver<->Client) */
/* Eiger Specific */ /* Eiger Specific */
@ -1435,10 +1434,10 @@ class CmdProxy {
/* Receiver Config */ /* Receiver Config */
INTEGER_COMMAND(rx_tcpport, getRxPort, setRxPort, StringTo<int>, INTEGER_IND_COMMAND(rx_tcpport, getRxPort, setRxPort, StringTo<int>, 1,
"[port]\n\tTCP port for client-receiver communication. Default is 1954. Must be different if multiple receivers on same pc. Must be first command to set a receiver parameter. Multi command will automatically increment for individual modules."); "[port]\n\tTCP port for client-receiver communication. Default is 1954. Must be different if multiple receivers on same pc. Must be first command to set a receiver parameter. Multi command will automatically increment for individual modules.");
INTEGER_COMMAND(rx_tcpport2, getRxPort2, setRxPort2, StringTo<int>, INTEGER_IND_COMMAND(rx_tcpport2, getRxPort, setRxPort, StringTo<int>, 2,
"[port]\n\t[Eiger][Jungfrau] TCP port for client-receiver communication for 2nd udp port. For details, refer rx_tcpport."); "[port]\n\t[Eiger][Jungfrau] TCP port for client-receiver communication for 2nd udp port. For details, refer rx_tcpport.");
INTEGER_COMMAND(rx_fifodepth, getRxFifoDepth, setRxFifoDepth, StringTo<int>, INTEGER_COMMAND(rx_fifodepth, getRxFifoDepth, setRxFifoDepth, StringTo<int>,

View File

@ -695,55 +695,71 @@ Result<bool> Detector::getUseReceiverFlag(Positions pos) const {
return pimpl->Parallel(&Module::getUseReceiverFlag, pos); return pimpl->Parallel(&Module::getUseReceiverFlag, pos);
} }
Result<std::string> Detector::getRxHostname(Positions pos) const { Result<std::string> Detector::getRxHostname(const int udpInterface, Positions pos) const {
switch (udpInterface) {
case 1:
return pimpl->Parallel1(&Receiver::getHostname, pos, {0}); return pimpl->Parallel1(&Receiver::getHostname, pos, {0});
} case 2:
Result<std::string> Detector::getRxHostname2(Positions pos) const {
return pimpl->Parallel2(&Receiver::getHostname, pos, {0}); return pimpl->Parallel2(&Receiver::getHostname, pos, {0});
default:
throw RuntimeError("Invalid udp interface number");
}
} }
void Detector::setRxHostname(const std::string &hostname, Positions pos) { void Detector::setRxHostname(const int udpInterface, const std::string &hostname, Positions pos) {
switch (udpInterface) {
case 1:
if (!pimpl->isReceiverInitialized()) { if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver(); pimpl->initReceiver();
} }
pimpl->Parallel1(&Receiver::setHostname, pos, {0}, hostname); pimpl->Parallel1(&Receiver::setHostname, pos, {0}, hostname);
} break;
case 2:
void Detector::setRxHostname2(const std::string &hostname, Positions pos) {
if (!pimpl->isReceiver2Initialized()) { if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2(); pimpl->initReceiver2();
} }
pimpl->Parallel2(&Receiver::setHostname, pos, {0}, hostname); pimpl->Parallel2(&Receiver::setHostname, pos, {0}, hostname);
break;
default:
throw RuntimeError("Invalid udp interface number");
}
} }
void Detector::setRxHostname(const std::string &hostname, const int port, void Detector::setRxHostname(const int udpInterface, const std::string &hostname, const int port,
int module_id) { int module_id) {
switch (udpInterface) {
case 1:
if (!pimpl->isReceiverInitialized()) { if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver(); pimpl->initReceiver();
} }
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port); pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
pimpl->Parallel1(&Receiver::setHostname, {module_id}, {0}, hostname); pimpl->Parallel1(&Receiver::setHostname, {module_id}, {0}, hostname);
} break;
case 2:
void Detector::setRxHostname2(const std::string &hostname, const int port,
int module_id) {
if (!pimpl->isReceiver2Initialized()) { if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2(); pimpl->initReceiver2();
} }
pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port); pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port);
pimpl->Parallel2(&Receiver::setHostname, {module_id}, {0}, hostname); pimpl->Parallel2(&Receiver::setHostname, {module_id}, {0}, hostname);
break;
default:
throw RuntimeError("Invalid udp interface number");
}
} }
Result<int> Detector::getRxPort(Positions pos) const { Result<int> Detector::getRxPort(const int udpInterface, Positions pos) const {
switch (udpInterface) {
case 1:
return pimpl->Parallel1(&Receiver::getTCPPort, pos, {0}); return pimpl->Parallel1(&Receiver::getTCPPort, pos, {0});
} case 2:
Result<int> Detector::getRxPort2(Positions pos) const {
return pimpl->Parallel2(&Receiver::getTCPPort, pos, {0}); return pimpl->Parallel2(&Receiver::getTCPPort, pos, {0});
default:
throw RuntimeError("Invalid udp interface number");
}
} }
void Detector::setRxPort(int port, int module_id) { void Detector::setRxPort(const int udpInterface, int port, int module_id) {
if (udpInterface == 1) {
if (!pimpl->isReceiverInitialized()) { if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver(); pimpl->initReceiver();
} }
@ -756,9 +772,7 @@ void Detector::setRxPort(int port, int module_id) {
} else { } else {
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port); pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
} }
} } else if (udpInterface == 2) {
void Detector::setRxPort2(int port, int module_id) {
if (!pimpl->isReceiver2Initialized()) { if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2(); pimpl->initReceiver2();
} }
@ -771,6 +785,9 @@ void Detector::setRxPort2(int port, int module_id) {
} else { } else {
pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port); pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port);
} }
} else {
throw RuntimeError("Invalid udp interface number");
}
} }
Result<int> Detector::getRxFifoDepth(Positions pos) const { Result<int> Detector::getRxFifoDepth(Positions pos) const {

View File

@ -330,7 +330,7 @@ void DetectorImpl::setHostname(const std::vector<std::string> &name,
void DetectorImpl::addModule(const std::string &hostname, void DetectorImpl::addModule(const std::string &hostname,
const int port) { const int port) {
LOG(logINFO) << "Adding detector " << hostname; LOG(logINFO) << "Adding detector " << hostname << " on port " << port;
if (hostname != "localhost") { if (hostname != "localhost") {
for (auto &d : detectors) { for (auto &d : detectors) {