Rosetta
|
ozstream: Output file stream wrapper for uncompressed and compressed files More...
#include <ozstream.hh>
Public Member Functions | |
ozstream () | |
Default constructor. More... | |
ozstream (std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::out, std::streamsize buf_size=OZSTREAM_DEFAULT_BUFFER_SIZE) | |
Filename constructor. More... | |
~ozstream () override | |
Destructor. More... | |
operator bool () const override | |
bool conversion More... | |
operator std::ostream const & () const override | |
Stream conversion. More... | |
operator std::ostream & () override | |
Stream conversion. More... | |
template<typename T > | |
ozstream & | operator<< (T const &t) |
Stream output: override to preserve type of return value. More... | |
ozstream & | operator<< (manipulator m) override |
Stream output overload to replace std::endl with to avoid flushing. More... | |
void | open (std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::out) |
Open a file. More... | |
void | open_append (std::string const &filename_a) |
Open a text file for appending. More... | |
void | open_append_if_existed (std::string const &filename_a, std::stringstream &preprinted_header) |
open file as append if it exists, return true if file existed before, false if it is new. More... | |
ozstream & | put (char const c) override |
Write a char. More... | |
ozstream & | write (char const *str, std::streamsize const count) override |
Write a string. More... | |
ozstream & | write (std::string const &str, std::streamsize const count) override |
Write a string. More... | |
ozstream & | flush () override |
Flush the stream – currently alias to flush_finalize() More... | |
ozstream & | flush_finalize () |
Flush the streams and finalize the zip stream. More... | |
void | zflush () |
Flush the zip_ostream. More... | |
void | zflush_finalize () |
Flush and finalize the zip_stream. More... | |
void | clear () override |
Clear the stream. More... | |
void | close () |
Close the ofstream and reset the state. More... | |
std::ostream const & | operator() () const override |
Stream access. More... | |
std::ostream & | operator() () override |
Stream access. More... | |
std::ostream const & | stream () const override |
Stream access. More... | |
std::ostream & | stream () override |
Stream access. More... | |
std::streambuf * | rdbuf () const override |
Pointer to the stream buffer. More... | |
std::string const & | filename () const |
File name. More... | |
bool | good () const override |
Good? More... | |
bool | eof () const override |
End of file? More... | |
bool | fail () const override |
Fail? More... | |
bool | bad () const override |
Bad? More... | |
bool | compressed () const override |
Compressed? More... | |
bool | uncompressed () const override |
Uncompressed? More... | |
bool | gzipped () const override |
gzipped? More... | |
std::streamsize | buffer_size () const |
get buffer size (bytes) More... | |
void | buffer_size (std::streamsize const &buf_size) |
set buffer size (bytes) More... | |
![]() | |
virtual | ~orstream () |
Destructor. More... | |
template<typename T > | |
orstream & | operator<< (T const &t) |
Stream output. More... | |
Static Public Member Functions | |
static void | enable_MPI_reroute (int min_client_rank, int master_rank) |
static int | MPI_reroute_rank () |
Private Types | |
enum | Compression { NONE , UNCOMPRESSED , GZIP } |
Private Member Functions | |
bool | is_gzip () const |
Is stream attached to a gzip file? More... | |
long | get_crc () const |
CRC of the uncompressed data (see zipstream documentation) More... | |
long | get_in_size () const |
Uncompressed data size. More... | |
long | get_out_size () const |
Compressed data size. More... | |
bool | allocate_assign_char_buffer () |
if character buffer does not exist, create it and assign it to internal ofstream More... | |
bool | destroy_char_buffer () |
if character buffer exists, destroy it More... | |
Private Attributes | |
Compression | compression_ |
Compression state. More... | |
std::ofstream | of_stream_ |
File stream. More... | |
std::string | filename_ |
File name. More... | |
std::streamsize | buffer_size_ |
size of buffer (in bytes) More... | |
char * | char_buffer_p_ |
character buffer pointer (owning) More... | |
zlib_stream::zip_ostream * | zip_stream_p_ |
Zip file stream pointer (owning) More... | |
mpi_stream::mpi_ostream * | mpi_stream_p_ |
Static Private Attributes | |
static bool | bMPI_reroute_stream_ |
static int | mpi_FileBuf_master_rank_ |
Friends | |
long | utility::file::gzip (std::string const &uncompressedfile, bool overwrite) |
long | utility::file::gunzip (std::string const &compressedfile, bool overwrite) |
Additional Inherited Members | |
![]() | |
typedef std::ostream &(* | manipulator) (std::ostream &) |
![]() | |
orstream ()=default | |
Default constructor. More... | |
ozstream: Output file stream wrapper for uncompressed and compressed files
|
private |
|
inline |
Default constructor.
|
inlineexplicit |
Filename constructor.
[in] | filename_a | filename |
[in] | open_mode | opening mode bitmask, use std::ios_base::out for gzip files |
[in] | buf_size | buffer size (bytes), enforced lower bound of 4KB |
References buffer_size(), and open().
|
inlineoverride |
Destructor.
References close().
|
inlineprivate |
if character buffer does not exist, create it and assign it to internal ofstream
File must be closed for this operation to be successful, otherwise we can run into implementation dependent behavior of std::basic_filebuf.
References buffer_size_, char_buffer_p_, and of_stream_.
Referenced by open(), and open_append().
|
inlineoverridevirtual |
|
inline |
get buffer size (bytes)
In uncompressed mode this is the size of the character buffer. In compressed mode this is the size of the zip buffer.
References buffer_size_.
Referenced by ozstream().
|
inline |
set buffer size (bytes)
In uncompressed mode this is the size of the character buffer. In compressed mode this is the size of the zip buffer. Lower bound of 4KB is enforced due to zipstream requirements. Operation is skipped if the file is currently open, as the buffer is considered locked.
References buffer_size_, max(), and of_stream_.
|
inlineoverridevirtual |
Clear the stream.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
Referenced by add_scores(), pyrosetta.bindings.pose.ResidueLabelAccessor::discard(), do_event_prediction(), dump_data(), dump_ddg_pdb(), dump_grid_pdb(), dump_water_grid_file(), main(), and output_results().
|
inline |
Close the ofstream and reset the state.
References utility::io::mpi_stream::basic_mpi_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::close(), compression_, destroy_char_buffer(), filename_, mpi_stream_p_, NONE, of_stream_, zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize(), and zip_stream_p_.
Referenced by pyrosetta.distributed.utility.log.LoggingContext::__exit__(), ez_setup.ContextualZipFile::__exit__(), PyMOL-Rosetta-relay-client.SecretInputDialog::__init__(), add_scores(), SuperDeviationMover::apply(), SpartaSuperDeviationMover::apply(), AnchorFinderMover::apply(), create_bp_jump_database_test(), create_rna_benchmark_test(), do_event_prediction(), dock(), dump_data(), dump_ddg_pdb(), dump_grid_pdb(), dump_water_grid_file(), files_for_openMM_test(), TCDock::gather_hits(), main(), mg_pdbstats_test(), my_main(), open(), open_append(), open_append_if_existed(), output_benchmark_stuff(), output_packstat_pdb(), output_results(), output_stuff(), pdb_little_motif_test(), pdb_stats(), predict_chem_map_test(), print_base_centroid_atoms(), SuperDeviationMover::print_stats(), SpartaSuperDeviationMover::print_stats(), pymol_struct_type_test(), rna_motif_test(), rna_protein_pdbstats_test(), run(), sicdock_thread_num(), PyMOL-Rosetta-relay-client.SecretInputDialog::start_server(), symmetrize_map(), tar_motif_test(), vdw_stats(), XMLprinterMover::write_output_file(), numeric::write_tensor_to_file(), numeric::write_tensor_to_file_without_json(), and ~ozstream().
|
inlineoverridevirtual |
Compressed?
Implements utility::io::orstream.
References compression_, and GZIP.
Referenced by pyrosetta.distributed.cluster.io.IO::_save_results().
|
inlineprivate |
if character buffer exists, destroy it
File must be closed for this operation to be successful, otherwise we are deleting a buffer that's still in use.
References char_buffer_p_, and of_stream_.
Referenced by close().
|
static |
References utility_exit_with_message.
|
inlineoverridevirtual |
|
inlineoverridevirtual |
|
inline |
File name.
References filename_.
Referenced by pyrosetta.io.silent_file_map.SilentFileMap::write_file().
|
inlineoverridevirtual |
Flush the stream – currently alias to flush_finalize()
Instead doing a regular flush, we currently force a completion of the zip stream. We do this to pre-empt against several things: (1) the expensive operation of closing and re-opening a stream (2) confusion and inconvenience that may result from users calling flushes and ending upon with broken or corrupted files if a job is somehow interrupted (e.g. on a cluster). Please note that calling flush_finalize() too often can seriously degrade compression. zlib documentation appears to imply that every 1MB or so is a reasonable rule of thumb.
Implements utility::io::orstream.
References utility::io::mpi_stream::basic_mpi_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::flush(), flush(), mpi_stream_p_, of_stream_, zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize(), and zip_stream_p_.
Referenced by flush(), flush_finalize(), and operator<<().
|
inline |
Flush the streams and finalize the zip stream.
Calling this will complete the zip stream. Upon the next write, a new zip stream will be started. Please note that calling flush_finalize() too often can seriously degrade compression. zlib documentation appears to imply that every 1MB or so is a reasonable rule of thumb.
References utility::io::mpi_stream::basic_mpi_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::flush(), flush(), mpi_stream_p_, of_stream_, zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize(), and zip_stream_p_.
|
inlineprivate |
CRC of the uncompressed data (see zipstream documentation)
References zlib_stream::basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT >::get_crc(), and zip_stream_p_.
|
inlineprivate |
Uncompressed data size.
References zlib_stream::basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT >::get_in_size(), and zip_stream_p_.
|
inlineprivate |
Compressed data size.
References zlib_stream::basic_zip_ostreambase< Elem, Tr, ElemA, ByteT, ByteAT >::get_out_size(), and zip_stream_p_.
|
inlineoverridevirtual |
Good?
Implements utility::io::orstream.
References stream().
Referenced by compute_intrinsic_deviation(), open_append_if_existed(), numeric::write_tensor_to_file(), and numeric::write_tensor_to_file_without_json().
|
inlineoverridevirtual |
|
inlineprivate |
Is stream attached to a gzip file?
References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::is_gzip(), and zip_stream_p_.
|
inlinestatic |
References bMPI_reroute_stream_, and mpi_FileBuf_master_rank_.
void utility::io::ozstream::open | ( | std::string const & | filename_a, |
std::ios_base::openmode | open_mode = std::ios_base::out |
||
) |
Open a file.
References allocate_assign_char_buffer(), job_manager::app, bMPI_reroute_stream_, buffer_size_, close(), compression_, zlib_stream::DefaultStrategy, utility::file::file_extension(), filename_, GZIP, basic::options::OptionKeys::in::in, zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::is_gzip(), mpi_FileBuf_master_rank_, mpi_stream_p_, NONE, of_stream_, erraser_single_res_analysis::out, utility::file::trytry_ofstream_open(), UNCOMPRESSED, and zip_stream_p_.
Referenced by add_scores(), IAMover::apply(), compute_intrinsic_deviation(), dump_data(), dump_ddg_pdb(), dump_grid_pdb(), dump_water_grid_file(), main(), one_chain_ST_MC(), open_append_if_existed(), ozstream(), print_base_centroid_atoms(), SpartaSuperDeviationMover::print_stats(), symmetrize_map(), and XMLprinterMover::write_output_file().
void utility::io::ozstream::open_append | ( | std::string const & | filename_a | ) |
Open a text file for appending.
Open a text file or gzip'd file for appending.
References allocate_assign_char_buffer(), job_manager::app, bMPI_reroute_stream_, buffer_size_, close(), compression_, utility::io::oc::cout, zlib_stream::DefaultStrategy, utility::options::OptionKeys::options::exit, utility::file::file_extension(), filename_, GZIP, zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::is_gzip(), mpi_FileBuf_master_rank_, mpi_stream_p_, NONE, of_stream_, erraser_single_res_analysis::out, utility::file::trytry_ofstream_open(), UNCOMPRESSED, and zip_stream_p_.
Referenced by IAMover::apply(), main(), and open_append_if_existed().
void utility::io::ozstream::open_append_if_existed | ( | std::string const & | filename_a, |
std::stringstream & | preprinted_header | ||
) |
open file as append if it exists, return true if file existed before, false if it is new.
@detail special "atomic" method to open a stream and print a header if it is new. This is necessary to avoid process competition when checking for existance to decided whether or not to write a header.
References bMPI_reroute_stream_, close(), compression_, utility::file::file_exists(), filename_, good(), mpi_FileBuf_master_rank_, mpi_stream_p_, NONE, open(), open_append(), and UNCOMPRESSED.
|
inlineoverridevirtual |
bool conversion
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
|
inlineoverridevirtual |
Stream conversion.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
|
inlineoverridevirtual |
Stream conversion.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
|
inlineoverridevirtual |
Stream access.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
|
inlineoverridevirtual |
Stream access.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
|
inlineoverridevirtual |
Stream output overload to replace std::endl with
to avoid flushing.
and call ozstream::flush() when passed std::flush
Implements utility::io::orstream.
References flush(), kmeans_adaptive_kernel_density_bb_dependent_rotlib::m, mpi_stream_p_, of_stream_, and zip_stream_p_.
Stream output: override to preserve type of return value.
References mpi_stream_p_, of_stream_, predPRE::t, and zip_stream_p_.
|
inlineoverridevirtual |
Write a char.
Implements utility::io::orstream.
References kmeans_adaptive_kernel_density_bb_dependent_rotlib::c, mpi_stream_p_, of_stream_, utility::io::mpi_stream::basic_mpi_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::put(), zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::put(), put(), and zip_stream_p_.
Referenced by put().
|
inlineoverridevirtual |
|
inlineoverridevirtual |
Stream access.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
Referenced by bad(), eof(), fail(), good(), rdbuf(), and write().
|
inlineoverridevirtual |
Stream access.
Implements utility::io::orstream.
References mpi_stream_p_, of_stream_, and zip_stream_p_.
|
inlineoverridevirtual |
|
inlineoverridevirtual |
Write a string.
Implements utility::io::orstream.
References count, mpi_stream_p_, of_stream_, str(), utility::io::mpi_stream::basic_mpi_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::write(), zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::write(), write(), and zip_stream_p_.
Referenced by main(), write(), and numeric::write_tensor_to_file_without_json().
|
inlineoverridevirtual |
|
inline |
Flush the zip_ostream.
this will flush but not finalize the zip stream
References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush(), and zip_stream_p_.
|
inline |
Flush and finalize the zip_stream.
Calling this will complete the zip stream. Upon the next write, a new zip stream will be started Please note that calling zflush_finalize() too often can seriously degrade compression. zlib documentation appears to imply that every 1MB or so is a reasonable rule of thumb.
References zlib_stream::basic_zip_ostream< Elem, Tr, ElemA, ByteT, ByteAT >::zflush_finalize(), and zip_stream_p_.
|
friend |
|
friend |
|
staticprivate |
Referenced by MPI_reroute_rank(), open(), open_append(), and open_append_if_existed().
|
private |
size of buffer (in bytes)
In uncompressed mode this is the size of the character buffer. In compressed mode this is the size of the zip buffer. Must be at least 4KB otherwise zipstream will break.
Referenced by allocate_assign_char_buffer(), buffer_size(), open(), and open_append().
|
private |
character buffer pointer (owning)
Referenced by allocate_assign_char_buffer(), and destroy_char_buffer().
|
private |
Compression state.
Referenced by close(), compressed(), gzipped(), open(), open_append(), open_append_if_existed(), and uncompressed().
|
private |
File name.
Referenced by close(), filename(), open(), open_append(), and open_append_if_existed().
|
staticprivate |
Referenced by MPI_reroute_rank(), open(), open_append(), and open_append_if_existed().
|
private |
|
private |
File stream.
Referenced by allocate_assign_char_buffer(), buffer_size(), clear(), close(), destroy_char_buffer(), flush(), flush_finalize(), open(), open_append(), operator bool(), operator std::ostream &(), operator std::ostream const &(), operator()(), operator<<(), put(), stream(), and write().
|
private |
Zip file stream pointer (owning)
Referenced by clear(), close(), flush(), flush_finalize(), get_crc(), get_in_size(), get_out_size(), is_gzip(), open(), open_append(), operator bool(), operator std::ostream &(), operator std::ostream const &(), operator()(), operator<<(), put(), stream(), write(), zflush(), and zflush_finalize().