← Documentation
ADS-IDAC Engine 5.0.0
CheckedIO.h File Reference
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
Include dependency graph for CheckedIO.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool checked_close (std::ofstream &ofs, const std::string &path)
 Flush and close an output stream and report a failed write. More...
 
void write_file_or_die (const std::string &path, const char *data, size_t size)
 Write an entire buffer to a binary file (truncating it); fatal on any failure. More...
 
bool read_file_verified (const std::string &path, std::vector< char > &out)
 Read an entire binary file into out, verifying the byte count. More...
 

Function Documentation

◆ checked_close()

bool checked_close ( std::ofstream &  ofs,
const std::string &  path 
)
inline

Flush and close an output stream and report a failed write.

Disk-full and quota errors on HPC filesystems otherwise leave truncated ZKPS/ZESNode/analysis files behind without any message. On failure the line "ERROR: write failed (disk full or I/O error): <path>" goes to stderr and is appended to "err messages.txt" in the working directory. The process is NOT terminated; acting on the result is up to the caller.

Parameters
ofsStream to flush and close (closed in every case).
pathFile name used in the message only.
Returns
true when the stream was still good after the flush.

Definition at line 19 of file CheckedIO.h.

Referenced by BranchEndState::saveInfoToFile().

Here is the caller graph for this function:

◆ read_file_verified()

bool read_file_verified ( const std::string &  path,
std::vector< char > &  out 
)
inline

Read an entire binary file into out, verifying the byte count.

Parameters
pathFile to read.
outResized to the file size and overwritten. After a short read it keeps the full size with only the leading bytes valid; after an open failure it is left unchanged.
Returns
true if every byte was read (an empty file is a success with an empty out); false, after an "ERROR: ..." line on stderr, on open failure or short read.

Definition at line 64 of file CheckedIO.h.

Referenced by build_serial_checkpoint(), Client::ensure_base_cache(), RelapSolver::restore(), Client::restore_relap_state(), and Client::Work().

Here is the caller graph for this function:

◆ write_file_or_die()

void write_file_or_die ( const std::string &  path,
const char *  data,
size_t  size 
)
inline

Write an entire buffer to a binary file (truncating it); fatal on any failure.

A restart backup truncated under ENOSPC would surface much later as a RELAP5 abort when the corrupt blob is restored, so corrupt restart data is never survivable: on an open or write failure this prints "FATAL: failed to write ..." on stderr and calls std::exit(1) (not MPI_Abort). A partial file may remain at path.

Parameters
pathDestination file.
dataBuffer to write.
sizeNumber of bytes in data.

Definition at line 42 of file CheckedIO.h.

References PG::size.

Referenced by main(), and AdsidacCallback::onBranchingPoint().

Here is the caller graph for this function: