47#ifndef _INCLUDED_Field3D_Field3DFileHDF5_H_
48#define _INCLUDED_Field3D_Field3DFileHDF5_H_
58#include <boost/intrusive_ptr.hpp>
84template <
class Data_T>
86readField(
const std::string &className, hid_t layerGroup,
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;
287 const std::string &partitionName)
const;
290 const std::string &partitionName)
const;
305 std::string intPartitionName(
const std::string &partitionName,
306 const std::string &layerName,
311 std::string removeUniqueId(
const std::string &partitionName)
const;
314 void addGroupMembership(
const GroupMembershipMap &groupMembers);
338 void printHierarchy()
const;
463 template <
class Data_T>
468 template <
class Data_T>
471 const std::string &layerName)
const;
477 template <
class Data_T>
482 template <
class Data_T>
485 const std::string &layerName)
const;
489 template <
template <
typename T>
class Field_T,
class Data_T>
490 typename Field_T<Data_T>::Vec
494 typedef typename Field_T<Data_T>::Vec TypedFieldList;
501 TypedFieldList output;
502 typename FieldList::iterator i = originals.begin();
503 for (; i != originals.end(); ++i) {
504 typename Field_T<Data_T>::Ptr targetField;
507 output.push_back(targetField);
509 typename Field_T<Data_T>::Ptr newTarget(
new Field_T<Data_T>);
510 newTarget->name = (*i)->name;
511 newTarget->attribute = (*i)->attribute;
512 newTarget->copyMetadata(**i);
513 newTarget->copyFrom(*i);
514 output.push_back(newTarget);
523 template <
template <
typename T>
class Field_T,
class Data_T>
524 typename Field_T<Data_T>::Vec
526 const std::string &layerName)
const
529 typedef typename Field_T<Data_T>::Vec TypedFieldList;
536 TypedFieldList output;
537 typename FieldList::iterator i = originals.begin();
538 for (; i != originals.end(); ++i) {
539 typename Field_T<Data_T>::Ptr targetField;
542 output.push_back(targetField);
544 typename Field_T<Data_T>::Ptr newTarget(
new Field_T<Data_T>);
545 newTarget->name = (*i)->name;
546 newTarget->attribute = (*i)->attribute;
547 newTarget->copyMetadata(**i);
548 newTarget->copyFrom(*i);
549 output.push_back(newTarget);
558 template <
template <
typename T>
class Field_T,
class Data_T>
559 typename Field_T<FIELD3D_VEC3_T<Data_T> >
::Vec
562 typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
564 typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >
::Vec TypedFieldList;
571 TypedFieldList output;
572 typename FieldList::iterator i = originals.begin();
573 for (; i != originals.end(); ++i) {
574 typename TypedVField::Ptr targetField;
577 output.push_back(targetField);
579 typename TypedVField::Ptr newTarget(
new TypedVField);
580 newTarget->name = (*i)->name;
581 newTarget->attribute = (*i)->attribute;
582 newTarget->copyMetadata(**i);
583 newTarget->copyFrom(*i);
584 output.push_back(newTarget);
593 template <
template <
typename T>
class Field_T,
class Data_T>
594 typename Field_T<FIELD3D_VEC3_T<Data_T> >
::Vec
596 const std::string &layerName)
const
598 typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
600 typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >
::Vec TypedFieldList;
607 TypedFieldList output;
608 typename FieldList::iterator i = originals.begin();
609 for (; i != originals.end(); ++i) {
610 typename TypedVField::Ptr targetField;
613 output.push_back(targetField);
615 typename TypedVField::Ptr newTarget(
new TypedVField);
616 newTarget->name = (*i)->name;
617 newTarget->attribute = (*i)->attribute;
618 newTarget->copyMetadata(**i);
619 newTarget->copyFrom(*i);
620 output.push_back(newTarget);
637 template <
class Data_T>
639 readProxyLayer(
const std::string &partitionName,
640 const std::string &layerName,
641 bool isVectorLayer)
const;
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);
685 herr_t parsePartition(hid_t loc_id,
const std::string partitionName);
688 herr_t parseLayer(hid_t loc_id,
const std::string &partitionName,
689 const std::string &layerName);
696 bool readGroupMembership(GroupMembershipMap &gpMembershipMap);
704 template <
class Data_T>
706 readScalarLayer(
const std::string &intPartitionName,
707 const std::string &layerName)
const;
711 template <
class Data_T>
713 readVectorLayer(
const std::string &intPartitionName,
714 const std::string &layerName)
const;
718 template <
class Data_T>
720 readLayer(
const std::string &intPartitionName,
721 const std::string &layerName,
722 bool isVectorLayer)
const;
725 bool readPartitionAndLayerInfo();
731 bool readMetadata(hid_t metadata_id);
794 template <
class Data_T>
800 template <
class Data_T>
807 template <
class Data_T>
808 bool writeScalarLayer(
const std::string &partitionName,
809 const std::string &layerName,
814 template <
class Data_T>
819 template <
class Data_T>
820 bool writeVectorLayer(
const std::string &partitionName,
821 const std::string &layerName,
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,
848 const std::string &layerName,
860 template <
class Data_T>
861 bool writeLayer(
const std::string &partitionName,
862 const std::string &layerName,
870 bool writeMetadata(hid_t metadataGroup);
894 const H5L_info_t *linfo,
void *opdata);
900 const H5L_info_t *linfo,
void *opdata);
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>
943 const std::string &layerName)
const
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();
963 l != layers.end(); ++l) {
965 if (*l == layerName) {
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>
1014 const std::string &layerName)
const
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();
1034 l != layers.end(); ++l) {
1036 if (*l == layerName) {
1050template <
class Data_T>
1053 const std::string &layerName,
1054 bool isVectorLayer)
const
1056 using namespace boost;
1057 using namespace std;
1077 l = part->vectorLayer(layerName);
1079 l = part->scalarLayer(layerName);
1086 string layerPath = l->
parent +
"/" + l->
name;
1089 if (layerGroup.
id() < 0) {
1091 +
" in .f3d file ");
1134 string metadataPath = layerPath +
"/metadata";
1136 if (metadataGroup.
id() > 0) {
1155template <
class Data_T>
1158 const std::string &layerName,
1159 bool isVectorLayer)
const
1161 using namespace boost;
1162 using namespace std;
1170 if ((layerName.length() == 0) || (partitionName.length() == 0))
1173 std::vector<std::string> parts, layers;
1176 bool foundPartition =
false;
1178 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1180 foundPartition =
true;
1181 if (isVectorLayer) {
1186 for (vector<string>::iterator l = layers.begin();
1187 l != layers.end(); ++l) {
1188 if (*l == layerName) {
1198 layer = part->vectorLayer(layerName);
1200 layer = part->scalarLayer(layerName);
1206 string layerPath = layer->
parent +
"/" + layer->
name;
1208 if (layerGroup.
id() < 0) {
1210 + layerName +
" in .f3d file ");
1222 if (mipGroup.
id() >= 0)
1227 output.push_back(field);
1233 if (!foundPartition) {
1243template <
class Data_T>
1246 const std::string &name,
1247 const std::string &attribute,
1250 using namespace boost;
1251 using namespace std;
1259 Box3i extents, dataW;
1260 if (!
readAttribute(location,
"extents", 6, extents.min.x)) {
1263 if (!
readAttribute(location,
"data_window", 6, dataW.min.x)) {
1269 field->
setSize(extents, dataW);
1273 if (metadataGroup.
id() > 0) {
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>
1360 const std::string &layerName)
const
1367template <
class Data_T>
1370 const std::string &layerName)
const
1379template <
class Data_T>
1382 const std::string & ,
1386 using namespace Exc;
1392 newPart->name = partitionName;
1395 if (partGroup.
id() < 0) {
1397 "Error creating partition: " + newPart->name);
1412 "writeMapping returned false for an unknown reason ");
1416 catch (WriteMappingException &e) {
1423 "Unknown error when writing mapping for partition: "
1431 part->mapping = field->
mapping();
1445template <
class Data_T>
1448 const std::string &layerName,
1452 using namespace std;
1453 using namespace Exc;
1460 "Called writeLayer with null pointer. Ignoring...");
1466 "Attempting to write layer without opening file first. ");
1470 string partitionName =
intPartitionName(userPartitionName, layerName, field);
1484 "Couldn't add layer \"" + layerName +
"\" to partition \""
1485 + partitionName +
"\" because the layer's mapping is null.");
1491 if (!isVectorLayer) {
1492 if (part->scalarLayer(layerName)) {
1500 if (part->vectorLayer(layerName)) {
1510 if (!part->mapping) {
1517 if (!field->
mapping()->isIdentical(part->mapping)) {
1519 +
"\" to partition \"" + partitionName
1520 +
"\" because mapping doesn't match");
1530 layer.
name = layerName;
1531 layer.
parent = partitionName;
1536 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1538 if (layerGroup.
id() < 0) {
1551 if (metadataGroup.
id() < 0) {
1568 part->addVectorLayer(layer);
1570 part->addScalarLayer(layer);
1577template <
class Data_T>
1580 const std::string &layerName,
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>
1611 const std::string &layerName,
1620template <
class Data_T>
1625 if (layer->
name.size() == 0) {
1627 "Tried to write a vector layer with no name");
1632 "Tried to write a vector layer with no attribute name");
1642template <
class Data_T>
1645 const std::string &filename,
const std::string &layerPath)
1660 FieldBase::Ptr field = io->read(layerGroup, filename, layerPath, typeEnum);
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
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
static ClassFactory & singleton()
}
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.
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ....
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.
bool close()
Closes the file. No need to call this unless you specifically want to close the file early....
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 ...
friend class Field3DInputFile
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.
friend class Field3DOutputFile
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 closeInternal()
Closes the file if open.
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.
int numIntPartitions(const std::string &partitionName) const
Returns the number of internal partitions for a given partition name.
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
void clear()
Clear the data structures and close the file.
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
friend class Field3DInputFile
friend class Field3DOutputFile
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
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.
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
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.
hid_t id() const
Query the hid_t value.
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.
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...
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
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)