3#include "centipede/data/entry.hpp"
4#include "centipede/util/error_types.hpp"
5#include "centipede/util/return_types.hpp"
79 static constexpr auto DEFAULT_BUFFER_SIZE = std::size_t{ 10000 };
85 using BufferType = std::pair<std::vector<uint32_t>, std::vector<float>>;
133 template <std::
size_t NLocals, std::
size_t NGlobals>
170 bool has_entry_ =
false;
175 auto check_buffer_size(std::size_t size_to_add)
const -> bool;
176 auto write_to_binary() -> std::size_t;
178 void resize_data_buffer(std::size_t size);
179 auto fill_entrypoint_to_buffer(
BufferPoint buffer_point,
bool has_check_value =
false) -> bool;
182 template <std::
size_t NLocals, std::
size_t NGlobals>
187 if (entry_point.sigma <= 0.)
195 if (not check_buffer_size(NLocals + NGlobals + 2))
201 auto has_entry =
false;
203 fill_entrypoint_to_buffer(
BufferPoint{ 0, entry_point.measurement });
207 for (
const auto& [idx, local_deriv] : std::views::zip(std::views::iota(0), entry_point.local_derivs))
209 has_entry |= fill_entrypoint_to_buffer(
BufferPoint{ idx + 1, local_deriv },
true);
212 fill_entrypoint_to_buffer(
BufferPoint{ 0, entry_point.sigma });
214 for (
const auto& [idx, global_deriv] : entry_point.global_derivs)
216 has_entry |= fill_entrypoint_to_buffer(
BufferPoint{ idx + 1, global_deriv },
true);
219 has_entry_ |= has_entry;
222 resize_data_buffer(old_size);
Class for configuring the binary writer class (Binary).
Binary()=default
Default constructor.
Class for writing binary files.
constexpr Binary(Config config)
Constructor takes an argument for the configuration.
auto add_entrypoint(const EntryPoint< NLocals, NGlobals > &entry_point) -> EnumError<>
Add an entrypoint to the internal data buffer.
auto init() -> EnumError<>
Initialization.
auto write_current_entry() -> EnumError< std::size_t >
Streaming an entry data to the output file.
std::pair< std::vector< uint32_t >, std::vector< float > > BufferType
Type of the data_buffer_.
constexpr auto get_buffer() const -> const BufferType &
Getter of the buffer.
void close()
Manually close the output file handler.
BufferType data_buffer_
Data buffer to store entry_point.
Binary()=default
Default constructor.
Config config_
Member variable for the configuration.
std::pair< uint32_t, float > BufferPoint
Type of the buffer point stored in the data_buffer_.
std::ofstream output_file_
Output file handler.
constexpr auto get_config() const -> const Config &
Getter of the configuration.
@ writer_buffer_overflow
Buffer size is too small for a new entry occurs. See writer::Binary.
@ writer_uninitialized
Write is not initialized.
@ writer_neg_or_zero_sigma
Zero or negative sigma occurs. See writer::Binary.
@ writer_entrypoint_rejected
std::expected< T, ErrorCode > EnumError
Template alias for expected return values.
Structure of a entrypoint.
Class for configuring the binary writer class (Binary).
std::string out_filename
Output binary filename.
uint32_t max_bufferpoint_size
maximum bufferpoint for an entry.