Field3D
Field3DOutputFileHDF5 Class Reference

Provides writing of .f3d (internally, hdf5) files. More...

#include <Field3DFileHDF5.h>

Inheritance diagram for Field3DOutputFileHDF5:
Field3DFileHDF5Base MetadataCallback

Public Types

enum  CreateMode { OverwriteMode, FailOnExisting }
 
- Public Types inherited from Field3DFileHDF5Base
typedef std::map< std::string, std::string > GroupMembershipMap
 

Public Member Functions

bool create (const std::string &filename, CreateMode cm=OverwriteMode)
 Creates a .f3d file on disk. More...
 
template<class Data_T >
FileHDF5::Partition::Ptr createNewPartition (const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr field)
 create newPartition given the input config More...
 
std::string incrementPartitionName (std::string &pname)
 increment the partition or make it zero if there's not an integer suffix More...
 
bool writeGlobalMetadata ()
 This routine is call if you want to write out global metadata to disk. More...
 
bool writeGroupMembership ()
 This routine is called just before closing to write out any group membership to disk. More...
 
Constructors & destructor
 Field3DOutputFileHDF5 ()
 
virtual ~Field3DOutputFileHDF5 ()
 
Writing layer to disk
template<class Data_T >
bool writeScalarLayer (const std::string &layerName, typename Field< Data_T >::Ptr layer)
 Writes a scalar layer to the "Default" partition. More...
 
template<class Data_T >
bool writeVectorLayer (const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
 Writes a vector layer to the "Default" partition. More...
 
template<class Data_T >
bool writeScalarLayer (const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr layer)
 Writes a layer to a specific partition. The partition will be created if not specified. More...
 
template<class Data_T >
bool writeScalarLayer (typename Field< Data_T >::Ptr layer)
 Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively. More...
 
template<class Data_T >
bool writeVectorLayer (const std::string &partitionName, const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
 Writes a layer to a specific partition. The partition will be created if not specified. More...
 
template<class Data_T >
bool writeVectorLayer (typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
 Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively. More...
 
- Public Member Functions inherited from Field3DFileHDF5Base
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 FileHDF5 object goes out of scope. More...
 
FieldMetadatametadata ()
 accessor to the m_metadata class More...
 
const FieldMetadatametadata () const
 Read only access to the m_metadata class. More...
 
virtual void metadataHasChanged (const std::string &)
 This function should implemented by concrete classes to
get the callback when metadata changes. More...
 
 Field3DFileHDF5Base ()
 
virtual ~Field3DFileHDF5Base ()=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...
 
FileHDF5::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 >
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. More...
 
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 stored as plain attributes under a group. More...
 
bool writeMetadata (hid_t metadataGroup)
 Writes metadata for this file. More...
 
bool writeMetadata (hid_t metadataGroup, FieldBase::Ptr layer)
 Writes metadata for this layer. More...
 

Friends

class Field3DInputFile
 
class Field3DOutputFile
 

Additional Inherited Members

- Protected Types inherited from Field3DFileHDF5Base
typedef std::map< std::string, int > PartitionCountMap
 
typedef std::vector< FileHDF5::Partition::PtrPartitionList
 
- Protected Member Functions inherited from Field3DFileHDF5Base
void closeInternal ()
 Closes the file if open. More...
 
FileHDF5::Partition::Ptr partition (const std::string &partitionName)
 Returns a pointer to the given partition. More...
 
FileHDF5::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 Field3DFileHDF5Base
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 m_metadata
 metadata More...
 
PartitionCountMap m_partitionCount
 Contains a counter for each partition name. This is used to keep multiple fields with the same name unique in the file. More...
 
std::vector< std::string > m_partitionNames
 This stores partition names. More...
 
PartitionList m_partitions
 Vector of partitions. More...
 

Detailed Description

Provides writing 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 764 of file Field3DFileHDF5.h.

Member Enumeration Documentation

◆ CreateMode

Enumerator
OverwriteMode 
FailOnExisting 

Definition at line 773 of file Field3DFileHDF5.h.

773  {
776  };

Constructor & Destructor Documentation

◆ Field3DOutputFileHDF5()

Field3DOutputFileHDF5::Field3DOutputFileHDF5 ( )

Definition at line 1223 of file Field3DFileHDF5.cpp.

1224 {
1225  // Empty
1226 }

◆ ~Field3DOutputFileHDF5()

Field3DOutputFileHDF5::~Field3DOutputFileHDF5 ( )
virtual

Definition at line 1230 of file Field3DFileHDF5.cpp.

1231 {
1232 
1233 }

Member Function Documentation

◆ writeScalarLayer() [1/3]

template<class Data_T >
bool Field3DOutputFileHDF5::writeScalarLayer ( const std::string &  layerName,
typename Field< Data_T >::Ptr  layer 
)
inline

Writes a scalar layer to the "Default" partition.

Definition at line 795 of file Field3DFileHDF5.h.

797  { return writeScalarLayer<Data_T>(layerName, std::string("default"), layer); }

◆ writeVectorLayer() [1/3]

template<class Data_T >
bool Field3DOutputFileHDF5::writeVectorLayer ( const std::string &  layerName,
typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr  layer 
)
inline

Writes a vector layer to the "Default" partition.

Definition at line 801 of file Field3DFileHDF5.h.

803  { return writeVectorLayer<Data_T>(layerName, std::string("default"), layer); }

◆ writeScalarLayer() [2/3]

template<class Data_T >
bool Field3DOutputFileHDF5::writeScalarLayer ( const std::string &  partitionName,
const std::string &  layerName,
typename Field< Data_T >::Ptr  layer 
)

Writes a layer to a specific partition. The partition will be created if not specified.

Definition at line 1579 of file Field3DFileHDF5.h.

1582 {
1583  return writeLayer<Data_T>(partitionName, layerName, false, field);
1584 }

◆ writeScalarLayer() [3/3]

template<class Data_T >
bool Field3DOutputFileHDF5::writeScalarLayer ( typename Field< Data_T >::Ptr  layer)

Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.

Definition at line 1590 of file Field3DFileHDF5.h.

1591 {
1592  if (layer->name.size() == 0) {
1593  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeScalarLayer: "
1594  "Tried to write a scalar layer with no name");
1595  return false;
1596  }
1597  if (layer->attribute.size() == 0) {
1598  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeScalarLayer: "
1599  "Tried to write a scalar layer with no attribute name");
1600  return false;
1601  }
1602  return writeScalarLayer<Data_T>(layer->name, layer->attribute, layer);
1603 }

References FieldBase::attribute, FieldBase::name, Msg::print(), and Msg::SevWarning.

◆ writeVectorLayer() [2/3]

template<class Data_T >
bool Field3DOutputFileHDF5::writeVectorLayer ( const std::string &  partitionName,
const std::string &  layerName,
typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr  layer 
)

Writes a layer to a specific partition. The partition will be created if not specified.

Definition at line 1609 of file Field3DFileHDF5.h.

1613 {
1614  return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName,
1615  true, field);
1616 }

◆ writeVectorLayer() [3/3]

template<class Data_T >
bool Field3DOutputFileHDF5::writeVectorLayer ( typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr  layer)

Writes a layer to a specific partition. The field name and attribute name are used for partition and layer, respectively.

Definition at line 1622 of file Field3DFileHDF5.h.

1624 {
1625  if (layer->name.size() == 0) {
1626  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeVectorLayer: "
1627  "Tried to write a vector layer with no name");
1628  return false;
1629  }
1630  if (layer->attribute.size() == 0) {
1631  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeVectorLayer: "
1632  "Tried to write a vector layer with no attribute name");
1633  return false;
1634  }
1635  return writeVectorLayer<Data_T>(layer->name, layer->attribute, layer);
1636 }

References Msg::print(), and Msg::SevWarning.

◆ create()

bool Field3DOutputFileHDF5::create ( const std::string &  filename,
CreateMode  cm = OverwriteMode 
)

Creates a .f3d file on disk.

Todo:
If the file can't be created hdf5 spits out an ugly error msg, we should make sure that doesn't happen.

Definition at line 1239 of file Field3DFileHDF5.cpp.

1240 {
1241  GlobalLock lock(g_hdf5Mutex);
1242 
1243  closeInternal();
1244 
1245  bool success = true;
1246 
1247  try {
1248 
1249  hid_t faid = H5Pcreate(H5P_FILE_ACCESS);
1250  H5Pset_libver_bounds(faid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
1251 
1252  // Create new file
1253  switch (cm) {
1254  case OverwriteMode:
1255  m_file = H5Fcreate(filename.c_str(),
1256  H5F_ACC_TRUNC, H5P_DEFAULT, faid);
1257  break;
1258  case FailOnExisting:
1259  m_file = H5Fcreate(filename.c_str(),
1260  H5F_ACC_EXCL, H5P_DEFAULT, faid);
1261  break;
1262  }
1263 
1264  // Check that file was created
1265  if (m_file < 0)
1266  throw ErrorCreatingFileException(filename);
1267 
1268  // Create a version attribute on the root node
1269  if (!writeAttribute(m_file, k_versionAttrName, 3,
1270  k_currentFileVersion[0])) {
1271  Msg::print(Msg::SevWarning, "Adding version number.");
1272  closeInternal();
1273  return false;
1274  }
1275 
1276  }
1277  catch (ErrorCreatingFileException &e) {
1278  Msg::print(Msg::SevWarning, "Couldn't create file: " + string(e.what()) );
1279  success = false;
1280  }
1281  catch (WriteAttributeException &e) {
1282  Msg::print(Msg::SevWarning, "In file : " + filename +
1283  " - Couldn't add attribute " + string(e.what()) );
1284  success = false;
1285  }
1286  catch (...) {
1288  "Unknown error when creating file: " + filename );
1289  success = false;
1290  }
1291 
1292  return success;
1293 }

References Field3DFileHDF5Base::closeInternal(), g_hdf5Mutex, Field3DFileHDF5Base::m_file, Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

◆ writeGlobalMetadata()

bool Field3DOutputFileHDF5::writeGlobalMetadata ( )

This routine is call if you want to write out global metadata to disk.

Definition at line 1483 of file Field3DFileHDF5.cpp.

1484 {
1485  GlobalLock lock(g_hdf5Mutex);
1486 
1487  // Add metadata group and write it out
1488  H5ScopedGcreate metadataGroup(m_file, "field3d_global_metadata");
1489  if (metadataGroup.id() < 0) {
1490  Msg::print(Msg::SevWarning, "Error creating group: file metadata");
1491  return false;
1492  }
1493  if (!writeMetadata(metadataGroup.id())) {
1494  Msg::print(Msg::SevWarning, "Error writing file metadata.");
1495  return false;
1496  }
1497 
1498  return true;
1499 }

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, Msg::print(), and Msg::SevWarning.

◆ writeGroupMembership()

bool Field3DOutputFileHDF5::writeGroupMembership ( )

This routine is called just before closing to write out any group membership to disk.

Definition at line 1504 of file Field3DFileHDF5.cpp.

1505 {
1506  using namespace std;
1507  using namespace Hdf5Util;
1508 
1509  GlobalLock lock(g_hdf5Mutex);
1510 
1511  if (!m_groupMembership.size())
1512  return true;
1513 
1514  H5ScopedGcreate group(m_file, "field3d_group_membership");
1515  if (group < 0) {
1517  "Error creating field3d_group_membership group.");
1518  return false;
1519  }
1520 
1521  if (!writeAttribute(group, "is_field3d_group_membership", "1")) {
1523  "Failed to write field3d_group_membership attribute.");
1524  return false;
1525  }
1526 
1527  std::map<std::string, std::string>::const_iterator iter =
1528  m_groupMembership.begin();
1529  std::map<std::string, std::string>::const_iterator iEnd =
1530  m_groupMembership.end();
1531 
1532  for (; iter != iEnd; ++iter) {
1533  if (!writeAttribute(group, iter->first, iter->second)) {
1535  "Failed to write groupMembership string: "+ iter->first);
1536  return false;
1537  }
1538  }
1539 
1540  return true;
1541 }

References g_hdf5Mutex, Field3DFileHDF5Base::m_file, Field3DFileHDF5Base::m_groupMembership, Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

◆ incrementPartitionName()

std::string Field3DOutputFileHDF5::incrementPartitionName ( std::string &  pname)

increment the partition or make it zero if there's not an integer suffix

Definition at line 1546 of file Field3DFileHDF5.cpp.

1547 {
1548  std::string myPartitionName = removeUniqueId(partitionName);
1549  int nextIdx = -1;
1550  if (m_partitionCount.find(myPartitionName) != m_partitionCount.end()) {
1551  nextIdx = ++m_partitionCount[myPartitionName];
1552  } else {
1553  nextIdx = 0;
1554  m_partitionCount[myPartitionName] = 0;
1555  }
1556 
1557  return makeIntPartitionName(myPartitionName, nextIdx);
1558 }

References Field3DFileHDF5Base::m_partitionCount, Field3DFileHDF5Base::makeIntPartitionName(), and Field3DFileHDF5Base::removeUniqueId().

◆ createNewPartition()

template<class Data_T >
FileHDF5::Partition::Ptr Field3DOutputFileHDF5::createNewPartition ( const std::string &  partitionName,
const std::string &  layerName,
typename Field< Data_T >::Ptr  field 
)

create newPartition given the input config

Todo:
We should probably remove the group on disk if we can't write the mapping

Definition at line 1381 of file Field3DFileHDF5.h.

1384 {
1385  using namespace Hdf5Util;
1386  using namespace Exc;
1387 
1388  GlobalLock lock(g_hdf5Mutex);
1389 
1391 
1392  newPart->name = partitionName;
1393 
1394  H5ScopedGcreate partGroup(m_file, newPart->name.c_str());
1395  if (partGroup.id() < 0) {
1397  "Error creating partition: " + newPart->name);
1398  return FileHDF5::Partition::Ptr();
1399  }
1400 
1401  m_partitions.push_back(newPart);
1402 
1403  // Pick up new pointer
1404  FileHDF5::Partition::Ptr part = partition(partitionName);
1405 
1406  // Add mapping group to the partition
1409  try {
1410  if (!writeMapping(partGroup.id(), field->mapping())) {
1412  "writeMapping returned false for an unknown reason ");
1413  return FileHDF5::Partition::Ptr();
1414  }
1415  }
1416  catch (WriteMappingException &e) {
1417  Msg::print(Msg::SevWarning, "Couldn't write mapping for partition: "
1418  + partitionName);
1419  return FileHDF5::Partition::Ptr();
1420  }
1421  catch (...) {
1423  "Unknown error when writing mapping for partition: "
1424  + partitionName);
1425  return FileHDF5::Partition::Ptr();
1426  }
1427 
1428  // Set the mapping of the partition. Since all layers share their
1429  // partition's mapping, we can just pick this first one. All subsequent
1430  // additions to the same partition are checked to have the same mapping
1431  part->mapping = field->mapping();
1432 
1433  // Tag node as partition
1434  // Create a version attribute on the root node
1435  if (!writeAttribute(partGroup.id(), "is_field3d_partition", "1")) {
1436  Msg::print(Msg::SevWarning, "Adding partition string.");
1437  return FileHDF5::Partition::Ptr();
1438  }
1439 
1440  return part;
1441 }

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::m_file, Field3DFileHDF5Base::m_partitions, FieldRes::mapping(), Field3DFileHDF5Base::partition(), Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

◆ writeMapping()

bool Field3DOutputFileHDF5::writeMapping ( hid_t  partitionLocation,
FieldMapping::Ptr  mapping 
)
private

Writes the mapping to the given hdf5 node. Mappings are assumed to be light-weight enough to be stored as plain attributes under a group.

Definition at line 1297 of file Field3DFileHDF5.cpp.

1299 {
1300  GlobalLock lock(g_hdf5Mutex);
1301 
1302  try {
1303  // Make a group under the partition to store the mapping data
1304  H5ScopedGcreate mappingGroup(partitionGroup, k_mappingStr);
1305  if (mappingGroup.id() < 0)
1306  throw CreateGroupException(k_mappingStr);
1307  // Let FieldMappingIO handle the rest
1308  if (!writeFieldMapping(mappingGroup.id(), mapping))
1309  throw WriteMappingException(k_mappingStr);
1310  }
1311  catch (CreateGroupException &e) {
1312  Msg::print(Msg::SevWarning, "Couldn't create group: " + string(e.what()) );
1313  throw WriteMappingException(k_mappingStr);
1314  }
1315  return true;
1316 }

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

◆ writeLayer()

template<class Data_T >
bool Field3DOutputFileHDF5::writeLayer ( const std::string &  partitionName,
const std::string &  layerName,
bool  isVectorLayer,
typename Field< Data_T >::Ptr  layer 
)
private

Performs the actual writing of the layer to disk.

Definition at line 1447 of file Field3DFileHDF5.h.

1451 {
1452  using namespace std;
1453  using namespace Exc;
1454  using namespace Hdf5Util;
1455 
1456  GlobalLock lock(g_hdf5Mutex);
1457 
1458  if (!field) {
1460  "Called writeLayer with null pointer. Ignoring...");
1461  return false;
1462  }
1463 
1464  if (m_file < 0) {
1466  "Attempting to write layer without opening file first. ");
1467  return false;
1468  }
1469 
1470  string partitionName = intPartitionName(userPartitionName, layerName, field);
1471 
1472  // See if the partition already exists or if we need to make it ---
1473 
1474  FileHDF5::Partition::Ptr part = partition(partitionName);
1475 
1476  if (!part) {
1477  part = createNewPartition<Data_T>(partitionName,layerName,field);
1478  if (!part)
1479  return false;
1480  } else {
1481 
1482  if (!field->mapping()) {
1484  "Couldn't add layer \"" + layerName + "\" to partition \""
1485  + partitionName + "\" because the layer's mapping is null.");
1486  return false;
1487  }
1488 
1489  // If the partition already existed, we need to make sure that the layer
1490  // doesn't also exist
1491  if (!isVectorLayer) {
1492  if (part->scalarLayer(layerName)) {
1493  //need to create a new partition and then add the layer to that
1494  std::string newPartitionName = incrementPartitionName(partitionName);
1495  part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1496  if (!part)
1497  return false;
1498  }
1499  } else {
1500  if (part->vectorLayer(layerName)) {
1501  //need to create a new partition and then add the layer to that
1502  std::string newPartitionName = incrementPartitionName(partitionName);
1503  part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1504  if (!part)
1505  return false;
1506  }
1507  }
1508  }
1509 
1510  if (!part->mapping) {
1511  Msg::print(Msg::SevWarning, "Severe error - partition mapping is null: "
1512  + partitionName);
1513  return false;
1514  }
1515 
1516  // Check that the mapping matches what's already in the Partition
1517  if (!field->mapping()->isIdentical(part->mapping)) {
1518  Msg::print(Msg::SevWarning, "Couldn't add layer \"" + layerName
1519  + "\" to partition \"" + partitionName
1520  + "\" because mapping doesn't match");
1521  return false;
1522  }
1523 
1524  // Open the partition
1525  H5ScopedGopen partGroup(m_file, part->name.c_str(), H5P_DEFAULT);
1526 
1527  // Build a Layer object ---
1528 
1529  FileHDF5::Layer layer;
1530  layer.name = layerName;
1531  layer.parent = partitionName;
1532 
1533  // Add Layer to file ---
1534 
1535  H5ScopedGcreate layerGroup(partGroup.id(), layerName.c_str(),
1536  H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1537 
1538  if (layerGroup.id() < 0) {
1539  Msg::print(Msg::SevWarning, "Error creating layer: " + layerName);
1540  return false;
1541  }
1542 
1543  // Tag as layer
1544  if (!writeAttribute(layerGroup.id(), "class_type", "field3d_layer")) {
1545  Msg::print(Msg::SevWarning, "Error adding layer string.");
1546  return false;
1547  }
1548 
1549  // Add metadata group and write it out
1550  H5ScopedGcreate metadataGroup(layerGroup.id(), "metadata");
1551  if (metadataGroup.id() < 0) {
1552  Msg::print(Msg::SevWarning, "Error creating group: metadata");
1553  return false;
1554  }
1555  if (!writeMetadata(metadataGroup.id(), field)) {
1556  Msg::print(Msg::SevWarning, "Error writing metadata.");
1557  return false;
1558  }
1559 
1560  if (!writeField(layerGroup.id(), field)) {
1561  Msg::print(Msg::SevWarning, "Error writing layer: " + layer.name);
1562  return false;
1563  }
1564 
1565  // Add layer to partition ---
1566 
1567  if (isVectorLayer)
1568  part->addVectorLayer(layer);
1569  else
1570  part->addScalarLayer(layer);
1571 
1572  return true;
1573 }

References g_hdf5Mutex, Hdf5Util::H5Base::id(), Field3DFileHDF5Base::intPartitionName(), Field3DFileHDF5Base::m_file, FieldRes::mapping(), FileHDF5::Layer::name, FileHDF5::Layer::parent, Field3DFileHDF5Base::partition(), Msg::print(), Msg::SevWarning, Hdf5Util::writeAttribute(), and writeField().

◆ writeMetadata() [1/2]

bool Field3DOutputFileHDF5::writeMetadata ( hid_t  metadataGroup,
FieldBase::Ptr  layer 
)
private

Writes metadata for this layer.

Definition at line 1320 of file Field3DFileHDF5.cpp.

1321 {
1322  using namespace Hdf5Util;
1323 
1324  {
1325  FieldMetadata::StrMetadata::const_iterator i =
1326  field->metadata().strMetadata().begin();
1327  FieldMetadata::StrMetadata::const_iterator end =
1328  field->metadata().strMetadata().end();
1329  for (; i != end; ++i) {
1330  if (!writeAttribute(metadataGroup, i->first, i->second))
1331  {
1332  Msg::print(Msg::SevWarning, "Writing attribute " + i->first );
1333  return false;
1334  }
1335  }
1336  }
1337 
1338  {
1339  FieldMetadata::IntMetadata::const_iterator i =
1340  field->metadata().intMetadata().begin();
1341  FieldMetadata::IntMetadata::const_iterator end =
1342  field->metadata().intMetadata().end();
1343  for (; i != end; ++i) {
1344  if (!writeAttribute(metadataGroup, i->first, 1, i->second))
1345  {
1346  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1347  return false;
1348  }
1349  }
1350  }
1351 
1352  {
1353  FieldMetadata::FloatMetadata::const_iterator i =
1354  field->metadata().floatMetadata().begin();
1355  FieldMetadata::FloatMetadata::const_iterator end =
1356  field->metadata().floatMetadata().end();
1357  for (; i != end; ++i) {
1358  if (!writeAttribute(metadataGroup, i->first, 1, i->second))
1359  {
1360  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1361  return false;
1362  }
1363  }
1364  }
1365 
1366  {
1367  FieldMetadata::VecIntMetadata::const_iterator i =
1368  field->metadata().vecIntMetadata().begin();
1369  FieldMetadata::VecIntMetadata::const_iterator end =
1370  field->metadata().vecIntMetadata().end();
1371  for (; i != end; ++i) {
1372  if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
1373  {
1374  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1375  return false;
1376  }
1377  }
1378  }
1379 
1380  {
1381  FieldMetadata::VecFloatMetadata::const_iterator i =
1382  field->metadata().vecFloatMetadata().begin();
1383  FieldMetadata::VecFloatMetadata::const_iterator end =
1384  field->metadata().vecFloatMetadata().end();
1385  for (; i != end; ++i) {
1386  if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
1387  {
1388  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1389  return false;
1390  }
1391  }
1392 
1393  }
1394 
1395  return true;
1396 
1397 }

References Msg::print(), Msg::SevWarning, and Hdf5Util::writeAttribute().

◆ writeMetadata() [2/2]

bool Field3DOutputFileHDF5::writeMetadata ( hid_t  metadataGroup)
private

Writes metadata for this file.

Definition at line 1401 of file Field3DFileHDF5.cpp.

1402 {
1403  using namespace Hdf5Util;
1404 
1405  {
1406  FieldMetadata::StrMetadata::const_iterator i =
1407  metadata().strMetadata().begin();
1408  FieldMetadata::StrMetadata::const_iterator end =
1409  metadata().strMetadata().end();
1410  for (; i != end; ++i) {
1411  if (!writeAttribute(metadataGroup, i->first, i->second))
1412  {
1413  Msg::print(Msg::SevWarning, "Writing attribute " + i->first );
1414  return false;
1415  }
1416  }
1417  }
1418 
1419  {
1420  FieldMetadata::IntMetadata::const_iterator i =
1421  metadata().intMetadata().begin();
1422  FieldMetadata::IntMetadata::const_iterator end =
1423  metadata().intMetadata().end();
1424  for (; i != end; ++i) {
1425  if (!writeAttribute(metadataGroup, i->first, 1, i->second))
1426  {
1427  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1428  return false;
1429  }
1430  }
1431  }
1432 
1433  {
1434  FieldMetadata::FloatMetadata::const_iterator i =
1435  metadata().floatMetadata().begin();
1436  FieldMetadata::FloatMetadata::const_iterator end =
1437  metadata().floatMetadata().end();
1438  for (; i != end; ++i) {
1439  if (!writeAttribute(metadataGroup, i->first, 1, i->second))
1440  {
1441  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1442  return false;
1443  }
1444  }
1445  }
1446 
1447  {
1448  FieldMetadata::VecIntMetadata::const_iterator i =
1449  metadata().vecIntMetadata().begin();
1450  FieldMetadata::VecIntMetadata::const_iterator end =
1451  metadata().vecIntMetadata().end();
1452  for (; i != end; ++i) {
1453  if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
1454  {
1455  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1456  return false;
1457  }
1458  }
1459  }
1460 
1461  {
1462  FieldMetadata::VecFloatMetadata::const_iterator i =
1463  metadata().vecFloatMetadata().begin();
1464  FieldMetadata::VecFloatMetadata::const_iterator end =
1465  metadata().vecFloatMetadata().end();
1466  for (; i != end; ++i) {
1467  if (!writeAttribute(metadataGroup, i->first, 3, i->second.x))
1468  {
1469  Msg::print(Msg::SevWarning, "Writing attribute " + i->first);
1470  return false;
1471  }
1472  }
1473 
1474  }
1475 
1476  return true;
1477 
1478 }

References FieldMetadata::floatMetadata(), FieldMetadata::intMetadata(), Field3DFileHDF5Base::metadata(), Msg::print(), Msg::SevWarning, FieldMetadata::strMetadata(), FieldMetadata::vecFloatMetadata(), FieldMetadata::vecIntMetadata(), and Hdf5Util::writeAttribute().

Friends And Related Function Documentation

◆ Field3DInputFile

friend class Field3DInputFile
friend

Definition at line 768 of file Field3DFileHDF5.h.

◆ Field3DOutputFile

friend class Field3DOutputFile
friend

Definition at line 769 of file Field3DFileHDF5.h.


The documentation for this class was generated from the following files:
Field3DFileHDF5Base::m_groupMembership
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
Definition: Field3DFileHDF5.h:403
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
FieldMetadata::vecIntMetadata
V3i vecIntMetadata(const std::string &name, const V3i &defaultVal) const
Tries to retrieve a V3i metadata value. Returns the specified default value if no metadata was found.
Definition: FieldMetadata.cpp:143
Field3DFileHDF5Base::m_partitionCount
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
Definition: Field3DFileHDF5.h:398
FieldMetadata::vecFloatMetadata
V3f vecFloatMetadata(const std::string &name, const V3f &defaultVal) const
Tries to retrieve a V3f metadata value. Returns the specified default value if no metadata was found.
Definition: FieldMetadata.cpp:113
Field3DOutputFileHDF5::writeMapping
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...
Definition: Field3DFileHDF5.cpp:1297
FieldMetadata::intMetadata
int intMetadata(const std::string &name, const int defaultVal) const
Tries to retrieve an int metadata value. Returns the specified default value if no metadata was found...
Definition: FieldMetadata.cpp:158
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
Hdf5Util::H5ScopedGcreate
Scoped object - creates a group on creation and closes it on destruction.
Definition: Hdf5Util.h:166
FileHDF5::Layer::name
std::string name
The name of the layer (always available)
Definition: Field3DFileHDF5.h:124
Field3DFileHDF5Base::partition
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DFileHDF5Base::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition: Field3DFileHDF5.cpp:373
Field3DOutputFileHDF5::writeMetadata
bool writeMetadata(hid_t metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Definition: Field3DFileHDF5.cpp:1320
Field3DFileHDF5Base::m_file
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFileHDF5.h:390
Field3DOutputFileHDF5::incrementPartitionName
std::string incrementPartitionName(std::string &pname)
increment the partition or make it zero if there's not an integer suffix
Definition: Field3DFileHDF5.cpp:1546
Field3DFileHDF5Base::makeIntPartitionName
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ....
Definition: Field3DFileHDF5.cpp:542
FileHDF5::Layer
Definition: Field3DFileHDF5.h:121
Hdf5Util::H5ScopedGopen
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:195
FileHDF5::Layer::parent
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition: Field3DFileHDF5.h:127
FieldMetadata::strMetadata
std::string strMetadata(const std::string &name, const std::string &defaultVal) const
Tries to retrieve a string metadata value. Returns the specified default value if no metadata was fou...
Definition: FieldMetadata.cpp:173
Field3DOutputFileHDF5::OverwriteMode
@ OverwriteMode
Definition: Field3DFileHDF5.h:774
Field3DFileHDF5Base::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFileHDF5.h:392
Field3DOutputFileHDF5::FailOnExisting
@ FailOnExisting
Definition: Field3DFileHDF5.h:775
g_hdf5Mutex
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
Field3DFileHDF5Base::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field3DFileHDF5.h:321
Exc
Namespace for Exception objects.
Definition: Exception.h:57
writeFieldMapping
bool writeFieldMapping(hid_t mappingGroup, FieldMapping::Ptr mapping)
This function creates a FieldMappingIO instance based on mapping->className() which then writes Field...
Definition: Field3DFileHDF5.cpp:1645
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
Field3DFileHDF5Base::closeInternal
void closeInternal()
Closes the file if open.
Definition: Field3DFileHDF5.cpp:505
Field3DFileHDF5Base::intPartitionName
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
Definition: Field3DFileHDF5.cpp:316
Hdf5Util
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
FileHDF5::Partition
Definition: Field3DFileHDF5.h:146
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition: Log.cpp:70
FieldMetadata::floatMetadata
float floatMetadata(const std::string &name, const float defaultVal) const
Tries to retrieve a float metadata value. Returns the specified default value if no metadata was foun...
Definition: FieldMetadata.cpp:128
FileHDF5::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFileHDF5.h:152
writeField
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...
Definition: Field3DFileHDF5.cpp:1589