Celeritas 0.7.0-3+develop.835656ac1
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
celeritas::OutputRegistry Class Reference

Store classes that can output data at the end of the run. More...

#include <OutputRegistry.hh>

Public Types

enum class  OpenMode { app , trunc }
 
Type aliases
using SPConstInterface = std::shared_ptr< OutputInterface const >
 

Public Member Functions

void open (std::string s)
 Open a persistent file to write with output.
 
void open (std::string s, OpenMode)
 Open a persistent file to write with output.
 
void close ()
 Close persistent file if open.
 
std::string const & output_filename () const
 Get persistent output filename (debug error if not open).
 
void output () const
 Output all classes to the persistent filename.
 
bool is_open () const
 Whether a persistent file is open.
 
void insert (SPConstInterface)
 Add an interface for writing.
 
void output (JsonPimpl *) const
 Output all classes to a JSON object.
 
void output (std::ostream *os) const
 Output all classes to a JSON object that's written to the given stream.
 
bool empty () const
 Whether no output has been registered.
 
void clear ()
 Clear output interfaces.
 

Static Public Member Functions

static std::string stdout_filename ()
 Special filename for writing persistent output to stdout.
 

Friends

std::ostream & operator<< (std::ostream &os, OutputRegistry const &reg)
 Output to a stream.
 

Detailed Description

Store classes that can output data at the end of the run.

Each output interface defines a category (e.g. input, result, system) and a name. The output manager then writes the JSON output from that entry into a nested database:

  {"category": {"label": "data"}}
* 
Newline-delimited json output
The output registry will avoid newlines in its output, allowing compatibility with NDJSON/JSONL.
std::ofstream out("foo.jsonl");
out << reg << std::endl;
out << reg << std::endl;

Member Enumeration Documentation

◆ OpenMode

Enumerator
app 

Seek to end of file before each write.

trunc 

Overwrite existing file.

Member Function Documentation

◆ clear()

void celeritas::OutputRegistry::clear ( )

Clear output interfaces.

This is useful when printing to a persistent file in JSONL format: the first write includes all the problem setup metadata, and subsequent writes can just include the results (which are presumably added by whoever calls "clear" after).

◆ open() [1/2]

void celeritas::OutputRegistry::open ( std::string  s)

Open a persistent file to write with output.

This signature defaults to overwriting a file or streaming to stdout.

◆ open() [2/2]

void celeritas::OutputRegistry::open ( std::string  s,
OpenMode  om 
)

Open a persistent file to write with output.

Note
This class is not MPI-aware, so only open on the main process.

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