mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-21 03:07:59 +02:00
use clang-tidy (#59)
* use clang-tidy for Frame.cpp * fixes for defs.cpp * clang-tidy 6/45 * clang-tidy for core * clang-tidy fixes: for hpp File,FileInterface,SubFile.cpp * ci fixes * fix build errors * fix clang-tidy command ci * fix clang-tidy ci * clang-tidy for rawfile.cpp * clang-tidy numpy helpers * fix ci * clang-tidy file_io * clang-tidy file_io and core working * zmqheader * clagn-tidy: network_io,file_io,core * clang-tidy working * format --------- Co-authored-by: Bechir <bechir.brahem420@gmail.com>
This commit is contained in:
@ -18,16 +18,16 @@ template <> simdjson_inline simdjson::simdjson_result<std::array<int, 4>> simdjs
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
std::array<int, 4> arr;
|
||||
std::array<int, 4> arr{};
|
||||
int i = 0;
|
||||
for (auto v : array) {
|
||||
int64_t val;
|
||||
int64_t val = 0;
|
||||
error = v.get_int64().get(val);
|
||||
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
arr[i++] = val;
|
||||
arr[i++] = static_cast<int>(val);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
@ -37,7 +37,7 @@ template <> simdjson_inline simdjson::simdjson_result<std::array<int, 4>> simdjs
|
||||
* adds a check for 32bit overflow
|
||||
*/
|
||||
template <> simdjson_inline simdjson::simdjson_result<uint32_t> simdjson::ondemand::value::get() noexcept {
|
||||
size_t val;
|
||||
size_t val = 0;
|
||||
auto error = get_uint64().get(val);
|
||||
if (error) {
|
||||
return error;
|
||||
@ -70,9 +70,9 @@ simdjson::ondemand::value::get() noexcept {
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
std::string_view key_view = field.unescaped_key();
|
||||
std::string key_str(key_view.data(), key_view.size());
|
||||
std::string_view value_view = field.value().get_string();
|
||||
std::string_view const key_view = field.unescaped_key();
|
||||
std::string const key_str(key_view.data(), key_view.size());
|
||||
std::string_view const value_view = field.value().get_string();
|
||||
map[key_str] = {value_view.data(), value_view.size()};
|
||||
}
|
||||
return map;
|
||||
@ -122,7 +122,7 @@ struct ZmqHeader {
|
||||
uint8_t detType{0};
|
||||
uint8_t version{0};
|
||||
/** if rows of image should be flipped */
|
||||
int flipRows{0};
|
||||
int64_t flipRows{0};
|
||||
/** quad type (eiger hardware specific) */
|
||||
uint32_t quad{0};
|
||||
/** true if complete image, else missing packets */
|
||||
|
@ -32,7 +32,7 @@ class ZmqSocket {
|
||||
std::string m_endpoint;
|
||||
int m_zmq_hwm{1000};
|
||||
int m_timeout_ms{1000};
|
||||
size_t m_potential_frame_size{1024 * 1024};
|
||||
size_t m_potential_frame_size{static_cast<size_t>(1024) * 1024};
|
||||
constexpr static size_t m_max_header_size = 1024;
|
||||
char *m_header_buffer = new char[m_max_header_size];
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ namespace aare {
|
||||
*/
|
||||
class ZmqSocketReceiver : public ZmqSocket {
|
||||
public:
|
||||
ZmqSocketReceiver(const std::string &endpoint);
|
||||
explicit ZmqSocketReceiver(const std::string &endpoint);
|
||||
void connect();
|
||||
std::vector<ZmqFrame> receive_n();
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace aare {
|
||||
*/
|
||||
class ZmqSocketSender : public ZmqSocket {
|
||||
public:
|
||||
ZmqSocketSender(const std::string &endpoint);
|
||||
explicit ZmqSocketSender(const std::string &endpoint);
|
||||
void bind();
|
||||
size_t send(const ZmqHeader &header, const std::byte *data, size_t size);
|
||||
size_t send(const ZmqFrame &zmq_frame);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace aare {
|
||||
|
||||
/**
|
||||
* @brief ZmqFrame structure
|
||||
* wrapper class to contain a ZmqHeader and a Frame
|
||||
@ -24,9 +25,9 @@ class NetworkError : public std::runtime_error {
|
||||
const char *m_msg;
|
||||
|
||||
public:
|
||||
NetworkError(const char *msg) : std::runtime_error(msg), m_msg(msg) {}
|
||||
NetworkError(const std::string msg) : std::runtime_error(msg) { m_msg = strdup(msg.c_str()); }
|
||||
virtual const char *what() const noexcept override { return m_msg; }
|
||||
explicit NetworkError(const char *msg) : std::runtime_error(msg), m_msg(msg) {}
|
||||
explicit NetworkError(const std::string &msg) : std::runtime_error(msg), m_msg(strdup(msg.c_str())) {}
|
||||
const char *what() const noexcept override { return m_msg; }
|
||||
};
|
||||
|
||||
} // namespace network_io
|
||||
|
@ -3,8 +3,6 @@
|
||||
|
||||
#include "simdjson.h"
|
||||
|
||||
using namespace simdjson;
|
||||
|
||||
// helper functions to write json
|
||||
// append to string for better performance (not tested)
|
||||
|
||||
@ -37,11 +35,11 @@ void write_map(std::string &s, const std::string &key, const std::map<std::strin
|
||||
s += "\"";
|
||||
s += key;
|
||||
s += "\": {";
|
||||
for (auto &kv : value) {
|
||||
for (const auto &kv : value) {
|
||||
write_str(s, kv.first, kv.second);
|
||||
}
|
||||
// remove last comma or trailing spaces
|
||||
for (int i = s.size() - 1; i >= 0; i--) {
|
||||
for (size_t i = s.size() - 1; i > 0; i--) {
|
||||
if (s[i] == ',' or s[i] == ' ') {
|
||||
s.pop_back();
|
||||
} else
|
||||
@ -66,7 +64,7 @@ void write_array(std::string &s, const std::string &key, const std::array<int, 4
|
||||
namespace aare {
|
||||
|
||||
std::string ZmqHeader::to_string() const {
|
||||
std::string s = "";
|
||||
std::string s;
|
||||
s.reserve(1024);
|
||||
s += "{";
|
||||
write_digit(s, "data", data ? 1 : 0);
|
||||
@ -108,78 +106,79 @@ std::string ZmqHeader::to_string() const {
|
||||
return s;
|
||||
}
|
||||
|
||||
void ZmqHeader::from_string(std::string &s) {
|
||||
void ZmqHeader::from_string(std::string &s) { // NOLINT
|
||||
|
||||
simdjson::padded_string ps(s.c_str(), s.size());
|
||||
ondemand::parser parser;
|
||||
ondemand::document doc = parser.iterate(ps);
|
||||
ondemand::object object = doc.get_object();
|
||||
simdjson::padded_string const ps(s.c_str(), s.size());
|
||||
simdjson::ondemand::parser parser;
|
||||
simdjson::ondemand::document doc = parser.iterate(ps);
|
||||
simdjson::ondemand::object object = doc.get_object();
|
||||
|
||||
for (auto field : object) {
|
||||
std::string_view key = field.unescaped_key();
|
||||
std::string_view const key = field.unescaped_key();
|
||||
|
||||
if (key == "data") {
|
||||
data = uint64_t(field.value()) ? true : false;
|
||||
data = static_cast<uint64_t>(field.value()) != 0;
|
||||
} else if (key == "jsonversion") {
|
||||
jsonversion = uint32_t(field.value());
|
||||
jsonversion = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "dynamicRange") {
|
||||
dynamicRange = uint32_t(field.value());
|
||||
dynamicRange = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "fileIndex") {
|
||||
fileIndex = uint64_t(field.value());
|
||||
fileIndex = static_cast<uint64_t>(field.value());
|
||||
} else if (key == "ndetx") {
|
||||
ndetx = uint32_t(field.value());
|
||||
ndetx = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "ndety") {
|
||||
ndety = uint32_t(field.value());
|
||||
ndety = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "npixelsx") {
|
||||
npixelsx = uint32_t(field.value());
|
||||
npixelsx = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "npixelsy") {
|
||||
npixelsy = uint32_t(field.value());
|
||||
npixelsy = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "size") {
|
||||
size = uint32_t(field.value());
|
||||
size = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "acqIndex") {
|
||||
acqIndex = uint64_t(field.value());
|
||||
acqIndex = static_cast<uint64_t>(field.value());
|
||||
} else if (key == "frameIndex") {
|
||||
frameIndex = uint64_t(field.value());
|
||||
frameIndex = static_cast<uint64_t>(field.value());
|
||||
} else if (key == "progress") {
|
||||
progress = field.value().get_double();
|
||||
} else if (key == "fname") {
|
||||
std::string_view tmp = field.value().get_string();
|
||||
std::string_view const tmp = field.value().get_string();
|
||||
fname = {tmp.begin(), tmp.end()};
|
||||
} else if (key == "frameNumber") {
|
||||
frameNumber = uint64_t(field.value());
|
||||
frameNumber = static_cast<uint64_t>(field.value());
|
||||
} else if (key == "expLength") {
|
||||
expLength = uint32_t(field.value());
|
||||
expLength = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "packetNumber") {
|
||||
packetNumber = uint32_t(field.value());
|
||||
packetNumber = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "detSpec1") {
|
||||
detSpec1 = uint64_t(field.value());
|
||||
detSpec1 = static_cast<uint64_t>(field.value());
|
||||
} else if (key == "timestamp") {
|
||||
timestamp = uint64_t(field.value());
|
||||
timestamp = static_cast<uint64_t>(field.value());
|
||||
} else if (key == "modId") {
|
||||
modId = uint32_t(field.value());
|
||||
modId = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "row") {
|
||||
row = uint32_t(field.value());
|
||||
row = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "column") {
|
||||
column = uint32_t(field.value());
|
||||
column = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "detSpec2") {
|
||||
detSpec2 = uint32_t(field.value());
|
||||
detSpec2 = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "detSpec3") {
|
||||
detSpec3 = uint32_t(field.value());
|
||||
detSpec3 = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "detSpec4") {
|
||||
detSpec4 = uint32_t(field.value());
|
||||
detSpec4 = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "detType") {
|
||||
detType = uint32_t(field.value());
|
||||
detType = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "version") {
|
||||
version = uint32_t(field.value());
|
||||
version = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "flipRows") {
|
||||
flipRows = uint32_t(field.value());
|
||||
flipRows = static_cast<int64_t>(field.value());
|
||||
} else if (key == "quad") {
|
||||
quad = uint32_t(field.value());
|
||||
quad = static_cast<uint32_t>(field.value());
|
||||
} else if (key == "completeImage") {
|
||||
completeImage = uint64_t(field.value()) ? true : false;
|
||||
completeImage = static_cast<uint64_t>(field.value()) != 0;
|
||||
} else if (key == "addJsonHeader") {
|
||||
addJsonHeader = std::map<std::string, std::string>(field.value());
|
||||
addJsonHeader = static_cast<std::map<std::string, std::string>>(field.value());
|
||||
} else if (key == "rx_roi") {
|
||||
rx_roi = std::array<int, 4>(field.value());
|
||||
rx_roi = static_cast<std::array<int, 4>>(field.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,13 @@ void ZmqSocketReceiver::connect() {
|
||||
fmt::print("Setting ZMQ_RCVHWM to {}\n", m_zmq_hwm);
|
||||
int rc = zmq_setsockopt(m_socket, ZMQ_RCVHWM, &m_zmq_hwm, sizeof(m_zmq_hwm)); // should be set before connect
|
||||
if (rc)
|
||||
throw network_io::NetworkError(fmt::format("Could not set ZMQ_RCVHWM: {}", strerror(errno)));
|
||||
throw network_io::NetworkError(fmt::format("Could not set ZMQ_RCVHWM: {}", zmq_strerror(errno)));
|
||||
|
||||
int bufsize = m_potential_frame_size * m_zmq_hwm;
|
||||
fmt::print("Setting ZMQ_RCVBUF to: {} MB\n", bufsize / (1024 * 1024));
|
||||
size_t bufsize = m_potential_frame_size * m_zmq_hwm;
|
||||
fmt::print("Setting ZMQ_RCVBUF to: {} MB\n", bufsize / (static_cast<size_t>(1024) * 1024));
|
||||
rc = zmq_setsockopt(m_socket, ZMQ_RCVBUF, &bufsize, sizeof(bufsize));
|
||||
if (rc)
|
||||
throw network_io::NetworkError(fmt::format("Could not set ZMQ_RCVBUF: {}", strerror(errno)));
|
||||
throw network_io::NetworkError(fmt::format("Could not set ZMQ_RCVBUF: {}", zmq_strerror(errno)));
|
||||
|
||||
zmq_connect(m_socket, m_endpoint.c_str());
|
||||
zmq_setsockopt(m_socket, ZMQ_SUBSCRIBE, "", 0);
|
||||
@ -44,7 +44,7 @@ ZmqHeader ZmqSocketReceiver::receive_header() {
|
||||
|
||||
// receive string ZmqHeader
|
||||
aare::logger::debug("Receiving header");
|
||||
size_t header_bytes_received = zmq_recv(m_socket, m_header_buffer, m_max_header_size, 0);
|
||||
int const header_bytes_received = zmq_recv(m_socket, m_header_buffer, m_max_header_size, 0);
|
||||
aare::logger::debug("Bytes: ", header_bytes_received);
|
||||
|
||||
m_header_buffer[header_bytes_received] = '\0'; // make sure we zero terminate
|
||||
@ -71,9 +71,9 @@ ZmqHeader ZmqSocketReceiver::receive_header() {
|
||||
* @return ZmqHeader
|
||||
*/
|
||||
int ZmqSocketReceiver::receive_data(std::byte *data, size_t size) {
|
||||
int data_bytes_received = zmq_recv(m_socket, data, size, 0);
|
||||
int const data_bytes_received = zmq_recv(m_socket, data, size, 0);
|
||||
if (data_bytes_received == -1)
|
||||
network_io::NetworkError("Got half of a multipart msg!!!");
|
||||
throw network_io::NetworkError("Got half of a multipart msg!!!");
|
||||
aare::logger::debug("Bytes: ", data_bytes_received);
|
||||
|
||||
return data_bytes_received;
|
||||
@ -98,7 +98,7 @@ ZmqFrame ZmqSocketReceiver::receive_zmqframe() {
|
||||
if (bytes_received == -1) {
|
||||
throw network_io::NetworkError(LOCATION + "Error receiving frame");
|
||||
}
|
||||
if ((uint32_t)bytes_received != header.size) {
|
||||
if (static_cast<uint32_t>(bytes_received) != header.size) {
|
||||
throw network_io::NetworkError(
|
||||
fmt::format("{} Expected {} bytes but received {}", LOCATION, header.size, bytes_received));
|
||||
}
|
||||
@ -113,7 +113,7 @@ std::vector<ZmqFrame> ZmqSocketReceiver::receive_n() {
|
||||
std::vector<ZmqFrame> frames;
|
||||
while (true) {
|
||||
// receive header and frame
|
||||
ZmqFrame zmq_frame = receive_zmqframe();
|
||||
ZmqFrame const zmq_frame = receive_zmqframe();
|
||||
if (!zmq_frame.header.data) {
|
||||
break;
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ ZmqSocketSender::ZmqSocketSender(const std::string &endpoint) { m_endpoint = end
|
||||
void ZmqSocketSender::bind() {
|
||||
m_context = zmq_ctx_new();
|
||||
m_socket = zmq_socket(m_context, ZMQ_PUB);
|
||||
size_t rc = zmq_bind(m_socket, m_endpoint.c_str());
|
||||
size_t const rc = zmq_bind(m_socket, m_endpoint.c_str());
|
||||
if (rc != 0) {
|
||||
std::string error = zmq_strerror(zmq_errno());
|
||||
std::string const error = zmq_strerror(zmq_errno());
|
||||
throw network_io::NetworkError("zmq_bind failed: " + error);
|
||||
}
|
||||
}
|
||||
@ -31,11 +31,11 @@ void ZmqSocketSender::bind() {
|
||||
* @return number of bytes sent
|
||||
*/
|
||||
size_t ZmqSocketSender::send(const ZmqHeader &header, const std::byte *data, size_t size) {
|
||||
size_t rc;
|
||||
size_t rc = 0;
|
||||
// if (serialize_header) {
|
||||
// rc = zmq_send(m_socket, &header, sizeof(ZmqHeader), ZMQ_SNDMORE);
|
||||
// assert(rc == sizeof(ZmqHeader));
|
||||
std::string header_str = header.to_string();
|
||||
std::string const header_str = header.to_string();
|
||||
aare::logger::debug("Header :", header_str);
|
||||
rc = zmq_send(m_socket, header_str.c_str(), header_str.size(), ZMQ_SNDMORE);
|
||||
assert(rc == header_str.size());
|
||||
@ -43,7 +43,7 @@ size_t ZmqSocketSender::send(const ZmqHeader &header, const std::byte *data, siz
|
||||
return rc;
|
||||
}
|
||||
|
||||
size_t rc2 = zmq_send(m_socket, data, size, 0);
|
||||
size_t const rc2 = zmq_send(m_socket, data, size, 0);
|
||||
assert(rc2 == size);
|
||||
return rc + rc2;
|
||||
}
|
||||
@ -56,11 +56,11 @@ size_t ZmqSocketSender::send(const ZmqHeader &header, const std::byte *data, siz
|
||||
size_t ZmqSocketSender::send(const ZmqFrame &zmq_frame) {
|
||||
const Frame &frame = zmq_frame.frame;
|
||||
// send frame
|
||||
size_t rc = send(zmq_frame.header, frame.data(), frame.size());
|
||||
size_t const rc = send(zmq_frame.header, frame.data(), frame.size());
|
||||
// send end of message header
|
||||
ZmqHeader end_header = zmq_frame.header;
|
||||
end_header.data = false;
|
||||
size_t rc2 = send(end_header, nullptr, 0);
|
||||
size_t const rc2 = send(end_header, nullptr, 0);
|
||||
|
||||
return rc + rc2;
|
||||
}
|
||||
|
Reference in New Issue
Block a user