Commit bddb0698 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Add XdmfHeavyDataController base class and make XdmfArray use it. Add...

ENH: Add XdmfHeavyDataController base class and make XdmfArray use it.  Add XdmfHeavyDataWriter base class and make XdmfWriter use it.  This is in preparation to add additional heavy data formats.
parent b3b06601
#include "XdmfAttribute.hpp"
#include "XdmfGridCollection.hpp"
#include "XdmfGridCollectionType.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfHeavyDataController.hpp"
#include "XdmfMap.hpp"
/**
......@@ -12,9 +12,9 @@ class XdmfMap::XdmfMapImpl {
public:
XdmfMapImpl() :
mLocalNodeIdsHDF5Controller(boost::shared_ptr<XdmfHDF5Controller>()),
mRemoteLocalNodeIdsHDF5Controller(boost::shared_ptr<XdmfHDF5Controller>()),
mRemoteTaskIdsHDF5Controller(boost::shared_ptr<XdmfHDF5Controller>())
mLocalNodeIdsHeavyDataController(boost::shared_ptr<XdmfHeavyDataController>()),
mRemoteLocalNodeIdsHeavyDataController(boost::shared_ptr<XdmfHeavyDataController>()),
mRemoteTaskIdsHeavyDataController(boost::shared_ptr<XdmfHeavyDataController>())
{
};
......@@ -22,10 +22,10 @@ public:
{
};
boost::shared_ptr<XdmfHDF5Controller> mLocalNodeIdsHDF5Controller;
boost::shared_ptr<XdmfHeavyDataController> mLocalNodeIdsHeavyDataController;
std::map<unsigned int, std::map<unsigned int, unsigned int> > mMap; // localNodeId | remoteTaskId | remoteLocalNodeId
boost::shared_ptr<XdmfHDF5Controller> mRemoteLocalNodeIdsHDF5Controller;
boost::shared_ptr<XdmfHDF5Controller> mRemoteTaskIdsHDF5Controller;
boost::shared_ptr<XdmfHeavyDataController> mRemoteLocalNodeIdsHeavyDataController;
boost::shared_ptr<XdmfHeavyDataController> mRemoteTaskIdsHeavyDataController;
};
......@@ -182,23 +182,23 @@ void XdmfMap::populateItem(const std::map<std::string, std::string> & itemProper
}
else
{
mImpl->mLocalNodeIdsHDF5Controller = arrayVector[0]->getHDF5Controller();
mImpl->mRemoteTaskIdsHDF5Controller = arrayVector[1]->getHDF5Controller();
mImpl->mRemoteLocalNodeIdsHDF5Controller = arrayVector[2]->getHDF5Controller();
mImpl->mLocalNodeIdsHeavyDataController = arrayVector[0]->getHeavyDataController();
mImpl->mRemoteTaskIdsHeavyDataController = arrayVector[1]->getHeavyDataController();
mImpl->mRemoteLocalNodeIdsHeavyDataController = arrayVector[2]->getHeavyDataController();
}
}
void XdmfMap::read()
{
if(mImpl->mLocalNodeIdsHDF5Controller && mImpl->mRemoteTaskIdsHDF5Controller && mImpl->mRemoteLocalNodeIdsHDF5Controller)
if(mImpl->mLocalNodeIdsHeavyDataController && mImpl->mRemoteTaskIdsHeavyDataController && mImpl->mRemoteLocalNodeIdsHeavyDataController)
{
assert(mImpl->mLocalNodeIdsHDF5Controller->getSize() == mImpl->mRemoteTaskIdsHDF5Controller->getSize() && mImpl->mLocalNodeIdsHDF5Controller->getSize() == mImpl->mRemoteLocalNodeIdsHDF5Controller->getSize());
assert(mImpl->mLocalNodeIdsHeavyDataController->getSize() == mImpl->mRemoteTaskIdsHeavyDataController->getSize() && mImpl->mLocalNodeIdsHeavyDataController->getSize() == mImpl->mRemoteLocalNodeIdsHeavyDataController->getSize());
boost::shared_ptr<XdmfArray> globalNodeIds = XdmfArray::New();
boost::shared_ptr<XdmfArray> taskIds = XdmfArray::New();
boost::shared_ptr<XdmfArray> localNodeIds = XdmfArray::New();
mImpl->mLocalNodeIdsHDF5Controller->read(globalNodeIds.get());
mImpl->mRemoteTaskIdsHDF5Controller->read(taskIds.get());
mImpl->mRemoteLocalNodeIdsHDF5Controller->read(localNodeIds.get());
mImpl->mLocalNodeIdsHeavyDataController->read(globalNodeIds.get());
mImpl->mRemoteTaskIdsHeavyDataController->read(taskIds.get());
mImpl->mRemoteLocalNodeIdsHeavyDataController->read(localNodeIds.get());
for(unsigned int i=0; i<globalNodeIds->getSize(); ++i)
{
......@@ -222,12 +222,12 @@ void XdmfMap::release()
mImpl->mMap.clear();
}
void XdmfMap::setHDF5Controllers(boost::shared_ptr<XdmfHDF5Controller> localNodeIdsHDF5Controller, boost::shared_ptr<XdmfHDF5Controller> remoteTaskIdsHDF5Controller, boost::shared_ptr<XdmfHDF5Controller> remoteLocalNodeIdsHDF5Controller)
void XdmfMap::setHeavyDataControllers(boost::shared_ptr<XdmfHeavyDataController> localNodeIdsHeavyDataController, boost::shared_ptr<XdmfHeavyDataController> remoteTaskIdsHeavyDataController, boost::shared_ptr<XdmfHeavyDataController> remoteLocalNodeIdsHeavyDataController)
{
assert(localNodeIdsHDF5Controller->getSize() == remoteTaskIdsHDF5Controller->getSize() && localNodeIdsHDF5Controller->getSize() == remoteLocalNodeIdsHDF5Controller->getSize());
mImpl->mLocalNodeIdsHDF5Controller = localNodeIdsHDF5Controller;
mImpl->mRemoteTaskIdsHDF5Controller = remoteTaskIdsHDF5Controller;
mImpl->mRemoteLocalNodeIdsHDF5Controller = remoteLocalNodeIdsHDF5Controller;
assert(localNodeIdsHeavyDataController->getSize() == remoteTaskIdsHeavyDataController->getSize() && localNodeIdsHeavyDataController->getSize() == remoteLocalNodeIdsHeavyDataController->getSize());
mImpl->mLocalNodeIdsHeavyDataController = localNodeIdsHeavyDataController;
mImpl->mRemoteTaskIdsHeavyDataController = remoteTaskIdsHeavyDataController;
mImpl->mRemoteLocalNodeIdsHeavyDataController = remoteLocalNodeIdsHeavyDataController;
}
......@@ -246,13 +246,13 @@ void XdmfMap::traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor)
remoteLocalNodeIds->pushBack(iter2->second);
}
}
localNodeIds->setHDF5Controller(mImpl->mLocalNodeIdsHDF5Controller);
remoteTaskIds->setHDF5Controller(mImpl->mRemoteTaskIdsHDF5Controller);
remoteLocalNodeIds->setHDF5Controller(mImpl->mRemoteLocalNodeIdsHDF5Controller);
localNodeIds->setHeavyDataController(mImpl->mLocalNodeIdsHeavyDataController);
remoteTaskIds->setHeavyDataController(mImpl->mRemoteTaskIdsHeavyDataController);
remoteLocalNodeIds->setHeavyDataController(mImpl->mRemoteLocalNodeIdsHeavyDataController);
localNodeIds->accept(visitor);
remoteTaskIds->accept(visitor);
remoteLocalNodeIds->accept(visitor);
mImpl->mLocalNodeIdsHDF5Controller = localNodeIds->getHDF5Controller();
mImpl->mRemoteTaskIdsHDF5Controller = remoteTaskIds->getHDF5Controller();
mImpl->mRemoteLocalNodeIdsHDF5Controller = remoteLocalNodeIds->getHDF5Controller();
mImpl->mLocalNodeIdsHeavyDataController = localNodeIds->getHeavyDataController();
mImpl->mRemoteTaskIdsHeavyDataController = remoteTaskIds->getHeavyDataController();
mImpl->mRemoteLocalNodeIdsHeavyDataController = remoteLocalNodeIds->getHeavyDataController();
}
......@@ -70,11 +70,11 @@ public:
void read();
/**
* Release all data held in memory. The HDF5Controllers remain attached.
* Release all data held in memory. The heavy data remain attached.
*/
void release();
void setHDF5Controllers(boost::shared_ptr<XdmfHDF5Controller> localNodeIdsHDF5Controller, boost::shared_ptr<XdmfHDF5Controller> remoteTaskIdsHDF5Controller, boost::shared_ptr<XdmfHDF5Controller> remoteLocalNodeIdsHDF5Controller);
void setHeavyDataControllers(boost::shared_ptr<XdmfHeavyDataController> localNodeIdsHeavyDataController, boost::shared_ptr<XdmfHeavyDataController> remoteTaskIdsHeavyDataController, boost::shared_ptr<XdmfHeavyDataController> remoteLocalNodeIdsHeavyDataController);
void traverse(const boost::shared_ptr<XdmfBaseVisitor> visitor);
......
......@@ -30,6 +30,8 @@ set(XdmfCoreSources
XdmfCoreReader
XdmfHDF5Controller
XdmfHDF5Writer
XdmfHeavyDataController
XdmfHeavyDataWriter
XdmfInformation
XdmfItem
XdmfItemProperty
......
......@@ -10,6 +10,7 @@
#include "XdmfArray.hpp"
#include "XdmfArrayType.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfHeavyDataController.hpp"
#include "XdmfSystemUtils.hpp"
#include "XdmfVisitor.hpp"
......@@ -325,7 +326,7 @@ XdmfArray::XdmfArray() :
mArrayPointerNumValues(0),
mHaveArray(false),
mHaveArrayPointer(false),
mHDF5Controller(boost::shared_ptr<XdmfHDF5Controller>()),
mHeavyDataController(boost::shared_ptr<XdmfHeavyDataController>()),
mName(""),
mTmpReserveSize(0)
{
......@@ -364,9 +365,9 @@ boost::shared_ptr<const XdmfArrayType> XdmfArray::getArrayType() const
{
return boost::apply_visitor(GetArrayType(), mArrayPointer);
}
else if(mHDF5Controller)
else if(mHeavyDataController)
{
return mHDF5Controller->getType();
return mHeavyDataController->getType();
}
return XdmfArrayType::Uninitialized();
}
......@@ -392,22 +393,22 @@ int XdmfArray::getElementSize() const
return(aType->getElementSize());
}
boost::shared_ptr<XdmfHDF5Controller> XdmfArray::getHDF5Controller()
boost::shared_ptr<XdmfHeavyDataController> XdmfArray::getHeavyDataController()
{
return boost::const_pointer_cast<XdmfHDF5Controller>(static_cast<const XdmfArray &>(*this).getHDF5Controller());
return boost::const_pointer_cast<XdmfHeavyDataController>(static_cast<const XdmfArray &>(*this).getHeavyDataController());
}
boost::shared_ptr<const XdmfHDF5Controller> XdmfArray::getHDF5Controller() const
boost::shared_ptr<const XdmfHeavyDataController> XdmfArray::getHeavyDataController() const
{
return mHDF5Controller;
return mHeavyDataController;
}
std::map<std::string, std::string> XdmfArray::getItemProperties() const
{
std::map<std::string, std::string> arrayProperties;
if(mHDF5Controller)
if(mHeavyDataController)
{
arrayProperties["Format"] = "HDF";
arrayProperties["Format"] = mHeavyDataController->getName();
}
else
{
......@@ -445,9 +446,9 @@ unsigned int XdmfArray::getSize() const
{
return mArrayPointerNumValues;
}
else if(mHDF5Controller)
else if(mHeavyDataController)
{
return mHDF5Controller->getSize();
return mHeavyDataController->getSize();
}
return 0;
}
......@@ -613,7 +614,7 @@ void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProp
newHDF5Path << xmlDir->second << hdf5Path;
hdf5Path = newHDF5Path.str();
}
mHDF5Controller = XdmfHDF5Controller::New(hdf5Path, dataSetPath, sizeVal, arrayType);
mHeavyDataController = XdmfHDF5Controller::New(hdf5Path, dataSetPath, sizeVal, arrayType);
}
else
{
......@@ -654,9 +655,9 @@ void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProp
void XdmfArray::read()
{
if(mHDF5Controller)
if(mHeavyDataController)
{
mHDF5Controller->read(this);
mHeavyDataController->read(this);
}
}
......@@ -696,9 +697,9 @@ void XdmfArray::reserve(const unsigned int size)
}
}
void XdmfArray::setHDF5Controller(const boost::shared_ptr<XdmfHDF5Controller> hdf5Controller)
void XdmfArray::setHeavyDataController(const boost::shared_ptr<XdmfHeavyDataController> heavyDataController)
{
mHDF5Controller = hdf5Controller;
mHeavyDataController = heavyDataController;
}
void XdmfArray::setName(const std::string & name)
......@@ -713,19 +714,19 @@ void XdmfArray::swap(const boost::shared_ptr<XdmfArray> array)
int tmpArrayPointerNumValues = array->mArrayPointerNumValues;
bool tmpHaveArray = array->mHaveArray;
bool tmpHaveArrayPointer = array->mHaveArrayPointer;
boost::shared_ptr<XdmfHDF5Controller> tmpHDF5Controller = array->mHDF5Controller;
boost::shared_ptr<XdmfHeavyDataController> tmpHeavyDataController = array->mHeavyDataController;
array->mArray = mArray;
array->mArrayPointer = mArrayPointer;
array->mArrayPointerNumValues = mArrayPointerNumValues;
array->mHaveArray = mHaveArray;
array->mHaveArrayPointer = mHaveArrayPointer;
array->mHDF5Controller = mHDF5Controller;
array->mHeavyDataController = mHeavyDataController;
mArray = tmpArray;
mArrayPointer = tmpArrayPointer;
mArrayPointerNumValues = tmpArrayPointerNumValues;
mHaveArray = tmpHaveArray;
mHaveArrayPointer = tmpHaveArrayPointer;
mHDF5Controller = tmpHDF5Controller;
mHeavyDataController = tmpHeavyDataController;
}
......@@ -3,7 +3,7 @@
// Forward Declarations
class XdmfArrayType;
class XdmfHDF5Controller;
class XdmfHeavyDataController;
// Includes
#include "XdmfItem.hpp"
......@@ -102,18 +102,18 @@ public:
int getElementSize() const;
/**
* Get the hdf5 controller attached to this XdmfArray.
* Get the heavy data controller attached to this XdmfArray.
*
* @return the hdf5 controller attached to this XdmfArray.
* @return the heavy data controller attached to this XdmfArray.
*/
boost::shared_ptr<XdmfHDF5Controller> getHDF5Controller();
boost::shared_ptr<XdmfHeavyDataController> getHeavyDataController();
/**
* Get the hdf5 controller attached to this XdmfArray (const version).
* Get the heavy data controller attached to this XdmfArray (const version).
*
* @return the hdf5 controller attached to this XdmfArray.
* @return the heavy data controller attached to this XdmfArray.
*/
boost::shared_ptr<const XdmfHDF5Controller> getHDF5Controller() const;
boost::shared_ptr<const XdmfHeavyDataController> getHeavyDataController() const;
std::map<std::string, std::string> getItemProperties() const;
......@@ -276,7 +276,7 @@ public:
*
* @param hdf5Controller the hdf5 controller to attach to this XdmfArray.
*/
void setHDF5Controller(const boost::shared_ptr<XdmfHDF5Controller> hdf5Controller);
void setHeavyDataController(const boost::shared_ptr<XdmfHeavyDataController> hdf5Controller);
/**
* Set the name of the array.
......@@ -361,7 +361,6 @@ private:
class Erase;
class GetArrayType;
class GetCapacity;
class GetHDF5Type;
template <typename T>
class GetValues;
......@@ -432,7 +431,7 @@ private:
unsigned int mArrayPointerNumValues;
bool mHaveArray;
bool mHaveArrayPointer;
boost::shared_ptr<XdmfHDF5Controller> mHDF5Controller;
boost::shared_ptr<XdmfHeavyDataController> mHeavyDataController;
std::string mName;
unsigned int mTmpReserveSize;
std::string mDimensionString;
......
......@@ -15,10 +15,7 @@ boost::shared_ptr<XdmfHDF5Controller> XdmfHDF5Controller::New(const std::string
}
XdmfHDF5Controller::XdmfHDF5Controller(const std::string & hdf5FilePath, const std::string & dataSetPath, const unsigned int size, const boost::shared_ptr<const XdmfArrayType> type) :
mDataSetPath(dataSetPath),
mFilePath(XdmfSystemUtils::getRealPath(hdf5FilePath)),
mSize(size),
mType(type)
XdmfHeavyDataController(hdf5FilePath, dataSetPath, size, type)
{
}
......@@ -26,24 +23,9 @@ XdmfHDF5Controller::~XdmfHDF5Controller()
{
}
std::string XdmfHDF5Controller::getDataSetPath() const
std::string XdmfHDF5Controller::getName() const
{
return mDataSetPath;
}
std::string XdmfHDF5Controller::getFilePath() const
{
return mFilePath;
}
unsigned int XdmfHDF5Controller::getSize() const
{
return mSize;
}
boost::shared_ptr<const XdmfArrayType> XdmfHDF5Controller::getType() const
{
return mType;
return "HDF";
}
void XdmfHDF5Controller::read(XdmfArray * const array)
......
#ifndef XDMFHDF5CONTROLLER_HPP_
#define XDMFHDF5CONTROLLER_HPP_
// Forward Declarations
class XdmfArray;
class XdmfArrayType;
// Includes
#include <boost/shared_ptr.hpp>
#include "XdmfHeavyDataController.hpp"
/**
* @brief Couples an XdmfArray with HDF5 data stored on disk.
......@@ -15,7 +11,7 @@ class XdmfArrayType;
* written to disk an XdmfHDF5Controller is attached to XdmfArrays. This allows data to be released
* from memory but still be accessible or have its location written to light data.
*/
class XdmfHDF5Controller {
class XdmfHDF5Controller : public XdmfHeavyDataController {
public:
......@@ -26,39 +22,8 @@ public:
*/
static boost::shared_ptr<XdmfHDF5Controller> New(const std::string & hdf5FilePath, const std::string & dataSetPath, const unsigned int size, const boost::shared_ptr<const XdmfArrayType> type);
/**
* Get the path of the data set within the hdf5 file owned by this controller. For "/home/output.h5:/foo/data" this is "/foo/data"
*
* @return a std::string containing the path of the data set.
*/
std::string getDataSetPath() const;
/**
* Get the absolute path to the hdf5 file on disk where the data set owned by this controller resides. For "/home/output.h5:/foo/data" this is "/home/output.h5"
*
* @return a std::string containing the path to the hdf5 file.
*/
std::string getFilePath() const;
/**
* Get the size of the hdf5 data set owned by this controller.
*
* @return a int containing the size of the hdf5 data set.
*/
unsigned int getSize() const;
std::string getName() const;
/**
* Get the array type of the hdf5 data set owned by this controller.
*
* @return an XdmfArrayType containing the array type of the hdf5 data set.
*/
boost::shared_ptr<const XdmfArrayType> getType() const;
/**
* Read data owned by this controller on disk into the passed XdmfArray.
*
* @param array and XdmfArray to read data into.
*/
void read(XdmfArray * const array);
protected:
......@@ -70,10 +35,6 @@ private:
XdmfHDF5Controller(const XdmfHDF5Controller & hdf5Controller); // Not implemented.
void operator=(const XdmfHDF5Controller & hdf5Controller); // Not implemented.
std::string mDataSetPath;
std::string mFilePath;
unsigned int mSize;
boost::shared_ptr<const XdmfArrayType> mType;
};
#endif /* XDMFHDF5CONTROLLER_HPP_ */
......@@ -7,60 +7,20 @@
#include "XdmfArrayType.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfHDF5Writer.hpp"
#include "XdmfSystemUtils.hpp"
/**
* PIMPL
*/
class XdmfHDF5Writer::XdmfHDF5WriterImpl {
public:
XdmfHDF5WriterImpl(const std::string & hdf5FilePath) :
mDataSetId(0),
mFilePath(XdmfSystemUtils::getRealPath(hdf5FilePath)),
mMode(Default)
{
};
~XdmfHDF5WriterImpl()
{
};
int mDataSetId;
std::string mFilePath;
Mode mMode;
};
boost::shared_ptr<XdmfHDF5Writer> XdmfHDF5Writer::New(const std::string & hdf5FilePath)
boost::shared_ptr<XdmfHDF5Writer> XdmfHDF5Writer::New(const std::string & filePath)
{
boost::shared_ptr<XdmfHDF5Writer> p(new XdmfHDF5Writer(hdf5FilePath));
boost::shared_ptr<XdmfHDF5Writer> p(new XdmfHDF5Writer(filePath));
return p;
}
XdmfHDF5Writer::XdmfHDF5Writer(const std::string & hdf5FilePath) :
mImpl(new XdmfHDF5WriterImpl(hdf5FilePath))
XdmfHDF5Writer::XdmfHDF5Writer(const std::string & filePath) :
XdmfHeavyDataWriter(filePath)
{
}
XdmfHDF5Writer::~XdmfHDF5Writer()
{
delete mImpl;
}
std::string XdmfHDF5Writer::getFilePath() const
{
return mImpl->mFilePath;
}
XdmfHDF5Writer::Mode XdmfHDF5Writer::getMode() const
{
return mImpl->mMode;
}
void XdmfHDF5Writer::setMode(const Mode mode)
{
mImpl->mMode = mode;
}
void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisitor>)
......@@ -113,18 +73,18 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
if(datatype != -1)
{
std::string hdf5FilePath = mImpl->mFilePath;
std::string hdf5FilePath = mFilePath;
std::stringstream dataSetPath;
if((mImpl->mMode == Overwrite || mImpl->mMode == Append) && array.getHDF5Controller())
if((mMode == Overwrite || mMode == Append) && array.getHeavyDataController())
{
// Write to the previous dataset
dataSetPath << array.getHDF5Controller()->getDataSetPath();
hdf5FilePath = array.getHDF5Controller()->getFilePath();
dataSetPath << array.getHeavyDataController()->getDataSetPath();
hdf5FilePath = array.getHeavyDataController()->getFilePath();
}
else
{
dataSetPath << "Data" << mImpl->mDataSetId;
dataSetPath << "Data" << mDataSetId;
}
// Open a hdf5 dataset and write to it on disk.
......@@ -164,7 +124,7 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
else
{
// Need to resize dataset to fit new data
if(mImpl->mMode == Append)
if(mMode == Append)
{
// Get size of old dataset
dataspace = H5Dget_space(dataset);
......@@ -202,11 +162,11 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
H5Eset_auto2(0, old_func, old_client_data);
// Attach a new controller to the array if needed.
if(mImpl->mMode == Default || !array.getHDF5Controller())
if(mMode == Default || !array.getHeavyDataController())
{
boost::shared_ptr<XdmfHDF5Controller> newDataSetController = XdmfHDF5Controller::New(hdf5FilePath, dataSetPath.str(), array.getSize(), array.getArrayType());
array.setHDF5Controller(newDataSetController);
mImpl->mDataSetId++;
array.setHeavyDataController(newDataSetController);
mDataSetId++;
}
}
}
#ifndef XDMFHDF5WRITER_HPP_
#define XDMFHDF5WRITER_HPP_
// Forward Declarations
class XdmfArray;
// Includes
#include "XdmfVisitor.hpp"
#include "XdmfHeavyDataWriter.hpp"
/**
* @brief Traverse the Xdmf graph and write heavy data stored in XdmfArrays to HDF5 on disk.
......@@ -15,77 +12,34 @@ class XdmfArray;
* as the parameter. The writer will write all XdmfArrays under the XdmfItem to an hdf5 file on
* disk. It will also attach an XdmfHDF5Controller to all XdmfArrays that it writes to disk.
*
* There are three modes of operation for this writer:
* Default - All initialized XdmfArrays are written to new hdf5 datasets regardless of whether they
* are attached to another hdf5 dataset on disk via an XdmfHDF5Controller.
* Overwrite - If an initialized XdmfArray is attached to an hdf5 dataset via an XdmfHDF5Contoller the writer
* will write values to that location, overwriting all previous written values.
* Append - If an initialized XdmfArray is attached to an hdf5 dataset via an XdmfHDF5Controller the writer
* will append the values to the end of the dataset on disk.
* This writer supports all heavy data writing modes listed in XdmfHeavyDataWriter.
*/
class XdmfHDF5Writer : public XdmfVisitor,
public Loki::Visitor<XdmfArray> {
class XdmfHDF5Writer : public XdmfHeavyDataWriter {
public:
enum Mode {
Default, Overwrite, Append
};
/**
* Construct XdmfHDF5Writer
*
* @param hdf5FilePath the location of the hdf5 file to output to on disk.
* @param filePath the location of the hdf5 file to output to on disk.
* @return new XdmfHDF5Writer
*/
static boost::shared_ptr<XdmfHDF5Writer> New(const std::string & hdf5FilePath);
static boost::shared_ptr<XdmfHDF5Writer> New(const std::string & filePath);
virtual ~XdmfHDF5Writer();
/**
* Get the path to the hdf5 file on disk this writer is writing to.
*
* @return a std::string containing the path to the hdf5 file on disk this writer is writing to.
*/
std::string getFilePath() const;
/**
* Get the Mode of operation for this writer.
*
* @return the Mode of operation for this writer.
*/
Mode getMode() const;
/**
* Set the mode of operation for this writer.
*
* @param mode the Mode of operation for this writer.
*/
void setMode(const Mode mode);
/**
* Write an XdmfArray to HDF5.
*
* @param array an XdmfArray to write to HDF5.
* @param visitor a smart pointer to this visitor --- aids in grid traversal.
*/
void visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisitor> visitor);
protected:
XdmfHDF5Writer(const std::string & hdf5FilePath);
XdmfHDF5Writer(const std::string & filePath);
private:
/**
* PIMPL
*/
class XdmfHDF5WriterImpl;
XdmfHDF5Writer(const XdmfHDF5Writer & hdf5Writer); // Not implemented.
void operator=(const XdmfHDF5Writer & hdf5Writer); // Not implemented.
XdmfHDF5WriterImpl * const mImpl;
int mDataSetId;
};
#endif /* XDMFHDF5WRITER_HPP_ */
// Kenneth Leiter
// Xdmf Smart Pointer Test
#include "XdmfHeavyDataController.hpp"
#include "XdmfSystemUtils.hpp"
XdmfHeavyDataController::XdmfHeavyDataController(const std::string & heavyDataFilePath, const std::string & dataSetPath, const unsigned int size, const boost::shared_ptr<const XdmfArrayType> type) :
mDataSetPath(dataSetPath),
mFilePath(XdmfSystemUtils::getRealPath(heavyDataFilePath)),
mSize(size),
mType(type)
{
}
XdmfHeavyDataController::~XdmfHeavyDataController()
{
}
std::string XdmfHeavyDataController::getDataSetPath() const
{
return mDataSetPath;
}
std::string XdmfHeavyDataController::getFilePath() const
{
return mFilePath;
}
unsigned int XdmfHeavyDataController::getSize() const
{
return mSize;
}
boost::shared_ptr<const XdmfArrayType> XdmfHeavyDataController::getType() const
{
return mType;
}
#ifndef XDMFHEAVYDATACONTROLLER_HPP_
#define XDMFHEAVYDATACONTROLLER_HPP_
// Forward Declarations
class XdmfArray;
class XdmfArrayType;
// Includes
#include <boost/shared_ptr.hpp>
#include <string>
/**
* @brief Couples an XdmfArray with heavy data stored on disk.
* This is an abstract base class to support the reading of different heavy data formats.
*
* Serves as an interface between data stored in XdmfArrays and data stored on disk. When an Xdmf file is read from or
* written to disk an XdmfHeavyController is attached to XdmfArrays. This allows data to be released
* from memory but still be accessible or have its location written to light data.
*/
class XdmfHeavyDataController {
public:
virtual ~XdmfHeavyDataController();
/**
* Get the path of the data set within the heavy data file owned by this controller.
* For "/home/output.h5:/foo/data" this is "/foo/data"
*
* @return a std::string containing the path of the data set.
*/
std::string getDataSetPath() const;
/**
* Get the absolute path to the heavy data file on disk where the data set owned by this controller resides.
* For "/home/output.h5:/foo/data" this is "/home/output.h5"
*
* @return a std::string containing the path to the heavy data file.
*/
std::string getFilePath() const;
/**
* Get the name of this heavy data format. E.g. "HDF" for hdf5 format.
*
* @return std::string containing the name of this heavy data format
*/
virtual std::string getName() const = 0;
/**
* Get the size of the heavy data set owned by this controller.
*
* @return a int containing the size of the heavy data set.
*/
unsigned int getSize() const;
/**
* Get the array type of the heavy data set owned by this controller.
*
* @return an XdmfArrayType containing the array type of the heavy data set.
*/
boost::shared_ptr<const XdmfArrayType> getType() const;