format + exception.cpp

This commit is contained in:
Erik Frojdh 2020-05-13 14:48:52 +02:00
parent f0f97f265a
commit 3962714b48
14 changed files with 63 additions and 39 deletions

View File

@ -1282,7 +1282,8 @@ int Module::getADC(dacIndex index) {
slsDetectorDefs::externalSignalFlag slsDetectorDefs::externalSignalFlag
Module::setExternalSignalFlags(externalSignalFlag pol) { Module::setExternalSignalFlags(externalSignalFlag pol) {
LOG(logDEBUG1) << "Setting signal flag to " << pol; LOG(logDEBUG1) << "Setting signal flag to " << pol;
return sendToDetector<slsDetectorDefs::externalSignalFlag>(F_SET_EXTERNAL_SIGNAL_FLAG, pol); return sendToDetector<slsDetectorDefs::externalSignalFlag>(
F_SET_EXTERNAL_SIGNAL_FLAG, pol);
} }
void Module::setParallelMode(const bool enable) { void Module::setParallelMode(const bool enable) {
@ -1835,7 +1836,8 @@ std::string Module::getAdditionalJsonParameter(const std::string &key) {
} }
int64_t Module::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize) { int64_t Module::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize) {
return sendToReceiver<int64_t>(F_RECEIVER_UDP_SOCK_BUF_SIZE, udpsockbufsize); return sendToReceiver<int64_t>(F_RECEIVER_UDP_SOCK_BUF_SIZE,
udpsockbufsize);
} }
int64_t Module::getReceiverUDPSocketBufferSize() { int64_t Module::getReceiverUDPSocketBufferSize() {
@ -2216,7 +2218,8 @@ bool Module::getDeactivatedRxrPaddingMode() {
} }
void Module::setDeactivatedRxrPaddingMode(bool padding) { void Module::setDeactivatedRxrPaddingMode(bool padding) {
sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING, static_cast<int>(padding), nullptr); sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING,
static_cast<int>(padding), nullptr);
} }
bool Module::getFlippedDataX() { bool Module::getFlippedDataX() {
@ -2656,7 +2659,7 @@ int64_t Module::getFramesCaughtByReceiver() const {
} }
std::vector<uint64_t> Module::getNumMissingPackets() const { std::vector<uint64_t> Module::getNumMissingPackets() const {
//TODO!(Erik) Refactor // TODO!(Erik) Refactor
LOG(logDEBUG1) << "Getting num missing packets"; LOG(logDEBUG1) << "Getting num missing packets";
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
int fnum = F_GET_NUM_MISSING_PACKETS; int fnum = F_GET_NUM_MISSING_PACKETS;
@ -2701,7 +2704,8 @@ bool Module::getFileWrite() {
} }
void Module::setMasterFileWrite(bool value) { void Module::setMasterFileWrite(bool value) {
sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, static_cast<int>(value), nullptr); sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, static_cast<int>(value),
nullptr);
} }
bool Module::getMasterFileWrite() { bool Module::getMasterFileWrite() {

View File

@ -2,7 +2,7 @@
#include "catch.hpp" #include "catch.hpp"
using dt = slsDetectorDefs::detectorType; using dt = slsDetectorDefs::detectorType;
TEST_CASE("Construction with a defined detector type") { TEST_CASE("Construction with a defined detector type") {
sls::Module m(dt::EIGER); sls::Module m(dt::EIGER);
REQUIRE(m.getDetectorType() == dt::EIGER); REQUIRE(m.getDetectorType() == dt::EIGER);
} }

View File

@ -2,6 +2,7 @@
* binary */ * binary */
#include "Receiver.h" #include "Receiver.h"
#include "container_utils.h" #include "container_utils.h"
#include "logger.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include <csignal> //SIGINT #include <csignal> //SIGINT

View File

@ -9,13 +9,13 @@ set(SOURCES
src/network_utils.cpp src/network_utils.cpp
src/ZmqSocket.cpp src/ZmqSocket.cpp
src/UdpRxSocket.cpp src/UdpRxSocket.cpp
src/sls_detector_exceptions.cpp
) )
set(HEADERS set(HEADERS
) )
set(PUBLICHEADERS set(PUBLICHEADERS
include/ansi.h
include/sls_detector_defs.h include/sls_detector_defs.h
include/sls_detector_funcs.h include/sls_detector_funcs.h
include/versionAPI.h include/versionAPI.h
@ -23,7 +23,6 @@ set(PUBLICHEADERS
include/file_utils.h include/file_utils.h
include/container_utils.h include/container_utils.h
include/string_utils.h include/string_utils.h
include/logger.h
include/ClientSocket.h include/ClientSocket.h
include/DataSocket.h include/DataSocket.h
include/ServerSocket.h include/ServerSocket.h

View File

@ -7,12 +7,12 @@
* *
*/ */
#include "FixedCapacityContainer.h"
#include "TimeHelper.h" #include "TimeHelper.h"
#include "TypeTraits.h" #include "TypeTraits.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include "string_utils.h" #include "string_utils.h"
#include "FixedCapacityContainer.h"
#include <chrono> #include <chrono>
#include <iomanip> #include <iomanip>
#include <map> #include <map>
@ -40,8 +40,9 @@ std::string ToString(const defs::timingSourceType s);
std::string ToString(const slsDetectorDefs::ROI &roi); std::string ToString(const slsDetectorDefs::ROI &roi);
std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi);
template<typename T, size_t Capacity> template <typename T, size_t Capacity>
std::ostream &operator<<(std::ostream &os, const sls::FixedCapacityContainer<T, Capacity>& c){ std::ostream &operator<<(std::ostream &os,
const sls::FixedCapacityContainer<T, Capacity> &c) {
return os << ToString(c); return os << ToString(c);
} }

View File

@ -1,55 +1,48 @@
#pragma once #pragma once
#include "logger.h"
#include <iostream>
#include <stdexcept> #include <stdexcept>
namespace sls { namespace sls {
struct RuntimeError : public std::runtime_error { struct RuntimeError : public std::runtime_error {
public: public:
RuntimeError() : runtime_error("SLS Detector Package Failed") { RuntimeError();
LOG(logERROR) << "SLS Detector Package Failed"; RuntimeError(const std::string &msg);
} RuntimeError(const char *msg);
RuntimeError(const std::string &msg) : runtime_error(msg) {
LOG(logERROR) << msg;
}
RuntimeError(const char *msg) : runtime_error(msg) { LOG(logERROR) << msg; }
}; };
struct SharedMemoryError : public RuntimeError { struct SharedMemoryError : public RuntimeError {
public: public:
SharedMemoryError(const std::string &msg) : RuntimeError(msg) {} SharedMemoryError(const std::string &msg);
}; };
struct SocketError : public RuntimeError { struct SocketError : public RuntimeError {
public: public:
SocketError(const std::string &msg) : RuntimeError(msg) {} SocketError(const std::string &msg);
}; };
struct ZmqSocketError : public RuntimeError { struct ZmqSocketError : public RuntimeError {
public: public:
ZmqSocketError(const std::string &msg) : RuntimeError(msg) {} ZmqSocketError(const std::string &msg);
}; };
struct NotImplementedError : public RuntimeError { struct NotImplementedError : public RuntimeError {
public: public:
NotImplementedError(const std::string &msg) : RuntimeError(msg) {} NotImplementedError(const std::string &msg);
}; };
struct DetectorError : public RuntimeError { struct DetectorError : public RuntimeError {
public: public:
DetectorError(const std::string &msg) : RuntimeError(msg) {} DetectorError(const std::string &msg);
}; };
struct ReceiverError : public RuntimeError { struct ReceiverError : public RuntimeError {
public: public:
ReceiverError(const std::string &msg) : RuntimeError(msg) {} ReceiverError(const std::string &msg);
}; };
struct GuiError : public RuntimeError { struct GuiError : public RuntimeError {
public: public:
GuiError(const std::string &msg) : RuntimeError(msg) {} GuiError(const std::string &msg);
}; };
} // namespace sls } // namespace sls

View File

@ -10,4 +10,4 @@
#define APIJUNGFRAU 0x200508 #define APIJUNGFRAU 0x200508
#define APIMYTHEN3 0x200508 #define APIMYTHEN3 0x200508
#define APIMOENCH 0x200508 #define APIMOENCH 0x200508
#define APIEIGER 0x200513 #define APIEIGER 0x200513

View File

@ -1,4 +1,5 @@
#include "ServerInterface.h" #include "ServerInterface.h"
#include "logger.h"
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <sstream> #include <sstream>

View File

@ -2,13 +2,13 @@
namespace sls { namespace sls {
std::string ToString(const slsDetectorDefs::ROI& roi){ std::string ToString(const slsDetectorDefs::ROI &roi) {
std::ostringstream oss; std::ostringstream oss;
oss << '[' << roi.xmin << ", " << roi.xmax << ']'; oss << '[' << roi.xmin << ", " << roi.xmax << ']';
return oss.str(); return oss.str();
} }
std::ostream&operator<<(std::ostream &os, const slsDetectorDefs::ROI& roi){ std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi) {
return os << ToString(roi); return os << ToString(roi);
} }

View File

@ -1,4 +1,5 @@
#include "UdpRxSocket.h" #include "UdpRxSocket.h"
#include "logger.h"
#include "network_utils.h" #include "network_utils.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include <cstdint> #include <cstdint>

View File

@ -1,4 +1,5 @@
#include "ZmqSocket.h" #include "ZmqSocket.h"
#include "logger.h"
#include <arpa/inet.h> //inet_ntoa #include <arpa/inet.h> //inet_ntoa
#include <errno.h> #include <errno.h>
#include <iostream> #include <iostream>

View File

@ -0,0 +1,23 @@
#include "sls_detector_exceptions.h"
#include "logger.h"
namespace sls {
RuntimeError::RuntimeError() : runtime_error("SLS Detector Package Failed") {
LOG(logERROR) << "SLS Detector Package Failed";
}
RuntimeError::RuntimeError(const std::string &msg) : runtime_error(msg) {
LOG(logERROR) << msg;
}
RuntimeError::RuntimeError(const char *msg) : runtime_error(msg) {
LOG(logERROR) << msg;
}
SharedMemoryError::SharedMemoryError(const std::string &msg)
: RuntimeError(msg) {}
SocketError::SocketError(const std::string &msg) : RuntimeError(msg) {}
ZmqSocketError::ZmqSocketError(const std::string &msg) : RuntimeError(msg) {}
NotImplementedError::NotImplementedError(const std::string &msg)
: RuntimeError(msg) {}
DetectorError::DetectorError(const std::string &msg) : RuntimeError(msg) {}
ReceiverError::ReceiverError(const std::string &msg) : RuntimeError(msg) {}
GuiError::GuiError(const std::string &msg) : RuntimeError(msg) {}
} // namespace sls

View File

@ -5,8 +5,8 @@
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include <array> #include <array>
#include <map> #include <map>
#include <vector>
#include <sstream> #include <sstream>
#include <vector>
// using namespace sls; // using namespace sls;
using sls::defs; using sls::defs;
@ -219,28 +219,27 @@ TEST_CASE("Detector type") {
REQUIRE(StringTo<defs::detectorType>("Eiger") == dt); REQUIRE(StringTo<defs::detectorType>("Eiger") == dt);
} }
TEST_CASE("Formatting slsDetectorDefs::ROI") {
TEST_CASE("Formatting slsDetectorDefs::ROI"){ slsDetectorDefs::ROI roi{5, 159};
slsDetectorDefs::ROI roi{5,159};
REQUIRE(ToString(roi) == "[5, 159]"); REQUIRE(ToString(roi) == "[5, 159]");
} }
TEST_CASE("Streaming of slsDetectorDefs::ROI"){ TEST_CASE("Streaming of slsDetectorDefs::ROI") {
using namespace sls; using namespace sls;
slsDetectorDefs::ROI roi{-10,1}; slsDetectorDefs::ROI roi{-10, 1};
std::ostringstream oss; std::ostringstream oss;
oss << roi; oss << roi;
REQUIRE(oss.str() == "[-10, 1]"); REQUIRE(oss.str() == "[-10, 1]");
} }
TEST_CASE("sls::FixedCapacityContainer"){ TEST_CASE("sls::FixedCapacityContainer") {
sls::FixedCapacityContainer<int, 5> vec; sls::FixedCapacityContainer<int, 5> vec;
vec.push_back(3); vec.push_back(3);
vec.push_back(8); vec.push_back(8);
REQUIRE(ToString(vec) == "[3, 8]"); REQUIRE(ToString(vec) == "[3, 8]");
} }
TEST_CASE("sls::FixedCapacityContainer stream"){ TEST_CASE("sls::FixedCapacityContainer stream") {
sls::FixedCapacityContainer<int, 5> vec; sls::FixedCapacityContainer<int, 5> vec;
vec.push_back(33); vec.push_back(33);
vec.push_back(85667); vec.push_back(85667);

View File

@ -2,6 +2,7 @@
#include "catch.hpp" #include "catch.hpp"
#include "network_utils.h" #include "network_utils.h"
#include <iostream> #include <iostream>
#include <sstream>
#include <vector> #include <vector>
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"