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.
 
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.
 
FieldMetadatametadata ()
 accessor to the m_metadata class
 
const FieldMetadatametadata () const
 Read only access to the m_metadata class.
 
virtual void metadataHasChanged (const std::string &)
 This function should implemented by concrete classes to
get the callback when metadata changes.
 
Constructors & destructor
 Field3DFileHDF5Base ()
 
virtual ~Field3DFileHDF5Base ()=0
 Pure virtual destructor to ensure we never instantiate this class.
 
Retreiving partition and layer names
void getPartitionNames (std::vector< std::string > &names) const
 Gets the names of all the partitions in the file.
 
void getScalarLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
 Gets the names of all the scalar layers in a given partition.
 
void getVectorLayerNames (std::vector< std::string > &names, const std::string &partitionName) const
 Gets the names of all the vector layers in a given partition.
 
FileHDF5::Partition::Ptr getPartition (const std::string &partitionName) const
 Returns a pointer to the given partition.
 
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.
 
std::string removeUniqueId (const std::string &partitionName) const
 Strips any unique identifiers from the partition name and returns the original name.
 
void addGroupMembership (const GroupMembershipMap &groupMembers)
 Add to the group membership.
 
Debug
void printHierarchy () const
 

Protected Types

typedef std::map< std::string, intPartitionCountMap
 
typedef std::vector< FileHDF5::Partition::PtrPartitionList
 

Protected Member Functions

Convenience methods
void closeInternal ()
 Closes the file if open.
 
FileHDF5::Partition::Ptr partition (const std::string &partitionName)
 Returns a pointer to the given partition.
 
FileHDF5::Partition::Ptr partition (const std::string &partitionName) const
 Returns a pointer to the given partition.
 
void getIntPartitionNames (std::vector< std::string > &names) const
 Gets the names of all the -internal- partitions in the file.
 
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.
 
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.
 
int numIntPartitions (const std::string &partitionName) const
 Returns the number of internal partitions for a given partition name.
 
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.
 

Protected Attributes

hid_t m_file
 The hdf5 id of the current file. Will be -1 if no file is open.
 
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 ..."

 
std::vector< LayerInfom_layerInfo
 This stores layer info.
 
FieldMetadata m_metadata
 metadata
 
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.
 
std::vector< std::string > m_partitionNames
 This stores partition names.
 
PartitionList m_partitions
 Vector of partitions.
 

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

◆ GroupMembershipMap

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

Definition at line 257 of file Field3DFileHDF5.h.

◆ PartitionList

Definition at line 346 of file Field3DFileHDF5.h.

◆ PartitionCountMap

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

Definition at line 347 of file Field3DFileHDF5.h.

Constructor & Destructor Documentation

◆ Field3DFileHDF5Base() [1/2]

Field3DFileHDF5Base::Field3DFileHDF5Base ( )

Definition at line 290 of file Field3DFileHDF5.cpp.

291 : m_file(-1), m_metadata(this)
292{
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;
301 } else {
303 }
304}
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition Hdf5Util.cpp:67
boost::recursive_mutex::scoped_lock GlobalLock
Definition Hdf5Util.h:78
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
FieldMetadata m_metadata
metadata

References FIELD3D_MTX_T, and g_hdf5Mutex.

◆ ~Field3DFileHDF5Base()

Field3DFileHDF5Base::~Field3DFileHDF5Base ( )
pure virtual

Pure virtual destructor to ensure we never instantiate this class.

Definition at line 308 of file Field3DFileHDF5.cpp.

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

References close().

◆ Field3DFileHDF5Base() [2/2]

Field3DFileHDF5Base::Field3DFileHDF5Base ( const Field3DFileHDF5Base & )
private

Member Function Documentation

◆ clear()

void Field3DFileHDF5Base::clear ( )

Clear the data structures and close the file.

Definition at line 487 of file Field3DFileHDF5.cpp.

488{
490 m_partitions.clear();
491 m_groupMembership.clear();
492}
PartitionList m_partitions
Vector of partitions.
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
void closeInternal()
Closes the file if open.

References closeInternal(), m_groupMembership, and m_partitions.

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

◆ close()

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.

497{
499
500 return true;
501}

References closeInternal().

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

◆ getPartitionNames()

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.

387{
388 names.clear();
389
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
398}
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.

References FIELD3D_MTX_T, m_partitions, and removeUniqueId().

Referenced by Field3DInputFileHDF5::readProxyScalarLayers(), and Field3DInputFileHDF5::readProxyVectorLayers().

◆ getScalarLayerNames()

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.

405{
406 names.clear();
407
408 for (int i = 0; i < numIntPartitions(partitionName); i++) {
409 string internalName = makeIntPartitionName(partitionName, i);
411 if (part)
412 part->getScalarLayerNames(names);
413 }
414
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 ....
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.
boost::intrusive_ptr< Partition > Ptr

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

Referenced by Field3DInputFileHDF5::readProxyScalarLayers().

◆ getVectorLayerNames()

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.

423{
424 names.clear();
425
426 for (int i = 0; i < numIntPartitions(partitionName); i++) {
427 string internalName = makeIntPartitionName(partitionName, i);
429 if (part)
430 part->getVectorLayerNames(names);
431 }
432
434}

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

Referenced by Field3DInputFileHDF5::readProxyVectorLayers().

◆ getPartition()

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); }

◆ intPartitionName()

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.

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}
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...

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

Referenced by getIntScalarLayerNames(), getIntVectorLayerNames(), Field3DInputFileHDF5::readLayer(), Field3DInputFileHDF5::readScalarLayer(), Field3DInputFileHDF5::readVectorLayer(), and Field3DOutputFileHDF5::writeLayer().

◆ removeUniqueId()

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.

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}

Referenced by getPartitionNames(), Field3DOutputFileHDF5::incrementPartitionName(), intPartitionName(), Field3DInputFileHDF5::readGroupMembership(), Field3DInputFileHDF5::readLayer(), Field3DInputFileHDF5::readProxyLayer(), Field3DInputFileHDF5::readScalarLayers(), and Field3DInputFileHDF5::readVectorLayers().

◆ addGroupMembership()

void Field3DFileHDF5Base::addGroupMembership ( const GroupMembershipMap & groupMembers)

Add to the group membership.

Definition at line 551 of file Field3DFileHDF5.cpp.

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}

References FIELD3D_MTX_T, and m_groupMembership.

◆ metadata() [1/2]

FieldMetadata & Field3DFileHDF5Base::metadata ( )
inline

accessor to the m_metadata class

Definition at line 321 of file Field3DFileHDF5.h.

322 { return m_metadata; }

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

◆ metadata() [2/2]

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; }

◆ metadataHasChanged()

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 */ }

◆ printHierarchy()

void Field3DFileHDF5Base::printHierarchy ( ) const

Definition at line 1564 of file Field3DFileHDF5.cpp.

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;
1576 (**i).getScalarLayerNames(sNames);
1577 for_each(sNames.begin(), sNames.end(), print<string>(4));
1578 cout << " Vector layers: " << endl;
1580 (**i).getVectorLayerNames(vNames);
1581 for_each(vNames.begin(), vNames.end(), print<string>(4));
1582 }
1583}

References FIELD3D_MTX_T, and m_partitions.

◆ closeInternal()

void Field3DFileHDF5Base::closeInternal ( )
protected

Closes the file if open.

Definition at line 505 of file Field3DFileHDF5.cpp.

506{
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}
@ SevWarning
Definition Log.h:68
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

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

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

◆ partition() [1/2]

◆ partition() [2/2]

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

◆ getIntPartitionNames()

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.

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}

References FIELD3D_MTX_T, and m_partitions.

Referenced by Field3DInputFileHDF5::readProxyLayer(), Field3DInputFileHDF5::readScalarLayers(), Field3DInputFileHDF5::readScalarLayers(), Field3DInputFileHDF5::readVectorLayers(), and Field3DInputFileHDF5::readVectorLayers().

◆ getIntScalarLayerNames()

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.

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

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

Referenced by Field3DInputFileHDF5::readProxyLayer(), Field3DInputFileHDF5::readScalarLayers(), and Field3DInputFileHDF5::readScalarLayers().

◆ getIntVectorLayerNames()

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.

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}

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

Referenced by Field3DInputFileHDF5::readProxyLayer(), Field3DInputFileHDF5::readVectorLayers(), and Field3DInputFileHDF5::readVectorLayers().

◆ numIntPartitions()

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.

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}

References FIELD3D_MTX_T, and m_partitions.

Referenced by getScalarLayerNames(), and getVectorLayerNames().

◆ makeIntPartitionName()

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.

544{
545 return partitionName + "." + boost::lexical_cast<std::string>(i);
546}

References FIELD3D_MTX_T.

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

◆ operator=()

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

Friends And Related Symbol Documentation

◆ Field3DInputFile

Definition at line 240 of file Field3DFileHDF5.h.

◆ Field3DOutputFile

Definition at line 241 of file Field3DFileHDF5.h.

Member Data Documentation

◆ m_layerInfo

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

◆ m_file

◆ m_partitions

◆ m_partitionNames

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

◆ m_partitionCount

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

◆ m_groupMembership

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

◆ m_metadata

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: