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::PtrPartitionList
 

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 236 of file Field3DFile.h.

Member Typedef Documentation

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

Definition at line 254 of file Field3DFile.h.

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

Definition at line 343 of file Field3DFile.h.

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

Definition at line 344 of file Field3DFile.h.

Constructor & Destructor Documentation

Field3DFileBase::Field3DFileBase ( )

Definition at line 274 of file Field3DFile.cpp.

References g_hdf5Mutex.

275  : m_file(-1), m_metadata(this)
276 {
277  GlobalLock lock(g_hdf5Mutex);
278 
279  // Suppressing HDF error messages
280  // Explanation about the function for the error stack is here:
281  // http://www.hdfgroup.org/HDF5/doc/RM/RM_H5E.html#Error-SetAuto2
282  if (getenv("DEBUG_HDF")) {
283  cerr << "Field3DFile -- HDF5 messages are on" << endl;
284  H5Eset_auto(H5E_DEFAULT, localPrintError, NULL);
285  } else {
286  H5Eset_auto(H5E_DEFAULT, NULL, NULL);
287  }
288 }
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:403
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:387
Field3DFileBase::~Field3DFileBase ( )
pure virtual

Pure virtual destructor to ensure we never instantiate this class.

Definition at line 292 of file Field3DFile.cpp.

References close().

293 {
294  close();
295 }
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 471 of file Field3DFile.cpp.

References closeInternal(), m_groupMembership, and m_partitions.

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

472 {
473  closeInternal();
474  m_partitions.clear();
475  m_groupMembership.clear();
476 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:389
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...
Definition: Field3DFile.h:400
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 480 of file Field3DFile.cpp.

References closeInternal().

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

481 {
482  closeInternal();
483 
484  return true;
485 }
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 370 of file Field3DFile.cpp.

References m_partitions, and removeUniqueId().

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::load().

371 {
372  names.clear();
373 
374  vector<string> tempNames;
375 
376  for (PartitionList::const_iterator i = m_partitions.begin();
377  i != m_partitions.end(); ++i) {
378  tempNames.push_back(removeUniqueId((**i).name));
379  }
380 
381  names = makeUnique(tempNames);
382 }
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:389
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 387 of file Field3DFile.cpp.

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

389 {
390  names.clear();
391 
392  for (int i = 0; i < numIntPartitions(partitionName); i++) {
393  string internalName = makeIntPartitionName(partitionName, i);
394  Partition::Ptr part = partition(internalName);
395  if (part)
396  part->getScalarLayerNames(names);
397  }
398 
399  names = makeUnique(names);
400 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:152
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 405 of file Field3DFile.cpp.

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

407 {
408  names.clear();
409 
410  for (int i = 0; i < numIntPartitions(partitionName); i++) {
411  string internalName = makeIntPartitionName(partitionName, i);
412  Partition::Ptr part = partition(internalName);
413  if (part)
414  part->getVectorLayerNames(names);
415  }
416 
417  names = makeUnique(names);
418 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:152
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 291 of file Field3DFile.h.

292  { 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 300 of file Field3DFile.cpp.

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

303 {
304  // Loop over existing partitions and see if there's a matching mapping
305  for (PartitionList::const_iterator i = m_partitions.begin();
306  i != m_partitions.end(); ++i) {
307  if (removeUniqueId((**i).name) == partitionName) {
308  if ((**i).mapping->isIdentical(field->mapping())) {
309  return (**i).name;
310  }
311  }
312  }
313 
314  // If there was no previously matching name, then make a new one
315 
316  int nextIdx = -1;
317  if (m_partitionCount.find(partitionName) != m_partitionCount.end()) {
318  nextIdx = ++m_partitionCount[partitionName];
319  } else {
320  nextIdx = 0;
321  m_partitionCount[partitionName] = 0;
322  }
323 
324  return makeIntPartitionName(partitionName, nextIdx);
325 }
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:395
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:389
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 357 of file Field3DFile.cpp.

Referenced by getPartitionNames(), Field3DOutputFile::incrementPartitionName(), intPartitionName(), and Field3DInputFile::readGroupMembership().

358 {
359  size_t pos = partitionName.rfind(".");
360  if (pos == partitionName.npos) {
361  return partitionName;
362  } else {
363  return partitionName.substr(0, pos);
364  }
365 }
void Field3DFileBase::addGroupMembership ( const GroupMembershipMap groupMembers)

Add to the group membership.

Definition at line 535 of file Field3DFile.cpp.

References m_groupMembership.

536 {
537  GroupMembershipMap::const_iterator i= groupMembers.begin();
538  GroupMembershipMap::const_iterator end= groupMembers.end();
539 
540  for (; i != end; ++i) {
541  GroupMembershipMap::iterator foundGroupIter =
542  m_groupMembership.find(i->first);
543  if (foundGroupIter != m_groupMembership.end()){
544  std::string value = m_groupMembership[i->first] + i->second;
545  m_groupMembership[i->first] = value;
546  } else {
547  m_groupMembership[i->first] = i->second;
548  }
549  }
550 }
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:400
FieldMetadata<Field3DFileBase>& Field3DFileBase::metadata ( )
inline

accessor to the m_metadata class

Definition at line 318 of file Field3DFile.h.

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

319  { return m_metadata; }
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:403
const FieldMetadata<Field3DFileBase>& Field3DFileBase::metadata ( ) const
inline

Read only access to the m_metadata class.

Definition at line 322 of file Field3DFile.h.

323  { return m_metadata; }
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:403
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 327 of file Field3DFile.h.

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

Definition at line 1547 of file Field3DFile.cpp.

References m_partitions.

1548 {
1549  // For each partition
1550  for (PartitionList::const_iterator i = m_partitions.begin();
1551  i != m_partitions.end(); ++i) {
1552  cout << "Name: " << (**i).name << endl;
1553  if ((**i).mapping)
1554  cout << " Mapping: " << (**i).mapping->className() << endl;
1555  else
1556  cout << " Mapping: NULL" << endl;
1557  cout << " Scalar layers: " << endl;
1558  vector<string> sNames;
1559  (**i).getScalarLayerNames(sNames);
1560  for_each(sNames.begin(), sNames.end(), print<string>(4));
1561  cout << " Vector layers: " << endl;
1562  vector<string> vNames;
1563  (**i).getVectorLayerNames(vNames);
1564  for_each(vNames.begin(), vNames.end(), print<string>(4));
1565  }
1566 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:389
void Field3DFileBase::closeInternal ( )
protected

Closes the file if open.

Definition at line 489 of file Field3DFile.cpp.

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

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

490 {
491  GlobalLock lock(g_hdf5Mutex);
492 
493  if (m_file != -1) {
494  if (H5Fclose(m_file) < 0) {
495  Msg::print(Msg::SevWarning, "Failed to close hdf5 file handle");
496  return;
497  }
498  m_file = -1;
499  }
500 }
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:66
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:387
File::Partition::Ptr Field3DFileBase::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 Field3DInputFile::readPartitionAndLayerInfo().

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

References m_partitions.

424 {
425  names.clear();
426 
427  for (PartitionList::const_iterator i = m_partitions.begin();
428  i != m_partitions.end(); ++i) {
429  names.push_back((**i).name);
430  }
431 }
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:389
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 436 of file Field3DFile.cpp.

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

438 {
439  names.clear();
440 
442 
443  if (!part) {
444  Msg::print("getIntScalarLayerNames no partition: " + intPartitionName);
445  return;
446  }
447 
448  part->getScalarLayerNames(names);
449 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:152
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:66
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 454 of file Field3DFile.cpp.

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

456 {
457  names.clear();
458 
460 
461  if (!part) {
462  Msg::print("getIntVectorLayerNames no partition: " + intPartitionName);
463  return;
464  }
465 
466  part->getVectorLayerNames(names);
467 }
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:152
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:66
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 505 of file Field3DFile.cpp.

References m_partitions.

Referenced by getScalarLayerNames(), and getVectorLayerNames().

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

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

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

Member Data Documentation

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

This stores layer info.

Definition at line 384 of file Field3DFile.h.

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

hid_t Field3DFileBase::m_file
protected
PartitionList Field3DFileBase::m_partitions
protected
std::vector<std::string> Field3DFileBase::m_partitionNames
protected

This stores partition names.

Definition at line 391 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 395 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 400 of file Field3DFile.h.

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

FieldMetadata<Field3DFileBase> Field3DFileBase::m_metadata
protected

metadata

Definition at line 403 of file Field3DFile.h.


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