Commit 7bcbfe72 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Performance improvements for large reads/writes

Eliminate getRealPath calls which are expensive and not necessary in many cases
Parse XML node content only when necessary (parsing arrays)
Fix cases where copies were made of strings instead of using references
Use "map.insert()" rather than "map[] =" when adding properties to map
parent 8c27cc2d
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp"
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
......@@ -56,7 +57,7 @@ std::map<std::string, std::string>
XdmfAttribute::getItemProperties() const
{
std::map<std::string, std::string> attributeProperties;
attributeProperties["Name"] = mName;
attributeProperties.insert(std::make_pair("Name", mName));
mType->getProperties(attributeProperties);
mCenter->getProperties(attributeProperties);
return attributeProperties;
......@@ -82,7 +83,7 @@ XdmfAttribute::getType() const
void
XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......@@ -93,7 +94,9 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
mName = name->second;
}
else {
XdmfError::message(XdmfError::FATAL,"'Name' not found in itemProperties in XdmfAttribute::populateItem");
XdmfError::message(XdmfError::FATAL,
"'Name' not found in itemProperties in "
"XdmfAttribute::populateItem");
}
mCenter = XdmfAttributeCenter::New(itemProperties);
......@@ -104,8 +107,8 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array);
break;
}
// TODO: If multiple dataitems.
}
}
......
......@@ -109,7 +109,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttributeCenter.hpp"
#include "XdmfError.hpp"
......@@ -79,37 +80,38 @@ XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperti
{
std::map<std::string, std::string>::const_iterator center =
itemProperties.find("Center");
if(center != itemProperties.end()) {
const std::string centerVal = center->second;
if(centerVal.compare("Grid") == 0) {
return Grid();
}
else if(centerVal.compare("Cell") == 0) {
return Cell();
}
else if(centerVal.compare("Face") == 0) {
return Face();
}
else if(centerVal.compare("Edge") == 0) {
return Edge();
}
else if(centerVal.compare("Node") == 0) {
return Node();
}
else {
XdmfError::message(XdmfError::FATAL,
"Center not of 'Grid','Cell','Face','Edge','Node' "
"in XdmfAttributeCenter::New");
}
if(center == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"'Center' not found in itemProperties in "
"XdmfAttributeCenter::New");
}
const std::string & centerVal = center->second;
if(centerVal.compare("Node") == 0) {
return Node();
}
else if(centerVal.compare("Cell") == 0) {
return Cell();
}
else if(centerVal.compare("Grid") == 0) {
return Grid();
}
else if(centerVal.compare("Face") == 0) {
return Face();
}
else if(centerVal.compare("Edge") == 0) {
return Edge();
}
XdmfError::message(XdmfError::FATAL,
"'Center' not found in itemProperties in "
"XdmfAttributeCenter::New");
"Center not of 'Grid','Cell','Face','Edge','Node' "
"in XdmfAttributeCenter::New");
return shared_ptr<const XdmfAttributeCenter>();
}
void
XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Center"] = mName;
collectedProperties.insert(std::make_pair("Center", mName));
}
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttributeType.hpp"
#include "XdmfError.hpp"
......@@ -98,44 +99,45 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties
if(type == itemProperties.end()) {
type = itemProperties.find("AttributeType");
}
if(type != itemProperties.end()) {
const std::string typeVal = type->second;
if(typeVal.compare("None") == 0) {
return NoAttributeType();
}
else if(typeVal.compare("Scalar") == 0) {
return Scalar();
}
else if(typeVal.compare("Vector") == 0) {
return Vector();
}
else if(typeVal.compare("Tensor") == 0) {
return Tensor();
}
else if(typeVal.compare("Matrix") == 0) {
return Matrix();
}
else if(typeVal.compare("Tensor6") == 0) {
return Tensor6();
}
else if(typeVal.compare("GlobalId") == 0) {
return GlobalId();
}
else {
XdmfError::message(XdmfError::FATAL,
"Type not of 'None','Scalar','Vector','Tensor', "
"'Matrix','Tensor6', or 'GlobalId' in "
"XdmfAttributeType::New");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'AttributeType' found in "
"itemProperties in XdmfAttributeType::New");
}
const std::string & typeVal = type->second;
if(typeVal.compare("Scalar") == 0) {
return Scalar();
}
else if(typeVal.compare("Vector") == 0) {
return Vector();
}
else if(typeVal.compare("Tensor") == 0) {
return Tensor();
}
else if(typeVal.compare("Matrix") == 0) {
return Matrix();
}
else if(typeVal.compare("Tensor6") == 0) {
return Tensor6();
}
else if(typeVal.compare("GlobalId") == 0) {
return GlobalId();
}
else if(typeVal.compare("None") == 0) {
return NoAttributeType();
}
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'AttributeType' found in "
"itemProperties in XdmfAttributeType::New");
"Type not of 'None','Scalar','Vector','Tensor', "
"'Matrix','Tensor6', or 'GlobalId' in "
"XdmfAttributeType::New");
return shared_ptr<const XdmfAttributeType>();
}
void
XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = mName;
collectedProperties.insert(std::make_pair("Type", mName));
}
......@@ -244,7 +244,7 @@ XdmfCurvilinearGrid::getGeometry()
void
XdmfCurvilinearGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfGrid::populateItem(itemProperties, childItems, reader);
......
......@@ -131,7 +131,7 @@ protected:
void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -81,7 +81,7 @@ XdmfDomain::getItemTag() const
void
XdmfDomain::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......
......@@ -76,7 +76,7 @@ protected:
XdmfDomain();
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -73,7 +73,7 @@ XdmfGeometry::getType() const
void
XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......@@ -84,8 +84,8 @@ XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProper
++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array);
break;
}
// TODO: If multiple dataitems.
}
}
......
......@@ -84,7 +84,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfGeometryType.hpp"
#include "XdmfError.hpp"
......@@ -65,26 +66,26 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
if(type == itemProperties.end()) {
type = itemProperties.find("GeometryType");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'GeometryType' in itemProperties "
"in XdmfGeometryType::New");
}
const std::string & typeVal = type->second;
if(type != itemProperties.end()) {
const std::string typeVal = type->second;
if(typeVal.compare("None") == 0) {
return NoGeometryType();
}
else if(typeVal.compare("XYZ") == 0) {
return XYZ();
}
else if(typeVal.compare("XY") == 0) {
return XY();
}
else {
XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' "
"in XdmfGeometryType::New");
}
if(typeVal.compare("None") == 0) {
return NoGeometryType();
}
else if(typeVal.compare("XYZ") == 0) {
return XYZ();
}
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'GeometryType' in itemProperties in "
"XdmfGeometryType::New");
else if(typeVal.compare("XY") == 0) {
return XY();
}
XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' "
"in XdmfGeometryType::New");
return shared_ptr<const XdmfGeometryType>();
}
......@@ -103,5 +104,5 @@ XdmfGeometryType::getName() const
void
XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = mName;
collectedProperties.insert(std::make_pair("Type", mName));
}
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
......@@ -59,7 +60,7 @@ std::map<std::string, std::string>
XdmfGrid::getItemProperties() const
{
std::map<std::string, std::string> gridProperties;
gridProperties["Name"] = mName;
gridProperties.insert(std::make_pair("Name", mName));
return gridProperties;
}
......@@ -96,7 +97,7 @@ XdmfGrid::getTopology() const
void
XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......
......@@ -130,7 +130,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
shared_ptr<XdmfGeometry> mGeometry;
......
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfGeometry.hpp"
#include "XdmfTopology.hpp"
#include "XdmfGridCollection.hpp"
......@@ -51,7 +52,7 @@ XdmfGridCollection::getItemProperties() const
{
std::map<std::string, std::string> collectionProperties =
XdmfGrid::getItemProperties();
collectionProperties["GridType"] = "Collection";
collectionProperties.insert(std::make_pair("GridType", "Collection"));
mType->getProperties(collectionProperties);
return collectionProperties;
}
......@@ -76,7 +77,7 @@ XdmfGridCollection::insert(const shared_ptr<XdmfInformation> information)
void
XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
mType = XdmfGridCollectionType::New(itemProperties);
......
......@@ -97,7 +97,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -21,8 +21,9 @@
/* */
/*****************************************************************************/
#include "XdmfGridCollectionType.hpp"
#include <utility>
#include "XdmfError.hpp"
#include "XdmfGridCollectionType.hpp"
// Supported XdmfGridCollectionTypes
shared_ptr<const XdmfGridCollectionType>
......@@ -63,31 +64,32 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope
{
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("CollectionType");
if(type != itemProperties.end()) {
const std::string typeVal = type->second;
if(typeVal.compare("None") == 0) {
return NoCollectionType();
}
else if(typeVal.compare("Spatial") == 0) {
return Spatial();
}
else if(typeVal.compare("Temporal") == 0) {
return Temporal();
}
else {
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not of 'None', 'Spatial', or "
"'Temporal' in XdmfGridCollectionType::New");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not in itemProperties in "
"XdmfGridCollectionType::New");
}
const std::string & typeVal = type->second;
if(typeVal.compare("None") == 0) {
return NoCollectionType();
}
else if(typeVal.compare("Spatial") == 0) {
return Spatial();
}
else if(typeVal.compare("Temporal") == 0) {
return Temporal();
}
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not in itemProperties in "
"XdmfGridCollectionType::New");
"'CollectionType' not of 'None', 'Spatial', or "
"'Temporal' in XdmfGridCollectionType::New");
return shared_ptr<const XdmfGridCollectionType>();
}
void
XdmfGridCollectionType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["CollectionType"] = mName;
collectedProperties.insert(std::make_pair("CollectionType", mName));
}
......@@ -80,13 +80,11 @@ XdmfItemFactory::createItem(const std::string & itemTag,
}
if(type != itemProperties.end()) {
const std::string typeVal = type->second;
const std::string & typeVal = type->second;
if(typeVal.compare("ORIGIN_DXDY") == 0 ||
typeVal.compare("ORIGIN_DXDYDZ") == 0) {
shared_ptr<XdmfArray> origin =
shared_ptr<XdmfArray>();
shared_ptr<XdmfArray> brickSize =
shared_ptr<XdmfArray>();
shared_ptr<XdmfArray> origin = shared_ptr<XdmfArray>();
shared_ptr<XdmfArray> brickSize = shared_ptr<XdmfArray>();
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
......
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp"
#include "XdmfError.hpp"
#include "XdmfGridCollection.hpp"
......@@ -93,7 +94,7 @@ std::map<std::string, std::string>
XdmfMap::getItemProperties() const
{
std::map<std::string, std::string> mapProperties;
mapProperties["Name"] = mName;
mapProperties.insert(std::make_pair("Name", mName));
return mapProperties;
}
......@@ -142,7 +143,7 @@ bool XdmfMap::isInitialized() const
void
XdmfMap::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......
......@@ -186,7 +186,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -373,7 +373,7 @@ XdmfRectilinearGrid::getDimensions() const
void
XdmfRectilinearGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfGrid::populateItem(itemProperties, childItems, reader);
......
......@@ -165,7 +165,7 @@ protected:
XdmfRectilinearGrid(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates);
void populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -397,7 +397,7 @@ XdmfRegularGrid::getOrigin() const
void
XdmfRegularGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfGrid::populateItem(itemProperties, childItems, reader);
......
......@@ -188,7 +188,7 @@ protected:
const shared_ptr<XdmfArray> origin);
void populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfSet.hpp"
......@@ -52,7 +53,7 @@ std::map<std::string, std::string>
XdmfSet::getItemProperties() const
{
std::map<std::string, std::string> setProperties;
setProperties["Name"] = mName;
setProperties.insert(std::make_pair("Name", mName));
mType->getProperties(setProperties);
return setProperties;
}
......@@ -77,7 +78,7 @@ XdmfSet::getType() const
void
XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......
......@@ -107,7 +107,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private:
......
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfSetType.hpp"
#include "XdmfError.hpp"
......@@ -77,37 +78,38 @@ XdmfSetType::New(const std::map<std::string, std::string> & itemProperties)
if(type == itemProperties.end()) {
type = itemProperties.find("SetType");
}
if(type != itemProperties.end()) {
const std::string typeVal = type->second;
if(typeVal.compare("None") == 0) {
return NoSetType();
}
else if(typeVal.compare("Node") == 0) {
return Node();
}
else if(typeVal.compare("Cell") == 0) {
return Cell();
}
else if(typeVal.compare("Face") == 0) {
return Face();
}
else if(typeVal.compare("Edge") == 0) {
return Edge();
}
else {
XdmfError::message(XdmfError::FATAL,
"Type not of 'None', 'Node', 'Cell', 'Face', or "
"'Edge' in XdmfSetType::New");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'SetType' found in itemProperties "
"in XdmfSetType::New");
}
const std::string & typeVal = type->second;
if(typeVal.compare("Node") == 0) {
return Node();
}
else if(typeVal.compare("Cell") == 0) {
return Cell();
}
else if(typeVal.compare("Face") == 0) {
return Face();
}
else if(typeVal.compare("Edge") == 0) {
return Edge();
}
else if(typeVal.compare("None") == 0) {
return NoSetType();
}
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'SetType' found in itemProperties "
"in XdmfSetType::New");
"Type not of 'None', 'Node', 'Cell', 'Face', or "
"'Edge' in XdmfSetType::New");
return shared_ptr<const XdmfSetType>();
}
void
XdmfSetType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = this->mName;
collectedProperties.insert(std::make_pair("Type", mName));
}
......@@ -22,6 +22,7 @@
/*****************************************************************************/
#include <sstream>
#include <utility>
#include "XdmfTime.hpp"
#include "XdmfError.hpp"
......@@ -49,7 +50,7 @@ XdmfTime::getItemProperties() const
std::map<std::string, std::string> timeProperties;
std::stringstream value;
value << mValue;
timeProperties["Value"] = value.str();
timeProperties.insert(std::make_pair("Value", value.str()));
return timeProperties;
}
......@@ -67,7 +68,7 @@ XdmfTime::getValue() const
void
XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......@@ -77,7 +78,9 @@ XdmfTime::populateItem(const std::map<std::string, std::string> & itemProperties
mValue = atof(value->second.c_str());
}
else {
XdmfError::message(XdmfError::FATAL, "'Value' not in itemProperties in XdmfTime::populateItem");
XdmfError::message(XdmfError::FATAL,
"'Value' not in itemProperties in "
"XdmfTime::populateItem");
}
}
......
......@@ -74,7 +74,7 @@ protected:
virtual void
populateItem(const std::map<std::string, std::string> & itemProperties,
std::vector<shared_ptr<XdmfItem> > & childItems,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader);
private: