vitrio 0.3.1
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
vitrio::image_scratch_storage Class Referenceabstract

Where a scratch keeps its copies: a block of bytes, in main memory or in a file, which it reads and writes through the operations of the storage. More...

#include <vitrio/image_scratch_storage.hpp>

Public Member Functions

 image_scratch_storage (const image_scratch_storage &other)=delete
 image_scratch_storage (image_scratch_storage &&other)=delete
image_scratch_storage & operator= (const image_scratch_storage &other)=delete
image_scratch_storage & operator= (image_scratch_storage &&other)=delete
virtual std::size_t get_size () const noexcept=0
 Get the size of the block.
virtual void read (std::size_t offset, span< byte > bytes) const =0
 Read bytes of the block, before this returns.
virtual void write (std::size_t offset, span< const byte > bytes)=0
 Write bytes of the block, before this returns.
virtual void write_async (std::size_t offset, span< const byte > bytes, std::shared_ptr< completion_notifier > done)=0
 Start writing bytes of the block, as a transfer.
virtual void serve_async (const array_descriptor &values, array destination, image_transfer_plan regions, std::shared_ptr< completion_notifier > done) const =0
 Start reading regions of values the block holds into an array.
virtual void load_async (std::shared_ptr< const image_reader > file, const array_descriptor &values, image_transfer_plan regions, std::shared_ptr< completion_notifier > done)=0
 Start taking regions of a file into values the block holds.

Detailed Description

Where a scratch keeps its copies: a block of bytes, in main memory or in a file, which it reads and writes through the operations of the storage.

The copies are values laid out in the block as an array_descriptor states: its extents and strides, in elements of its data type, and its offset, in elements from the first byte of the block, which a value of that type is aligned at. The storage serves regions of them into arrays and takes regions of files into them, asynchronously, as transfers do: either reports exactly once, a failure is reported rather than thrown, and only a null notifier throws. Besides them the block holds a few bytes of the scratch's own, such as which copies are whole, which are read and written on the calling thread, or written as a transfer.

Thread safety
Every method may be called concurrently, on different bytes of the block. Bytes that are being written are not read meanwhile.

Member Function Documentation

◆ get_size()

virtual std::size_t vitrio::image_scratch_storage::get_size ( ) const
pure virtualnoexcept

Get the size of the block.

Returns
std::size_t The number of bytes, which does not change.

◆ load_async()

virtual void vitrio::image_scratch_storage::load_async ( std::shared_ptr< const image_reader > file,
const array_descriptor & values,
image_transfer_plan regions,
std::shared_ptr< completion_notifier > done )
pure virtual

Start taking regions of a file into values the block holds.

The file is the file side of the plan, as in image_reader::read_async, and the values its array side.

Parameters
fileA reader over the file, which is kept until the outcome is reported: the storage may read it later. Must not be null.
valuesWhere the values lie in the block. Within it.
regionsThe regions, at their position in the file, and where each one lands among the values.
doneWhere the outcome is reported, which is what reading the file reports, or what writing the block fails with, such as an std::invalid_argument for a null file. Must not be null.
Exceptions
std::invalid_argumentIf done is null.

◆ read()

virtual void vitrio::image_scratch_storage::read ( std::size_t offset,
span< byte > bytes ) const
pure virtual

Read bytes of the block, before this returns.

Parameters
offsetWhere the bytes start, from the first of the block.
bytesWhere they go: as many as are read.
Exceptions
std::out_of_rangeIf the bytes reach past the block.
image_file_errorIf the block can not be read.

◆ serve_async()

virtual void vitrio::image_scratch_storage::serve_async ( const array_descriptor & values,
array destination,
image_transfer_plan regions,
std::shared_ptr< completion_notifier > done ) const
pure virtual

Start reading regions of values the block holds into an array.

The values are the file side of the plan, as a file is to image_reader::read_async, and destination its array side: the same values land on the same elements, converted the same way, and the transfer keeps destination until it reports.

Parameters
valuesWhere the values lie in the block. Within it.
destinationWhere the regions land.
regionsThe regions, at their position among the values, and where each one lands.
doneWhere the outcome is reported. Must not be null.
Exceptions
std::invalid_argumentIf done is null.

◆ write()

virtual void vitrio::image_scratch_storage::write ( std::size_t offset,
span< const byte > bytes )
pure virtual

Write bytes of the block, before this returns.

Parameters
offsetWhere the bytes start, from the first of the block.
bytesWhat is written: as many as are written.
Exceptions
std::out_of_rangeIf the bytes reach past the block.
image_file_errorIf the block can not be written.

◆ write_async()

virtual void vitrio::image_scratch_storage::write_async ( std::size_t offset,
span< const byte > bytes,
std::shared_ptr< completion_notifier > done )
pure virtual

Start writing bytes of the block, as a transfer.

Parameters
offsetWhere the bytes start, from the first of the block.
bytesWhat is written, which is copied before this returns.
doneWhere the outcome is reported: once the bytes are written, or with what failed them, such as an std::out_of_range for bytes that reach past the block. Must not be null.
Exceptions
std::invalid_argumentIf done is null.

The documentation for this class was generated from the following file: