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. More...
 
bool open (const std::string &filename)
 Opens the given file. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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 . More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from Field3DFileBase
void clear ()
 Clear the data structures and close the file. More...
 
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. More...
 
FieldMetadatametadata ()
 accessor to the m_metadata class More...
 
const FieldMetadatametadata () const
 Read only access to the m_metadata class. More...
 
virtual void metadataHasChanged (const std::string &)
 This function should implemented by concrete classes to
get the callback when metadata changes. More...
 
 Field3DFileBase ()
 
virtual ~Field3DFileBase ()=0
 Pure virtual destructor to ensure we never instantiate this class. More...
 
void getPartitionNames (std::vector< std::string > &names) const
 Gets the names of all the partitions in the file. More...
 
void getScalarLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
 Gets the names of all the scalar layers in a given partition. More...
 
void getVectorLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
 Gets the names of all the vector layers in a given partition. More...
 
void addGroupMembership (const GroupMembershipMap &groupMembers)
 Add to the group membership. More...
 
void printHierarchy () const
 

Private Member Functions

void cleanup ()
 
virtual void closeInternal ()
 Closes the file if open. More...
 
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. More...
 
bool readMetadata (const OgIGroup &metadataGroup)
 Read global metadata for this file. More...
 
bool readMetadata (const OgIGroup &metadataGroup, FieldBase::Ptr field) const
 Read metadata for this layer. More...
 
bool readPartitionAndLayerInfo ()
 Sets up all the partitions and layers, but does not load any data. More...
 
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. More...
 

Private Attributes

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

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::PtrPartitionList
 
- Protected Member Functions inherited from Field3DFileBase
File::Partition::Ptr getPartition (const std::string &partitionName) const
 Returns a pointer to the given partition. More...
 
File::Partition::Ptr partition (const std::string &partitionName)
 Returns a pointer to the given partition. More...
 
File::Partition::Ptr partition (const std::string &partitionName) const
 Returns a pointer to the given partition. More...
 
void getIntPartitionNames (std::vector< std::string > &names) const
 Gets the names of all the -internal- partitions in the file. More...
 
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. More...
 
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. More...
 
int numIntPartitions (const std::string &partitionName) const
 Returns the number of internal partitions for a given partition name. More...
 
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. More...
 
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. More...
 
std::string removeUniqueId (const std::string &partitionName) const
 Strips any unique identifiers from the partition name and returns the original name. More...
 
- 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 ..."
More...
 
boost::shared_ptr< Field3DFileHDF5Basem_hdf5Base
 HDF5 fallback. More...
 
std::vector< LayerInfom_layerInfo
 This stores layer info. More...
 
FieldMetadata m_metadata
 metadata More...
 
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. More...
 
std::vector< std::string > m_partitionNames
 This stores partition names. More...
 
PartitionList m_partitions
 Vector of partitions. More...
 

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);
734  m_hdf5Base = m_hdf5;
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] };
756  if (!isSupportedFileVersion(fileVersion, k_minFileVersion)) {
757  stringstream versionStr;
758  versionStr << fileVersion[0] << "."
759  << fileVersion[1] << "."
760  << fileVersion[2];
761  throw UnsupportedVersionException(versionStr.str());
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()) {
773  readMetadata(metadataGroup);
774  }
775  }
776  catch (...) {
778  "Unknown error when reading file metadata ");
779  }
780 
781  // Read the partition and layer info
782  try {
783  if (!readPartitionAndLayerInfo()) {
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  }
812  catch (MissingAttributeException &e) {
814  "In file: " + filename + " - "
815  + string(e.what()) );
816  success = false;
817  }
818  catch (UnsupportedVersionException &e) {
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 (...) {
831  "In file: " + filename + " Unknown exception ");
832  success = false;
833  }
834 
835  if (!success) {
836  close();
837  }
838 
839  return success;
840 }

References Field3DFileBase::clear(), Field3DFileBase::close(), m_archive, m_filename, m_hdf5, Field3DFileBase::m_hdf5Base, m_root, Msg::print(), readMetadata(), readPartitionAndLayerInfo(), Msg::SevWarning, and Exc::Exception::what().

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  }

◆ readLayers() [1/2]

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

Definition at line 1595 of file Field3DFile.cpp.

1596 {
1597  using std::vector;
1598  using std::string;
1599 
1600  typedef typename Field<Data_T>::Ptr FieldPtr;
1601  typedef typename Field<Data_T>::Vec FieldList;
1602 
1603  FieldList ret;
1604  std::vector<std::string> parts;
1605  getIntPartitionNames(parts);
1606 
1607  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1608  vector<std::string> layers;
1609  getIntScalarLayerNames(layers, *p);
1610  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1611  // Only read if it matches the name
1612  if ((name.length() == 0) || (*l == name)) {
1613  FieldPtr mf = readLayer<Data_T>(*p, *l);
1614  if (mf) {
1615  ret.push_back(mf);
1616  }
1617  }
1618  }
1619  }
1620 
1621  return ret;
1622 }

References 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 1628 of file Field3DFile.cpp.

1630 {
1631  using namespace std;
1632 
1633  typedef typename Field<Data_T>::Ptr FieldPtr;
1634  typedef typename Field<Data_T>::Vec FieldList;
1635 
1636  FieldList ret;
1637 
1638  if ((layerName.length() == 0) || (partitionName.length() == 0))
1639  return ret;
1640 
1641  std::vector<std::string> parts;
1642  getIntPartitionNames(parts);
1643 
1644  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1645  std::vector<std::string> layers;
1646  getIntScalarLayerNames(layers, *p);
1647  if (removeUniqueId(*p) == partitionName) {
1648  for (vector<string>::iterator l = layers.begin();
1649  l != layers.end(); ++l) {
1650  // Only read if it matches the name
1651  if (*l == layerName) {
1652  FieldPtr mf = readLayer<Data_T>(*p, *l);
1653  if (mf)
1654  ret.push_back(mf);
1655  }
1656  }
1657  }
1658  }
1659 
1660  return ret;
1661 }

References 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  }
466  return readLayers<Data_T>(layerName);
467  }

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

◆ 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  }
492  return readLayers<FIELD3D_VEC3_T<Data_T> >(layerName);
493  }

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

◆ 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 1742 of file Field3DFile.cpp.

1745 {
1746  using namespace boost;
1747  using namespace std;
1748  using namespace Hdf5Util;
1749 
1750  if (m_hdf5) {
1751  return m_hdf5->readProxyLayer<Data_T>(partitionName, layerName,
1752  isVectorLayer);
1753  }
1754 
1755  // Instantiate a null pointer for easier code reading
1756  typename EmptyField<Data_T>::Vec emptyList, output;
1757 
1758  if ((layerName.length() == 0) || (partitionName.length() == 0))
1759  return emptyList;
1760 
1761  std::vector<std::string> parts, layers;
1762  getIntPartitionNames(parts);
1763 
1764  bool foundPartition = false;
1765 
1766  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1767  if (removeUniqueId(*p) == partitionName) {
1768  foundPartition = true;
1769  if (isVectorLayer) {
1770  getIntVectorLayerNames(layers, *p);
1771  } else {
1772  getIntScalarLayerNames(layers, *p);
1773  }
1774  for (vector<string>::iterator l = layers.begin();
1775  l != layers.end(); ++l) {
1776  if (*l == layerName) {
1777  // Find the partition
1778  File::Partition::Ptr part = partition(*p);
1779  if (!part) {
1780  Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
1781  return emptyList;
1782  }
1783  // Find the layer
1784  const File::Layer *layer;
1785  if (isVectorLayer) {
1786  layer = part->layer(layerName);
1787  } else {
1788  layer = part->layer(layerName);
1789  }
1790  if (!layer) {
1791  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1792  return emptyList;
1793  }
1794  // Open the layer group
1795  string layerPath = layer->parent + "/" + layer->name;
1796  OgIGroup parent = m_root->findGroup(layer->parent);
1797  if (!parent.isValid()) {
1798  Msg::print(Msg::SevWarning, "Couldn't find layer parent "
1799  + layerPath + " in .f3d file ");
1800  return emptyList;
1801  }
1802  OgIGroup layerGroup = parent.findGroup(layer->name);
1803  if (!layerGroup.isValid()) {
1804  Msg::print(Msg::SevWarning, "Couldn't find layer group "
1805  + layerPath + " in .f3d file ");
1806  return emptyList;
1807  }
1808 
1809  // Make the proxy representation
1810  typename EmptyField<Data_T>::Ptr field =
1811  readProxyLayer<Data_T>(layerGroup, partitionName, layerName,
1812  part->mapping);
1813 
1814  // Read MIPField's number of mip levels
1815  int numLevels = 0;
1816  OgIGroup mipGroup = layerGroup.findGroup("mip_levels");
1817  if (mipGroup.isValid()) {
1818  OgIAttribute<uint32_t> levelsAttr =
1819  mipGroup.findAttribute<uint32_t>("levels");
1820  if (levelsAttr.isValid()) {
1821  numLevels = levelsAttr.value();
1822  }
1823  }
1824  field->metadata().setIntMetadata("mip_levels", numLevels);
1825 
1826  // Add field to output
1827  output.push_back(field);
1828  }
1829  }
1830  }
1831  }
1832 
1833  if (!foundPartition) {
1834  Msg::print(Msg::SevWarning, "Couldn't find partition: " + partitionName);
1835  return emptyList;
1836  }
1837 
1838  return output;
1839 }

References Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntScalarLayerNames(), Field3DFileBase::getIntVectorLayerNames(), Field3DOutputFile::m_hdf5, Field3DOutputFile::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 1845 of file Field3DFile.cpp.

1846 {
1847  using namespace std;
1848 
1849  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1850  typedef std::vector<FieldPtr> FieldList;
1851 
1852  FieldList ret;
1853 
1854  std::vector<std::string> parts;
1855  getPartitionNames(parts);
1856 
1857  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1858  std::vector<std::string> layers;
1859  getScalarLayerNames(layers, *p);
1860  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1861  // Only read if it matches the name
1862  if ((name.length() == 0) || (*l == name)) {
1863  FieldList f = readProxyLayer<Data_T>(*p, *l, false);
1864  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1865  if (*i) {
1866  ret.push_back(*i);
1867  }
1868  }
1869  }
1870  }
1871  }
1872 
1873  return ret;
1874 }

References 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 1880 of file Field3DFile.cpp.

1881 {
1882  using namespace std;
1883 
1884  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1885  typedef std::vector<FieldPtr> FieldList;
1886 
1887  FieldList ret;
1888 
1889  std::vector<std::string> parts;
1890  getPartitionNames(parts);
1891 
1892  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1893  std::vector<std::string> layers;
1894  getVectorLayerNames(layers, *p);
1895  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1896  // Only read if it matches the name
1897  if ((name.length() == 0) || (*l == name)) {
1898  FieldList f = readProxyLayer<Data_T>(*p, *l, true);
1899  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1900  if (*i) {
1901  ret.push_back(*i);
1902  }
1903  }
1904  }
1905  }
1906  }
1907 
1908  return ret;
1909 }

References 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  }

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 1503 of file Field3DFile.cpp.

1505 {
1506  typedef typename Field<Data_T>::Ptr FieldPtr;
1507 
1508  // Instantiate a null pointer for easier code reading
1509  FieldPtr nullPtr;
1510 
1511  // Find the partition
1513  if (!part) {
1514  Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
1515  return nullPtr;
1516  }
1517 
1518  // Find the layer
1519  const File::Layer *layer = part->layer(layerName);
1520  if (!layer) {
1521  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1522  return nullPtr;
1523  }
1524 
1525  // Open the partition group
1526  const OgIGroup partitionGroup = m_root->findGroup(intPartitionName);
1527  if (!partitionGroup.isValid()) {
1528  Msg::print(Msg::SevWarning, "Couldn't open partition group " +
1530  return nullPtr;
1531  }
1532 
1533  // Open the layer group
1534  const OgIGroup layerGroup = partitionGroup.findGroup(layerName);
1535  if (!layerGroup.isValid()) {
1536  Msg::print(Msg::SevWarning, "Couldn't open layer group " +
1537  layerName);
1538  return nullPtr;
1539  }
1540 
1541  // Get the class name
1542  string layerPath = layer->parent + "/" + layer->name;
1543  string className;
1544  try {
1545  className = layerGroup.findAttribute<string>("class_name").value();
1546  }
1547  catch (OgIAttributeException &e) {
1548  Msg::print(Msg::SevWarning, "Couldn't find class_name attrib in layer " +
1549  layerName);
1550  return nullPtr;
1551  }
1552 
1553  // Check the cache
1554 
1556  FieldPtr cachedField = cache.getCachedField(m_filename, layerPath);
1557 
1558  if (cachedField) {
1559  return cachedField;
1560  }
1561 
1562  // Construct the field and load the data
1563 
1564  typename Field<Data_T>::Ptr field;
1565  field = readField<Data_T>(className, layerGroup, m_filename, layerPath);
1566 
1567  if (!field) {
1568  // This isn't really an error
1569  return nullPtr;
1570  }
1571 
1572  // Read the metadata
1573  const OgIGroup metadataGroup = layerGroup.findGroup("metadata");
1574  if (metadataGroup.isValid()) {
1575  readMetadata(metadataGroup, field);
1576  }
1577 
1578  // Set the name of the field appropriately
1580  field->attribute = layerName;
1581  field->setMapping(part->mapping);
1582 
1583  // Cache the field for future use
1584  if (field) {
1585  cache.cacheField(field, m_filename, layerPath);
1586  }
1587 
1588  return field;
1589 }

References FieldBase::attribute, FieldCache< Data_T >::cacheField(), FieldCache< Data_T >::getCachedField(), Field3DFileBase::intPartitionName(), Field3DOutputFile::m_root, File::Layer::name, FieldBase::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), 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 1667 of file Field3DFile.cpp.

1671 {
1672  using namespace boost;
1673  using namespace std;
1674 
1675  typename EmptyField<Data_T>::Ptr null;
1676 
1677  const std::string extentsMinStr("extents_min");
1678  const std::string extentsMaxStr("extents_max");
1679  const std::string dataWindowMinStr("data_window_min");
1680  const std::string dataWindowMaxStr("data_window_max");
1681 
1682  Box3i extents, dataW;
1683 
1684  // Get extents ---
1685 
1686  OgIAttribute<veci32_t> extMinAttr =
1687  location.findAttribute<veci32_t>(extentsMinStr);
1688  OgIAttribute<veci32_t> extMaxAttr =
1689  location.findAttribute<veci32_t>(extentsMaxStr);
1690  if (!extMinAttr.isValid()) {
1691  throw MissingAttributeException("Couldn't find attribute " +
1692  extentsMinStr);
1693  }
1694  if (!extMaxAttr.isValid()) {
1695  throw MissingAttributeException("Couldn't find attribute " +
1696  extentsMaxStr);
1697  }
1698 
1699  extents.min = extMinAttr.value();
1700  extents.max = extMaxAttr.value();
1701 
1702  // Get data window ---
1703 
1704  OgIAttribute<veci32_t> dwMinAttr =
1705  location.findAttribute<veci32_t>(dataWindowMinStr);
1706  OgIAttribute<veci32_t> dwMaxAttr =
1707  location.findAttribute<veci32_t>(dataWindowMaxStr);
1708  if (!dwMinAttr.isValid()) {
1709  throw MissingAttributeException("Couldn't find attribute " +
1710  dataWindowMinStr);
1711  }
1712  if (!dwMaxAttr.isValid()) {
1713  throw MissingAttributeException("Couldn't find attribute " +
1714  dataWindowMaxStr);
1715  }
1716 
1717  dataW.min = dwMinAttr.value();
1718  dataW.max = dwMaxAttr.value();
1719 
1720  // Construct the field
1721  typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
1722  field->setSize(extents, dataW);
1723 
1724  // Read the metadata
1725  OgIGroup metadataGroup = location.findGroup("metadata");
1726  if (metadataGroup.isValid()) {
1727  readMetadata(metadataGroup, field);
1728  }
1729 
1730  // Set field properties
1731  field->name = name;
1732  field->attribute = attribute;
1733  field->setMapping(mapping);
1734 
1735  return field;
1736 }

References FieldBase::attribute, FieldBase::name, 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 844 of file Field3DFile.cpp.

845 {
846  // Find all the partition names
847  std::vector<std::string> groups = m_root->groupNames();
848 
849  // Store the partition names
850  m_partitions.clear();
851  for (std::vector<std::string>::const_iterator i = groups.begin(),
852  end = groups.end(); i != end; ++i) {
853  // Grab the name
854  const std::string &name = *i;
855  // Skip metadata
856  if (name == "field3d_global_metadata") {
857  continue;
858  }
859  // Build partition
861  part->name = name;
862  m_partitions.push_back(part);
863  }
864 
865  // For each partition, find its mapping ---
866 
867  for (PartitionList::iterator i = m_partitions.begin();
868  i != m_partitions.end(); ++i) {
869  // Grab the name
870  const std::string &name = (**i).name;
871  // Open the partition group
872  const OgIGroup partitionGroup = m_root->findGroup(name);
873  if (!partitionGroup.isValid()) {
874  Msg::print(Msg::SevWarning, "Couldn't open partition group " + name);
875  }
876  // Open the mapping group
877  const OgIGroup mappingGroup = partitionGroup.findGroup(k_mappingStr);
878  if (!mappingGroup.isValid()) {
879  Msg::print(Msg::SevWarning, "Couldn't open mapping group " + name);
880  }
881  // Build the mapping
882  FieldMapping::Ptr mapping = readFieldMapping(mappingGroup);
883 #if 0
884  if (!mapping) {
885  Msg::print(Msg::SevWarning, "Got a null pointer when reading mapping");
886  throw ReadMappingException((**i).name);
887  }
888 #endif
889  // Attach the mapping to the partition
890  (**i).mapping = mapping;
891  }
892 
893  // ... And then find its layers ---
894 
895  for (PartitionList::const_iterator i = m_partitions.begin();
896  i != m_partitions.end(); ++i) {
897  // Grab the name
898  const std::string &partitionName = (**i).name;
899  // Open the partition group
900  const OgIGroup partitionGroup = m_root->findGroup(partitionName);
901  if (!partitionGroup.isValid()) {
902  Msg::print(Msg::SevWarning, "Couldn't open partition group " +
903  partitionName);
904  }
905  // Get all the layer names
906  groups = partitionGroup.groupNames();
907  for (std::vector<std::string>::const_iterator l = groups.begin(),
908  lEnd = groups.end(); l != lEnd; ++l) {
909  // Grab layer name
910  const std::string layerName = *l;
911  // Skip the mapping group
912  if (layerName == k_mappingStr) {
913  continue;
914  }
915  // Construct the layer
916  File::Layer layer;
917  layer.name = *l;
918  layer.parent = partitionName;
919  // Add to partition
920  partition(partitionName)->addLayer(layer);
921  }
922  }
923 
924  return true;
925 }

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 929 of file Field3DFile.cpp.

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

Referenced by open().

◆ readMetadata() [2/2]

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

Read global metadata for this file.

Definition at line 937 of file Field3DFile.cpp.

938 {
939  return readMeta(metadataGroup, metadata());
940 }

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().

◆ 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(), and readPartitionAndLayerInfo().

◆ m_hdf5

boost::shared_ptr<Field3DInputFileHDF5> Field3DInputFile::m_hdf5
private

HDF5 fallback.

Definition at line 607 of file Field3DFile.h.

Referenced by open().


The documentation for this class was generated from the following files:
Field3DInputFile::m_archive
boost::shared_ptr< Alembic::Ogawa::IArchive > m_archive
Pointer to the Ogawa archive.
Definition: Field3DFile.h:602
Field3DInputFile::readMetadata
bool readMetadata(const OgIGroup &metadataGroup, FieldBase::Ptr field) const
Read metadata for this layer.
Definition: Field3DFile.cpp:929
Exc::Exception::what
virtual const char * what() const
Definition: Exception.h:90
Msg::SevWarning
Definition: Log.h:68
Field3DInputFile::m_hdf5
boost::shared_ptr< Field3DInputFileHDF5 > m_hdf5
HDF5 fallback.
Definition: Field3DFile.h:607
FieldBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field.h:155
EmptyField::Vec
std::vector< Ptr > Vec
Definition: EmptyField.h:94
Field::Ptr
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:395
OgIAttribute
Definition: OgawaFwd.h:62
FieldCache::singleton
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Definition: FieldCache.h:134
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
EmptyField::Ptr
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:93
Field3DFileBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field3DFile.h:276
FieldBase::name
std::string name
Optional name of the field.
Definition: Field.h:171
FieldRes::setMapping
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition: Field.h:347
File::Partition
Definition: Field3DFile.h:121
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
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::m_hdf5Base
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
Definition: Field3DFile.h:388
Field3DFileBase::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:371
Exc::Exception
Definition: Exception.h:73
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
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition: Field.h:173
Field3DInputFile::m_filename
std::string m_filename
Filename, only to be set by open().
Definition: Field3DFile.h:600
Field::Vec
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:403
Field3DInputFile::cleanup
void cleanup()
Definition: Field3DFile.h:557
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
EmptyField
This subclass of Field does not store any data.
Definition: EmptyField.h:86
Field3DFileBase::partition
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Hdf5Util
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
Field3DFileBase::getPartitionNames
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
Definition: Field3DFile.cpp:492
FieldCache::getCachedField
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
Definition: FieldCache.h:147
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
Field3DFileBase::clear
void clear()
Clear the data structures and close the file.
Definition: Field3DFile.cpp:616
File::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:127
Box3i
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
Field3DInputFile::readPartitionAndLayerInfo
bool readPartitionAndLayerInfo()
Sets up all the partitions and layers, but does not load any data.
Definition: Field3DFile.cpp:844
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
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
FieldCache::cacheField
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
Definition: FieldCache.h:168
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
File::Layer
Definition: Field3DFile.h:96
FieldCache
Definition: FieldCache.h:79
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::m_root
boost::shared_ptr< OgIGroup > m_root
Pointer to root group.
Definition: Field3DFile.h:604
veci32_t
Field3D::V3i veci32_t
Definition: Traits.h:94
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
Field3DInputFileHDF5
Provides reading of .f3d (internally, hdf5) files.
Definition: Field3DFileHDF5.h:437
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
File::Layer::name
std::string name
The name of the layer (always available)
Definition: Field3DFile.h:100
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