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 (runtime_error &e) {
830  // HDF5 fallback
831  m_hdf5.reset(new Field3DInputFileHDF5);
832  m_hdf5Base = m_hdf5;
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 }

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 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;
1618  getIntPartitionNames(parts);
1619 
1620  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1621  vector<std::string> layers;
1622  getIntScalarLayerNames(layers, *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 }

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 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;
1655  getIntPartitionNames(parts);
1656 
1657  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1658  std::vector<std::string> layers;
1659  getIntScalarLayerNames(layers, *p);
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 }

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 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,
1765  isVectorLayer);
1766  }
1767 
1768  // Instantiate a null pointer for easier code reading
1769  typename EmptyField<Data_T>::Vec emptyList, output;
1770 
1771  if ((layerName.length() == 0) || (partitionName.length() == 0))
1772  return emptyList;
1773 
1774  std::vector<std::string> parts, layers;
1775  getIntPartitionNames(parts);
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) {
1783  getIntVectorLayerNames(layers, *p);
1784  } else {
1785  getIntScalarLayerNames(layers, *p);
1786  }
1787  for (vector<string>::iterator l = layers.begin();
1788  l != layers.end(); ++l) {
1789  if (*l == layerName) {
1790  // Find the partition
1791  File::Partition::Ptr part = partition(*p);
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 =
1824  readProxyLayer<Data_T>(layerGroup, partitionName, layerName,
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()) {
1831  OgIAttribute<uint32_t> levelsAttr =
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 }

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 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;
1868  getPartitionNames(parts);
1869 
1870  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1871  std::vector<std::string> layers;
1872  getScalarLayerNames(layers, *p);
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 }

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 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;
1903  getPartitionNames(parts);
1904 
1905  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1906  std::vector<std::string> layers;
1907  getVectorLayerNames(layers, *p);
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 }

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 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()) {
1588  readMetadata(metadataGroup, field);
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 }

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

1684 {
1685  using namespace boost;
1686  using namespace std;
1687 
1688  typename EmptyField<Data_T>::Ptr null;
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 
1699  OgIAttribute<veci32_t> extMinAttr =
1700  location.findAttribute<veci32_t>(extentsMinStr);
1701  OgIAttribute<veci32_t> extMaxAttr =
1702  location.findAttribute<veci32_t>(extentsMaxStr);
1703  if (!extMinAttr.isValid()) {
1704  throw MissingAttributeException("Couldn't find attribute " +
1705  extentsMinStr);
1706  }
1707  if (!extMaxAttr.isValid()) {
1708  throw MissingAttributeException("Couldn't find attribute " +
1709  extentsMaxStr);
1710  }
1711 
1712  extents.min = extMinAttr.value();
1713  extents.max = extMaxAttr.value();
1714 
1715  // Get data window ---
1716 
1717  OgIAttribute<veci32_t> dwMinAttr =
1718  location.findAttribute<veci32_t>(dataWindowMinStr);
1719  OgIAttribute<veci32_t> dwMaxAttr =
1720  location.findAttribute<veci32_t>(dataWindowMaxStr);
1721  if (!dwMinAttr.isValid()) {
1722  throw MissingAttributeException("Couldn't find attribute " +
1723  dataWindowMinStr);
1724  }
1725  if (!dwMaxAttr.isValid()) {
1726  throw MissingAttributeException("Couldn't find attribute " +
1727  dataWindowMaxStr);
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()) {
1740  readMetadata(metadataGroup, field);
1741  }
1742 
1743  // Set field properties
1744  field->name = name;
1745  field->attribute = attribute;
1746  field->setMapping(mapping);
1747 
1748  return field;
1749 }

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 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
890  const OgIGroup mappingGroup = partitionGroup.findGroup(k_mappingStr);
891  if (!mappingGroup.isValid()) {
892  Msg::print(Msg::SevWarning, "Couldn't open mapping group " + name);
893  }
894  // Build the mapping
895  FieldMapping::Ptr mapping = readFieldMapping(mappingGroup);
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 }

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.

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

Referenced by open().

◆ 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 {
952  return readMeta(metadataGroup, metadata());
953 }

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:942
Exc::Exception::what
virtual const char * what() const
Definition: Exception.h:90
Msg::SevWarning
@ 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:135
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:122
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:74
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:88
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:148
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:857
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:169
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:97
FieldCache
Definition: FieldCache.h:81
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:438
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