rxr sls namespace (#457)

* rxr src files and classes (detectordata, ZmqSocket) added to sls namespace

* moving defines inside namespace

* moving defines inside namespace, added helpdacs to namespace

* added namespace to gui

* gui also updated

* removed unnecessary sls:: when already in sls namespace for slsDetectoSoftware, receverSoftware, slsDetectorGui and slsSupportlib
This commit is contained in:
Dhanya Thattil
2022-05-18 11:48:38 +02:00
committed by GitHub
parent fcc7f7aef8
commit 4259363169
88 changed files with 1200 additions and 923 deletions

View File

@ -93,7 +93,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
Receive(retval, retval_size);
}
// debugging
catch (sls::SocketError &e) {
catch (SocketError &e) {
if (socketType == "Receiver") {
throw ReceiverError("Receiver returned: " + std::string(e.what()));
} else if (socketType == "Detector") {

View File

@ -65,7 +65,7 @@ int DataSocket::Receive(void *buffer, size_t size) {
ss << "TCP socket read " << bytes_read << " bytes instead of "
<< bytes_expected << " bytes ("
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum_)) << ')';
throw sls::SocketError(ss.str());
throw SocketError(ss.str());
}
}
@ -91,7 +91,7 @@ int DataSocket::Send(const void *buffer, size_t size) {
ss << "TCP socket sent " << bytes_sent << " bytes instead of "
<< data_size << " bytes ("
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum_)) << ')';
throw sls::SocketError(ss.str());
throw SocketError(ss.str());
}
return bytes_sent;
}

View File

@ -14,12 +14,14 @@
#include <iostream>
#include <stdexcept>
#include <unistd.h>
namespace sls {
#define DEFAULT_PACKET_SIZE 1286
#define SOCKET_BUFFER_SIZE (100 * 1024 * 1024) // 100 MB
#define DEFAULT_BACKLOG 5
namespace sls {
ServerSocket::ServerSocket(int port)
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), serverPort(port) {
@ -31,7 +33,7 @@ ServerSocket::ServerSocket(int port)
if (bind(getSocketId(), (struct sockaddr *)&serverAddr,
sizeof(serverAddr)) != 0) {
close();
throw sls::SocketError(
throw SocketError(
std::string("Server ERROR: cannot bind socket with port number ") +
std::to_string(port) +
std::string(". Please check if another instance is running."));
@ -49,7 +51,7 @@ ServerInterface ServerSocket::accept() {
int newSocket =
::accept(getSocketId(), (struct sockaddr *)&clientAddr, &addr_size);
if (newSocket == -1) {
throw sls::SocketError("Server ERROR: socket accept failed\n");
throw SocketError("Server ERROR: socket accept failed\n");
}
char tc[INET_ADDRSTRLEN]{};
inet_ntop(AF_INET, &(clientAddr.sin_addr), tc, INET_ADDRSTRLEN);

View File

@ -38,11 +38,11 @@ std::string ToString(const slsDetectorDefs::rxParameters &r) {
<< "hostname:" << r.hostname << std::endl
<< "udpInterfaces:" << r.udpInterfaces << std::endl
<< "udp_dstport:" << r.udp_dstport << std::endl
<< "udp_dstip:" << sls::IpAddr(r.udp_dstip) << std::endl
<< "udp_dstmac:" << sls::MacAddr(r.udp_dstmac) << std::endl
<< "udp_dstip:" << IpAddr(r.udp_dstip) << std::endl
<< "udp_dstmac:" << MacAddr(r.udp_dstmac) << std::endl
<< "udp_dstport2:" << r.udp_dstport2 << std::endl
<< "udp_dstip2:" << sls::IpAddr(r.udp_dstip2) << std::endl
<< "udp_dstmac2:" << sls::MacAddr(r.udp_dstmac2) << std::endl
<< "udp_dstip2:" << IpAddr(r.udp_dstip2) << std::endl
<< "udp_dstmac2:" << MacAddr(r.udp_dstmac2) << std::endl
<< "frames:" << r.frames << std::endl
<< "triggers:" << r.triggers << std::endl
<< "bursts:" << r.bursts << std::endl
@ -86,7 +86,7 @@ std::string ToString(const slsDetectorDefs::rxParameters &r) {
<< "gateDelay3:" << ToString(std::chrono::nanoseconds(r.gateDelay3Ns))
<< std::endl
<< "gates:" << r.gates << std::endl
<< "scanParams:" << sls::ToString(r.scanParams) << std::endl
<< "scanParams:" << ToString(r.scanParams) << std::endl
<< ']';
return oss.str();
}
@ -123,7 +123,7 @@ std::ostream &operator<<(std::ostream &os,
std::string ToString(const slsDetectorDefs::currentSrcParameters &r) {
std::ostringstream oss;
if (r.fix < -1 || r.fix > 1 || r.normal < -1 || r.normal > 1) {
throw sls::RuntimeError(
throw RuntimeError(
"Invalid current source parameters. Cannot print.");
}
oss << '[';
@ -674,7 +674,7 @@ template <> defs::detectorType StringTo(const std::string &s) {
return defs::MYTHEN3;
if (s == "Gotthard2")
return defs::GOTTHARD2;
throw sls::RuntimeError("Unknown detector type " + s);
throw RuntimeError("Unknown detector type " + s);
}
template <> defs::detectorSettings StringTo(const std::string &s) {
@ -718,7 +718,7 @@ template <> defs::detectorSettings StringTo(const std::string &s) {
return defs::GAIN0;
if (s == "g4_lg")
return defs::G4_LOWGAIN;
throw sls::RuntimeError("Unknown setting " + s);
throw RuntimeError("Unknown setting " + s);
}
template <> defs::speedLevel StringTo(const std::string &s) {
@ -738,7 +738,7 @@ template <> defs::speedLevel StringTo(const std::string &s) {
return defs::G2_108MHZ;
if (s == "144")
return defs::G2_144MHZ;
throw sls::RuntimeError("Unknown speed " + s);
throw RuntimeError("Unknown speed " + s);
}
template <> defs::timingMode StringTo(const std::string &s) {
@ -752,7 +752,7 @@ template <> defs::timingMode StringTo(const std::string &s) {
return defs::BURST_TRIGGER;
if (s == "trigger_gating")
return defs::TRIGGER_GATED;
throw sls::RuntimeError("Unknown timing mode " + s);
throw RuntimeError("Unknown timing mode " + s);
}
template <> defs::frameDiscardPolicy StringTo(const std::string &s) {
@ -762,7 +762,7 @@ template <> defs::frameDiscardPolicy StringTo(const std::string &s) {
return defs::DISCARD_EMPTY_FRAMES;
if (s == "discardpartial")
return defs::DISCARD_PARTIAL_FRAMES;
throw sls::RuntimeError("Unknown frame discard policy " + s);
throw RuntimeError("Unknown frame discard policy " + s);
}
template <> defs::fileFormat StringTo(const std::string &s) {
@ -770,7 +770,7 @@ template <> defs::fileFormat StringTo(const std::string &s) {
return defs::HDF5;
if (s == "binary")
return defs::BINARY;
throw sls::RuntimeError("Unknown file format " + s);
throw RuntimeError("Unknown file format " + s);
}
template <> defs::externalSignalFlag StringTo(const std::string &s) {
@ -782,7 +782,7 @@ template <> defs::externalSignalFlag StringTo(const std::string &s) {
return defs::INVERSION_ON;
if (s == "inversion_off")
return defs::INVERSION_OFF;
throw sls::RuntimeError("Unknown external signal flag " + s);
throw RuntimeError("Unknown external signal flag " + s);
}
template <> defs::readoutMode StringTo(const std::string &s) {
@ -792,7 +792,7 @@ template <> defs::readoutMode StringTo(const std::string &s) {
return defs::DIGITAL_ONLY;
if (s == "analog_digital")
return defs::ANALOG_AND_DIGITAL;
throw sls::RuntimeError("Unknown readout mode " + s);
throw RuntimeError("Unknown readout mode " + s);
}
template <> defs::dacIndex StringTo(const std::string &s) {
@ -982,7 +982,7 @@ template <> defs::dacIndex StringTo(const std::string &s) {
return defs::TEMPERATURE_FPGA3;
if (s == "temp_slowadc")
return defs::SLOW_ADC_TEMP;
throw sls::RuntimeError("Unknown dac Index " + s);
throw RuntimeError("Unknown dac Index " + s);
}
template <> defs::burstMode StringTo(const std::string &s) {
@ -994,7 +994,7 @@ template <> defs::burstMode StringTo(const std::string &s) {
return defs::CONTINUOUS_INTERNAL;
if (s == "cw_external")
return defs::CONTINUOUS_EXTERNAL;
throw sls::RuntimeError("Unknown burst mode " + s);
throw RuntimeError("Unknown burst mode " + s);
}
template <> defs::timingSourceType StringTo(const std::string &s) {
@ -1002,7 +1002,7 @@ template <> defs::timingSourceType StringTo(const std::string &s) {
return defs::TIMING_INTERNAL;
if (s == "external")
return defs::TIMING_EXTERNAL;
throw sls::RuntimeError("Unknown timing source type " + s);
throw RuntimeError("Unknown timing source type " + s);
}
template <> defs::M3_GainCaps StringTo(const std::string &s) {
@ -1018,7 +1018,7 @@ template <> defs::M3_GainCaps StringTo(const std::string &s) {
return defs::M3_C225ACsh;
if (s == "C15pre")
return defs::M3_C15pre;
throw sls::RuntimeError("Unknown gain cap " + s);
throw RuntimeError("Unknown gain cap " + s);
}
template <> defs::portPosition StringTo(const std::string &s) {
@ -1030,7 +1030,7 @@ template <> defs::portPosition StringTo(const std::string &s) {
return defs::TOP;
if (s == "bottom")
return defs::BOTTOM;
throw sls::RuntimeError("Unknown port position " + s);
throw RuntimeError("Unknown port position " + s);
}
template <> defs::streamingInterface StringTo(const std::string &s) {
@ -1043,7 +1043,7 @@ template <> defs::streamingInterface StringTo(const std::string &s) {
return defs::streamingInterface::LOW_LATENCY_LINK;
if (rs == "10gbe")
return defs::streamingInterface::ETHERNET_10GB;
throw sls::RuntimeError("Unknown streamingInterface type " + s);
throw RuntimeError("Unknown streamingInterface type " + s);
}
template <> defs::vetoAlgorithm StringTo(const std::string &s) {
@ -1051,7 +1051,7 @@ template <> defs::vetoAlgorithm StringTo(const std::string &s) {
return defs::ALG_HITS;
if (s == "raw")
return defs::ALG_RAW;
throw sls::RuntimeError("Unknown veto algorithm " + s);
throw RuntimeError("Unknown veto algorithm " + s);
}
template <> defs::gainMode StringTo(const std::string &s) {
@ -1067,7 +1067,7 @@ template <> defs::gainMode StringTo(const std::string &s) {
return defs::FIX_G2;
if (s == "fixg0")
return defs::FIX_G0;
throw sls::RuntimeError("Unknown gain mode " + s);
throw RuntimeError("Unknown gain mode " + s);
}
template <> defs::polarity StringTo(const std::string &s) {
@ -1075,7 +1075,7 @@ template <> defs::polarity StringTo(const std::string &s) {
return defs::POSITIVE;
if (s == "neg")
return defs::NEGATIVE;
throw sls::RuntimeError("Unknown polarity mode " + s);
throw RuntimeError("Unknown polarity mode " + s);
}
template <> uint32_t StringTo(const std::string &s) {
@ -1101,7 +1101,7 @@ template <> bool StringTo(const std::string &s) {
case 1:
return true;
default:
throw sls::RuntimeError("Unknown boolean. Expecting be 0 or 1.");
throw RuntimeError("Unknown boolean. Expecting be 0 or 1.");
}
}

View File

@ -10,14 +10,15 @@
#include <string.h>
#include <thread>
#include <vector>
#include <zmq.h>
namespace sls {
using namespace rapidjson;
ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
const uint32_t portnumber)
: portno(portnumber), sockfd(false) {
// Extra check that throws if conversion fails, could be removed
auto ipstr = sls::HostnameToIp(hostname_or_ip).str();
auto ipstr = HostnameToIp(hostname_or_ip).str();
std::ostringstream oss;
oss << "tcp://" << ipstr << ":" << portno;
sockfd.serverAddress = oss.str();
@ -26,20 +27,20 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
// create context
sockfd.contextDescriptor = zmq_ctx_new();
if (sockfd.contextDescriptor == nullptr)
throw sls::ZmqSocketError("Could not create contextDescriptor");
throw ZmqSocketError("Could not create contextDescriptor");
// create subscriber
sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_SUB);
if (sockfd.socketDescriptor == nullptr) {
PrintError();
throw sls::ZmqSocketError("Could not create socket");
throw ZmqSocketError("Could not create socket");
}
// Socket Options provided above
// an empty string implies receiving any messages
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SUBSCRIBE, "", 0)) {
PrintError();
throw sls::ZmqSocketError("Could set socket opt");
throw ZmqSocketError("Could set socket opt");
}
// ZMQ_LINGER default is already -1 means no messages discarded. use this
// options if optimizing required ZMQ_SNDHWM default is 0 means no limit.
@ -48,7 +49,7 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_LINGER, &value,
sizeof(value))) {
PrintError();
throw sls::ZmqSocketError("Could not set ZMQ_LINGER");
throw ZmqSocketError("Could not set ZMQ_LINGER");
}
LOG(logDEBUG) << "Default receive high water mark:"
<< GetReceiveHighWaterMark();
@ -59,13 +60,13 @@ ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip)
// create context
sockfd.contextDescriptor = zmq_ctx_new();
if (sockfd.contextDescriptor == nullptr)
throw sls::ZmqSocketError("Could not create contextDescriptor");
throw ZmqSocketError("Could not create contextDescriptor");
// create publisher
sockfd.socketDescriptor = zmq_socket(sockfd.contextDescriptor, ZMQ_PUB);
if (sockfd.socketDescriptor == nullptr) {
PrintError();
throw sls::ZmqSocketError("Could not create socket");
throw ZmqSocketError("Could not create socket");
}
LOG(logDEBUG) << "Default send high water mark:" << GetSendHighWaterMark();
@ -78,7 +79,7 @@ ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip)
// bind address
if (zmq_bind(sockfd.socketDescriptor, sockfd.serverAddress.c_str())) {
PrintError();
throw sls::ZmqSocketError("Could not bind socket");
throw ZmqSocketError("Could not bind socket");
}
// sleep to allow a slow-joiner
std::this_thread::sleep_for(std::chrono::milliseconds(200));
@ -90,7 +91,7 @@ int ZmqSocket::GetSendHighWaterMark() {
if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_SNDHWM, &value,
&value_size)) {
PrintError();
throw sls::ZmqSocketError("Could not get ZMQ_SNDHWM");
throw ZmqSocketError("Could not get ZMQ_SNDHWM");
}
return value;
}
@ -99,7 +100,7 @@ void ZmqSocket::SetSendHighWaterMark(int limit) {
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_SNDHWM, &limit,
sizeof(limit))) {
PrintError();
throw sls::ZmqSocketError("Could not set ZMQ_SNDHWM");
throw ZmqSocketError("Could not set ZMQ_SNDHWM");
}
}
@ -109,7 +110,7 @@ int ZmqSocket::GetReceiveHighWaterMark() {
if (zmq_getsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &value,
&value_size)) {
PrintError();
throw sls::ZmqSocketError("Could not get ZMQ_SNDHWM");
throw ZmqSocketError("Could not get ZMQ_SNDHWM");
}
return value;
}
@ -118,7 +119,7 @@ void ZmqSocket::SetReceiveHighWaterMark(int limit) {
if (zmq_setsockopt(sockfd.socketDescriptor, ZMQ_RCVHWM, &limit,
sizeof(limit))) {
PrintError();
throw sls::ZmqSocketError("Could not set ZMQ_SNDHWM");
throw ZmqSocketError("Could not set ZMQ_SNDHWM");
}
}
@ -414,3 +415,6 @@ void ZmqSocket::mySocketDescriptors::Close() {
contextDescriptor = nullptr;
}
};
} // namespace sls

View File

@ -60,28 +60,28 @@ std::vector<char> readBinaryFile(const std::string &fname,
// check if it exists
struct stat st;
if (stat(fname.c_str(), &st) != 0) {
throw sls::RuntimeError(errorPrefix +
throw RuntimeError(errorPrefix +
std::string(" (file does not exist)"));
}
FILE *fp = fopen(fname.c_str(), "rb");
if (fp == nullptr) {
throw sls::RuntimeError(errorPrefix +
throw RuntimeError(errorPrefix +
std::string(" (Could not open file: ") + fname +
std::string(")"));
}
// get file size to print progress
ssize_t filesize = sls::getFileSize(fp, errorPrefix);
ssize_t filesize = getFileSize(fp, errorPrefix);
std::vector<char> buffer(filesize, 0);
if ((ssize_t)fread(buffer.data(), sizeof(char), filesize, fp) != filesize) {
throw sls::RuntimeError(errorPrefix +
throw RuntimeError(errorPrefix +
std::string(" (Could not read file)"));
}
if (fclose(fp) != 0) {
throw sls::RuntimeError(errorPrefix +
throw RuntimeError(errorPrefix +
std::string(" (Could not close file)"));
}
@ -125,7 +125,7 @@ void mkdir_p(const std::string &path, std::string dir) {
}
if (mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
if (errno != EEXIST)
throw sls::RuntimeError("Could not create: " + dir);
throw RuntimeError("Could not create: " + dir);
}
if (i + 1 < path.length())