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

A writer that writes on the calling thread. More...

#include <vitrio/synchronous_image_writer.hpp>

Inheritance diagram for vitrio::synchronous_image_writer:
Collaboration diagram for vitrio::synchronous_image_writer:

Public Member Functions

void write_async (const_array source, image_transfer_plan regions, std::shared_ptr< completion_notifier > done) final
 Start writing a set of hyperrectangles of the file from one array.
void flush_async (std::shared_ptr< completion_notifier > done) final
 Start making what has been written reach the storage.
virtual void write (const_array_ref source, const image_transfer_plan &regions)=0
 Write a set of hyperrectangles of the file from one array, all before returning.
virtual void flush ()=0
 Make what has been written reach the storage, before returning.
Public Member Functions inherited from vitrio::image_writer
 image_writer (const image_writer &other)=delete
 image_writer (image_writer &&other)=delete
image_writer & operator= (const image_writer &other)=delete
image_writer & operator= (image_writer &&other)=delete
virtual const image_descriptor & get_descriptor () const noexcept=0
 Get the shape and data type of the file.

Detailed Description

A writer that writes on the calling thread.

Its write and flush are done before they return, and write_async and flush_async are those, reported to their notifiers before they return. A writer whose work belongs on the thread that asks for it implements write and flush alone.

Member Function Documentation

◆ flush()

virtual void vitrio::synchronous_image_writer::flush ( )
pure virtual

Make what has been written reach the storage, before returning.

Exceptions
image_file_errorIf what has been written could not reach the storage.

◆ flush_async()

void vitrio::synchronous_image_writer::flush_async ( std::shared_ptr< completion_notifier > done)
finalvirtual

Start making what has been written reach the storage.

What has been written is what every write that reported to its notifier before this was called wrote. A write still under way is not covered.

Call this before dropping a writer whose failures matter. A writer flushes itself when it is destroyed, but a destructor can not report a failure, so a write that only fails on the way out is lost unless it was flushed explicitly.

The flush may still be under way when this returns. It reports to done exactly once: when what has been written has reached the storage, or with what made it fail.

Parameters
doneWhere the outcome is reported. Must not be null.
Exceptions
std::invalid_argumentIf done is null. Every other failure is reported to done rather than thrown: image_file_error if what has been written could not reach the storage.

Flushes as flush does, and reports to done before returning.

Implements vitrio::image_writer.

◆ write()

virtual void vitrio::synchronous_image_writer::write ( const_array_ref source,
const image_transfer_plan & regions )
pure virtual

Write a set of hyperrectangles of the file from one array, all before returning.

As image_writer::write_async describes, except that it is done when it returns and a failure is thrown. source must outlive the call, and no longer.

Parameters
sourceThe values to write. Must be initialized.
regionsThe regions to write and where each one comes from.
Exceptions
std::invalid_argument,std::out_of_range,unsupported_operation_error,image_file_errorAs image_writer::write_async reports them.

◆ write_async()

void vitrio::synchronous_image_writer::write_async ( const_array source,
image_transfer_plan regions,
std::shared_ptr< completion_notifier > done )
finalvirtual

Start writing a set of hyperrectangles of the file from one array.

The mirror of image_reader::read_async, sharing its plan and naming its sides the same way: the file is the file side and source the array side, so every region names where it is taken from in source and where it lands in the file, and all of them share the extents the plan carries. The plan is therefore built the same way for a write as for a read. Passing every region in one call lets a writer order and merge the accesses it is about to make, and pays for the source's geometry once.

source is the whole array and may be strided. Its rank must be the array rank of the plan and the file's the file rank, and values are converted as a cast between the two types does, without scaling or normalising.

Regions that do not overlap may be written by concurrent calls. Overlapping ones may not, and where two regions of one call land on the same elements of the file, which one prevails is unspecified.

A region that is never written keeps whatever the format leaves in a file it has laid out but not filled. An empty plan writes nothing and reports success.

The write may still be under way when this returns. It reports to done exactly once: when every region has been written, or with what made it fail. It keeps source, and with it the memory it writes from, until then.

Parameters
sourceThe values to write. Must be initialized.
regionsThe regions to write and where each one comes from.
doneWhere the outcome is reported. Must not be null.
Exceptions
std::invalid_argumentIf done is null. Every other failure is reported to done rather than thrown:
  • std::invalid_argument if the array offsets do not have the rank of source, if the file offsets do not have the rank of the file, or if source is not initialized;
  • std::out_of_range if a region is not contained in the file, or is not contained in source where it is taken from;
  • unsupported_operation_error if the data type of the file can not be produced from the one of source;
  • image_file_error if the file can not be written.

Writes as write does, and reports to done before returning.

Implements vitrio::image_writer.


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