47#ifndef _INCLUDED_Field3D_Field3DFileHDF5_H_
48#define _INCLUDED_Field3D_Field3DFileHDF5_H_
58#include <boost/intrusive_ptr.hpp>
84template <
class Data_T>
87 const std::string &filename,
const std::string &layerPath);
152 typedef boost::intrusive_ptr<Partition>
Ptr;
153 typedef boost::intrusive_ptr<const Partition>
CPtr;
177 virtual std::string className()
const;
194 void getScalarLayerNames(std::vector<std::string> &
names)
const;
196 void getVectorLayerNames(std::vector<std::string> &
names)
const;
251 : name(
nm), parentName(
par), components(
cpt)
284 void getPartitionNames(std::vector<std::string> &
names)
const;
286 void getScalarLayerNames(std::vector<std::string> &
names,
287 const std::string &partitionName)
const;
289 void getVectorLayerNames(std::vector<std::string> &
names,
290 const std::string &partitionName)
const;
295 {
return partition(partitionName); }
305 std::string intPartitionName(
const std::string &partitionName,
311 std::string removeUniqueId(
const std::string &partitionName)
const;
314 void addGroupMembership(
const GroupMembershipMap &
groupMembers);
322 {
return m_metadata; }
326 {
return m_metadata; }
338 void printHierarchy()
const;
355 void closeInternal();
364 void getIntPartitionNames(std::vector<std::string> &
names)
const;
367 void getIntScalarLayerNames(std::vector<std::string> &
names,
368 const std::string &intPartitionName)
const;
371 void getIntVectorLayerNames(std::vector<std::string> &
names,
372 const std::string &intPartitionName)
const;
375 int numIntPartitions(
const std::string &partitionName)
const;
379 std::string makeIntPartitionName(
const std::string &
partitionsName,
463 template <
class Data_T>
465 readScalarLayers(
const std::string &
layerName = std::string(
""))
const;
468 template <
class Data_T>
470 readScalarLayers(
const std::string &partitionName,
477 template <
class Data_T>
479 readVectorLayers(
const std::string &
layerName = std::string(
""))
const;
482 template <
class Data_T>
484 readVectorLayers(
const std::string &partitionName,
489 template <
template <
typename T>
class Field_T,
class Data_T>
490 typename Field_T<Data_T>::Vec
502 typename FieldList::iterator
i =
originals.begin();
523 template <
template <
typename T>
class Field_T,
class Data_T>
524 typename Field_T<Data_T>::Vec
537 typename FieldList::iterator
i =
originals.begin();
558 template <
template <
typename T>
class Field_T,
class Data_T>
572 typename FieldList::iterator
i =
originals.begin();
593 template <
template <
typename T>
class Field_T,
class Data_T>
608 typename FieldList::iterator
i =
originals.begin();
637 template <
class Data_T>
639 readProxyLayer(
const std::string &partitionName,
647 template <
class Data_T>
649 readProxyLayer(
hid_t location,
const std::string &name,
650 const std::string &attribute,
658 template <
class Data_T>
660 readProxyScalarLayers(
const std::string &name = std::string(
""))
const;
667 template <
class Data_T>
669 readProxyVectorLayers(
const std::string &name = std::string(
""))
const;
677 bool open(
const std::string &filename);
704 template <
class Data_T>
706 readScalarLayer(
const std::string &intPartitionName,
711 template <
class Data_T>
713 readVectorLayer(
const std::string &intPartitionName,
718 template <
class Data_T>
720 readLayer(
const std::string &intPartitionName,
725 bool readPartitionAndLayerInfo();
794 template <
class Data_T>
800 template <
class Data_T>
807 template <
class Data_T>
808 bool writeScalarLayer(
const std::string &partitionName,
814 template <
class Data_T>
819 template <
class Data_T>
820 bool writeVectorLayer(
const std::string &partitionName,
826 template <
class Data_T>
832 bool create(
const std::string &filename, CreateMode
cm = OverwriteMode);
835 bool writeGlobalMetadata();
839 bool writeGroupMembership();
842 std::string incrementPartitionName(std::string &
pname);
845 template <
class Data_T>
847 createNewPartition(
const std::string &partitionName,
860 template <
class Data_T>
861 bool writeLayer(
const std::string &partitionName,
908template <
class Data_T>
918 std::vector<std::string>
parts;
921 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
922 std::vector<std::string>
layers;
924 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
926 if ((name.length() == 0) || (*
l == name)) {
940template <
class Data_T>
952 if ((
layerName.length() == 0) || (partitionName.length() == 0))
955 std::vector<std::string>
parts;
958 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
959 std::vector<std::string>
layers;
962 for (vector<string>::iterator
l =
layers.begin();
979template <
class Data_T>
990 std::vector<std::string>
parts;
993 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
994 std::vector<std::string>
layers;
996 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
998 if ((name.length() == 0) || (*
l == name)) {
1011template <
class Data_T>
1016 using namespace std;
1023 if ((
layerName.length() == 0) || (partitionName.length() == 0))
1026 std::vector<std::string>
parts;
1029 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1030 std::vector<std::string>
layers;
1033 for (vector<string>::iterator
l =
layers.begin();
1050template <
class Data_T>
1056 using namespace boost;
1057 using namespace std;
1086 string layerPath =
l->parent +
"/" +
l->name;
1091 +
" in .f3d file ");
1097 if (!readAttribute(
layerGroup.id(),
"class_name", className)) {
1155template <
class Data_T>
1161 using namespace boost;
1162 using namespace std;
1170 if ((
layerName.length() == 0) || (partitionName.length() == 0))
1178 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1186 for (vector<string>::iterator
l =
layers.begin();
1206 string layerPath = layer->
parent +
"/" + layer->
name;
1223 readAttribute(
mipGroup,
"levels", 1, numLevels);
1243template <
class Data_T>
1246 const std::string &name,
1247 const std::string &attribute,
1250 using namespace boost;
1251 using namespace std;
1260 if (!readAttribute(location,
"extents", 6, extents.min.x)) {
1263 if (!readAttribute(location,
"data_window", 6,
dataW.min.x)) {
1287template <
class Data_T>
1291 using namespace std;
1294 typedef std::vector<FieldPtr>
FieldList;
1298 std::vector<std::string>
parts;
1301 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1302 std::vector<std::string>
layers;
1304 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
1306 if ((name.length() == 0) || (*
l == name)) {
1308 for (
typename FieldList::iterator
i =
f.begin();
i !=
f.end(); ++
i) {
1322template <
class Data_T>
1326 using namespace std;
1329 typedef std::vector<FieldPtr>
FieldList;
1333 std::vector<std::string>
parts;
1336 for (vector<string>::iterator
p =
parts.begin();
p !=
parts.end(); ++
p) {
1337 std::vector<std::string>
layers;
1339 for (vector<string>::iterator
l =
layers.begin();
l !=
layers.end(); ++
l) {
1341 if ((name.length() == 0) || (*
l == name)) {
1343 for (
typename FieldList::iterator
i =
f.begin();
i !=
f.end(); ++
i) {
1357template <
class Data_T>
1367template <
class Data_T>
1379template <
class Data_T>
1382 const std::string & ,
1386 using namespace Exc;
1392 newPart->name = partitionName;
1397 "Error creating partition: " +
newPart->name);
1412 "writeMapping returned false for an unknown reason ");
1423 "Unknown error when writing mapping for partition: "
1435 if (!writeAttribute(
partGroup.id(),
"is_field3d_partition",
"1")) {
1445template <
class Data_T>
1452 using namespace std;
1453 using namespace Exc;
1460 "Called writeLayer with null pointer. Ignoring...");
1466 "Attempting to write layer without opening file first. ");
1484 "Couldn't add layer \"" +
layerName +
"\" to partition \""
1485 + partitionName +
"\" because the layer's mapping is null.");
1510 if (!
part->mapping) {
1517 if (!field->
mapping()->isIdentical(
part->mapping)) {
1519 +
"\" to partition \"" + partitionName
1520 +
"\" because mapping doesn't match");
1531 layer.
parent = partitionName;
1544 if (!writeAttribute(
layerGroup.id(),
"class_type",
"field3d_layer")) {
1568 part->addVectorLayer(layer);
1570 part->addScalarLayer(layer);
1577template <
class Data_T>
1588template <
class Data_T>
1592 if (layer->
name.size() == 0) {
1594 "Tried to write a scalar layer with no name");
1599 "Tried to write a scalar layer with no attribute name");
1607template <
class Data_T>
1620template <
class Data_T>
1625 if (layer->name.size() == 0) {
1627 "Tried to write a vector layer with no name");
1630 if (layer->attribute.size() == 0) {
1632 "Tried to write a vector layer with no attribute name");
1642template <
class Data_T>
1645 const std::string &filename,
const std::string &layerPath)
Contains the ClassFactory class for registering Field3D classes.
Contains the EmptyField class.
Field< Data_T >::Ptr readField(const std::string &className, hid_t layerGroup, const std::string &filename, const std::string &layerPath)
This function creates a FieldIO instance based on className which then reads the field data from laye...
FIELD3D_API bool writeField(hid_t layerGroup, FieldBase::Ptr field)
This function creates a FieldIO instance based on field->className() which then writes the field data...
FIELD3D_API bool writeFieldMapping(hid_t mappingGroup, FieldMapping::Ptr mapping)
This function creates a FieldMappingIO instance based on mapping->className() which then writes Field...
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
Contains the FieldCache class.
Contains Field, WritableField and ResizableField classes.
Contains various utility functions for Hdf5.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
boost::recursive_mutex::scoped_lock GlobalLock
static ClassFactory & singleton()
}
This subclass of Field does not store any data.
boost::intrusive_ptr< EmptyField > Ptr
std::map< std::string, int > PartitionCountMap
std::vector< std::string > m_partitionNames
This stores partition names.
PartitionList m_partitions
Vector of partitions.
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.
virtual void metadataHasChanged(const std::string &)
This function should implemented by concrete classes to get the callback when metadata changes.
Field3DFileHDF5Base(const Field3DFileHDF5Base &)
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
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 ...
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
void getIntScalarLayerNames(std::vector< std::string > &names, const std::string &intPartitionName) const
Gets the names of all the scalar layers in a given partition, but assumes that partition name is the ...
std::vector< FileHDF5::Partition::Ptr > PartitionList
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 ...
FileHDF5::Partition::Ptr partition(const std::string &partitionName) const
Returns a pointer to the given partition.
FieldMetadata & metadata()
accessor to the m_metadata class
void getScalarLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the scalar layers in a given partition.
std::vector< LayerInfo > m_layerInfo
This stores layer info.
const FieldMetadata & metadata() const
Read only access to the m_metadata class.
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
FieldMetadata m_metadata
metadata
FileHDF5::Partition::Ptr getPartition(const std::string &partitionName) const
Returns a pointer to the given partition.
std::map< std::string, std::string > GroupMembershipMap
Provides writing of .f3d (internally, hdf5) files.
FileHDF5::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr field)
create newPartition given the input config
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a vector layer to the "Default" partition.
bool writeMapping(hid_t partitionLocation, FieldMapping::Ptr mapping)
Writes the mapping to the given hdf5 node. Mappings are assumed to be light-weight enough to be store...
bool writeMetadata(hid_t metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
bool writeLayer(const std::string &partitionName, const std::string &layerName, bool isVectorLayer, typename Field< Data_T >::Ptr layer)
Performs the actual writing of the layer to disk.
bool writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
std::string incrementPartitionName(std::string &pname)
increment the partition or make it zero if there's not an integer suffix
Provides writing of .f3d (internally, hdf5 or Ogawa) files.
boost::intrusive_ptr< FieldBase > Ptr
FieldMetadata & metadata()
accessor to the m_metadata class
std::string attribute
Optional name of the attribute the field represents.
std::string name
Optional name of the field.
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
boost::intrusive_ptr< FieldIO > Ptr
boost::intrusive_ptr< FieldMapping > Ptr
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
boost::intrusive_ptr< FieldRes > Ptr
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
boost::intrusive_ptr< Field > Ptr
std::string parent
The name of the parent partition. We need this in order to open its group.
std::string name
The name of the layer (always available)
boost::intrusive_ptr< Partition > Ptr
boost::intrusive_ptr< const Partition > CPtr
std::vector< Layer > VectorLayerList
std::string name
Name of the partition.
DEFINE_FIELD_RTTI_CONCRETE_CLASS
RefBase base
Convenience typedef for referring to base class.
VectorLayerList m_vectorLayers
The vector-valued layers belonging to this partition.
static const char * staticClassType()
FieldMapping::Ptr mapping
Pointer to the mapping object.
std::vector< Layer > ScalarLayerList
ScalarLayerList m_scalarLayers
The scalar-valued layers belonging to this partition.
Scoped object - creates a group on creation and closes it on destruction.
Scoped object - opens a group on creation and closes it on destruction.
RefBase & operator=(const RefBase &)
Assignment operator.
void setSize(const V3i &size)
Resizes the object.
Namespace for Exception objects.
Namespace for file I/O specifics.
Contains utility functions and classes for Hdf5 files.
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
static DataTypeEnum typeEnum()
LayerInfo(std::string par, std::string nm, int cpt)