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. 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...
 
FieldMetadata< Field3DFileBase > & metadata ()
 accessor to the m_metadata class More...
 
const FieldMetadata
< Field3DFileBase > & 
metadata () 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
 Field3DFileBase ()
 
virtual ~Field3DFileBase ()=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...
 
File::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
< File::Partition::Ptr
PartitionList
 

Protected Member Functions

Convenience methods
void closeInternal ()
 Closes the file if open. 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...
 

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

 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.

284  : m_file(-1), m_metadata(this)
285 {
286  // Suppressing HDF error messages
287  // Explanation about the function for the error stack is here:
288  // http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-SetAuto2
289  if (getenv("DEBUG_HDF")) {
290  cerr << "Field3DFile -- HDF5 messages are on" << endl;
291  H5Eset_auto(H5E_DEFAULT, localPrintError, NULL);
292  } else {
293  H5Eset_auto(H5E_DEFAULT, NULL, NULL);
294  }
295 }
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:400
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
Field3DFileBase::~Field3DFileBase ( )
pure virtual

Pure virtual destructor to ensure we never instantiate this class.

Definition at line 299 of file Field3DFile.cpp.

References close().

300 {
301  close();
302 }
bool close()
Closes the file. No need to call this unless you specifically want to close the file early...
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().

479 {
480  closeInternal();
481  m_partitions.clear();
482  m_groupMembership.clear();
483 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
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 &quot;group&quot; and the valu...
Definition: Field3DFile.h:397
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().

488 {
489  closeInternal();
490 
491  return true;
492 }
void closeInternal()
Closes the file if open.
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().

378 {
379  names.clear();
380 
381  vector<string> tempNames;
382 
383  for (PartitionList::const_iterator i = m_partitions.begin();
384  i != m_partitions.end(); ++i) {
385  tempNames.push_back(removeUniqueId((**i).name));
386  }
387 
388  names = makeUnique(tempNames);
389 }
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
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().

396 {
397  names.clear();
398 
399  for (int i = 0; i < numIntPartitions(partitionName); i++) {
400  string internalName = makeIntPartitionName(partitionName, i);
401  Partition::Ptr part = partition(internalName);
402  if (part)
403  part->getScalarLayerNames(names);
404  }
405 
406  names = makeUnique(names);
407 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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.
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().

414 {
415  names.clear();
416 
417  for (int i = 0; i < numIntPartitions(partitionName); i++) {
418  string internalName = makeIntPartitionName(partitionName, i);
419  Partition::Ptr part = partition(internalName);
420  if (part)
421  part->getVectorLayerNames(names);
422  }
423 
424  names = makeUnique(names);
425 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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.
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().

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

310 {
311  // Loop over existing partitions and see if there's a matching mapping
312  for (PartitionList::const_iterator i = m_partitions.begin();
313  i != m_partitions.end(); ++i) {
314  if (removeUniqueId((**i).name) == partitionName) {
315  if ((**i).mapping->isIdentical(field->mapping())) {
316  return (**i).name;
317  }
318  }
319  }
320 
321  // If there was no previously matching name, then make a new one
322 
323  int nextIdx = -1;
324  if (m_partitionCount.find(partitionName) != m_partitionCount.end()) {
325  nextIdx = ++m_partitionCount[partitionName];
326  } else {
327  nextIdx = 0;
328  m_partitionCount[partitionName] = 0;
329  }
330 
331  return makeIntPartitionName(partitionName, nextIdx);
332 }
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:392
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original 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 ...
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
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().

365 {
366  size_t pos = partitionName.rfind(".");
367  if (pos == partitionName.npos) {
368  return partitionName;
369  } else {
370  return partitionName.substr(0, pos);
371  }
372 }
void Field3DFileBase::addGroupMembership ( const GroupMembershipMap groupMembers)

Add to the group membership.

Definition at line 540 of file Field3DFile.cpp.

References m_groupMembership.

541 {
542  GroupMembershipMap::const_iterator i= groupMembers.begin();
543  GroupMembershipMap::const_iterator end= groupMembers.end();
544 
545  for (; i != end; ++i) {
546  GroupMembershipMap::iterator foundGroupIter =
547  m_groupMembership.find(i->first);
548  if (foundGroupIter != m_groupMembership.end()){
549  std::string value = m_groupMembership[i->first] + i->second;
550  m_groupMembership[i->first] = value;
551  } else {
552  m_groupMembership[i->first] = i->second;
553  }
554  }
555 }
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the &quot;group&quot; and the valu...
Definition: Field3DFile.h:397
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().

316  { return m_metadata; }
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:400
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.

320  { return m_metadata; }
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:400
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.

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

Definition at line 1533 of file Field3DFile.cpp.

References m_partitions.

1534 {
1535  // For each partition
1536  for (PartitionList::const_iterator i = m_partitions.begin();
1537  i != m_partitions.end(); ++i) {
1538  cout << "Name: " << (**i).name << endl;
1539  if ((**i).mapping)
1540  cout << " Mapping: " << (**i).mapping->className() << endl;
1541  else
1542  cout << " Mapping: NULL" << endl;
1543  cout << " Scalar layers: " << endl;
1544  vector<string> sNames;
1545  (**i).getScalarLayerNames(sNames);
1546  for_each(sNames.begin(), sNames.end(), print<string>(4));
1547  cout << " Vector layers: " << endl;
1548  vector<string> vNames;
1549  (**i).getVectorLayerNames(vNames);
1550  for_each(vNames.begin(), vNames.end(), print<string>(4));
1551  }
1552 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
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().

497 {
498  if (m_file != -1) {
499  if (H5Fclose(m_file) < 0) {
500  Msg::print(Msg::SevWarning, "Failed to close hdf5 file handle");
501  return;
502  }
503  m_file = -1;
504  }
505 }
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:384
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().

431 {
432  names.clear();
433 
434  for (PartitionList::const_iterator i = m_partitions.begin();
435  i != m_partitions.end(); ++i) {
436  names.push_back((**i).name);
437  }
438 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
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().

445 {
446  names.clear();
447 
449 
450  if (!part) {
451  Msg::print("getIntScalarLayerNames no partition: " + intPartitionName);
452  return;
453  }
454 
455  part->getScalarLayerNames(names);
456 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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 ...
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().

463 {
464  names.clear();
465 
467 
468  if (!part) {
469  Msg::print("getIntVectorLayerNames no partition: " + intPartitionName);
470  return;
471  }
472 
473  part->getVectorLayerNames(names);
474 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:149
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
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 ...
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().

511 {
512  int count = 0;
513 
514  for (PartitionList::const_iterator i = m_partitions.begin();
515  i != m_partitions.end(); ++i) {
516  string name = (**i).name;
517  size_t pos = name.rfind(".");
518  if (pos != name.npos) {
519  if (name.substr(0, pos) == partitionName) {
520  count++;
521  }
522  }
523  }
524 
525  return count;
526 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:386
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().

533 {
534  return partitionName + "." + boost::lexical_cast<std::string>(i);
535 }
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: