Field3D
Field3DInputFile Class Reference

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

#include <Field3DFile.h>

Inheritance diagram for Field3DInputFile:
Field3DFileBase MetadataCallback

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.
 
FieldMetadatametadata ()
 accessor to the m_metadata class
 
const FieldMetadatametadata () 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< Field3DInputFileHDF5m_hdf5
 HDF5 fallback.
 
boost::shared_ptr< OgIGroupm_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, intPartitionCountMap
 
typedef std::vector< File::Partition::PtrPartitionList
 
- 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< Field3DFileHDF5Basem_hdf5Base
 HDF5 fallback.
 
std::vector< LayerInfom_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.

701{
702 // Empty
703}

◆ ~Field3DInputFile()

Field3DInputFile::~Field3DInputFile ( )
virtual

Definition at line 707 of file Field3DFile.cpp.

708{
709 cleanup();
710}

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.

715{
716 clear();
717
718 bool success = true;
719
720 // Record filename
721 m_filename = filename;
722
723 try {
724
725 // Throws exceptions if the file doesn't exist.
726 checkFile(filename);
727
728 // Open the Ogawa archive
729 m_archive.reset(new Alembic::Ogawa::IArchive(filename));
730
731 // Error check and HDF5 fallback
732 if (!m_archive->isValid()) {
733 m_hdf5.reset(new Field3DInputFileHDF5);
735 if (m_hdf5->open(filename)) {
736 // Handled. Just return.
737 return true;
738 } else {
739 throw NoSuchFileException(filename);
740 }
741 }
742
743 // Grab the root group
744 m_root.reset(new OgIGroup(*m_archive));
745
746 // Check version number
747 try {
748 OgIAttribute<veci32_t> version =
749 m_root->findAttribute<veci32_t>(k_versionAttrName);
750 if (!version.isValid()) {
751 throw OgIAttributeException("Missing version attribute.");
752 }
753 int fileVersion[3] = { version.value()[0],
754 version.value()[1],
755 version.value()[2] };
758 versionStr << fileVersion[0] << "."
759 << fileVersion[1] << "."
760 << fileVersion[2];
762 }
763 }
764 catch (OgIAttributeException &e) {
765
766 }
767
768 // Read the global metadata. This does not always exists,
769 // depends on if it was written or not.
770 try {
771 const OgIGroup metadataGroup = m_root->findGroup("field3d_global_metadata");
772 if (metadataGroup.isValid()) {
774 }
775 }
776 catch (...) {
778 "Unknown error when reading file metadata ");
779 }
780
781 // Read the partition and layer info
782 try {
784 success = false;
785 }
786 }
787 catch (MissingGroupException &e) {
788 Msg::print(Msg::SevWarning, "Missing group: " + string(e.what()));
789 throw BadFileHierarchyException(filename);
790 }
791 catch (ReadMappingException &e) {
792 Msg::print(Msg::SevWarning, "Couldn't read mapping for partition: "
793 + string(e.what()));
794 throw BadFileHierarchyException(filename);
795 }
796 catch (Exception &e) {
797 Msg::print(Msg::SevWarning, "Unknown error when reading file hierarchy: "
798 + string(e.what()));
799 throw BadFileHierarchyException(filename);
800 }
801 catch (...) {
803 "Unknown error when reading file hierarchy. ");
804 throw BadFileHierarchyException(filename);
805 }
806 }
807 catch (NoSuchFileException &e) {
808 Msg::print(Msg::SevWarning, "Couldn't open file: "
809 + string(e.what()) );
810 success = false;
811 }
814 "In file: " + filename + " - "
815 + string(e.what()) );
816 success = false;
817 }
820 "In file: " + filename + " - File version can not be read: "
821 + string(e.what()));
822 success = false;
823 }
824 catch (BadFileHierarchyException &) {
826 "In file: " + filename + " - Bad file hierarchy. ");
827 success = false;
828 }
829 catch (runtime_error &e) {
830 // HDF5 fallback
831 m_hdf5.reset(new Field3DInputFileHDF5);
833 if (m_hdf5->open(filename)) {
834 // Handled. Just return.
835 return true;
836 } else {
838 "In file: " + filename + ": " + string(e.what()));
839 success = false;
840 }
841 }
842 catch (...) {
844 "In file: " + filename + " Unknown exception ");
845 success = false;
846 }
847
848 if (!success) {
849 close();
850 }
851
852 return success;
853}
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
Field3D::V3i veci32_t
Definition Traits.h:94
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
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....
Provides reading of .f3d (internally, hdf5) files.
std::string m_filename
Filename, only to be set by open().
boost::shared_ptr< OgIGroup > m_root
Pointer to root group.
boost::shared_ptr< Field3DInputFileHDF5 > m_hdf5
HDF5 fallback.
boost::shared_ptr< Alembic::Ogawa::IArchive > m_archive
Pointer to the Ogawa archive.
bool readPartitionAndLayerInfo()
Sets up all the partitions and layers, but does not load any data.
bool readMetadata(const OgIGroup &metadataGroup, FieldBase::Ptr field) const
Read metadata for this layer.
@ SevWarning
Definition Log.h:68
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(), FIELD3D_MTX_T, 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.

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

References FIELD3D_MTX_T.

◆ 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.

1609{
1610 using std::vector;
1611 using std::string;
1612
1613 typedef typename Field<Data_T>::Ptr FieldPtr;
1614 typedef typename Field<Data_T>::Vec FieldList;
1615
1616 FieldList ret;
1617 std::vector<std::string> parts;
1619
1620 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1623 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1624 // Only read if it matches the name
1625 if ((name.length() == 0) || (*l == name)) {
1626 FieldPtr mf = readLayer<Data_T>(*p, *l);
1627 if (mf) {
1628 ret.push_back(mf);
1629 }
1630 }
1631 }
1632 }
1633
1634 return ret;
1635}
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 ...
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition Field.h:403
boost::intrusive_ptr< Field > Ptr
Definition Field.h:395

References FIELD3D_MTX_T, Field3DFileBase::getIntPartitionNames(), and Field3DFileBase::getIntScalarLayerNames().

◆ 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.

1643{
1644 using namespace std;
1645
1646 typedef typename Field<Data_T>::Ptr FieldPtr;
1647 typedef typename Field<Data_T>::Vec FieldList;
1648
1649 FieldList ret;
1650
1651 if ((layerName.length() == 0) || (partitionName.length() == 0))
1652 return ret;
1653
1654 std::vector<std::string> parts;
1656
1657 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1658 std::vector<std::string> layers;
1660 if (removeUniqueId(*p) == partitionName) {
1661 for (vector<string>::iterator l = layers.begin();
1662 l != layers.end(); ++l) {
1663 // Only read if it matches the name
1664 if (*l == layerName) {
1665 FieldPtr mf = readLayer<Data_T>(*p, *l);
1666 if (mf)
1667 ret.push_back(mf);
1668 }
1669 }
1670 }
1671 }
1672
1673 return ret;
1674}
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.

References FIELD3D_MTX_T, Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntScalarLayerNames(), 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
layerNameIf a string is passed in, only layers of that name will be read from disk.

Definition at line 461 of file Field3DFile.h.

462 {
463 if (m_hdf5) {
464 return m_hdf5->readScalarLayers<Data_T>(layerName);
465 }
467 }

References FIELD3D_MTX_T.

◆ 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.

474 {
475 if (m_hdf5) {
476 return m_hdf5->readScalarLayers<Data_T>(partitionName, layerName);
477 }
478 return readLayers<Data_T>(partitionName, layerName);
479 }

References FIELD3D_MTX_T.

◆ 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
layerNameIf a string is passed in, only layers of that name will be read from disk.

Definition at line 487 of file Field3DFile.h.

488 {
489 if (m_hdf5) {
490 return m_hdf5->readVectorLayers<Data_T>(layerName);
491 }
493 }

References FIELD3D_MTX_T.

◆ 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.

500 {
501 if (m_hdf5) {
502 return m_hdf5->readVectorLayers<Data_T>(partitionName, layerName);
503 }
504 return readLayers<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName);
505 }

References FIELD3D_MTX_T.

◆ 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
nameIf a string is passed in, only layers of that name will be read from disk.

Definition at line 1755 of file Field3DFile.cpp.

1758{
1759 using namespace boost;
1760 using namespace std;
1761 using namespace Hdf5Util;
1762
1763 if (m_hdf5) {
1764 return m_hdf5->readProxyLayer<Data_T>(partitionName, layerName,
1766 }
1767
1768 // Instantiate a null pointer for easier code reading
1770
1771 if ((layerName.length() == 0) || (partitionName.length() == 0))
1772 return emptyList;
1773
1774 std::vector<std::string> parts, layers;
1776
1777 bool foundPartition = false;
1778
1779 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1780 if (removeUniqueId(*p) == partitionName) {
1781 foundPartition = true;
1782 if (isVectorLayer) {
1784 } else {
1786 }
1787 for (vector<string>::iterator l = layers.begin();
1788 l != layers.end(); ++l) {
1789 if (*l == layerName) {
1790 // Find the partition
1792 if (!part) {
1793 Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
1794 return emptyList;
1795 }
1796 // Find the layer
1797 const File::Layer *layer;
1798 if (isVectorLayer) {
1799 layer = part->layer(layerName);
1800 } else {
1801 layer = part->layer(layerName);
1802 }
1803 if (!layer) {
1804 Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1805 return emptyList;
1806 }
1807 // Open the layer group
1808 string layerPath = layer->parent + "/" + layer->name;
1809 OgIGroup parent = m_root->findGroup(layer->parent);
1810 if (!parent.isValid()) {
1811 Msg::print(Msg::SevWarning, "Couldn't find layer parent "
1812 + layerPath + " in .f3d file ");
1813 return emptyList;
1814 }
1815 OgIGroup layerGroup = parent.findGroup(layer->name);
1816 if (!layerGroup.isValid()) {
1817 Msg::print(Msg::SevWarning, "Couldn't find layer group "
1818 + layerPath + " in .f3d file ");
1819 return emptyList;
1820 }
1821
1822 // Make the proxy representation
1823 typename EmptyField<Data_T>::Ptr field =
1825 part->mapping);
1826
1827 // Read MIPField's number of mip levels
1828 int numLevels = 0;
1829 OgIGroup mipGroup = layerGroup.findGroup("mip_levels");
1830 if (mipGroup.isValid()) {
1832 mipGroup.findAttribute<uint32_t>("levels");
1833 if (levelsAttr.isValid()) {
1834 numLevels = levelsAttr.value();
1835 }
1836 }
1837 field->metadata().setIntMetadata("mip_levels", numLevels);
1838
1839 // Add field to output
1840 output.push_back(field);
1841 }
1842 }
1843 }
1844 }
1845
1846 if (!foundPartition) {
1847 Msg::print(Msg::SevWarning, "Couldn't find partition: " + partitionName);
1848 return emptyList;
1849 }
1850
1851 return output;
1852}
boost::intrusive_ptr< EmptyField > Ptr
Definition EmptyField.h:93
std::vector< Ptr > Vec
Definition EmptyField.h:94
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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 ...
FieldMetadata & metadata()
accessor to the m_metadata class
Definition Field.h:155
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.
std::string name
The name of the layer (always available)
std::string parent
The name of the parent partition. We need this in order to open its group.
boost::intrusive_ptr< Partition > Ptr
Contains utility functions and classes for Hdf5 files.
Definition Hdf5Util.h:86

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

◆ 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
nameIf a string is passed in, only layers of that name will be read from disk.

Definition at line 1858 of file Field3DFile.cpp.

1859{
1860 using namespace std;
1861
1862 typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1863 typedef std::vector<FieldPtr> FieldList;
1864
1865 FieldList ret;
1866
1867 std::vector<std::string> parts;
1869
1870 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1871 std::vector<std::string> layers;
1873 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1874 // Only read if it matches the name
1875 if ((name.length() == 0) || (*l == name)) {
1876 FieldList f = readProxyLayer<Data_T>(*p, *l, false);
1877 for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1878 if (*i) {
1879 ret.push_back(*i);
1880 }
1881 }
1882 }
1883 }
1884 }
1885
1886 return ret;
1887}
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 getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.

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

◆ 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
nameIf a string is passed in, only layers of that name will be read from disk.

Definition at line 1893 of file Field3DFile.cpp.

1894{
1895 using namespace std;
1896
1897 typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1898 typedef std::vector<FieldPtr> FieldList;
1899
1900 FieldList ret;
1901
1902 std::vector<std::string> parts;
1904
1905 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1906 std::vector<std::string> layers;
1908 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1909 // Only read if it matches the name
1910 if ((name.length() == 0) || (*l == name)) {
1911 FieldList f = readProxyLayer<Data_T>(*p, *l, true);
1912 for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1913 if (*i) {
1914 ret.push_back(*i);
1915 }
1916 }
1917 }
1918 }
1919 }
1920
1921 return ret;
1922}
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.

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

◆ closeInternal()

virtual void Field3DInputFile::closeInternal ( )
inlineprivatevirtual

Closes the file if open.

Implements Field3DFileBase.

Definition at line 547 of file Field3DFile.h.

548 {
549 if (m_hdf5) {
550 m_hdf5->closeInternal();
551 return;
552 }
553
554 cleanup();
555 }

◆ cleanup()

void Field3DInputFile::cleanup ( )
inlineprivate

Definition at line 557 of file Field3DFile.h.

558 {
559 // The destruction of the various Ogawa components must happen in the
560 // right order
561
562 // First, the partition groups
563 m_partitions.clear();
564 // Then the root group
565 m_root.reset();
566 // Finally, the archive
567 m_archive.reset();
568 }
PartitionList m_partitions
Vector of partitions.

Referenced by ~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.

1518{
1519 typedef typename Field<Data_T>::Ptr FieldPtr;
1520
1521 // Instantiate a null pointer for easier code reading
1522 FieldPtr nullPtr;
1523
1524 // Find the partition
1526 if (!part) {
1527 Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
1528 return nullPtr;
1529 }
1530
1531 // Find the layer
1532 const File::Layer *layer = part->layer(layerName);
1533 if (!layer) {
1534 Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1535 return nullPtr;
1536 }
1537
1538 // Open the partition group
1539 const OgIGroup partitionGroup = m_root->findGroup(intPartitionName);
1540 if (!partitionGroup.isValid()) {
1541 Msg::print(Msg::SevWarning, "Couldn't open partition group " +
1543 return nullPtr;
1544 }
1545
1546 // Open the layer group
1547 const OgIGroup layerGroup = partitionGroup.findGroup(layerName);
1548 if (!layerGroup.isValid()) {
1549 Msg::print(Msg::SevWarning, "Couldn't open layer group " +
1550 layerName);
1551 return nullPtr;
1552 }
1553
1554 // Get the class name
1555 string layerPath = layer->parent + "/" + layer->name;
1556 string className;
1557 try {
1558 className = layerGroup.findAttribute<string>("class_name").value();
1559 }
1560 catch (OgIAttributeException &e) {
1561 Msg::print(Msg::SevWarning, "Couldn't find class_name attrib in layer " +
1562 layerName);
1563 return nullPtr;
1564 }
1565
1566 // Check the cache
1567
1569 FieldPtr cachedField = cache.getCachedField(m_filename, layerPath);
1570
1571 if (cachedField) {
1572 return cachedField;
1573 }
1574
1575 // Construct the field and load the data
1576
1577 typename Field<Data_T>::Ptr field;
1578 field = readField<Data_T>(className, layerGroup, m_filename, layerPath);
1579
1580 if (!field) {
1581 // This isn't really an error
1582 return nullPtr;
1583 }
1584
1585 // Read the metadata
1586 const OgIGroup metadataGroup = layerGroup.findGroup("metadata");
1587 if (metadataGroup.isValid()) {
1589 }
1590
1591 // Set the name of the field appropriately
1593 field->attribute = layerName;
1594 field->setMapping(part->mapping);
1595
1596 // Cache the field for future use
1597 if (field) {
1598 cache.cacheField(field, m_filename, layerPath);
1599 }
1600
1601 return field;
1602}
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 ...
std::string attribute
Optional name of the attribute the field represents.
Definition Field.h:173
std::string name
Optional name of the field.
Definition Field.h:171
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Definition FieldCache.h:135
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition Field.h:347

References FieldBase::attribute, FIELD3D_MTX_T, Field3DFileBase::intPartitionName(), m_filename, m_root, FieldBase::name, File::Layer::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), readMetadata(), Field3DFileBase::removeUniqueId(), FieldRes::setMapping(), Msg::SevWarning, and FieldCache< Data_T >::singleton().

◆ 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.

1684{
1685 using namespace boost;
1686 using namespace std;
1687
1689
1690 const std::string extentsMinStr("extents_min");
1691 const std::string extentsMaxStr("extents_max");
1692 const std::string dataWindowMinStr("data_window_min");
1693 const std::string dataWindowMaxStr("data_window_max");
1694
1695 Box3i extents, dataW;
1696
1697 // Get extents ---
1698
1700 location.findAttribute<veci32_t>(extentsMinStr);
1702 location.findAttribute<veci32_t>(extentsMaxStr);
1703 if (!extMinAttr.isValid()) {
1704 throw MissingAttributeException("Couldn't find attribute " +
1706 }
1707 if (!extMaxAttr.isValid()) {
1708 throw MissingAttributeException("Couldn't find attribute " +
1710 }
1711
1712 extents.min = extMinAttr.value();
1713 extents.max = extMaxAttr.value();
1714
1715 // Get data window ---
1716
1718 location.findAttribute<veci32_t>(dataWindowMinStr);
1720 location.findAttribute<veci32_t>(dataWindowMaxStr);
1721 if (!dwMinAttr.isValid()) {
1722 throw MissingAttributeException("Couldn't find attribute " +
1724 }
1725 if (!dwMaxAttr.isValid()) {
1726 throw MissingAttributeException("Couldn't find attribute " +
1728 }
1729
1730 dataW.min = dwMinAttr.value();
1731 dataW.max = dwMaxAttr.value();
1732
1733 // Construct the field
1734 typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
1735 field->setSize(extents, dataW);
1736
1737 // Read the metadata
1738 OgIGroup metadataGroup = location.findGroup("metadata");
1739 if (metadataGroup.isValid()) {
1741 }
1742
1743 // Set field properties
1744 field->name = name;
1745 field->attribute = attribute;
1746 field->setMapping(mapping);
1747
1748 return field;
1749}
Imath::Box3i Box3i
Definition SpiMathLib.h:77
This subclass of Field does not store any data.
Definition EmptyField.h:88

References FieldBase::attribute, FIELD3D_MTX_T, 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.

858{
859 // Find all the partition names
860 std::vector<std::string> groups = m_root->groupNames();
861
862 // Store the partition names
863 m_partitions.clear();
864 for (std::vector<std::string>::const_iterator i = groups.begin(),
865 end = groups.end(); i != end; ++i) {
866 // Grab the name
867 const std::string &name = *i;
868 // Skip metadata
869 if (name == "field3d_global_metadata") {
870 continue;
871 }
872 // Build partition
874 part->name = name;
875 m_partitions.push_back(part);
876 }
877
878 // For each partition, find its mapping ---
879
880 for (PartitionList::iterator i = m_partitions.begin();
881 i != m_partitions.end(); ++i) {
882 // Grab the name
883 const std::string &name = (**i).name;
884 // Open the partition group
885 const OgIGroup partitionGroup = m_root->findGroup(name);
886 if (!partitionGroup.isValid()) {
887 Msg::print(Msg::SevWarning, "Couldn't open partition group " + name);
888 }
889 // Open the mapping group
891 if (!mappingGroup.isValid()) {
892 Msg::print(Msg::SevWarning, "Couldn't open mapping group " + name);
893 }
894 // Build the mapping
896#if 0
897 if (!mapping) {
898 Msg::print(Msg::SevWarning, "Got a null pointer when reading mapping");
899 throw ReadMappingException((**i).name);
900 }
901#endif
902 // Attach the mapping to the partition
903 (**i).mapping = mapping;
904 }
905
906 // ... And then find its layers ---
907
908 for (PartitionList::const_iterator i = m_partitions.begin();
909 i != m_partitions.end(); ++i) {
910 // Grab the name
911 const std::string &partitionName = (**i).name;
912 // Open the partition group
913 const OgIGroup partitionGroup = m_root->findGroup(partitionName);
914 if (!partitionGroup.isValid()) {
915 Msg::print(Msg::SevWarning, "Couldn't open partition group " +
916 partitionName);
917 }
918 // Get all the layer names
919 groups = partitionGroup.groupNames();
920 for (std::vector<std::string>::const_iterator l = groups.begin(),
921 lEnd = groups.end(); l != lEnd; ++l) {
922 // Grab layer name
923 const std::string layerName = *l;
924 // Skip the mapping group
925 if (layerName == k_mappingStr) {
926 continue;
927 }
928 // Construct the layer
929 File::Layer layer;
930 layer.name = *l;
931 layer.parent = partitionName;
932 // Add to partition
933 partition(partitionName)->addLayer(layer);
934 }
935 }
936
937 return true;
938}
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
boost::intrusive_ptr< FieldMapping > Ptr

References FIELD3D_MTX_T, 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.

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

References FIELD3D_MTX_T.

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.

951{
953}
FieldMetadata & metadata()
accessor to the m_metadata class

References FIELD3D_MTX_T, and 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 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 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 open(), and readProxyLayer().


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