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

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 @@ ...@@ -21,6 +21,7 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp" #include "XdmfAttribute.hpp"
#include "XdmfAttributeCenter.hpp" #include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp" #include "XdmfAttributeType.hpp"
...@@ -56,7 +57,7 @@ std::map<std::string, std::string> ...@@ -56,7 +57,7 @@ std::map<std::string, std::string>
XdmfAttribute::getItemProperties() const XdmfAttribute::getItemProperties() const
{ {
std::map<std::string, std::string> attributeProperties; std::map<std::string, std::string> attributeProperties;
attributeProperties["Name"] = mName; attributeProperties.insert(std::make_pair("Name", mName));
mType->getProperties(attributeProperties); mType->getProperties(attributeProperties);
mCenter->getProperties(attributeProperties); mCenter->getProperties(attributeProperties);
return attributeProperties; return attributeProperties;
...@@ -82,7 +83,7 @@ XdmfAttribute::getType() const ...@@ -82,7 +83,7 @@ XdmfAttribute::getType() const
void void
XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties, 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) const XdmfCoreReader * const reader)
{ {
XdmfItem::populateItem(itemProperties, childItems, reader); XdmfItem::populateItem(itemProperties, childItems, reader);
...@@ -93,7 +94,9 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope ...@@ -93,7 +94,9 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
mName = name->second; mName = name->second;
} }
else { 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); mCenter = XdmfAttributeCenter::New(itemProperties);
...@@ -104,8 +107,8 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope ...@@ -104,8 +107,8 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
++iter) { ++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) { if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array); this->swap(array);
break;
} }
// TODO: If multiple dataitems.
} }
} }
......
...@@ -109,7 +109,7 @@ protected: ...@@ -109,7 +109,7 @@ protected:
virtual void virtual void
populateItem(const std::map<std::string, std::string> & itemProperties, 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); const XdmfCoreReader * const reader);
private: private:
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include <utility>
#include "XdmfAttributeCenter.hpp" #include "XdmfAttributeCenter.hpp"
#include "XdmfError.hpp" #include "XdmfError.hpp"
...@@ -79,37 +80,38 @@ XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperti ...@@ -79,37 +80,38 @@ XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperti
{ {
std::map<std::string, std::string>::const_iterator center = std::map<std::string, std::string>::const_iterator center =
itemProperties.find("Center"); itemProperties.find("Center");
if(center != itemProperties.end()) { if(center == itemProperties.end()) {
const std::string centerVal = center->second; XdmfError::message(XdmfError::FATAL,
if(centerVal.compare("Grid") == 0) { "'Center' not found in itemProperties in "
return Grid(); "XdmfAttributeCenter::New");
}
const std::string & centerVal = center->second;
if(centerVal.compare("Node") == 0) {
return Node();
} }
else if(centerVal.compare("Cell") == 0) { else if(centerVal.compare("Cell") == 0) {
return Cell(); return Cell();
} }
else if(centerVal.compare("Grid") == 0) {
return Grid();
}
else if(centerVal.compare("Face") == 0) { else if(centerVal.compare("Face") == 0) {
return Face(); return Face();
} }
else if(centerVal.compare("Edge") == 0) { else if(centerVal.compare("Edge") == 0) {
return Edge(); return Edge();
} }
else if(centerVal.compare("Node") == 0) {
return Node();
}
else {
XdmfError::message(XdmfError::FATAL, XdmfError::message(XdmfError::FATAL,
"Center not of 'Grid','Cell','Face','Edge','Node' " "Center not of 'Grid','Cell','Face','Edge','Node' "
"in XdmfAttributeCenter::New"); "in XdmfAttributeCenter::New");
}
}
XdmfError::message(XdmfError::FATAL,
"'Center' not found in itemProperties in "
"XdmfAttributeCenter::New");
return shared_ptr<const XdmfAttributeCenter>(); return shared_ptr<const XdmfAttributeCenter>();
} }
void void
XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const XdmfAttributeCenter::getProperties(std::map<std::string, std::string> & collectedProperties) const
{ {
collectedProperties["Center"] = mName; collectedProperties.insert(std::make_pair("Center", mName));
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include <utility>
#include "XdmfAttributeType.hpp" #include "XdmfAttributeType.hpp"
#include "XdmfError.hpp" #include "XdmfError.hpp"
...@@ -98,12 +99,14 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties ...@@ -98,12 +99,14 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties
if(type == itemProperties.end()) { if(type == itemProperties.end()) {
type = itemProperties.find("AttributeType"); type = itemProperties.find("AttributeType");
} }
if(type != itemProperties.end()) { if(type == itemProperties.end()) {
const std::string typeVal = type->second; XdmfError::message(XdmfError::FATAL,
if(typeVal.compare("None") == 0) { "Neither 'Type' nor 'AttributeType' found in "
return NoAttributeType(); "itemProperties in XdmfAttributeType::New");
} }
else if(typeVal.compare("Scalar") == 0) { const std::string & typeVal = type->second;
if(typeVal.compare("Scalar") == 0) {
return Scalar(); return Scalar();
} }
else if(typeVal.compare("Vector") == 0) { else if(typeVal.compare("Vector") == 0) {
...@@ -121,21 +124,20 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties ...@@ -121,21 +124,20 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties
else if(typeVal.compare("GlobalId") == 0) { else if(typeVal.compare("GlobalId") == 0) {
return GlobalId(); return GlobalId();
} }
else { else if(typeVal.compare("None") == 0) {
return NoAttributeType();
}
XdmfError::message(XdmfError::FATAL, XdmfError::message(XdmfError::FATAL,
"Type not of 'None','Scalar','Vector','Tensor', " "Type not of 'None','Scalar','Vector','Tensor', "
"'Matrix','Tensor6', or 'GlobalId' in " "'Matrix','Tensor6', or 'GlobalId' in "
"XdmfAttributeType::New"); "XdmfAttributeType::New");
}
}
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'AttributeType' found in "
"itemProperties in XdmfAttributeType::New");
return shared_ptr<const XdmfAttributeType>(); return shared_ptr<const XdmfAttributeType>();
} }
void void
XdmfAttributeType::getProperties(std::map<std::string, std::string> & collectedProperties) const 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() ...@@ -244,7 +244,7 @@ XdmfCurvilinearGrid::getGeometry()
void void
XdmfCurvilinearGrid::populateItem(const std::map<std::string, std::string> & itemProperties, 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) const XdmfCoreReader * const reader)
{ {
XdmfGrid::populateItem(itemProperties, childItems, reader); XdmfGrid::populateItem(itemProperties, childItems, reader);
......
...@@ -131,7 +131,7 @@ protected: ...@@ -131,7 +131,7 @@ protected:
void void
populateItem(const std::map<std::string, std::string> & itemProperties, 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); const XdmfCoreReader * const reader);
private: private:
......
...@@ -81,7 +81,7 @@ XdmfDomain::getItemTag() const ...@@ -81,7 +81,7 @@ XdmfDomain::getItemTag() const
void void
XdmfDomain::populateItem(const std::map<std::string, std::string> & itemProperties, 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) const XdmfCoreReader * const reader)
{ {
XdmfItem::populateItem(itemProperties, childItems, reader); XdmfItem::populateItem(itemProperties, childItems, reader);
......
...@@ -76,7 +76,7 @@ protected: ...@@ -76,7 +76,7 @@ protected:
XdmfDomain(); XdmfDomain();
virtual void virtual void
populateItem(const std::map<std::string, std::string> & itemProperties, 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); const XdmfCoreReader * const reader);
private: private:
......
...@@ -73,7 +73,7 @@ XdmfGeometry::getType() const ...@@ -73,7 +73,7 @@ XdmfGeometry::getType() const
void void
XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProperties, 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) const XdmfCoreReader * const reader)
{ {
XdmfItem::populateItem(itemProperties, childItems, reader); XdmfItem::populateItem(itemProperties, childItems, reader);
...@@ -84,8 +84,8 @@ XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProper ...@@ -84,8 +84,8 @@ XdmfGeometry::populateItem(const std::map<std::string, std::string> & itemProper
++iter) { ++iter) {
if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) { if(shared_ptr<XdmfArray> array = shared_dynamic_cast<XdmfArray>(*iter)) {
this->swap(array); this->swap(array);
break;
} }
// TODO: If multiple dataitems.
} }
} }
......
...@@ -84,7 +84,7 @@ protected: ...@@ -84,7 +84,7 @@ protected:
virtual void virtual void
populateItem(const std::map<std::string, std::string> & itemProperties, 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); const XdmfCoreReader * const reader);
private: private:
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include <utility>
#include "XdmfGeometryType.hpp" #include "XdmfGeometryType.hpp"
#include "XdmfError.hpp" #include "XdmfError.hpp"
...@@ -65,9 +66,13 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties) ...@@ -65,9 +66,13 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
if(type == itemProperties.end()) { if(type == itemProperties.end()) {
type = itemProperties.find("GeometryType"); 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) { if(typeVal.compare("None") == 0) {
return NoGeometryType(); return NoGeometryType();
} }
...@@ -77,14 +82,10 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties) ...@@ -77,14 +82,10 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
else if(typeVal.compare("XY") == 0) { else if(typeVal.compare("XY") == 0) {
return XY(); return XY();
} }
else {
XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' " XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' "
"in XdmfGeometryType::New"); "in XdmfGeometryType::New");
}
}
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'GeometryType' in itemProperties in "
"XdmfGeometryType::New");
return shared_ptr<const XdmfGeometryType>(); return shared_ptr<const XdmfGeometryType>();
} }
...@@ -103,5 +104,5 @@ XdmfGeometryType::getName() const ...@@ -103,5 +104,5 @@ XdmfGeometryType::getName() const
void void
XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const XdmfGeometryType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{ {
collectedProperties["Type"] = mName; collectedProperties.insert(std::make_pair("Type", mName));
} }
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp" #include "XdmfAttribute.hpp"
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp" #include "XdmfGrid.hpp"
...@@ -59,7 +60,7 @@ std::map<std::string, std::string> ...@@ -59,7 +60,7 @@ std::map<std::string, std::string>
XdmfGrid::getItemProperties() const XdmfGrid::getItemProperties() const
{ {
std::map<std::string, std::string> gridProperties; std::map<std::string, std::string> gridProperties;
gridProperties["Name"] = mName; gridProperties.insert(std::make_pair("Name", mName));
return gridProperties; return gridProperties;
} }
...@@ -96,7 +97,7 @@ XdmfGrid::getTopology() const ...@@ -96,7 +97,7 @@ XdmfGrid::getTopology() const
void void
XdmfGrid::populateItem(const std::map<std::string, std::string> & itemProperties, 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) const XdmfCoreReader * const reader)
{ {
XdmfItem::populateItem(itemProperties, childItems, reader); XdmfItem::populateItem(itemProperties, childItems, reader);
......
...@@ -130,7 +130,7 @@ protected: ...@@ -130,7 +130,7 @@ protected:
virtual void virtual void
populateItem(const std::map<std::string, std::string> & itemProperties, 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); const XdmfCoreReader * const reader);
shared_ptr<XdmfGeometry> mGeometry; shared_ptr<XdmfGeometry> mGeometry;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include <utility>
#include "XdmfGeometry.hpp" #include "XdmfGeometry.hpp"
#include "XdmfTopology.hpp" #include "XdmfTopology.hpp"
#include "XdmfGridCollection.hpp" #include "XdmfGridCollection.hpp"
...@@ -51,7 +52,7 @@ XdmfGridCollection::getItemProperties() const ...@@ -51,7 +52,7 @@ XdmfGridCollection::getItemProperties() const
{ {
std::map<std::string, std::string> collectionProperties = std::map<std::string, std::string> collectionProperties =
XdmfGrid::getItemProperties(); XdmfGrid::getItemProperties();
collectionProperties["GridType"] = "Collection"; collectionProperties.insert(std::make_pair("GridType", "Collection"));
mType->getProperties(collectionProperties); mType->getProperties(collectionProperties);
return collectionProperties; return collectionProperties;
} }
...@@ -76,7 +77,7 @@ XdmfGridCollection::insert(const shared_ptr<XdmfInformation> information) ...@@ -76,7 +77,7 @@ XdmfGridCollection::insert(const shared_ptr<XdmfInformation> information)
void void
XdmfGridCollection::populateItem(const std::map<std::string, std::string> & itemProperties, 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) const XdmfCoreReader * const reader)
{ {
mType = XdmfGridCollectionType::New(itemProperties); mType = XdmfGridCollectionType::New(itemProperties);
......
...@@ -97,7 +97,7 @@ protected: ...@@ -97,7 +97,7 @@ protected:
virtual void virtual void
populateItem(const std::map<std::string, std::string> & itemProperties, 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); const XdmfCoreReader * const reader);
private: private:
......
...@@ -21,8 +21,9 @@ ...@@ -21,8 +21,9 @@
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#include "XdmfGridCollectionType.hpp" #include <utility>
#include "XdmfError.hpp" #include "XdmfError.hpp"
#include "XdmfGridCollectionType.hpp"
// Supported XdmfGridCollectionTypes // Supported XdmfGridCollectionTypes
shared_ptr<const XdmfGridCollectionType> shared_ptr<const XdmfGridCollectionType>
...@@ -63,8 +64,13 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope ...@@ -63,8 +64,13 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope
{ {
std::map<std::string, std::string>::const_iterator type = std::map<std::string, std::string>::const_iterator type =
itemProperties.find("CollectionType"); itemProperties.find("CollectionType");
if(type != itemProperties.end()) { if(type == itemProperties.end()) {
const std::string typeVal = type->second; XdmfError::message(XdmfError::FATAL,
"'CollectionType' not in itemProperties in "
"XdmfGridCollectionType::New");
}
const std::string & typeVal = type->second;
if(typeVal.compare("None") == 0) { if(typeVal.compare("None") == 0) {
return NoCollectionType(); return NoCollectionType();
} }
...@@ -74,20 +80,16 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope ...@@ -74,20 +80,16 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope
else if(typeVal.compare("Temporal") == 0) { else if(typeVal.compare("Temporal") == 0) {
return Temporal(); return Temporal();
} }
else {
XdmfError::message(XdmfError::FATAL, XdmfError::message(XdmfError::FATAL,
"'CollectionType' not of 'None', 'Spatial', or " "'CollectionType' not of 'None', 'Spatial', or "
"'Temporal' in XdmfGridCollectionType::New"); "'Temporal' in XdmfGridCollectionType::New");
}
}
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not in itemProperties in "
"XdmfGridCollectionType::New");
return shared_ptr<const XdmfGridCollectionType>(); return shared_ptr<const XdmfGridCollectionType>();
} }
void void
XdmfGridCollectionType::getProperties(std::map<std::string, std::string> & collectedProperties) const 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, ...@@ -80,13 +80,11 @@ XdmfItemFactory::createItem(const std::string & itemTag,
} }
if(type != itemProperties.end()) { if(type != itemProperties.end()) {
const std::string typeVal = type->second;