Field3D
Field3DFileBase Class Referenceabstract

#include <Field3DFile.h>

Inheritance diagram for Field3DFileBase:
Field3DInputFile Field3DOutputFile

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 File object goes out of scope.
 
FieldMetadata< Field3DFileBase > & metadata ()
 accessor to the m_metadata class
 
const FieldMetadata
< Field3DFileBase > & 
metadata () 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
 Field3DFileBase ()
 
virtual ~Field3DFileBase ()=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.
 
File::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,
int > 
PartitionCountMap
 
typedef std::vector
< File::Partition::Ptr
PartitionList
 

Protected Member Functions

Convenience methods
void closeInternal ()
 Closes the file if open.
 
File::Partition::Ptr partition (const std::string &partitionName)
 Returns a pointer to the given partition.
 
File::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< Field3DFileBasem_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

 Field3DFileBase (const Field3DFileBase &)
 
void operator= (const Field3DFileBase &)
 

Detailed Description

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

Definition at line 233 of file Field3DFile.h.

Member Typedef Documentation

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

Definition at line 251 of file Field3DFile.h.

typedef std::vector<File::Partition::Ptr> Field3DFileBase::PartitionList
protected

Definition at line 340 of file Field3DFile.h.

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

Definition at line 341 of file Field3DFile.h.

Constructor & Destructor Documentation

Field3DFileBase::Field3DFileBase ( )

Definition at line 283 of file Field3DFile.cpp.

: m_file(-1), m_metadata(this)
{
// Suppressing HDF error messages
// Explanation about the function for the error stack is here:
// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-SetAuto2
if (getenv("DEBUG_HDF")) {
cerr << "Field3DFile -- HDF5 messages are on" << endl;
H5Eset_auto(H5E_DEFAULT, localPrintError, NULL);
} else {
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
}
}
Field3DFileBase::~Field3DFileBase ( )
pure virtual

Pure virtual destructor to ensure we never instantiate this class.

Definition at line 299 of file Field3DFile.cpp.

References close().

{
close();
}
Field3DFileBase::Field3DFileBase ( const Field3DFileBase )
private

Member Function Documentation

void Field3DFileBase::clear ( )

Clear the data structures and close the file.

Definition at line 478 of file Field3DFile.cpp.

References closeInternal(), m_groupMembership, and m_partitions.

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

{
m_partitions.clear();
}
bool Field3DFileBase::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.

Definition at line 487 of file Field3DFile.cpp.

References closeInternal().

Referenced by Field3DInputFile::open(), and ~Field3DFileBase().

{
return true;
}
void Field3DFileBase::getPartitionNames ( std::vector< std::string > &  names) const

Gets the names of all the partitions in the file.

Definition at line 377 of file Field3DFile.cpp.

References m_partitions, and removeUniqueId().

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

{
names.clear();
vector<string> tempNames;
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
tempNames.push_back(removeUniqueId((**i).name));
}
names = makeUnique(tempNames);
}
void Field3DFileBase::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 394 of file Field3DFile.cpp.

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

Referenced by Field3DInputFile::readProxyScalarLayers().

{
names.clear();
for (int i = 0; i < numIntPartitions(partitionName); i++) {
string internalName = makeIntPartitionName(partitionName, i);
Partition::Ptr part = partition(internalName);
if (part)
part->getScalarLayerNames(names);
}
names = makeUnique(names);
}
void Field3DFileBase::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 412 of file Field3DFile.cpp.

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

Referenced by Field3DInputFile::readProxyVectorLayers().

{
names.clear();
for (int i = 0; i < numIntPartitions(partitionName); i++) {
string internalName = makeIntPartitionName(partitionName, i);
Partition::Ptr part = partition(internalName);
if (part)
part->getVectorLayerNames(names);
}
names = makeUnique(names);
}
File::Partition::Ptr Field3DFileBase::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 288 of file Field3DFile.h.

References partition().

{ return partition(partitionName); }
std::string Field3DFileBase::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 307 of file Field3DFile.cpp.

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

Referenced by Field3DInputFile::readScalarLayer(), Field3DInputFile::readVectorLayer(), and Field3DOutputFile::writeLayer().

{
// Loop over existing partitions and see if there's a matching mapping
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
if (removeUniqueId((**i).name) == partitionName) {
if ((**i).mapping->isIdentical(field->mapping())) {
return (**i).name;
}
}
}
// If there was no previously matching name, then make a new one
int nextIdx = -1;
if (m_partitionCount.find(partitionName) != m_partitionCount.end()) {
nextIdx = ++m_partitionCount[partitionName];
} else {
nextIdx = 0;
m_partitionCount[partitionName] = 0;
}
return makeIntPartitionName(partitionName, nextIdx);
}
std::string Field3DFileBase::removeUniqueId ( const std::string &  partitionName) const

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

Definition at line 364 of file Field3DFile.cpp.

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

{
size_t pos = partitionName.rfind(".");
if (pos == partitionName.npos) {
return partitionName;
} else {
return partitionName.substr(0, pos);
}
}
void Field3DFileBase::addGroupMembership ( const GroupMembershipMap groupMembers)

Add to the group membership.

Definition at line 540 of file Field3DFile.cpp.

References m_groupMembership.

{
GroupMembershipMap::const_iterator i= groupMembers.begin();
GroupMembershipMap::const_iterator end= groupMembers.end();
for (; i != end; ++i) {
GroupMembershipMap::iterator foundGroupIter =
m_groupMembership.find(i->first);
if (foundGroupIter != m_groupMembership.end()){
std::string value = m_groupMembership[i->first] + i->second;
m_groupMembership[i->first] = value;
} else {
m_groupMembership[i->first] = i->second;
}
}
}
FieldMetadata<Field3DFileBase>& Field3DFileBase::metadata ( )
inline

accessor to the m_metadata class

Definition at line 315 of file Field3DFile.h.

References m_metadata.

Referenced by Field3DInputFile::readMetadata(), and Field3DOutputFile::writeMetadata().

{ return m_metadata; }
const FieldMetadata<Field3DFileBase>& Field3DFileBase::metadata ( ) const
inline

Read only access to the m_metadata class.

Definition at line 319 of file Field3DFile.h.

References m_metadata.

{ return m_metadata; }
virtual void Field3DFileBase::metadataHasChanged ( const std::string &  )
inlinevirtual

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

Definition at line 324 of file Field3DFile.h.

{ /* Empty */ }
void Field3DFileBase::printHierarchy ( ) const

Definition at line 1533 of file Field3DFile.cpp.

References m_partitions.

{
// For each partition
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
cout << "Name: " << (**i).name << endl;
if ((**i).mapping)
cout << " Mapping: " << (**i).mapping->className() << endl;
else
cout << " Mapping: NULL" << endl;
cout << " Scalar layers: " << endl;
vector<string> sNames;
(**i).getScalarLayerNames(sNames);
for_each(sNames.begin(), sNames.end(), print<string>(4));
cout << " Vector layers: " << endl;
vector<string> vNames;
(**i).getVectorLayerNames(vNames);
for_each(vNames.begin(), vNames.end(), print<string>(4));
}
}
void Field3DFileBase::closeInternal ( )
protected

Closes the file if open.

Definition at line 496 of file Field3DFile.cpp.

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

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

{
if (m_file != -1) {
if (H5Fclose(m_file) < 0) {
Msg::print(Msg::SevWarning, "Failed to close hdf5 file handle");
return;
}
m_file = -1;
}
}
File::Partition::Ptr Field3DFileBase::partition ( const std::string &  partitionName)
protected
File::Partition::Ptr Field3DFileBase::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 Field3DFileBase::getIntPartitionNames ( std::vector< std::string > &  names) const
protected

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

Definition at line 430 of file Field3DFile.cpp.

References m_partitions.

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

{
names.clear();
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
names.push_back((**i).name);
}
}
void Field3DFileBase::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 443 of file Field3DFile.cpp.

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

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

{
names.clear();
if (!part) {
Msg::print("getIntScalarLayerNames no partition: " + intPartitionName);
return;
}
part->getScalarLayerNames(names);
}
void Field3DFileBase::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 461 of file Field3DFile.cpp.

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

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

{
names.clear();
if (!part) {
Msg::print("getIntVectorLayerNames no partition: " + intPartitionName);
return;
}
part->getVectorLayerNames(names);
}
int Field3DFileBase::numIntPartitions ( const std::string &  partitionName) const
protected

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

Definition at line 510 of file Field3DFile.cpp.

References m_partitions.

Referenced by getScalarLayerNames(), and getVectorLayerNames().

{
int count = 0;
for (PartitionList::const_iterator i = m_partitions.begin();
i != m_partitions.end(); ++i) {
string name = (**i).name;
size_t pos = name.rfind(".");
if (pos != name.npos) {
if (name.substr(0, pos) == partitionName) {
count++;
}
}
}
return count;
}
string Field3DFileBase::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 531 of file Field3DFile.cpp.

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

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

Member Data Documentation

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

This stores layer info.

Definition at line 381 of file Field3DFile.h.

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

std::vector<std::string> Field3DFileBase::m_partitionNames
protected

This stores partition names.

Definition at line 388 of file Field3DFile.h.

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

PartitionCountMap Field3DFileBase::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 392 of file Field3DFile.h.

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

GroupMembershipMap Field3DFileBase::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 397 of file Field3DFile.h.

Referenced by addGroupMembership(), clear(), Field3DInputFile::readGroupMembership(), and Field3DOutputFile::writeGroupMembership().

FieldMetadata<Field3DFileBase> Field3DFileBase::m_metadata
protected

metadata

Definition at line 400 of file Field3DFile.h.

Referenced by metadata().


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