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

@ -4,10 +4,11 @@
#include "sls/sls_detector_defs.h"
#include <memory>
class ClientInterface;
namespace sls {
class ClientInterface;
class Receiver : private virtual slsDetectorDefs {
public:

View File

@ -6,6 +6,8 @@
#include <chrono>
#include <unistd.h>
namespace sls {
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
@ -16,7 +18,7 @@ void Arping::SetInterfacesAndIps(const int index, const std::string &interface,
const std::string &ip) {
if (interface.empty() || ip.empty()) {
throw sls::RuntimeError("Could not arping. Interface name and ip not "
throw RuntimeError("Could not arping. Interface name and ip not "
"set up for interface " +
std::to_string(index));
}
@ -38,7 +40,7 @@ void Arping::StartThread() {
try {
t = std::thread(&Arping::ThreadExecution, this);
} catch (...) {
throw sls::RuntimeError("Could not start arping thread");
throw RuntimeError("Could not start arping thread");
}
runningFlag = true;
}
@ -74,13 +76,13 @@ void Arping::ThreadExecution() {
void Arping::TestCommands() {
// atleast one interface must be set up
if (commands[0].empty()) {
throw sls::RuntimeError(
throw RuntimeError(
"Could not arping. Interface not set up in apring thread");
}
// test if arping commands throw an error
std::string error = ExecuteCommands();
if (!error.empty()) {
throw sls::RuntimeError(error);
throw RuntimeError(error);
}
}
@ -117,4 +119,6 @@ std::string Arping::ExecuteCommands() {
}
return std::string();
}
}
} // namespace sls

View File

@ -12,6 +12,8 @@ is listening to.
#include <atomic>
#include <thread>
namespace sls {
class Arping {
public:
@ -33,3 +35,6 @@ class Arping {
std::thread t;
std::atomic<pid_t> threadId{0};
};
} // namespace sls

View File

@ -2,6 +2,8 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "BinaryDataFile.h"
namespace sls {
BinaryDataFile::BinaryDataFile(const int index) : File(BINARY), index_(index) {}
BinaryDataFile::~BinaryDataFile() { CloseFile(); }
@ -47,12 +49,12 @@ void BinaryDataFile::CreateFile() {
if (!overWriteEnable_) {
if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "wx"))) {
fd_ = nullptr;
throw sls::RuntimeError("Could not create/overwrite file " +
throw RuntimeError("Could not create/overwrite file " +
fileName_);
}
} else if (nullptr == (fd_ = fopen((const char *)fileName_.c_str(), "w"))) {
fd_ = nullptr;
throw sls::RuntimeError("Could not create file " + fileName_);
throw RuntimeError("Could not create file " + fileName_);
}
// setting to no file buffering
setvbuf(fd_, nullptr, _IONBF, 0);
@ -103,8 +105,10 @@ void BinaryDataFile::WriteToFile(char *buffer, const int buffersize,
// if write error
if (ret != buffersize) {
throw sls::RuntimeError(std::to_string(index_) +
throw RuntimeError(std::to_string(index_) +
" : Write to file failed for image number " +
std::to_string(currentFrameNumber));
}
}
}
} // namespace sls

View File

@ -4,6 +4,8 @@
#include "File.h"
namespace sls {
class BinaryDataFile : private virtual slsDetectorDefs, public File {
public:
@ -42,4 +44,6 @@ class BinaryDataFile : private virtual slsDetectorDefs, public File {
int numUnitsPerReadout_{0};
uint32_t udpPortNumber_{0};
uint32_t maxFramesPerFile_{0};
};
};
} // namespace sls

View File

@ -22,10 +22,11 @@
#include <unistd.h>
#include <vector>
namespace sls {
using ns = std::chrono::nanoseconds;
using sls::RuntimeError;
using sls::SocketError;
using Interface = sls::ServerInterface;
using Interface = ServerInterface;
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
@ -33,6 +34,7 @@ using Interface = sls::ServerInterface;
#define gettid() syscall(SYS_gettid)
#endif
ClientInterface::~ClientInterface() {
killTcpThread = true;
LOG(logINFO) << "Shutting down TCP Socket on port " << portNumber;
@ -48,7 +50,7 @@ ClientInterface::ClientInterface(int portNumber)
functionTable();
parentThreadId = gettid();
tcpThread =
sls::make_unique<std::thread>(&ClientInterface::startTCPServer, this);
make_unique<std::thread>(&ClientInterface::startTCPServer, this);
}
int64_t ClientInterface::getReceiverVersion() { return APIRECEIVER; }
@ -98,7 +100,7 @@ void ClientInterface::startTCPServer() {
} catch (const RuntimeError &e) {
// We had an error needs to be sent to client
char mess[MAX_STR_LENGTH]{};
sls::strcpy_safe(mess, e.what());
strcpy_safe(mess, e.what());
socket.Send(FAIL);
socket.Send(mess);
}
@ -277,7 +279,7 @@ void ClientInterface::validate(T arg, T retval, const std::string &modename,
void ClientInterface::verifyLock() {
if (lockedByClient && server.getThisClient() != server.getLockedBy()) {
throw sls::SocketError("Receiver locked\n");
throw SocketError("Receiver locked\n");
}
}
@ -287,7 +289,7 @@ void ClientInterface::verifyIdle(Interface &socket) {
oss << "Can not execute "
<< getFunctionNameFromEnum((enum detFuncs)fnum)
<< " when receiver is not idle";
throw sls::SocketError(oss.str());
throw SocketError(oss.str());
}
}
@ -299,7 +301,7 @@ int ClientInterface::lock_receiver(Interface &socket) {
(server.getLockedBy() == server.getThisClient())) {
lockedByClient = lock;
lock ? server.setLockedBy(server.getThisClient())
: server.setLockedBy(sls::IpAddr{});
: server.setLockedBy(IpAddr{});
} else {
throw RuntimeError("Receiver locked\n");
}
@ -317,7 +319,7 @@ int ClientInterface::get_version(Interface &socket) {
int ClientInterface::setup_receiver(Interface &socket) {
auto arg = socket.Receive<rxParameters>();
LOG(logDEBUG) << sls::ToString(arg);
LOG(logDEBUG) << ToString(arg);
// if object exists, verify unlocked and idle, else only verify lock
// (connecting first time)
@ -333,17 +335,17 @@ int ClientInterface::setup_receiver(Interface &socket) {
// udp setup
// update retvals only if detmac is not the same as in detector
sls::MacAddr retvals[2];
MacAddr retvals[2];
if (arg.udp_dstip != 0) {
sls::MacAddr r = setUdpIp(sls::IpAddr(arg.udp_dstip));
sls::MacAddr detMac{arg.udp_dstmac};
MacAddr r = setUdpIp(IpAddr(arg.udp_dstip));
MacAddr detMac{arg.udp_dstmac};
if (detMac != r) {
retvals[0] = r;
}
}
if (arg.udp_dstip2 != 0) {
sls::MacAddr r = setUdpIp2(sls::IpAddr(arg.udp_dstip2));
sls::MacAddr detMac{arg.udp_dstmac2};
MacAddr r = setUdpIp2(IpAddr(arg.udp_dstip2));
MacAddr detMac{arg.udp_dstmac2};
if (detMac != r) {
retvals[1] = r;
}
@ -499,7 +501,7 @@ void ClientInterface::setDetectorType(detectorType arg) {
try {
detType = GENERIC;
receiver = sls::make_unique<Implementation>(arg);
receiver = make_unique<Implementation>(arg);
detType = arg;
} catch (std::exception &e) {
std::ostringstream os;
@ -527,7 +529,7 @@ void ClientInterface::setDetectorType(detectorType arg) {
int ClientInterface::set_detector_roi(Interface &socket) {
auto arg = socket.Receive<ROI>();
LOG(logDEBUG1) << "Set Detector ROI: " << sls::ToString(arg);
LOG(logDEBUG1) << "Set Detector ROI: " << ToString(arg);
if (detType != GOTTHARD)
functionNotImplemented();
@ -644,7 +646,7 @@ int ClientInterface::set_exptime(Interface &socket) {
socket.Receive(args);
int gateIndex = static_cast<int>(args[0]);
ns value = std::chrono::nanoseconds(args[1]);
LOG(logDEBUG1) << "Setting exptime to " << sls::ToString(value)
LOG(logDEBUG1) << "Setting exptime to " << ToString(value)
<< " (gateIndex: " << gateIndex << ")";
switch (gateIndex) {
case -1:
@ -683,14 +685,14 @@ int ClientInterface::set_exptime(Interface &socket) {
int ClientInterface::set_period(Interface &socket) {
auto value = std::chrono::nanoseconds(socket.Receive<int64_t>());
LOG(logDEBUG1) << "Setting period to " << sls::ToString(value);
LOG(logDEBUG1) << "Setting period to " << ToString(value);
impl()->setAcquisitionPeriod(value);
return socket.Send(OK);
}
int ClientInterface::set_subexptime(Interface &socket) {
auto value = std::chrono::nanoseconds(socket.Receive<int64_t>());
LOG(logDEBUG1) << "Setting period to " << sls::ToString(value);
LOG(logDEBUG1) << "Setting period to " << ToString(value);
ns subdeadtime = impl()->getSubPeriod() - impl()->getSubExpTime();
impl()->setSubExpTime(value);
impl()->setSubPeriod(impl()->getSubExpTime() + subdeadtime);
@ -699,10 +701,10 @@ int ClientInterface::set_subexptime(Interface &socket) {
int ClientInterface::set_subdeadtime(Interface &socket) {
auto value = std::chrono::nanoseconds(socket.Receive<int64_t>());
LOG(logDEBUG1) << "Setting sub deadtime to " << sls::ToString(value);
LOG(logDEBUG1) << "Setting sub deadtime to " << ToString(value);
impl()->setSubPeriod(value + impl()->getSubExpTime());
LOG(logDEBUG1) << "Setting sub period to "
<< sls::ToString(impl()->getSubPeriod());
<< ToString(impl()->getSubPeriod());
return socket.Send(OK);
}
@ -773,7 +775,7 @@ int ClientInterface::get_streaming_frequency(Interface &socket) {
int ClientInterface::get_status(Interface &socket) {
auto retval = impl()->getStatus();
LOG(logDEBUG1) << "Status:" << sls::ToString(retval);
LOG(logDEBUG1) << "Status:" << ToString(retval);
return socket.sendResult(retval);
}
@ -795,7 +797,7 @@ int ClientInterface::stop_receiver(Interface &socket) {
auto s = impl()->getStatus();
if (s != IDLE)
throw RuntimeError("Could not stop receiver. It as it is: " +
sls::ToString(s));
ToString(s));
return socket.Send(OK);
}
@ -856,7 +858,7 @@ int ClientInterface::get_file_index(Interface &socket) {
int ClientInterface::get_frame_index(Interface &socket) {
auto retval = impl()->getCurrentFrameIndex();
LOG(logDEBUG1) << "frames index:" << sls::ToString(retval);
LOG(logDEBUG1) << "frames index:" << ToString(retval);
auto size = static_cast<int>(retval.size());
socket.Send(OK);
socket.Send(size);
@ -866,7 +868,7 @@ int ClientInterface::get_frame_index(Interface &socket) {
int ClientInterface::get_missing_packets(Interface &socket) {
auto missing_packets = impl()->getNumMissingPackets();
LOG(logDEBUG1) << "missing packets:" << sls::ToString(missing_packets);
LOG(logDEBUG1) << "missing packets:" << ToString(missing_packets);
auto size = static_cast<int>(missing_packets.size());
socket.Send(OK);
socket.Send(size);
@ -876,7 +878,7 @@ int ClientInterface::get_missing_packets(Interface &socket) {
int ClientInterface::get_frames_caught(Interface &socket) {
auto retval = impl()->getFramesCaught();
LOG(logDEBUG1) << "frames caught:" << sls::ToString(retval);
LOG(logDEBUG1) << "frames caught:" << ToString(retval);
auto size = static_cast<int>(retval.size());
socket.Send(OK);
socket.Send(size);
@ -1094,7 +1096,7 @@ int ClientInterface::get_streaming_port(Interface &socket) {
}
int ClientInterface::set_streaming_source_ip(Interface &socket) {
auto ip = socket.Receive<sls::IpAddr>();
auto ip = socket.Receive<IpAddr>();
if (ip == 0)
throw RuntimeError("Invalid zmq ip " + ip.str());
verifyIdle(socket);
@ -1103,7 +1105,7 @@ int ClientInterface::set_streaming_source_ip(Interface &socket) {
}
int ClientInterface::get_streaming_source_ip(Interface &socket) {
sls::IpAddr retval = impl()->getStreamingSourceIP();
IpAddr retval = impl()->getStreamingSourceIP();
LOG(logDEBUG1) << "streaming IP:" << retval;
return socket.sendResult(retval);
}
@ -1151,14 +1153,14 @@ int ClientInterface::set_additional_json_header(Interface &socket) {
}
}
// verifyIdle(socket); allowing it to be set on the fly
LOG(logDEBUG1) << "Setting additional json header: " << sls::ToString(json);
LOG(logDEBUG1) << "Setting additional json header: " << ToString(json);
impl()->setAdditionalJsonHeader(json);
return socket.Send(OK);
}
int ClientInterface::get_additional_json_header(Interface &socket) {
std::map<std::string, std::string> json = impl()->getAdditionalJsonHeader();
LOG(logDEBUG1) << "additional json header:" << sls::ToString(json);
LOG(logDEBUG1) << "additional json header:" << ToString(json);
std::ostringstream oss;
for (auto &it : json) {
oss << it.first << ' ' << it.second << ' ';
@ -1323,7 +1325,7 @@ int ClientInterface::set_adc_mask(Interface &socket) {
}
int ClientInterface::set_dbit_list(Interface &socket) {
sls::StaticVector<int, MAX_RX_DBIT> args;
StaticVector<int, MAX_RX_DBIT> args;
socket.Receive(args);
if (detType != CHIPTESTBOARD)
functionNotImplemented();
@ -1340,7 +1342,7 @@ int ClientInterface::set_dbit_list(Interface &socket) {
int ClientInterface::get_dbit_list(Interface &socket) {
if (detType != CHIPTESTBOARD)
functionNotImplemented();
sls::StaticVector<int, MAX_RX_DBIT> retval;
StaticVector<int, MAX_RX_DBIT> retval;
retval = impl()->getDbitList();
LOG(logDEBUG1) << "Dbit list size retval:" << retval.size();
return socket.sendResult(retval);
@ -1403,10 +1405,10 @@ int ClientInterface::set_read_n_rows(Interface &socket) {
return socket.Send(OK);
}
sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
MacAddr ClientInterface::setUdpIp(IpAddr arg) {
LOG(logINFO) << "Received UDP IP: " << arg;
// getting eth
std::string eth = sls::IpToInterfaceName(arg.str());
std::string eth = IpToInterfaceName(arg.str());
if (eth == "none") {
throw RuntimeError("Failed to get udp ethernet interface from IP " +
arg.str());
@ -1425,7 +1427,7 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
udpips[0] = arg.str();
// get mac address
auto retval = sls::InterfaceNameToMac(eth);
auto retval = InterfaceNameToMac(eth);
if (retval == 0 && arg.str() != LOCALHOST_IP) {
throw RuntimeError("Failed to get udp mac adddress to listen to (eth:" +
eth + ", ip:" + arg.str() + ")\n");
@ -1435,16 +1437,16 @@ sls::MacAddr ClientInterface::setUdpIp(sls::IpAddr arg) {
}
int ClientInterface::set_udp_ip(Interface &socket) {
auto arg = socket.Receive<sls::IpAddr>();
auto arg = socket.Receive<IpAddr>();
verifyIdle(socket);
auto retval = setUdpIp(arg);
return socket.sendResult(retval);
}
sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
MacAddr ClientInterface::setUdpIp2(IpAddr arg) {
LOG(logINFO) << "Received UDP IP2: " << arg;
// getting eth
std::string eth = sls::IpToInterfaceName(arg.str());
std::string eth = IpToInterfaceName(arg.str());
if (eth == "none") {
throw RuntimeError("Failed to get udp ethernet interface2 from IP " +
arg.str());
@ -1460,7 +1462,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
udpips[1] = arg.str();
// get mac address
auto retval = sls::InterfaceNameToMac(eth);
auto retval = InterfaceNameToMac(eth);
if (retval == 0 && arg.str() != LOCALHOST_IP) {
throw RuntimeError(
"Failed to get udp mac adddress2 to listen to (eth:" + eth +
@ -1471,7 +1473,7 @@ sls::MacAddr ClientInterface::setUdpIp2(sls::IpAddr arg) {
}
int ClientInterface::set_udp_ip2(Interface &socket) {
auto arg = socket.Receive<sls::IpAddr>();
auto arg = socket.Receive<IpAddr>();
verifyIdle(socket);
if (detType != JUNGFRAU && detType != GOTTHARD2) {
throw RuntimeError(
@ -1595,7 +1597,7 @@ int ClientInterface::set_gate_delay(Interface &socket) {
socket.Receive(args);
int gateIndex = static_cast<int>(args[0]);
auto value = std::chrono::nanoseconds(args[1]);
LOG(logDEBUG1) << "Setting gate delay to " << sls::ToString(value)
LOG(logDEBUG1) << "Setting gate delay to " << ToString(value)
<< " (gateIndex: " << gateIndex << ")";
if (detType != MYTHEN3) {
functionNotImplemented();
@ -1624,7 +1626,7 @@ int ClientInterface::set_gate_delay(Interface &socket) {
int ClientInterface::get_thread_ids(Interface &socket) {
auto retval = impl()->getThreadIds();
LOG(logDEBUG1) << "thread ids retval: " << sls::ToString(retval);
LOG(logDEBUG1) << "thread ids retval: " << ToString(retval);
return socket.sendResult(retval);
}
@ -1663,7 +1665,7 @@ int ClientInterface::set_rate_correct(Interface &socket) {
int ClientInterface::set_scan(Interface &socket) {
auto arg = socket.Receive<scanParameters>();
LOG(logDEBUG) << "Scan Mode: " << sls::ToString(arg);
LOG(logDEBUG) << "Scan Mode: " << ToString(arg);
verifyIdle(socket);
impl()->setScan(arg);
return socket.Send(OK);
@ -1698,7 +1700,7 @@ int ClientInterface::set_streaming_hwm(Interface &socket) {
int ClientInterface::set_all_threshold(Interface &socket) {
auto eVs = socket.Receive<std::array<int, 3>>();
LOG(logDEBUG) << "Threshold:" << sls::ToString(eVs);
LOG(logDEBUG) << "Threshold:" << ToString(eVs);
if (detType != MYTHEN3)
functionNotImplemented();
verifyIdle(socket);
@ -1718,8 +1720,8 @@ int ClientInterface::set_detector_datastream(Interface &socket) {
throw RuntimeError("Invalid port type");
}
bool enable = static_cast<int>(args[1]);
LOG(logDEBUG1) << "Setting datastream (" << sls::ToString(port) << ") to "
<< sls::ToString(enable);
LOG(logDEBUG1) << "Setting datastream (" << ToString(port) << ") to "
<< ToString(enable);
if (detType != EIGER)
functionNotImplemented();
verifyIdle(socket);
@ -1746,7 +1748,7 @@ int ClientInterface::set_arping(Interface &socket) {
int ClientInterface::get_receiver_roi(Interface &socket) {
auto retval = impl()->getReceiverROI();
LOG(logDEBUG1) << "Receiver roi retval:" << sls::ToString(retval);
LOG(logDEBUG1) << "Receiver roi retval:" << ToString(retval);
return socket.sendResult(retval);
}
@ -1754,7 +1756,7 @@ int ClientInterface::set_receiver_roi(Interface &socket) {
auto arg = socket.Receive<ROI>();
if (detType == CHIPTESTBOARD || detType == MOENCH)
functionNotImplemented();
LOG(logDEBUG1) << "Set Receiver ROI: " << sls::ToString(arg);
LOG(logDEBUG1) << "Set Receiver ROI: " << ToString(arg);
verifyIdle(socket);
try {
impl()->setReceiverROI(arg);
@ -1768,7 +1770,7 @@ int ClientInterface::set_receiver_roi_metadata(Interface &socket) {
auto arg = socket.Receive<ROI>();
if (detType == CHIPTESTBOARD || detType == MOENCH)
functionNotImplemented();
LOG(logDEBUG1) << "Set Receiver ROI Metadata: " << sls::ToString(arg);
LOG(logDEBUG1) << "Set Receiver ROI Metadata: " << ToString(arg);
verifyIdle(socket);
try {
impl()->setReceiverROIMetadata(arg);
@ -1776,4 +1778,6 @@ int ClientInterface::set_receiver_roi_metadata(Interface &socket) {
throw RuntimeError("Could not set ReceiverROI metadata");
}
return socket.Send(OK);
}
}
} // namespace sls

View File

@ -6,16 +6,19 @@
#include "sls/ServerSocket.h"
#include "sls/sls_detector_defs.h"
#include "sls/sls_detector_funcs.h"
class ServerInterface;
#include <atomic>
#include <future>
namespace sls {
class ServerInterface;
class ClientInterface : private virtual slsDetectorDefs {
enum numberMode { DEC, HEX };
detectorType detType;
int portNumber{0};
sls::ServerSocket server;
ServerSocket server;
std::unique_ptr<Implementation> receiver;
std::unique_ptr<std::thread> tcpThread;
int ret{OK};
@ -53,132 +56,132 @@ class ClientInterface : private virtual slsDetectorDefs {
private:
void startTCPServer();
int functionTable();
int decodeFunction(sls::ServerInterface &socket);
int decodeFunction(ServerInterface &socket);
void functionNotImplemented();
void modeNotImplemented(const std::string &modename, int mode);
template <typename T>
void validate(T arg, T retval, const std::string &modename, numberMode hex);
void verifyLock();
void verifyIdle(sls::ServerInterface &socket);
void verifyIdle(ServerInterface &socket);
int lock_receiver(sls::ServerInterface &socket);
int get_last_client_ip(sls::ServerInterface &socket);
int get_version(sls::ServerInterface &socket);
int setup_receiver(sls::ServerInterface &socket);
int lock_receiver(ServerInterface &socket);
int get_last_client_ip(ServerInterface &socket);
int get_version(ServerInterface &socket);
int setup_receiver(ServerInterface &socket);
void setDetectorType(detectorType arg);
int set_detector_roi(sls::ServerInterface &socket);
int set_num_frames(sls::ServerInterface &socket);
int set_num_triggers(sls::ServerInterface &socket);
int set_num_bursts(sls::ServerInterface &socket);
int set_num_add_storage_cells(sls::ServerInterface &socket);
int set_timing_mode(sls::ServerInterface &socket);
int set_burst_mode(sls::ServerInterface &socket);
int set_num_analog_samples(sls::ServerInterface &socket);
int set_num_digital_samples(sls::ServerInterface &socket);
int set_exptime(sls::ServerInterface &socket);
int set_period(sls::ServerInterface &socket);
int set_subexptime(sls::ServerInterface &socket);
int set_subdeadtime(sls::ServerInterface &socket);
int set_dynamic_range(sls::ServerInterface &socket);
int set_streaming_frequency(sls::ServerInterface &socket);
int get_streaming_frequency(sls::ServerInterface &socket);
int get_status(sls::ServerInterface &socket);
int start_receiver(sls::ServerInterface &socket);
int stop_receiver(sls::ServerInterface &socket);
int set_file_dir(sls::ServerInterface &socket);
int get_file_dir(sls::ServerInterface &socket);
int set_file_name(sls::ServerInterface &socket);
int get_file_name(sls::ServerInterface &socket);
int set_file_index(sls::ServerInterface &socket);
int get_file_index(sls::ServerInterface &socket);
int get_frame_index(sls::ServerInterface &socket);
int get_missing_packets(sls::ServerInterface &socket);
int get_frames_caught(sls::ServerInterface &socket);
int set_file_write(sls::ServerInterface &socket);
int get_file_write(sls::ServerInterface &socket);
int set_master_file_write(sls::ServerInterface &socket);
int get_master_file_write(sls::ServerInterface &socket);
int enable_compression(sls::ServerInterface &socket);
int set_overwrite(sls::ServerInterface &socket);
int get_overwrite(sls::ServerInterface &socket);
int enable_tengiga(sls::ServerInterface &socket);
int set_fifo_depth(sls::ServerInterface &socket);
int set_activate(sls::ServerInterface &socket);
int set_streaming(sls::ServerInterface &socket);
int get_streaming(sls::ServerInterface &socket);
int set_streaming_timer(sls::ServerInterface &socket);
int get_flip_rows(sls::ServerInterface &socket);
int set_flip_rows(sls::ServerInterface &socket);
int set_file_format(sls::ServerInterface &socket);
int get_file_format(sls::ServerInterface &socket);
int set_streaming_port(sls::ServerInterface &socket);
int get_streaming_port(sls::ServerInterface &socket);
int set_streaming_source_ip(sls::ServerInterface &socket);
int get_streaming_source_ip(sls::ServerInterface &socket);
int set_silent_mode(sls::ServerInterface &socket);
int get_silent_mode(sls::ServerInterface &socket);
int restream_stop(sls::ServerInterface &socket);
int set_additional_json_header(sls::ServerInterface &socket);
int get_additional_json_header(sls::ServerInterface &socket);
int set_udp_socket_buffer_size(sls::ServerInterface &socket);
int get_real_udp_socket_buffer_size(sls::ServerInterface &socket);
int set_frames_per_file(sls::ServerInterface &socket);
int get_frames_per_file(sls::ServerInterface &socket);
int check_version_compatibility(sls::ServerInterface &socket);
int set_discard_policy(sls::ServerInterface &socket);
int get_discard_policy(sls::ServerInterface &socket);
int set_padding_enable(sls::ServerInterface &socket);
int get_padding_enable(sls::ServerInterface &socket);
int set_readout_mode(sls::ServerInterface &socket);
int set_adc_mask(sls::ServerInterface &socket);
int set_dbit_list(sls::ServerInterface &socket);
int get_dbit_list(sls::ServerInterface &socket);
int set_dbit_offset(sls::ServerInterface &socket);
int get_dbit_offset(sls::ServerInterface &socket);
int set_quad_type(sls::ServerInterface &socket);
int set_read_n_rows(sls::ServerInterface &socket);
sls::MacAddr setUdpIp(sls::IpAddr arg);
int set_udp_ip(sls::ServerInterface &socket);
sls::MacAddr setUdpIp2(sls::IpAddr arg);
int set_udp_ip2(sls::ServerInterface &socket);
int set_udp_port(sls::ServerInterface &socket);
int set_udp_port2(sls::ServerInterface &socket);
int set_num_interfaces(sls::ServerInterface &socket);
int set_adc_mask_10g(sls::ServerInterface &socket);
int set_counter_mask(sls::ServerInterface &socket);
int increment_file_index(sls::ServerInterface &socket);
int set_additional_json_parameter(sls::ServerInterface &socket);
int get_additional_json_parameter(sls::ServerInterface &socket);
int get_progress(sls::ServerInterface &socket);
int set_num_gates(sls::ServerInterface &socket);
int set_gate_delay(sls::ServerInterface &socket);
int get_thread_ids(sls::ServerInterface &socket);
int get_streaming_start_fnum(sls::ServerInterface &socket);
int set_streaming_start_fnum(sls::ServerInterface &socket);
int set_rate_correct(sls::ServerInterface &socket);
int set_scan(sls::ServerInterface &socket);
int set_threshold(sls::ServerInterface &socket);
int get_streaming_hwm(sls::ServerInterface &socket);
int set_streaming_hwm(sls::ServerInterface &socket);
int set_all_threshold(sls::ServerInterface &socket);
int set_detector_datastream(sls::ServerInterface &socket);
int get_arping(sls::ServerInterface &socket);
int set_arping(sls::ServerInterface &socket);
int get_receiver_roi(sls::ServerInterface &socket);
int set_receiver_roi(sls::ServerInterface &socket);
int set_receiver_roi_metadata(sls::ServerInterface &socket);
int set_detector_roi(ServerInterface &socket);
int set_num_frames(ServerInterface &socket);
int set_num_triggers(ServerInterface &socket);
int set_num_bursts(ServerInterface &socket);
int set_num_add_storage_cells(ServerInterface &socket);
int set_timing_mode(ServerInterface &socket);
int set_burst_mode(ServerInterface &socket);
int set_num_analog_samples(ServerInterface &socket);
int set_num_digital_samples(ServerInterface &socket);
int set_exptime(ServerInterface &socket);
int set_period(ServerInterface &socket);
int set_subexptime(ServerInterface &socket);
int set_subdeadtime(ServerInterface &socket);
int set_dynamic_range(ServerInterface &socket);
int set_streaming_frequency(ServerInterface &socket);
int get_streaming_frequency(ServerInterface &socket);
int get_status(ServerInterface &socket);
int start_receiver(ServerInterface &socket);
int stop_receiver(ServerInterface &socket);
int set_file_dir(ServerInterface &socket);
int get_file_dir(ServerInterface &socket);
int set_file_name(ServerInterface &socket);
int get_file_name(ServerInterface &socket);
int set_file_index(ServerInterface &socket);
int get_file_index(ServerInterface &socket);
int get_frame_index(ServerInterface &socket);
int get_missing_packets(ServerInterface &socket);
int get_frames_caught(ServerInterface &socket);
int set_file_write(ServerInterface &socket);
int get_file_write(ServerInterface &socket);
int set_master_file_write(ServerInterface &socket);
int get_master_file_write(ServerInterface &socket);
int enable_compression(ServerInterface &socket);
int set_overwrite(ServerInterface &socket);
int get_overwrite(ServerInterface &socket);
int enable_tengiga(ServerInterface &socket);
int set_fifo_depth(ServerInterface &socket);
int set_activate(ServerInterface &socket);
int set_streaming(ServerInterface &socket);
int get_streaming(ServerInterface &socket);
int set_streaming_timer(ServerInterface &socket);
int get_flip_rows(ServerInterface &socket);
int set_flip_rows(ServerInterface &socket);
int set_file_format(ServerInterface &socket);
int get_file_format(ServerInterface &socket);
int set_streaming_port(ServerInterface &socket);
int get_streaming_port(ServerInterface &socket);
int set_streaming_source_ip(ServerInterface &socket);
int get_streaming_source_ip(ServerInterface &socket);
int set_silent_mode(ServerInterface &socket);
int get_silent_mode(ServerInterface &socket);
int restream_stop(ServerInterface &socket);
int set_additional_json_header(ServerInterface &socket);
int get_additional_json_header(ServerInterface &socket);
int set_udp_socket_buffer_size(ServerInterface &socket);
int get_real_udp_socket_buffer_size(ServerInterface &socket);
int set_frames_per_file(ServerInterface &socket);
int get_frames_per_file(ServerInterface &socket);
int check_version_compatibility(ServerInterface &socket);
int set_discard_policy(ServerInterface &socket);
int get_discard_policy(ServerInterface &socket);
int set_padding_enable(ServerInterface &socket);
int get_padding_enable(ServerInterface &socket);
int set_readout_mode(ServerInterface &socket);
int set_adc_mask(ServerInterface &socket);
int set_dbit_list(ServerInterface &socket);
int get_dbit_list(ServerInterface &socket);
int set_dbit_offset(ServerInterface &socket);
int get_dbit_offset(ServerInterface &socket);
int set_quad_type(ServerInterface &socket);
int set_read_n_rows(ServerInterface &socket);
MacAddr setUdpIp(IpAddr arg);
int set_udp_ip(ServerInterface &socket);
MacAddr setUdpIp2(IpAddr arg);
int set_udp_ip2(ServerInterface &socket);
int set_udp_port(ServerInterface &socket);
int set_udp_port2(ServerInterface &socket);
int set_num_interfaces(ServerInterface &socket);
int set_adc_mask_10g(ServerInterface &socket);
int set_counter_mask(ServerInterface &socket);
int increment_file_index(ServerInterface &socket);
int set_additional_json_parameter(ServerInterface &socket);
int get_additional_json_parameter(ServerInterface &socket);
int get_progress(ServerInterface &socket);
int set_num_gates(ServerInterface &socket);
int set_gate_delay(ServerInterface &socket);
int get_thread_ids(ServerInterface &socket);
int get_streaming_start_fnum(ServerInterface &socket);
int set_streaming_start_fnum(ServerInterface &socket);
int set_rate_correct(ServerInterface &socket);
int set_scan(ServerInterface &socket);
int set_threshold(ServerInterface &socket);
int get_streaming_hwm(ServerInterface &socket);
int set_streaming_hwm(ServerInterface &socket);
int set_all_threshold(ServerInterface &socket);
int set_detector_datastream(ServerInterface &socket);
int get_arping(ServerInterface &socket);
int set_arping(ServerInterface &socket);
int get_receiver_roi(ServerInterface &socket);
int set_receiver_roi(ServerInterface &socket);
int set_receiver_roi_metadata(ServerInterface &socket);
Implementation *impl() {
if (receiver != nullptr) {
return receiver.get();
} else {
throw sls::SocketError(
throw SocketError(
"Receiver not set up. Please use rx_hostname first.\n");
}
}
int (ClientInterface::*flist[NUM_REC_FUNCTIONS])(
sls::ServerInterface &socket);
ServerInterface &socket);
//***callback parameters***
@ -198,3 +201,5 @@ class ClientInterface : private virtual slsDetectorDefs {
std::vector<std::string> udpips =
std::vector<std::string>(MAX_NUMBER_OF_LISTENING_THREADS);
};
} // namespace sls

View File

@ -24,6 +24,8 @@
#include <cstring>
#include <iostream>
namespace sls {
const std::string DataProcessor::typeName_ = "DataProcessor";
DataProcessor::DataProcessor(int index, detectorType detectorType, Fifo *fifo,
@ -65,7 +67,7 @@ void DataProcessor::ResetParametersforNewAcquisition() {
currentFrameIndex_ = 0;
firstStreamerFrame_ = true;
streamCurrentFrame_ = false;
completeImageToStreamBeforeCropping = sls::make_unique<char[]>(generalData_->imageSize);
completeImageToStreamBeforeCropping = make_unique<char[]>(generalData_->imageSize);
}
void DataProcessor::RecordFirstIndex(uint64_t fnum) {
@ -105,7 +107,7 @@ void DataProcessor::SetupFileWriter(const bool filewriteEnable,
dataFile_ = new BinaryDataFile(index);
break;
default:
throw sls::RuntimeError(
throw RuntimeError(
"Unknown file format (compile with hdf5 flags");
}
}
@ -119,7 +121,7 @@ void DataProcessor::CreateFirstFiles(
const uint64_t numImages, const uint32_t dynamicRange,
const bool detectorDataStream) {
if (dataFile_ == nullptr) {
throw sls::RuntimeError("file object not contstructed");
throw RuntimeError("file object not contstructed");
}
CloseFiles();
@ -154,14 +156,14 @@ void DataProcessor::CreateFirstFiles(
modulePos, numUnitsPerReadout, udpPortNumber, maxFramesPerFile);
break;
default:
throw sls::RuntimeError("Unknown file format (compile with hdf5 flags");
throw RuntimeError("Unknown file format (compile with hdf5 flags");
}
}
#ifdef HDF5C
uint32_t DataProcessor::GetFilesInAcquisition() const {
if (dataFile_ == nullptr) {
throw sls::RuntimeError("No data file object created to get number of "
throw RuntimeError("No data file object created to get number of "
"files in acquiistion");
}
return dataFile_->GetFilesInAcquisition();
@ -243,7 +245,7 @@ std::string DataProcessor::CreateMasterFile(
filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode,
attr);
default:
throw sls::RuntimeError("Unknown file format (compile with hdf5 flags");
throw RuntimeError("Unknown file format (compile with hdf5 flags");
}
}
@ -373,7 +375,7 @@ void DataProcessor::ProcessAnImage(char *buf) {
(*((uint32_t *)buf)) = revsize;
}
} catch (const std::exception &e) {
throw sls::RuntimeError("Get Data Callback Error: " +
throw RuntimeError("Get Data Callback Error: " +
std::string(e.what()));
}
@ -386,7 +388,7 @@ void DataProcessor::ProcessAnImage(char *buf) {
(uint32_t)(*((uint32_t *)buf)), //+ size of data (resizable
// from previous call back
fnum - firstIndex_, nump);
} catch (const sls::RuntimeError &e) {
} catch (const RuntimeError &e) {
; // ignore write exception for now (TODO: send error message
// via stopReceiver tcp)
}
@ -559,7 +561,7 @@ void DataProcessor::RearrangeDbitData(char *buf) {
}
void DataProcessor::CropImage(char *buf) {
LOG(logDEBUG) << "Cropping Image to ROI " << sls::ToString(receiverRoi_);
LOG(logDEBUG) << "Cropping Image to ROI " << ToString(receiverRoi_);
int nPixelsX = generalData_->nPixelsX;
int xmin = receiverRoi_.xmin;
int xmax = receiverRoi_.xmax;
@ -598,3 +600,5 @@ void DataProcessor::CropImage(char *buf) {
}
}
}
} // namespace sls

View File

@ -14,16 +14,18 @@
#include "ThreadObject.h"
#include "receiver_defs.h"
#include <atomic>
#include <mutex>
#include <vector>
namespace sls {
class GeneralData;
class Fifo;
class File;
class DataStreamer;
struct MasterAttributes;
#include <atomic>
#include <mutex>
#include <vector>
class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
public:
@ -206,3 +208,5 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
void *pRawDataReady{nullptr};
};
} // namespace sls

View File

@ -14,6 +14,8 @@
#include <cerrno>
#include <iostream>
namespace sls {
const std::string DataStreamer::TypeName = "DataStreamer";
DataStreamer::DataStreamer(int ind, Fifo *f, uint32_t *dr, ROI *r, uint64_t *fi,
@ -74,7 +76,7 @@ void DataStreamer::SetAdditionalJsonHeader(
}
void DataStreamer::CreateZmqSockets(int *nunits, uint32_t port,
const sls::IpAddr ip, int hwm) {
const IpAddr ip, int hwm) {
uint32_t portnum = port + index;
std::string sip = ip.str();
try {
@ -83,7 +85,7 @@ void DataStreamer::CreateZmqSockets(int *nunits, uint32_t port,
if (hwm >= 0) {
zmqSocket->SetSendHighWaterMark(hwm);
if (zmqSocket->GetSendHighWaterMark() != hwm) {
throw sls::RuntimeError(
throw RuntimeError(
"Could not set zmq send high water mark to " +
std::to_string(hwm));
}
@ -262,8 +264,10 @@ void DataStreamer::RestreamStop() {
zHeader.jsonversion = SLS_DETECTOR_JSON_HEADER_VERSION;
int ret = zmqSocket->SendHeader(index, zHeader);
if (!ret) {
throw sls::RuntimeError(
throw RuntimeError(
"Could not restream Dummy Header via ZMQ for port " +
std::to_string(zmqSocket->GetPortNumber()));
}
}
} // namespace sls

View File

@ -12,14 +12,16 @@
#include "ThreadObject.h"
#include "sls/network_utils.h"
#include <map>
#include <mutex>
namespace sls {
class GeneralData;
class Fifo;
class DataStreamer;
class ZmqSocket;
#include <map>
#include <mutex>
class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
public:
@ -62,7 +64,7 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
* @param ip streaming source ip
* @param hwm streaming high water mark
*/
void CreateZmqSockets(int *nunits, uint32_t port, const sls::IpAddr ip,
void CreateZmqSockets(int *nunits, uint32_t port, const IpAddr ip,
int hwm);
void CloseZmqSocket();
void RestreamStop();
@ -131,3 +133,5 @@ class DataStreamer : private virtual slsDetectorDefs, public ThreadObject {
bool *quadEnable;
uint64_t *totalNumFrames;
};
} // namespace sls

View File

@ -15,6 +15,8 @@
#include <iostream>
#include <unistd.h>
namespace sls {
Fifo::Fifo(int ind, uint32_t fifoItemSize, uint32_t depth)
: index(ind), memory(nullptr), fifoBound(nullptr), fifoFree(nullptr),
fifoStream(nullptr), fifoDepth(depth), status_fifoBound(0),
@ -35,14 +37,14 @@ void Fifo::CreateFifos(uint32_t fifoItemSize) {
DestroyFifos();
// create fifos
fifoBound = new sls::CircularFifo<char>(fifoDepth);
fifoFree = new sls::CircularFifo<char>(fifoDepth);
fifoStream = new sls::CircularFifo<char>(fifoDepth);
fifoBound = new CircularFifo<char>(fifoDepth);
fifoFree = new CircularFifo<char>(fifoDepth);
fifoStream = new CircularFifo<char>(fifoDepth);
// allocate memory
size_t mem_len = (size_t)fifoItemSize * (size_t)fifoDepth * sizeof(char);
memory = (char *)malloc(mem_len);
if (memory == nullptr) {
throw sls::RuntimeError("Could not allocate memory for fifos");
throw RuntimeError("Could not allocate memory for fifos");
}
memset(memory, 0, mem_len);
int pagesize = getpagesize();
@ -116,3 +118,5 @@ int Fifo::GetMinLevelForFifoFree() {
status_fifoFree = fifoDepth;
return temp;
}
} // namespace sls

View File

@ -16,6 +16,8 @@
#include "sls/CircularFifo.h"
namespace sls {
class Fifo : private virtual slsDetectorDefs {
public:
@ -94,13 +96,13 @@ class Fifo : private virtual slsDetectorDefs {
char *memory;
/** Circular Fifo pointing to addresses of bound data in memory */
sls::CircularFifo<char> *fifoBound;
CircularFifo<char> *fifoBound;
/** Circular Fifo pointing to addresses of freed data in memory */
sls::CircularFifo<char> *fifoFree;
CircularFifo<char> *fifoFree;
/** Circular Fifo pointing to addresses of to be streamed data in memory */
sls::CircularFifo<char> *fifoStream;
CircularFifo<char> *fifoStream;
/** Fifo depth set */
int fifoDepth;
@ -108,3 +110,6 @@ class Fifo : private virtual slsDetectorDefs {
volatile int status_fifoBound;
volatile int status_fifoFree;
};
} // namespace sls

View File

@ -4,8 +4,12 @@
#include <iostream>
namespace sls {
File::File(const slsDetectorDefs::fileFormat format) : format_(format) {}
File::~File() {}
slsDetectorDefs::fileFormat File::GetFileFormat() const { return format_; }
} // namespace sls

View File

@ -5,7 +5,9 @@
#include "sls/logger.h"
#include "sls/sls_detector_defs.h"
struct MasterAttributes;
#include <array>
namespace sls {
#ifdef HDF5C
#include "H5Cpp.h"
@ -14,7 +16,7 @@ using namespace H5;
#endif
#endif
#include <array>
struct MasterAttributes;
class File : private virtual slsDetectorDefs {
@ -89,3 +91,5 @@ class File : private virtual slsDetectorDefs {
protected:
slsDetectorDefs::fileFormat format_;
};
} // namespace sls

View File

@ -16,6 +16,8 @@
#include <cmath> //ceil
#include <vector>
namespace sls {
class GeneralData {
public:
@ -71,7 +73,7 @@ class GeneralData {
float GetPixelDepth() { return float(dynamicRange) / 8; }
void ThrowGenericError(std::string msg) const {
throw sls::RuntimeError(
throw RuntimeError(
msg + std::string("This is a generic function that should be "
"overloaded by a derived class"));
}
@ -393,7 +395,7 @@ class Mythen3Data : public GeneralData {
virtual void SetCounterMask(const int mask) {
int n = __builtin_popcount(mask);
if (n < 1 || n > 3) {
throw sls::RuntimeError("Invalid number of counters " +
throw RuntimeError("Invalid number of counters " +
std::to_string(n) + ". Expected 1-3.");
}
counterMask = mask;
@ -642,3 +644,5 @@ class MoenchData : public GeneralData {
LOG(logDEBUG) << "Databytes: " << imageSize;
};
};
} // namespace sls

View File

@ -5,6 +5,8 @@
#include <iomanip>
namespace sls {
HDF5DataFile::HDF5DataFile(int index, std::mutex *hdf5Lib)
: File(HDF5), index_(index), hdf5Lib_(hdf5Lib) {
@ -218,7 +220,7 @@ void HDF5DataFile::CreateFile() {
} catch (const Exception &error) {
error.printErrorStack();
CloseFile();
throw sls::RuntimeError("Could not create HDF5 handles in object " +
throw RuntimeError("Could not create HDF5 handles in object " +
index_);
}
if (!silentMode_) {
@ -266,7 +268,7 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
if (dynamicRange_ == 12) {
revBuffer = (char *)malloc(EIGER_16_BIT_IMAGE_SIZE);
if (revBuffer == nullptr) {
throw sls::RuntimeError("Could not allocate memory for 12 bit to "
throw RuntimeError("Could not allocate memory for 12 bit to "
"16 bit conversion in object " +
std::to_string(index_));
}
@ -300,7 +302,7 @@ void HDF5DataFile::WriteDataFile(const uint64_t currentFrameNumber,
}
LOG(logERROR) << "Could not write to file in object " << index_;
error.printErrorStack();
throw sls::RuntimeError("Could not write to file in object " +
throw RuntimeError("Could not write to file in object " +
std::to_string(index_));
}
}
@ -383,7 +385,7 @@ void HDF5DataFile::WriteParameterDatasets(const uint64_t currentFrameNumber,
i = 14;
} catch (const Exception &error) {
error.printErrorStack();
throw sls::RuntimeError(
throw RuntimeError(
"Could not write parameters (index:" + std::to_string(i) +
") to file in object " + std::to_string(index_));
}
@ -413,7 +415,7 @@ void HDF5DataFile::ExtendDataset() {
} catch (const Exception &error) {
error.printErrorStack();
throw sls::RuntimeError("Could not extend dataset in object " +
throw RuntimeError("Could not extend dataset in object " +
std::to_string(index_));
}
if (!silentMode_) {
@ -421,4 +423,6 @@ void HDF5DataFile::ExtendDataset() {
<< ", Total x Dimension: " << (extNumImages_ + numImages_);
}
extNumImages_ += numImages_;
}
}
} // namespace sls

View File

@ -6,6 +6,8 @@
#include <mutex>
namespace sls {
class HDF5DataFile : private virtual slsDetectorDefs, public File {
public:
@ -76,4 +78,6 @@ class HDF5DataFile : private virtual slsDetectorDefs, public File {
static const int EIGER_NUM_PIXELS{256 * 2 * 256};
static const int EIGER_16_BIT_IMAGE_SIZE{EIGER_NUM_PIXELS * 2};
};
};
} // namespace sls

View File

@ -22,6 +22,8 @@
#include <thread>
#include <unistd.h>
namespace sls {
/** cosntructor & destructor */
Implementation::Implementation(const detectorType d) { setDetectorType(d); }
@ -73,12 +75,12 @@ void Implementation::SetupFifoStructure() {
// create fifo structure
try {
fifo.push_back(sls::make_unique<Fifo>(
fifo.push_back(make_unique<Fifo>(
i, datasize + (generalData->fifoBufferHeaderSize), fifoDepth));
} catch (...) {
fifo.clear();
fifoDepth = 0;
throw sls::RuntimeError(
throw RuntimeError(
"Could not allocate memory for fifo structure " +
std::to_string(i) + ". FifoDepth is now 0.");
}
@ -117,10 +119,10 @@ void Implementation::setDetectorType(const detectorType d) {
case MOENCH:
case MYTHEN3:
case GOTTHARD2:
LOG(logINFO) << " ***** " << sls::ToString(d) << " Receiver *****";
LOG(logINFO) << " ***** " << ToString(d) << " Receiver *****";
break;
default:
throw sls::RuntimeError("This is an unknown receiver type " +
throw RuntimeError("This is an unknown receiver type " +
std::to_string(static_cast<int>(d)));
}
@ -176,7 +178,7 @@ void Implementation::setDetectorType(const detectorType d) {
try {
auto fifo_ptr = fifo[i].get();
listener.push_back(sls::make_unique<Listener>(
listener.push_back(make_unique<Listener>(
i, detType, fifo_ptr, &status, &udpPortNum[i], &eth[i],
&udpSocketBufferSize, &actualUDPSocketBufferSize,
&framesPerFile, &frameDiscardMode, &detectorDataStream[i],
@ -185,14 +187,14 @@ void Implementation::setDetectorType(const detectorType d) {
if (detType == CHIPTESTBOARD) {
ctbAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
}
dataProcessor.push_back(sls::make_unique<DataProcessor>(
dataProcessor.push_back(make_unique<DataProcessor>(
i, detType, fifo_ptr, &dataStreamEnable, &streamingFrequency,
&streamingTimerInMs, &streamingStartFnum, &framePadding,
&ctbDbitList, &ctbDbitOffset, &ctbAnalogDataBytes));
} catch (...) {
listener.clear();
dataProcessor.clear();
throw sls::RuntimeError(
throw RuntimeError(
"Could not create listener/dataprocessor threads (index:" +
std::to_string(i) + ")");
}
@ -209,7 +211,7 @@ void Implementation::setDetectorType(const detectorType d) {
}
SetThreadPriorities();
LOG(logDEBUG) << " Detector type set to " << sls::ToString(d);
LOG(logDEBUG) << " Detector type set to " << ToString(d);
}
slsDetectorDefs::xy Implementation::getDetectorSize() const {
@ -240,7 +242,7 @@ void Implementation::setDetectorSize(const slsDetectorDefs::xy size) {
it->SetNumberofPorts(numPorts);
}
LOG(logINFO) << "Detector Size (ports): " << sls::ToString(numPorts);
LOG(logINFO) << "Detector Size (ports): " << ToString(numPorts);
}
int Implementation::getModulePositionId() const { return modulePos; }
@ -303,7 +305,7 @@ Implementation::getFrameDiscardPolicy() const {
void Implementation::setFrameDiscardPolicy(const frameDiscardPolicy i) {
frameDiscardMode = i;
LOG(logINFO) << "Frame Discard Policy: " << sls::ToString(frameDiscardMode);
LOG(logINFO) << "Frame Discard Policy: " << ToString(frameDiscardMode);
}
bool Implementation::getFramePaddingEnable() const { return framePadding; }
@ -406,7 +408,7 @@ void Implementation::setReceiverROI(const slsDetectorDefs::ROI arg) {
}
}
LOG(logDEBUG)
<< iPort << ": portfullroi:" << sls::ToString(portFullRoi);
<< iPort << ": portfullroi:" << ToString(portFullRoi);
// no roi
if (arg.xmin > portFullRoi.xmax ||
@ -440,15 +442,15 @@ void Implementation::setReceiverROI(const slsDetectorDefs::ROI arg) {
}
for (size_t i = 0; i != dataProcessor.size(); ++i)
dataProcessor[i]->SetReceiverROI(portRois[i]);
LOG(logINFO) << "receiver roi: " << sls::ToString(receiverRoi);
LOG(logINFO) << "receiver roi: " << ToString(receiverRoi);
if (numUDPInterfaces == 2 && detType != slsDetectorDefs::GOTTHARD2) {
LOG(logINFO) << "port rois: " << sls::ToString(portRois);
LOG(logINFO) << "port rois: " << ToString(portRois);
}
}
void Implementation::setReceiverROIMetadata(const ROI arg) {
receiverRoiMetadata = arg;
LOG(logINFO) << "receiver roi Metadata: " << sls::ToString(receiverRoiMetadata);
LOG(logINFO) << "receiver roi Metadata: " << ToString(receiverRoiMetadata);
}
/**************************************************
@ -472,20 +474,20 @@ void Implementation::setFileFormat(const fileFormat f) {
fileFormatType = BINARY;
break;
default:
throw sls::RuntimeError("Unknown file format");
throw RuntimeError("Unknown file format");
}
for (const auto &it : dataProcessor)
it->SetupFileWriter(fileWriteEnable, fileFormatType, &hdf5LibMutex);
}
LOG(logINFO) << "File Format: " << sls::ToString(fileFormatType);
LOG(logINFO) << "File Format: " << ToString(fileFormatType);
}
std::string Implementation::getFilePath() const { return filePath; }
void Implementation::setFilePath(const std::string &c) {
if (!c.empty()) {
sls::mkdir_p(c); // throws if it can't create
mkdir_p(c); // throws if it can't create
filePath = c;
}
LOG(logINFO) << "File path: " << filePath;
@ -615,7 +617,7 @@ std::vector<int64_t> Implementation::getNumMissingPackets() const {
void Implementation::setScan(slsDetectorDefs::scanParameters s) {
scanParams = s;
LOG(logINFO) << "Scan parameters: " << sls::ToString(scanParams);
LOG(logINFO) << "Scan parameters: " << ToString(scanParams);
}
void Implementation::startReceiver() {
@ -634,7 +636,7 @@ void Implementation::startReceiver() {
startAcquisitionCallBack(filePath, fileName, fileIndex, imageSize,
pStartAcquisition);
} catch (const std::exception &e) {
throw sls::RuntimeError("Start Acquisition Callback Error: " +
throw RuntimeError("Start Acquisition Callback Error: " +
std::string(e.what()));
}
if (rawDataReadyCallBack != nullptr) {
@ -657,7 +659,7 @@ void Implementation::startReceiver() {
StartRunning();
LOG(logINFO) << "Receiver Started";
LOG(logINFO) << "Status: " << sls::ToString(status);
LOG(logINFO) << "Status: " << ToString(status);
}
void Implementation::setStoppedFlag(bool stopped) { stoppedFlag = stopped; }
@ -698,7 +700,7 @@ void Implementation::stopReceiver() {
}
status = RUN_FINISHED;
LOG(logINFO) << "Status: " << sls::ToString(status);
LOG(logINFO) << "Status: " << ToString(status);
{ // statistics
auto mp = getNumMissingPackets();
@ -741,8 +743,8 @@ void Implementation::stopReceiver() {
// change status
status = IDLE;
LOG(logINFO) << "Receiver Stopped";
LOG(logINFO) << "Status: " << sls::ToString(status);
throw sls::RuntimeError(
LOG(logINFO) << "Status: " << ToString(status);
throw RuntimeError(
"Acquisition Finished Callback Error: " +
std::string(e.what()));
}
@ -752,7 +754,7 @@ void Implementation::stopReceiver() {
// change status
status = IDLE;
LOG(logINFO) << "Receiver Stopped";
LOG(logINFO) << "Status: " << sls::ToString(status);
LOG(logINFO) << "Status: " << ToString(status);
}
void Implementation::startReadout() {
@ -823,9 +825,9 @@ void Implementation::CreateUDPSockets() {
for (unsigned int i = 0; i < listener.size(); ++i) {
listener[i]->CreateUDPSockets();
}
} catch (const sls::RuntimeError &e) {
} catch (const RuntimeError &e) {
shutDownUDPSockets();
throw sls::RuntimeError("Could not create UDP Socket(s).");
throw RuntimeError("Could not create UDP Socket(s).");
}
LOG(logDEBUG) << "UDP socket(s) created successfully.";
}
@ -838,11 +840,11 @@ void Implementation::SetupWriter() {
modulePos, numUDPInterfaces, udpPortNum[i], framesPerFile,
numberOfTotalFrames, dynamicRange, detectorDataStream[i]);
}
} catch (const sls::RuntimeError &e) {
} catch (const RuntimeError &e) {
shutDownUDPSockets();
for (const auto &it : dataProcessor)
it->CloseFiles();
throw sls::RuntimeError("Could not create first data file.");
throw RuntimeError("Could not create first data file.");
}
}
@ -968,7 +970,7 @@ int Implementation::getNumberofUDPInterfaces() const {
// not Eiger
void Implementation::setNumberofUDPInterfaces(const int n) {
if (detType == EIGER) {
throw sls::RuntimeError(
throw RuntimeError(
"Cannot set number of UDP interfaces for Eiger");
}
@ -994,7 +996,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
// listener and dataprocessor threads
try {
auto fifo_ptr = fifo[i].get();
listener.push_back(sls::make_unique<Listener>(
listener.push_back(make_unique<Listener>(
i, detType, fifo_ptr, &status, &udpPortNum[i], &eth[i],
&udpSocketBufferSize, &actualUDPSocketBufferSize,
&framesPerFile, &frameDiscardMode, &detectorDataStream[i],
@ -1007,7 +1009,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
ctbAnalogDataBytes =
generalData->GetNumberOfAnalogDatabytes();
}
dataProcessor.push_back(sls::make_unique<DataProcessor>(
dataProcessor.push_back(make_unique<DataProcessor>(
i, detType, fifo_ptr, &dataStreamEnable,
&streamingFrequency, &streamingTimerInMs,
&streamingStartFnum, &framePadding, &ctbDbitList,
@ -1018,7 +1020,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
} catch (...) {
listener.clear();
dataProcessor.clear();
throw sls::RuntimeError(
throw RuntimeError(
"Could not create listener/dataprocessor threads (index:" +
std::to_string(i) + ")");
}
@ -1029,7 +1031,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
if (quadEnable) {
flip = (i == 1 ? true : false);
}
dataStreamer.push_back(sls::make_unique<DataStreamer>(
dataStreamer.push_back(make_unique<DataStreamer>(
i, fifo[i].get(), &dynamicRange, &detectorRoi,
&fileIndex, flip, numPorts, &quadEnable,
&numberOfTotalFrames));
@ -1044,7 +1046,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
dataStreamer.clear();
dataStreamEnable = false;
}
throw sls::RuntimeError(
throw RuntimeError(
"Could not create datastreamer threads (index:" +
std::to_string(i) + ")");
}
@ -1116,7 +1118,7 @@ void Implementation::setUDPSocketBufferSize(const int s) {
size_t listSize = listener.size();
if ((detType == JUNGFRAU || detType == GOTTHARD2) &&
(int)listSize != numUDPInterfaces) {
throw sls::RuntimeError(
throw RuntimeError(
"Number of Interfaces " + std::to_string(numUDPInterfaces) +
" do not match listener size " + std::to_string(listSize));
}
@ -1126,7 +1128,7 @@ void Implementation::setUDPSocketBufferSize(const int s) {
}
// custom and didnt set, throw error
if (s != 0 && udpSocketBufferSize != s) {
throw sls::RuntimeError("Could not set udp socket buffer size. (No "
throw RuntimeError("Could not set udp socket buffer size. (No "
"CAP_NET_ADMIN privileges?)");
}
}
@ -1156,7 +1158,7 @@ void Implementation::setDataStreamEnable(const bool enable) {
if (quadEnable) {
flip = (i == 1 ? true : false);
}
dataStreamer.push_back(sls::make_unique<DataStreamer>(
dataStreamer.push_back(make_unique<DataStreamer>(
i, fifo[i].get(), &dynamicRange, &detectorRoi,
&fileIndex, flip, numPorts, &quadEnable,
&numberOfTotalFrames));
@ -1169,7 +1171,7 @@ void Implementation::setDataStreamEnable(const bool enable) {
} catch (...) {
dataStreamer.clear();
dataStreamEnable = false;
throw sls::RuntimeError(
throw RuntimeError(
"Could not set data stream enable.");
}
}
@ -1213,11 +1215,11 @@ void Implementation::setStreamingPort(const uint32_t i) {
LOG(logINFO) << "Streaming Port: " << streamingPort;
}
sls::IpAddr Implementation::getStreamingSourceIP() const {
IpAddr Implementation::getStreamingSourceIP() const {
return streamingSrcIP;
}
void Implementation::setStreamingSourceIP(const sls::IpAddr ip) {
void Implementation::setStreamingSourceIP(const IpAddr ip) {
streamingSrcIP = ip;
LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP;
}
@ -1243,7 +1245,7 @@ void Implementation::setAdditionalJsonHeader(
it->SetAdditionalJsonHeader(c);
}
LOG(logINFO) << "Additional JSON Header: "
<< sls::ToString(additionalJsonHeader);
<< ToString(additionalJsonHeader);
}
std::string
@ -1251,7 +1253,7 @@ Implementation::getAdditionalJsonParameter(const std::string &key) const {
if (additionalJsonHeader.find(key) != additionalJsonHeader.end()) {
return additionalJsonHeader.at(key);
}
throw sls::RuntimeError("No key " + key +
throw RuntimeError("No key " + key +
" found in additional json header");
}
@ -1286,7 +1288,7 @@ void Implementation::setAdditionalJsonParameter(const std::string &key,
it->SetAdditionalJsonHeader(additionalJsonHeader);
}
LOG(logINFO) << "Additional JSON Header: "
<< sls::ToString(additionalJsonHeader);
<< ToString(additionalJsonHeader);
}
/**************************************************
@ -1322,7 +1324,7 @@ void Implementation::updateTotalNumberOfFrames() {
numberOfTotalFrames =
numFrames * repeats * (int64_t)(numberOfAdditionalStorageCells + 1);
if (numberOfTotalFrames == 0) {
throw sls::RuntimeError("Invalid total number of frames to receive: 0");
throw RuntimeError("Invalid total number of frames to receive: 0");
}
LOG(logINFO) << "Total Number of Frames: " << numberOfTotalFrames;
}
@ -1393,7 +1395,7 @@ ns Implementation::getAcquisitionPeriod() const { return acquisitionPeriod; }
void Implementation::setAcquisitionPeriod(const ns i) {
acquisitionPeriod = i;
LOG(logINFO) << "Acquisition Period: " << sls::ToString(acquisitionPeriod);
LOG(logINFO) << "Acquisition Period: " << ToString(acquisitionPeriod);
}
ns Implementation::getAcquisitionTime() const { return acquisitionTime; }
@ -1409,54 +1411,54 @@ void Implementation::updateAcquisitionTime() {
void Implementation::setAcquisitionTime(const ns i) {
acquisitionTime = i;
LOG(logINFO) << "Acquisition Time: " << sls::ToString(acquisitionTime);
LOG(logINFO) << "Acquisition Time: " << ToString(acquisitionTime);
}
void Implementation::setAcquisitionTime1(const ns i) {
acquisitionTime1 = i;
LOG(logINFO) << "Acquisition Time1: " << sls::ToString(acquisitionTime1);
LOG(logINFO) << "Acquisition Time1: " << ToString(acquisitionTime1);
updateAcquisitionTime();
}
void Implementation::setAcquisitionTime2(const ns i) {
acquisitionTime2 = i;
LOG(logINFO) << "Acquisition Time2: " << sls::ToString(acquisitionTime2);
LOG(logINFO) << "Acquisition Time2: " << ToString(acquisitionTime2);
updateAcquisitionTime();
}
void Implementation::setAcquisitionTime3(const ns i) {
acquisitionTime3 = i;
LOG(logINFO) << "Acquisition Time3: " << sls::ToString(acquisitionTime3);
LOG(logINFO) << "Acquisition Time3: " << ToString(acquisitionTime3);
updateAcquisitionTime();
}
void Implementation::setGateDelay1(const ns i) {
gateDelay1 = i;
LOG(logINFO) << "Gate Delay1: " << sls::ToString(gateDelay1);
LOG(logINFO) << "Gate Delay1: " << ToString(gateDelay1);
}
void Implementation::setGateDelay2(const ns i) {
gateDelay2 = i;
LOG(logINFO) << "Gate Delay2: " << sls::ToString(gateDelay2);
LOG(logINFO) << "Gate Delay2: " << ToString(gateDelay2);
}
void Implementation::setGateDelay3(const ns i) {
gateDelay3 = i;
LOG(logINFO) << "Gate Delay3: " << sls::ToString(gateDelay3);
LOG(logINFO) << "Gate Delay3: " << ToString(gateDelay3);
}
ns Implementation::getSubExpTime() const { return subExpTime; }
void Implementation::setSubExpTime(const ns i) {
subExpTime = i;
LOG(logINFO) << "Sub Exposure Time: " << sls::ToString(subExpTime);
LOG(logINFO) << "Sub Exposure Time: " << ToString(subExpTime);
}
ns Implementation::getSubPeriod() const { return subPeriod; }
void Implementation::setSubPeriod(const ns i) {
subPeriod = i;
LOG(logINFO) << "Sub Period: " << sls::ToString(subPeriod);
LOG(logINFO) << "Sub Period: " << ToString(subPeriod);
}
uint32_t Implementation::getNumberofAnalogSamples() const {
@ -1497,7 +1499,7 @@ void Implementation::setCounterMask(const uint32_t i) {
counterMask = i;
SetupFifoStructure();
}
LOG(logINFO) << "Counter mask: " << sls::ToStringHex(counterMask);
LOG(logINFO) << "Counter mask: " << ToStringHex(counterMask);
int ncounters = __builtin_popcount(counterMask);
LOG(logINFO) << "Number of counters: " << ncounters;
}
@ -1530,7 +1532,7 @@ void Implementation::setDetectorROI(slsDetectorDefs::ROI arg) {
SetupFifoStructure();
}
LOG(logINFO) << "Detector ROI: " << sls::ToString(detectorRoi);
LOG(logINFO) << "Detector ROI: " << ToString(detectorRoi);
LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame);
}
@ -1553,9 +1555,9 @@ void Implementation::setTenGigaEnable(const bool b) {
detectorDataStream[RIGHT] = detectorDataStream10GbE[RIGHT];
}
LOG(logDEBUG) << "Detector datastream updated [Left: "
<< sls::ToString(detectorDataStream[LEFT])
<< ToString(detectorDataStream[LEFT])
<< ", Right: "
<< sls::ToString(detectorDataStream[RIGHT]) << "]";
<< ToString(detectorDataStream[RIGHT]) << "]";
}
}
LOG(logINFO) << "Ten Giga: " << (tengigaEnable ? "enabled" : "disabled");
@ -1623,14 +1625,14 @@ void Implementation::setDetectorDataStream(const portPosition port,
const bool enable) {
int index = (port == LEFT ? 0 : 1);
detectorDataStream10GbE[index] = enable;
LOG(logINFO) << "Detector 10GbE datastream (" << sls::ToString(port)
<< " Port): " << sls::ToString(detectorDataStream10GbE[index]);
LOG(logINFO) << "Detector 10GbE datastream (" << ToString(port)
<< " Port): " << ToString(detectorDataStream10GbE[index]);
// update datastream for 10g
if (tengigaEnable) {
detectorDataStream[index] = detectorDataStream10GbE[index];
LOG(logDEBUG) << "Detector datastream updated ["
<< (index == 0 ? "Left" : "Right")
<< "] : " << sls::ToString(detectorDataStream[index]);
<< "] : " << ToString(detectorDataStream[index]);
}
}
@ -1649,12 +1651,12 @@ void Implementation::setThresholdEnergy(const int value) {
void Implementation::setThresholdEnergy(const std::array<int, 3> value) {
thresholdAllEnergyeV = value;
LOG(logINFO) << "Threshold Energy (eV): "
<< sls::ToString(thresholdAllEnergyeV);
<< ToString(thresholdAllEnergyeV);
}
void Implementation::setRateCorrections(const std::vector<int64_t> &t) {
rateCorrections = t;
LOG(logINFO) << "Rate Corrections: " << sls::ToString(rateCorrections);
LOG(logINFO) << "Rate Corrections: " << ToString(rateCorrections);
}
slsDetectorDefs::readoutMode Implementation::getReadoutMode() const {
@ -1668,7 +1670,7 @@ void Implementation::setReadoutMode(const readoutMode f) {
generalData->SetReadoutMode(f);
SetupFifoStructure();
}
LOG(logINFO) << "Readout Mode: " << sls::ToString(f);
LOG(logINFO) << "Readout Mode: " << ToString(f);
LOG(logINFO) << "Packets per Frame: " << (generalData->packetsPerFrame);
}
@ -1748,3 +1750,5 @@ void Implementation::registerCallBackRawDataModifyReady(
it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,
pRawDataReady);
}
} // namespace sls

View File

@ -6,12 +6,7 @@
#include "sls/container_utils.h"
#include "sls/logger.h"
#include "sls/network_utils.h"
class GeneralData;
class Listener;
class DataProcessor;
class DataStreamer;
class Fifo;
class slsDetectorDefs;
#include "sls/sls_detector_defs.h"
#include <atomic>
#include <chrono>
@ -20,8 +15,16 @@ class slsDetectorDefs;
#include <memory>
#include <mutex>
#include <vector>
namespace sls {
using ns = std::chrono::nanoseconds;
class GeneralData;
class Listener;
class DataProcessor;
class DataStreamer;
class Fifo;
class Implementation : private virtual slsDetectorDefs {
public:
explicit Implementation(const detectorType d);
@ -137,8 +140,8 @@ class Implementation : private virtual slsDetectorDefs {
void setStreamingStartingFrameNumber(const uint32_t fnum);
uint32_t getStreamingPort() const;
void setStreamingPort(const uint32_t i);
sls::IpAddr getStreamingSourceIP() const;
void setStreamingSourceIP(const sls::IpAddr ip);
IpAddr getStreamingSourceIP() const;
void setStreamingSourceIP(const IpAddr ip);
int getStreamingHwm() const;
void setStreamingHwm(const int i);
std::map<std::string, std::string> getAdditionalJsonHeader() const;
@ -338,7 +341,7 @@ class Implementation : private virtual slsDetectorDefs {
uint32_t streamingTimerInMs{DEFAULT_STREAMING_TIMER_IN_MS};
uint32_t streamingStartFnum{0};
uint32_t streamingPort{0};
sls::IpAddr streamingSrcIP = sls::IpAddr{};
IpAddr streamingSrcIP = IpAddr{};
int streamingHwm{-1};
std::map<std::string, std::string> additionalJsonHeader;
@ -406,3 +409,5 @@ class Implementation : private virtual slsDetectorDefs {
// mutex shared across all hdf5 virtual, master and data files
std::mutex hdf5LibMutex;
};
} // namespace sls

View File

@ -11,7 +11,7 @@
#include "Fifo.h"
#include "GeneralData.h"
#include "sls/UdpRxSocket.h"
#include "sls/container_utils.h" // For sls::make_unique<>
#include "sls/container_utils.h" // For make_unique<>
#include "sls/network_utils.h"
#include "sls/sls_detector_exceptions.h"
@ -19,6 +19,8 @@
#include <cstring>
#include <iostream>
namespace sls {
const std::string Listener::TypeName = "Listener";
Listener::Listener(int ind, detectorType dtype, Fifo *f,
@ -86,9 +88,9 @@ void Listener::ResetParametersforNewAcquisition() {
if (myDetectorType == GOTTHARD2 && index != 0) {
packetSize = generalData->vetoPacketSize;
}
carryOverPacket = sls::make_unique<char[]>(packetSize);
carryOverPacket = make_unique<char[]>(packetSize);
memset(carryOverPacket.get(), 0, packetSize);
listeningPacket = sls::make_unique<char[]>(packetSize);
listeningPacket = make_unique<char[]>(packetSize);
memset(carryOverPacket.get(), 0, packetSize);
numPacketsStatistic = 0;
@ -139,14 +141,14 @@ void Listener::CreateUDPSockets() {
// InterfaceNameToIp(eth).str().c_str()
try {
udpSocket = sls::make_unique<sls::UdpRxSocket>(
udpSocket = make_unique<UdpRxSocket>(
*udpPortNumber, packetSize,
((*eth).length() ? sls::InterfaceNameToIp(*eth).str().c_str()
((*eth).length() ? InterfaceNameToIp(*eth).str().c_str()
: nullptr),
*udpSocketBufferSize);
LOG(logINFO) << index << ": UDP port opened at port " << *udpPortNumber;
} catch (...) {
throw sls::RuntimeError("Could not create UDP socket on port " +
throw RuntimeError("Could not create UDP socket on port " +
std::to_string(*udpPortNumber));
}
@ -188,9 +190,9 @@ void Listener::CreateDummySocketForUDPSocketBufferSize(int s) {
// create dummy socket
try {
sls::UdpRxSocket g(*udpPortNumber, packetSize,
UdpRxSocket g(*udpPortNumber, packetSize,
((*eth).length()
? sls::InterfaceNameToIp(*eth).str().c_str()
? InterfaceNameToIp(*eth).str().c_str()
: nullptr),
*udpSocketBufferSize);
@ -204,7 +206,7 @@ void Listener::CreateDummySocketForUDPSocketBufferSize(int s) {
}
} catch (...) {
throw sls::RuntimeError("Could not create a test UDP socket on port " +
throw RuntimeError("Could not create a test UDP socket on port " +
std::to_string(*udpPortNumber));
}
}
@ -649,3 +651,5 @@ void Listener::PrintFifoStatistics() {
<< " \tFree_Slots_Min_Level:" << fifo->GetMinLevelForFifoFree()
<< " \tCurrent_Frame#:" << currentFrameIndex;
}
} // namespace sls

View File

@ -16,6 +16,8 @@
#include <atomic>
#include <memory>
namespace sls {
class GeneralData;
class Fifo;
@ -117,7 +119,7 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
// individual members
detectorType myDetectorType;
std::atomic<runStatus> *status;
std::unique_ptr<sls::UdpRxSocket> udpSocket{nullptr};
std::unique_ptr<UdpRxSocket> udpSocket{nullptr};
uint32_t *udpPortNumber;
std::string *eth;
int *udpSocketBufferSize;
@ -172,3 +174,5 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject {
* (pecific to gotthard, can vary between modules, hence defined here) */
bool oddStartingPacket{true};
};
} // namespace sls

View File

@ -2,6 +2,8 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "MasterAttributes.h"
namespace sls {
void MasterAttributes::GetBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w) {
w->StartObject();
@ -29,7 +31,7 @@ void MasterAttributes::GetBinaryAttributes(
GetCtbBinaryAttributes(w);
break;
default:
throw sls::RuntimeError(
throw RuntimeError(
"Unknown Detector type to get master attributes");
}
GetFinalBinaryAttributes(w);
@ -62,7 +64,7 @@ void MasterAttributes::WriteHDF5Attributes(H5File *fd, Group *group) {
WriteCtbHDF5Attributes(fd, group);
break;
default:
throw sls::RuntimeError(
throw RuntimeError(
"Unknown Detector type to get master attributes");
}
WriteFinalHDF5Attributes(fd, group);
@ -75,14 +77,14 @@ void MasterAttributes::GetCommonBinaryAttributes(
w->SetMaxDecimalPlaces(2);
w->Double(BINARY_WRITER_VERSION);
w->Key("Timestamp");
time_t t = time(nullptr);
time_t t = std::time(nullptr);
std::string sTime(ctime(&t));
std::replace(sTime.begin(), sTime.end(), '\n', '\0');
w->String(sTime.c_str());
w->Key("Detector Type");
w->String(sls::ToString(detType).c_str());
w->String(ToString(detType).c_str());
w->Key("Timing Mode");
w->String(sls::ToString(timingMode).c_str());
w->String(ToString(timingMode).c_str());
w->Key("Geometry");
w->StartObject();
w->Key("x");
@ -102,11 +104,11 @@ void MasterAttributes::GetCommonBinaryAttributes(
w->Key("Max Frames Per File");
w->Uint(maxFramesPerFile);
w->Key("Frame Discard Policy");
w->String(sls::ToString(frameDiscardMode).c_str());
w->String(ToString(frameDiscardMode).c_str());
w->Key("Frame Padding");
w->Uint(framePadding);
w->Key("Scan Parameters");
w->String(sls::ToString(scanParams).c_str());
w->String(ToString(scanParams).c_str());
w->Key("Total Frames");
w->Uint64(totalFrames);
w->Key("Receiver Roi");
@ -127,7 +129,7 @@ void MasterAttributes::GetFinalBinaryAttributes(
// adding few common parameters to the end
if (!additionalJsonHeader.empty()) {
w->Key("Additional Json Header");
w->String(sls::ToString(additionalJsonHeader).c_str());
w->String(ToString(additionalJsonHeader).c_str());
}
w->Key("Frames in File");
w->Uint64(framesInFile);
@ -182,7 +184,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset =
group->createDataSet("Timestamp", strdatatype, dataspace);
sls::strcpy_safe(c, std::string(ctime(&t)));
strcpy_safe(c, std::string(ctime(&t)));
dataset.write(c, strdatatype);
}
// detector type
@ -191,7 +193,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Detector Type", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(detType));
strcpy_safe(c, ToString(detType));
dataset.write(c, strdatatype);
}
// timing mode
@ -200,7 +202,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Timing Mode", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(timingMode));
strcpy_safe(c, ToString(timingMode));
dataset.write(c, strdatatype);
}
// TODO: make this into an array?
@ -228,7 +230,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "bytes");
strcpy_safe(c, "bytes");
attribute.write(strdatatype, c);
}
// TODO: make this into an array?
@ -259,7 +261,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset = group->createDataSet("Frame Discard Policy",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(frameDiscardMode));
strcpy_safe(c, ToString(frameDiscardMode));
dataset.write(c, strdatatype);
}
// Frame Padding
@ -275,7 +277,7 @@ void MasterAttributes::WriteCommonHDF5Attributes(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Scan Parameters", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(scanParams));
strcpy_safe(c, ToString(scanParams));
dataset.write(c, strdatatype);
}
// Total Frames
@ -326,12 +328,12 @@ void MasterAttributes::WriteFinalHDF5Attributes(H5File *fd, Group *group) {
}
// additional json header
if (!additionalJsonHeader.empty()) {
std::string json = sls::ToString(additionalJsonHeader);
std::string json = ToString(additionalJsonHeader);
StrType strdatatype(PredType::C_S1, json.length());
DataSpace dataspace = DataSpace(H5S_SCALAR);
DataSet dataset = group->createDataSet("Additional JSON Header",
strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(additionalJsonHeader));
strcpy_safe(c, ToString(additionalJsonHeader));
dataset.write(c, strdatatype);
}
}
@ -342,7 +344,7 @@ void MasterAttributes::WriteHDF5Exptime(H5File *fd, Group *group) {
DataSet dataset =
group->createDataSet("Exposure Time", strdatatype, dataspace);
char c[1024]{};
sls::strcpy_safe(c, sls::ToString(exptime));
strcpy_safe(c, ToString(exptime));
dataset.write(c, strdatatype);
}
@ -352,7 +354,7 @@ void MasterAttributes::WriteHDF5Period(H5File *fd, Group *group) {
DataSet dataset =
group->createDataSet("Acquisition Period", strdatatype, dataspace);
char c[1024]{};
sls::strcpy_safe(c, sls::ToString(period));
strcpy_safe(c, ToString(period));
dataset.write(c, strdatatype);
}
@ -417,7 +419,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergy(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
Attribute attribute =
dataset.createAttribute("Unit", strdatatype, dataspaceAttr);
sls::strcpy_safe(c, "eV");
strcpy_safe(c, "eV");
attribute.write(strdatatype, c);
}
@ -427,7 +429,7 @@ void MasterAttributes::WriteHDF5ThresholdEnergies(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset =
group->createDataSet("Threshold Energies", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(thresholdAllEnergyeV));
strcpy_safe(c, ToString(thresholdAllEnergyeV));
dataset.write(c, strdatatype);
}
@ -437,7 +439,7 @@ void MasterAttributes::WriteHDF5SubExpTime(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Sub Exposure Time", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subExptime));
strcpy_safe(c, ToString(subExptime));
dataset.write(c, strdatatype);
}
@ -447,7 +449,7 @@ void MasterAttributes::WriteHDF5SubPeriod(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Sub Period", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(subPeriod));
strcpy_safe(c, ToString(subPeriod));
dataset.write(c, strdatatype);
}
@ -464,7 +466,7 @@ void MasterAttributes::WriteHDF5RateCorrections(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 1024);
DataSet dataset =
group->createDataSet("Rate Corrections", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(ratecorr));
strcpy_safe(c, ToString(ratecorr));
dataset.write(c, strdatatype);
}
@ -482,7 +484,7 @@ void MasterAttributes::WriteHDF5ExptimeArray(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Exposure Time1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(exptimeArray[i]));
strcpy_safe(c, ToString(exptimeArray[i]));
dataset.write(c, strdatatype);
}
}
@ -494,7 +496,7 @@ void MasterAttributes::WriteHDF5GateDelayArray(H5File *fd, Group *group) {
StrType strdatatype(PredType::C_S1, 256);
DataSet dataset =
group->createDataSet("Gate Delay1", strdatatype, dataspace);
sls::strcpy_safe(c, sls::ToString(gateDelayArray[i]));
strcpy_safe(c, ToString(gateDelayArray[i]));
dataset.write(c, strdatatype);
}
}
@ -512,7 +514,7 @@ void MasterAttributes::WriteHDF5BurstMode(H5File *fd, Group *group) {
DataSet dataset =
group->createDataSet("Burst Mode", strdatatype, dataspace);
char c[1024]{};
sls::strcpy_safe(c, sls::ToString(burstMode));
strcpy_safe(c, ToString(burstMode));
dataset.write(c, strdatatype);
}
@ -569,9 +571,9 @@ void MasterAttributes::WriteHDF5DbitList(H5File *fd, Group *group) {
void MasterAttributes::GetGotthardBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w) {
w->Key("Exptime");
w->String(sls::ToString(exptime).c_str());
w->String(ToString(exptime).c_str());
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Detector Roi");
w->StartObject();
w->Key("xmin");
@ -592,9 +594,9 @@ void MasterAttributes::WriteGotthardHDF5Attributes(H5File *fd, Group *group) {
void MasterAttributes::GetJungfrauBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w) {
w->Key("Exptime");
w->String(sls::ToString(exptime).c_str());
w->String(ToString(exptime).c_str());
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Number of UDP Interfaces");
w->Uint(numUDPInterfaces);
w->Key("Number of rows");
@ -617,21 +619,21 @@ void MasterAttributes::GetEigerBinaryAttributes(
w->Key("Ten Giga");
w->Uint(tenGiga);
w->Key("Exptime");
w->String(sls::ToString(exptime).c_str());
w->String(ToString(exptime).c_str());
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Threshold Energy");
w->Int(thresholdEnergyeV);
w->Key("Sub Exptime");
w->String(sls::ToString(subExptime).c_str());
w->String(ToString(subExptime).c_str());
w->Key("Sub Period");
w->String(sls::ToString(subPeriod).c_str());
w->String(ToString(subPeriod).c_str());
w->Key("Quad");
w->Int(quad);
w->Key("Number of rows");
w->Int(readNRows);
w->Key("Rate Corrections");
w->String(sls::ToString(ratecorr).c_str());
w->String(ToString(ratecorr).c_str());
}
#ifdef HDF5C
@ -656,21 +658,21 @@ void MasterAttributes::GetMythen3BinaryAttributes(
w->Key("Ten Giga");
w->Uint(tenGiga);
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Counter Mask");
w->String(sls::ToStringHex(counterMask).c_str());
w->String(ToStringHex(counterMask).c_str());
for (int i = 0; i != 3; ++i) {
w->Key((std::string("Exptime") + std::to_string(i + 1)).c_str());
w->String(sls::ToString(exptimeArray[i]).c_str());
w->String(ToString(exptimeArray[i]).c_str());
}
for (int i = 0; i != 3; ++i) {
w->Key((std::string("GateDelay") + std::to_string(i + 1)).c_str());
w->String(sls::ToString(gateDelayArray[i]).c_str());
w->String(ToString(gateDelayArray[i]).c_str());
}
w->Key("Gates");
w->Uint(gates);
w->Key("Threshold Energies");
w->String(sls::ToString(thresholdAllEnergyeV).c_str());
w->String(ToString(thresholdAllEnergyeV).c_str());
}
#ifdef HDF5C
@ -689,11 +691,11 @@ void MasterAttributes::WriteMythen3HDF5Attributes(H5File *fd, Group *group) {
void MasterAttributes::GetGotthard2BinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w) {
w->Key("Exptime");
w->String(sls::ToString(exptime).c_str());
w->String(ToString(exptime).c_str());
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Burst Mode");
w->String(sls::ToString(burstMode).c_str());
w->String(ToString(burstMode).c_str());
}
#ifdef HDF5C
@ -707,13 +709,13 @@ void MasterAttributes::WriteGotthard2HDF5Attributes(H5File *fd, Group *group) {
void MasterAttributes::GetMoenchBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w) {
w->Key("Exptime");
w->String(sls::ToString(exptime).c_str());
w->String(ToString(exptime).c_str());
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Ten Giga");
w->Uint(tenGiga);
w->Key("ADC Mask");
w->String(sls::ToStringHex(adcmask).c_str());
w->String(ToStringHex(adcmask).c_str());
w->Key("Analog Samples");
w->Uint(analogSamples);
}
@ -731,13 +733,13 @@ void MasterAttributes::WriteMoenchHDF5Attributes(H5File *fd, Group *group) {
void MasterAttributes::GetCtbBinaryAttributes(
rapidjson::PrettyWriter<rapidjson::StringBuffer> *w) {
w->Key("Exptime");
w->String(sls::ToString(exptime).c_str());
w->String(ToString(exptime).c_str());
w->Key("Period");
w->String(sls::ToString(period).c_str());
w->String(ToString(period).c_str());
w->Key("Ten Giga");
w->Uint(tenGiga);
w->Key("ADC Mask");
w->String(sls::ToStringHex(adcmask).c_str());
w->String(ToStringHex(adcmask).c_str());
w->Key("Analog Flag");
w->Uint(analog);
w->Key("Analog Samples");
@ -766,3 +768,5 @@ void MasterAttributes::WriteCtbHDF5Attributes(H5File *fd, Group *group) {
MasterAttributes::WriteHDF5DbitList(fd, group);
}
#endif
} // namespace sls

View File

@ -9,6 +9,11 @@
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <chrono>
namespace sls {
using ns = std::chrono::nanoseconds;
#ifdef HDF5C
#include "H5Cpp.h"
@ -17,9 +22,6 @@ using namespace H5;
#endif
#endif
#include <chrono>
using ns = std::chrono::nanoseconds;
class MasterAttributes {
public:
// (before acquisition)
@ -148,3 +150,5 @@ class MasterAttributes {
void WriteCtbHDF5Attributes(H5File *fd, Group *group);
#endif
};
} // namespace sls

View File

@ -5,6 +5,8 @@
#include <iomanip>
namespace sls {
namespace masterFileUtility {
std::string CreateMasterBinaryFile(const std::string &filePath,
@ -23,7 +25,7 @@ std::string CreateMasterBinaryFile(const std::string &filePath,
mode = "wx";
FILE *fd = fopen(fileName.c_str(), mode.c_str());
if(!fd) {
throw sls::RuntimeError("Could not create/overwrite binary master file " +
throw RuntimeError("Could not create/overwrite binary master file " +
fileName);
}
@ -32,7 +34,7 @@ std::string CreateMasterBinaryFile(const std::string &filePath,
attr->GetBinaryAttributes(&writer);
if (fwrite(s.GetString(), 1, strlen(s.GetString()), fd) !=
strlen(s.GetString())) {
throw sls::RuntimeError(
throw RuntimeError(
"Master binary file incorrect number of bytes written to file");
}
if (fd) {
@ -64,7 +66,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName,
FileCreatPropList::DEFAULT, flist);
// open data file
fd = sls::make_unique<H5File>(dataFilename.c_str(), H5F_ACC_RDONLY,
fd = make_unique<H5File>(dataFilename.c_str(), H5F_ACC_RDONLY,
FileCreatPropList::DEFAULT, flist);
// create link for data dataset
@ -73,7 +75,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName,
if (H5Lcreate_external(dataFilename.c_str(), dataSetname.c_str(),
masterfd.getLocId(), linkname.c_str(),
H5P_DEFAULT, H5P_DEFAULT) < 0) {
throw sls::RuntimeError(
throw RuntimeError(
"Could not create link to data dataset in master");
}
@ -85,7 +87,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName,
parameterNames[i].c_str(),
masterfd.getLocId(), linkname.c_str(),
H5P_DEFAULT, H5P_DEFAULT) < 0) {
throw sls::RuntimeError(
throw RuntimeError(
"Could not create link to parameter dataset in master");
}
}
@ -95,7 +97,7 @@ void LinkHDF5FileInMaster(const std::string &masterFileName,
error.printErrorStack();
if (fd != nullptr)
fd->close();
throw sls::RuntimeError("Could not link in master hdf5 file");
throw RuntimeError("Could not link in master hdf5 file");
}
if (!silentMode) {
LOG(logINFO) << "Linked in Master File: " << dataFilename;
@ -127,7 +129,7 @@ std::string CreateMasterHDF5File(const std::string &filePath,
if (overWriteEnable) {
createFlags = H5F_ACC_TRUNC;
}
fd = sls::make_unique<H5File>(fileName.c_str(), createFlags,
fd = make_unique<H5File>(fileName.c_str(), createFlags,
FileCreatPropList::DEFAULT, flist);
// attributes - version
@ -151,7 +153,7 @@ std::string CreateMasterHDF5File(const std::string &filePath,
error.printErrorStack();
if (fd != nullptr)
fd->close();
throw sls::RuntimeError(
throw RuntimeError(
"Could not create/overwrite master HDF5 handles");
}
if (!silentMode) {
@ -195,10 +197,10 @@ std::array<std::string, 2> CreateVirtualHDF5File(
FileAccPropList fapl;
fapl.setFcloseDegree(H5F_CLOSE_STRONG);
if (!overWriteEnable)
fd = sls::make_unique<H5File>(fileName.c_str(), H5F_ACC_EXCL,
fd = make_unique<H5File>(fileName.c_str(), H5F_ACC_EXCL,
FileCreatPropList::DEFAULT, fapl);
else
fd = sls::make_unique<H5File>(fileName.c_str(), H5F_ACC_TRUNC,
fd = make_unique<H5File>(fileName.c_str(), H5F_ACC_TRUNC,
FileCreatPropList::DEFAULT, fapl);
// attributes - version
@ -338,7 +340,7 @@ std::array<std::string, 2> CreateVirtualHDF5File(
if (fd) {
fd->close();
}
throw sls::RuntimeError(
throw RuntimeError(
"Could not create/overwrite virtual HDF5 handles");
}
if (!silentMode) {
@ -349,3 +351,5 @@ std::array<std::string, 2> CreateVirtualHDF5File(
#endif
} // namespace masterFileUtility
} // namespace sls

View File

@ -4,6 +4,10 @@
#include "MasterAttributes.h"
namespace sls {
namespace masterFileUtility {
#ifdef HDF5C
#include "H5Cpp.h"
#include <mutex>
@ -12,7 +16,6 @@ using namespace H5;
#endif
#endif
namespace masterFileUtility {
std::string CreateMasterBinaryFile(const std::string &filePath,
const std::string &fileNamePrefix,
@ -47,4 +50,6 @@ std::array<std::string, 2> CreateVirtualHDF5File(
const std::vector<DataType> parameterDataTypes, std::mutex *hdf5LibMutex,
bool gotthard25um);
#endif
} // namespace masterFileUtility
} // namespace masterFileUtility
} // namespace sls

View File

@ -53,7 +53,7 @@ void printHelp() {
*/
int StartAcq(const std::string &filePath, const std::string &fileName,
uint64_t fileIndex, size_t imageSize, void *objectPointer) {
LOG(logINFOBLUE) << "#### StartAcq: filePath:" << filePath
LOG(sls::logINFOBLUE) << "#### StartAcq: filePath:" << filePath
<< " fileName:" << fileName << " fileIndex:" << fileIndex
<< " imageSize:" << imageSize << " ####";
return 0;
@ -61,7 +61,7 @@ int StartAcq(const std::string &filePath, const std::string &fileName,
/** Acquisition Finished Call back */
void AcquisitionFinished(uint64_t framesCaught, void *objectPointer) {
LOG(logINFOBLUE) << "#### AcquisitionFinished: framesCaught:"
LOG(sls::logINFOBLUE) << "#### AcquisitionFinished: framesCaught:"
<< framesCaught << " ####";
}
@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
try {
receiver = sls::make_unique<sls::Receiver>(startTCPPort + i);
} catch (...) {
LOG(logINFOBLUE)
LOG(sls::logINFOBLUE)
<< "Exiting Child Process [ Tid: " << gettid() << " ]";
throw;
}

View File

@ -16,14 +16,14 @@
#include <string>
#include <unistd.h>
namespace sls {
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
namespace sls {
Receiver::~Receiver() = default;
Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
@ -66,7 +66,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
case 'u':
if (sscanf(optarg, "%u", &userid) != 1) {
throw sls::RuntimeError("Could not scan uid");
throw RuntimeError("Could not scan uid");
}
break;
@ -90,7 +90,7 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
"\t started with privileges. \n\n";
// std::cout << help_message << std::endl;
throw sls::RuntimeError(help_message);
throw RuntimeError(help_message);
}
}
@ -103,25 +103,25 @@ Receiver::Receiver(int argc, char *argv[]) : tcpipInterface(nullptr) {
if (seteuid(userid) != 0) {
std::ostringstream oss;
oss << "Could not set Effective UID to " << userid;
throw sls::RuntimeError(oss.str());
throw RuntimeError(oss.str());
}
if (geteuid() != userid) {
std::ostringstream oss;
oss << "Could not set Effective UID to " << userid << ". Got "
<< geteuid();
throw sls::RuntimeError(oss.str());
throw RuntimeError(oss.str());
}
LOG(logINFO) << "Process Effective UID changed to " << userid;
}
}
// might throw an exception
tcpipInterface = sls::make_unique<ClientInterface>(tcpip_port_no);
tcpipInterface = make_unique<ClientInterface>(tcpip_port_no);
}
Receiver::Receiver(int tcpip_port_no) {
// might throw an exception
tcpipInterface = sls::make_unique<ClientInterface>(tcpip_port_no);
tcpipInterface = make_unique<ClientInterface>(tcpip_port_no);
}
int64_t Receiver::getReceiverVersion() {

View File

@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {
sem_init(&semaphore, 1, 0);
LOG(logINFOBLUE) << "Created [ Tid: " << gettid() << " ]";
LOG(sls::logINFOBLUE) << "Created [ Tid: " << gettid() << " ]";
// Catch signal SIGINT to close files and call destructors properly
struct sigaction sa;
@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation
// of handler
if (sigaction(SIGINT, &sa, nullptr) == -1) {
LOG(logERROR) << "Could not set handler function for SIGINT";
LOG(sls::logERROR) << "Could not set handler function for SIGINT";
}
// if socket crash, ignores SISPIPE, prevents global signal handler
@ -44,18 +44,18 @@ int main(int argc, char *argv[]) {
sigemptyset(&asa.sa_mask); // dont block additional signals during
// invocation of handler
if (sigaction(SIGPIPE, &asa, nullptr) == -1) {
LOG(logERROR) << "Could not set handler function for SIGPIPE";
LOG(sls::logERROR) << "Could not set handler function for SIGPIPE";
}
try {
sls::Receiver r(argc, argv);
LOG(logINFO) << "[ Press \'Ctrl+c\' to exit ]";
LOG(sls::logINFO) << "[ Press \'Ctrl+c\' to exit ]";
sem_wait(&semaphore);
sem_destroy(&semaphore);
} catch (...) {
// pass
}
LOG(logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
LOG(logINFO) << "Exiting Receiver";
LOG(sls::logINFOBLUE) << "Exiting [ Tid: " << gettid() << " ]";
LOG(sls::logINFO) << "Exiting Receiver";
return 0;
}

View File

@ -10,6 +10,8 @@
#include <iostream>
#include <unistd.h>
namespace sls {
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
@ -23,7 +25,7 @@ ThreadObject::ThreadObject(int threadIndex, std::string threadType)
try {
threadObject = std::thread(&ThreadObject::RunningThread, this);
} catch (...) {
throw sls::RuntimeError("Could not create " + type +
throw RuntimeError("Could not create " + type +
" thread with index " + std::to_string(index));
}
}
@ -75,3 +77,5 @@ void ThreadObject::SetThreadPriority(int priority) {
LOG(logINFO) << "Priorities set - " << type << ": " << priority;
}
}
} // namespace sls

View File

@ -17,6 +17,8 @@
#include <string>
#include <thread>
namespace sls {
class ThreadObject : private virtual slsDetectorDefs {
protected:
const int index{0};
@ -47,3 +49,5 @@ class ThreadObject : private virtual slsDetectorDefs {
const std::string type;
std::atomic<pid_t> threadId{0};
};
} // namespace sls

View File

@ -5,6 +5,8 @@
#include "sls/sls_detector_defs.h"
#include <cstdint>
namespace sls {
#define MAX_DIMENSIONS (2)
#define MAX_NUMBER_OF_LISTENING_THREADS (2)
@ -55,3 +57,6 @@
#define PROCESSOR_PRIORITY (70)
#define STREAMER_PRIORITY (10)
#define TCP_PRIORITY (10)
} // namespace sls