mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-12 15:32:13 +02:00
WIP: some bug fixes and reducing redundant code
This commit is contained in:
parent
cd45f9d45b
commit
78fb8080ce
@ -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*/
|
/** cannot be for multiple detectors as port is unique */
|
||||||
void setRxHostname(const std::string &hostname, const int port,
|
void setRxHostname(const int udpInterface, const std::string &hostname,
|
||||||
int module_id);
|
const int port, int module_id);
|
||||||
void setRxHostname2(const std::string &hostname, const int port,
|
|
||||||
int module_id);
|
|
||||||
|
|
||||||
Result<int> getRxPort(Positions pos = {}) const;
|
/** interface is by 1 (primary udp interface),
|
||||||
/** for 2nd udp port receiver */
|
* 2 for second udp interface [Eiger][Jungfrau] */
|
||||||
Result<int> getRxPort2(Positions pos = {}) const;
|
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;
|
||||||
|
|
||||||
|
@ -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,24 +940,41 @@ 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) {
|
||||||
os << "[hostname or ip address]\n\t"
|
if (cmd == "rx_hostname") {
|
||||||
"[hostname or ip address]:[tcp port]\n\t"
|
os << "[hostname or ip address]\n\t"
|
||||||
"Receiver hostname or IP. Port is the receiver tcp port (optional).\n\t"
|
"[hostname or ip address]:[tcp port]\n\t"
|
||||||
"Used for TCP control communication between client and receiver "
|
"Receiver hostname or IP. Port is the receiver tcp port (optional).\n\t"
|
||||||
"to configure receiver. Also updates receiver with detector parameters.\n\t"
|
"Used for TCP control communication between client and receiver "
|
||||||
"TCP port must be unique, if included.\n\t"
|
"to configure receiver. Also updates receiver with detector parameters.\n\t"
|
||||||
"If port not included and not set earlier, then it takes default port 1954"
|
"TCP port must be unique, if included.\n\t"
|
||||||
" and calculates from there. \n\t"
|
"If port not included and not set earlier, then it takes default port 1954"
|
||||||
"[Eiger][Jungfrau] For the 2nd udp interface, use rx_hostname2."
|
" and calculates from there. \n\t"
|
||||||
<< '\n';
|
"[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) {
|
} 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 */
|
||||||
|
@ -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>,
|
||||||
|
@ -695,81 +695,98 @@ 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 {
|
||||||
return pimpl->Parallel1(&Receiver::getHostname, pos, {0});
|
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 {
|
void Detector::setRxHostname(const int udpInterface, const std::string &hostname, Positions pos) {
|
||||||
return pimpl->Parallel2(&Receiver::getHostname, pos, {0});
|
switch (udpInterface) {
|
||||||
}
|
case 1:
|
||||||
|
if (!pimpl->isReceiverInitialized()) {
|
||||||
void Detector::setRxHostname(const std::string &hostname, Positions pos) {
|
pimpl->initReceiver();
|
||||||
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) {
|
void Detector::setRxHostname(const int udpInterface, const std::string &hostname, const int port,
|
||||||
if (!pimpl->isReceiver2Initialized()) {
|
|
||||||
pimpl->initReceiver2();
|
|
||||||
}
|
|
||||||
pimpl->Parallel2(&Receiver::setHostname, pos, {0}, hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Detector::setRxHostname(const std::string &hostname, const int port,
|
|
||||||
int module_id) {
|
int module_id) {
|
||||||
if (!pimpl->isReceiverInitialized()) {
|
switch (udpInterface) {
|
||||||
pimpl->initReceiver();
|
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,
|
Result<int> Detector::getRxPort(const int udpInterface, Positions pos) const {
|
||||||
int module_id) {
|
switch (udpInterface) {
|
||||||
if (!pimpl->isReceiver2Initialized()) {
|
case 1:
|
||||||
pimpl->initReceiver2();
|
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 {
|
void Detector::setRxPort(const int udpInterface, int port, int module_id) {
|
||||||
return pimpl->Parallel1(&Receiver::getTCPPort, pos, {0});
|
if (udpInterface == 1) {
|
||||||
}
|
if (!pimpl->isReceiverInitialized()) {
|
||||||
|
pimpl->initReceiver();
|
||||||
Result<int> Detector::getRxPort2(Positions pos) const {
|
}
|
||||||
return pimpl->Parallel2(&Receiver::getTCPPort, pos, {0});
|
if (module_id == -1) {
|
||||||
}
|
std::vector<int> port_list = getPortNumbers(port);
|
||||||
|
for (int idet = 0; idet < size(); ++idet) {
|
||||||
void Detector::setRxPort(int port, int module_id) {
|
pimpl->Parallel1(&Receiver::setTCPPort, {idet}, {0},
|
||||||
if (!pimpl->isReceiverInitialized()) {
|
port_list[idet]);
|
||||||
pimpl->initReceiver();
|
}
|
||||||
}
|
} else {
|
||||||
if (module_id == -1) {
|
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
|
||||||
std::vector<int> port_list = getPortNumbers(port);
|
}
|
||||||
for (int idet = 0; idet < size(); ++idet) {
|
} else if (udpInterface == 2) {
|
||||||
pimpl->Parallel1(&Receiver::setTCPPort, {idet}, {0},
|
if (!pimpl->isReceiver2Initialized()) {
|
||||||
port_list[idet]);
|
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 {
|
} else {
|
||||||
pimpl->Parallel1(&Receiver::setTCPPort, {module_id}, {0}, port);
|
throw RuntimeError("Invalid udp interface number");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user