Field3D
Field3DFileHDF5Base Class Referenceabstract

#include <Field3DFileHDF5.h>

Inheritance diagram for Field3DFileHDF5Base:
MetadataCallback Field3DInputFileHDF5 Field3DOutputFileHDF5

Classes

struct  LayerInfo
 

Public Types

typedef std::map< std::string, std::string > GroupMembershipMap
 

Public Member Functions

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...
 
Constructors & destructor
 Field3DFileHDF5Base ()
 
virtual ~Field3DFileHDF5Base ()=0
 Pure virtual destructor to ensure we never instantiate this class. More...
 
Retreiving partition and layer names
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...
 
Convenience methods for partitionName
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...
 
Debug
void printHierarchy () const
 

Protected Types

typedef std::map< std::string, int > PartitionCountMap
 
typedef std::vector< FileHDF5::Partition::PtrPartitionList
 

Protected Member Functions

Convenience methods
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

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...
 

Private Member Functions

 Field3DFileHDF5Base (const Field3DFileHDF5Base &)
 
void operator= (const Field3DFileHDF5Base &)
 

Friends

class Field3DInputFile
 
class Field3DOutputFile
 

Detailed Description

Provides some common functionality for Field3DInputFileHDF5 and Field3DOutputFileHDF5. It hold the partition->layer data structures, but knows nothing about how to actually get them to/from disk.

Definition at line 236 of file Field3DFileHDF5.h.

Member Typedef Documentation

typedef std::map<std::string, std::string> Field3DFileHDF5Base::GroupMembershipMap

Definition at line 257 of file Field3DFileHDF5.h.

Definition at line 346 of file Field3DFileHDF5.h.

typedef std::map<std::string, int> Field3DFileHDF5Base::PartitionCountMap
protected

Definition at line 347 of file Field3DFileHDF5.h.

Constructor & Destructor Documentation

Field3DFileHDF5Base::Field3DFileHDF5Base ( )

Definition at line 290 of file Field3DFileHDF5.cpp.

References g_hdf5Mutex.

291  : m_file(-1), m_metadata(this)
292 {
293  GlobalLock lock(g_hdf5Mutex);
294 
295  // Suppressing HDF error messages
296  // Explanation about the function for the error stack is here:
297  // http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-SetAuto2
298  if (getenv("DEBUG_HDF")) {
299  cerr << "Field3DFileHDF5 -- HDF5 messages are on" << endl;
300  H5Eset_auto(H5E_DEFAULT, localPrintError, NULL);
301  } else {
302  H5Eset_auto(H5E_DEFAULT, NULL, NULL);
303  }
304 }
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
FieldMetadata m_metadata
metadata
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
Field3DFileHDF5Base::~Field3DFileHDF5Base ( )
pure virtual

Pure virtual destructor to ensure we never instantiate this class.

Definition at line 308 of file Field3DFileHDF5.cpp.

References close().

309 {
310  close();
311 }
bool close()
Closes the file. No need to call this unless you specifically want to close the file early...
Field3DFileHDF5Base::Field3DFileHDF5Base ( const Field3DFileHDF5Base )
private

Member Function Documentation

void Field3DFileHDF5Base::clear ( )

Clear the data structures and close the file.

Definition at line 487 of file Field3DFileHDF5.cpp.

References closeInternal(), m_groupMembership, and m_partitions.

Referenced by Field3DInputFileHDF5::open(), and Field3DInputFileHDF5::~Field3DInputFileHDF5().

488 {
489  closeInternal();
490  m_partitions.clear();
491  m_groupMembership.clear();
492 }
void closeInternal()
Closes the file if open.
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
PartitionList m_partitions
Vector of partitions.
bool Field3DFileHDF5Base::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.

Definition at line 496 of file Field3DFileHDF5.cpp.

References closeInternal().

Referenced by Field3DInputFileHDF5::open(), and ~Field3DFileHDF5Base().

497 {
498  closeInternal();
499 
500  return true;
501 }
void closeInternal()
Closes the file if open.
void Field3DFileHDF5Base::getPartitionNames ( std::vector< std::string > &  names) const

Gets the names of all the partitions in the file.

Definition at line 386 of file Field3DFileHDF5.cpp.

References m_partitions, and removeUniqueId().

387 {
388  names.clear();
389 
390  vector<string> tempNames;
391 
392  for (PartitionList::const_iterator i = m_partitions.begin();
393  i != m_partitions.end(); ++i) {
394  tempNames.push_back(removeUniqueId((**i).name));
395  }
396 
397  names = makeUnique(tempNames);
398 }
PartitionList m_partitions
Vector of partitions.
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
void Field3DFileHDF5Base::getScalarLayerNames ( std::vector< std::string > &  names,
const std::string &  partitionName 
) const

Gets the names of all the scalar layers in a given partition.

Definition at line 403 of file Field3DFileHDF5.cpp.

References makeIntPartitionName(), numIntPartitions(), and partition().

405 {
406  names.clear();
407 
408  for (int i = 0; i < numIntPartitions(partitionName); i++) {
409  string internalName = makeIntPartitionName(partitionName, i);
410  Partition::Ptr part = partition(internalName);
411  if (part)
412  part->getScalarLayerNames(names);
413  }
414 
415  names = makeUnique(names);
416 }
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ...
boost::intrusive_ptr< Partition > Ptr
int numIntPartitions(const std::string &partitionName) const
Returns the number of internal partitions for a given partition name.
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
void Field3DFileHDF5Base::getVectorLayerNames ( std::vector< std::string > &  names,
const std::string &  partitionName 
) const

Gets the names of all the vector layers in a given partition.

Definition at line 421 of file Field3DFileHDF5.cpp.

References makeIntPartitionName(), numIntPartitions(), and partition().

423 {
424  names.clear();
425 
426  for (int i = 0; i < numIntPartitions(partitionName); i++) {
427  string internalName = makeIntPartitionName(partitionName, i);
428  Partition::Ptr part = partition(internalName);
429  if (part)
430  part->getVectorLayerNames(names);
431  }
432 
433  names = makeUnique(names);
434 }
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ...
boost::intrusive_ptr< Partition > Ptr
int numIntPartitions(const std::string &partitionName) const
Returns the number of internal partitions for a given partition name.
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
FileHDF5::Partition::Ptr Field3DFileHDF5Base::getPartition ( const std::string &  partitionName) const
inline

Returns a pointer to the given partition.

Returns
NULL if no partition was found of that name

Definition at line 294 of file Field3DFileHDF5.h.

295  { return partition(partitionName); }
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
std::string Field3DFileHDF5Base::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.

Definition at line 316 of file Field3DFileHDF5.cpp.

References m_partitionCount, m_partitions, makeIntPartitionName(), partition(), and removeUniqueId().

319 {
320  // Loop over existing partitions and see if there's a matching mapping
321  for (PartitionList::const_iterator i = m_partitions.begin();
322  i != m_partitions.end(); ++i) {
323  if (removeUniqueId((**i).name) == partitionName) {
324  if ((**i).mapping->isIdentical(field->mapping())) {
325  return (**i).name;
326  }
327  }
328  }
329 
330  // If there was no previously matching name, then make a new one
331 
332  int nextIdx = -1;
333  if (m_partitionCount.find(partitionName) != m_partitionCount.end()) {
334  nextIdx = ++m_partitionCount[partitionName];
335  } else {
336  nextIdx = 0;
337  m_partitionCount[partitionName] = 0;
338  }
339 
340  return makeIntPartitionName(partitionName, nextIdx);
341 }
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ...
PartitionList m_partitions
Vector of partitions.
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
std::string Field3DFileHDF5Base::removeUniqueId ( const std::string &  partitionName) const

Strips any unique identifiers from the partition name and returns the original name.

Definition at line 373 of file Field3DFileHDF5.cpp.

Referenced by getPartitionNames(), Field3DOutputFileHDF5::incrementPartitionName(), intPartitionName(), and Field3DInputFileHDF5::readGroupMembership().

374 {
375  size_t pos = partitionName.rfind(".");
376  if (pos == partitionName.npos) {
377  return partitionName;
378  } else {
379  return partitionName.substr(0, pos);
380  }
381 }
void Field3DFileHDF5Base::addGroupMembership ( const GroupMembershipMap groupMembers)

Add to the group membership.

Definition at line 551 of file Field3DFileHDF5.cpp.

References m_groupMembership.

552 {
553  GroupMembershipMap::const_iterator i= groupMembers.begin();
554  GroupMembershipMap::const_iterator end= groupMembers.end();
555 
556  for (; i != end; ++i) {
557  GroupMembershipMap::iterator foundGroupIter =
558  m_groupMembership.find(i->first);
559  if (foundGroupIter != m_groupMembership.end()){
560  std::string value = m_groupMembership[i->first] + i->second;
561  m_groupMembership[i->first] = value;
562  } else {
563  m_groupMembership[i->first] = i->second;
564  }
565  }
566 }
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
FieldMetadata& Field3DFileHDF5Base::metadata ( )
inline

accessor to the m_metadata class

Definition at line 321 of file Field3DFileHDF5.h.

Referenced by Field3DInputFileHDF5::readMetadata(), and Field3DOutputFileHDF5::writeMetadata().

322  { return m_metadata; }
FieldMetadata m_metadata
metadata
const FieldMetadata& Field3DFileHDF5Base::metadata ( ) const
inline

Read only access to the m_metadata class.

Definition at line 325 of file Field3DFileHDF5.h.

326  { return m_metadata; }
FieldMetadata m_metadata
metadata
virtual void Field3DFileHDF5Base::metadataHasChanged ( const std::string &  )
inlinevirtual

This function should implemented by concrete classes to get the callback when metadata changes.

Reimplemented from MetadataCallback.

Definition at line 330 of file Field3DFileHDF5.h.

331  { /* Empty */ }
void Field3DFileHDF5Base::printHierarchy ( ) const

Definition at line 1564 of file Field3DFileHDF5.cpp.

References m_partitions.

1565 {
1566  // For each partition
1567  for (PartitionList::const_iterator i = m_partitions.begin();
1568  i != m_partitions.end(); ++i) {
1569  cout << "Name: " << (**i).name << endl;
1570  if ((**i).mapping)
1571  cout << " Mapping: " << (**i).mapping->className() << endl;
1572  else
1573  cout << " Mapping: NULL" << endl;
1574  cout << " Scalar layers: " << endl;
1575  vector<string> sNames;
1576  (**i).getScalarLayerNames(sNames);
1577  for_each(sNames.begin(), sNames.end(), print<string>(4));
1578  cout << " Vector layers: " << endl;
1579  vector<string> vNames;
1580  (**i).getVectorLayerNames(vNames);
1581  for_each(vNames.begin(), vNames.end(), print<string>(4));
1582  }
1583 }
PartitionList m_partitions
Vector of partitions.
void Field3DFileHDF5Base::closeInternal ( )
protected

Closes the file if open.

Definition at line 505 of file Field3DFileHDF5.cpp.

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

Referenced by clear(), close(), and Field3DOutputFileHDF5::create().

506 {
507  GlobalLock lock(g_hdf5Mutex);
508 
509  if (m_file != -1) {
510  if (H5Fclose(m_file) < 0) {
511  Msg::print(Msg::SevWarning, "Failed to close hdf5 file handle");
512  return;
513  }
514  m_file = -1;
515  }
516 }
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
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
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
FileHDF5::Partition::Ptr Field3DFileHDF5Base::partition ( const std::string &  partitionName)
protected

Returns a pointer to the given partition.

Returns
NULL if no partition was found of that name

Referenced by getIntScalarLayerNames(), getIntVectorLayerNames(), getScalarLayerNames(), getVectorLayerNames(), intPartitionName(), and Field3DInputFileHDF5::readPartitionAndLayerInfo().

FileHDF5::Partition::Ptr Field3DFileHDF5Base::partition ( const std::string &  partitionName) const
protected

Returns a pointer to the given partition.

Returns
NULL if no partition was found of that name
void Field3DFileHDF5Base::getIntPartitionNames ( std::vector< std::string > &  names) const
protected

Gets the names of all the -internal- partitions in the file.

Definition at line 439 of file Field3DFileHDF5.cpp.

References m_partitions.

440 {
441  names.clear();
442 
443  for (PartitionList::const_iterator i = m_partitions.begin();
444  i != m_partitions.end(); ++i) {
445  names.push_back((**i).name);
446  }
447 }
PartitionList m_partitions
Vector of partitions.
void Field3DFileHDF5Base::getIntScalarLayerNames ( std::vector< std::string > &  names,
const std::string &  intPartitionName 
) const
protected

Gets the names of all the scalar layers in a given partition, but assumes that partition name is the -internal- partition name.

Definition at line 452 of file Field3DFileHDF5.cpp.

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

454 {
455  names.clear();
456 
458 
459  if (!part) {
460  Msg::print("getIntScalarLayerNames no partition: " + intPartitionName);
461  return;
462  }
463 
464  part->getScalarLayerNames(names);
465 }
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 ...
boost::intrusive_ptr< Partition > Ptr
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
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
void Field3DFileHDF5Base::getIntVectorLayerNames ( std::vector< std::string > &  names,
const std::string &  intPartitionName 
) const
protected

Gets the names of all the vector layers in a given partition, but assumes that partition name is the -internal- partition name.

Definition at line 470 of file Field3DFileHDF5.cpp.

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

472 {
473  names.clear();
474 
476 
477  if (!part) {
478  Msg::print("getIntVectorLayerNames no partition: " + intPartitionName);
479  return;
480  }
481 
482  part->getVectorLayerNames(names);
483 }
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 ...
boost::intrusive_ptr< Partition > Ptr
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
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
int Field3DFileHDF5Base::numIntPartitions ( const std::string &  partitionName) const
protected

Returns the number of internal partitions for a given partition name.

Definition at line 521 of file Field3DFileHDF5.cpp.

References m_partitions.

Referenced by getScalarLayerNames(), and getVectorLayerNames().

522 {
523  int count = 0;
524 
525  for (PartitionList::const_iterator i = m_partitions.begin();
526  i != m_partitions.end(); ++i) {
527  string name = (**i).name;
528  size_t pos = name.rfind(".");
529  if (pos != name.npos) {
530  if (name.substr(0, pos) == partitionName) {
531  count++;
532  }
533  }
534  }
535 
536  return count;
537 }
PartitionList m_partitions
Vector of partitions.
string Field3DFileHDF5Base::makeIntPartitionName ( const std::string &  partitionsName,
int  i 
) const
protected

Makes an internal partition name given the external partition name. Effectively just tacks on .X to the name, where X is the number.

Definition at line 542 of file Field3DFileHDF5.cpp.

Referenced by getScalarLayerNames(), getVectorLayerNames(), Field3DOutputFileHDF5::incrementPartitionName(), and intPartitionName().

544 {
545  return partitionName + "." + boost::lexical_cast<std::string>(i);
546 }
void Field3DFileHDF5Base::operator= ( const Field3DFileHDF5Base )
private

Friends And Related Function Documentation

friend class Field3DInputFile
friend

Definition at line 240 of file Field3DFileHDF5.h.

friend class Field3DOutputFile
friend

Definition at line 241 of file Field3DFileHDF5.h.

Member Data Documentation

std::vector<LayerInfo> Field3DFileHDF5Base::m_layerInfo
protected

This stores layer info.

Definition at line 387 of file Field3DFileHDF5.h.

Referenced by Field3DInputFileHDF5::parseLayer(), and Field3DInputFileHDF5::readPartitionAndLayerInfo().

PartitionList Field3DFileHDF5Base::m_partitions
protected
std::vector<std::string> Field3DFileHDF5Base::m_partitionNames
protected

This stores partition names.

Definition at line 394 of file Field3DFileHDF5.h.

Referenced by Field3DInputFileHDF5::parsePartition(), and Field3DInputFileHDF5::readPartitionAndLayerInfo().

PartitionCountMap Field3DFileHDF5Base::m_partitionCount
protected

Contains a counter for each partition name. This is used to keep multiple fields with the same name unique in the file.

Definition at line 398 of file Field3DFileHDF5.h.

Referenced by Field3DOutputFileHDF5::incrementPartitionName(), and intPartitionName().

GroupMembershipMap Field3DFileHDF5Base::m_groupMembership
protected

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 ...".

Definition at line 403 of file Field3DFileHDF5.h.

Referenced by addGroupMembership(), clear(), Field3DInputFileHDF5::readGroupMembership(), and Field3DOutputFileHDF5::writeGroupMembership().

FieldMetadata Field3DFileHDF5Base::m_metadata
protected

metadata

Definition at line 406 of file Field3DFileHDF5.h.


The documentation for this class was generated from the following files: