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

A reader that reads on the calling thread. More...

#include <vitrio/synchronous_image_reader.hpp>

Inheritance diagram for vitrio::synchronous_image_reader:
Collaboration diagram for vitrio::synchronous_image_reader:

Public Member Functions

void read_async (array destination, image_transfer_plan regions, std::shared_ptr< completion_notifier > done) const final
 Start reading a set of hyperrectangles of the file into one array.
virtual void read (array_ref destination, const image_transfer_plan &regions) const =0
 Read a set of hyperrectangles of the file into one array, all before returning.
Public Member Functions inherited from vitrio::image_reader
 image_reader (const image_reader &other)=delete
 image_reader (image_reader &&other)=delete
image_reader & operator= (const image_reader &other)=delete
image_reader & operator= (image_reader &&other)=delete
virtual const image_descriptor & get_descriptor () const noexcept=0
 Get the shape and data type of what the file holds.

Detailed Description

A reader that reads on the calling thread.

Its read is done before it returns, and read_async is that read, reported to its notifier before it returns. A reader whose work belongs on the thread that asks for it, such as one decoding a file through a library that reads it, implements read alone.

Member Function Documentation

◆ read()

virtual void vitrio::synchronous_image_reader::read ( array_ref destination,
const image_transfer_plan & regions ) const
pure virtual

Read a set of hyperrectangles of the file into one array, all before returning.

As image_reader::read_async describes, except that it is done when it returns and a failure is thrown. destination must outlive the call, and no longer.

Parameters
destinationWhere the regions are written. Must be initialized.
regionsThe regions to read and where each one lands.
Exceptions
std::invalid_argument,std::out_of_range,unsupported_operation_error,image_file_format_error,image_file_errorAs image_reader::read_async reports them.

Implemented in vitrio::detector_event_image_reader.

◆ read_async()

void vitrio::synchronous_image_reader::read_async ( array destination,
image_transfer_plan regions,
std::shared_ptr< completion_notifier > done ) const
finalvirtual

Start reading a set of hyperrectangles of the file into one array.

The file is the file side of the plan and destination its array side: every region names where it starts in the file and where it lands in destination, and all of them share the extents the plan carries. Passing every region in one call is what lets a reader sort the regions by their position on the storage and merge neighbouring ones into a single larger read, which one call per region can not express; it also pays for the destination's geometry once rather than once per region.

destination is the whole array, not a view of the part a region lands in, and it may be strided. The file offsets of the plan must have the rank of the file and its array offsets the rank of destination; a side whose rank exceeds that of the extents spans a single position along the axes they do not reach.

Regions may be read in any order. If two of them land on the same elements of destination, which one prevails is unspecified and thus this pattern should be avoided.

Values are converted to the data type of destination as a cast between the two types does, which preserves the numeric value where the destination can hold it. Nothing is scaled, normalised or clipped, whatever statistics the file may carry in its header; asking for the data type of get_descriptor converts nothing at all.

The read may still be under way when this returns. It reports to done exactly once: when every region has landed, or with what made it fail. It keeps destination, and with it the memory it writes into, until then.

Thread safety
This method may be called concurrently on one reader. A reader that can not decode in parallel serialises the calls itself, so issuing them at once never costs correctness.

An empty plan reads nothing and reports success.

Parameters
destinationWhere the regions are written. Must be initialized.
regionsThe regions to read and where each one lands.
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 file offsets do not have the rank of the file, if the array offsets do not have the rank of destination, or if destination is not initialized;
  • std::out_of_range if a region is not contained in the file, or does not fit in destination where it is placed;
  • unsupported_operation_error if the data type of destination can not be produced from the one of the file;
  • image_file_format_error if the file turns out to be malformed or truncated where a region is read;
  • image_file_error if the file can not be read where a region is read.

Reads as read does, and reports to done before returning.

Implements vitrio::image_reader.


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