Field3DFileHDF5.cpp
Go to the documentation of this file.
//----------------------------------------------------------------------------//
/*
* Copyright (c) 2009 Sony Pictures Imageworks Inc
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution. Neither the name of Sony Pictures Imageworks nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <hdf5.h>
#include <H5Epublic.h>
#include <boost/tokenizer.hpp>
#include <boost/utility.hpp>
#include "Field3DFileHDF5.h"
#include "Field.h"
#include "ClassFactory.h"
//----------------------------------------------------------------------------//
using namespace std;
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_OPEN
//----------------------------------------------------------------------------//
// Field3D namespaces
//----------------------------------------------------------------------------//
using namespace Exc;
using namespace Hdf5Util;
using namespace FileHDF5;
//----------------------------------------------------------------------------//
// Local namespace
//----------------------------------------------------------------------------//
namespace {
// Strings used only in this file --------------------------------------------
const std::string k_mappingStr("mapping");
const std::string k_partitionName("partition");
const std::string k_versionAttrName("version_number");
const std::string k_classNameAttrName("class_name");
const std::string k_mappingTypeAttrName("mapping_type");
int k_currentFileVersion[3] =
{ FIELD3D_MAJOR_VER, FIELD3D_MINOR_VER, FIELD3D_MICRO_VER };
int k_minFileVersion[2] = { 0, 0 };
// Function objects used only in this file -----------------------------------
std::vector<std::string> makeUnique(std::vector<std::string> vec)
{
std::vector<string> ret;
std::sort(vec.begin(), vec.end());
std::vector<std::string>::iterator newEnd =
std::unique(vec.begin(), vec.end());
ret.resize(std::distance(vec.begin(), newEnd));
std::copy(vec.begin(), newEnd, ret.begin());
return ret;
}
//----------------------------------------------------------------------------//
template <class T>
class print : std::unary_function<T, void>
{
public:
print(int indentAmt)
: indent(indentAmt)
{ }
void operator()(const T& x) const
{
for (int i = 0; i < indent; i++)
std::cout << " ";
std::cout << x << std::endl;
}
int indent;
};
//----------------------------------------------------------------------------//
bool fileExists(const std::string &filename)
{
#ifdef WIN32
struct __stat64 statbuf;
return (_stat64(filename.c_str(), &statbuf) != -1);
#else
struct stat statbuf;
return (stat(filename.c_str(), &statbuf) != -1);
#endif
}
void checkFile(const std::string &filename)
{
if (!fileExists(filename))
{
throw NoSuchFileException(filename);
}
}
//----------------------------------------------------------------------------//
bool isSupportedFileVersion(const int fileVersion[3],
const int minVersion[2])
{
stringstream currentVersionStr;
currentVersionStr << k_currentFileVersion[0] << "."
<< k_currentFileVersion[1] << "."
<< k_currentFileVersion[2];
stringstream fileVersionStr;
fileVersionStr << fileVersion[0] << "."
<< fileVersion[1] << "."
<< fileVersion[2];
stringstream minVersionStr;
minVersionStr << minVersion[0] << "."
<< minVersion[1];
if (fileVersion[0] > k_currentFileVersion[0] ||
(fileVersion[0] == k_currentFileVersion[0] &&
fileVersion[1] > k_currentFileVersion[1])) {
Msg::print(Msg::SevWarning, "File version " + fileVersionStr.str() +
" is higher than the current version " +
currentVersionStr.str());
return true;
}
if (fileVersion[0] < minVersion[0] ||
(fileVersion[0] == minVersion[0] &&
fileVersion[1] < minVersion[1])) {
Msg::print(Msg::SevWarning, "File version " + fileVersionStr.str() +
" is lower than the minimum supported version " +
minVersionStr.str());
return false;
}
return true;
}
//----------------------------------------------------------------------------//
static herr_t localPrintError( hid_t estack_id, void *stream )
{
printf("H5E message -----------------------\n");
return H5Eprint2(estack_id, static_cast<FILE*>(stream));
}
//----------------------------------------------------------------------------//
} // end of local namespace
//----------------------------------------------------------------------------//
// Partition implementations
//----------------------------------------------------------------------------//
std::string Partition::className() const
{
return k_partitionName;
}
//----------------------------------------------------------------------------//
void
Partition::addScalarLayer(const Layer &layer)
{
m_scalarLayers.push_back(layer);
}
//----------------------------------------------------------------------------//
void
Partition::addVectorLayer(const Layer &layer)
{
m_vectorLayers.push_back(layer);
}
//----------------------------------------------------------------------------//
const Layer*
Partition::scalarLayer(const std::string &name) const
{
for (ScalarLayerList::const_iterator i = m_scalarLayers.begin();
i != m_scalarLayers.end(); ++i) {
if (i->name == name)
return &(*i);
}
return NULL;
}
//----------------------------------------------------------------------------//
const Layer*
Partition::vectorLayer(const std::string &name) const
{
for (VectorLayerList::const_iterator i = m_vectorLayers.begin();
i != m_vectorLayers.end(); ++i) {
if (i->name == name)
return &(*i);
}
return NULL;
}
//----------------------------------------------------------------------------//
void
Partition::getScalarLayerNames(std::vector<std::string> &names) const
{
// We don't want to do names.clear() here, since this gets called
// inside some loops that want to accumulate names.
for (ScalarLayerList::const_iterator i = m_scalarLayers.begin();
i != m_scalarLayers.end(); ++i) {
names.push_back(i->name);
}
}
//----------------------------------------------------------------------------//
void
Partition::getVectorLayerNames(std::vector<std::string> &names) const
{
// We don't want to do names.clear() here, since this gets called
// inside some loops that want to accumulate names.
for (VectorLayerList::const_iterator i = m_vectorLayers.begin();
i != m_vectorLayers.end(); ++i) {
names.push_back(i->name);
}
}
//----------------------------------------------------------------------------//
// Field3DFileHDF5Base implementations
//----------------------------------------------------------------------------//
Field3DFileHDF5Base::Field3DFileHDF5Base()
: m_file(-1), m_metadata(this)
{
GlobalLock lock(g_hdf5Mutex);
// Suppressing HDF error messages
// Explanation about the function for the error stack is here:
// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-SetAuto2
if (getenv("DEBUG_HDF")) {
cerr << "Field3DFileHDF5 -- HDF5 messages are on" << endl;
H5Eset_auto(H5E_DEFAULT, localPrintError, NULL);
} else {
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
}
}
//----------------------------------------------------------------------------//
Field3DFileHDF5Base::~Field3DFileHDF5Base()
{
close();
}
//----------------------------------------------------------------------------//
std::string
Field3DFileHDF5Base::intPartitionName(const std::string &partitionName,
const std::string & /* layerName */,
FieldRes::Ptr field)
{
// Loop over existing partitions and see if there's a matching mapping
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
if (removeUniqueId((**i).name) == partitionName) {
if ((**i).mapping->isIdentical(field->mapping())) {
return (**i).name;
}
}
}
// If there was no previously matching name, then make a new one
int nextIdx = -1;
if (m_partitionCount.find(partitionName) != m_partitionCount.end()) {
nextIdx = ++m_partitionCount[partitionName];
} else {
nextIdx = 0;
m_partitionCount[partitionName] = 0;
}
return makeIntPartitionName(partitionName, nextIdx);
}
//----------------------------------------------------------------------------//
Partition::Ptr Field3DFileHDF5Base::partition(const string &partitionName)
{
for (PartitionList::iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
if ((**i).name == partitionName)
return *i;
}
return Partition::Ptr();
}
//----------------------------------------------------------------------------//
Partition::Ptr
Field3DFileHDF5Base::partition(const string &partitionName) const
{
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
if ((**i).name == partitionName)
return *i;
}
return Partition::Ptr();
}
//----------------------------------------------------------------------------//
std::string
Field3DFileHDF5Base::removeUniqueId(const std::string &partitionName) const
{
size_t pos = partitionName.rfind(".");
if (pos == partitionName.npos) {
return partitionName;
} else {
return partitionName.substr(0, pos);
}
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::getPartitionNames(vector<string> &names) const
{
names.clear();
vector<string> tempNames;
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
tempNames.push_back(removeUniqueId((**i).name));
}
names = makeUnique(tempNames);
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::getScalarLayerNames(vector<string> &names,
const string &partitionName) const
{
names.clear();
for (int i = 0; i < numIntPartitions(partitionName); i++) {
string internalName = makeIntPartitionName(partitionName, i);
Partition::Ptr part = partition(internalName);
if (part)
part->getScalarLayerNames(names);
}
names = makeUnique(names);
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::getVectorLayerNames(vector<string> &names,
const string &partitionName) const
{
names.clear();
for (int i = 0; i < numIntPartitions(partitionName); i++) {
string internalName = makeIntPartitionName(partitionName, i);
Partition::Ptr part = partition(internalName);
if (part)
part->getVectorLayerNames(names);
}
names = makeUnique(names);
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::getIntPartitionNames(vector<string> &names) const
{
names.clear();
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
names.push_back((**i).name);
}
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::getIntScalarLayerNames(vector<string> &names,
const string &intPartitionName) const
{
names.clear();
Partition::Ptr part = partition(intPartitionName);
if (!part) {
Msg::print("getIntScalarLayerNames no partition: " + intPartitionName);
return;
}
part->getScalarLayerNames(names);
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::getIntVectorLayerNames(vector<string> &names,
const string &intPartitionName) const
{
names.clear();
Partition::Ptr part = partition(intPartitionName);
if (!part) {
Msg::print("getIntVectorLayerNames no partition: " + intPartitionName);
return;
}
part->getVectorLayerNames(names);
}
//----------------------------------------------------------------------------//
void Field3DFileHDF5Base::clear()
{
closeInternal();
m_partitions.clear();
m_groupMembership.clear();
}
//----------------------------------------------------------------------------//
bool Field3DFileHDF5Base::close()
{
closeInternal();
return true;
}
//----------------------------------------------------------------------------//
void Field3DFileHDF5Base::closeInternal()
{
GlobalLock lock(g_hdf5Mutex);
if (m_file != -1) {
if (H5Fclose(m_file) < 0) {
Msg::print(Msg::SevWarning, "Failed to close hdf5 file handle");
return;
}
m_file = -1;
}
}
//----------------------------------------------------------------------------//
int
Field3DFileHDF5Base::numIntPartitions(const std::string &partitionName) const
{
int count = 0;
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
string name = (**i).name;
size_t pos = name.rfind(".");
if (pos != name.npos) {
if (name.substr(0, pos) == partitionName) {
count++;
}
}
}
return count;
}
//----------------------------------------------------------------------------//
string
Field3DFileHDF5Base::makeIntPartitionName(const std::string &partitionName,
int i) const
{
return partitionName + "." + boost::lexical_cast<std::string>(i);
}
//----------------------------------------------------------------------------//
void
Field3DFileHDF5Base::addGroupMembership(const GroupMembershipMap& groupMembers)
{
GroupMembershipMap::const_iterator i= groupMembers.begin();
GroupMembershipMap::const_iterator end= groupMembers.end();
for (; i != end; ++i) {
GroupMembershipMap::iterator foundGroupIter =
m_groupMembership.find(i->first);
if (foundGroupIter != m_groupMembership.end()){
std::string value = m_groupMembership[i->first] + i->second;
m_groupMembership[i->first] = value;
} else {
m_groupMembership[i->first] = i->second;
}
}
}
//----------------------------------------------------------------------------//
// Field3DInputFileHDF5 implementations
//----------------------------------------------------------------------------//
Field3DInputFileHDF5::Field3DInputFileHDF5()
{
// Empty
}
//----------------------------------------------------------------------------//
Field3DInputFileHDF5::~Field3DInputFileHDF5()
{
clear();
}
//----------------------------------------------------------------------------//
bool Field3DInputFileHDF5::open(const string &filename)
{
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;
}
//----------------------------------------------------------------------------//
bool Field3DInputFileHDF5::readPartitionAndLayerInfo()
{
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;
}
//----------------------------------------------------------------------------//
herr_t Field3DInputFileHDF5::parsePartition(hid_t /* loc_id */,
const std::string itemName)
{
// Add the partition ---
m_partitionNames.push_back(string(itemName));
return 0;
}
//----------------------------------------------------------------------------//
herr_t Field3DInputFileHDF5::parseLayer(hid_t layerGroup,
const std::string &partitionName,
const std::string &layerName)
{
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;
}
//----------------------------------------------------------------------------//
bool
Field3DInputFileHDF5::
readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
{
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;
}
//----------------------------------------------------------------------------//
bool
Field3DInputFileHDF5::readMetadata(hid_t metadata_id)
{
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;
}
//----------------------------------------------------------------------------//
bool
Field3DInputFileHDF5::
readGroupMembership(GroupMembershipMap &gpMembershipMap)
{
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;
}
//----------------------------------------------------------------------------//
// Field3DFileHDF5-related callback functions
//----------------------------------------------------------------------------//
namespace InputFileHDF5 {
//----------------------------------------------------------------------------//
herr_t parsePartitions(hid_t loc_id, const char *itemName,
const H5L_info_t * /* linfo */, void *opdata)
{
GlobalLock lock(g_hdf5Mutex);
herr_t status;
H5O_info_t infobuf;
status = H5Oget_info_by_name(loc_id, itemName, &infobuf, H5P_DEFAULT);
if (status < 0) {
return -1;
}
if (infobuf.type == H5O_TYPE_GROUP) {
// Check that we have a name
if (!itemName) {
return -1;
}
// check that this group is not "groupMembership"
if (string(itemName) != "field3d_group_membership" &&
string(itemName) != "field3d_global_metadata")
{
// Get a pointer to the file data structure
Field3DInputFileHDF5* fileObject = static_cast<Field3DInputFileHDF5*>(opdata);
if (!fileObject) {
return -1;
}
return fileObject->parsePartition(loc_id, itemName);
}
}
return 0;
}
//----------------------------------------------------------------------------//
herr_t parseLayers(hid_t loc_id, const char *itemName,
const H5L_info_t * /* linfo */, void *opdata)
{
GlobalLock lock(g_hdf5Mutex);
herr_t status;
H5O_info_t infobuf;
status = H5Oget_info_by_name (loc_id, itemName, &infobuf, H5P_DEFAULT);
if (infobuf.type == H5O_TYPE_GROUP) {
// Check that we have a name
if (!itemName)
return -1;
// Get a pointer to the file data structure
ParseLayersInfo* info = static_cast<ParseLayersInfo*>(opdata);
if (!info)
return -1;
// Open up the layer group
H5ScopedGopen layerGroup(loc_id, itemName);
// Check if it's a layer
string classType;
try {
if (!readAttribute(layerGroup.id(), "class_type", classType)) {
return 0;
}
if (classType == string("field3d_layer"))
return info->file->parseLayer(layerGroup.id(), info->partitionName,
itemName);
}
catch (MissingAttributeException &) {
}
return 0;
}
return 0;
}
//----------------------------------------------------------------------------//
} // namespace InputFileHDF5
//----------------------------------------------------------------------------//
// Field3DOutputFileHDF5 implementations
//----------------------------------------------------------------------------//
Field3DOutputFileHDF5::Field3DOutputFileHDF5()
{
// Empty
}
//----------------------------------------------------------------------------//
Field3DOutputFileHDF5::~Field3DOutputFileHDF5()
{
}
//----------------------------------------------------------------------------//
bool Field3DOutputFileHDF5::create(const string &filename, CreateMode cm)
{
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;
}
//----------------------------------------------------------------------------//
bool Field3DOutputFileHDF5::writeMapping(hid_t partitionGroup,
FieldMapping::Ptr mapping)
{
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;
}
//----------------------------------------------------------------------------//
bool Field3DOutputFileHDF5::writeMetadata(hid_t metadataGroup, FieldBase::Ptr field)
{
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;
}
//----------------------------------------------------------------------------//
bool Field3DOutputFileHDF5::writeMetadata(hid_t metadataGroup)
{
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;
}
//----------------------------------------------------------------------------//
bool
Field3DOutputFileHDF5::writeGlobalMetadata()
{
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;
}
//----------------------------------------------------------------------------//
bool
Field3DOutputFileHDF5::writeGroupMembership()
{
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;
}
//----------------------------------------------------------------------------//
std::string
Field3DOutputFileHDF5::incrementPartitionName(std::string &partitionName)
{
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);
}
//----------------------------------------------------------------------------//
// Debug
//----------------------------------------------------------------------------//
void Field3DFileHDF5Base::printHierarchy() const
{
// For each partition
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
cout << "Name: " << (**i).name << endl;
if ((**i).mapping)
cout << " Mapping: " << (**i).mapping->className() << endl;
else
cout << " Mapping: NULL" << endl;
cout << " Scalar layers: " << endl;
vector<string> sNames;
(**i).getScalarLayerNames(sNames);
for_each(sNames.begin(), sNames.end(), print<string>(4));
cout << " Vector layers: " << endl;
vector<string> vNames;
(**i).getVectorLayerNames(vNames);
for_each(vNames.begin(), vNames.end(), print<string>(4));
}
}
//----------------------------------------------------------------------------//
// Function Implementations
//----------------------------------------------------------------------------//
bool writeField(hid_t layerGroup, FieldBase::Ptr field)
{
ClassFactory &factory = ClassFactory::singleton();
FieldIO::Ptr io = factory.createFieldIO(field->className());
assert(io != 0);
if (!io) {
Msg::print(Msg::SevWarning, "Unable to find class type: " +
field->className());
return false;
}
// Add class name attribute
if (!writeAttribute(layerGroup, k_classNameAttrName,
field->className())) {
Msg::print(Msg::SevWarning, "Error adding class name attribute.");
return false;
}
return io->write(layerGroup, field);
}
//----------------------------------------------------------------------------//
FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
{
ClassFactory &factory = ClassFactory::singleton();
std::string className;
if (!readAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
Msg::print(Msg::SevWarning, "Couldn't find " + k_mappingTypeAttrName +
" attribute");
return FieldMapping::Ptr();
}
FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
assert(io != 0);
if (!io) {
Msg::print(Msg::SevWarning, "Unable to find class type: " +
className);
return FieldMapping::Ptr();
}
FieldMapping::Ptr mapping = io->read(mappingGroup);
if (!mapping) {
Msg::print(Msg::SevWarning, "Couldn't read mapping");
return FieldMapping::Ptr();
}
return mapping;
}
//----------------------------------------------------------------------------//
bool writeFieldMapping(hid_t mappingGroup, FieldMapping::Ptr mapping)
{
ClassFactory &factory = ClassFactory::singleton();
std::string className = mapping->className();
if (!writeAttribute(mappingGroup, k_mappingTypeAttrName, className)) {
Msg::print(Msg::SevWarning, "Couldn't add " + className + " attribute");
return false;
}
FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
assert(io != 0);
if (!io) {
Msg::print(Msg::SevWarning, "Unable to find class type: " +
className);
return false;
}
return io->write(mappingGroup, mapping);
}
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_SOURCE_CLOSE
//----------------------------------------------------------------------------//
ClassFactory.h
Contains the ClassFactory class for registering Field3D classes.
readFieldMapping
FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
Definition Field3DFileHDF5.cpp:1613
writeFieldMapping
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
writeField
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
Field3DFileHDF5.h
Contains the Field3DFileHDF5 classes.
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
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
fileExists
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
Definition Field3DFile.cpp:1341
Field.h
Contains Field, WritableField and ResizableField classes.
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
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
V3f
Imath::V3f V3f
Definition SpiMathLib.h:73
ClassFactory
Definition ClassFactory.h:72
ClassFactory::createFieldIO
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
Definition ClassFactory.cpp:165
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
Exc::Exception
Definition Exception.h:74
Field3DFileHDF5Base::Field3DFileHDF5Base
Field3DFileHDF5Base()
Definition Field3DFileHDF5.cpp:290
Field3DFileHDF5Base::m_partitionNames
std::vector< std::string > m_partitionNames
This stores partition names.
Definition Field3DFileHDF5.h:394
Field3DFileHDF5Base::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition Field3DFileHDF5.h:392
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::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
Field3DFileHDF5Base::printHierarchy
void printHierarchy() const
Definition Field3DFileHDF5.cpp:1564
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::close
bool close()
Closes the file. No need to call this unless you specifically want to close the file early....
Definition Field3DFileHDF5.cpp:496
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
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
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::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::closeInternal
void closeInternal()
Closes the file if open.
Definition Field3DFileHDF5.cpp:505
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
Field3DFileHDF5Base::~Field3DFileHDF5Base
virtual ~Field3DFileHDF5Base()=0
Pure virtual destructor to ensure we never instantiate this class.
Definition Field3DFileHDF5.cpp:308
Field3DFileHDF5Base::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field3DFileHDF5.h:321
Field3DFileHDF5Base::addGroupMembership
void addGroupMembership(const GroupMembershipMap &groupMembers)
Add to the group membership.
Definition Field3DFileHDF5.cpp:551
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
Field3DFileHDF5Base::m_layerInfo
std::vector< LayerInfo > m_layerInfo
This stores layer info.
Definition Field3DFileHDF5.h:387
Field3DFileHDF5Base::numIntPartitions
int numIntPartitions(const std::string &partitionName) const
Returns the number of internal partitions for a given partition name.
Definition Field3DFileHDF5.cpp:521
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::partition
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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
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
Field3DFileHDF5Base::m_metadata
FieldMetadata m_metadata
metadata
Definition Field3DFileHDF5.h:406
Field3DFileHDF5Base::clear
void clear()
Clear the data structures and close the file.
Definition Field3DFileHDF5.cpp:487
Field3DFileHDF5Base::GroupMembershipMap
std::map< std::string, std::string > GroupMembershipMap
Definition Field3DFileHDF5.h:257
Field3DInputFileHDF5
Provides reading of .f3d (internally, hdf5) files.
Definition Field3DFileHDF5.h:438
Field3DInputFileHDF5::m_filename
std::string m_filename
Filename, only to be set by open().
Definition Field3DFileHDF5.h:736
Field3DInputFileHDF5::parsePartition
herr_t parsePartition(hid_t loc_id, const std::string partitionName)
Gets called from parsePartitions. Not intended for any other use.
Definition Field3DFileHDF5.cpp:800
Field3DInputFileHDF5::readMetadata
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
Definition Field3DFileHDF5.cpp:837
Field3DInputFileHDF5::parseLayer
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.
Definition Field3DFileHDF5.cpp:814
Field3DInputFileHDF5::readPartitionAndLayerInfo
bool readPartitionAndLayerInfo()
Sets up all the partitions and layers, but does not load any data.
Definition Field3DFileHDF5.cpp:706
Field3DInputFileHDF5::readGroupMembership
bool readGroupMembership(GroupMembershipMap &gpMembershipMap)
Read the group membership for the partitions.
Definition Field3DFileHDF5.cpp:1057
Field3DInputFileHDF5::~Field3DInputFileHDF5
virtual ~Field3DInputFileHDF5()
Definition Field3DFileHDF5.cpp:579
Field3DInputFileHDF5::open
bool open(const std::string &filename)
Opens the given file.
Definition Field3DFileHDF5.cpp:586
Field3DInputFileHDF5::Field3DInputFileHDF5
Field3DInputFileHDF5()
Definition Field3DFileHDF5.cpp:572
Field3DOutputFileHDF5::writeGlobalMetadata
bool writeGlobalMetadata()
This routine is call if you want to write out global metadata to disk.
Definition Field3DFileHDF5.cpp:1483
Field3DOutputFileHDF5::create
bool create(const std::string &filename, CreateMode cm=OverwriteMode)
Creates a .f3d file on disk.
Definition Field3DFileHDF5.cpp:1239
Field3DOutputFileHDF5::CreateMode
CreateMode
Definition Field3DFileHDF5.h:773
Field3DOutputFileHDF5::OverwriteMode
@ OverwriteMode
Definition Field3DFileHDF5.h:774
Field3DOutputFileHDF5::FailOnExisting
@ FailOnExisting
Definition Field3DFileHDF5.h:775
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
Field3DOutputFileHDF5::writeMetadata
bool writeMetadata(hid_t metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Definition Field3DFileHDF5.cpp:1320
Field3DOutputFileHDF5::writeGroupMembership
bool writeGroupMembership()
This routine is called just before closing to write out any group membership to disk.
Definition Field3DFileHDF5.cpp:1504
Field3DOutputFileHDF5::~Field3DOutputFileHDF5
virtual ~Field3DOutputFileHDF5()
Definition Field3DFileHDF5.cpp:1230
Field3DOutputFileHDF5::Field3DOutputFileHDF5
Field3DOutputFileHDF5()
Definition Field3DFileHDF5.cpp:1223
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
FieldBase::Ptr
boost::intrusive_ptr< FieldBase > Ptr
Definition Field.h:97
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition FieldIO.h:91
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition FieldMappingIO.h:71
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92
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
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::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
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
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition Field.h:213
FileHDF5::Layer
Definition Field3DFileHDF5.h:121
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
Definition Field3DFileHDF5.h:146
FileHDF5::Partition::getVectorLayerNames
void getVectorLayerNames(std::vector< std::string > &names) const
Gets all the vector layer names.
Definition Field3DFileHDF5.cpp:276
FileHDF5::Partition::getScalarLayerNames
void getScalarLayerNames(std::vector< std::string > &names) const
Gets all the scalar layer names.
Definition Field3DFileHDF5.cpp:263
FileHDF5::Partition::className
virtual std::string className() const
Definition Field3DFileHDF5.cpp:213
FileHDF5::Partition::vectorLayer
const FileHDF5::Layer * vectorLayer(const std::string &name) const
Finds a vector layer.
Definition Field3DFileHDF5.cpp:250
FileHDF5::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition Field3DFileHDF5.h:152
FileHDF5::Partition::addScalarLayer
void addScalarLayer(const FileHDF5::Layer &layer)
Adds a scalar layer.
Definition Field3DFileHDF5.cpp:221
FileHDF5::Partition::addVectorLayer
void addVectorLayer(const FileHDF5::Layer &layer)
Adds a vector layer.
Definition Field3DFileHDF5.cpp:229
FileHDF5::Partition::name
std::string name
Name of the partition.
Definition Field3DFileHDF5.h:201
FileHDF5::Partition::m_vectorLayers
VectorLayerList m_vectorLayers
The vector-valued layers belonging to this partition.
Definition Field3DFileHDF5.h:212
FileHDF5::Partition::scalarLayer
const FileHDF5::Layer * scalarLayer(const std::string &name) const
Finds a scalar layer.
Definition Field3DFileHDF5.cpp:237
FileHDF5::Partition::m_scalarLayers
ScalarLayerList m_scalarLayers
The scalar-valued layers belonging to this partition.
Definition Field3DFileHDF5.h:210
Hdf5Util::H5Base::id
hid_t id() const
Query the hid_t value.
Definition Hdf5Util.h:100
Hdf5Util::H5ScopedAget_space
Scoped object - opens an attribute data space on creation and closes it on destruction.
Definition Hdf5Util.h:288
Hdf5Util::H5ScopedAget_type
Scoped object - opens an attribute data type on creation and closes it on destruction.
Definition Hdf5Util.h:311
Hdf5Util::H5ScopedAopenIdx
Scoped object - Opens attribute by index and closes it on destruction.
Definition Hdf5Util.h:143
Hdf5Util::H5ScopedAopen
Scoped object - Opens attribute by name and closes it on destruction.
Definition Hdf5Util.h:114
Hdf5Util::H5ScopedGcreate
Scoped object - creates a group on creation and closes it on destruction.
Definition Hdf5Util.h:166
Hdf5Util::H5ScopedGopen
Scoped object - opens a group on creation and closes it on destruction.
Definition Hdf5Util.h:195
Hdf5Util::readAttribute
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
Exc
Namespace for Exception objects.
Definition Exception.h:57
FIELD3D_NAMESPACE_OPEN
Definition FieldMapping.cpp:74
FileHDF5
Namespace for file I/O specifics.
Definition Field3DFileHDF5.h:111
Hdf5Util
Contains utility functions and classes for Hdf5 files.
Definition Hdf5Util.h:86
InputFileHDF5
Namespace for file input specifics.
Definition Field3DFileHDF5.h:879
InputFileHDF5::parsePartitions
FIELD3D_API herr_t parsePartitions(hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
Gets called from readPartitionAndLayerInfo to check each group found under the root of the file....
Definition Field3DFileHDF5.cpp:1130
InputFileHDF5::parseLayers
FIELD3D_API herr_t parseLayers(hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
Gets called from readPartitionAndLayerInfo to check each group found under the root of the file....
Definition Field3DFileHDF5.cpp:1170
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
FIELD3D_MAJOR_VER
#define FIELD3D_MAJOR_VER
Definition ns.h:38
FIELD3D_NAMESPACE_SOURCE_CLOSE
#define FIELD3D_NAMESPACE_SOURCE_CLOSE
Definition ns.h:60
FIELD3D_MINOR_VER
#define FIELD3D_MINOR_VER
Definition ns.h:39
FIELD3D_MICRO_VER
#define FIELD3D_MICRO_VER
Definition ns.h:40
Field3DFileHDF5Base::LayerInfo
Definition Field3DFileHDF5.h:246
InputFileHDF5::ParseLayersInfo
struct used to pass the class and partition info back to the parseLayers() callback
Definition Field3DFileHDF5.h:885
InputFileHDF5::ParseLayersInfo::file
Field3DInputFileHDF5 * file
Definition Field3DFileHDF5.h:886
InputFileHDF5::ParseLayersInfo::partitionName
std::string partitionName
Definition Field3DFileHDF5.h:887