Finished refactoring sf-buffer

This commit is contained in:
2020-05-20 12:22:20 +02:00
parent b45b7d17fa
commit 6d210ed702
18 changed files with 1468 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#ifndef JFFILEFORMAT_HPP
#define JFFILEFORMAT_HPP
#include "jungfrau.hpp"
const char JF_FORMAT_START_BYTE = 0xBE;
#pragma pack(push)
#pragma pack(1)
struct BufferBinaryFormat {
BufferBinaryFormat() : FORMAT_MARKER(JF_FORMAT_START_BYTE) {};
const char FORMAT_MARKER;
uint64_t pulse_id;
uint64_t frame_id;
uint32_t daq_rec;
uint16_t n_recv_packets;
char data[JUNGFRAU_DATA_BYTES_PER_FRAME];
};
#pragma pack(pop)
#endif // JFFILEFORMAT_HPP
+32
View File
@@ -0,0 +1,32 @@
#ifndef BINARYWRITER_HPP
#define BINARYWRITER_HPP
#include <string>
#include "BufferBinaryFormat.hpp"
class BufferBinaryWriter {
const std::string device_name_;
const std::string root_folder_;
std::string latest_filename_;
std::string current_output_filename_;
int output_file_fd_;
void open_file(const std::string& filename);
void close_current_file();
public:
BufferBinaryWriter(
const std::string& device_name,
const std::string& root_folder);
virtual ~BufferBinaryWriter();
void write(const uint64_t pulse_id, const BufferBinaryFormat* buffer);
};
#endif //BINARYWRITER_HPP
+36
View File
@@ -0,0 +1,36 @@
#ifndef SF_DAQ_BUFFER_BUFFERUDPRECEIVER_HPP
#define SF_DAQ_BUFFER_BUFFERUDPRECEIVER_HPP
#include <netinet/in.h>
#include "UdpReceiver.hpp"
#include "jungfrau.hpp"
#include "buffer_config.hpp"
class BufferUdpReceiver {
const int source_id_;
UdpReceiver udp_receiver_;
jungfrau_packet packet_buffer_[core_buffer::BUFFER_UDP_N_RECV_MSG];
iovec recv_buff_ptr_[core_buffer::BUFFER_UDP_N_RECV_MSG];
mmsghdr msgs_[core_buffer::BUFFER_UDP_N_RECV_MSG];
sockaddr_in sock_from_[core_buffer::BUFFER_UDP_N_RECV_MSG];
bool packet_buffer_loaded_ = false;
int packet_buffer_n_packets_ = 0;
int packet_buffer_offset_ = 0;
inline void init_frame(ModuleFrame& frame_metadata, const int i_packet);
inline void copy_packet_to_buffers(
ModuleFrame& metadata, char* frame_buffer, const int i_packet);
inline uint64_t process_packets(
const int n_packets, ModuleFrame& metadata, char* frame_buffer);
public:
BufferUdpReceiver(const uint16_t port, const int source_id);
virtual ~BufferUdpReceiver();
uint64_t get_frame_from_udp(ModuleFrame& metadata, char* frame_buffer);
};
#endif //SF_DAQ_BUFFER_BUFFERUDPRECEIVER_HPP
+22
View File
@@ -0,0 +1,22 @@
#ifndef UDPRECEIVER_H
#define UDPRECEIVER_H
#include <sys/socket.h>
class UdpReceiver {
int socket_fd_;
public:
UdpReceiver();
virtual ~UdpReceiver();
bool receive(void* buffer, const size_t buffer_n_bytes);
int receive_many(mmsghdr* msgs, const size_t n_msgs);
void bind(const uint16_t port);
void disconnect();
};
#endif //LIB_CPP_H5_WRITER_UDPRECEIVER_H
+11
View File
@@ -0,0 +1,11 @@
#ifndef WRITERUTILS_H
#define WRITERUTILS_H
#include <string>
namespace WriterUtils {
void set_process_effective_id(int user_id);
void create_destination_folder(const std::string& output_file);
}
#endif // WRITERUTILS_H