Field3DInputFileHDF5 Class Reference
File I/O

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

`#include <Field3DFileHDF5.h>`

Inheritance diagram for Field3DInputFileHDF5:

## Public Member Functions

bool | open (const std::string &filename)
| Opens the given file.
bool | readGroupMembership (GroupMembershipMap &gpMembershipMap)
| Read the group membership for the partitions.
Constructors & destructor
| Field3DInputFileHDF5 ()
virtual | ~Field3DInputFileHDF5 ()
Reading layers from disk
template<class Data_T>
Field< Data_T >::Vec | readScalarLayers (const std::string &layerName=std::string("")) const
| Retrieves all the layers of scalar type and maintains their on-disk data types.
template<class Data_T>
Field< Data_T >::Vec | readScalarLayers (const std::string &partitionName, const std::string &layerName) const
| This one allows the allows the partitionName to be passed in.
template<class Data_T>
Field< FIELD3D_VEC3_T< Data_T > >::Vec | readVectorLayers (const std::string &layerName=std::string("")) const
| Retrieves all the layers of vector type and maintains their on-disk data types.
template<class Data_T>
Field< FIELD3D_VEC3_T< Data_T > >::Vec | readVectorLayers (const std::string &partitionName, const std::string &layerName) const
| This version allows you to pass in the partition name.
template<template< typename T > class Field_T, class Data_T>
Field_T< Data_T >::Vec | readScalarLayersAs (const std::string &layerName=std::string("")) const
| Retrieves all layers for all partitions. Converts it to the given template type if needed.
template<template< typename T > class Field_T, class Data_T>
Field_T< Data_T >::Vec | readScalarLayersAs (const std::string &partitionName, const std::string &layerName) const
| Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed.
template<template< typename T > class Field_T, class Data_T>
Field_T< FIELD3D_VEC3_T< Data_T > >::Vec | readVectorLayersAs (const std::string &layerName=std::string("")) const
| Retrieves a layers for all partitions. Converts it to the given template type if needed.
template<template< typename T > class Field_T, class Data_T>
Field_T< FIELD3D_VEC3_T< Data_T > >::Vec | readVectorLayersAs (const std::string &partitionName, const std::string &layerName) const
| Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed.
Reading proxy data from disk
template<class Data_T>
EmptyField< Data_T >::Vec | readProxyLayer (const std::string &partitionName, const std::string &layerName, bool isVectorLayer) const
| Retrieves a proxy version (EmptyField) of each layer .
template<class Data_T>
EmptyField< Data_T >::Ptr | readProxyLayer (hid_t location, const std::string &name, const std::string &attribute, FieldMapping::Ptr mapping) const
| Retrieves a proxy version (EmptyField) from a given HDF5 location.
template<class Data_T>
EmptyField< Data_T >::Vec | readProxyScalarLayers (const std::string &name=std::string("")) const
| Retrieves a proxy version (EmptyField) of each scalar layer.
template<class Data_T>
EmptyField< Data_T >::Vec | readProxyVectorLayers (const std::string &name=std::string("")) const
| Retrieves a proxy version (EmptyField) of each vector layer.
Internal utility methods
herr_t | parsePartition (hid_t loc_id, const std::string partitionName)
| Gets called from parsePartitions. Not intended for any other use.
herr_t | parseLayer (hid_t loc_id, const std::string &partitionName, const std::string &layerName)
| Gets called from parsePartitions. Not intended for any other use.
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>
Field< Data_T >::Ptr | readLayer (const std::string &intPartitionName, const std::string &layerName, bool isVectorLayer) const
| This call does the actual reading of a layer. Notice that it expects a unique -internal- partition name.
bool | readMetadata (hid_t metadata_id)
| Read global metadata for this file.
bool | readMetadata (hid_t metadata_id, FieldBase::Ptr field) const
| Read metadata for this layer.
bool | readPartitionAndLayerInfo ()
| Sets up all the partitions and layers, but does not load any data.
template<class Data_T>
Field< Data_T >::Ptr | readScalarLayer (const std::string &intPartitionName, const std::string &layerName) const
| Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.
template<class Data_T>
Field< FIELD3D_VEC3_T< Data_T > >::Ptr | readVectorLayer (const std::string &intPartitionName, const std::string &layerName) const
| Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.

## Private Attributes

std::string | m_filename
| Filename, only to be set by open().

## Friends

class | Field3DInputFile
class | Field3DOutputFile

## Additional Inherited Members

Public Types inherited from Field3DFileHDF5Base
typedef std::map< std::string, std::string > | GroupMembershipMap
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 reading 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 437 of file Field3DFileHDF5.h.

## Constructor & Destructor Documentation

## Field3DInputFileHDF5()

Field3DInputFileHDF5::Field3DInputFileHDF5 | ( |  | ) |

Definition at line 572 of file Field3DFileHDF5.cpp.

{
// Empty
}

Referenced by Field3DOutputFile.

## ~Field3DInputFileHDF5()

Field3DInputFileHDF5::~Field3DInputFileHDF5 | ( |  | ) |

virtual

Definition at line 579 of file Field3DFileHDF5.cpp.

{
clear();
}
Field3DFileHDF5Base::clear
void clear()
Clear the data structures and close the file.
Definition Field3DFileHDF5.cpp:487

References Field3DFileHDF5Base::clear().

## Member Function Documentation

## readScalarLayers() [1/2]

template<class Data_T>

Field< Data_T >::Vec Field3DInputFileHDF5::readScalarLayers | ( | const std::string & | layerName = std::string("") | ) | const

Retrieves all the layers of scalar type and maintains their on-disk data types.

Parameters

  layerName | If a string is passed in, only layers of that name will be read from disk.

Definition at line 910 of file Field3DFileHDF5.h.

{
using namespace std;
typedef typename Field<Data_T>::Ptr FieldPtr;
typedef typename Field<Data_T>::Vec FieldList;
FieldList ret;
std::vector<std::string> parts;
getIntPartitionNames(parts);
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
std::vector<std::string> layers;
getIntScalarLayerNames(layers, *p);
for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
// Only read if it matches the name
if ((name.length() == 0) || (*l == name)) {
FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
if (mf) {
ret.push_back(mf);
}
}
}
}
return ret;
}
Field3DFileHDF5Base::getIntScalarLayerNames
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 ...
Definition Field3DFileHDF5.cpp:452
Field3DFileHDF5Base::getIntPartitionNames
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
Definition Field3DFileHDF5.cpp:439
Field3DInputFileHDF5::readScalarLayer
Field< Data_T >::Ptr readScalarLayer(const std::string &intPartitionName, const std::string &layerName) const
Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.
Definition Field3DFileHDF5.h:1359
Field::Vec
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition Field.h:403
Field::Ptr
boost::intrusive_ptr< Field > Ptr
Definition Field.h:395

References Field3DFileHDF5Base::getIntPartitionNames(), Field3DFileHDF5Base::getIntScalarLayerNames(), and readScalarLayer().

Referenced by Field3DOutputFile, readScalarLayersAs(), and readScalarLayersAs().

## readScalarLayers() [2/2]

template<class Data_T>

Field< Data_T >::Vec Field3DInputFileHDF5::readScalarLayers | ( | const std::string & | partitionName,
|  | const std::string & | layerName ) const

This one allows the allows the partitionName to be passed in.

Definition at line 942 of file Field3DFileHDF5.h.

{
using namespace std;
typedef typename Field<Data_T>::Ptr FieldPtr;
typedef typename Field<Data_T>::Vec FieldList;
FieldList ret;
if ((layerName.length() == 0) || (partitionName.length() == 0))
return ret;
std::vector<std::string> parts;
getIntPartitionNames(parts);
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
std::vector<std::string> layers;
getIntScalarLayerNames(layers, *p);
if (removeUniqueId(*p) == partitionName) {
for (vector<string>::iterator l = layers.begin();
l != layers.end(); ++l) {
// Only read if it matches the name
if (*l == layerName) {
FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
if (mf)
ret.push_back(mf);
}
}
}
}
return ret;
}
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

References Field3DFileHDF5Base::getIntPartitionNames(), Field3DFileHDF5Base::getIntScalarLayerNames(), readScalarLayer(), and Field3DFileHDF5Base::removeUniqueId().

## readVectorLayers() [1/2]

template<class Data_T>

Field< FIELD3D_VEC3_T< Data_T > >::Vec Field3DInputFileHDF5::readVectorLayers | ( | const std::string & | layerName = std::string("") | ) | const

Retrieves all the layers of vector type and maintains their on-disk data types.

Parameters

  layerName | If a string is passed in, only layers of that name will be read from disk.

Definition at line 981 of file Field3DFileHDF5.h.

{
using namespace std;
typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
FieldList ret;
std::vector<std::string> parts;
getIntPartitionNames(parts);
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
std::vector<std::string> layers;
getIntVectorLayerNames(layers, *p);
for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
// Only read if it matches the name
if ((name.length() == 0) || (*l == name)) {
FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
if (mf)
ret.push_back(mf);
}
}
}
return ret;
}
Field3DFileHDF5Base::getIntVectorLayerNames
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 ...
Definition Field3DFileHDF5.cpp:470
Field3DInputFileHDF5::readVectorLayer
Field< FIELD3D_VEC3_T< Data_T > >::Ptr readVectorLayer(const std::string &intPartitionName, const std::string &layerName) const
Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.
Definition Field3DFileHDF5.h:1369

References Field3DFileHDF5Base::getIntPartitionNames(), Field3DFileHDF5Base::getIntVectorLayerNames(), and readVectorLayer().

Referenced by Field3DOutputFile, readVectorLayersAs(), and readVectorLayersAs().

## readVectorLayers() [2/2]

template<class Data_T>

Field< FIELD3D_VEC3_T< Data_T > >::Vec Field3DInputFileHDF5::readVectorLayers | ( | const std::string & | partitionName,
|  | const std::string & | layerName ) const

This version allows you to pass in the partition name.

Definition at line 1013 of file Field3DFileHDF5.h.

{
using namespace std;
typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
FieldList ret;
if ((layerName.length() == 0) || (partitionName.length() == 0))
return ret;
std::vector<std::string> parts;
getIntPartitionNames(parts);
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
std::vector<std::string> layers;
getIntVectorLayerNames(layers, *p);
if (removeUniqueId(*p) == partitionName) {
for (vector<string>::iterator l = layers.begin();
l != layers.end(); ++l) {
// Only read if it matches the name
if (*l == layerName) {
FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
if (mf)
ret.push_back(mf);
}
}
}
}
return ret;
}

References Field3DFileHDF5Base::getIntPartitionNames(), Field3DFileHDF5Base::getIntVectorLayerNames(), readVectorLayer(), and Field3DFileHDF5Base::removeUniqueId().

## readScalarLayersAs() [1/2]

template<template< typename T > class Field_T, class Data_T>

Field_T< Data_T >::Vec Field3DInputFileHDF5::readScalarLayersAs | ( | const std::string & | layerName = std::string("") | ) | const

inline

Retrieves all layers for all partitions. Converts it to the given template type if needed.

Definition at line 491 of file Field3DFileHDF5.h.

{
typedef typename Field<Data_T>::Vec FieldList;
typedef typename Field_T<Data_T>::Vec TypedFieldList;
// First, read the layers as-is
FieldList originals;
originals = readScalarLayers<Data_T>(layerName);
// Loop over fields, converting if needed
TypedFieldList output;
typename FieldList::iterator i = originals.begin();
for (; i != originals.end(); ++i) {
typename Field_T<Data_T>::Ptr targetField;
targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
if (targetField) {
output.push_back(targetField);
} else {
typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
newTarget->name = (*i)->name;
newTarget->attribute = (*i)->attribute;
newTarget->copyMetadata(**i);
newTarget->copyFrom(*i);
output.push_back(newTarget);
}
}
return output;
}
Field3DInputFileHDF5::readScalarLayers
Field< Data_T >::Vec readScalarLayers(const std::string &layerName=std::string("")) const
Retrieves all the layers of scalar type and maintains their on-disk data types.
Definition Field3DFileHDF5.h:910
field_dynamic_cast
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition RefCount.h:256

References field_dynamic_cast(), and readScalarLayers().

## readScalarLayersAs() [2/2]

template<template< typename T > class Field_T, class Data_T>

Field_T< Data_T >::Vec Field3DInputFileHDF5::readScalarLayersAs | ( | const std::string & | partitionName,
|  | const std::string & | layerName ) const

inline

Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed.

Definition at line 525 of file Field3DFileHDF5.h.

{
typedef typename Field<Data_T>::Vec FieldList;
typedef typename Field_T<Data_T>::Vec TypedFieldList;
// First, read the layers as-is
FieldList originals;
originals = readScalarLayers<Data_T>(partitionName, layerName);
// Loop over fields, converting if needed
TypedFieldList output;
typename FieldList::iterator i = originals.begin();
for (; i != originals.end(); ++i) {
typename Field_T<Data_T>::Ptr targetField;
targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
if (targetField) {
output.push_back(targetField);
} else {
typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
newTarget->name = (*i)->name;
newTarget->attribute = (*i)->attribute;
newTarget->copyMetadata(**i);
newTarget->copyFrom(*i);
output.push_back(newTarget);
}
}
return output;
}

References field_dynamic_cast(), and readScalarLayers().

## readVectorLayersAs() [1/2]

template<template< typename T > class Field_T, class Data_T>

Field_T< FIELD3D_VEC3_T< Data_T > >::Vec Field3DInputFileHDF5::readVectorLayersAs | ( | const std::string & | layerName = std::string("") | ) | const

inline

Retrieves a layers for all partitions. Converts it to the given template type if needed.

Definition at line 560 of file Field3DFileHDF5.h.

{
typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec TypedFieldList;
// First, read the layers as-is
FieldList originals;
originals = readVectorLayers<Data_T>(layerName);
// Loop over fields, converting if needed
TypedFieldList output;
typename FieldList::iterator i = originals.begin();
for (; i != originals.end(); ++i) {
typename TypedVField::Ptr targetField;
targetField = field_dynamic_cast<TypedVField>(*i);
if (targetField) {
output.push_back(targetField);
} else {
typename TypedVField::Ptr newTarget(new TypedVField);
newTarget->name = (*i)->name;
newTarget->attribute = (*i)->attribute;
newTarget->copyMetadata(**i);
newTarget->copyFrom(*i);
output.push_back(newTarget);
}
}
return output;
}
Field3DInputFileHDF5::readVectorLayers
Field< FIELD3D_VEC3_T< Data_T > >::Vec readVectorLayers(const std::string &layerName=std::string("")) const
Retrieves all the layers of vector type and maintains their on-disk data types.
Definition Field3DFileHDF5.h:981

References field_dynamic_cast(), and readVectorLayers().

## readVectorLayersAs() [2/2]

template<template< typename T > class Field_T, class Data_T>

Field_T< FIELD3D_VEC3_T< Data_T > >::Vec Field3DInputFileHDF5::readVectorLayersAs | ( | const std::string & | partitionName,
|  | const std::string & | layerName ) const

inline

Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed.

Definition at line 595 of file Field3DFileHDF5.h.

{
typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec TypedFieldList;
// First, read the layers as-is
FieldList originals;
originals = readVectorLayers<Data_T>(partitionName, layerName);
// Loop over fields, converting if needed
TypedFieldList output;
typename FieldList::iterator i = originals.begin();
for (; i != originals.end(); ++i) {
typename TypedVField::Ptr targetField;
targetField = field_dynamic_cast<TypedVField>(*i);
if (targetField) {
output.push_back(targetField);
} else {
typename TypedVField::Ptr newTarget(new TypedVField);
newTarget->name = (*i)->name;
newTarget->attribute = (*i)->attribute;
newTarget->copyMetadata(**i);
newTarget->copyFrom(*i);
output.push_back(newTarget);
}
}
return output;
}

References field_dynamic_cast(), and readVectorLayers().

## readProxyLayer() [1/2]

template<class Data_T>

EmptyField< Data_T >::Vec Field3DInputFileHDF5::readProxyLayer | ( | const std::string & | partitionName,
|  | const std::string & | layerName,
|  | bool | isVectorLayer ) const

Retrieves a proxy version (EmptyField) of each layer .

Note
  Although the call is templated, all fields are read, regardless of bit depth.

Parameters

  name | If a string is passed in, only layers of that name will be read from disk.

Definition at line 1157 of file Field3DFileHDF5.h.

{
using namespace boost;
using namespace std;
using namespace Hdf5Util;
GlobalLock lock(g_hdf5Mutex);
// Instantiate a null pointer for easier code reading
typename EmptyField<Data_T>::Vec emptyList, output;
if ((layerName.length() == 0) || (partitionName.length() == 0))
return emptyList;
std::vector<std::string> parts, layers;
getIntPartitionNames(parts);
bool foundPartition = false;
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
if (removeUniqueId(*p) == partitionName) {
foundPartition = true;
if (isVectorLayer) {
getIntVectorLayerNames(layers, *p);
} else {
getIntScalarLayerNames(layers, *p);
}
for (vector<string>::iterator l = layers.begin();
l != layers.end(); ++l) {
if (*l == layerName) {
// Find the partition
FileHDF5::Partition::Ptr part = partition(*p);
if (!part) {
Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
return emptyList;
}
// Find the layer
const FileHDF5::Layer *layer;
if (isVectorLayer)
layer = part->vectorLayer(layerName);
else
layer = part->scalarLayer(layerName);
if (!layer) {
Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
return emptyList;
}
// Open the layer group
string layerPath = layer->parent + "/" + layer->name;
H5ScopedGopen layerGroup(m_file, layerPath.c_str());
if (layerGroup.id() < 0) {
Msg::print(Msg::SevWarning, "Couldn't find layer group "
+ layerName + " in .f3d file ");
return emptyList;
}
// Make the proxy representation
typename EmptyField<Data_T>::Ptr field =
readProxyLayer<Data_T>(layerGroup, partitionName, layerName,
part->mapping);
// Read MIPField's number of mip levels
int numLevels = 0;
H5ScopedGopen mipGroup(layerGroup, "mip_levels");
if (mipGroup.id() >= 0)
readAttribute(mipGroup, "levels", 1, numLevels);
field->metadata().setIntMetadata("mip_levels", numLevels);
// Add field to output
output.push_back(field);
}
}
}
}
if (!foundPartition) {
Msg::print(Msg::SevWarning, "Couldn't find partition: " + partitionName);
return emptyList;
}
return output;
}
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
EmptyField::Ptr
boost::intrusive_ptr< EmptyField > Ptr
Definition EmptyField.h:93
EmptyField::Vec
std::vector< Ptr > Vec
Definition EmptyField.h:94
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::partition
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DInputFileHDF5::readProxyLayer
EmptyField< Data_T >::Vec readProxyLayer(const std::string &partitionName, const std::string &layerName, bool isVectorLayer) const
Retrieves a proxy version (EmptyField) of each layer .
Definition Field3DFileHDF5.h:1157
FieldBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field.h:155
FieldMetadata::setIntMetadata
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.
Definition FieldMetadata.cpp:91
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
FileHDF5::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition Field3DFileHDF5.h:152
Hdf5Util::readAttribute
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
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 g_hdf5Mutex, Field3DFileHDF5Base::getIntPartitionNames(), Field3DFileHDF5Base::getIntScalarLayerNames(), Field3DFileHDF5Base::getIntVectorLayerNames(), Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, FieldBase::metadata(), FileHDF5::Layer::name, FileHDF5::Layer::parent, Field3DFileHDF5Base::partition(), Msg::print(), Hdf5Util::readAttribute(), readProxyLayer(), Field3DFileHDF5Base::removeUniqueId(), FieldMetadata::setIntMetadata(), and Msg::SevWarning.

Referenced by readProxyLayer(), readProxyScalarLayers(), and readProxyVectorLayers().

## readProxyLayer() [2/2]

template<class Data_T>

EmptyField< Data_T >::Ptr Field3DInputFileHDF5::readProxyLayer | ( | hid_t | location,
|  | const std::string & | name,
|  | const std::string & | attribute,
|  | FieldMapping::Ptr | mapping ) const

Retrieves a proxy version (EmptyField) from a given HDF5 location.

Note
  Although the call is templated, all fields are read, regardless of bit depth.

Parameters

  location | HDF5 file location

Definition at line 1245 of file Field3DFileHDF5.h.

{
using namespace boost;
using namespace std;
using namespace Hdf5Util;
typename EmptyField<Data_T>::Ptr null;
GlobalLock lock(g_hdf5Mutex);
// Read the extents and data window
Box3i extents, dataW;
if (!readAttribute(location, "extents", 6, extents.min.x)) {
return null;
}
if (!readAttribute(location, "data_window", 6, dataW.min.x)) {
return null;
}
// Construct the field and load the data
typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
field->setSize(extents, dataW);
// Read the metadata
H5ScopedGopen metadataGroup(location, "metadata");
if (metadataGroup.id() > 0) {
readMetadata(metadataGroup.id(), field);
}
// Set field properties
field->name = name;
field->attribute = attribute;
field->setMapping(mapping);
return field;
}
Box3i
Imath::Box3i Box3i
Definition SpiMathLib.h:77
Field3DInputFileHDF5::readMetadata
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
Definition Field3DFileHDF5.cpp:837

References FieldBase::attribute, g_hdf5Mutex, Hdf5Util::H5Base::id(), FieldBase::name, Hdf5Util::readAttribute(), readMetadata(), FieldRes::setMapping(), and ResizableField< Data_T >::setSize().

## readProxyScalarLayers()

template<class Data_T>

EmptyField< Data_T >::Vec Field3DInputFileHDF5::readProxyScalarLayers | ( | const std::string & | name = std::string("") | ) | const

Retrieves a proxy version (EmptyField) of each scalar layer.

Note
  Although the call is templated, all fields are read, regardless of bit depth.

Parameters

  name | If a string is passed in, only layers of that name will be read from disk.

Definition at line 1289 of file Field3DFileHDF5.h.

{
using namespace std;
typedef typename EmptyField<Data_T>::Ptr FieldPtr;
typedef std::vector<FieldPtr> FieldList;
FieldList ret;
std::vector<std::string> parts;
getPartitionNames(parts);
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
std::vector<std::string> layers;
getScalarLayerNames(layers, *p);
for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
// Only read if it matches the name
if ((name.length() == 0) || (*l == name)) {
FieldList f = readProxyLayer<Data_T>(*p, *l, false);
for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
if (*i) {
ret.push_back(*i);
}
}
}
}
}
return ret;
}
Field3DFileHDF5Base::getPartitionNames
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
Definition Field3DFileHDF5.cpp:386
Field3DFileHDF5Base::getScalarLayerNames
void getScalarLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the scalar layers in a given partition.
Definition Field3DFileHDF5.cpp:403

References Field3DFileHDF5Base::getPartitionNames(), Field3DFileHDF5Base::getScalarLayerNames(), and readProxyLayer().

## readProxyVectorLayers()

template<class Data_T>

EmptyField< Data_T >::Vec Field3DInputFileHDF5::readProxyVectorLayers | ( | const std::string & | name = std::string("") | ) | const

Retrieves a proxy version (EmptyField) of each vector layer.

Note
  Although the call is templated, all fields are read, regardless of bit depth.

Parameters

  name | If a string is passed in, only layers of that name will be read from disk.

Definition at line 1324 of file Field3DFileHDF5.h.

{
using namespace std;
typedef typename EmptyField<Data_T>::Ptr FieldPtr;
typedef std::vector<FieldPtr> FieldList;
FieldList ret;
std::vector<std::string> parts;
getPartitionNames(parts);
for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
std::vector<std::string> layers;
getVectorLayerNames(layers, *p);
for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
// Only read if it matches the name
if ((name.length() == 0) || (*l == name)) {
FieldList f = readProxyLayer<Data_T>(*p, *l, true);
for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
if (*i) {
ret.push_back(*i);
}
}
}
}
}
return ret;
}
Field3DFileHDF5Base::getVectorLayerNames
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.
Definition Field3DFileHDF5.cpp:421

References Field3DFileHDF5Base::getPartitionNames(), Field3DFileHDF5Base::getVectorLayerNames(), and readProxyLayer().

## open()

bool Field3DInputFileHDF5::open | ( | const std::string & | filename | ) |

Opens the given file.

Returns
  Whether successful

Definition at line 586 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
clear();
bool success = true;
// Record filename
m_filename = filename;
try {
string version;
// Throws exceptions if the file doesn't exist.
// This was added because H5Fopen prints out a lot of junk
// to the terminal.
checkFile(filename);
m_file = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
if (m_file < 0)
throw NoSuchFileException(filename);
int fileVersion[3];
try {
if (!readAttribute(m_file, k_versionAttrName, 3, fileVersion[0])) {
//Msg::print(Msg::SevWarning, "Missing version_number attribute");
} else {
if (!isSupportedFileVersion(fileVersion, k_minFileVersion)) {
stringstream versionStr;
versionStr << fileVersion[0] << "."
<< fileVersion[1] << "."
<< fileVersion[2];
throw UnsupportedVersionException(versionStr.str());
}
}
}
catch (MissingAttributeException &) {
//Msg::print(Msg::SevWarning, "Missing version_number attribute");
}
try {
if (H5Lexists(m_file, "field3d_global_metadata", H5P_DEFAULT)) {
// read the metadata
H5ScopedGopen metadataGroup(m_file, "field3d_global_metadata");
if (metadataGroup.id() > 0) {
readMetadata(metadataGroup.id());
}
}
}
catch (...) {
Msg::print(Msg::SevWarning,
"Unknown error when reading file metadata ");
//throw BadFileHierarchyException(filename);
}
try {
if (!readPartitionAndLayerInfo()) {
success = false;
}
}
catch (MissingGroupException &e) {
Msg::print(Msg::SevWarning, "Missing group: " + string(e.what()));
throw BadFileHierarchyException(filename);
}
catch (ReadMappingException &e) {
Msg::print(Msg::SevWarning, "Couldn't read mapping for partition: "
+ string(e.what()));
throw BadFileHierarchyException(filename);
}
catch (Exception &e) {
Msg::print(Msg::SevWarning, "Unknown error when reading file hierarchy: "
+ string(e.what()));
throw BadFileHierarchyException(filename);
}
catch (...) {
Msg::print(Msg::SevWarning,
"Unknown error when reading file hierarchy. ");
throw BadFileHierarchyException(filename);
}
}
catch (NoSuchFileException &e) {
Msg::print(Msg::SevWarning, "Couldn't open file: "
+ string(e.what()) );
success = false;
}
catch (MissingAttributeException &e) {
Msg::print(Msg::SevWarning,
"In file: " + filename + " - "
+ string(e.what()) );
success = false;
}
catch (UnsupportedVersionException &e) {
Msg::print(Msg::SevWarning,
"In file: " + filename + " - File version can not be read: "
+ string(e.what()));
success = false;
}
catch (BadFileHierarchyException &) {
Msg::print(Msg::SevWarning,
"In file: " + filename + " - Bad file hierarchy. ");
success = false;
}
catch (...) {
Msg::print(Msg::SevWarning,
"In file: " + filename + " Unknown exception ");
success = false;
}
if (!success)
close();
return success;
}
Exc::Exception::what
virtual const char * what() const
Definition Exception.h:90
Field3DFileHDF5Base::close
bool close()
Closes the file. No need to call this unless you specifically want to close the file early....
Definition Field3DFileHDF5.cpp:496
Field3DInputFileHDF5::m_filename
std::string m_filename
Filename, only to be set by open().
Definition Field3DFileHDF5.h:736
Field3DInputFileHDF5::readPartitionAndLayerInfo
bool readPartitionAndLayerInfo()
Sets up all the partitions and layers, but does not load any data.
Definition Field3DFileHDF5.cpp:706

References Field3DFileHDF5Base::clear(), Field3DFileHDF5Base::close(), g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, m_filename, Msg::print(), Hdf5Util::readAttribute(), readMetadata(), readPartitionAndLayerInfo(), and Msg::SevWarning.

## parsePartition()

herr_t Field3DInputFileHDF5::parsePartition | ( | hid_t | loc_id,
|  | const std::string | partitionName )

Gets called from parsePartitions. Not intended for any other use.

Definition at line 800 of file Field3DFileHDF5.cpp.

{
// Add the partition ---
m_partitionNames.push_back(string(itemName));
return 0;
}
Field3DFileHDF5Base::m_partitionNames
std::vector< std::string > m_partitionNames
This stores partition names.
Definition Field3DFileHDF5.h:394

References Field3DFileHDF5Base::m_partitionNames.

Referenced by InputFileHDF5::parsePartitions().

## parseLayer()

herr_t Field3DInputFileHDF5::parseLayer | ( | hid_t | layerGroup,
|  | const std::string & | partitionName,
|  | const std::string & | layerName )

Gets called from parsePartitions. Not intended for any other use.

Note
  Don't throw exceptions into the hdf5 lib.

Todo
  Set some sort of flag if we fail during this call. We can't throw exceptions inside hdf5.

Definition at line 814 of file Field3DFileHDF5.cpp.

{
int components;
if (!readAttribute(layerGroup, string("components"), 1, components)) {
Msg::print(Msg::SevWarning, "Couldn't read components attribute for layer "
+ partitionName + "/" + layerName);
return 0;
}
LayerInfo linfo(partitionName,layerName,components);
m_layerInfo.push_back(linfo);
return 0;
}
Field3DFileHDF5Base::m_layerInfo
std::vector< LayerInfo > m_layerInfo
This stores layer info.
Definition Field3DFileHDF5.h:387
Field3DFileHDF5Base::LayerInfo
Definition Field3DFileHDF5.h:246

References Field3DFileHDF5Base::m_layerInfo, Msg::print(), Hdf5Util::readAttribute(), and Msg::SevWarning.

Referenced by InputFileHDF5::parseLayers().

## readGroupMembership()

bool Field3DInputFileHDF5::readGroupMembership | ( | GroupMembershipMap & | gpMembershipMap | ) |

Read the group membership for the partitions.

Definition at line 1056 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
if (!H5Lexists(m_file, "field3d_group_membership", H5P_DEFAULT)) {
return false;
}
H5ScopedGopen memberGroup(m_file, "field3d_group_membership");
if (memberGroup < 0) {
return false;
}
typedef boost::tokenizer<boost::char_separator<char> > Tok;
hsize_t num_attrs = H5Aget_num_attrs(memberGroup);
if (num_attrs > 0) {
for (hsize_t idx=0; idx < num_attrs ; ++idx) {
H5ScopedAopenIdx attrIdx(memberGroup, idx);
size_t len = H5Aget_name(attrIdx.id(), 0, NULL);
if (len>0) {
char *name = new char[len+1];
if (H5Aget_name(attrIdx.id(), len+1, name) > 0) {
if (string(name) == "is_field3d_group_membership")
continue;
H5ScopedAopen attr(memberGroup, name, H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
H5T_class_t typeClass = H5Tget_class(attrType);
if (typeClass == H5T_STRING) {
string value;
if (!readAttribute(memberGroup, name, value)) {
Msg::print(Msg::SevWarning,
"Failed to read group membership data "
+ string(name));
continue;
}
{
boost::char_separator<char> sep(" :");
Tok tok(value, sep);
string new_value;
for(Tok::iterator beg=tok.begin(); beg!=tok.end();){
string fieldgroup = *beg; ++beg;
fieldgroup = removeUniqueId(fieldgroup) + ":" + *beg; ++beg;
new_value += fieldgroup + " ";
}
m_groupMembership[name] = value;
gpMembershipMap[name] = new_value;
}
}
}
}
}
}
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, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, Field3DFileHDF5Base::m_groupMembership, Msg::print(), Hdf5Util::readAttribute(), Field3DFileHDF5Base::removeUniqueId(), and Msg::SevWarning.

## readScalarLayer()

template<class Data_T>

Field< Data_T >::Ptr Field3DInputFileHDF5::readScalarLayer | ( | const std::string & | intPartitionName,
|  | const std::string & | layerName ) const

private

Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.

Definition at line 1359 of file Field3DFileHDF5.h.

{
return readLayer<Data_T>(intPartitionName, layerName, false);
}
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
Field3DInputFileHDF5::readLayer
Field< Data_T >::Ptr readLayer(const std::string &intPartitionName, const std::string &layerName, bool isVectorLayer) const
This call does the actual reading of a layer. Notice that it expects a unique -internal- partition na...
Definition Field3DFileHDF5.h:1052

References Field3DFileHDF5Base::intPartitionName(), and readLayer().

Referenced by readScalarLayers(), and readScalarLayers().

## readVectorLayer()

template<class Data_T>

Field< FIELD3D_VEC3_T< Data_T > >::Ptr Field3DInputFileHDF5::readVectorLayer | ( | const std::string & | intPartitionName,
|  | const std::string & | layerName ) const

private

Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.

Definition at line 1369 of file Field3DFileHDF5.h.

{
return readLayer<FIELD3D_VEC3_T<Data_T> >(intPartitionName, layerName, true);
}

References Field3DFileHDF5Base::intPartitionName(), and readLayer().

Referenced by readVectorLayers(), and readVectorLayers().

## readLayer()

template<class Data_T>

Field< Data_T >::Ptr Field3DInputFileHDF5::readLayer | ( | const std::string & | intPartitionName,
|  | const std::string & | layerName,
|  | bool | isVectorLayer ) const

private

This call does the actual reading of a layer. Notice that it expects a unique -internal- partition name.

Definition at line 1052 of file Field3DFileHDF5.h.

{
using namespace boost;
using namespace std;
using namespace Hdf5Util;
typedef typename Field<Data_T>::Ptr FieldPtr;
// Instantiate a null pointer for easier code reading
FieldPtr nullPtr;
GlobalLock lock(g_hdf5Mutex);
// Find the partition
FileHDF5::Partition::Ptr part = partition(intPartitionName);
if (!part) {
Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
return nullPtr;
}
// Find the layer in the partition
const FileHDF5::Layer *l;
if (isVectorLayer)
l = part->vectorLayer(layerName);
else
l = part->scalarLayer(layerName);
if (!l) {
Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName );
return nullPtr;
}
// Open the layer group
string layerPath = l->parent + "/" + l->name;
H5ScopedGopen layerGroup(m_file, layerPath.c_str());
if (layerGroup.id() < 0) {
Msg::print(Msg::SevWarning, "Couldn't find layer group " + layerName
+ " in .f3d file ");
return nullPtr;
}
// Get the class name
string className;
if (!readAttribute(layerGroup.id(), "class_name", className)) {
Msg::print(Msg::SevWarning, "Couldn't find class_name attrib in layer " +
layerName);
return nullPtr;
}
// Check the cache
FieldCache<Data_T> &cache = FieldCache<Data_T>::singleton();
FieldPtr cachedField = cache.getCachedField(m_filename, layerPath);
if (cachedField) {
return cachedField;
}
// Construct the field and load the data
// Unlock the g_hdf5Mutex while calling readField() so that other threads
// have a chance to pre-empt loading in between (prevents deadlocks with
// sparse reader)
lock.unlock();
typename Field<Data_T>::Ptr field;
field = readField<Data_T>(className, layerGroup.id(), m_filename, layerPath);
if (!field) {
#if 0 // This isn't really an error
Msg::print(Msg::SevWarning, "Couldn't read the layer data of layer: "
+ layerName);
#endif
return nullPtr;
}
// Now we need to use Hdf5 again, so re-aquire the lock.
lock.lock();
// read the metadata
string metadataPath = layerPath + "/metadata";
H5ScopedGopen metadataGroup(m_file, metadataPath.c_str());
if (metadataGroup.id() > 0) {
readMetadata(metadataGroup.id(), field);
}
// Set the name of the field so it's possible to re-create the file
field->name = removeUniqueId(intPartitionName);
field->attribute = layerName;
field->setMapping(part->mapping);
// Cache the field for future use
if (field) {
cache.cacheField(field, m_filename, layerPath);
}
return field;
}
readField
Field< Data_T >::Ptr readField(const std::string &className, hid_t layerGroup, const std::string &filename, const std::string &layerPath)
This function creates a FieldIO instance based on className which then reads the field data from laye...
Definition Field3DFileHDF5.h:1644
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition Field.h:173
FieldBase::name
std::string name
Optional name of the field.
Definition Field.h:171
FieldCache::cacheField
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
Definition FieldCache.h:169
FieldCache::singleton
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Definition FieldCache.h:135
FieldCache::getCachedField
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
Definition FieldCache.h:148
FieldRes::setMapping
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition Field.h:347

References FieldBase::attribute, FieldCache< Data_T >::cacheField(), g_hdf5Mutex, FieldCache< Data_T >::getCachedField(), Hdf5Util::H5Base::id(), Field3DFileHDF5Base::intPartitionName(), Field3DFileHDF5Base::m_file, m_filename, FieldBase::name, FileHDF5::Layer::name, FileHDF5::Layer::parent, Field3DFileHDF5Base::partition(), Msg::print(), Hdf5Util::readAttribute(), readField(), readMetadata(), Field3DFileHDF5Base::removeUniqueId(), FieldRes::setMapping(), Msg::SevWarning, and FieldCache< Data_T >::singleton().

Referenced by readScalarLayer(), and readVectorLayer().

## readPartitionAndLayerInfo()

bool Field3DInputFileHDF5::readPartitionAndLayerInfo | ( |  | ) |

private

Sets up all the partitions and layers, but does not load any data.

Definition at line 706 of file Field3DFileHDF5.cpp.

{
using namespace InputFileHDF5;
GlobalLock lock(g_hdf5Mutex);
// First, find the partitions ---
herr_t status;
status = H5Literate(m_file, H5_INDEX_NAME, H5_ITER_NATIVE, NULL,
&parsePartitions, this);
// Get the partition names to store
m_partitions.clear();
for (size_t i=0; i < m_partitionNames.size(); i++) {
Partition::Ptr part(new Partition);
part->name = m_partitionNames[i];
m_partitions.push_back(part);
}
// For each partition, find its mapping ---
for (PartitionList::iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
// Open the partition
H5ScopedGopen partitionGroup(m_file, (**i).name);
string mappingPath = "/" + (**i).name + "/" + k_mappingStr;
// Open up the mapping group
H5ScopedGopen mappingGroup(m_file, mappingPath);
if (mappingGroup.id() < 0)
throw MissingGroupException((**i).name + "/" + k_mappingStr);
// Try to build a mapping from it
FieldMapping::Ptr mapping;
mapping = readFieldMapping(mappingGroup.id());
if (!mapping) {
Msg::print(Msg::SevWarning, "Got a null pointer when reading mapping");
throw ReadMappingException((**i).name);
}
// Attach the mapping to the partition
(**i).mapping = mapping;
}
// ... And then find its layers ---
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
// Open the partition
H5ScopedGopen partitionGroup(m_file, (**i).name);
// Set up the info struct for the callback
ParseLayersInfo info;
info.file = this;
info.partitionName = (**i).name;
m_layerInfo.clear();
status = H5Literate(partitionGroup.id(), H5_INDEX_NAME, H5_ITER_NATIVE,
NULL, &parseLayers, &info);
//set the layer information on the partitions here
for (std::vector<LayerInfo>::iterator i = m_layerInfo.begin();
i != m_layerInfo.end(); i++) {
std::string parent = i->parentName;
Partition::Ptr part = partition(parent);
Layer layer;
layer.name = i->name;
layer.parent = i->parentName;
if (i->components == 1) {
part->addScalarLayer(layer);
} else if (i->components == 3) {
part->addVectorLayer(layer);
}
}
}
return true;
}
readFieldMapping
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
Definition Field3DFileHDF5.cpp:1613
Field3DFileHDF5Base::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition Field3DFileHDF5.h:392
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92
InputFileHDF5::ParseLayersInfo::file
Field3DInputFileHDF5 * file
Definition Field3DFileHDF5.h:886
InputFileHDF5::ParseLayersInfo::partitionName
std::string partitionName
Definition Field3DFileHDF5.h:887

References InputFileHDF5::ParseLayersInfo::file, g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, Field3DFileHDF5Base::m_layerInfo, Field3DFileHDF5Base::m_partitionNames, Field3DFileHDF5Base::m_partitions, FileHDF5::Layer::name, FileHDF5::Layer::parent, InputFileHDF5::parseLayers(), InputFileHDF5::parsePartitions(), Field3DFileHDF5Base::partition(), InputFileHDF5::ParseLayersInfo::partitionName, Msg::print(), readFieldMapping(), and Msg::SevWarning.

Referenced by open().

## readMetadata() [1/2]

bool Field3DInputFileHDF5::readMetadata | ( | hid_t | metadata_id,
|  | FieldBase::Ptr | field ) const

private

Read metadata for this layer.

Todo
  Replace char* with std::string

Definition at line 836 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
hsize_t num_attrs = H5Aget_num_attrs(metadata_id);
if (num_attrs > 0) {
for (hsize_t idx=0; idx < num_attrs ; ++idx) {
H5ScopedAopenIdx attrIdx(metadata_id, idx);
size_t len = H5Aget_name(attrIdx.id(), 0, NULL);
if (len > 0) {
char *name = new char[len+1];
if (H5Aget_name(attrIdx.id(), len+1, name) > 0) {
H5ScopedAopen attr(metadata_id, name, H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
H5T_class_t typeClass = H5Tget_class(attrType);
if (typeClass == H5T_STRING) {
string value;
if (!readAttribute(metadata_id, name, value)) {
Msg::print(Msg::SevWarning,
"Failed to read metadata " + string(name));
if (name) {
delete[] name;
}
continue;
}
field->metadata().setStrMetadata(name, value);
}
else {
if (H5Sget_simple_extent_ndims(attrSpace) != 1) {
Msg::print(Msg::SevWarning, "Bad attribute rank for attribute "
+ string(name));
if (name) {
delete[] name;
}
continue;
}
hsize_t dims[1];
H5Sget_simple_extent_dims(attrSpace, dims, NULL);
if (typeClass == H5T_INTEGER) {
if (dims[0] == 1){
int value;
if (!readAttribute(metadata_id, name, dims[0], value))
Msg::print(Msg::SevWarning, "Failed to read metadata "
+ string(name));
field->metadata().setIntMetadata(name, value);
}
else if (dims[0] == 3){
V3i value;
if (!readAttribute(metadata_id, name, dims[0], value.x))
Msg::print(Msg::SevWarning, "Failed to read metadata " +
string(name) );
field->metadata().setVecIntMetadata(name, value);
}
else {
Msg::print(Msg::SevWarning,
"Attribute of size " +
boost::lexical_cast<std::string>(dims[0])
+ " is not valid for metadata");
}
}
else if (typeClass == H5T_FLOAT) {
if (dims[0] == 1){
float value;
if (!readAttribute(metadata_id, name, dims[0], value))
Msg::print(Msg::SevWarning, "Failed to read metadata " +
string(name) );
field->metadata().setFloatMetadata(name, value);
}
else if (dims[0] == 3){
V3f value;
if (!readAttribute(metadata_id, name, dims[0], value.x))
Msg::print(Msg::SevWarning, "Failed to read metadata "+
string(name) );
field->metadata().setVecFloatMetadata(name, value);
}
else {
Msg::print(Msg::SevWarning, "Attribute of size " +
boost::lexical_cast<std::string>(dims[0]) +
" is not valid for metadata");
}
}
else {
Msg::print(Msg::SevWarning, "Attribute '" + string(name) +
+ "' has unsupported data type for metadata");
}
}
}
if (name) {
delete[] name;
}
}
}
}
return true;
}
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
V3f
Imath::V3f V3f
Definition SpiMathLib.h:73

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

Referenced by open(), readLayer(), and readProxyLayer().

## readMetadata() [2/2]

bool Field3DInputFileHDF5::readMetadata | ( | hid_t | metadata_id | ) |

private

Read global metadata for this file.

Todo
  Replace char* with std::string

Definition at line 947 of file Field3DFileHDF5.cpp.

{
GlobalLock lock(g_hdf5Mutex);
hsize_t num_attrs = H5Aget_num_attrs(metadata_id);
if (num_attrs > 0) {
for (hsize_t idx=0; idx < num_attrs ; ++idx) {
H5ScopedAopenIdx attrIdx(metadata_id, idx);
size_t len = H5Aget_name(attrIdx.id(), 0, NULL);
if (len > 0) {
char *name = new char[len+1];
if (H5Aget_name(attrIdx.id(), len+1, name) > 0) {
H5ScopedAopen attr(metadata_id, name, H5P_DEFAULT);
H5ScopedAget_space attrSpace(attr);
H5ScopedAget_type attrType(attr);
H5T_class_t typeClass = H5Tget_class(attrType);
if (typeClass == H5T_STRING) {
string value;
if (!readAttribute(metadata_id, name, value)) {
Msg::print(Msg::SevWarning,
"Failed to read metadata " + string(name));
if (name) {
delete[] name;
}
continue;
}
metadata().setStrMetadata(name, value);
}
else {
if (H5Sget_simple_extent_ndims(attrSpace) != 1) {
Msg::print(Msg::SevWarning, "Bad attribute rank for attribute "
+ string(name));
if (name) {
delete[] name;
}
continue;
}
hsize_t dims[1];
H5Sget_simple_extent_dims(attrSpace, dims, NULL);
if (typeClass == H5T_INTEGER) {
if (dims[0] == 1){
int value;
if (!readAttribute(metadata_id, name, dims[0], value))
Msg::print(Msg::SevWarning, "Failed to read metadata "
+ string(name));
metadata().setIntMetadata(name, value);
}
else if (dims[0] == 3){
V3i value;
if (!readAttribute(metadata_id, name, dims[0], value.x))
Msg::print(Msg::SevWarning, "Failed to read metadata " +
string(name) );
metadata().setVecIntMetadata(name, value);
}
else {
Msg::print(Msg::SevWarning,
"Attribute of size " +
boost::lexical_cast<std::string>(dims[0])
+ " is not valid for metadata");
}
}
else if (typeClass == H5T_FLOAT) {
if (dims[0] == 1){
float value;
if (!readAttribute(metadata_id, name, dims[0], value))
Msg::print(Msg::SevWarning, "Failed to read metadata " +
string(name) );
metadata().setFloatMetadata(name, value);
}
else if (dims[0] == 3){
V3f value;
if (!readAttribute(metadata_id, name, dims[0], value.x))
Msg::print(Msg::SevWarning, "Failed to read metadata "+
string(name) );
metadata().setVecFloatMetadata(name, value);
}
else {
Msg::print(Msg::SevWarning, "Attribute of size " +
boost::lexical_cast<std::string>(dims[0]) +
" is not valid for metadata");
}
}
else {
Msg::print(Msg::SevWarning, "Attribute '" + string(name) +
+ "' has unsupported data type for metadata");
}
}
}
if (name) {
delete[] name;
}
}
}
}
return true;
}
Field3DFileHDF5Base::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field3DFileHDF5.h:321
FieldMetadata::setStrMetadata
void setStrMetadata(const std::string &name, const std::string &val)
Set the a string value for the given metadata name.
Definition FieldMetadata.cpp:102
FieldMetadata::setVecFloatMetadata
void setVecFloatMetadata(const std::string &name, const V3f &val)
Set the a V3f value for the given metadata name.
Definition FieldMetadata.cpp:58
FieldMetadata::setVecIntMetadata
void setVecIntMetadata(const std::string &name, const V3i &val)
Set the a V3i value for the given metadata name.
Definition FieldMetadata.cpp:80
FieldMetadata::setFloatMetadata
void setFloatMetadata(const std::string &name, const float val)
Set the a float value for the given metadata name.
Definition FieldMetadata.cpp:69

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::metadata(), Msg::print(), Hdf5Util::readAttribute(), FieldMetadata::setFloatMetadata(), FieldMetadata::setIntMetadata(), FieldMetadata::setStrMetadata(), FieldMetadata::setVecFloatMetadata(), FieldMetadata::setVecIntMetadata(), and Msg::SevWarning.

## Friends And Related Symbol Documentation

## Field3DInputFile

friend class Field3DInputFile

friend

Definition at line 441 of file Field3DFileHDF5.h.

References Field3DInputFile.

Referenced by Field3DInputFile.

## Field3DOutputFile

friend class Field3DOutputFile

friend

Definition at line 442 of file Field3DFileHDF5.h.

References Field3DInputFileHDF5(), Field3DOutputFile, readScalarLayers(), and readVectorLayers().

Referenced by Field3DOutputFile.

## Member Data Documentation

## m_filename

std::string Field3DInputFileHDF5::m_filename

private

Filename, only to be set by open().

Definition at line 736 of file Field3DFileHDF5.h.

Referenced by open(), and readLayer().

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

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