Field3DOutputFile Class Reference
File I/O

Provides writing of .f3d (internally, hdf5 or Ogawa) files. More...

`#include <Field3DFile.h>`

Inheritance diagram for Field3DOutputFile:

## Public Types

enum | CreateMode { OverwriteMode , FailOnExisting }
Public Types inherited from Field3DFileBase
typedef std::map< std::string, std::string > | GroupMembershipMap

## Public Member Functions

bool | create (const std::string &filename, CreateMode cm=OverwriteMode)
| Creates a .f3d file on disk.
Constructors & destructor
| Field3DOutputFile ()
virtual | ~Field3DOutputFile ()
Writing layer to disk
template<class Data_T>
bool | writeLayer (const std::string &layerName, typename Field< Data_T >::Ptr layer)
| Writes a scalar layer to the "Default" partition.
template<class Data_T>
bool | writeLayer (const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr layer)
| Writes a layer to a specific partition. The partition will be created if not specified.
template<class Data_T>
bool | writeLayer (typename Field< Data_T >::Ptr layer)
| Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.
Backward compatibility
template<class Data_T>
bool | writeScalarLayer (const std::string &layerName, typename Field< Data_T >::Ptr layer)
| Writes a scalar layer to the "Default" partition.
template<class Data_T>
bool | writeScalarLayer (const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr layer)
| Writes a layer to a specific partition. The partition will be created if not specified.
template<class Data_T>
bool | writeScalarLayer (typename Field< Data_T >::Ptr layer)
| Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.
template<class Data_T>
bool | writeVectorLayer (const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
| Writes a scalar layer to the "Default" partition.
template<class Data_T>
bool | writeVectorLayer (const std::string &partitionName, const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
| Writes a layer to a specific partition. The partition will be created if not specified.
template<class Data_T>
bool | writeVectorLayer (typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
| Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.
bool | writeGlobalMetadata ()
| This routine is call if you want to write out global metadata to disk.
bool | writeGroupMembership ()
| This routine is called just before closing to write out any group membership to disk.
Public Member Functions inherited from Field3DFileBase
void | clear ()
| Clear the data structures and close the file.
bool | close ()
| Closes the file. No need to call this unless you specifically want to close the file early. It will close once the File object goes out of scope.
FieldMetadata & | metadata ()
| accessor to the m_metadata class
const FieldMetadata & | metadata () const
| Read only access to the m_metadata class.
virtual void | metadataHasChanged (const std::string &)
| This function should implemented by concrete classes to get the callback when metadata changes.
| Field3DFileBase ()
virtual | ~Field3DFileBase ()=0
| Pure virtual destructor to ensure we never instantiate this class.
void | getPartitionNames (std::vector< std::string > &names) const
| Gets the names of all the partitions in the file.
void | getScalarLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
| Gets the names of all the scalar layers in a given partition.
void | getVectorLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
| Gets the names of all the vector layers in a given partition.
void | addGroupMembership (const GroupMembershipMap &groupMembers)
| Add to the group membership.
void | printHierarchy () const

## Static Public Member Functions

static void | useOgawa (const bool enabled)
| Whether to output ogawa files.

## Private Member Functions

void | cleanup ()
virtual void | closeInternal ()
| Closes the file if open.
File::Partition::Ptr | createNewPartition (const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
| Create newPartition given the input config.
std::string | incrementPartitionName (std::string &pname)
| Increment the partition or make it zero if there's not an integer suffix.
bool | writeMapping (OgOGroup &partitionGroup, FieldMapping::Ptr mapping)
| Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored as plain attributes under a group.
bool | writeMetadata (OgOGroup &metadataGroup)
| Writes metadata for this file.
bool | writeMetadata (OgOGroup &metadataGroup, FieldBase::Ptr layer)
| Writes metadata for this layer.

## Private Attributes

boost::shared_ptr< Alembic::Ogawa::OArchive > | m_archive
| Pointer to the Ogawa archive.
boost::shared_ptr< Field3DOutputFileHDF5 > | m_hdf5
| HDF5 fallback.
boost::shared_ptr< OgOGroup > | m_root
| Pointer to root group.

## Static Private Attributes

static bool | ms_doOgawa = true
| Whether to output ogawa files.

## Additional Inherited Members

Protected Types inherited from Field3DFileBase
typedef std::map< std::string, int > | PartitionCountMap
typedef std::vector< File::Partition::Ptr > | PartitionList
Protected Member Functions inherited from Field3DFileBase
File::Partition::Ptr | getPartition (const std::string &partitionName) const
| Returns a pointer to the given partition.
File::Partition::Ptr | partition (const std::string &partitionName)
| Returns a pointer to the given partition.
File::Partition::Ptr | partition (const std::string &partitionName) const
| Returns a pointer to the given partition.
void | getIntPartitionNames (std::vector< std::string > &names) const
| Gets the names of all the -internal- partitions in the file.
void | getIntScalarLayerNames (std::vector< std::string > &names, const std::string &intPartitionName) const
| Gets the names of all the scalar layers in a given partition, but assumes that partition name is the -internal- partition name.
void | getIntVectorLayerNames (std::vector< std::string > &names, const std::string &intPartitionName) const
| Gets the names of all the vector layers in a given partition, but assumes that partition name is the -internal- partition name.
int | numIntPartitions (const std::string &partitionName) const
| Returns the number of internal partitions for a given partition name.
std::string | makeIntPartitionName (const std::string &partitionsName, int i) const
| Makes an internal partition name given the external partition name. Effectively just tacks on .X to the name, where X is the number.
std::string | intPartitionName (const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
| Returns a unique partition name given the requested name. This ensures that partitions with matching mappings get the same name but each subsequent differing mapping gets a new, separate name.
std::string | removeUniqueId (const std::string &partitionName) const
| Strips any unique identifiers from the partition name and returns the original name.
Protected Attributes inherited from Field3DFileBase
GroupMembershipMap | m_groupMembership
| Keeps track of group membership for each layer of partition name. The key is the "group" and the value is a space separated list of "partitionName.0:Layer1 partitionName.1:Layer0 ...".
boost::shared_ptr< Field3DFileHDF5Base > | m_hdf5Base
| HDF5 fallback.
std::vector< LayerInfo > | m_layerInfo
| This stores layer info.
FieldMetadata | m_metadata
| metadata
PartitionCountMap | m_partitionCount
| Contains a counter for each partition name. This is used to keep multiple fields with the same name unique in the file.
std::vector< std::string > | m_partitionNames
| This stores partition names.
PartitionList | m_partitions
| Vector of partitions.

## Detailed Description

Provides writing of .f3d (internally, hdf5 or Ogawa) files.

Refer to using_files for examples of how to use this in your code.

Definition at line 636 of file Field3DFile.h.

## Member Enumeration Documentation

## CreateMode

enum Field3DOutputFile::CreateMode

Enumerator
OverwriteMode |
FailOnExisting |

Definition at line 642 of file Field3DFile.h.

{
OverwriteMode,
FailOnExisting
};
Field3DOutputFile::FailOnExisting
@ FailOnExisting
Definition Field3DFile.h:644
Field3DOutputFile::OverwriteMode
@ OverwriteMode
Definition Field3DFile.h:643

## Constructor & Destructor Documentation

## Field3DOutputFile()

Field3DOutputFile::Field3DOutputFile | ( |  | ) |

Definition at line 963 of file Field3DFile.cpp.

{
// Empty
}

## ~Field3DOutputFile()

Field3DOutputFile::~Field3DOutputFile | ( |  | ) |

virtual

Definition at line 970 of file Field3DFile.cpp.

{
cleanup();
}
Field3DOutputFile::cleanup
void cleanup()
Definition Field3DFile.h:805

References cleanup().

## Member Function Documentation

## create()

bool Field3DOutputFile::create | ( | const std::string & | filename,
|  | CreateMode | cm = OverwriteMode )

Creates a .f3d file on disk.

Definition at line 977 of file Field3DFile.cpp.

{
if (!ms_doOgawa) {
m_hdf5.reset(new Field3DOutputFileHDF5);
m_hdf5Base = m_hdf5;
int ccm = cm;
return m_hdf5->create(filename, Field3DOutputFileHDF5::CreateMode(ccm));
}
closeInternal();
if (cm == FailOnExisting && fileExists(filename)) {
return false;
}
// Create the Ogawa archive
m_archive.reset(new Alembic::Ogawa::OArchive(filename));
// Check that it's valid
if (!m_archive->isValid()) {
m_archive.reset();
return false;
}
// Get the root
m_root.reset(new OgOGroup(*m_archive));
// Create the version attribute
OgOAttribute<veci32_t> f3dVersion(*m_root, k_versionAttrName,
k_currentFileVersion);
return true;
}
fileExists
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
Definition Field3DFile.cpp:1341
Field3DFileBase::m_hdf5Base
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
Definition Field3DFile.h:388
Field3DOutputFileHDF5::CreateMode
CreateMode
Definition Field3DFileHDF5.h:773
Field3DOutputFile::ms_doOgawa
static bool ms_doOgawa
Whether to output ogawa files.
Definition Field3DFile.h:841
Field3DOutputFile::closeInternal
virtual void closeInternal()
Closes the file if open.
Definition Field3DFile.h:796
Field3DOutputFile::m_hdf5
boost::shared_ptr< Field3DOutputFileHDF5 > m_hdf5
HDF5 fallback.
Definition Field3DFile.h:849
Field3DOutputFile::m_root
boost::shared_ptr< OgOGroup > m_root
Pointer to root group.
Definition Field3DFile.h:846
Field3DOutputFile::m_archive
boost::shared_ptr< Alembic::Ogawa::OArchive > m_archive
Pointer to the Ogawa archive.
Definition Field3DFile.h:844

References closeInternal(), FailOnExisting, fileExists(), m_archive, m_hdf5, Field3DFileBase::m_hdf5Base, m_root, and ms_doOgawa.

## useOgawa()

void Field3DOutputFile::useOgawa | ( | const bool | enabled | ) |

inline static

Whether to output ogawa files.

Definition at line 663 of file Field3DFile.h.

{
// simple temporary endian check
union {
uint32_t l;
char c[4];
} u;
u.l = 0x01234567;
if (u.c[0] == 0x67) {
ms_doOgawa = enabled;
} else {
std::cerr << "WARNING: Field3D only supports Ogawa-backed files "
<< "on little-endian systems." << std::endl;
ms_doOgawa = false;
}
}

References ms_doOgawa.

## writeLayer() [1/3]

template<class Data_T>

bool Field3DOutputFile::writeLayer | ( | const std::string & | layerName,
|  | typename Field< Data_T >::Ptr | layer )

inline

Writes a scalar layer to the "Default" partition.

Definition at line 687 of file Field3DFile.h.

{
return writeLayer<Data_T>(std::string("default"), layerName, layer);
}
Field3DOutputFile::writeLayer
bool writeLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition Field3DFile.h:687

References writeLayer().

Referenced by writeLayer(), writeLayer(), writeScalarLayer(), writeScalarLayer(), writeVectorLayer(), and writeVectorLayer().

## writeLayer() [2/3]

template<class Data_T>

bool Field3DOutputFile::writeLayer | ( | const std::string & | partitionName,
|  | const std::string & | layerName,
|  | typename Field< Data_T >::Ptr | layer )

Writes a layer to a specific partition. The partition will be created if not specified.

Definition at line 1409 of file Field3DFile.cpp.

{
using std::string;
// Null pointer check
if (!field) {
Msg::print(Msg::SevWarning,
"Called writeLayer with null pointer. Ignoring...");
return false;
}
// Make sure archive is open
if (!m_archive) {
Msg::print(Msg::SevWarning,
"Attempting to write layer without opening file first.");
return false;
}
// Get the partition name
string partitionName = intPartitionName(userPartitionName, layerName, field);
// Get the partition
File::Partition::Ptr part = partition(partitionName);
if (!part) {
// Create a new partition
part = createNewPartition(partitionName, layerName, field);
// Make sure it was created
if (!part) {
return false;
}
} else {
// Check that we have a valid mapping
if (!field->mapping()) {
Msg::print(Msg::SevWarning,
"Couldn't add layer \"" + layerName + "\" to partition \""
+ partitionName + "\" because the layer's mapping is null.");
return false;
}
// Check if the layer already exists. If it does, we need to make a
// different partition
if (part->layer(layerName)) {
// Increment the internal partition name
partitionName = incrementPartitionName(partitionName);
// Create a new partition
part = createNewPartition(partitionName, layerName, field);
// Make sure it was created
if (!part) {
return false;
}
}
}
// Check mapping not null
if (!part->mapping) {
Msg::print(Msg::SevWarning, "Severe error - partition mapping is null: "
+ partitionName);
return false;
}
// Check that the mapping matches what's already in the Partition
if (!field->mapping()->isIdentical(part->mapping)) {
Msg::print(Msg::SevWarning, "Couldn't add layer \"" + layerName
+ "\" to partition \"" + partitionName
+ "\" because mapping doesn't match");
return false;
}
// Open the partition
OgOGroup &ogPartition = part->group();
// Build a Layer
File::Layer layer;
layer.name = layerName;
layer.parent = partitionName;
// Add Layer to file ---
OgOGroup ogLayer(ogPartition, layerName);
// Tag as layer
OgOAttribute<string> classType(ogLayer, "class_type", "field3d_layer");
// Create metadata
OgOGroup ogMetadata(ogLayer, "metadata");
// Write metadata
writeMetadata(ogMetadata, field);
// Write field data
writeField(ogLayer, field);
// Add to partition
part->addLayer(layer);
return true;
}
writeField
FIELD3D_API bool writeField(hid_t layerGroup, FieldBase::Ptr field)
This function creates a FieldIO instance based on field->className() which then writes the field data...
Definition Field3DFileHDF5.cpp:1589
Field3DFileBase::partition
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DFileBase::intPartitionName
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
Definition Field3DFile.cpp:422
Field3DOutputFile::createNewPartition
File::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Create newPartition given the input config.
Definition Field3DFile.cpp:1355
Field3DOutputFile::writeMetadata
bool writeMetadata(OgOGroup &metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Definition Field3DFile.cpp:1045
Field3DOutputFile::incrementPartitionName
std::string incrementPartitionName(std::string &pname)
Increment the partition or make it zero if there's not an integer suffix.
Definition Field3DFile.cpp:1302
File::Layer::name
std::string name
The name of the layer (always available).
Definition Field3DFile.h:100
File::Layer::parent
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition Field3DFile.h:103
File::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition Field3DFile.h:127
Msg::SevWarning
@ SevWarning
Definition Log.h:68
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References createNewPartition(), incrementPartitionName(), Field3DFileBase::intPartitionName(), m_archive, FieldRes::mapping(), File::Layer::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), Msg::SevWarning, writeField(), and writeMetadata().

## writeLayer() [3/3]

template<class Data_T>

bool Field3DOutputFile::writeLayer | ( | typename Field< Data_T >::Ptr | layer | ) |

inline

Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.

Definition at line 703 of file Field3DFile.h.

{
return writeLayer<Data_T>(layer->name, layer->attribute, layer);
}

References FieldBase::attribute, FieldBase::name, and writeLayer().

## writeScalarLayer() [1/3]

template<class Data_T>

bool Field3DOutputFile::writeScalarLayer | ( | const std::string & | layerName,
|  | typename Field< Data_T >::Ptr | layer )

inline

Writes a scalar layer to the "Default" partition.

Definition at line 715 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->writeScalarLayer<Data_T>(layerName, layer);
}
return writeScalarLayer<Data_T>(std::string("default"), layerName, layer);
}
Field3DOutputFile::writeScalarLayer
bool writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition Field3DFile.h:715

References m_hdf5, and writeScalarLayer().

Referenced by writeScalarLayer().

## writeScalarLayer() [2/3]

template<class Data_T>

bool Field3DOutputFile::writeScalarLayer | ( | const std::string & | partitionName,
|  | const std::string & | layerName,
|  | typename Field< Data_T >::Ptr | layer )

inline

Writes a layer to a specific partition. The partition will be created if not specified.

Definition at line 727 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->writeScalarLayer<Data_T>(partitionName, layerName, layer);
}
return writeLayer<Data_T>(partitionName, layerName, layer);
}

References m_hdf5, and writeLayer().

## writeScalarLayer() [3/3]

template<class Data_T>

bool Field3DOutputFile::writeScalarLayer | ( | typename Field< Data_T >::Ptr | layer | ) |

inline

Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.

Definition at line 740 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->writeScalarLayer<Data_T>(layer);
}
return writeLayer<Data_T>(layer);
}

References m_hdf5, and writeLayer().

## writeVectorLayer() [1/3]

template<class Data_T>

bool Field3DOutputFile::writeVectorLayer | ( | const std::string & | layerName,
|  | typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr | layer )

inline

Writes a scalar layer to the "Default" partition.

Definition at line 750 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->writeVectorLayer<Data_T>(layerName, layer);
}
return writeVectorLayer<Data_T>(std::string("default"), layerName, layer);
}
Field3DOutputFile::writeVectorLayer
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition Field3DFile.h:750

References FIELD3D_VEC3_T, m_hdf5, and writeVectorLayer().

Referenced by writeVectorLayer().

## writeVectorLayer() [2/3]

template<class Data_T>

bool Field3DOutputFile::writeVectorLayer | ( | const std::string & | partitionName,
|  | const std::string & | layerName,
|  | typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr | layer )

inline

Writes a layer to a specific partition. The partition will be created if not specified.

Definition at line 762 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->writeVectorLayer<Data_T>(partitionName, layerName, layer);
}
return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName, layer);
}

References FIELD3D_VEC3_T, m_hdf5, and writeLayer().

## writeVectorLayer() [3/3]

template<class Data_T>

bool Field3DOutputFile::writeVectorLayer | ( | typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr | layer | ) |

inline

Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.

Definition at line 775 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->writeVectorLayer<Data_T>(layer);
}
return writeLayer<FIELD3D_VEC3_T<Data_T> >(layer);
}

References FIELD3D_VEC3_T, m_hdf5, and writeLayer().

## writeGlobalMetadata()

bool Field3DOutputFile::writeGlobalMetadata | ( |  | ) |

This routine is call if you want to write out global metadata to disk.

Definition at line 1234 of file Field3DFile.cpp.

{
if (m_hdf5) {
return m_hdf5->writeGlobalMetadata();
}
OgOGroup ogMetadata(*m_root, "field3d_global_metadata");
if (!writeMetadata(ogMetadata)) {
Msg::print(Msg::SevWarning, "Error writing file metadata.");
return false;
}
return true;
}

References m_hdf5, m_root, Msg::print(), Msg::SevWarning, and writeMetadata().

## writeGroupMembership()

bool Field3DOutputFile::writeGroupMembership | ( |  | ) |

This routine is called just before closing to write out any group membership to disk.

Definition at line 1252 of file Field3DFile.cpp.

{
if (m_hdf5) {
return m_hdf5->writeGroupMembership();
}
#if 0
using namespace std;
using namespace Hdf5Util;
if (!m_groupMembership.size())
return true;
H5ScopedGcreate group(m_file, "field3d_group_membership");
if (group < 0) {
Msg::print(Msg::SevWarning,
"Error creating field3d_group_membership group.");
return false;
}
if (!writeAttribute(group, "is_field3d_group_membership", "1")) {
Msg::print(Msg::SevWarning,
"Failed to write field3d_group_membership attribute.");
return false;
}
std::map<std::string, std::string>::const_iterator iter =
m_groupMembership.begin();
std::map<std::string, std::string>::const_iterator iEnd =
m_groupMembership.end();
for (; iter != iEnd; ++iter) {
if (!writeAttribute(group, iter->first, iter->second)) {
Msg::print(Msg::SevWarning,
"Failed to write groupMembership string: "+ iter->first);
return false;
}
}
#endif
return true;
}
Field3DFileBase::m_groupMembership
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
Definition Field3DFile.h:382
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.

References Field3DFileBase::m_groupMembership, m_hdf5, Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

## closeInternal()

virtual void Field3DOutputFile::closeInternal | ( |  | ) |

inline private virtual

Closes the file if open.

Implements Field3DFileBase.

Definition at line 796 of file Field3DFile.h.

{
if (m_hdf5) {
m_hdf5->closeInternal();
return;
}
cleanup();
}

References cleanup(), and m_hdf5.

Referenced by create().

## cleanup()

void Field3DOutputFile::cleanup | ( |  | ) |

inline private

Definition at line 805 of file Field3DFile.h.

{
// The destruction of the various Ogawa components must happen in the
// right order
// First, the partition groups
m_partitions.clear();
// Then the root group
m_root.reset();
// Finally, the archive
m_archive.reset();
}
Field3DFileBase::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition Field3DFile.h:371

References m_archive, Field3DFileBase::m_partitions, and m_root.

Referenced by closeInternal(), and ~Field3DOutputFile().

## incrementPartitionName()

std::string Field3DOutputFile::incrementPartitionName | ( | std::string & | pname | ) |

private

Increment the partition or make it zero if there's not an integer suffix.

Definition at line 1302 of file Field3DFile.cpp.

{
std::string myPartitionName = removeUniqueId(partitionName);
int nextIdx = -1;
if (m_partitionCount.find(myPartitionName) != m_partitionCount.end()) {
nextIdx = ++m_partitionCount[myPartitionName];
} else {
nextIdx = 0;
m_partitionCount[myPartitionName] = 0;
}
return makeIntPartitionName(myPartitionName, nextIdx);
}
Field3DFileBase::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition Field3DFile.cpp:479
Field3DFileBase::makeIntPartitionName
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ....
Definition Field3DFile.cpp:665
Field3DFileBase::m_partitionCount
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
Definition Field3DFile.h:377

References Field3DFileBase::m_partitionCount, Field3DFileBase::makeIntPartitionName(), and Field3DFileBase::removeUniqueId().

Referenced by writeLayer().

## createNewPartition()

File::Partition::Ptr Field3DOutputFile::createNewPartition | ( | const std::string & | partitionName,
|  | const std::string & | layerName,
|  | FieldRes::Ptr | field )

private

Create newPartition given the input config.

Definition at line 1355 of file Field3DFile.cpp.

{
using namespace Exc;
File::Partition::Ptr newPart(new File::Partition);
newPart->name = partitionName;
boost::shared_ptr<OgOGroup> ogPartition(new OgOGroup(*m_root, newPart->name));
newPart->setGroup(ogPartition);
m_partitions.push_back(newPart);
// Pick up new pointer
File::Partition::Ptr part = partition(partitionName);
// Add mapping group to the partition
try {
if (!writeMapping(*ogPartition, field->mapping())) {
Msg::print(Msg::SevWarning,
"writeMapping returned false for an unknown reason ");
return File::Partition::Ptr();
}
}
catch (WriteMappingException &e) {
Msg::print(Msg::SevWarning, "Couldn't write mapping for partition: "
+ partitionName);
return File::Partition::Ptr();
}
catch (...) {
Msg::print(Msg::SevWarning,
"Unknown error when writing mapping for partition: "
+ partitionName);
return File::Partition::Ptr();
}
// Set the mapping of the partition. Since all layers share their
// partition's mapping, we can just pick this first one. All subsequent
// additions to the same partition are checked to have the same mapping
part->mapping = field->mapping();
// Tag node as partition
// Create a version attribute on the root node
OgOAttribute<string>(*ogPartition, "is_field3d_partition", "1");
return part;
}
Field3DOutputFile::writeMapping
bool writeMapping(OgOGroup &partitionGroup, FieldMapping::Ptr mapping)
Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored ...
Definition Field3DFile.cpp:1013

References Field3DFileBase::m_partitions, m_root, Field3DFileBase::partition(), Msg::print(), Msg::SevWarning, and writeMapping().

Referenced by writeLayer().

## writeMapping()

bool Field3DOutputFile::writeMapping | ( | OgOGroup & | partitionGroup,
|  | FieldMapping::Ptr | mapping )

private

Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored as plain attributes under a group.

Definition at line 1013 of file Field3DFile.cpp.

{
ClassFactory &factory = ClassFactory::singleton();
const std::string className = mapping->className();
try {
OgOGroup mappingGroup(partitionGroup, k_mappingStr);
OgOAttribute<string> classNameAttr(mappingGroup, k_mappingTypeAttrName,
className);
FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
if (!io) {
Msg::print(Msg::SevWarning, "Unable to find class type: " +
className);
return false;
}
return io->write(mappingGroup, mapping);
}
catch (OgOGroupException &e) {
Msg::print(Msg::SevWarning, "Couldn't create group: " + string(e.what()) );
throw WriteMappingException(k_mappingStr);
}
}
ClassFactory::singleton
static ClassFactory & singleton()
}
Definition ClassFactory.cpp:278
ClassFactory::createFieldMappingIO
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
Definition ClassFactory.cpp:266
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition FieldMappingIO.h:71

References ClassFactory::createFieldMappingIO(), Msg::print(), Msg::SevWarning, and ClassFactory::singleton().

Referenced by createNewPartition().

## writeMetadata() [1/2]

bool Field3DOutputFile::writeMetadata | ( | OgOGroup & | metadataGroup,
|  | FieldBase::Ptr | layer )

private

Writes metadata for this layer.

Definition at line 1045 of file Field3DFile.cpp.

{
{
FieldMetadata::StrMetadata::const_iterator i =
field->metadata().strMetadata().begin();
FieldMetadata::StrMetadata::const_iterator end =
field->metadata().strMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<string>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::IntMetadata::const_iterator i =
field->metadata().intMetadata().begin();
FieldMetadata::IntMetadata::const_iterator end =
field->metadata().intMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<int32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::FloatMetadata::const_iterator i =
field->metadata().floatMetadata().begin();
FieldMetadata::FloatMetadata::const_iterator end =
field->metadata().floatMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<float32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::VecIntMetadata::const_iterator i =
field->metadata().vecIntMetadata().begin();
FieldMetadata::VecIntMetadata::const_iterator end =
field->metadata().vecIntMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<veci32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::VecFloatMetadata::const_iterator i =
field->metadata().vecFloatMetadata().begin();
FieldMetadata::VecFloatMetadata::const_iterator end =
field->metadata().vecFloatMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<vec32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
return true;
}

References Msg::print(), and Msg::SevWarning.

Referenced by writeGlobalMetadata(), and writeLayer().

## writeMetadata() [2/2]

bool Field3DOutputFile::writeMetadata | ( | OgOGroup & | metadataGroup | ) |

private

Writes metadata for this file.

Definition at line 1140 of file Field3DFile.cpp.

{
{
FieldMetadata::StrMetadata::const_iterator i =
metadata().strMetadata().begin();
FieldMetadata::StrMetadata::const_iterator end =
metadata().strMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<string>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::IntMetadata::const_iterator i =
metadata().intMetadata().begin();
FieldMetadata::IntMetadata::const_iterator end =
metadata().intMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<int32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::FloatMetadata::const_iterator i =
metadata().floatMetadata().begin();
FieldMetadata::FloatMetadata::const_iterator end =
metadata().floatMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<float32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::VecIntMetadata::const_iterator i =
metadata().vecIntMetadata().begin();
FieldMetadata::VecIntMetadata::const_iterator end =
metadata().vecIntMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<veci32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
{
FieldMetadata::VecFloatMetadata::const_iterator i =
metadata().vecFloatMetadata().begin();
FieldMetadata::VecFloatMetadata::const_iterator end =
metadata().vecFloatMetadata().end();
for (; i != end; ++i) {
try {
OgOAttribute<vec32_t>(metadataGroup, i->first, i->second);
}
catch (OgOAttributeException &e) {
Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
" " + e.what());
return false;
}
}
}
return true;
}
Field3DFileBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field3DFile.h:276
FieldMetadata::vecFloatMetadata
V3f vecFloatMetadata(const std::string &name, const V3f &defaultVal) const
Tries to retrieve a V3f metadata value. Returns the specified default value if no metadata was found.
Definition FieldMetadata.cpp:113
FieldMetadata::vecIntMetadata
V3i vecIntMetadata(const std::string &name, const V3i &defaultVal) const
Tries to retrieve a V3i metadata value. Returns the specified default value if no metadata was found.
Definition FieldMetadata.cpp:143
FieldMetadata::intMetadata
int intMetadata(const std::string &name, const int defaultVal) const
Tries to retrieve an int metadata value. Returns the specified default value if no metadata was found...
Definition FieldMetadata.cpp:158
FieldMetadata::strMetadata
std::string strMetadata(const std::string &name, const std::string &defaultVal) const
Tries to retrieve a string metadata value. Returns the specified default value if no metadata was fou...
Definition FieldMetadata.cpp:173
FieldMetadata::floatMetadata
float floatMetadata(const std::string &name, const float defaultVal) const
Tries to retrieve a float metadata value. Returns the specified default value if no metadata was foun...
Definition FieldMetadata.cpp:128

References FieldMetadata::floatMetadata(), FieldMetadata::intMetadata(), Field3DFileBase::metadata(), Msg::print(), Msg::SevWarning, FieldMetadata::strMetadata(), FieldMetadata::vecFloatMetadata(), and FieldMetadata::vecIntMetadata().

## Member Data Documentation

## ms_doOgawa

bool Field3DOutputFile::ms_doOgawa = true

static private

Whether to output ogawa files.

Definition at line 841 of file Field3DFile.h.

Referenced by create(), and useOgawa().

## m_archive

boost::shared_ptr<Alembic::Ogawa::OArchive> Field3DOutputFile::m_archive

private

Pointer to the Ogawa archive.

Definition at line 844 of file Field3DFile.h.

Referenced by cleanup(), create(), and writeLayer().

## m_root

boost::shared_ptr<OgOGroup> Field3DOutputFile::m_root

private

Pointer to root group.

Definition at line 846 of file Field3DFile.h.

Referenced by cleanup(), create(), createNewPartition(), and writeGlobalMetadata().

## m_hdf5

boost::shared_ptr<Field3DOutputFileHDF5> Field3DOutputFile::m_hdf5

private

HDF5 fallback.

Definition at line 849 of file Field3DFile.h.

Referenced by closeInternal(), create(), writeGlobalMetadata(), writeGroupMembership(), writeScalarLayer(), writeScalarLayer(), writeScalarLayer(), writeVectorLayer(), writeVectorLayer(), and writeVectorLayer().

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

- export/Field3DFile.h
- src/Field3DFile.cpp