mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-04 06:04:14 +02:00
Made BufferUtils a first class citizen
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#ifndef BUFFER_UTILS_HPP
|
||||
#define BUFFER_UTILS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace BufferUtils
|
||||
{
|
||||
extern const size_t FILE_MOD;
|
||||
extern const size_t FOLDER_MOD;
|
||||
|
||||
std::string get_filename(
|
||||
std::string root_folder,
|
||||
std::string device_name,
|
||||
uint64_t pulse_id);
|
||||
|
||||
std::size_t get_file_frame_index(uint64_t pulse_id);
|
||||
}
|
||||
|
||||
#endif //BUFFER_UTILS_HPP
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <buffer_utils.hpp>
|
||||
#include <BufferUtils.hpp>
|
||||
#include <fcntl.h>
|
||||
|
||||
using namespace std;
|
||||
@@ -40,14 +40,14 @@ BinaryWriter::~BinaryWriter()
|
||||
void BinaryWriter::write(uint64_t pulse_id, const JFFileFormat* buffer)
|
||||
{
|
||||
auto current_frame_file =
|
||||
get_filename(root_folder_, device_name_, pulse_id);
|
||||
BufferUtils::get_filename(root_folder_, device_name_, pulse_id);
|
||||
|
||||
if (current_frame_file != current_output_filename_) {
|
||||
open_file(current_frame_file);
|
||||
}
|
||||
|
||||
size_t n_bytes_offset =
|
||||
get_file_frame_index(pulse_id) * sizeof(JFFileFormat);
|
||||
BufferUtils::get_file_frame_index(pulse_id) * sizeof(JFFileFormat);
|
||||
|
||||
auto lseek_result = lseek(output_file_fd_, n_bytes_offset, SEEK_SET);
|
||||
if (lseek_result < 0) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#ifndef BUFFER_UTILS_HPP
|
||||
#define BUFFER_UTILS_HPP
|
||||
using namespace std;
|
||||
|
||||
const size_t FILE_MOD = 1000;
|
||||
const size_t FOLDER_MOD = 100000;
|
||||
#include "BufferUtils.hpp"
|
||||
#include <sstream>
|
||||
|
||||
std::string get_filename(
|
||||
const size_t BufferUtils::FILE_MOD = 1000;
|
||||
const size_t BufferUtils::FOLDER_MOD = 100000;
|
||||
|
||||
string BufferUtils::get_filename(
|
||||
std::string root_folder,
|
||||
std::string device_name,
|
||||
uint64_t pulse_id)
|
||||
@@ -15,7 +17,7 @@ std::string get_filename(
|
||||
uint64_t file_base = pulse_id / FILE_MOD;
|
||||
file_base *= FILE_MOD;
|
||||
|
||||
std::stringstream folder;
|
||||
stringstream folder;
|
||||
folder << root_folder << "/";
|
||||
folder << device_name << "/";
|
||||
folder << folder_base << "/";
|
||||
@@ -24,12 +26,10 @@ std::string get_filename(
|
||||
return folder.str();
|
||||
}
|
||||
|
||||
std::size_t get_file_frame_index(uint64_t pulse_id)
|
||||
size_t BufferUtils::get_file_frame_index(uint64_t pulse_id)
|
||||
{
|
||||
uint64_t file_base = pulse_id / FILE_MOD;
|
||||
file_base *= FILE_MOD;
|
||||
|
||||
return pulse_id - file_base;
|
||||
}
|
||||
|
||||
#endif //BUFFER_UTILS_HPP
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "buffer_utils.hpp"
|
||||
#include "BufferUtils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -10,28 +10,28 @@ TEST(BufferUtils, get_filename)
|
||||
auto root_folder = "/root";
|
||||
auto device_name = "device-1";
|
||||
|
||||
auto result = get_filename(
|
||||
auto result = BufferUtils::get_filename(
|
||||
root_folder,
|
||||
device_name,
|
||||
12345000);
|
||||
|
||||
ASSERT_EQ(result, expected_file);
|
||||
|
||||
auto result2 = get_filename(
|
||||
auto result2 = BufferUtils::get_filename(
|
||||
root_folder,
|
||||
device_name,
|
||||
12345999);
|
||||
|
||||
ASSERT_EQ(result2, expected_file);
|
||||
|
||||
auto result3 = get_filename(
|
||||
auto result3 = BufferUtils::get_filename(
|
||||
root_folder,
|
||||
device_name,
|
||||
12346000);
|
||||
|
||||
ASSERT_NE(result3, expected_file);
|
||||
|
||||
auto result4 = get_filename(
|
||||
auto result4 = BufferUtils::get_filename(
|
||||
root_folder,
|
||||
device_name,
|
||||
12344999);
|
||||
@@ -41,7 +41,7 @@ TEST(BufferUtils, get_filename)
|
||||
|
||||
TEST(BufferUtils, get_file_frame_index)
|
||||
{
|
||||
ASSERT_EQ(get_file_frame_index(12345000), 0);
|
||||
ASSERT_EQ(get_file_frame_index(12345543), 543);
|
||||
ASSERT_EQ(get_file_frame_index(12345999), 999);
|
||||
ASSERT_EQ(BufferUtils::get_file_frame_index(12345000), 0);
|
||||
ASSERT_EQ(BufferUtils::get_file_frame_index(12345543), 543);
|
||||
ASSERT_EQ(BufferUtils::get_file_frame_index(12345999), 999);
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "config.hpp"
|
||||
#include "jungfrau.hpp"
|
||||
#include "buffer_utils.hpp"
|
||||
#include "BufferUtils.hpp"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
Reference in New Issue
Block a user