Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ozstream.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/io/ozstream.hh
11 /// @brief Output file stream wrapper for uncompressed and compressed files
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 /// @author David Kim (dekim@u.washington.edu)
14 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
15 
16 
17 #ifndef INCLUDED_utility_io_ozstream_hh
18 #define INCLUDED_utility_io_ozstream_hh
19 
20 
21 #ifdef USEMPI
22 #include <mpi.h>
23 #endif
24 // Unit headers
26 
27 // Package headers
28 #include <utility/io/orstream.hh>
29 
30 // Project headers
32 #if defined( USE_FILE_PROVIDER )
34 #endif
35 
36 // Utility headers
37 #include <utility/io/zipstream.hpp>
38 #include <utility/io/mpistream.hh>
39 
40 // C++ headers
41 #include <fstream>
42 
43 namespace utility {
44 namespace io {
45 
46 
47 /// @brief default buffer size for ozstreams (900KB)
48 /// @note this must be at least 4KB, otherwise zipstream will break
49 std::streamsize const OZSTREAM_DEFAULT_BUFFER_SIZE = 921600;
50 
51 
52 /// @brief ozstream: Output file stream wrapper for uncompressed and compressed files
53 class ozstream :
54  public orstream
55 {
56 
57 
58 private: // Friends
59 
60 
61  friend long utility::file::gzip( std::string const & uncompressedfile, bool overwrite );
62  friend long utility::file::gunzip( std::string const & compressedfile, bool overwrite );
63 
64 
65 private: // Types
66 
67 
69 
70 
71 public: // Creation
72 
73 
74  /// @brief Default constructor
75  inline
77  compression_( NONE ),
79  char_buffer_p_( NULL ),
80  zip_stream_p_( 0 ),
81  mpi_stream_p_( 0 )
82 #if defined( USE_FILE_PROVIDER )
83  ,file_provider_stream( &bad_stream )
84 #endif
85 
86  {}
87 
88 
89  /// @brief Filename constructor
90  /// @param [in] filename_a filename
91  /// @param [in] open_mode opening mode bitmask, use std::ios_base::out for gzip files
92  /// @param [in] buf_size buffer size (bytes), enforced lower bound of 4KB
93  inline
94  explicit
96  std::string const & filename_a,
97  std::ios_base::openmode open_mode = std::ios_base::out, // Ignored for gzip files
98  std::streamsize buf_size = OZSTREAM_DEFAULT_BUFFER_SIZE
99  ) :
100  compression_( NONE ),
101  char_buffer_p_( NULL ),
102  zip_stream_p_( 0 ),
103  mpi_stream_p_( 0 )
104 #if defined( USE_FILE_PROVIDER )
105  ,file_provider_stream( &bad_stream )
106 #endif
107 
108  {
109  buffer_size( buf_size ); // set buffer
110  open( filename_a, open_mode );
111  }
112 
113 
114  /// @brief Destructor
115  inline
116  virtual
118  {
119  close();
120  }
121 
122 
123 public: // Methods: conversion
124 
125 
126  /// @brief bool conversion
127  inline
128  operator bool() const
129  {
130 #if defined( USE_FILE_PROVIDER )
131  if ( file_provider_stream->good() ) {
132  return true;
133  }
134 #endif
135  return ( zip_stream_p_ ? !zip_stream_p_->fail() : ( mpi_stream_p_ ? !mpi_stream_p_->fail() : !!of_stream_ ));
136  }
137 
138 
139  /// @brief Stream conversion
140  inline
141  operator std::ostream const &() const
142  {
143 #if defined( USE_FILE_PROVIDER )
144  if ( file_provider_stream->good() ) {
145  return *file_provider_stream;
146  }
147 #endif
148  return ( zip_stream_p_
149  ? static_cast< std::ostream const & >( *zip_stream_p_ )
150  : ( mpi_stream_p_ ? static_cast< std::ostream const& > ( *mpi_stream_p_ )
151  : static_cast< std::ostream const & >( of_stream_ ) )
152  );
153  }
154 
155 
156  /// @brief Stream conversion
157  inline
158  operator std::ostream &()
159  {
160 #if defined( USE_FILE_PROVIDER )
161  if ( file_provider_stream->good() ) {
162  return *file_provider_stream;
163  }
164 #endif
165  return ( zip_stream_p_
166  ? static_cast< std::ostream & >( *zip_stream_p_ )
167  : ( mpi_stream_p_ ? static_cast< std::ostream & > ( *mpi_stream_p_ )
168  : static_cast< std::ostream & >( of_stream_ ) )
169  );
170  }
171 
172 
173 public: // Methods: formatting
174 
175 
176  /// @brief Stream output: override to preserve type of return value
177  template< typename T >
178  inline
179  ozstream &
180  operator <<( T const & t )
181  {
182 #if defined( USE_FILE_PROVIDER )
183  if ( file_provider_stream->good() ) {
184  (*file_provider_stream) << t;
185  return *this;
186  }
187 #endif
188  if ( zip_stream_p_ ) {
189  (*zip_stream_p_) << t;
190  } else if ( mpi_stream_p_ ) {
191  (*mpi_stream_p_) << t;
192  } else {
193  of_stream_ << t;
194  }
195  return *this;
196  }
197 
198 
199  /// @brief Stream output overload to replace std::endl with \n to avoid flushing
200  /// @brief and call ozstream::flush() when passed std::flush
201  inline
202  ozstream &
204  {
205  static manipulator const std_endl = std::endl;
206  static manipulator const std_flush = std::flush;
207  if ( m == std_endl && ( mpi_stream_p_ || zip_stream_p_ ) ) {
208 #if defined( USE_FILE_PROVIDER )
209  if ( file_provider_stream->good() ) {
210  (*file_provider_stream) << '\n';
211  return *this;
212  }
213 #endif
214  if ( zip_stream_p_ ) { // Output newline instead
215  (*zip_stream_p_) << '\n';
216  } else if ( mpi_stream_p_ ) {
217  (*mpi_stream_p_) << '\n';
218  }
219  } else if ( ( m == std_flush ) && ( zip_stream_p_ || mpi_stream_p_) ) {
220 #if defined( USE_FILE_PROVIDER )
221  if ( file_provider_stream->good() ) {
222  file_provider_stream->flush();
223  return *this;
224  }
225 #endif
226  flush(); // ozstream::flush()
227  } else {
228 #if defined( USE_FILE_PROVIDER )
229  if ( file_provider_stream->good() ) {
230  (*file_provider_stream) << m;
231  return *this;
232  }
233 #endif
234  of_stream_ << m;
235  }
236  return *this;
237  }
238 
239 
240 public: // Methods: i/o
241 
242 
243  /// @brief Open a file
244  void
245  open(
246  std::string const & filename_a,
247  std::ios_base::openmode open_mode = std::ios_base::out
248  );
249 
250 
251  /// @brief Open a text file for appending
252  void
253  open_append( std::string const & filename_a );
254 
255  /// @brief open file as append if it exists, return true if file existed before, false if it is new.
256  void
257  open_append_if_existed( std::string const& filename_a, std::stringstream& preprinted_header );
258 
259  /// @brief Write a char
260  inline
261  ozstream &
262  put( char const c )
263  {
264 #if defined( USE_FILE_PROVIDER )
265  if ( file_provider_stream->good() ) {
266  file_provider_stream->put( c );
267  return *this;
268  }
269 #endif
270 
271  if ( zip_stream_p_ ) {
272  zip_stream_p_->put( c );
273  } else if ( mpi_stream_p_ ) {
274  mpi_stream_p_->put( c );
275  } else {
276  of_stream_.put( c );
277  }
278  return *this;
279  }
280 
281 
282  /// @brief Write a string
283  inline
284  ozstream &
285  write( char const * str, std::streamsize const count )
286  {
287 #if defined( USE_FILE_PROVIDER )
288  if ( file_provider_stream->good() ) {
289  file_provider_stream->write( str, count );
290  return *this;
291  }
292 #endif
293  if ( zip_stream_p_ ) {
294  zip_stream_p_->write( str, count );
295  } else if ( mpi_stream_p_ ) {
296  mpi_stream_p_->write( str, count );
297  } else {
298  of_stream_.write( str, count );
299  }
300  return *this;
301  }
302 
303 
304  /// @brief Write a string
305  inline
306  ozstream &
307  write( std::string const & str, std::streamsize const count )
308  {
309  stream().write( str.c_str(), count );
310  return *this;
311  }
312 
313 
314  /// @brief Flush the stream -- currently alias to flush_finalize()
315  /// @details Instead doing a regular flush, we currently force a
316  /// completion of the zip stream. We do this to pre-empt
317  /// against several things: (1) the expensive operation
318  /// of closing and re-opening a stream (2) confusion and
319  /// inconvenience that may result from users calling flushes
320  /// and ending upon with broken or corrupted files if a
321  /// job is somehow interrupted (e.g. on a cluster).
322  /// Please note that calling flush_finalize() too often
323  /// can seriously degrade compression. zlib documentation
324  /// appears to imply that every 1MB or so is a reasonable
325  /// rule of thumb.
326  inline
327  ozstream &
329  {
330 #if defined( USE_FILE_PROVIDER )
331  if ( file_provider_stream->good() ) {
332  file_provider_stream->flush();
333  return *this;
334  }
335 #endif
336  // comment out the zflush_finalize() containing line and uncomment
337  // the flush() containing line to switch to "regular" flush behavior
339  // if ( zip_stream_p_ ) zip_stream_p_->zflush();
340  if ( mpi_stream_p_ ) {
341  mpi_stream_p_->flush();
342  return *this; //no of_stream_ if mpi_stream
343  }
344  of_stream_.flush();
345  return *this;
346  }
347 
348 
349  /// @brief Flush the streams and finalize the zip stream
350  /// @details Calling this will complete the zip stream.
351  /// Upon the next write, a new zip stream will be started.
352  /// Please note that calling flush_finalize() too often
353  /// can seriously degrade compression. zlib documentation
354  /// appears to imply that every 1MB or so is a reasonable
355  /// rule of thumb.
356  inline
357  ozstream &
359  {
360 #if defined( USE_FILE_PROVIDER )
361  if ( file_provider_stream->good() ) {
362  file_provider_stream->flush();
363  return *this;
364  }
365 #endif
367  if ( mpi_stream_p_ ) {
368  mpi_stream_p_->flush();
369  return *this; //no of_stream_ if mpi_stream
370  }
371  of_stream_.flush();
372  return *this;
373  }
374 
375 
376  /// @brief Flush the zip_ostream
377  /// @details this will flush but *not* finalize the zip stream
378  inline
379  void
381  {
382 #if defined( USE_FILE_PROVIDER )
383  if ( file_provider_stream->good() ) {
384  return;
385  }
386 #endif
388  }
389 
390 
391  /// @brief Flush and finalize the zip_stream
392  /// @details Calling this will complete the zip stream.
393  /// Upon the next write, a new zip stream will be started
394  /// Please note that calling zflush_finalize() too often
395  /// can seriously degrade compression. zlib documentation
396  /// appears to imply that every 1MB or so is a reasonable
397  /// rule of thumb.
398  inline
399  void
401  {
402 #if defined( USE_FILE_PROVIDER )
403  if ( file_provider_stream->good() ) {
404  return;
405  }
406 #endif
408  }
409 
410  /// @brief Clear the stream
411  inline
412  void
414  {
415 #if defined( USE_FILE_PROVIDER )
416  if ( file_provider_stream->good() ) {
417  file_provider_stream->clear();
418  return;
419  }
420 #endif
421  of_stream_.clear();
422  if ( zip_stream_p_ ) zip_stream_p_->clear();
423  if ( mpi_stream_p_ ) mpi_stream_p_->clear();
424  }
425 
426 
427  /// @brief Close the ofstream and reset the state
428  inline
429  void
431  {
432 #if defined( USE_FILE_PROVIDER )
433  if ( file_provider_stream->good() ) {
434  return;
435  }
436 #endif
437  if ( zip_stream_p_ ) {
439  delete zip_stream_p_; zip_stream_p_ = 0;
440  }
441  of_stream_.close();
442  of_stream_.clear();
443  if ( mpi_stream_p_ ) {
444  mpi_stream_p_->close();
445  mpi_stream_p_->clear();
446  delete mpi_stream_p_;
447  mpi_stream_p_ = 0;
448  }
449  compression_ = NONE;
450  filename_.clear();
451 
453  }
454 
455 
456 public: // Properties
457 
458 
459  /// @brief Stream access
460  inline
461  std::ostream const &
462  operator ()() const
463  {
464 #if defined( USE_FILE_PROVIDER )
465  return (*file_provider_stream);
466 #endif
467  return ( zip_stream_p_
468  ? static_cast< std::ostream const & >( *zip_stream_p_ )
469  : ( mpi_stream_p_ ? static_cast< std::ostream const & >( *mpi_stream_p_ )
470  : static_cast< std::ostream const & >( of_stream_ ) ) );
471  }
472 
473 
474  /// @brief Stream access
475  inline
476  std::ostream &
478  {
479 #if defined( USE_FILE_PROVIDER )
480  if ( file_provider_stream->good() ) {
481  return (*file_provider_stream);
482  }
483 #endif
484  return ( zip_stream_p_
485  ? static_cast< std::ostream & >( *zip_stream_p_ )
486  : ( mpi_stream_p_ ? static_cast< std::ostream & >( *mpi_stream_p_ )
487  : static_cast< std::ostream & >( of_stream_ ) ));
488  }
489 
490 
491  /// @brief Stream access
492  inline
493  std::ostream const &
494  stream() const
495  {
496 #if defined( USE_FILE_PROVIDER )
497  if ( file_provider_stream->good() ) {
498  return (*file_provider_stream);
499  }
500 #endif
501  return ( zip_stream_p_
502  ? static_cast< std::ostream const & >( *zip_stream_p_ )
503  : ( mpi_stream_p_ ? static_cast< std::ostream const & >( *mpi_stream_p_ )
504  : static_cast< std::ostream const & >( of_stream_ ) ));
505  }
506 
507 
508  /// @brief Stream access
509  inline
510  std::ostream &
512  {
513 #if defined( USE_FILE_PROVIDER )
514  if ( file_provider_stream->good() ) {
515  return (*file_provider_stream);
516  }
517 #endif
518  return ( zip_stream_p_
519  ? static_cast< std::ostream & >( *zip_stream_p_ )
520  : ( mpi_stream_p_ ? static_cast< std::ostream & >( *mpi_stream_p_ )
521  : static_cast< std::ostream & >( of_stream_ ) ));
522  }
523 
524 
525  /// @brief Pointer to the stream buffer
526  inline
527  std::streambuf *
528  rdbuf() const
529  {
530  return stream().rdbuf();
531  }
532 
533 
534  /// @brief File name
535  inline
536  std::string const &
537  filename() const
538  {
539  return filename_;
540  }
541 
542 
543 public: // Properties: predicate
544 
545 
546  /// @brief Good?
547  inline
548  bool
549  good() const
550  {
551  return stream().good();
552  }
553 
554 
555  /// @brief End of file?
556  inline
557  bool
558  eof() const
559  {
560  return stream().eof();
561  }
562 
563 
564  /// @brief Fail?
565  inline
566  bool
567  fail() const
568  {
569  return stream().fail();
570  }
571 
572 
573  /// @brief Bad?
574  inline
575  bool
576  bad() const
577  {
578  return stream().bad();
579  }
580 
581 
582  /// @brief Compressed?
583  inline
584  bool
585  compressed() const
586  {
587  return ( compression_ == GZIP );
588  }
589 
590 
591  /// @brief Uncompressed?
592  inline
593  bool
594  uncompressed() const
595  {
596  return ( compression_ == UNCOMPRESSED );
597  }
598 
599 
600  /// @brief gzipped?
601  inline
602  bool
603  gzipped() const
604  {
605  return ( compression_ == GZIP );
606  }
607 
608 
609 public: // Properties: buffer
610 
611 
612  /// @brief get buffer size (bytes)
613  /// @details In uncompressed mode this is the size of the character buffer.
614  /// In compressed mode this is the size of the zip buffer.
615  inline
616  std::streamsize
617  buffer_size() const
618  {
619  return buffer_size_;
620  }
621 
622 
623  /// @brief set buffer size (bytes)
624  /// @details In uncompressed mode this is the size of the character buffer.
625  /// In compressed mode this is the size of the zip buffer.
626  /// Lower bound of 4KB is enforced due to zipstream requirements.
627  /// Operation is skipped if the file is currently open, as the
628  /// buffer is considered locked.
629  void
631  std::streamsize const & buf_size
632  )
633  {
634  if ( !of_stream_.is_open() ) {
635  buffer_size_ = std::max( buf_size, static_cast< std::streamsize >( 4096 ) );
636  }
637  }
638 
639 
640 private: // Properties: internal zip stream predicates
641 
642 
643  /// @brief Is stream attached to a gzip file?
644  inline
645  bool
646  is_gzip() const
647  {
648  return ( zip_stream_p_ ? zip_stream_p_->is_gzip() : false );
649  }
650 
651 
652  /// @brief CRC of the uncompressed data (see zipstream documentation)
653  inline
654  long
655  get_crc() const
656  {
657  return ( zip_stream_p_ ? zip_stream_p_->get_crc() : 0 );
658  }
659 
660 
661  /// @brief Uncompressed data size
662  inline
663  long
664  get_in_size() const
665  {
666  return ( zip_stream_p_ ? zip_stream_p_->get_in_size() : 0 );
667  }
668 
669 
670  /// @brief Compressed data size
671  inline
672  long
673  get_out_size() const
674  {
675  return ( zip_stream_p_ ? zip_stream_p_->get_out_size() : 0 );
676  }
677 
678 
679 private: // buffer management
680 
681 
682  /// @brief if character buffer does not exist, create it and assign it to
683  /// internal ofstream
684  /// @details File must be closed for this operation to be successful,
685  /// otherwise we can run into implementation dependent behavior
686  /// of std::basic_filebuf.
687  /// @return true if successful, false otherwise
688  inline
689  bool
691  {
692  if ( !char_buffer_p_ && !of_stream_.is_open() ) {
693  char_buffer_p_ = new char[ buffer_size_ ];
694  of_stream_.rdbuf()->pubsetbuf( char_buffer_p_, buffer_size_ );
695 
696  return true;
697  }
698 
699  return false;
700  }
701 
702  /// @brief if character buffer exists, destroy it
703  /// @details File must be closed for this operation to be successful,
704  /// otherwise we are deleting a buffer that's still in use.
705  /// @return true if successful, false otherwise
706  inline
707  bool
709  {
710  if ( char_buffer_p_ && !of_stream_.is_open() ) {
711  delete [] char_buffer_p_;
712  char_buffer_p_ = NULL;
713 
714  return true;
715  }
716 
717  return false;
718  }
719 
720 public:
721 
722  static void enable_MPI_reroute( int min_client_rank, int master_rank );
723 
724  //return master( buffer ) rank or -1
725  static int MPI_reroute_rank() {
726 #ifdef USEMPI
728 #else
729  return -1;
730 #endif
731  }
732 private: // Fields
733 
734 
735  /// @brief Compression state
737 
738  /// @brief File stream
739  std::ofstream of_stream_;
740 
741  /// @brief File name
742  std::string filename_;
743 
744  /// @brief size of buffer (in bytes)
745  /// @details In uncompressed mode this is the size of the character buffer.
746  /// In compressed mode this is the size of the zip buffer.
747  /// Must be at least 4KB otherwise zipstream will break.
748  std::streamsize buffer_size_;
749 
750  /// @brief character buffer pointer (owning)
752 
753  /// @brief Zip file stream pointer (owning)
755 
756 
758 
759  static bool bMPI_reroute_stream_;
761 
762 #if defined( USE_FILE_PROVIDER )
763  std::ostream *file_provider_stream;
764  std::stringstream bad_stream;
765 #endif
766 
767 }; // ozstream
768 
769 
770 } // namespace io
771 } // namespace utility
772 
773 
774 #endif // INCLUDED_utility_io_ozstream_HH
Output stream wrapper abstract base class.
basic_zip_ostream & write(char const *str, std::streamsize const count)
write a string
Definition: zipstream.hpp:506
Altered zipstream library header.
std::streamsize const OZSTREAM_DEFAULT_BUFFER_SIZE
default buffer size for ozstreams (900KB)
Definition: ozstream.hh:49
bool is_gzip() const
Is stream attached to a gzip file?
Definition: ozstream.hh:646
ozstream & operator<<(T const &t)
Stream output: override to preserve type of return value.
Definition: ozstream.hh:180
utility::io::ozstream forward declarations
bool good() const
Good?
Definition: ozstream.hh:549
ozstream & put(char const c)
Write a char.
Definition: ozstream.hh:262
ozstream & flush_finalize()
Flush the streams and finalize the zip stream.
Definition: ozstream.hh:358
char * char_buffer_p_
character buffer pointer (owning)
Definition: ozstream.hh:751
std::streamsize buffer_size() const
get buffer size (bytes)
Definition: ozstream.hh:617
std::streambuf * rdbuf() const
Pointer to the stream buffer.
Definition: ozstream.hh:528
ozstream & flush()
Flush the stream – currently alias to flush_finalize()
Definition: ozstream.hh:328
bool allocate_assign_char_buffer()
if character buffer does not exist, create it and assign it to internal ofstream
Definition: ozstream.hh:690
basic_zip_ostream< Elem, Tr > & zflush()
flush inner buffer and zipper buffer
Definition: zipstream.hpp:455
std::streamsize buffer_size_
size of buffer (in bytes)
Definition: ozstream.hh:748
basic_zip_ostream< Elem, Tr > & zflush_finalize()
flush inner and zipper buffers and finalize zip stream
Definition: zipstream.hpp:462
Compression compression_
Compression state.
Definition: ozstream.hh:736
uLong get_in_size() const
returns the uncompressed data size
Definition: zipstream.hpp:295
basic_zip_ostream & put(char const c)
write char
Definition: zipstream.hpp:494
void zflush()
Flush the zip_ostream.
Definition: ozstream.hh:380
bool uncompressed() const
Uncompressed?
Definition: ozstream.hh:594
basic_mpi_ostream & write(char const *str, std::streamsize const count)
write a string
Definition: mpistream.hh:309
long gzip(std::string const &uncompressedfile, bool overwrite)
gzip: file compression
Definition: gzip_util.cc:42
bool destroy_char_buffer()
if character buffer exists, destroy it
Definition: ozstream.hh:708
bool is_gzip() const
returns true if it is a gzip
Definition: zipstream.hpp:451
void clear()
Clear the stream.
Definition: ozstream.hh:413
uLong get_out_size() const
returns the compressed data size
Definition: zipstream.hpp:292
static bool bMPI_reroute_stream_
Definition: ozstream.hh:759
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...
Definition: ozstream.cc:37
bool eof() const
End of file?
Definition: ozstream.hh:558
std::ostream &(* manipulator)(std::ostream &)
Definition: orstream.hh:40
long get_in_size() const
Uncompressed data size.
Definition: ozstream.hh:664
ozstream & write(std::string const &str, std::streamsize const count)
Write a string.
Definition: ozstream.hh:307
zlib_stream::zip_ostream * zip_stream_p_
Zip file stream pointer (owning)
Definition: ozstream.hh:754
uLong get_crc() const
returns the uncompressed data crc
Definition: zipstream.hpp:289
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.
Definition: ozstream.hh:95
std::ostream const & operator()() const
Stream access.
Definition: ozstream.hh:462
std::string const & filename() const
File name.
Definition: ozstream.hh:537
mpi_stream::mpi_ostream * mpi_stream_p_
Definition: ozstream.hh:757
virtual ~ozstream()
Destructor.
Definition: ozstream.hh:117
std::ostream & stream()
Stream access.
Definition: ozstream.hh:511
std::string filename_
File name.
Definition: ozstream.hh:742
static void enable_MPI_reroute(int min_client_rank, int master_rank)
Definition: ozstream.cc:225
bool gzipped() const
gzipped?
Definition: ozstream.hh:603
void open_append(std::string const &filename_a)
Open a text file for appending.
Definition: ozstream.cc:159
long get_crc() const
CRC of the uncompressed data (see zipstream documentation)
Definition: ozstream.hh:655
orstream: Output stream wrapper base class
Definition: orstream.hh:33
void close()
Close the ofstream and reset the state.
Definition: ozstream.hh:430
gzip utility functions
static int mpi_FileBuf_master_rank_
Definition: ozstream.hh:760
basic_mpi_ostream & put(char const c)
write char
Definition: mpistream.hh:298
void zflush_finalize()
Flush and finalize the zip_stream.
Definition: ozstream.hh:400
ozstream & write(char const *str, std::streamsize const count)
Write a string.
Definition: ozstream.hh:285
long gunzip(std::string const &compressedfile, bool overwrite)
gunzip: file decompression
Definition: gzip_util.cc:139
bool bad() const
Bad?
Definition: ozstream.hh:576
void buffer_size(std::streamsize const &buf_size)
set buffer size (bytes)
Definition: ozstream.hh:630
std::ostream const & stream() const
Stream access.
Definition: ozstream.hh:494
ozstream: Output file stream wrapper for uncompressed and compressed files
Definition: ozstream.hh:53
static int MPI_reroute_rank()
Definition: ozstream.hh:725
long get_out_size() const
Compressed data size.
Definition: ozstream.hh:673
void open(std::string const &filename_a, std::ios_base::openmode open_mode=std::ios_base::out)
Open a file.
Definition: ozstream.cc:62
bool compressed() const
Compressed?
Definition: ozstream.hh:585
static T max(T x, T y)
Definition: Svm.cc:19
std::ofstream of_stream_
File stream.
Definition: ozstream.hh:739
bool fail() const
Fail?
Definition: ozstream.hh:567
ozstream()
Default constructor.
Definition: ozstream.hh:76