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 950 of file Field3DFile.cpp.

951 {
952  // Empty
953 }

◆ ~Field3DOutputFile()

Field3DOutputFile::~Field3DOutputFile ( )
virtual

Definition at line 957 of file Field3DFile.cpp.

958 {
959  cleanup();
960 }

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 964 of file Field3DFile.cpp.

965 {
966  if (!ms_doOgawa) {
967  m_hdf5.reset(new Field3DOutputFileHDF5);
968  m_hdf5Base = m_hdf5;
969  int ccm = cm;
970  return m_hdf5->create(filename, Field3DOutputFileHDF5::CreateMode(ccm));
971  }
972 
973  closeInternal();
974 
975  if (cm == FailOnExisting && fileExists(filename)) {
976  return false;
977  }
978 
979  // Create the Ogawa archive
980  m_archive.reset(new Alembic::Ogawa::OArchive(filename));
981 
982  // Check that it's valid
983  if (!m_archive->isValid()) {
984  m_archive.reset();
985  return false;
986  }
987 
988  // Get the root
989  m_root.reset(new OgOGroup(*m_archive));
990 
991  // Create the version attribute
992  OgOAttribute<veci32_t> f3dVersion(*m_root, k_versionAttrName,
993  k_currentFileVersion);
994 
995  return true;
996 }

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 1396 of file Field3DFile.cpp.

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

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 1221 of file Field3DFile.cpp.

1222 {
1223  if (m_hdf5) {
1224  return m_hdf5->writeGlobalMetadata();
1225  }
1226 
1227  OgOGroup ogMetadata(*m_root, "field3d_global_metadata");
1228  if (!writeMetadata(ogMetadata)) {
1229  Msg::print(Msg::SevWarning, "Error writing file metadata.");
1230  return false;
1231  }
1232 
1233  return true;
1234 }

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 1239 of file Field3DFile.cpp.

1240 {
1241  if (m_hdf5) {
1242  return m_hdf5->writeGroupMembership();
1243  }
1244 
1245 #if 0
1246 
1248 
1249  using namespace std;
1250  using namespace Hdf5Util;
1251 
1252  if (!m_groupMembership.size())
1253  return true;
1254 
1255  H5ScopedGcreate group(m_file, "field3d_group_membership");
1256  if (group < 0) {
1258  "Error creating field3d_group_membership group.");
1259  return false;
1260  }
1261 
1262  if (!writeAttribute(group, "is_field3d_group_membership", "1")) {
1264  "Failed to write field3d_group_membership attribute.");
1265  return false;
1266  }
1267 
1268  std::map<std::string, std::string>::const_iterator iter =
1269  m_groupMembership.begin();
1270  std::map<std::string, std::string>::const_iterator iEnd =
1271  m_groupMembership.end();
1272 
1273  for (; iter != iEnd; ++iter) {
1274  if (!writeAttribute(group, iter->first, iter->second)) {
1276  "Failed to write groupMembership string: "+ iter->first);
1277  return false;
1278  }
1279  }
1280 
1281 #endif
1282 
1283  return true;
1284 }

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 1289 of file Field3DFile.cpp.

1290 {
1291  std::string myPartitionName = removeUniqueId(partitionName);
1292  int nextIdx = -1;
1293  if (m_partitionCount.find(myPartitionName) != m_partitionCount.end()) {
1294  nextIdx = ++m_partitionCount[myPartitionName];
1295  } else {
1296  nextIdx = 0;
1297  m_partitionCount[myPartitionName] = 0;
1298  }
1299 
1300  return makeIntPartitionName(myPartitionName, nextIdx);
1301 }

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 1342 of file Field3DFile.cpp.

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

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 1000 of file Field3DFile.cpp.

1002 {
1004  const std::string className = mapping->className();
1005 
1006  try {
1007 
1008  OgOGroup mappingGroup(partitionGroup, k_mappingStr);
1009 
1010  OgOAttribute<string> classNameAttr(mappingGroup, k_mappingTypeAttrName,
1011  className);
1012 
1013  FieldMappingIO::Ptr io = factory.createFieldMappingIO(className);
1014  if (!io) {
1015  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1016  className);
1017  return false;
1018  }
1019 
1020  return io->write(mappingGroup, mapping);
1021 
1022  }
1023  catch (OgOGroupException &e) {
1024  Msg::print(Msg::SevWarning, "Couldn't create group: " + string(e.what()) );
1025  throw WriteMappingException(k_mappingStr);
1026  }
1027 
1028 }

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 1032 of file Field3DFile.cpp.

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

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 1127 of file Field3DFile.cpp.

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

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:1000
Msg::SevWarning
Definition: Log.h:68
ClassFactory
Definition: ClassFactory.h:70
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:165
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:121
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
Definition: Field3DFile.h:643
Field3DOutputFile::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:1032
Field3DOutputFile::cleanup
void cleanup()
Definition: Field3DFile.h:805
Field3DOutputFileHDF5
Provides writing of .f3d (internally, hdf5) files.
Definition: Field3DFileHDF5.h:764
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:1328
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:96
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:1342
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:1289