AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
axom::sina::Document Class Reference

An object representing the top-level object of a Sina file. More...

#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/develop/src/axom/sina/core/Document.hpp>

Public Types

using RecordList = std::vector< std::unique_ptr< Record > >
 
using RelationshipList = std::vector< Relationship >
 

Public Member Functions

 Document ()=default
 
 Document (Document const &)=delete
 
Documentoperator= (Document const &)=delete
 
 Document (Document &&)=default
 
Documentoperator= (Document &&)=default
 
 Document (conduit::Node const &asNode, RecordLoader const &recordLoader)
 Create a Document from its Conduit Node representation. More...
 
 Document (std::string const &asJson, RecordLoader const &recordLoader)
 Create a Document from a JSON string representation. More...
 
void add (std::unique_ptr< Record > record)
 Add the given record to this document. More...
 
RecordList const & getRecords () const noexcept
 Get the list of records currently in this document. More...
 
void add (Relationship relationship)
 Add a relationship to this document. More...
 
RelationshipList const & getRelationships () const noexcept
 Get the list of relationships in this document. More...
 
conduit::Node toNode () const
 Convert this document to a conduit Node. More...
 
std::string toJson (conduit::index_t indent=0, conduit::index_t depth=0, const std::string &pad="", const std::string &eoe="") const
 Convert this document to a JSON string. More...
 
std::string get_supported_file_types ()
 Get the list of file types currently supported by the implementation. More...
 

Detailed Description

An object representing the top-level object of a Sina file.

A Document represents the top-level object of a file conforming to the Sina schema. When serialized, these documents can be ingested into a Sina database and used with the Sina tool. Sina files are defaulted to JSON but optionally support HDF5.

Documents contain at most two objects: a list of Records and a list of Relationships. A simple, empty document:

{
"records": [],
"relationships": []
}

The "records" list can contain Record objects and their inheriting types, such as Run (for a full list, please see the inheritance diagram in the Record documentation). The "relationships" list can contain Relationship objects.

Documents can be assembled programatically and/or generated from existing JSON. An example of an assembled Document is provided on the main page. To load a Document from an existing JSON file:

axom::sina::Document myDocument = axom::sina::loadDocument("path/to/infile.json");
An object representing the top-level object of a Sina file.
Definition: Document.hpp:129
Document loadDocument(std::string const &path, Protocol protocol=Protocol::JSON)
Load a document from the given path. Only records which this library knows about will be able to be l...

To generate a Document from a JSON string and vice versa:

std::string my_json = "{\"records\":[{\"type\":\"run\",\"id\":\"test\"}],\"relationships\":[]}";
std::cout << myDocument.toJson() << std::endl;);
std::string toJson(conduit::index_t indent=0, conduit::index_t depth=0, const std::string &pad="", const std::string &eoe="") const
Convert this document to a JSON string.
RecordLoader createRecordLoaderWithAllKnownTypes()
Create a RecordLoader which can load records of all known types.

You can add further entries to the Document using add():

std::unique_ptr<sina::Record> myRun{new axom::sina::Run{someID, "My Sim Code", "1.2.3", "jdoe"}};
axom::sina::Relationship myRelationship{someID, "comes before", someOtherID};
myDocument.add(myRun);
myDocument.add(myRelationship);
void add(std::unique_ptr< Record > record)
Add the given record to this document.
An object used to correlate 2 Records.
Definition: Relationship.hpp:85
A sub-type of Record representing a single run of an applicaiton.
Definition: Run.hpp:48

You can also export your Document to file:

axom::sina::saveDocument(myDocument, "path/to/outfile.json")
void saveDocument(Document const &document, std::string const &fileName, Protocol protocol=Protocol::AUTO_DETECT)
Save the given Document to the specified location. If the given file exists, it will be overwritten.

Loading and Saving documents will default to the JSON file type, but if an optional file type is loaded the Protocol parameter will control your file type. For example with HDF5:

axom::sina::Document myDocument = axom::sina::loadDocument("path/to/infile.hdf5, Protocol::HDF5");
axom::sina::saveDocument(myDocument, "path/to/outfile.hdf5", Protocol::HDF5)
@ HDF5
Force HDF5 format (supported_types[1], requires AXOM_USE_HDF5)

Check the Sina file format version with:

std::string getSinaFileFormatVersion()
Get the current file format version.
Definition: Document.hpp:284

Member Typedef Documentation

◆ RecordList

using axom::sina::Document::RecordList = std::vector<std::unique_ptr<Record> >

A vector of pointers to Record objects.

◆ RelationshipList

A vector of Relationship objects.

Constructor & Destructor Documentation

◆ Document() [1/5]

axom::sina::Document::Document ( )
default

Construct an empty Document.

◆ Document() [2/5]

axom::sina::Document::Document ( Document const &  )
delete

Disable copying Document objects. We must do this since we hold pointers to polymorphic objects.

◆ Document() [3/5]

axom::sina::Document::Document ( Document &&  )
default

Move constructor which should be handled by the compiler.

◆ Document() [4/5]

axom::sina::Document::Document ( conduit::Node const &  asNode,
RecordLoader const &  recordLoader 
)

Create a Document from its Conduit Node representation.

Parameters
asNodethe Document as a Node
recordLoaderan RecordLoader to use to load the different types of records which may be in the document

◆ Document() [5/5]

axom::sina::Document::Document ( std::string const &  asJson,
RecordLoader const &  recordLoader 
)

Create a Document from a JSON string representation.

Parameters
asJsonthe Document as a JSON string
recordLoaderan RecordLoader to use to load the different types of records which may be in the document

Member Function Documentation

◆ operator=() [1/2]

Document& axom::sina::Document::operator= ( Document const &  )
delete

Disabling copy assignment.

◆ operator=() [2/2]

Document& axom::sina::Document::operator= ( Document &&  )
default

Move assignment which should be handled by the compiler.

◆ add() [1/2]

void axom::sina::Document::add ( std::unique_ptr< Record record)

Add the given record to this document.

Parameters
recordthe record to add

◆ getRecords()

RecordList const& axom::sina::Document::getRecords ( ) const
inlinenoexcept

Get the list of records currently in this document.

Returns
the list of records

◆ add() [2/2]

void axom::sina::Document::add ( Relationship  relationship)

Add a relationship to this document.

Parameters
relationshipthe relationship to add

◆ getRelationships()

RelationshipList const& axom::sina::Document::getRelationships ( ) const
inlinenoexcept

Get the list of relationships in this document.

Returns
the list of relationships

◆ toNode()

conduit::Node axom::sina::Document::toNode ( ) const

Convert this document to a conduit Node.

Returns
the contents of the document as a Node

◆ toJson()

std::string axom::sina::Document::toJson ( conduit::index_t  indent = 0,
conduit::index_t  depth = 0,
const std::string &  pad = "",
const std::string &  eoe = "" 
) const

Convert this document to a JSON string.

Returns
the contents of the document as a JSON string

◆ get_supported_file_types()

std::string axom::sina::Document::get_supported_file_types ( )

Get the list of file types currently supported by the implementation.

Returns
a string of supported file types

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