Field3D
Field3DFileBase Class Referenceabstract

#include <Field3DFile.h>

Inheritance diagram for Field3DFileBase:
MetadataCallback 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...
 
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
 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...
 
Convenience methods for partitionName
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
File::Partition::Ptr getPartition (const std::string &partitionName) const
 Returns a pointer to the given partition. More...
 
virtual void closeInternal ()=0
 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...
 
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...
 

Protected Attributes

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...
 
boost::shared_ptr< Field3DFileHDF5Basem_hdf5Base
 HDF5 fallback. 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

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

Member Typedef Documentation

◆ GroupMembershipMap

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

Definition at line 228 of file Field3DFile.h.

◆ PartitionList

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

Definition at line 311 of file Field3DFile.h.

◆ PartitionCountMap

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

Definition at line 312 of file Field3DFile.h.

Constructor & Destructor Documentation

◆ Field3DFileBase() [1/2]

Field3DFileBase::Field3DFileBase ( )

Definition at line 405 of file Field3DFile.cpp.

406  : m_metadata(this)
407 {
408  // Empty
409 }

◆ ~Field3DFileBase()

Field3DFileBase::~Field3DFileBase ( )
pure virtual

Pure virtual destructor to ensure we never instantiate this class.

Definition at line 413 of file Field3DFile.cpp.

414 {
415  m_partitions.clear();
416  m_groupMembership.clear();
417 }

References m_groupMembership, and m_partitions.

◆ Field3DFileBase() [2/2]

Field3DFileBase::Field3DFileBase ( const Field3DFileBase )
private

Member Function Documentation

◆ clear()

void Field3DFileBase::clear ( )

Clear the data structures and close the file.

Definition at line 616 of file Field3DFile.cpp.

617 {
618  if (m_hdf5Base) {
619  m_hdf5Base->clear();
620  return;
621  }
622 
623  closeInternal();
624  m_partitions.clear();
625  m_groupMembership.clear();
626 }

References closeInternal(), m_groupMembership, m_hdf5Base, and m_partitions.

Referenced by Field3DInputFile::open().

◆ close()

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

631 {
632  if (m_hdf5Base) {
633  return m_hdf5Base->close();
634  }
635 
636  closeInternal();
637 
638  return true;
639 }

References closeInternal(), and m_hdf5Base.

Referenced by Field3DInputFile::open().

◆ getPartitionNames()

void Field3DFileBase::getPartitionNames ( std::vector< std::string > &  names) const

Gets the names of all the partitions in the file.

Definition at line 492 of file Field3DFile.cpp.

493 {
494  if (m_hdf5Base) {
495  m_hdf5Base->getPartitionNames(names);
496  return;
497  }
498 
499  names.clear();
500 
501  vector<string> tempNames;
502 
503  for (PartitionList::const_iterator i = m_partitions.begin();
504  i != m_partitions.end(); ++i) {
505  tempNames.push_back(removeUniqueId((**i).name));
506  }
507 
508  names = makeUnique(tempNames);
509 }

References m_hdf5Base, m_partitions, and removeUniqueId().

Referenced by FieldGroup< BaseTypeList_T, Dims_T >::load(), Field3DInputFile::readProxyScalarLayers(), and Field3DInputFile::readProxyVectorLayers().

◆ getScalarLayerNames()

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.

Todo:
Make this really only return scalar layers

Definition at line 514 of file Field3DFile.cpp.

516 {
517  if (m_hdf5Base) {
518  m_hdf5Base->getScalarLayerNames(names, partitionName);
519  return;
520  }
521 
523 
524  names.clear();
525 
526  for (int i = 0; i < numIntPartitions(partitionName); i++) {
527  string internalName = makeIntPartitionName(partitionName, i);
528  File::Partition::Ptr part = partition(internalName);
529  if (part)
530  part->getLayerNames(names);
531  }
532 
533  names = makeUnique(names);
534 }

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

Referenced by Field3DInputFile::readProxyScalarLayers().

◆ getVectorLayerNames()

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.

Todo:
Make this really only return vector layers

Definition at line 539 of file Field3DFile.cpp.

541 {
542  if (m_hdf5Base) {
543  m_hdf5Base->getVectorLayerNames(names, partitionName);
544  return;
545  }
546 
548 
549  names.clear();
550 
551  for (int i = 0; i < numIntPartitions(partitionName); i++) {
552  string internalName = makeIntPartitionName(partitionName, i);
553  File::Partition::Ptr part = partition(internalName);
554  if (part)
555  part->getLayerNames(names);
556  }
557 
558  names = makeUnique(names);
559 }

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

Referenced by Field3DInputFile::readProxyVectorLayers().

◆ addGroupMembership()

void Field3DFileBase::addGroupMembership ( const GroupMembershipMap groupMembers)

Add to the group membership.

Definition at line 674 of file Field3DFile.cpp.

675 {
676  if (m_hdf5Base) {
677  m_hdf5Base->addGroupMembership(groupMembers);
678  return;
679  }
680 
681  GroupMembershipMap::const_iterator i = groupMembers.begin();
682  GroupMembershipMap::const_iterator end = groupMembers.end();
683 
684  for (; i != end; ++i) {
685  GroupMembershipMap::iterator foundGroupIter =
686  m_groupMembership.find(i->first);
687  if (foundGroupIter != m_groupMembership.end()){
688  std::string value = m_groupMembership[i->first] + i->second;
689  m_groupMembership[i->first] = value;
690  } else {
691  m_groupMembership[i->first] = i->second;
692  }
693  }
694 }

References m_groupMembership, and m_hdf5Base.

◆ metadata() [1/2]

FieldMetadata& Field3DFileBase::metadata ( )
inline

accessor to the m_metadata class

Definition at line 276 of file Field3DFile.h.

277  {
278  if (m_hdf5Base) {
279  return m_hdf5Base->metadata();
280  }
281  return m_metadata;
282  }

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

◆ metadata() [2/2]

const FieldMetadata& Field3DFileBase::metadata ( ) const
inline

Read only access to the m_metadata class.

Definition at line 285 of file Field3DFile.h.

286  {
287  if (m_hdf5Base) {
288  return m_hdf5Base->metadata();
289  }
290  return m_metadata;
291  }

◆ metadataHasChanged()

virtual void Field3DFileBase::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 295 of file Field3DFile.h.

296  { /* Empty */ }

◆ printHierarchy()

void Field3DFileBase::printHierarchy ( ) const

Definition at line 1307 of file Field3DFile.cpp.

1308 {
1309  // For each partition
1310  for (PartitionList::const_iterator i = m_partitions.begin();
1311  i != m_partitions.end(); ++i) {
1312  cout << "Name: " << (**i).name << endl;
1313  if ((**i).mapping)
1314  cout << " Mapping: " << (**i).mapping->className() << endl;
1315  else
1316  cout << " Mapping: NULL" << endl;
1317  cout << " Layers: " << endl;
1318  vector<string> names;
1319  (**i).getLayerNames(names);
1320  for_each(names.begin(), names.end(), print<string>(4));
1321  }
1322 }

References m_partitions.

◆ getPartition()

File::Partition::Ptr Field3DFileBase::getPartition ( const std::string &  partitionName) const
inlineprotected

Returns a pointer to the given partition.

Returns
NULL if no partition was found of that name

Definition at line 321 of file Field3DFile.h.

322  { return partition(partitionName); }

◆ closeInternal()

virtual void Field3DFileBase::closeInternal ( )
protectedpure virtual

Closes the file if open.

Implemented in Field3DOutputFile, and Field3DInputFile.

Referenced by clear(), and close().

◆ partition() [1/2]

File::Partition::Ptr Field3DFileBase::partition ( const std::string &  partitionName)
protected

◆ partition() [2/2]

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

◆ getIntPartitionNames()

void Field3DFileBase::getIntPartitionNames ( std::vector< std::string > &  names) const
protected

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

Definition at line 564 of file Field3DFile.cpp.

565 {
566  names.clear();
567 
568  for (PartitionList::const_iterator i = m_partitions.begin();
569  i != m_partitions.end(); ++i) {
570  names.push_back((**i).name);
571  }
572 }

References m_partitions.

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

◆ getIntScalarLayerNames()

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.

Todo:
Make this really only return scalar layers

Definition at line 577 of file Field3DFile.cpp.

579 {
581 
582  names.clear();
583 
585 
586  if (!part) {
587  Msg::print("getIntScalarLayerNames no partition: " + intPartitionName);
588  return;
589  }
590 
591  part->getLayerNames(names);
592 }

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

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

◆ getIntVectorLayerNames()

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.

Todo:
Make this really only return vector layers

Definition at line 597 of file Field3DFile.cpp.

599 {
601 
602  names.clear();
603 
605 
606  if (!part) {
607  Msg::print("getIntVectorLayerNames no partition: " + intPartitionName);
608  return;
609  }
610 
611  part->getLayerNames(names);
612 }

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

Referenced by Field3DInputFile::readProxyLayer().

◆ numIntPartitions()

int Field3DFileBase::numIntPartitions ( const std::string &  partitionName) const
protected

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

Definition at line 644 of file Field3DFile.cpp.

645 {
646  int count = 0;
647 
648  for (PartitionList::const_iterator i = m_partitions.begin();
649  i != m_partitions.end(); ++i) {
650  string name = (**i).name;
651  size_t pos = name.rfind(".");
652  if (pos != name.npos) {
653  if (name.substr(0, pos) == partitionName) {
654  count++;
655  }
656  }
657  }
658 
659  return count;
660 }

References m_partitions.

Referenced by getScalarLayerNames(), and getVectorLayerNames().

◆ makeIntPartitionName()

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

667 {
668  return partitionName + "." + boost::lexical_cast<std::string>(i);
669 }

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

◆ intPartitionName()

std::string Field3DFileBase::intPartitionName ( const std::string &  partitionName,
const std::string &  layerName,
FieldRes::Ptr  field 
)
protected

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

425 {
426  // Loop over existing partitions and see if there's a matching mapping
427  for (PartitionList::const_iterator i = m_partitions.begin();
428  i != m_partitions.end(); ++i) {
429  if (removeUniqueId((**i).name) == partitionName) {
430  if ((**i).mapping->isIdentical(field->mapping())) {
431  return (**i).name;
432  }
433  }
434  }
435 
436  // If there was no previously matching name, then make a new one
437 
438  int nextIdx = -1;
439  if (m_partitionCount.find(partitionName) != m_partitionCount.end()) {
440  nextIdx = ++m_partitionCount[partitionName];
441  } else {
442  nextIdx = 0;
443  m_partitionCount[partitionName] = 0;
444  }
445 
446  return makeIntPartitionName(partitionName, nextIdx);
447 }

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

Referenced by getIntScalarLayerNames(), getIntVectorLayerNames(), Field3DInputFile::readLayer(), and Field3DOutputFile::writeLayer().

◆ removeUniqueId()

std::string Field3DFileBase::removeUniqueId ( const std::string &  partitionName) const
protected

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

Definition at line 479 of file Field3DFile.cpp.

480 {
481  size_t pos = partitionName.rfind(".");
482  if (pos == partitionName.npos) {
483  return partitionName;
484  } else {
485  return partitionName.substr(0, pos);
486  }
487 }

Referenced by getPartitionNames(), Field3DOutputFile::incrementPartitionName(), intPartitionName(), Field3DInputFile::readLayer(), Field3DInputFile::readLayers(), and Field3DInputFile::readProxyLayer().

◆ operator=()

void Field3DFileBase::operator= ( const Field3DFileBase )
private

Member Data Documentation

◆ m_layerInfo

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

This stores layer info.

Definition at line 368 of file Field3DFile.h.

◆ m_partitions

◆ m_partitionNames

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

This stores partition names.

Definition at line 373 of file Field3DFile.h.

◆ m_partitionCount

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

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

◆ m_groupMembership

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

Referenced by addGroupMembership(), clear(), Field3DOutputFile::writeGroupMembership(), and ~Field3DFileBase().

◆ m_metadata

FieldMetadata Field3DFileBase::m_metadata
protected

metadata

Definition at line 385 of file Field3DFile.h.

◆ m_hdf5Base

boost::shared_ptr<Field3DFileHDF5Base> Field3DFileBase::m_hdf5Base
protected

The documentation for this class was generated from the following files:
Field3DFileBase::numIntPartitions
int numIntPartitions(const std::string &partitionName) const
Returns the number of internal partitions for a given partition name.
Definition: Field3DFile.cpp:644
Field3DFileBase::m_hdf5Base
boost::shared_ptr< Field3DFileHDF5Base > m_hdf5Base
HDF5 fallback.
Definition: Field3DFile.h:388
Field3DFileBase::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:371
Field3DFileBase::m_groupMembership
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:382
Field3DFileBase::m_metadata
FieldMetadata m_metadata
metadata
Definition: Field3DFile.h:385
Field3DFileBase::partition
File::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DFileBase::makeIntPartitionName
std::string makeIntPartitionName(const std::string &partitionsName, int i) const
Makes an internal partition name given the external partition name. Effectively just tacks on ....
Definition: Field3DFile.cpp:665
Field3DFileBase::closeInternal
virtual void closeInternal()=0
Closes the file if open.
File::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:127
Field3DFileBase::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition: Field3DFile.cpp:479
Field3DFileBase::intPartitionName
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 ...
Definition: Field3DFile.cpp:422
Msg::print
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
Field3DFileBase::m_partitionCount
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:377