Field3D
Field3DOutputFile Class Reference

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

#include <Field3DFile.h>

Inheritance diagram for Field3DOutputFile:
Field3DFileBase MetadataCallback

Public Types

enum  CreateMode { OverwriteMode, FailOnExisting }
 
- Public Types inherited from Field3DFileBase
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...
 
Constructors & destructor
 Field3DOutputFile ()
 
virtual ~Field3DOutputFile ()
 
Writing layer to disk
template<class Data_T >
bool writeLayer (const std::string &layerName, typename Field< Data_T >::Ptr layer)
 Writes a scalar layer to the "Default" partition. More...
 
template<class Data_T >
bool writeLayer (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 writeLayer (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...
 
Backward compatibility
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 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 &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
 Writes a scalar layer to the "Default" partition. 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...
 
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...
 
- Public Member Functions inherited from Field3DFileBase
void clear ()
 Clear the data structures and close the file. More...
 
bool close ()
 Closes the file. No need to call this unless you specifically want to close the file early. It will close once the File object goes out of scope. More...
 
FieldMetadatametadata ()
 accessor to the m_metadata class More...
 
const FieldMetadatametadata () const
 Read only access to the m_metadata class. More...
 
virtual void metadataHasChanged (const std::string &)
 This function should implemented by concrete classes to
get the callback when metadata changes. More...
 
 Field3DFileBase ()
 
virtual ~Field3DFileBase ()=0
 Pure virtual destructor to ensure we never instantiate this class. More...
 
void getPartitionNames (std::vector< std::string > &names) const
 Gets the names of all the partitions in the file. More...
 
void getScalarLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
 Gets the names of all the scalar layers in a given partition. More...
 
void getVectorLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
 Gets the names of all the vector layers in a given partition. More...
 
void addGroupMembership (const GroupMembershipMap &groupMembers)
 Add to the group membership. More...
 
void printHierarchy () const
 

Static Public Member Functions

static void useOgawa (const bool enabled)
 Whether to output ogawa files. More...
 

Private Member Functions

void cleanup ()
 
virtual void closeInternal ()
 Closes the file if open. More...
 
File::Partition::Ptr createNewPartition (const std::string &partitionName, const std::string &layerName, FieldRes::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 writeMapping (OgOGroup &partitionGroup, FieldMapping::Ptr mapping)
 Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored as plain attributes under a group. More...
 
bool writeMetadata (OgOGroup &metadataGroup)
 Writes metadata for this file. More...
 
bool writeMetadata (OgOGroup &metadataGroup, FieldBase::Ptr layer)
 Writes metadata for this layer. More...
 

Private Attributes

boost::shared_ptr< Alembic::Ogawa::OArchive > m_archive
 Pointer to the Ogawa archive. More...
 
boost::shared_ptr< Field3DOutputFileHDF5m_hdf5
 HDF5 fallback. More...
 
boost::shared_ptr< OgOGroup > m_root
 Pointer to root group. More...
 

Static Private Attributes

static bool ms_doOgawa = true
 Whether to output ogawa files. More...
 

Additional Inherited Members

- Protected Types inherited from Field3DFileBase
typedef std::map< std::string, int > PartitionCountMap
 
typedef std::vector< File::Partition::PtrPartitionList
 
- Protected Member Functions inherited from Field3DFileBase
File::Partition::Ptr getPartition (const std::string &partitionName) const
 Returns a pointer to the given partition. More...
 
File::Partition::Ptr partition (const std::string &partitionName)
 Returns a pointer to the given partition. More...
 
File::Partition::Ptr partition (const std::string &partitionName) const
 Returns a pointer to the given partition. More...
 
void getIntPartitionNames (std::vector< std::string > &names) const
 Gets the names of all the -internal- partitions in the file. More...
 
void getIntScalarLayerNames (std::vector< std::string > &names, const std::string &intPartitionName) const
 Gets the names of all the scalar layers in a given partition, but assumes that partition name is the -internal- partition name. More...
 
void getIntVectorLayerNames (std::vector< std::string > &names, const std::string &intPartitionName) const
 Gets the names of all the vector layers in a given partition, but assumes that partition name is the -internal- partition name. More...
 
int numIntPartitions (const std::string &partitionName) const
 Returns the number of internal partitions for a given partition name. More...
 
std::string makeIntPartitionName (const std::string &partitionsName, int i) const
 Makes an internal partition name given the external partition name. Effectively just tacks on .X to the name, where X is the number. More...
 
std::string intPartitionName (const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
 Returns a unique partition name given the requested name. This ensures that partitions with matching mappings get the same name but each subsequent differing mapping gets a new, separate name. More...
 
std::string removeUniqueId (const std::string &partitionName) const
 Strips any unique identifiers from the partition name and returns the original name. More...
 
- Protected Attributes inherited from Field3DFileBase
GroupMembershipMap m_groupMembership
 Keeps track of group membership for each layer of partition name. The key is the "group" and the value is a space separated list of "partitionName.0:Layer1 partitionName.1:Layer0 ..."
More...
 
boost::shared_ptr< Field3DFileHDF5Basem_hdf5Base
 HDF5 fallback. More...
 
std::vector< LayerInfom_layerInfo
 This stores layer info. More...
 
FieldMetadata m_metadata
 metadata More...
 
PartitionCountMap m_partitionCount
 Contains a counter for each partition name. This is used to keep multiple fields with the same name unique in the file. More...
 
std::vector< std::string > m_partitionNames
 This stores partition names. More...
 
PartitionList m_partitions
 Vector of partitions. More...
 

Detailed Description

Provides writing of .f3d (internally, hdf5 or Ogawa) files.

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

Definition at line 636 of file Field3DFile.h.

Member Enumeration Documentation

◆ CreateMode

Enumerator
OverwriteMode 
FailOnExisting 

Definition at line 642 of file Field3DFile.h.

642  {
645  };

Constructor & Destructor Documentation

◆ Field3DOutputFile()

Field3DOutputFile::Field3DOutputFile ( )

Definition at line 963 of file Field3DFile.cpp.

964 {
965  // Empty
966 }

◆ ~Field3DOutputFile()

Field3DOutputFile::~Field3DOutputFile ( )
virtual

Definition at line 970 of file Field3DFile.cpp.

971 {
972  cleanup();
973 }

References cleanup().

Member Function Documentation

◆ create()

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

Creates a .f3d file on disk.

Definition at line 977 of file Field3DFile.cpp.

978 {
979  if (!ms_doOgawa) {
980  m_hdf5.reset(new Field3DOutputFileHDF5);
981  m_hdf5Base = m_hdf5;
982  int ccm = cm;
983  return m_hdf5->create(filename, Field3DOutputFileHDF5::CreateMode(ccm));
984  }
985 
986  closeInternal();
987 
988  if (cm == FailOnExisting && fileExists(filename)) {
989  return false;
990  }
991 
992  // Create the Ogawa archive
993  m_archive.reset(new Alembic::Ogawa::OArchive(filename));
994 
995  // Check that it's valid
996  if (!m_archive->isValid()) {
997  m_archive.reset();
998  return false;
999  }
1000 
1001  // Get the root
1002  m_root.reset(new OgOGroup(*m_archive));
1003 
1004  // Create the version attribute
1005  OgOAttribute<veci32_t> f3dVersion(*m_root, k_versionAttrName,
1006  k_currentFileVersion);
1007 
1008  return true;
1009 }

References closeInternal(), FailOnExisting, fileExists(), m_archive, m_hdf5, Field3DFileBase::m_hdf5Base, m_root, and ms_doOgawa.

◆ useOgawa()

static void Field3DOutputFile::useOgawa ( const bool  enabled)
inlinestatic

Whether to output ogawa files.

Definition at line 663 of file Field3DFile.h.

664  {
665  // simple temporary endian check
666  union {
667  uint32_t l;
668  char c[4];
669  } u;
670 
671  u.l = 0x01234567;
672 
673  if (u.c[0] == 0x67) {
674  ms_doOgawa = enabled;
675  } else {
676  std::cerr << "WARNING: Field3D only supports Ogawa-backed files "
677  << "on little-endian systems." << std::endl;
678  ms_doOgawa = false;
679  }
680  }

◆ writeLayer() [1/3]

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

Writes a scalar layer to the "Default" partition.

Definition at line 687 of file Field3DFile.h.

689  {
690  return writeLayer<Data_T>(std::string("default"), layerName, layer);
691  }

◆ writeLayer() [2/3]

template<class Data_T >
bool Field3DOutputFile::writeLayer ( 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 1409 of file Field3DFile.cpp.

1412 {
1413  using std::string;
1414 
1415  // Null pointer check
1416  if (!field) {
1418  "Called writeLayer with null pointer. Ignoring...");
1419  return false;
1420  }
1421 
1422  // Make sure archive is open
1423  if (!m_archive) {
1425  "Attempting to write layer without opening file first.");
1426  return false;
1427  }
1428 
1429  // Get the partition name
1430  string partitionName = intPartitionName(userPartitionName, layerName, field);
1431 
1432  // Get the partition
1433  File::Partition::Ptr part = partition(partitionName);
1434 
1435  if (!part) {
1436  // Create a new partition
1437  part = createNewPartition(partitionName, layerName, field);
1438  // Make sure it was created
1439  if (!part) {
1440  return false;
1441  }
1442  } else {
1443  // Check that we have a valid mapping
1444  if (!field->mapping()) {
1446  "Couldn't add layer \"" + layerName + "\" to partition \""
1447  + partitionName + "\" because the layer's mapping is null.");
1448  return false;
1449  }
1450  // Check if the layer already exists. If it does, we need to make a
1451  // different partition
1452  if (part->layer(layerName)) {
1453  // Increment the internal partition name
1454  partitionName = incrementPartitionName(partitionName);
1455  // Create a new partition
1456  part = createNewPartition(partitionName, layerName, field);
1457  // Make sure it was created
1458  if (!part) {
1459  return false;
1460  }
1461  }
1462  }
1463 
1464  // Check mapping not null
1465  if (!part->mapping) {
1466  Msg::print(Msg::SevWarning, "Severe error - partition mapping is null: "
1467  + partitionName);
1468  return false;
1469  }
1470 
1471  // Check that the mapping matches what's already in the Partition
1472  if (!field->mapping()->isIdentical(part->mapping)) {
1473  Msg::print(Msg::SevWarning, "Couldn't add layer \"" + layerName
1474  + "\" to partition \"" + partitionName
1475  + "\" because mapping doesn't match");
1476  return false;
1477  }
1478 
1479  // Open the partition
1480 
1481  OgOGroup &ogPartition = part->group();
1482 
1483  // Build a Layer
1484 
1485  File::Layer layer;
1486  layer.name = layerName;
1487  layer.parent = partitionName;
1488 
1489  // Add Layer to file ---
1490 
1491  OgOGroup ogLayer(ogPartition, layerName);
1492 
1493  // Tag as layer
1494  OgOAttribute<string> classType(ogLayer, "class_type", "field3d_layer");
1495 
1496  // Create metadata
1497  OgOGroup ogMetadata(ogLayer, "metadata");
1498 
1499  // Write metadata
1500  writeMetadata(ogMetadata, field);
1501 
1502  // Write field data
1503  writeField(ogLayer, field);
1504 
1505  // Add to partition
1506 
1507  part->addLayer(layer);
1508 
1509  return true;
1510 }

References createNewPartition(), incrementPartitionName(), Field3DFileBase::intPartitionName(), m_archive, FieldRes::mapping(), File::Layer::name, File::Layer::parent, Field3DFileBase::partition(), Msg::print(), Msg::SevWarning, writeField(), and writeMetadata().

◆ writeLayer() [3/3]

template<class Data_T >
bool Field3DOutputFile::writeLayer ( typename Field< Data_T >::Ptr  layer)
inline

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

Definition at line 703 of file Field3DFile.h.

704  {
705  return writeLayer<Data_T>(layer->name, layer->attribute, layer);
706  }

References FieldBase::attribute, and FieldBase::name.

◆ writeScalarLayer() [1/3]

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

Writes a scalar layer to the "Default" partition.

Definition at line 715 of file Field3DFile.h.

717  {
718  if (m_hdf5) {
719  return m_hdf5->writeScalarLayer<Data_T>(layerName, layer);
720  }
721  return writeScalarLayer<Data_T>(std::string("default"), layerName, layer);
722  }

◆ writeScalarLayer() [2/3]

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

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

Definition at line 727 of file Field3DFile.h.

730  {
731  if (m_hdf5) {
732  return m_hdf5->writeScalarLayer<Data_T>(partitionName, layerName, layer);
733  }
734  return writeLayer<Data_T>(partitionName, layerName, layer);
735  }

◆ writeScalarLayer() [3/3]

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

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

Definition at line 740 of file Field3DFile.h.

741  {
742  if (m_hdf5) {
743  return m_hdf5->writeScalarLayer<Data_T>(layer);
744  }
745  return writeLayer<Data_T>(layer);
746  }

◆ writeVectorLayer() [1/3]

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

Writes a scalar layer to the "Default" partition.

Definition at line 750 of file Field3DFile.h.

752  {
753  if (m_hdf5) {
754  return m_hdf5->writeVectorLayer<Data_T>(layerName, layer);
755  }
756  return writeVectorLayer<Data_T>(std::string("default"), layerName, layer);
757  }

◆ writeVectorLayer() [2/3]

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

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

Definition at line 762 of file Field3DFile.h.

765  {
766  if (m_hdf5) {
767  return m_hdf5->writeVectorLayer<Data_T>(partitionName, layerName, layer);
768  }
769  return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName, layer);
770  }

◆ writeVectorLayer() [3/3]

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

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

Definition at line 775 of file Field3DFile.h.

776  {
777  if (m_hdf5) {
778  return m_hdf5->writeVectorLayer<Data_T>(layer);
779  }
780  return writeLayer<FIELD3D_VEC3_T<Data_T> >(layer);
781  }

◆ writeGlobalMetadata()

bool Field3DOutputFile::writeGlobalMetadata ( )

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

Definition at line 1234 of file Field3DFile.cpp.

1235 {
1236  if (m_hdf5) {
1237  return m_hdf5->writeGlobalMetadata();
1238  }
1239 
1240  OgOGroup ogMetadata(*m_root, "field3d_global_metadata");
1241  if (!writeMetadata(ogMetadata)) {
1242  Msg::print(Msg::SevWarning, "Error writing file metadata.");
1243  return false;
1244  }
1245 
1246  return true;
1247 }

References m_hdf5, m_root, Msg::print(), Msg::SevWarning, and writeMetadata().

◆ writeGroupMembership()

bool Field3DOutputFile::writeGroupMembership ( )

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

Definition at line 1252 of file Field3DFile.cpp.

1253 {
1254  if (m_hdf5) {
1255  return m_hdf5->writeGroupMembership();
1256  }
1257 
1258 #if 0
1259 
1261 
1262  using namespace std;
1263  using namespace Hdf5Util;
1264 
1265  if (!m_groupMembership.size())
1266  return true;
1267 
1268  H5ScopedGcreate group(m_file, "field3d_group_membership");
1269  if (group < 0) {
1271  "Error creating field3d_group_membership group.");
1272  return false;
1273  }
1274 
1275  if (!writeAttribute(group, "is_field3d_group_membership", "1")) {
1277  "Failed to write field3d_group_membership attribute.");
1278  return false;
1279  }
1280 
1281  std::map<std::string, std::string>::const_iterator iter =
1282  m_groupMembership.begin();
1283  std::map<std::string, std::string>::const_iterator iEnd =
1284  m_groupMembership.end();
1285 
1286  for (; iter != iEnd; ++iter) {
1287  if (!writeAttribute(group, iter->first, iter->second)) {
1289  "Failed to write groupMembership string: "+ iter->first);
1290  return false;
1291  }
1292  }
1293 
1294 #endif
1295 
1296  return true;
1297 }

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

◆ closeInternal()

virtual void Field3DOutputFile::closeInternal ( )
inlineprivatevirtual

Closes the file if open.

Implements Field3DFileBase.

Definition at line 796 of file Field3DFile.h.

797  {
798  if (m_hdf5) {
799  m_hdf5->closeInternal();
800  return;
801  }
802  cleanup();
803  }

Referenced by create().

◆ cleanup()

void Field3DOutputFile::cleanup ( )
inlineprivate

Definition at line 805 of file Field3DFile.h.

806  {
807  // The destruction of the various Ogawa components must happen in the
808  // right order
809 
810  // First, the partition groups
811  m_partitions.clear();
812  // Then the root group
813  m_root.reset();
814  // Finally, the archive
815  m_archive.reset();
816  }

Referenced by ~Field3DOutputFile().

◆ incrementPartitionName()

std::string Field3DOutputFile::incrementPartitionName ( std::string &  pname)
private

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

Definition at line 1302 of file Field3DFile.cpp.

1303 {
1304  std::string myPartitionName = removeUniqueId(partitionName);
1305  int nextIdx = -1;
1306  if (m_partitionCount.find(myPartitionName) != m_partitionCount.end()) {
1307  nextIdx = ++m_partitionCount[myPartitionName];
1308  } else {
1309  nextIdx = 0;
1310  m_partitionCount[myPartitionName] = 0;
1311  }
1312 
1313  return makeIntPartitionName(myPartitionName, nextIdx);
1314 }

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

Referenced by writeLayer().

◆ createNewPartition()

File::Partition::Ptr Field3DOutputFile::createNewPartition ( const std::string &  partitionName,
const std::string &  layerName,
FieldRes::Ptr  field 
)
private

Create newPartition given the input config.

Definition at line 1355 of file Field3DFile.cpp.

1358 {
1359  using namespace Exc;
1360 
1362  newPart->name = partitionName;
1363 
1364  boost::shared_ptr<OgOGroup> ogPartition(new OgOGroup(*m_root, newPart->name));
1365  newPart->setGroup(ogPartition);
1366 
1367  m_partitions.push_back(newPart);
1368 
1369  // Pick up new pointer
1370  File::Partition::Ptr part = partition(partitionName);
1371 
1372  // Add mapping group to the partition
1373  try {
1374  if (!writeMapping(*ogPartition, field->mapping())) {
1376  "writeMapping returned false for an unknown reason ");
1377  return File::Partition::Ptr();
1378  }
1379  }
1380  catch (WriteMappingException &e) {
1381  Msg::print(Msg::SevWarning, "Couldn't write mapping for partition: "
1382  + partitionName);
1383  return File::Partition::Ptr();
1384  }
1385  catch (...) {
1387  "Unknown error when writing mapping for partition: "
1388  + partitionName);
1389  return File::Partition::Ptr();
1390  }
1391 
1392  // Set the mapping of the partition. Since all layers share their
1393  // partition's mapping, we can just pick this first one. All subsequent
1394  // additions to the same partition are checked to have the same mapping
1395  part->mapping = field->mapping();
1396 
1397  // Tag node as partition
1398  // Create a version attribute on the root node
1399  OgOAttribute<string>(*ogPartition, "is_field3d_partition", "1");
1400 
1401  return part;
1402 }

References Field3DFileBase::m_partitions, m_root, Field3DFileBase::partition(), Msg::print(), Msg::SevWarning, and writeMapping().

Referenced by writeLayer().

◆ writeMapping()

bool Field3DOutputFile::writeMapping ( OgOGroup &  partitionGroup,
FieldMapping::Ptr  mapping 
)
private

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

Definition at line 1013 of file Field3DFile.cpp.

1015 {
1017  const std::string className = mapping->className();
1018 
1019  try {
1020 
1021  OgOGroup mappingGroup(partitionGroup, k_mappingStr);
1022 
1023  OgOAttribute<string> classNameAttr(mappingGroup, k_mappingTypeAttrName,
1024  className);
1025 
1026  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1027  if (!io) {
1028  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1029  className);
1030  return false;
1031  }
1032 
1033  return io->write(mappingGroup, mapping);
1034 
1035  }
1036  catch (OgOGroupException &e) {
1037  Msg::print(Msg::SevWarning, "Couldn't create group: " + string(e.what()) );
1038  throw WriteMappingException(k_mappingStr);
1039  }
1040 
1041 }

References ClassFactory::createFieldMappingIO(), Msg::print(), Msg::SevWarning, and ClassFactory::singleton().

Referenced by createNewPartition().

◆ writeMetadata() [1/2]

bool Field3DOutputFile::writeMetadata ( OgOGroup &  metadataGroup,
FieldBase::Ptr  layer 
)
private

Writes metadata for this layer.

Definition at line 1045 of file Field3DFile.cpp.

1047 {
1048  {
1049  FieldMetadata::StrMetadata::const_iterator i =
1050  field->metadata().strMetadata().begin();
1051  FieldMetadata::StrMetadata::const_iterator end =
1052  field->metadata().strMetadata().end();
1053  for (; i != end; ++i) {
1054  try {
1055  OgOAttribute<string>(metadataGroup, i->first, i->second);
1056  }
1057  catch (OgOAttributeException &e) {
1058  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1059  " " + e.what());
1060  return false;
1061  }
1062  }
1063  }
1064 
1065  {
1066  FieldMetadata::IntMetadata::const_iterator i =
1067  field->metadata().intMetadata().begin();
1068  FieldMetadata::IntMetadata::const_iterator end =
1069  field->metadata().intMetadata().end();
1070  for (; i != end; ++i) {
1071  try {
1072  OgOAttribute<int32_t>(metadataGroup, i->first, i->second);
1073  }
1074  catch (OgOAttributeException &e) {
1075  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1076  " " + e.what());
1077  return false;
1078  }
1079  }
1080  }
1081 
1082  {
1083  FieldMetadata::FloatMetadata::const_iterator i =
1084  field->metadata().floatMetadata().begin();
1085  FieldMetadata::FloatMetadata::const_iterator end =
1086  field->metadata().floatMetadata().end();
1087  for (; i != end; ++i) {
1088  try {
1089  OgOAttribute<float32_t>(metadataGroup, i->first, i->second);
1090  }
1091  catch (OgOAttributeException &e) {
1092  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1093  " " + e.what());
1094  return false;
1095  }
1096  }
1097  }
1098 
1099  {
1100  FieldMetadata::VecIntMetadata::const_iterator i =
1101  field->metadata().vecIntMetadata().begin();
1102  FieldMetadata::VecIntMetadata::const_iterator end =
1103  field->metadata().vecIntMetadata().end();
1104  for (; i != end; ++i) {
1105  try {
1106  OgOAttribute<veci32_t>(metadataGroup, i->first, i->second);
1107  }
1108  catch (OgOAttributeException &e) {
1109  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1110  " " + e.what());
1111  return false;
1112  }
1113  }
1114  }
1115 
1116  {
1117  FieldMetadata::VecFloatMetadata::const_iterator i =
1118  field->metadata().vecFloatMetadata().begin();
1119  FieldMetadata::VecFloatMetadata::const_iterator end =
1120  field->metadata().vecFloatMetadata().end();
1121  for (; i != end; ++i) {
1122  try {
1123  OgOAttribute<vec32_t>(metadataGroup, i->first, i->second);
1124  }
1125  catch (OgOAttributeException &e) {
1126  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1127  " " + e.what());
1128  return false;
1129  }
1130  }
1131 
1132  }
1133 
1134  return true;
1135 
1136 }

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

Referenced by writeGlobalMetadata(), and writeLayer().

◆ writeMetadata() [2/2]

bool Field3DOutputFile::writeMetadata ( OgOGroup &  metadataGroup)
private

Writes metadata for this file.

Definition at line 1140 of file Field3DFile.cpp.

1141 {
1142  {
1143  FieldMetadata::StrMetadata::const_iterator i =
1144  metadata().strMetadata().begin();
1145  FieldMetadata::StrMetadata::const_iterator end =
1146  metadata().strMetadata().end();
1147  for (; i != end; ++i) {
1148  try {
1149  OgOAttribute<string>(metadataGroup, i->first, i->second);
1150  }
1151  catch (OgOAttributeException &e) {
1152  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1153  " " + e.what());
1154  return false;
1155  }
1156  }
1157  }
1158 
1159  {
1160  FieldMetadata::IntMetadata::const_iterator i =
1161  metadata().intMetadata().begin();
1162  FieldMetadata::IntMetadata::const_iterator end =
1163  metadata().intMetadata().end();
1164  for (; i != end; ++i) {
1165  try {
1166  OgOAttribute<int32_t>(metadataGroup, i->first, i->second);
1167  }
1168  catch (OgOAttributeException &e) {
1169  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1170  " " + e.what());
1171  return false;
1172  }
1173  }
1174  }
1175 
1176  {
1177  FieldMetadata::FloatMetadata::const_iterator i =
1178  metadata().floatMetadata().begin();
1179  FieldMetadata::FloatMetadata::const_iterator end =
1180  metadata().floatMetadata().end();
1181  for (; i != end; ++i) {
1182  try {
1183  OgOAttribute<float32_t>(metadataGroup, i->first, i->second);
1184  }
1185  catch (OgOAttributeException &e) {
1186  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1187  " " + e.what());
1188  return false;
1189  }
1190  }
1191  }
1192 
1193  {
1194  FieldMetadata::VecIntMetadata::const_iterator i =
1195  metadata().vecIntMetadata().begin();
1196  FieldMetadata::VecIntMetadata::const_iterator end =
1197  metadata().vecIntMetadata().end();
1198  for (; i != end; ++i) {
1199  try {
1200  OgOAttribute<veci32_t>(metadataGroup, i->first, i->second);
1201  }
1202  catch (OgOAttributeException &e) {
1203  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1204  " " + e.what());
1205  return false;
1206  }
1207  }
1208  }
1209 
1210  {
1211  FieldMetadata::VecFloatMetadata::const_iterator i =
1212  metadata().vecFloatMetadata().begin();
1213  FieldMetadata::VecFloatMetadata::const_iterator end =
1214  metadata().vecFloatMetadata().end();
1215  for (; i != end; ++i) {
1216  try {
1217  OgOAttribute<vec32_t>(metadataGroup, i->first, i->second);
1218  }
1219  catch (OgOAttributeException &e) {
1220  Msg::print(Msg::SevWarning, "Writing attribute " + i->first +
1221  " " + e.what());
1222  return false;
1223  }
1224  }
1225 
1226  }
1227 
1228  return true;
1229 }

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

Member Data Documentation

◆ ms_doOgawa

bool Field3DOutputFile::ms_doOgawa = true
staticprivate

Whether to output ogawa files.

Definition at line 841 of file Field3DFile.h.

Referenced by create().

◆ m_archive

boost::shared_ptr<Alembic::Ogawa::OArchive> Field3DOutputFile::m_archive
private

Pointer to the Ogawa archive.

Definition at line 844 of file Field3DFile.h.

Referenced by create(), and writeLayer().

◆ m_root

boost::shared_ptr<OgOGroup> Field3DOutputFile::m_root
private

◆ m_hdf5

boost::shared_ptr<Field3DOutputFileHDF5> Field3DOutputFile::m_hdf5
private

HDF5 fallback.

Definition at line 849 of file Field3DFile.h.

Referenced by create(), Field3DInputFile::readProxyLayer(), writeGlobalMetadata(), and writeGroupMembership().


The documentation for this class was generated from the following files:
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
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
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
Field3DOutputFile::writeMapping
bool writeMapping(OgOGroup &partitionGroup, FieldMapping::Ptr mapping)
Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored ...
Definition: Field3DFile.cpp:1013
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
ClassFactory
Definition: ClassFactory.h:72
Field3DOutputFile::closeInternal
virtual void closeInternal()
Closes the file if open.
Definition: Field3DFile.h:796
Field3DOutputFileHDF5::CreateMode
CreateMode
Definition: Field3DFileHDF5.h:773
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition: FieldMappingIO.h:71
Hdf5Util::H5ScopedGcreate
Scoped object - creates a group on creation and closes it on destruction.
Definition: Hdf5Util.h:166
Field3DFileBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field3DFile.h:276
OgOAttribute
Definition: OgawaFwd.h:64
Field3DOutputFile::m_hdf5
boost::shared_ptr< Field3DOutputFileHDF5 > m_hdf5
HDF5 fallback.
Definition: Field3DFile.h:849
File::Partition
Definition: Field3DFile.h:122
ClassFactory::singleton
static ClassFactory & singleton()
}
Definition: ClassFactory.cpp:278
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
File::Layer::parent
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition: Field3DFile.h:103
Field3DFileBase::m_hdf5Base
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
Definition: Field3DFile.h:388
Field3DFileBase::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:371
Field3DFileBase::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: Field3DFile.h:382
Field3DOutputFile::OverwriteMode
@ OverwriteMode
Definition: Field3DFile.h:643
Field3DOutputFile::FailOnExisting
@ FailOnExisting
Definition: Field3DFile.h:644
Field3DOutputFile::m_archive
boost::shared_ptr< Alembic::Ogawa::OArchive > m_archive
Pointer to the Ogawa archive.
Definition: Field3DFile.h:844
Field3DOutputFile::ms_doOgawa
static bool ms_doOgawa
Whether to output ogawa files.
Definition: Field3DFile.h:841
Field3DOutputFile::writeMetadata
bool writeMetadata(OgOGroup &metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Definition: Field3DFile.cpp:1045
Field3DOutputFile::cleanup
void cleanup()
Definition: Field3DFile.h:805
Field3DOutputFileHDF5
Provides writing of .f3d (internally, hdf5) files.
Definition: Field3DFileHDF5.h:765
Exc
Namespace for Exception objects.
Definition: Exception.h:57
Field3DFileBase::partition
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DFileBase::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: Field3DFile.cpp:665
Hdf5Util
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
File::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:127
fileExists
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
Definition: Field3DFile.cpp:1341
Field3DFileBase::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition: Field3DFile.cpp:479
Field3DFileBase::intPartitionName
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
Definition: Field3DFile.cpp:422
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition: Log.cpp:70
File::Layer
Definition: Field3DFile.h:97
Field3DOutputFile::createNewPartition
File::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Create newPartition given the input config.
Definition: Field3DFile.cpp:1355
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
ClassFactory::createFieldMappingIO
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
Definition: ClassFactory.cpp:266
File::Layer::name
std::string name
The name of the layer (always available)
Definition: Field3DFile.h:100
Field3DFileBase::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: Field3DFile.h:377
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
Field3DOutputFile::m_root
boost::shared_ptr< OgOGroup > m_root
Pointer to root group.
Definition: Field3DFile.h:846
Field3DOutputFile::incrementPartitionName
std::string incrementPartitionName(std::string &pname)
Increment the partition or make it zero if there's not an integer suffix.
Definition: Field3DFile.cpp:1302