|
vitrio 0.3.1
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
|
A provider that writes files. Its files are explicitly declared and closed by the client. More...
#include <vitrio/file_image_writer_provider.hpp>


Public Member Functions | |
| file_image_writer_provider (std::shared_ptr< const image_file_write_format_selector > formats, std::shared_ptr< const file_transfer_pool > transfers) | |
| Construct a provider creating files through a format selector. | |
| void | declare (std::string key, image_descriptor descriptor, const image_metadata &metadata) |
| Make a file writable. | |
| void | close (const std::string &key) |
| Finish a file. | |
| void | close_async (const std::string &key, std::shared_ptr< completion_notifier > done) |
| Start finishing a file, and report once it is finished. | |
| void | flush () |
| Make everything written to the files reach the storage. | |
| std::size_t | get_file_count () const noexcept |
| Get how many files are declared. | |
| std::shared_ptr< image_writer > | acquire (const std::string &key) override |
| Get the writer a key names. | |
| Public Member Functions inherited from vitrio::image_writer_provider | |
| image_writer_provider (const image_writer_provider &other)=delete | |
| image_writer_provider (image_writer_provider &&other)=delete | |
| image_writer_provider & | operator= (const image_writer_provider &other)=delete |
| image_writer_provider & | operator= (image_writer_provider &&other)=delete |
A provider that writes files. Its files are explicitly declared and closed by the client.
Creating a file replaces whatever was there, so a writer dropped and reopened would truncate everything already written to it, and no eviction policy can decide when that is safe. Which files exist and when each is finished is instead said outright, through declare and close.
Each file therefore has one lifecycle, declare, acquire as often as needed, close:
std::out_of_range.| vitrio::file_image_writer_provider::file_image_writer_provider | ( | std::shared_ptr< const image_file_write_format_selector > | formats, |
| std::shared_ptr< const file_transfer_pool > | transfers ) |
Construct a provider creating files through a format selector.
| formats | The formats a file may be created with. |
| transfers | The threads that carry out the transfers of the writers. |
| std::invalid_argument | If formats or transfers is null. |
|
overridevirtual |
Get the writer a key names.
Shared ownership rather than a reference, so that a writer the provider stops keeping stays alive for as long as it is still written through.
| key | Key of the file to write, such as its path. |
| std::out_of_range | If this provider serves no such file. |
| unsupported_operation_error | If no format can create the file, or the chosen one can not represent it. |
| image_file_error | If the file could not be created. |
Implements vitrio::image_writer_provider.
| void vitrio::file_image_writer_provider::close | ( | const std::string & | key | ) |
Finish a file.
Flushes the writer if the file was ever acquired, drops it, and forgets the declaration. Acquiring that key afterwards throws as an undeclared one does, and declaring it again creates the file afresh.
Closing a file that was declared but never acquired creates nothing and simply forgets it.
| key | Key of the file to finish. |
| std::out_of_range | If that key is not declared. |
| image_file_error | If the pending writes could not be completed. |
| void vitrio::file_image_writer_provider::close_async | ( | const std::string & | key, |
| std::shared_ptr< completion_notifier > | done ) |
Start finishing a file, and report once it is finished.
Does what close does, without waiting for the flush: the declaration is forgotten before this returns, as close forgets it, and the writer is dropped once its flush has reported. A file declared but never acquired is reported finished at once.
A program that finishes its files as it completes them keeps a few of these under way while it writes the next ones, so that waiting for one file to reach the storage never holds up the others.
| key | Key of the file to finish. |
| done | Where the outcome is reported, exactly once: an std::out_of_range if that key is not declared, or what the flush failed with. Must not be null. |
| std::invalid_argument | If done is null. |
| void vitrio::file_image_writer_provider::declare | ( | std::string | key, |
| image_descriptor | descriptor, | ||
| const image_metadata & | metadata ) |
Make a file writable.
Records the descriptor and metadata the file will be created with. Nothing is created until the file is first acquired, so this costs no file descriptor and can not fail on anything the file system has to say.
A key that is still declared is refused rather than replaced, because replacing it would silently strand whatever had been written to the file it names. close it first, which says so.
| key | Key of the file to create, which is handed to the format selector as its path. |
| descriptor | What the file holds. |
| metadata | What it states beyond its shape and data type. |
| std::logic_error | If that key is already declared. |
| void vitrio::file_image_writer_provider::flush | ( | ) |
Make everything written to the files reach the storage.
Flushes the writer of every file acquired so far and creates none: a file declared and never acquired stays uncreated. Every file stays declared and writable. The writers are flushed together, and every one of them is flushed even where another fails.
| image_file_error | If the pending writes could not be completed: the first failure of the flushes. |
|
noexcept |
Get how many files are declared.
Counts what has been declared and not yet closed, whether or not it has been acquired.