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 */
Result<bool> getUseReceiverFlag(Positions pos = {}) const;
Result<std::string> getRxHostname(Positions pos = {}) const;
Result<std::string> getRxHostname2(Positions pos = {}) const;
/** interface is by 1 (primary udp interface),
* 2 for second udp interface [Eiger][Jungfrau]
*/
Result<std::string> getRxHostname(const int udpInterface, Positions pos = {}) const;
/**
* Validates and sets the receiver.
* 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 = {});
/** receiver hostname for udp port 2 */
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);
void setRxHostname(const int udpInterface, const std::string &hostname,
Positions pos = {});
/** cannot be for multiple detectors as port is unique */
void setRxHostname(const int udpInterface, const std::string &hostname,
const int port, int module_id);
Result<int> getRxPort(Positions pos = {}) const;
/** for 2nd udp port receiver */
Result<int> getRxPort2(Positions pos = {}) const;
/** 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)
* module_id is -1 for all detectors, ports for each module is calculated
* (increments) */
void setRxPort(const int port, int module_id = -1);
void setRxPort2(const int port, int module_id = -1);
* (increments)
* interface is by 1 (primary udp interface),
* 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;

View File

@ -124,8 +124,10 @@ std::pair<std::string, int>
if (res.size() > 1) {
hostname = res[0];
port = StringTo<int>(res[1]);
} else {
hostname = host;
}
return std::make_pair(host, port);
return std::make_pair(hostname, port);
}
@ -938,24 +940,41 @@ std::string CmdProxy::UDPDestinationIP2(int action) {
/* Receiver Config */
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;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[hostname or ip address]\n\t"
"[hostname or ip address]:[tcp port]\n\t"
"Receiver hostname or IP. Port is the receiver tcp port (optional).\n\t"
"Used for TCP control communication between client and receiver "
"to configure receiver. Also updates receiver with detector parameters.\n\t"
"TCP port must be unique, if included.\n\t"
"If port not included and not set earlier, then it takes default port 1954"
" and calculates from there. \n\t"
"[Eiger][Jungfrau] For the 2nd udp interface, use rx_hostname2."
<< '\n';
if (cmd == "rx_hostname") {
os << "[hostname or ip address]\n\t"
"[hostname or ip address]:[tcp port]\n\t"
"Receiver hostname or IP. Port is the receiver tcp port (optional).\n\t"
"Used for TCP control communication between client and receiver "
"to configure receiver. Also updates receiver with detector parameters.\n\t"
"TCP port must be unique, if included.\n\t"
"If port not included and not set earlier, then it takes default port 1954"
" and calculates from there. \n\t"
"[Eiger][Jungfrau] For the 2nd udp interface, use rx_hostname2."
<< '\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) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getRxHostname({det_id});
auto t = det->getRxHostname(udpInterface, {det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 1) {
@ -968,15 +987,15 @@ std::string CmdProxy::ReceiverHostname(int action) {
std::string hostname = res.first;
int port = res.second;
if (port == 0) {
det->setRxHostname(hostname, {det_id});
det->setRxHostname(udpInterface, hostname, {det_id});
} else {
if (det_id == -1) {
if (det_id == -1 && det->size() > 1) {
throw sls::RuntimeError("Cannot set same tcp port "
"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';
} else {
throw sls::RuntimeError("Unknown action");
@ -984,48 +1003,6 @@ std::string CmdProxy::ReceiverHostname(int action) {
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 */
/* ZMQ Streaming Parameters (Receiver<->Client) */
/* Eiger Specific */

View File

@ -720,7 +720,7 @@ class CmdProxy {
/* Receiver Config */
{"rx_hostname", &CmdProxy::ReceiverHostname},
{"rx_hostname2", &CmdProxy::ReceiverHostname2},
{"rx_hostname2", &CmdProxy::ReceiverHostname},
{"rx_tcpport", &CmdProxy::rx_tcpport},
{"rx_tcpport2", &CmdProxy::rx_tcpport2},
{"rx_fifodepth", &CmdProxy::rx_fifodepth},
@ -944,7 +944,6 @@ class CmdProxy {
std::string UDPDestinationIP2(int action);
/* Receiver Config */
std::string ReceiverHostname(int action);
std::string ReceiverHostname2(int action);
/* File */
/* ZMQ Streaming Parameters (Receiver<->Client) */
/* Eiger Specific */
@ -1435,10 +1434,10 @@ class CmdProxy {
/* 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.");
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.");
INTEGER_COMMAND(rx_fifodepth, getRxFifoDepth, setRxFifoDepth, StringTo<int>,

View File

@ -695,81 +695,98 @@ Result<bool> Detector::getUseReceiverFlag(Positions pos) const {
return pimpl->Parallel(&Module::getUseReceiverFlag, pos);
}
Result<std::string> Detector::getRxHostname(Positions pos) const {
return pimpl->Parallel1(&Receiver::getHostname, pos, {0});
Result<std::string> Detector::getRxHostname(const int udpInterface, Positions pos) const {
switch (udpInterface) {
case 1:
return pimpl->Parallel1(&Receiver::getHostname, pos, {0});
case 2:
return pimpl->Parallel2(&Receiver::getHostname, pos, {0});
default:
throw RuntimeError("Invalid udp interface number");
}
}
Result<std::string> Detector::getRxHostname2(Positions pos) const {
return pimpl->Parallel2(&Receiver::getHostname, pos, {0});
}
void Detector::setRxHostname(const std::string &hostname, Positions pos) {
if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver();
void Detector::setRxHostname(const int udpInterface, const std::string &hostname, Positions pos) {
switch (udpInterface) {
case 1:
if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver();
}
pimpl->Parallel1(&Receiver::setHostname, pos, {0}, hostname);
break;
case 2:
if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2();
}
pimpl->Parallel2(&Receiver::setHostname, pos, {0}, hostname);
break;
default:
throw RuntimeError("Invalid udp interface number");
}
pimpl->Parallel1(&Receiver::setHostname, pos, {0}, hostname);
}
void Detector::setRxHostname2(const std::string &hostname, Positions pos) {
if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2();
}
pimpl->Parallel2(&Receiver::setHostname, pos, {0}, hostname);
}
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) {
if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver();
switch (udpInterface) {
case 1:
if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver();
}
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
pimpl->Parallel1(&Receiver::setHostname, {module_id}, {0}, hostname);
break;
case 2:
if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2();
}
pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port);
pimpl->Parallel2(&Receiver::setHostname, {module_id}, {0}, hostname);
break;
default:
throw RuntimeError("Invalid udp interface number");
}
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
pimpl->Parallel1(&Receiver::setHostname, {module_id}, {0}, hostname);
}
void Detector::setRxHostname2(const std::string &hostname, const int port,
int module_id) {
if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2();
Result<int> Detector::getRxPort(const int udpInterface, Positions pos) const {
switch (udpInterface) {
case 1:
return pimpl->Parallel1(&Receiver::getTCPPort, pos, {0});
case 2:
return pimpl->Parallel2(&Receiver::getTCPPort, pos, {0});
default:
throw RuntimeError("Invalid udp interface number");
}
pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port);
pimpl->Parallel2(&Receiver::setHostname, {module_id}, {0}, hostname);
}
Result<int> Detector::getRxPort(Positions pos) const {
return pimpl->Parallel1(&Receiver::getTCPPort, pos, {0});
}
Result<int> Detector::getRxPort2(Positions pos) const {
return pimpl->Parallel2(&Receiver::getTCPPort, pos, {0});
}
void Detector::setRxPort(int port, int module_id) {
if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver();
}
if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel1(&Receiver::setTCPPort, {idet}, {0},
port_list[idet]);
void Detector::setRxPort(const int udpInterface, int port, int module_id) {
if (udpInterface == 1) {
if (!pimpl->isReceiverInitialized()) {
pimpl->initReceiver();
}
if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel1(&Receiver::setTCPPort, {idet}, {0},
port_list[idet]);
}
} else {
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
}
} else if (udpInterface == 2) {
if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2();
}
if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel2(&Receiver::setTCPPort, {idet}, {0},
port_list[idet]);
}
} else {
pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port);
}
} else {
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
}
}
void Detector::setRxPort2(int port, int module_id) {
if (!pimpl->isReceiver2Initialized()) {
pimpl->initReceiver2();
}
if (module_id == -1) {
std::vector<int> port_list = getPortNumbers(port);
for (int idet = 0; idet < size(); ++idet) {
pimpl->Parallel2(&Receiver::setTCPPort, {idet}, {0},
port_list[idet]);
}
} else {
pimpl->Parallel2(&Receiver::setTCPPort, {module_id}, {0}, port);
throw RuntimeError("Invalid udp interface number");
}
}

View File

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