Field3D
Field3DInputFile Class Reference

Provides reading of .f3d (internally, hdf5) files.Refer to using_files for examples of how to use this in your code. More...

#include <Field3DFile.h>

Inheritance diagram for Field3DInputFile:
Field3DFileBase

Public Member Functions

bool open (const std::string &filename)
 Opens the given file. More...
 
bool readGroupMembership (GroupMembershipMap &gpMembershipMap)
 Read the group membership for the partitions. More...
 
Constructors & destructor
 Field3DInputFile ()
 
virtual ~Field3DInputFile ()
 
Reading layers from disk
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...
 
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec readScalarLayersAs (const std::string &layerName=std::string("")) const
 Retrieves all layers for all partitions. Converts it to the given template type if needed. More...
 
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec readScalarLayersAs (const std::string &partitionName, const std::string &layerName) const
 Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed. More...
 
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec readVectorLayersAs (const std::string &layerName=std::string("")) const
 Retrieves a layers for all partitions. Converts it to the given template type if needed. More...
 
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec readVectorLayersAs (const std::string &partitionName, const std::string &layerName) const
 Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed. 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...
 
Internal utility methods
herr_t parsePartition (hid_t loc_id, const std::string partitionName)
 Gets called from parsePartitions. Not intended for any other use. More...
 
herr_t parseLayer (hid_t loc_id, const std::string &partitionName, const std::string &layerName)
 Gets called from parsePartitions. Not intended for any other use. 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...
 
FieldMetadata< Field3DFileBase > & metadata ()
 accessor to the m_metadata class More...
 
const FieldMetadata
< Field3DFileBase > & 
metadata () 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...
 
File::Partition::Ptr getPartition (const std::string &partitionName) const
 Returns a pointer to the given partition. 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...
 
void addGroupMembership (const GroupMembershipMap &groupMembers)
 Add to the group membership. More...
 
void printHierarchy () const
 

Private Member Functions

template<class Data_T >
Field< Data_T >::Ptr readLayer (const std::string &intPartitionName, const std::string &layerName, bool isVectorLayer) const
 This call does the actual reading of a layer. Notice that it expects a unique -internal- partition name. More...
 
bool readMetadata (hid_t metadata_id, FieldBase::Ptr field) const
 Read metadata for this layer. More...
 
bool readMetadata (hid_t metadata_id)
 Read global metadata for this file. More...
 
bool readPartitionAndLayerInfo ()
 Sets up all the partitions and layers, but does not load any data. More...
 
template<class Data_T >
Field< Data_T >::Ptr readScalarLayer (const std::string &intPartitionName, const std::string &layerName) const
 Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types. More...
 
template<class Data_T >
Field< FIELD3D_VEC3_T< Data_T >
>::Ptr 
readVectorLayer (const std::string &intPartitionName, const std::string &layerName) const
 Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types. More...
 

Private Attributes

std::string m_filename
 Filename, only to be set by open(). 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::Ptr
PartitionList
 
- Protected Member Functions inherited from Field3DFileBase
void closeInternal ()
 Closes the file if open. 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...
 
- Protected Attributes inherited from Field3DFileBase
hid_t m_file
 The hdf5 id of the current file. Will be -1 if no file is open. More...
 
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...
 
std::vector< LayerInfom_layerInfo
 This stores layer info. More...
 
FieldMetadata< Field3DFileBasem_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) files.

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

Note
We distinguish between scalar and vector layers even though both are templated. A scalarField<float> layer is interchangeable with a scalarField<double> (conceptually) but not with a scalar<V3f>, and thus not with vectorField<float>.

Definition at line 431 of file Field3DFile.h.

Constructor & Destructor Documentation

Field3DInputFile::Field3DInputFile ( )

Definition at line 561 of file Field3DFile.cpp.

562 {
563  // Empty
564 }
Field3DInputFile::~Field3DInputFile ( )
virtual

Definition at line 568 of file Field3DFile.cpp.

References Field3DFileBase::clear().

569 {
570  clear();
571 }
void clear()
Clear the data structures and close the file.

Member Function Documentation

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

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

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

770 {
771  using namespace std;
772 
773  typedef typename Field<Data_T>::Ptr FieldPtr;
774  typedef typename Field<Data_T>::Vec FieldList;
775 
776  FieldList ret;
777  std::vector<std::string> parts;
778  getIntPartitionNames(parts);
779 
780  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
781  std::vector<std::string> layers;
782  getIntScalarLayerNames(layers, *p);
783  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
784  // Only read if it matches the name
785  if ((name.length() == 0) || (*l == name)) {
786  FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
787  if (mf) {
788  ret.push_back(mf);
789  }
790  }
791  }
792  }
793 
794  return ret;
795 }
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 ...
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:390
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:382
template<class Data_T >
Field< Data_T >::Vec Field3DInputFile::readScalarLayers ( const std::string &  partitionName,
const std::string &  layerName 
) const

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

Definition at line 801 of file Field3DFile.h.

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

803 {
804  using namespace std;
805 
806  typedef typename Field<Data_T>::Ptr FieldPtr;
807  typedef typename Field<Data_T>::Vec FieldList;
808 
809  FieldList ret;
810 
811  if ((layerName.length() == 0) || (partitionName.length() == 0))
812  return ret;
813 
814  std::vector<std::string> parts;
815  getIntPartitionNames(parts);
816 
817  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
818  std::vector<std::string> layers;
819  getIntScalarLayerNames(layers, *p);
820  if (removeUniqueId(*p) == partitionName) {
821  for (vector<string>::iterator l = layers.begin();
822  l != layers.end(); ++l) {
823  // Only read if it matches the name
824  if (*l == layerName) {
825  FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
826  if (mf)
827  ret.push_back(mf);
828  }
829  }
830  }
831  }
832 
833  return ret;
834 }
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 ...
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:390
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:382
template<class Data_T >
Field< FIELD3D_VEC3_T< Data_T > >::Vec Field3DInputFile::readVectorLayers ( const std::string &  layerName = std::string("")) const

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

References Field3DFileBase::getIntPartitionNames(), and Field3DFileBase::getIntVectorLayerNames().

841 {
842  using namespace std;
843 
844  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
845  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
846 
847  FieldList ret;
848 
849  std::vector<std::string> parts;
850  getIntPartitionNames(parts);
851 
852  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
853  std::vector<std::string> layers;
854  getIntVectorLayerNames(layers, *p);
855  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
856  // Only read if it matches the name
857  if ((name.length() == 0) || (*l == name)) {
858  FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
859  if (mf)
860  ret.push_back(mf);
861  }
862  }
863  }
864 
865  return ret;
866 }
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: Field.h:376
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
template<class Data_T >
Field< FIELD3D_VEC3_T< Data_T > >::Vec Field3DInputFile::readVectorLayers ( const std::string &  partitionName,
const std::string &  layerName 
) const

This version allows you to pass in the partition name.

Definition at line 872 of file Field3DFile.h.

References Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntVectorLayerNames(), and Field3DFileBase::removeUniqueId().

874 {
875  using namespace std;
876 
877  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
878  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
879 
880  FieldList ret;
881 
882  if ((layerName.length() == 0) || (partitionName.length() == 0))
883  return ret;
884 
885  std::vector<std::string> parts;
886  getIntPartitionNames(parts);
887 
888  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
889  std::vector<std::string> layers;
890  getIntVectorLayerNames(layers, *p);
891  if (removeUniqueId(*p) == partitionName) {
892  for (vector<string>::iterator l = layers.begin();
893  l != layers.end(); ++l) {
894  // Only read if it matches the name
895  if (*l == layerName) {
896  FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
897  if (mf)
898  ret.push_back(mf);
899  }
900  }
901  }
902  }
903 
904  return ret;
905 }
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: Field.h:376
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec Field3DInputFile::readScalarLayersAs ( const std::string &  layerName = std::string("")) const

Retrieves all layers for all partitions. Converts it to the given template type if needed.

Definition at line 990 of file Field3DFile.h.

References field_dynamic_cast().

991 {
992  typedef typename Field<Data_T>::Vec FieldList;
993  typedef typename Field_T<Data_T>::Vec TypedFieldList;
994 
995  // First, read the layers as-is
996  FieldList originals;
997  originals = readScalarLayers<Data_T>(layerName);
998 
999  // Loop over fields, converting if needed
1000  TypedFieldList output;
1001  typename FieldList::iterator i = originals.begin();
1002  for (; i != originals.end(); ++i) {
1003  typename Field_T<Data_T>::Ptr targetField;
1004  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
1005  if (targetField) {
1006  output.push_back(targetField);
1007  } else {
1008  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
1009  newTarget->name = (*i)->name;
1010  newTarget->attribute = (*i)->attribute;
1011  newTarget->copyMetadata(*i);
1012  newTarget->copyFrom(*i);
1013  output.push_back(newTarget);
1014  }
1015  }
1016 
1017  return output;
1018 }
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition: RefCount.h:224
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:390
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec Field3DInputFile::readScalarLayersAs ( const std::string &  partitionName,
const std::string &  layerName 
) const

Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed.

Definition at line 1024 of file Field3DFile.h.

References field_dynamic_cast().

1026 {
1027  typedef typename Field<Data_T>::Vec FieldList;
1028  typedef typename Field_T<Data_T>::Vec TypedFieldList;
1029 
1030  // First, read the layers as-is
1031  FieldList originals;
1032  originals = readScalarLayers<Data_T>(partitionName, layerName);
1033 
1034  // Loop over fields, converting if needed
1035  TypedFieldList output;
1036  typename FieldList::iterator i = originals.begin();
1037  for (; i != originals.end(); ++i) {
1038  typename Field_T<Data_T>::Ptr targetField;
1039  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
1040  if (targetField) {
1041  output.push_back(targetField);
1042  } else {
1043  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
1044  newTarget->name = (*i)->name;
1045  newTarget->attribute = (*i)->attribute;
1046  newTarget->copyMetadata(**i);
1047  newTarget->copyFrom(*i);
1048  output.push_back(newTarget);
1049  }
1050  }
1051 
1052  return output;
1053 }
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition: RefCount.h:224
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:390
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec Field3DInputFile::readVectorLayersAs ( const std::string &  layerName = std::string("")) const

Retrieves a layers for all partitions. Converts it to the given template type if needed.

Definition at line 1059 of file Field3DFile.h.

References field_dynamic_cast().

1060 {
1061  typedef typename Field<Data_T>::Vec FieldList;
1062  typedef typename Field_T<Data_T>::Vec TypedFieldList;
1063 
1064  // First, read the layers as-is
1065  FieldList originals;
1066  originals = readVectorLayers<Data_T>(layerName);
1067 
1068  // Loop over fields, converting if needed
1069  TypedFieldList output;
1070  typename FieldList::iterator i = originals.begin();
1071  for (; i != originals.end(); ++i) {
1072  typename Field_T<Data_T>::Ptr targetField;
1073  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
1074  if (targetField) {
1075  output.push_back(targetField);
1076  } else {
1077  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
1078  newTarget->name = (*i)->name;
1079  newTarget->attribute = (*i)->attribute;
1080  newTarget->copyMetadata(*i);
1081  newTarget->copyFrom(*i);
1082  output.push_back(newTarget);
1083  }
1084  }
1085 
1086  return output;
1087 }
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition: RefCount.h:224
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:390
template<template< typename T > class Field_T, class Data_T >
Field_T< Data_T >::Vec Field3DInputFile::readVectorLayersAs ( const std::string &  partitionName,
const std::string &  layerName 
) const

Retrieves a layers given their and its parent partition's name. Converts it to the given template type if needed.

Definition at line 1093 of file Field3DFile.h.

References field_dynamic_cast().

1095 {
1096  typedef typename Field<Data_T>::Vec FieldList;
1097  typedef typename Field_T<Data_T>::Vec TypedFieldList;
1098 
1099  // First, read the layers as-is
1100  FieldList originals;
1101  originals = readVectorLayers<Data_T>(partitionName, layerName);
1102 
1103  // Loop over fields, converting if needed
1104  TypedFieldList output;
1105  typename FieldList::iterator i = originals.begin();
1106  for (; i != originals.end(); ++i) {
1107  typename Field_T<Data_T>::Ptr targetField;
1108  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
1109  if (targetField) {
1110  output.push_back(targetField);
1111  } else {
1112  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
1113  newTarget->name = (*i)->name;
1114  newTarget->attribute = (*i)->attribute;
1115  newTarget->copyMetadata(*i);
1116  newTarget->copyFrom(*i);
1117  output.push_back(newTarget);
1118  }
1119  }
1120 
1121  return output;
1122 }
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition: RefCount.h:224
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:390
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 1128 of file Field3DFile.h.

References FieldBase::attribute, Field3DFileBase::getIntPartitionNames(), Field3DFileBase::getIntScalarLayerNames(), Field3DFileBase::getIntVectorLayerNames(), Field3DFileBase::m_file, File::Layer::name, FieldBase::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), Hdf5Util::readAttribute(), readMetadata(), Field3DFileBase::removeUniqueId(), FieldRes::setMapping(), ResizableField< Data_T >::setSize(), and Msg::SevWarning.

1131 {
1132  using namespace boost;
1133  using namespace std;
1134  using namespace Hdf5Util;
1135 
1136  // Instantiate a null pointer for easier code reading
1137  typename EmptyField<Data_T>::Vec emptyList, output;
1138 
1139  if ((layerName.length() == 0) || (partitionName.length() == 0))
1140  return emptyList;
1141 
1142  std::vector<std::string> parts, layers;
1143  getIntPartitionNames(parts);
1144 
1145  bool foundPartition = false;
1146 
1147  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1148  if (removeUniqueId(*p) == partitionName) {
1149  foundPartition = true;
1150  if (isVectorLayer) {
1151  getIntVectorLayerNames(layers, *p);
1152  } else {
1153  getIntScalarLayerNames(layers, *p);
1154  }
1155  for (vector<string>::iterator l = layers.begin();
1156  l != layers.end(); ++l) {
1157  if (*l == layerName) {
1158  // Find the partition
1159  File::Partition::Ptr part = partition(*p);
1160  if (!part) {
1161  Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
1162  return emptyList;
1163  }
1164  // Find the layer
1165  const File::Layer *layer;
1166  if (isVectorLayer)
1167  layer = part->vectorLayer(layerName);
1168  else
1169  layer = part->scalarLayer(layerName);
1170  if (!layer) {
1171  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1172  return emptyList;
1173  }
1174  // Open the layer group
1175  string layerPath = layer->parent + "/" + layer->name;
1176  H5ScopedGopen layerGroup(m_file, layerPath.c_str());
1177  if (layerGroup.id() < 0) {
1178  Msg::print(Msg::SevWarning, "Couldn't find layer group "
1179  + layerName + " in .f3d file ");
1180  return emptyList;
1181  }
1182  // Read the extents and data window
1183  Box3i extents, dataW;
1184  if (!readAttribute(layerGroup, "extents", 6, extents.min.x)) {
1185  return emptyList;
1186  }
1187  if (!readAttribute(layerGroup, "data_window", 6, dataW.min.x)) {
1188  return emptyList;
1189  }
1190  // Construct the field and load the data
1191  typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
1192  field->setSize(extents, dataW);
1193 
1194  // read the metadata
1195  string metadataPath = layerPath + "/metadata";
1196  H5ScopedGopen metadataGroup(m_file, metadataPath.c_str());
1197  if (metadataGroup.id() > 0) {
1198  readMetadata(metadataGroup.id(), field);
1199  }
1200 
1201  // ... Set the name of the field so it's possible to
1202  // ... re-create the file
1203  field->name = partitionName;
1204  field->attribute = layerName;
1205  field->setMapping(part->mapping);
1206  // Add field to output
1207  output.push_back(field);
1208  }
1209  }
1210  }
1211  }
1212 
1213  if (!foundPartition) {
1214  Msg::print(Msg::SevWarning, "Couldn't find partition: " + partitionName);
1215  return emptyList;
1216  }
1217 
1218  return output;
1219 }
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
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 ...
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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 ...
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
std::vector< Ptr > Vec
Definition: EmptyField.h:89
std::string name
The name of the layer (always available)
Definition: Field3DFile.h:121
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
This subclass of Field does not store any data.
Definition: EmptyField.h:81
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:88
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:176
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition: Field3DFile.h:124
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 1225 of file Field3DFile.h.

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

1226 {
1227  using namespace std;
1228 
1229  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1230  typedef std::vector<FieldPtr> FieldList;
1231 
1232  FieldList ret;
1233 
1234  std::vector<std::string> parts;
1235  getPartitionNames(parts);
1236 
1237  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1238  std::vector<std::string> layers;
1239  getScalarLayerNames(layers, *p);
1240  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1241  // Only read if it matches the name
1242  if ((name.length() == 0) || (*l == name)) {
1243  FieldList f = readProxyLayer<Data_T>(*p, *l, false);
1244  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1245  if (*i) {
1246  ret.push_back(*i);
1247  }
1248  }
1249  }
1250  }
1251  }
1252 
1253  return ret;
1254 }
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:88
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.
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 1260 of file Field3DFile.h.

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

1261 {
1262  using namespace std;
1263 
1264  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1265  typedef std::vector<FieldPtr> FieldList;
1266 
1267  FieldList ret;
1268 
1269  std::vector<std::string> parts;
1270  getPartitionNames(parts);
1271 
1272  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1273  std::vector<std::string> layers;
1274  getVectorLayerNames(layers, *p);
1275  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1276  // Only read if it matches the name
1277  if ((name.length() == 0) || (*l == name)) {
1278  FieldList f = readProxyLayer<Data_T>(*p, *l, true);
1279  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1280  if (*i) {
1281  ret.push_back(*i);
1282  }
1283  }
1284  }
1285  }
1286  }
1287 
1288  return ret;
1289 }
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:88
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.
bool Field3DInputFile::open ( const std::string &  filename)

Opens the given file.

Returns
Whether successful

Definition at line 575 of file Field3DFile.cpp.

References Field3DFileBase::clear(), Field3DFileBase::close(), Hdf5Util::H5Base::id(), Field3DFileBase::m_file, m_filename, Msg::print(), Hdf5Util::readAttribute(), readMetadata(), readPartitionAndLayerInfo(), Msg::SevWarning, and Exc::Exception::what().

576 {
577  clear();
578 
579  bool success = true;
580 
581  m_filename = filename;
582 
583  try {
584 
585  string version;
586 
587  // Throws exceptions if the file doesn't exist.
588  // This was added because H5Fopen prints out a lot of junk
589  // to the terminal.
590  checkFile(filename);
591 
592  m_file = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
593 
594  if (m_file < 0)
595  throw NoSuchFileException(filename);
596 
597  int fileVersion[3];
598  try {
599  if (!readAttribute(m_file, k_versionAttrName, 3, fileVersion[0])) {
600  //Msg::print(Msg::SevWarning, "Missing version_number attribute");
601  } else {
602  if (!isSupportedFileVersion(fileVersion, k_minFileVersion)) {
603  stringstream versionStr;
604  versionStr << fileVersion[0] << "."
605  << fileVersion[1] << "."
606  << fileVersion[2];
607  throw UnsupportedVersionException(versionStr.str());
608  }
609  }
610  }
611  catch (MissingAttributeException &e) {
612  //Msg::print(Msg::SevWarning, "Missing version_number attribute");
613  }
614 
615  try {
616  if (H5Lexists(m_file, "field3d_global_metadata", H5P_DEFAULT)) {
617  // read the metadata
618  H5ScopedGopen metadataGroup(m_file, "field3d_global_metadata");
619  if (metadataGroup.id() > 0) {
620  readMetadata(metadataGroup.id());
621  }
622  }
623  }
624  catch (...) {
626  "Unknown error when reading file metadata ");
627  //throw BadFileHierarchyException(filename);
628  }
629 
630  try {
631  if (!readPartitionAndLayerInfo()) {
632  success = false;
633  }
634  }
635  catch (MissingGroupException &e) {
636  Msg::print(Msg::SevWarning, "Missing group: " + string(e.what()));
637  throw BadFileHierarchyException(filename);
638  }
639  catch (ReadMappingException &e) {
640  Msg::print(Msg::SevWarning, "Couldn't read mapping for partition: "
641  + string(e.what()));
642  throw BadFileHierarchyException(filename);
643  }
644  catch (Exception &e) {
645  Msg::print(Msg::SevWarning, "Unknown error when reading file hierarchy: "
646  + string(e.what()));
647  throw BadFileHierarchyException(filename);
648  }
649  catch (...) {
651  "Unknown error when reading file hierarchy. ");
652  throw BadFileHierarchyException(filename);
653  }
654 
655  }
656  catch (NoSuchFileException &e) {
657  Msg::print(Msg::SevWarning, "Couldn't open file: "
658  + string(e.what()) );
659  success = false;
660  }
661  catch (MissingAttributeException &e) {
663  "In file: " + filename + " - "
664  + string(e.what()) );
665  success = false;
666  }
667  catch (UnsupportedVersionException &e) {
669  "In file: " + filename + " - File version can not be read: "
670  + string(e.what()));
671  success = false;
672  }
673  catch (BadFileHierarchyException &e) {
675  "In file: " + filename + " - Bad file hierarchy. ");
676  success = false;
677  }
678  catch (...) {
680  "In file: " + filename + " Unknown exception ");
681  success = false;
682  }
683 
684  if (!success)
685  close();
686 
687  return success;
688 }
virtual const char * what() const
Definition: Exception.h:90
std::string m_filename
Filename, only to be set by open().
Definition: Field3DFile.h:603
void clear()
Clear the data structures and close the file.
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
bool readPartitionAndLayerInfo()
Sets up all the partitions and layers, but does not load any data.
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
bool close()
Closes the file. No need to call this unless you specifically want to close the file early...
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:176
herr_t Field3DInputFile::parsePartition ( hid_t  loc_id,
const std::string  partitionName 
)

Gets called from parsePartitions. Not intended for any other use.

Definition at line 784 of file Field3DFile.cpp.

References Field3DFileBase::m_partitionNames.

Referenced by InputFile::parsePartitions().

786 {
787  // Add the partition ---
788 
789  m_partitionNames.push_back(string(itemName));
790  return 0;
791 }
std::vector< std::string > m_partitionNames
This stores partition names.
Definition: Field3DFile.h:388
herr_t Field3DInputFile::parseLayer ( hid_t  layerGroup,
const std::string &  partitionName,
const std::string &  layerName 
)

Gets called from parsePartitions. Not intended for any other use.

Note
Don't throw exceptions into the hdf5 lib.
Todo:
Set some sort of flag if we fail during this call. We can't throw exceptions inside hdf5.

Definition at line 798 of file Field3DFile.cpp.

References Field3DFileBase::m_layerInfo, Msg::print(), Hdf5Util::readAttribute(), and Msg::SevWarning.

Referenced by InputFile::parseLayers().

801 {
802  int components;
803  if (!readAttribute(layerGroup, string("components"), 1, components)) {
804  Msg::print(Msg::SevWarning, "Couldn't read components attribute for layer "
805  + partitionName + "/" + layerName);
806  return 0;
807  }
808 
809  LayerInfo linfo(partitionName,layerName,components);
810 
811  m_layerInfo.push_back(linfo);
812 
813  return 0;
814 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
std::vector< LayerInfo > m_layerInfo
This stores layer info.
Definition: Field3DFile.h:381
bool Field3DInputFile::readGroupMembership ( GroupMembershipMap gpMembershipMap)

Read the group membership for the partitions.

Definition at line 1039 of file Field3DFile.cpp.

References Hdf5Util::H5Base::id(), Field3DFileBase::m_file, Field3DFileBase::m_groupMembership, Msg::print(), Hdf5Util::readAttribute(), Field3DFileBase::removeUniqueId(), and Msg::SevWarning.

1040 {
1041  if (!H5Lexists(m_file, "field3d_group_membership", H5P_DEFAULT)) {
1042  return false;
1043  }
1044 
1045  H5ScopedGopen memberGroup(m_file, "field3d_group_membership");
1046  if (memberGroup < 0) {
1047  return false;
1048  }
1049 
1050  typedef boost::tokenizer<boost::char_separator<char> > Tok;
1051 
1052  hsize_t num_attrs = H5Aget_num_attrs(memberGroup);
1053  if (num_attrs > 0) {
1054 
1055  for (hsize_t idx=0; idx < num_attrs ; ++idx) {
1056  H5ScopedAopenIdx attrIdx(memberGroup, idx);
1057  size_t len = H5Aget_name(attrIdx.id(), 0, NULL);
1058  if (len>0) {
1059  char *name = new char[len+1];
1060  if (H5Aget_name(attrIdx.id(), len+1, name) > 0) {
1061 
1062  if (string(name) == "is_field3d_group_membership")
1063  continue;
1064 
1065  H5ScopedAopen attr(memberGroup, name, H5P_DEFAULT);
1066  H5ScopedAget_space attrSpace(attr);
1067  H5ScopedAget_type attrType(attr);
1068  H5T_class_t typeClass = H5Tget_class(attrType);
1069 
1070  if (typeClass == H5T_STRING) {
1071  string value;
1072  if (!readAttribute(memberGroup, name, value)) {
1074  "Failed to read group membership data "
1075  + string(name));
1076  continue;
1077  }
1078 
1079  {
1080  boost::char_separator<char> sep(" :");
1081  Tok tok(value, sep);
1082  string new_value;
1083  for(Tok::iterator beg=tok.begin(); beg!=tok.end();){
1084 
1085  string fieldgroup = *beg; ++beg;
1086  fieldgroup = removeUniqueId(fieldgroup) + ":" + *beg; ++beg;
1087  new_value += fieldgroup + " ";
1088  }
1089 
1090  m_groupMembership[name] = value;
1091  gpMembershipMap[name] = new_value;
1092  }
1093  }
1094  }
1095  }
1096  }
1097  }
1098 
1099  return true;
1100 }
Scoped object - opens an attribute data type on creation and closes it on destruction.
Definition: Hdf5Util.h:283
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Scoped object - Opens attribute by name and closes it on destruction.
Definition: Hdf5Util.h:103
Scoped object - Opens attribute by index and closes it on destruction.
Definition: Hdf5Util.h:129
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
Scoped object - opens an attribute data space on creation and closes it on destruction.
Definition: Hdf5Util.h:262
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the &quot;group&quot; and the valu...
Definition: Field3DFile.h:397
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:176
template<class Data_T >
Field< Data_T >::Ptr Field3DInputFile::readScalarLayer ( const std::string &  intPartitionName,
const std::string &  layerName 
) const
private

Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.

Definition at line 1295 of file Field3DFile.h.

References Field3DFileBase::intPartitionName().

1297 {
1298  return readLayer<Data_T>(intPartitionName, layerName, false);
1299 }
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 ...
template<class Data_T >
Field< FIELD3D_VEC3_T< Data_T > >::Ptr Field3DInputFile::readVectorLayer ( const std::string &  intPartitionName,
const std::string &  layerName 
) const
private

Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.

Definition at line 1305 of file Field3DFile.h.

References Field3DFileBase::intPartitionName().

1307 {
1308  return readLayer<FIELD3D_VEC3_T<Data_T> >(intPartitionName, layerName, true);
1309 }
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 ...
template<class Data_T >
Field< Data_T >::Ptr Field3DInputFile::readLayer ( const std::string &  intPartitionName,
const std::string &  layerName,
bool  isVectorLayer 
) const
private

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

Definition at line 911 of file Field3DFile.h.

References Field3DFileBase::m_file, m_filename, Field3DFileBase::partition(), Msg::print(), Hdf5Util::readAttribute(), readMetadata(), Field3DFileBase::removeUniqueId(), and Msg::SevWarning.

914 {
915  using namespace boost;
916  using namespace std;
917  using namespace Hdf5Util;
918 
919  // Instantiate a null pointer for easier code reading
920  typename Field<Data_T>::Ptr nullPtr;
921 
922  // Find the partition
924  if (!part) {
925  Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
926  return nullPtr;
927  }
928 
929  // Find the layer in the partition
930  const File::Layer *l;
931  if (isVectorLayer)
932  l = part->vectorLayer(layerName);
933  else
934  l = part->scalarLayer(layerName);
935  if (!l) {
936  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName );
937  return nullPtr;
938  }
939 
940  // Open the layer group
941  string layerPath = l->parent + "/" + l->name;
942  H5ScopedGopen layerGroup(m_file, layerPath.c_str());
943 
944  if (layerGroup.id() < 0) {
945  Msg::print(Msg::SevWarning, "Couldn't find layer group " + layerName
946  + " in .f3d file ");
947  return nullPtr;
948  }
949 
950  // Get the class name
951  string className;
952  if (!readAttribute(layerGroup.id(), "class_name", className)) {
953  Msg::print(Msg::SevWarning, "Couldn't find class_name attrib in layer " +
954  layerName);
955  return nullPtr;
956  }
957 
958  // Construct the field and load the data
959 
960  typename Field<Data_T>::Ptr field;
961  field = readField<Data_T>(className, layerGroup.id(), m_filename, layerPath);
962 
963  if (!field) {
964 #if 0 // This isn't really an error
965  Msg::print(Msg::SevWarning, "Couldn't read the layer data of layer: "
966  + layerName);
967 #endif
968  return nullPtr;
969  }
970 
971  // read the metadata
972  string metadataPath = layerPath + "/metadata";
973  H5ScopedGopen metadataGroup(m_file, metadataPath.c_str());
974  if (metadataGroup.id() > 0) {
975  readMetadata(metadataGroup.id(), field);
976  }
977 
978  // Set the name of the field so it's possible to re-create the file
979  field->name = removeUniqueId(intPartitionName);
980  field->attribute = layerName;
981  field->setMapping(part->mapping);
982 
983  return field;
984 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
std::string m_filename
Filename, only to be set by open().
Definition: Field3DFile.h:603
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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 removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:176
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:382
bool Field3DInputFile::readPartitionAndLayerInfo ( )
private

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

Definition at line 692 of file Field3DFile.cpp.

References InputFile::ParseLayersInfo::file, Hdf5Util::H5Base::id(), Field3DFileBase::m_file, Field3DFileBase::m_layerInfo, Field3DFileBase::m_partitionNames, Field3DFileBase::m_partitions, File::Layer::name, File::Layer::parent, InputFile::parseLayers(), InputFile::parsePartitions(), Field3DFileBase::partition(), InputFile::ParseLayersInfo::partitionName, Msg::print(), readFieldMapping(), and Msg::SevWarning.

Referenced by open().

693 {
694  using namespace InputFile;
695 
696  // First, find the partitions ---
697 
698  herr_t status;
699  status = H5Literate(m_file, H5_INDEX_NAME, H5_ITER_NATIVE, NULL,
700  &parsePartitions, this);
701 
702  // Get the partition names to store
703  m_partitions.clear();
704 
705  for (size_t i=0; i < m_partitionNames.size(); i++) {
706  Partition::Ptr part(new Partition);
707  part->name = m_partitionNames[i];
708  m_partitions.push_back(part);
709  }
710 
711  // For each partition, find its mapping ---
712 
713  for (PartitionList::iterator i = m_partitions.begin();
714  i != m_partitions.end(); ++i) {
715 
716  // Open the partition
717  H5ScopedGopen partitionGroup(m_file, (**i).name);
718 
719  string mappingPath = "/" + (**i).name + "/" + k_mappingStr;
720 
721  // Open up the mapping group
722  H5ScopedGopen mappingGroup(m_file, mappingPath);
723  if (mappingGroup.id() < 0)
724  throw MissingGroupException((**i).name + "/" + k_mappingStr);
725 
726  // Try to build a mapping from it
727  FieldMapping::Ptr mapping;
728 
729  mapping = readFieldMapping(mappingGroup.id());
730  if (!mapping) {
731  Msg::print(Msg::SevWarning, "Got a null pointer when reading mapping");
732  throw ReadMappingException((**i).name);
733  }
734 
735  // Attach the mapping to the partition
736  (**i).mapping = mapping;
737 
738  }
739 
740  // ... And then find its layers ---
741 
742  for (PartitionList::const_iterator i = m_partitions.begin();
743  i != m_partitions.end(); ++i) {
744 
745  // Open the partition
746  H5ScopedGopen partitionGroup(m_file, (**i).name);
747 
748  // Set up the info struct for the callback
749  ParseLayersInfo info;
750  info.file = this;
751  info.partitionName = (**i).name;
752 
753  m_layerInfo.clear();
754 
755  status = H5Literate(partitionGroup.id(), H5_INDEX_NAME, H5_ITER_NATIVE,
756  NULL, &parseLayers, &info);
757 
758  //set the layer information on the partitions here
759 
760  for (std::vector<LayerInfo>::iterator i = m_layerInfo.begin();
761  i != m_layerInfo.end(); i++) {
762 
763  std::string parent = i->parentName;
764 
765  Partition::Ptr part = partition(parent);
766 
767  Layer layer;
768  layer.name = i->name;
769  layer.parent = i->parentName;
770  if (i->components == 1) {
771  part->addScalarLayer(layer);
772  } else if (i->components == 3) {
773  part->addVectorLayer(layer);
774  }
775  }
776 
777  }
778 
779  return true;
780 }
herr_t parseLayers(hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
Gets called from readPartitionAndLayerInfo to check each group found under the root of the file...
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
std::vector< std::string > m_partitionNames
This stores partition names.
Definition: Field3DFile.h:388
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
std::string name
The name of the layer (always available)
Definition: Field3DFile.h:121
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
std::vector< LayerInfo > m_layerInfo
This stores layer info.
Definition: Field3DFile.h:381
struct used to pass the class and partition info back to the parseLayers() callback ...
Definition: Field3DFile.h:743
herr_t parsePartitions(hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
Gets called from readPartitionAndLayerInfo to check each group found under the root of the file...
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
Field3DInputFile * file
Definition: Field3DFile.h:745
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:176
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition: Field3DFile.h:124
bool Field3DInputFile::readMetadata ( hid_t  metadata_id,
FieldBase::Ptr  field 
) const
private

Read metadata for this layer.

Todo:
Replace char* with std::string

Definition at line 821 of file Field3DFile.cpp.

References Hdf5Util::H5Base::id(), Msg::print(), Hdf5Util::readAttribute(), and Msg::SevWarning.

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

822 {
823 
824  hsize_t num_attrs = H5Aget_num_attrs(metadata_id);
825 
826  if (num_attrs > 0) {
827  for (hsize_t idx=0; idx < num_attrs ; ++idx) {
828  H5ScopedAopenIdx attrIdx(metadata_id, idx);
829  size_t len = H5Aget_name(attrIdx.id(), 0, NULL);
830  if (len > 0) {
831  char *name = new char[len+1];
832  if (H5Aget_name(attrIdx.id(), len+1, name) > 0) {
833  H5ScopedAopen attr(metadata_id, name, H5P_DEFAULT);
834  H5ScopedAget_space attrSpace(attr);
835  H5ScopedAget_type attrType(attr);
836  H5T_class_t typeClass = H5Tget_class(attrType);
837 
838  if (typeClass == H5T_STRING) {
839  string value;
840  if (!readAttribute(metadata_id, name, value)) {
842  "Failed to read metadata " + string(name));
843  if (name) {
844  delete[] name;
845  }
846  continue;
847  }
848  field->metadata().setStrMetadata(name, value);
849 
850  }
851  else {
852 
853  if (H5Sget_simple_extent_ndims(attrSpace) != 1) {
854  Msg::print(Msg::SevWarning, "Bad attribute rank for attribute "
855  + string(name));
856  if (name) {
857  delete[] name;
858  }
859  continue;
860  }
861 
862  hsize_t dims[1];
863  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
864 
865  if (typeClass == H5T_INTEGER) {
866  if (dims[0] == 1){
867  int value;
868  if (!readAttribute(metadata_id, name, dims[0], value))
869  Msg::print(Msg::SevWarning, "Failed to read metadata "
870  + string(name));
871  field->metadata().setIntMetadata(name, value);
872  }
873  else if (dims[0] == 3){
874  V3i value;
875  if (!readAttribute(metadata_id, name, dims[0], value.x))
876  Msg::print(Msg::SevWarning, "Failed to read metadata " +
877  string(name) );
878  field->metadata().setVecIntMetadata(name, value);
879  }
880  else {
882  "Attribute of size " +
883  boost::lexical_cast<std::string>(dims[0])
884  + " is not valid for metadata");
885  }
886  }
887  else if (typeClass == H5T_FLOAT) {
888  if (dims[0] == 1){
889  float value;
890  if (!readAttribute(metadata_id, name, dims[0], value))
891  Msg::print(Msg::SevWarning, "Failed to read metadata " +
892  string(name) );
893 
894  field->metadata().setFloatMetadata(name, value);
895  }
896  else if (dims[0] == 3){
897  V3f value;
898  if (!readAttribute(metadata_id, name, dims[0], value.x))
899  Msg::print(Msg::SevWarning, "Failed to read metadata "+
900  string(name) );
901  field->metadata().setVecFloatMetadata(name, value);
902  }
903  else {
904  Msg::print(Msg::SevWarning, "Attribute of size " +
905  boost::lexical_cast<std::string>(dims[0]) +
906  " is not valid for metadata");
907  }
908  }
909  else {
910  Msg::print(Msg::SevWarning, "Attribute '" + string(name) +
911  + "' has unsupported data type for metadata");
912 
913  }
914  }
915  }
916  if (name) {
917  delete[] name;
918  }
919  }
920  }
921  }
922 
923  return true;
924 }
Scoped object - opens an attribute data type on creation and closes it on destruction.
Definition: Hdf5Util.h:283
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
Scoped object - Opens attribute by name and closes it on destruction.
Definition: Hdf5Util.h:103
Imath::V3i V3i
Definition: SpiMathLib.h:71
Scoped object - Opens attribute by index and closes it on destruction.
Definition: Hdf5Util.h:129
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
Imath::V3f V3f
Definition: SpiMathLib.h:73
Scoped object - opens an attribute data space on creation and closes it on destruction.
Definition: Hdf5Util.h:262
bool Field3DInputFile::readMetadata ( hid_t  metadata_id)
private

Read global metadata for this file.

Todo:
Replace char* with std::string

Definition at line 930 of file Field3DFile.cpp.

References Hdf5Util::H5Base::id(), Field3DFileBase::metadata(), Msg::print(), Hdf5Util::readAttribute(), FieldMetadata< CallBack_T >::setFloatMetadata(), FieldMetadata< CallBack_T >::setIntMetadata(), FieldMetadata< CallBack_T >::setStrMetadata(), FieldMetadata< CallBack_T >::setVecFloatMetadata(), FieldMetadata< CallBack_T >::setVecIntMetadata(), and Msg::SevWarning.

931 {
932 
933  hsize_t num_attrs = H5Aget_num_attrs(metadata_id);
934 
935  if (num_attrs > 0) {
936  for (hsize_t idx=0; idx < num_attrs ; ++idx) {
937  H5ScopedAopenIdx attrIdx(metadata_id, idx);
938  size_t len = H5Aget_name(attrIdx.id(), 0, NULL);
939  if (len > 0) {
940  char *name = new char[len+1];
941  if (H5Aget_name(attrIdx.id(), len+1, name) > 0) {
942  H5ScopedAopen attr(metadata_id, name, H5P_DEFAULT);
943  H5ScopedAget_space attrSpace(attr);
944  H5ScopedAget_type attrType(attr);
945  H5T_class_t typeClass = H5Tget_class(attrType);
946 
947  if (typeClass == H5T_STRING) {
948  string value;
949  if (!readAttribute(metadata_id, name, value)) {
951  "Failed to read metadata " + string(name));
952  if (name) {
953  delete[] name;
954  }
955  continue;
956  }
957  metadata().setStrMetadata(name, value);
958 
959  }
960  else {
961 
962  if (H5Sget_simple_extent_ndims(attrSpace) != 1) {
963  Msg::print(Msg::SevWarning, "Bad attribute rank for attribute "
964  + string(name));
965  if (name) {
966  delete[] name;
967  }
968  continue;
969  }
970 
971  hsize_t dims[1];
972  H5Sget_simple_extent_dims(attrSpace, dims, NULL);
973 
974  if (typeClass == H5T_INTEGER) {
975  if (dims[0] == 1){
976  int value;
977  if (!readAttribute(metadata_id, name, dims[0], value))
978  Msg::print(Msg::SevWarning, "Failed to read metadata "
979  + string(name));
980  metadata().setIntMetadata(name, value);
981  }
982  else if (dims[0] == 3){
983  V3i value;
984  if (!readAttribute(metadata_id, name, dims[0], value.x))
985  Msg::print(Msg::SevWarning, "Failed to read metadata " +
986  string(name) );
987  metadata().setVecIntMetadata(name, value);
988  }
989  else {
991  "Attribute of size " +
992  boost::lexical_cast<std::string>(dims[0])
993  + " is not valid for metadata");
994  }
995  }
996  else if (typeClass == H5T_FLOAT) {
997  if (dims[0] == 1){
998  float value;
999  if (!readAttribute(metadata_id, name, dims[0], value))
1000  Msg::print(Msg::SevWarning, "Failed to read metadata " +
1001  string(name) );
1002 
1003  metadata().setFloatMetadata(name, value);
1004  }
1005  else if (dims[0] == 3){
1006  V3f value;
1007  if (!readAttribute(metadata_id, name, dims[0], value.x))
1008  Msg::print(Msg::SevWarning, "Failed to read metadata "+
1009  string(name) );
1010  metadata().setVecFloatMetadata(name, value);
1011  }
1012  else {
1013  Msg::print(Msg::SevWarning, "Attribute of size " +
1014  boost::lexical_cast<std::string>(dims[0]) +
1015  " is not valid for metadata");
1016  }
1017  }
1018  else {
1019  Msg::print(Msg::SevWarning, "Attribute '" + string(name) +
1020  + "' has unsupported data type for metadata");
1021 
1022  }
1023  }
1024  }
1025  if (name) {
1026  delete[] name;
1027  }
1028  }
1029  }
1030  }
1031 
1032  return true;
1033 }
Scoped object - opens an attribute data type on creation and closes it on destruction.
Definition: Hdf5Util.h:283
void setFloatMetadata(const std::string &name, const float val)
Set the a float value for the given metadata name.
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
void setVecIntMetadata(const std::string &name, const V3i &val)
Set the a V3i value for the given metadata name.
Scoped object - Opens attribute by name and closes it on destruction.
Definition: Hdf5Util.h:103
Imath::V3i V3i
Definition: SpiMathLib.h:71
void setVecFloatMetadata(const std::string &name, const V3f &val)
Set the a V3f value for the given metadata name.
Scoped object - Opens attribute by index and closes it on destruction.
Definition: Hdf5Util.h:129
bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
void setStrMetadata(const std::string &name, const std::string &val)
Set the a string value for the given metadata name.
Imath::V3f V3f
Definition: SpiMathLib.h:73
Scoped object - opens an attribute data space on creation and closes it on destruction.
Definition: Hdf5Util.h:262
FieldMetadata< Field3DFileBase > & metadata()
accessor to the m_metadata class
Definition: Field3DFile.h:315
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.

Member Data Documentation

std::string Field3DInputFile::m_filename
private

Filename, only to be set by open().

Definition at line 603 of file Field3DFile.h.

Referenced by open(), and readLayer().


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