Class FileWriter

Class Documentation

class FileWriter

The File Writer provides a simple API to write PSRDADA compliant files to the file system.

Public Functions

FileWriter(bool use_o_direct, bool create_files)

Construct a new FileWriter object that supports O_DIRECT file access.

Parameters
  • use_o_direct – Flag to enable the O_DIRECT option.

  • create_files – Flag to control whether any output files are created, useful for testing on slow file systems.

~FileWriter()

Destroy the FileWriter object.

void configure(uint64_t header_bufsz)

Configure the file writer, allocating an internal buffer that will be used to write the header to the file.

Parameters

header_bufsz – size of a header buffer element in bytes

void deconfigure()

Deconfigure the file writer, releasing the internal buffer.

bool is_file_open()

Return a boolean describing if a file is currently open for writing.

Returns

true a file is currently open for writing

Returns

false a files is not open for writing

void open_file(const std::filesystem::path &new_file)

Open the output file specified.

Parameters

new_file – full path to the file to be opened

void check_block_size(uint64_t block_size) const

Throw an exception if the block size is not a multiple of the (assumed) logical block size of the filesystem.

Parameters

block_size – the block size to be tested, in bytes

ssize_t write_header(const ska::pst::common::AsciiHeader &header)

Write the header to the currently opened file.

Parameters

headerAsciiHeader to write to to the currently open file

Returns

ssize_t number of bytes written to the file

ssize_t write_data(char *data_ptr, uint64_t data_size)

Write data to the currently opened file.

Parameters
  • data_ptr – pointer to the data to write

  • data_size – number of bytes to write to the file

Returns

ssize_t number of bytes written to the file

void close_file(bool finalise = true)

Close the currently opened file.

If the currently opened file not to be reopened, finalise it by renaming the temporary_file to opened_file.

Parameters

finalise – flag to indicate the file will not be reopened.

void remove_file()

Close the currently opened file and remove it from the filesystem.

This will close the file with finalise as false and then remove the file from the filesystem.

inline uint64_t get_header_bytes_written()

Get the number of header bytes written to the current file.

Returns

uint64_t the number of header bytes written

inline uint64_t get_data_bytes_written()

Get the number of data bytes written to the current file.

Returns

uint64_t the number data bytes written to the current file

Public Static Functions

static std::filesystem::path get_filename(const std::string &utc_start, uint64_t obs_offset, unsigned file_number)

Get the filename for the specified scan_id, obs_offset and file_number. Output filename will be structured as [UTC_START]_[OBS_OFFSET]_[FILE_NUMBER].dada.

Parameters
  • utc_start – the UTC_START timestamp of the file to be written

  • obs_offset – offset in bytes from the start of the observation

  • file_number – file number in the sequence

Returns

std::filesystem::path full path to the output file

Public Static Attributes

static constexpr uint32_t o_direct_alignment = {512}

alignment for I/O operations on O-DIRECT buffers, noting that linux 2.6 kernels expect 512 as the commonly accepted value for this