mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-04 17:34:15 +02:00
Rename classes to new standard
Prefix all Buffer related classes with Buffer.
This commit is contained in:
@@ -7,9 +7,9 @@ const char JF_FORMAT_START_BYTE = 0xBE;
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
struct JFFileFormat {
|
||||
struct BufferBinaryFormat {
|
||||
|
||||
JFFileFormat() : FORMAT_MARKER(JF_FORMAT_START_BYTE) {};
|
||||
BufferBinaryFormat() : FORMAT_MARKER(JF_FORMAT_START_BYTE) {};
|
||||
|
||||
const char FORMAT_MARKER;
|
||||
uint64_t pulse_id;
|
||||
@@ -2,9 +2,9 @@
|
||||
#define BINARYWRITER_HPP
|
||||
|
||||
#include <string>
|
||||
#include "JFFileFormat.hpp"
|
||||
#include "BufferBinaryFormat.hpp"
|
||||
|
||||
class BinaryWriter {
|
||||
class BufferBinaryWriter {
|
||||
|
||||
const std::string device_name_;
|
||||
const std::string root_folder_;
|
||||
@@ -18,13 +18,13 @@ class BinaryWriter {
|
||||
|
||||
|
||||
public:
|
||||
BinaryWriter(
|
||||
BufferBinaryWriter(
|
||||
const std::string& device_name,
|
||||
const std::string& root_folder);
|
||||
|
||||
virtual ~BinaryWriter();
|
||||
virtual ~BufferBinaryWriter();
|
||||
|
||||
void write(const uint64_t pulse_id, const JFFileFormat* buffer);
|
||||
void write(const uint64_t pulse_id, const BufferBinaryFormat* buffer);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "BinaryWriter.hpp"
|
||||
#include "BufferBinaryWriter.hpp"
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include "date.h"
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
BinaryWriter::BinaryWriter(
|
||||
BufferBinaryWriter::BufferBinaryWriter(
|
||||
const string& device_name,
|
||||
const string& root_folder) :
|
||||
device_name_(device_name),
|
||||
@@ -22,12 +22,12 @@ BinaryWriter::BinaryWriter(
|
||||
{
|
||||
}
|
||||
|
||||
BinaryWriter::~BinaryWriter()
|
||||
BufferBinaryWriter::~BufferBinaryWriter()
|
||||
{
|
||||
close_current_file();
|
||||
}
|
||||
|
||||
void BinaryWriter::write(uint64_t pulse_id, const JFFileFormat* buffer)
|
||||
void BufferBinaryWriter::write(uint64_t pulse_id, const BufferBinaryFormat* buffer)
|
||||
{
|
||||
auto current_frame_file =
|
||||
BufferUtils::get_filename(root_folder_, device_name_, pulse_id);
|
||||
@@ -37,7 +37,7 @@ void BinaryWriter::write(uint64_t pulse_id, const JFFileFormat* buffer)
|
||||
}
|
||||
|
||||
size_t n_bytes_offset =
|
||||
BufferUtils::get_file_frame_index(pulse_id) * sizeof(JFFileFormat);
|
||||
BufferUtils::get_file_frame_index(pulse_id) * sizeof(BufferBinaryFormat);
|
||||
|
||||
auto lseek_result = lseek(output_file_fd_, n_bytes_offset, SEEK_SET);
|
||||
if (lseek_result < 0) {
|
||||
@@ -56,8 +56,8 @@ void BinaryWriter::write(uint64_t pulse_id, const JFFileFormat* buffer)
|
||||
throw runtime_error(err_msg.str());
|
||||
}
|
||||
|
||||
auto n_bytes = ::write(output_file_fd_, buffer, sizeof(JFFileFormat));
|
||||
if (n_bytes < sizeof(JFFileFormat)) {
|
||||
auto n_bytes = ::write(output_file_fd_, buffer, sizeof(BufferBinaryFormat));
|
||||
if (n_bytes < sizeof(BufferBinaryFormat)) {
|
||||
stringstream err_msg;
|
||||
|
||||
using namespace date;
|
||||
@@ -72,7 +72,7 @@ void BinaryWriter::write(uint64_t pulse_id, const JFFileFormat* buffer)
|
||||
}
|
||||
}
|
||||
|
||||
void BinaryWriter::open_file(const std::string& filename)
|
||||
void BufferBinaryWriter::open_file(const std::string& filename)
|
||||
{
|
||||
close_current_file();
|
||||
|
||||
@@ -97,7 +97,7 @@ void BinaryWriter::open_file(const std::string& filename)
|
||||
current_output_filename_ = filename;
|
||||
}
|
||||
|
||||
void BinaryWriter::close_current_file()
|
||||
void BufferBinaryWriter::close_current_file()
|
||||
{
|
||||
if (output_file_fd_ != -1) {
|
||||
if (close(output_file_fd_) < 0) {
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "test_UdpReceiver.cpp"
|
||||
#include "test_UdpRecvModule.cpp"
|
||||
#include "test_BinaryWriter.cpp"
|
||||
#include "test_BufferBinaryWriter.cpp"
|
||||
#include "test_buffer_utils.cpp"
|
||||
#include "test_BufferH5Writer.cpp"
|
||||
#include "test_SFWriter.cpp"
|
||||
|
||||
+15
-15
@@ -1,4 +1,4 @@
|
||||
#include <BinaryWriter.hpp>
|
||||
#include <BufferBinaryWriter.hpp>
|
||||
#include "BufferUtils.hpp"
|
||||
#include <fcntl.h>
|
||||
#include "gtest/gtest.h"
|
||||
@@ -9,9 +9,9 @@ TEST(BinaryWriter, basic_interaction)
|
||||
auto device_name = "test_device";
|
||||
uint64_t pulse_id = 5;
|
||||
|
||||
BinaryWriter writer(device_name, root_folder);
|
||||
BufferBinaryWriter writer(device_name, root_folder);
|
||||
|
||||
JFFileFormat frame_data;
|
||||
BufferBinaryFormat frame_data;
|
||||
frame_data.pulse_id = 1;
|
||||
frame_data.frame_id = 2;
|
||||
frame_data.daq_rec = 3;
|
||||
@@ -29,10 +29,10 @@ TEST(BinaryWriter, basic_interaction)
|
||||
|
||||
auto file_frame_index = BufferUtils::get_file_frame_index(pulse_id);
|
||||
|
||||
JFFileFormat read_data;
|
||||
BufferBinaryFormat read_data;
|
||||
|
||||
::lseek(read_fd, file_frame_index * sizeof(JFFileFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(JFFileFormat));
|
||||
::lseek(read_fd, file_frame_index * sizeof(BufferBinaryFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(BufferBinaryFormat));
|
||||
|
||||
ASSERT_EQ(frame_data.FORMAT_MARKER, JF_FORMAT_START_BYTE);
|
||||
ASSERT_EQ(frame_data.FORMAT_MARKER, read_data.FORMAT_MARKER);
|
||||
@@ -48,9 +48,9 @@ TEST(BinaryWriter, test_format_marker)
|
||||
auto device_name = "test_device";
|
||||
uint64_t pulse_id = 5;
|
||||
|
||||
BinaryWriter writer(device_name, root_folder);
|
||||
BufferBinaryWriter writer(device_name, root_folder);
|
||||
|
||||
JFFileFormat frame_data;
|
||||
BufferBinaryFormat frame_data;
|
||||
frame_data.pulse_id = 1;
|
||||
frame_data.frame_id = 2;
|
||||
frame_data.daq_rec = 3;
|
||||
@@ -66,21 +66,21 @@ TEST(BinaryWriter, test_format_marker)
|
||||
|
||||
auto file_frame_index = BufferUtils::get_file_frame_index(pulse_id);
|
||||
|
||||
JFFileFormat read_data;
|
||||
BufferBinaryFormat read_data;
|
||||
|
||||
// One frame before should be empty.
|
||||
::lseek(read_fd, (file_frame_index-1) * sizeof(JFFileFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(JFFileFormat));
|
||||
::lseek(read_fd, (file_frame_index-1) * sizeof(BufferBinaryFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(BufferBinaryFormat));
|
||||
ASSERT_NE(read_data.FORMAT_MARKER, JF_FORMAT_START_BYTE);
|
||||
|
||||
// One frame after should be empty as well.
|
||||
::lseek(read_fd, (file_frame_index+1) * sizeof(JFFileFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(JFFileFormat));
|
||||
::lseek(read_fd, (file_frame_index+1) * sizeof(BufferBinaryFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(BufferBinaryFormat));
|
||||
ASSERT_NE(read_data.FORMAT_MARKER, JF_FORMAT_START_BYTE);
|
||||
|
||||
// But this frame should be here.
|
||||
::lseek(read_fd, (file_frame_index) * sizeof(JFFileFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(JFFileFormat));
|
||||
::lseek(read_fd, (file_frame_index) * sizeof(BufferBinaryFormat), SEEK_SET);
|
||||
::read(read_fd, &read_data, sizeof(BufferBinaryFormat));
|
||||
ASSERT_EQ(read_data.FORMAT_MARKER, JF_FORMAT_START_BYTE);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user