Field3DInputFile Class Reference
File I/O

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

`#include <Field3DFile.h>`

Inheritance diagram for Field3DInputFile:

## Public Member Functions

const std::string & | encoding () const
| Returns an encoding descriptor of the given file.
bool | open (const std::string &filename)
| Opens the given file.
Constructors & destructor
| Field3DInputFile ()
virtual | ~Field3DInputFile ()
Reading layers from disk
template<class Data_T>
Field< Data_T >::Vec | readLayers (const std::string &layerName=std::string("")) const
template<class Data_T>
Field< Data_T >::Vec | readLayers (const std::string &partitionName, const std::string &layerName) const
Backward compatibility
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.
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 >::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.
Public Member Functions inherited from Field3DFileBase
void | clear ()
| Clear the data structures and close the file.
bool | close ()
| Closes the file. No need to call this unless you specifically want to close the file early. It will close once the File object goes out of scope.
FieldMetadata & | metadata ()
| accessor to the m_metadata class
const FieldMetadata & | metadata () const
| Read only access to the m_metadata class.
virtual void | metadataHasChanged (const std::string &)
| This function should implemented by concrete classes to get the callback when metadata changes.
| Field3DFileBase ()
virtual | ~Field3DFileBase ()=0
| Pure virtual destructor to ensure we never instantiate this class.
void | getPartitionNames (std::vector< std::string > &names) const
| Gets the names of all the partitions in the file.
void | getScalarLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
| Gets the names of all the scalar layers in a given partition.
void | getVectorLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
| Gets the names of all the vector layers in a given partition.
void | addGroupMembership (const GroupMembershipMap &groupMembers)
| Add to the group membership.
void | printHierarchy () const

## Private Member Functions

void | cleanup ()
virtual void | closeInternal ()
| Closes the file if open.
template<class Data_T>
Field< Data_T >::Ptr | readLayer (const std::string &intPartitionName, const std::string &layerName) const
| This call does the actual reading of a layer. Notice that it expects a unique -internal- partition name.
bool | readMetadata (const OgIGroup &metadataGroup)
| Read global metadata for this file.
bool | readMetadata (const OgIGroup &metadataGroup, 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>
EmptyField< Data_T >::Ptr | readProxyLayer (OgIGroup &location, const std::string &name, const std::string &attribute, FieldMapping::Ptr mapping) const
| Retrieves a proxy version (EmptyField) from a given Ogawa location.

## Private Attributes

boost::shared_ptr< Alembic::Ogawa::IArchive > | m_archive
| Pointer to the Ogawa archive.
std::string | m_filename
| Filename, only to be set by open().
boost::shared_ptr< Field3DInputFileHDF5 > | m_hdf5
| HDF5 fallback.
boost::shared_ptr< OgIGroup > | m_root
| Pointer to root group.

## Additional Inherited Members

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

## Detailed Description

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

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

Definition at line 413 of file Field3DFile.h.

## Constructor & Destructor Documentation

## Field3DInputFile()

Field3DInputFile::Field3DInputFile | ( |  | ) |

Definition at line 700 of file Field3DFile.cpp.

{
// Empty
}

## ~Field3DInputFile()

Field3DInputFile::~Field3DInputFile | ( |  | ) |

virtual

Definition at line 707 of file Field3DFile.cpp.

{
cleanup();
}
Field3DInputFile::cleanup
void cleanup()
Definition Field3DFile.h:557

References cleanup().

## Member Function Documentation

## open()

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

Opens the given file.

Returns
  Whether successful

Definition at line 714 of file Field3DFile.cpp.

{
clear();
bool success = true;
// Record filename
m_filename = filename;
try {
// Throws exceptions if the file doesn't exist.
checkFile(filename);
// Open the Ogawa archive
m_archive.reset(new Alembic::Ogawa::IArchive(filename));
// Error check and HDF5 fallback
if (!m_archive->isValid()) {
m_hdf5.reset(new Field3DInputFileHDF5);
m_hdf5Base = m_hdf5;
if (m_hdf5->open(filename)) {
// Handled. Just return.
return true;
} else {
throw NoSuchFileException(filename);
}
}
// Grab the root group
m_root.reset(new OgIGroup(*m_archive));
// Check version number
try {
OgIAttribute<veci32_t> version =
m_root->findAttribute<veci32_t>(k_versionAttrName);
if (!version.isValid()) {
throw OgIAttributeException("Missing version attribute.");
}
int fileVersion[3] = { version.value()[0],
version.value()[1],
version.value()[2] };
if (!isSupportedFileVersion(fileVersion, k_minFileVersion)) {
stringstream versionStr;
versionStr << fileVersion[0] << "."
<< fileVersion[1] << "."
<< fileVersion[2];
throw UnsupportedVersionException(versionStr.str());
}
}
catch (OgIAttributeException &e) {
}
// Read the global metadata. This does not always exists,
// depends on if it was written or not.
try {
const OgIGroup metadataGroup = m_root->findGroup("field3d_global_metadata");
if (metadataGroup.isValid()) {
readMetadata(metadataGroup);
}
}
catch (...) {
Msg::print(Msg::SevWarning,
"Unknown error when reading file metadata ");
}
// Read the partition and layer info
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 (runtime_error &e) {
// HDF5 fallback
m_hdf5.reset(new Field3DInputFileHDF5);
m_hdf5Base = m_hdf5;
if (m_hdf5->open(filename)) {
// Handled. Just return.
return true;
} else {
Msg::print(Msg::SevWarning,
"In file: " + filename + ": " + string(e.what()));
success = false;
}
}
catch (...) {
Msg::print(Msg::SevWarning,
"In file: " + filename + " Unknown exception ");
success = false;
}
if (!success) {
close();
}
return success;
}
veci32_t
Field3D::V3i veci32_t
Definition Traits.h:94
Exc::Exception::what
virtual const char * what() const
Definition Exception.h:90
Field3DFileBase::m_hdf5Base
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
Definition Field3DFile.h:388
Field3DFileBase::clear
void clear()
Clear the data structures and close the file.
Definition Field3DFile.cpp:616
Field3DFileBase::close
bool close()
Closes the file. No need to call this unless you specifically want to close the file early....
Definition Field3DFile.cpp:630
Field3DInputFile::m_filename
std::string m_filename
Filename, only to be set by open().
Definition Field3DFile.h:600
Field3DInputFile::m_root
boost::shared_ptr< OgIGroup > m_root
Pointer to root group.
Definition Field3DFile.h:604
Field3DInputFile::m_hdf5
boost::shared_ptr< Field3DInputFileHDF5 > m_hdf5
HDF5 fallback.
Definition Field3DFile.h:607
Field3DInputFile::m_archive
boost::shared_ptr< Alembic::Ogawa::IArchive > m_archive
Pointer to the Ogawa archive.
Definition Field3DFile.h:602
Field3DInputFile::readPartitionAndLayerInfo
bool readPartitionAndLayerInfo()
Sets up all the partitions and layers, but does not load any data.
Definition Field3DFile.cpp:857
Field3DInputFile::readMetadata
bool readMetadata(const OgIGroup &metadataGroup, FieldBase::Ptr field) const
Read metadata for this layer.
Definition Field3DFile.cpp:942
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 Field3DFileBase::clear(), Field3DFileBase::close(), m_archive, m_filename, m_hdf5, Field3DFileBase::m_hdf5Base, m_root, Msg::print(), readMetadata(), readPartitionAndLayerInfo(), and Msg::SevWarning.

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::load().

## encoding()

const std::string & Field3DInputFile::encoding | ( |  | ) | const

inline

Returns an encoding descriptor of the given file.

Definition at line 434 of file Field3DFile.h.

{
const static std::string encodings[2] = { "Ogawa", "HDF5" };
return encodings[m_hdf5 ? 1 : 0];
}

References m_hdf5.

## readLayers() [1/2]

template<class Data_T>

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

Definition at line 1608 of file Field3DFile.cpp.

{
using std::vector;
using std::string;
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) {
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 = readLayer<Data_T>(*p, *l);
if (mf) {
ret.push_back(mf);
}
}
}
}
return ret;
}
Field3DFileBase::getIntPartitionNames
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
Definition Field3DFile.cpp:564
Field3DFileBase::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 Field3DFile.cpp:577
Field3DInputFile::readLayer
Field< Data_T >::Ptr readLayer(const std::string &intPartitionName, const std::string &layerName) const
This call does the actual reading of a layer. Notice that it expects a unique -internal- partition na...
Definition Field3DFile.cpp:1516
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 Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntScalarLayerNames(), and readLayer().

Referenced by readScalarLayers(), readScalarLayers(), readVectorLayers(), and readVectorLayers().

## readLayers() [2/2]

template<class Data_T>

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

Definition at line 1641 of file Field3DFile.cpp.

{
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 = readLayer<Data_T>(*p, *l);
if (mf)
ret.push_back(mf);
}
}
}
}
return ret;
}
Field3DFileBase::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition Field3DFile.cpp:479

References Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntScalarLayerNames(), readLayer(), and Field3DFileBase::removeUniqueId().

## readScalarLayers() [1/2]

template<class Data_T>

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

inline

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 461 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->readScalarLayers<Data_T>(layerName);
}
return readLayers<Data_T>(layerName);
}
Field3DInputFile::readLayers
Field< Data_T >::Vec readLayers(const std::string &layerName=std::string("")) const
Definition Field3DFile.cpp:1608

References m_hdf5, and readLayers().

## readScalarLayers() [2/2]

template<class Data_T>

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

inline

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

Definition at line 472 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->readScalarLayers<Data_T>(partitionName, layerName);
}
return readLayers<Data_T>(partitionName, layerName);
}

References m_hdf5, and readLayers().

## readVectorLayers() [1/2]

template<class Data_T>

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

inline

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 487 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->readVectorLayers<Data_T>(layerName);
}
return readLayers<FIELD3D_VEC3_T<Data_T> >(layerName);
}

References m_hdf5, and readLayers().

## readVectorLayers() [2/2]

template<class Data_T>

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

inline

This version allows you to pass in the partition name.

Definition at line 498 of file Field3DFile.h.

{
if (m_hdf5) {
return m_hdf5->readVectorLayers<Data_T>(partitionName, layerName);
}
return readLayers<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName);
}

References m_hdf5, and readLayers().

## readProxyLayer() [1/2]

template<class Data_T>

EmptyField< Data_T >::Vec Field3DInputFile::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 1755 of file Field3DFile.cpp.

{
using namespace boost;
using namespace std;
using namespace Hdf5Util;
if (m_hdf5) {
return m_hdf5->readProxyLayer<Data_T>(partitionName, layerName,
isVectorLayer);
}
// 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
File::Partition::Ptr part = partition(*p);
if (!part) {
Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
return emptyList;
}
// Find the layer
const File::Layer *layer;
if (isVectorLayer) {
layer = part->layer(layerName);
} else {
layer = part->layer(layerName);
}
if (!layer) {
Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
return emptyList;
}
// Open the layer group
string layerPath = layer->parent + "/" + layer->name;
OgIGroup parent = m_root->findGroup(layer->parent);
if (!parent.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't find layer parent "
+ layerPath + " in .f3d file ");
return emptyList;
}
OgIGroup layerGroup = parent.findGroup(layer->name);
if (!layerGroup.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't find layer group "
+ layerPath + " 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;
OgIGroup mipGroup = layerGroup.findGroup("mip_levels");
if (mipGroup.isValid()) {
OgIAttribute<uint32_t> levelsAttr =
mipGroup.findAttribute<uint32_t>("levels");
if (levelsAttr.isValid()) {
numLevels = levelsAttr.value();
}
}
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;
}
EmptyField::Ptr
boost::intrusive_ptr< EmptyField > Ptr
Definition EmptyField.h:93
EmptyField::Vec
std::vector< Ptr > Vec
Definition EmptyField.h:94
Field3DFileBase::partition
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DFileBase::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 Field3DFile.cpp:597
Field3DInputFile::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 Field3DFile.cpp:1755
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
File::Layer::name
std::string name
The name of the layer (always available).
Definition Field3DFile.h:100
File::Layer::parent
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition Field3DFile.h:103
File::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition Field3DFile.h:127

References Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntScalarLayerNames(), Field3DFileBase::getIntVectorLayerNames(), m_hdf5, m_root, FieldBase::metadata(), File::Layer::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), readProxyLayer(), Field3DFileBase::removeUniqueId(), FieldMetadata::setIntMetadata(), and Msg::SevWarning.

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

## readProxyScalarLayers()

template<class Data_T>

EmptyField< Data_T >::Vec Field3DInputFile::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 1858 of file Field3DFile.cpp.

{
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;
}
Field3DFileBase::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 Field3DFile.cpp:514
Field3DFileBase::getPartitionNames
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
Definition Field3DFile.cpp:492

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

## readProxyVectorLayers()

template<class Data_T>

EmptyField< Data_T >::Vec Field3DInputFile::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 1893 of file Field3DFile.cpp.

{
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;
}
Field3DFileBase::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 Field3DFile.cpp:539

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

## closeInternal()

virtual void Field3DInputFile::closeInternal | ( |  | ) |

inline private virtual

Closes the file if open.

Implements Field3DFileBase.

Definition at line 547 of file Field3DFile.h.

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

References cleanup(), and m_hdf5.

## cleanup()

void Field3DInputFile::cleanup | ( |  | ) |

inline private

Definition at line 557 of file Field3DFile.h.

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

References m_archive, Field3DFileBase::m_partitions, and m_root.

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

## readLayer()

template<class Data_T>

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

private

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

Definition at line 1516 of file Field3DFile.cpp.

{
typedef typename Field<Data_T>::Ptr FieldPtr;
// Instantiate a null pointer for easier code reading
FieldPtr nullPtr;
// Find the partition
File::Partition::Ptr part = partition(intPartitionName);
if (!part) {
Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
return nullPtr;
}
// Find the layer
const File::Layer *layer = part->layer(layerName);
if (!layer) {
Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
return nullPtr;
}
// Open the partition group
const OgIGroup partitionGroup = m_root->findGroup(intPartitionName);
if (!partitionGroup.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't open partition group " +
intPartitionName);
return nullPtr;
}
// Open the layer group
const OgIGroup layerGroup = partitionGroup.findGroup(layerName);
if (!layerGroup.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't open layer group " +
layerName);
return nullPtr;
}
// Get the class name
string layerPath = layer->parent + "/" + layer->name;
string className;
try {
className = layerGroup.findAttribute<string>("class_name").value();
}
catch (OgIAttributeException &e) {
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
typename Field<Data_T>::Ptr field;
field = readField<Data_T>(className, layerGroup, m_filename, layerPath);
if (!field) {
// This isn't really an error
return nullPtr;
}
// Read the metadata
const OgIGroup metadataGroup = layerGroup.findGroup("metadata");
if (metadataGroup.isValid()) {
readMetadata(metadataGroup, field);
}
// Set the name of the field appropriately
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
Field3DFileBase::intPartitionName
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
Definition Field3DFile.cpp:422
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(), FieldCache< Data_T >::getCachedField(), Field3DFileBase::intPartitionName(), m_filename, m_root, FieldBase::name, File::Layer::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), readField(), readMetadata(), Field3DFileBase::removeUniqueId(), FieldRes::setMapping(), Msg::SevWarning, and FieldCache< Data_T >::singleton().

Referenced by readLayers(), and readLayers().

## readProxyLayer() [2/2]

template<class Data_T>

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

private

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

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

Definition at line 1680 of file Field3DFile.cpp.

{
using namespace boost;
using namespace std;
typename EmptyField<Data_T>::Ptr null;
const std::string extentsMinStr("extents_min");
const std::string extentsMaxStr("extents_max");
const std::string dataWindowMinStr("data_window_min");
const std::string dataWindowMaxStr("data_window_max");
Box3i extents, dataW;
// Get extents ---
OgIAttribute<veci32_t> extMinAttr =
location.findAttribute<veci32_t>(extentsMinStr);
OgIAttribute<veci32_t> extMaxAttr =
location.findAttribute<veci32_t>(extentsMaxStr);
if (!extMinAttr.isValid()) {
throw MissingAttributeException("Couldn't find attribute " +
extentsMinStr);
}
if (!extMaxAttr.isValid()) {
throw MissingAttributeException("Couldn't find attribute " +
extentsMaxStr);
}
extents.min = extMinAttr.value();
extents.max = extMaxAttr.value();
// Get data window ---
OgIAttribute<veci32_t> dwMinAttr =
location.findAttribute<veci32_t>(dataWindowMinStr);
OgIAttribute<veci32_t> dwMaxAttr =
location.findAttribute<veci32_t>(dataWindowMaxStr);
if (!dwMinAttr.isValid()) {
throw MissingAttributeException("Couldn't find attribute " +
dataWindowMinStr);
}
if (!dwMaxAttr.isValid()) {
throw MissingAttributeException("Couldn't find attribute " +
dataWindowMaxStr);
}
dataW.min = dwMinAttr.value();
dataW.max = dwMaxAttr.value();
// Construct the field
typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
field->setSize(extents, dataW);
// Read the metadata
OgIGroup metadataGroup = location.findGroup("metadata");
if (metadataGroup.isValid()) {
readMetadata(metadataGroup, field);
}
// Set field properties
field->name = name;
field->attribute = attribute;
field->setMapping(mapping);
return field;
}
Box3i
Imath::Box3i Box3i
Definition SpiMathLib.h:77

References FieldBase::attribute, FieldBase::name, readMetadata(), FieldRes::setMapping(), and ResizableField< Data_T >::setSize().

## readPartitionAndLayerInfo()

bool Field3DInputFile::readPartitionAndLayerInfo | ( |  | ) |

private

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

Definition at line 857 of file Field3DFile.cpp.

{
// Find all the partition names
std::vector<std::string> groups = m_root->groupNames();
// Store the partition names
m_partitions.clear();
for (std::vector<std::string>::const_iterator i = groups.begin(),
end = groups.end(); i != end; ++i) {
// Grab the name
const std::string &name = *i;
// Skip metadata
if (name == "field3d_global_metadata") {
continue;
}
// Build partition
File::Partition::Ptr part(new File::Partition);
part->name = name;
m_partitions.push_back(part);
}
// For each partition, find its mapping ---
for (PartitionList::iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
// Grab the name
const std::string &name = (**i).name;
// Open the partition group
const OgIGroup partitionGroup = m_root->findGroup(name);
if (!partitionGroup.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't open partition group " + name);
}
// Open the mapping group
const OgIGroup mappingGroup = partitionGroup.findGroup(k_mappingStr);
if (!mappingGroup.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't open mapping group " + name);
}
// Build the mapping
FieldMapping::Ptr mapping = readFieldMapping(mappingGroup);
#if 0
if (!mapping) {
Msg::print(Msg::SevWarning, "Got a null pointer when reading mapping");
throw ReadMappingException((**i).name);
}
#endif
// 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) {
// Grab the name
const std::string &partitionName = (**i).name;
// Open the partition group
const OgIGroup partitionGroup = m_root->findGroup(partitionName);
if (!partitionGroup.isValid()) {
Msg::print(Msg::SevWarning, "Couldn't open partition group " +
partitionName);
}
// Get all the layer names
groups = partitionGroup.groupNames();
for (std::vector<std::string>::const_iterator l = groups.begin(),
lEnd = groups.end(); l != lEnd; ++l) {
// Grab layer name
const std::string layerName = *l;
// Skip the mapping group
if (layerName == k_mappingStr) {
continue;
}
// Construct the layer
File::Layer layer;
layer.name = *l;
layer.parent = partitionName;
// Add to partition
partition(partitionName)->addLayer(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
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92

References Field3DFileBase::m_partitions, m_root, File::Layer::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), readFieldMapping(), and Msg::SevWarning.

Referenced by open().

## readMetadata() [1/2]

bool Field3DInputFile::readMetadata | ( | const OgIGroup & | metadataGroup,
|  | FieldBase::Ptr | field ) const

private

Read metadata for this layer.

Definition at line 942 of file Field3DFile.cpp.

{
return readMeta(metadataGroup, field->metadata());
}

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

## readMetadata() [2/2]

bool Field3DInputFile::readMetadata | ( | const OgIGroup & | metadataGroup | ) |

private

Read global metadata for this file.

Definition at line 950 of file Field3DFile.cpp.

{
return readMeta(metadataGroup, metadata());
}
Field3DFileBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field3DFile.h:276

References Field3DFileBase::metadata().

## Member Data Documentation

## m_filename

std::string Field3DInputFile::m_filename

private

Filename, only to be set by open().

Definition at line 600 of file Field3DFile.h.

Referenced by open(), and readLayer().

## m_archive

boost::shared_ptr<Alembic::Ogawa::IArchive> Field3DInputFile::m_archive

private

Pointer to the Ogawa archive.

Definition at line 602 of file Field3DFile.h.

Referenced by cleanup(), and open().

## m_root

boost::shared_ptr<OgIGroup> Field3DInputFile::m_root

private

Pointer to root group.

Definition at line 604 of file Field3DFile.h.

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

## m_hdf5

boost::shared_ptr<Field3DInputFileHDF5> Field3DInputFile::m_hdf5

private

HDF5 fallback.

Definition at line 607 of file Field3DFile.h.

Referenced by closeInternal(), encoding(), open(), readProxyLayer(), readScalarLayers(), readScalarLayers(), readVectorLayers(), and readVectorLayers().

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

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