Field3DOutputFileHDF5 Class Reference
File I/O

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

`#include <Field3DFileHDF5.h>`

Inheritance diagram for Field3DOutputFileHDF5:

## Public Types

enum | CreateMode { OverwriteMode , FailOnExisting }
Public Types inherited from Field3DFileHDF5Base
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.
template<class Data_T>
FileHDF5::Partition::Ptr | createNewPartition (const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::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 | 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.
Constructors & destructor
| Field3DOutputFileHDF5 ()
virtual | ~Field3DOutputFileHDF5 ()
Writing layer to disk
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 | writeVectorLayer (const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
| Writes a vector 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 &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.
Public Member Functions inherited from Field3DFileHDF5Base
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 FileHDF5 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.
| Field3DFileHDF5Base ()
virtual | ~Field3DFileHDF5Base ()=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.
FileHDF5::Partition::Ptr | getPartition (const std::string &partitionName) const
| Returns a pointer to the given partition.
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.
void | addGroupMembership (const GroupMembershipMap &groupMembers)
| Add to the group membership.
void | printHierarchy () const

## Private Member Functions

template<class Data_T>
bool | writeLayer (const std::string &partitionName, const std::string &layerName, bool isVectorLayer, typename Field< Data_T >::Ptr layer)
| Performs the actual writing of the layer to disk.
bool | writeMapping (hid_t partitionLocation, FieldMapping::Ptr mapping)
| Writes the mapping to the given hdf5 node. Mappings are assumed to be light-weight enough to be stored as plain attributes under a group.
bool | writeMetadata (hid_t metadataGroup)
| Writes metadata for this file.
bool | writeMetadata (hid_t metadataGroup, FieldBase::Ptr layer)
| Writes metadata for this layer.

## Friends

class | Field3DInputFile
class | Field3DOutputFile

## Additional Inherited Members

Protected Types inherited from Field3DFileHDF5Base
typedef std::map< std::string, int > | PartitionCountMap
typedef std::vector< FileHDF5::Partition::Ptr > | PartitionList
Protected Member Functions inherited from Field3DFileHDF5Base
void | closeInternal ()
| Closes the file if open.
FileHDF5::Partition::Ptr | partition (const std::string &partitionName)
| Returns a pointer to the given partition.
FileHDF5::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.
Protected Attributes inherited from Field3DFileHDF5Base
hid_t | m_file
| The hdf5 id of the current file. Will be -1 if no file is open.
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 ...".
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) files.

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

Note
  We distinguish between scalar and vector layers even though both are templated. A scalarField<float> layer is interchangeable with a scalarField<double> (conceptually) but not with a scalar<V3f>, and thus not with vectorField<float>.

Definition at line 764 of file Field3DFileHDF5.h.

## Member Enumeration Documentation

## CreateMode

enum Field3DOutputFileHDF5::CreateMode

Enumerator
OverwriteMode |
FailOnExisting |

Definition at line 773 of file Field3DFileHDF5.h.

{
OverwriteMode,
FailOnExisting
};
Field3DOutputFileHDF5::OverwriteMode
@ OverwriteMode
Definition Field3DFileHDF5.h:774
Field3DOutputFileHDF5::FailOnExisting
@ FailOnExisting
Definition Field3DFileHDF5.h:775

## Constructor & Destructor Documentation

## Field3DOutputFileHDF5()

Field3DOutputFileHDF5::Field3DOutputFileHDF5 | ( |  | ) |

Definition at line 1223 of file Field3DFileHDF5.cpp.

{
// Empty
}

## ~Field3DOutputFileHDF5()

Field3DOutputFileHDF5::~Field3DOutputFileHDF5 | ( |  | ) |

virtual

Definition at line 1230 of file Field3DFileHDF5.cpp.

{
}

## Member Function Documentation

## writeScalarLayer() [1/3]

template<class Data_T>

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

inline

Writes a scalar layer to the "Default" partition.

Definition at line 795 of file Field3DFileHDF5.h.

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

References writeScalarLayer().

Referenced by writeScalarLayer(), and writeScalarLayer().

## writeVectorLayer() [1/3]

template<class Data_T>

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

inline

Writes a vector layer to the "Default" partition.

Definition at line 801 of file Field3DFileHDF5.h.

{ return writeVectorLayer<Data_T>(layerName, std::string("default"), layer); }
Field3DOutputFileHDF5::writeVectorLayer
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a vector layer to the "Default" partition.
Definition Field3DFileHDF5.h:801

References FIELD3D_VEC3_T, and writeVectorLayer().

Referenced by writeVectorLayer(), and writeVectorLayer().

## writeScalarLayer() [2/3]

template<class Data_T>

bool Field3DOutputFileHDF5::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.

Definition at line 1579 of file Field3DFileHDF5.h.

{
return writeLayer<Data_T>(partitionName, layerName, false, field);
}
Field3DOutputFileHDF5::writeLayer
bool writeLayer(const std::string &partitionName, const std::string &layerName, bool isVectorLayer, typename Field< Data_T >::Ptr layer)
Performs the actual writing of the layer to disk.
Definition Field3DFileHDF5.h:1447

References writeLayer().

## writeScalarLayer() [3/3]

template<class Data_T>

bool Field3DOutputFileHDF5::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.

Definition at line 1590 of file Field3DFileHDF5.h.

{
if (layer->name.size() == 0) {
Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeScalarLayer: "
"Tried to write a scalar layer with no name");
return false;
}
if (layer->attribute.size() == 0) {
Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeScalarLayer: "
"Tried to write a scalar layer with no attribute name");
return false;
}
return writeScalarLayer<Data_T>(layer->name, layer->attribute, layer);
}
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 FieldBase::attribute, FieldBase::name, Msg::print(), Msg::SevWarning, and writeScalarLayer().

## writeVectorLayer() [2/3]

template<class Data_T>

bool Field3DOutputFileHDF5::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.

Definition at line 1609 of file Field3DFileHDF5.h.

{
return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName,
true, field);
}

References FIELD3D_VEC3_T, and writeLayer().

## writeVectorLayer() [3/3]

template<class Data_T>

bool Field3DOutputFileHDF5::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.

Definition at line 1622 of file Field3DFileHDF5.h.

{
if (layer->name.size() == 0) {
Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeVectorLayer: "
"Tried to write a vector layer with no name");
return false;
}
if (layer->attribute.size() == 0) {
Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeVectorLayer: "
"Tried to write a vector layer with no attribute name");
return false;
}
return writeVectorLayer<Data_T>(layer->name, layer->attribute, layer);
}

References FieldBase::attribute, FIELD3D_VEC3_T, FieldBase::name, Msg::print(), Msg::SevWarning, and writeVectorLayer().

## create()

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

Creates a .f3d file on disk.

Todo
  If the file can't be created hdf5 spits out an ugly error msg, we should make sure that doesn't happen.

Definition at line 1239 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
closeInternal();
bool success = true;
try {
hid_t faid = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_libver_bounds(faid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
// Create new file
switch (cm) {
case OverwriteMode:
m_file = H5Fcreate(filename.c_str(),
H5F_ACC_TRUNC, H5P_DEFAULT, faid);
break;
case FailOnExisting:
m_file = H5Fcreate(filename.c_str(),
H5F_ACC_EXCL, H5P_DEFAULT, faid);
break;
}
// Check that file was created
if (m_file < 0)
throw ErrorCreatingFileException(filename);
// Create a version attribute on the root node
if (!writeAttribute(m_file, k_versionAttrName, 3,
k_currentFileVersion[0])) {
Msg::print(Msg::SevWarning, "Adding version number.");
closeInternal();
return false;
}
}
catch (ErrorCreatingFileException &e) {
Msg::print(Msg::SevWarning, "Couldn't create file: " + string(e.what()) );
success = false;
}
catch (WriteAttributeException &e) {
Msg::print(Msg::SevWarning, "In file : " + filename +
" - Couldn't add attribute " + string(e.what()) );
success = false;
}
catch (...) {
Msg::print(Msg::SevWarning,
"Unknown error when creating file: " + filename );
success = false;
}
return success;
}
g_hdf5Mutex
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition Hdf5Util.cpp:67
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition Hdf5Util.h:78
Field3DFileHDF5Base::m_file
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition Field3DFileHDF5.h:390
Field3DFileHDF5Base::closeInternal
void closeInternal()
Closes the file if open.
Definition Field3DFileHDF5.cpp:505
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.

References Field3DFileHDF5Base::closeInternal(), FailOnExisting, g_hdf5Mutex, Field3DFileHDF5Base::m_file, OverwriteMode, Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

## writeGlobalMetadata()

bool Field3DOutputFileHDF5::writeGlobalMetadata | ( |  | ) |

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

Definition at line 1483 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
// Add metadata group and write it out
H5ScopedGcreate metadataGroup(m_file, "field3d_global_metadata");
if (metadataGroup.id() < 0) {
Msg::print(Msg::SevWarning, "Error creating group: file metadata");
return false;
}
if (!writeMetadata(metadataGroup.id())) {
Msg::print(Msg::SevWarning, "Error writing file metadata.");
return false;
}
return true;
}
Field3DOutputFileHDF5::writeMetadata
bool writeMetadata(hid_t metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Definition Field3DFileHDF5.cpp:1320

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, Msg::print(), Msg::SevWarning, and writeMetadata().

## writeGroupMembership()

bool Field3DOutputFileHDF5::writeGroupMembership | ( |  | ) |

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

Definition at line 1504 of file Field3DFileHDF5.cpp.

{
using namespace std;
using namespace Hdf5Util;
GlobalLock lock(g_hdf5Mutex);
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;
}
}
return true;
}
Field3DFileHDF5Base::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 Field3DFileHDF5.h:403

References g_hdf5Mutex, Field3DFileHDF5Base::m_file, Field3DFileHDF5Base::m_groupMembership, Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

## incrementPartitionName()

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

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

Definition at line 1546 of file Field3DFileHDF5.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);
}
Field3DFileHDF5Base::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 Field3DFileHDF5.cpp:542
Field3DFileHDF5Base::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition Field3DFileHDF5.cpp:373
Field3DFileHDF5Base::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 Field3DFileHDF5.h:398

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

Referenced by writeLayer().

## createNewPartition()

template<class Data_T>

FileHDF5::Partition::Ptr Field3DOutputFileHDF5::createNewPartition | ( | const std::string & | partitionName,
|  | const std::string & | layerName,
|  | typename Field< Data_T >::Ptr | field )

create newPartition given the input config

Todo
  We should probably remove the group on disk if we can't write the mapping

Definition at line 1381 of file Field3DFileHDF5.h.

{
using namespace Hdf5Util;
using namespace Exc;
GlobalLock lock(g_hdf5Mutex);
FileHDF5::Partition::Ptr newPart(new FileHDF5::Partition);
newPart->name = partitionName;
H5ScopedGcreate partGroup(m_file, newPart->name.c_str());
if (partGroup.id() < 0) {
Msg::print(Msg::SevWarning,
"Error creating partition: " + newPart->name);
return FileHDF5::Partition::Ptr();
}
m_partitions.push_back(newPart);
// Pick up new pointer
FileHDF5::Partition::Ptr part = partition(partitionName);
// Add mapping group to the partition
try {
if (!writeMapping(partGroup.id(), field->mapping())) {
Msg::print(Msg::SevWarning,
"writeMapping returned false for an unknown reason ");
return FileHDF5::Partition::Ptr();
}
}
catch (WriteMappingException &e) {
Msg::print(Msg::SevWarning, "Couldn't write mapping for partition: "
+ partitionName);
return FileHDF5::Partition::Ptr();
}
catch (...) {
Msg::print(Msg::SevWarning,
"Unknown error when writing mapping for partition: "
+ partitionName);
return FileHDF5::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
if (!writeAttribute(partGroup.id(), "is_field3d_partition", "1")) {
Msg::print(Msg::SevWarning, "Adding partition string.");
return FileHDF5::Partition::Ptr();
}
return part;
}
Field3DFileHDF5Base::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition Field3DFileHDF5.h:392
Field3DFileHDF5Base::partition
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DOutputFileHDF5::writeMapping
bool writeMapping(hid_t partitionLocation, FieldMapping::Ptr mapping)
Writes the mapping to the given hdf5 node. Mappings are assumed to be light-weight enough to be store...
Definition Field3DFileHDF5.cpp:1297
FileHDF5::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition Field3DFileHDF5.h:152

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, Field3DFileHDF5Base::m_partitions, FieldRes::mapping(), Field3DFileHDF5Base::partition(), Msg::print(), Msg::SevWarning, Hdf5Util::writeAttribute(), and writeMapping().

Referenced by writeLayer().

## writeMapping()

bool Field3DOutputFileHDF5::writeMapping | ( | hid_t | partitionLocation,
|  | FieldMapping::Ptr | mapping )

private

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

Definition at line 1297 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
try {
// Make a group under the partition to store the mapping data
H5ScopedGcreate mappingGroup(partitionGroup, k_mappingStr);
if (mappingGroup.id() < 0)
throw CreateGroupException(k_mappingStr);
// Let FieldMappingIO handle the rest
if (!writeFieldMapping(mappingGroup.id(), mapping))
throw WriteMappingException(k_mappingStr);
}
catch (CreateGroupException &e) {
Msg::print(Msg::SevWarning, "Couldn't create group: " + string(e.what()) );
throw WriteMappingException(k_mappingStr);
}
return true;
}
writeFieldMapping
FIELD3D_API bool writeFieldMapping(hid_t mappingGroup, FieldMapping::Ptr mapping)
This function creates a FieldMappingIO instance based on mapping->className() which then writes Field...
Definition Field3DFileHDF5.cpp:1645

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Msg::print(), Msg::SevWarning, and writeFieldMapping().

Referenced by createNewPartition().

## writeLayer()

template<class Data_T>

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

private

Performs the actual writing of the layer to disk.

Definition at line 1447 of file Field3DFileHDF5.h.

{
using namespace std;
using namespace Exc;
using namespace Hdf5Util;
GlobalLock lock(g_hdf5Mutex);
if (!field) {
Msg::print(Msg::SevWarning,
"Called writeLayer with null pointer. Ignoring...");
return false;
}
if (m_file < 0) {
Msg::print(Msg::SevWarning,
"Attempting to write layer without opening file first. ");
return false;
}
string partitionName = intPartitionName(userPartitionName, layerName, field);
// See if the partition already exists or if we need to make it ---
FileHDF5::Partition::Ptr part = partition(partitionName);
if (!part) {
part = createNewPartition<Data_T>(partitionName,layerName,field);
if (!part)
return false;
} else {
if (!field->mapping()) {
Msg::print(Msg::SevWarning,
"Couldn't add layer \"" + layerName + "\" to partition \""
+ partitionName + "\" because the layer's mapping is null.");
return false;
}
// If the partition already existed, we need to make sure that the layer
// doesn't also exist
if (!isVectorLayer) {
if (part->scalarLayer(layerName)) {
//need to create a new partition and then add the layer to that
std::string newPartitionName = incrementPartitionName(partitionName);
part = createNewPartition<Data_T>(newPartitionName,layerName,field);
if (!part)
return false;
}
} else {
if (part->vectorLayer(layerName)) {
//need to create a new partition and then add the layer to that
std::string newPartitionName = incrementPartitionName(partitionName);
part = createNewPartition<Data_T>(newPartitionName,layerName,field);
if (!part)
return false;
}
}
}
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
H5ScopedGopen partGroup(m_file, part->name.c_str(), H5P_DEFAULT);
// Build a Layer object ---
FileHDF5::Layer layer;
layer.name = layerName;
layer.parent = partitionName;
// Add Layer to file ---
H5ScopedGcreate layerGroup(partGroup.id(), layerName.c_str(),
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if (layerGroup.id() < 0) {
Msg::print(Msg::SevWarning, "Error creating layer: " + layerName);
return false;
}
// Tag as layer
if (!writeAttribute(layerGroup.id(), "class_type", "field3d_layer")) {
Msg::print(Msg::SevWarning, "Error adding layer string.");
return false;
}
// Add metadata group and write it out
H5ScopedGcreate metadataGroup(layerGroup.id(), "metadata");
if (metadataGroup.id() < 0) {
Msg::print(Msg::SevWarning, "Error creating group: metadata");
return false;
}
if (!writeMetadata(metadataGroup.id(), field)) {
Msg::print(Msg::SevWarning, "Error writing metadata.");
return false;
}
if (!writeField(layerGroup.id(), field)) {
Msg::print(Msg::SevWarning, "Error writing layer: " + layer.name);
return false;
}
// Add layer to partition ---
if (isVectorLayer)
part->addVectorLayer(layer);
else
part->addScalarLayer(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
Field3DFileHDF5Base::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 Field3DFileHDF5.cpp:316
Field3DOutputFileHDF5::createNewPartition
FileHDF5::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr field)
create newPartition given the input config
Definition Field3DFileHDF5.h:1381
Field3DOutputFileHDF5::incrementPartitionName
std::string incrementPartitionName(std::string &pname)
increment the partition or make it zero if there's not an integer suffix
Definition Field3DFileHDF5.cpp:1546
FileHDF5::Layer::parent
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition Field3DFileHDF5.h:127
FileHDF5::Layer::name
std::string name
The name of the layer (always available).
Definition Field3DFileHDF5.h:124

References createNewPartition(), g_hdf5Mutex, Hdf5Util::H5Base::id(), incrementPartitionName(), Field3DFileHDF5Base::intPartitionName(), Field3DFileHDF5Base::m_file, FieldRes::mapping(), FileHDF5::Layer::name, FileHDF5::Layer::parent, Field3DFileHDF5Base::partition(), Msg::print(), Msg::SevWarning, Hdf5Util::writeAttribute(), writeField(), and writeMetadata().

Referenced by writeScalarLayer(), and writeVectorLayer().

## writeMetadata() [1/2]

bool Field3DOutputFileHDF5::writeMetadata | ( | hid_t | metadataGroup,
|  | FieldBase::Ptr | layer )

private

Writes metadata for this layer.

Definition at line 1320 of file Field3DFileHDF5.cpp.

{
using namespace Hdf5Util;
{
FieldMetadata::StrMetadata::const_iterator i =
field->metadata().strMetadata().begin();
FieldMetadata::StrMetadata::const_iterator end =
field->metadata().strMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, i->second))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first );
return false;
}
}
}
{
FieldMetadata::IntMetadata::const_iterator i =
field->metadata().intMetadata().begin();
FieldMetadata::IntMetadata::const_iterator end =
field->metadata().intMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 1, i->second))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
{
FieldMetadata::FloatMetadata::const_iterator i =
field->metadata().floatMetadata().begin();
FieldMetadata::FloatMetadata::const_iterator end =
field->metadata().floatMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 1, i->second))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
{
FieldMetadata::VecIntMetadata::const_iterator i =
field->metadata().vecIntMetadata().begin();
FieldMetadata::VecIntMetadata::const_iterator end =
field->metadata().vecIntMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
{
FieldMetadata::VecFloatMetadata::const_iterator i =
field->metadata().vecFloatMetadata().begin();
FieldMetadata::VecFloatMetadata::const_iterator end =
field->metadata().vecFloatMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
return true;
}

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

Referenced by writeGlobalMetadata(), and writeLayer().

## writeMetadata() [2/2]

bool Field3DOutputFileHDF5::writeMetadata | ( | hid_t | metadataGroup | ) |

private

Writes metadata for this file.

Definition at line 1401 of file Field3DFileHDF5.cpp.

{
using namespace Hdf5Util;
{
FieldMetadata::StrMetadata::const_iterator i =
metadata().strMetadata().begin();
FieldMetadata::StrMetadata::const_iterator end =
metadata().strMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, i->second))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first );
return false;
}
}
}
{
FieldMetadata::IntMetadata::const_iterator i =
metadata().intMetadata().begin();
FieldMetadata::IntMetadata::const_iterator end =
metadata().intMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 1, i->second))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
{
FieldMetadata::FloatMetadata::const_iterator i =
metadata().floatMetadata().begin();
FieldMetadata::FloatMetadata::const_iterator end =
metadata().floatMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 1, i->second))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
{
FieldMetadata::VecIntMetadata::const_iterator i =
metadata().vecIntMetadata().begin();
FieldMetadata::VecIntMetadata::const_iterator end =
metadata().vecIntMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
{
FieldMetadata::VecFloatMetadata::const_iterator i =
metadata().vecFloatMetadata().begin();
FieldMetadata::VecFloatMetadata::const_iterator end =
metadata().vecFloatMetadata().end();
for (; i != end; ++i) {
if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
{
Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
return false;
}
}
}
return true;
}
Field3DFileHDF5Base::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field3DFileHDF5.h:321
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(), Field3DFileHDF5Base::metadata(), Msg::print(), Msg::SevWarning, FieldMetadata::strMetadata(), FieldMetadata::vecFloatMetadata(), FieldMetadata::vecIntMetadata(), and Hdf5Util::writeAttribute().

## Friends And Related Symbol Documentation

## Field3DInputFile

friend class Field3DInputFile

friend

Definition at line 768 of file Field3DFileHDF5.h.

References Field3DInputFile.

Referenced by Field3DInputFile.

## Field3DOutputFile

friend class Field3DOutputFile

friend

Definition at line 769 of file Field3DFileHDF5.h.

References Field3DOutputFile.

Referenced by Field3DOutputFile.

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

- export/Field3DFileHDF5.h
- src/Field3DFileHDF5.cpp