Skip to content

Commit

Permalink
refs #6449 Created MDBox Saveable and enabled some tests for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 5, 2013
1 parent ac457c1 commit 4cb721c
Show file tree
Hide file tree
Showing 27 changed files with 889 additions and 537 deletions.
30 changes: 10 additions & 20 deletions Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace API
* @return BoxController instance
*/
BoxController(size_t nd)
:nd(nd), m_maxId(0),m_SplitThreshold(1024), m_numSplit(1), m_diskBuffer()//, m_useWriteBuffer(true)
:nd(nd), m_maxId(0),m_SplitThreshold(1024), m_numSplit(1)
{
// TODO: Smarter ways to determine all of these values
m_maxDepth = 5;
Expand Down Expand Up @@ -347,18 +347,7 @@ namespace API
m_mutexNumMDBoxes.unlock();
}

//-----------------------------------------------------------------------------------
/** Return the DiskBuffer for disk caching */
const Mantid::Kernel::DiskBuffer & getDiskBuffer() const
{ return m_diskBuffer; }

/** Return the DiskBuffer for disk caching */
Mantid::Kernel::DiskBuffer & getDiskBuffer()
{ return m_diskBuffer; }

/** Return true if the DiskBuffer should be used -- in current edition it is always used*/
bool useWriteBuffer() const{return true;}
// { return m_useWriteBuffer; }
// { return m_useWriteBuffer; }
/// Returns if current box controller is file backed. Assumes that BC(workspace) is fileBackd if fileIO is defined;
bool isFileBacked()const
{return m_fileIO;}
Expand All @@ -375,15 +364,16 @@ namespace API
* @param bytesPerEvent :: sizeof(MDLeanEvent) that is in the workspace
* @param writeBufferSize :: number of EVENTS to accumulate before performing a disk write.
*/
void setCacheParameters(size_t bytesPerEvent,uint64_t writeBufferSize)
void setCacheParameters(uint64_t writeBufferSize)
{
if (bytesPerEvent == 0)
throw std::invalid_argument("Size of an event cannot be == 0.");
if(m_fileIO)
{
// Save the values
m_diskBuffer.setWriteBufferSize(writeBufferSize);
m_fileIO->setWriteBufferSize(writeBufferSize);
// If all caches are 0, don't use the MRU at all
// m_useWriteBuffer = !(writeBufferSize==0);
m_bytesPerEvent = bytesPerEvent;
// m_fileIO->m_bytesPerEvent = bytesPerEvent;
}
}

//BoxCtrlChangesInterface *getChangesList(){return m_ChangesList;}
Expand Down Expand Up @@ -473,13 +463,13 @@ namespace API
// the class which does actual IO operations
boost::shared_ptr<IBoxControllerIO> m_fileIO;
/// Instance of the disk-caching MRU list.
mutable Mantid::Kernel::DiskBuffer m_diskBuffer;
// mutable Mantid::Kernel::DiskBuffer m_diskBuffer;

/// Do we use the DiskBuffer at all? Always use WB
// bool m_useWriteBuffer;

/// Number of bytes in a single MDLeanEvent<> of the workspace.
size_t m_bytesPerEvent;
//size_t m_bytesPerEvent;
public:
};

Expand Down
34 changes: 24 additions & 10 deletions Code/Mantid/Framework/API/inc/MantidAPI/IBoxControllerIO.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#ifndef H_IBOXCONTROLLER_IO
#define H_IBOXCONTROLLER_IO
#include "MantidKernel/System.h"
#include "MantidKernel/DiskBuffer.h"

namespace Mantid
{
namespace API
{

/** The header describes interface to IO Operations perfomed by the box controller
* May be replaced by a boos filestream in a future.
* May be replaced by a boost filestream in a future.
* It also currently assumes disk buffer usage.
*
* @date March 21, 2013
Copyright &copy; 2007-2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand All @@ -33,20 +36,31 @@ namespace API
*/

class DLLExport IBoxControllerIO
class DLLExport IBoxControllerIO : public Kernel::DiskBuffer
{
public:
/** open file for i/o operations
* @param fileName -- the name of the file to open
* @param mode -- the string describing file access mode. if w or W is present in the string file is opened in read/write mode.
it is opened in read mode otherwise
* @return false if the file had been already opened. Throws if problems with openeing */
virtual bool openFile(const std::string &fileName,const std::string &mode)=0;
/**@return true if file is already opened */
virtual bool isOpened()const=0;
/**@return the full name of the used data file*/
virtual const std::string &getFileName()const=0;


virtual void saveBlock(const std::vector<float> & /* DataBlock */, const uint64_t /*blockPosition*/)=0;
virtual void saveBlock(const std::vector<double> & /* DataBlock */, const uint64_t /*blockPosition*/)=0;
virtual void loadBlock(std::vector<float> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)=0;
virtual void loadBlock(std::vector<double> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)=0;

virtual void flushData()=0;
/**Save a float data block in the specified file position */
virtual void saveBlock(const std::vector<float> & /* DataBlock */, const uint64_t /*blockPosition*/)const=0;
/**Save a double data block in the specified file position */
virtual void saveBlock(const std::vector<double> & /* DataBlock */, const uint64_t /*blockPosition*/)const=0;
/** load known size float data block from spefied file position */
virtual void loadBlock(std::vector<float> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)const=0;
virtual void loadBlock(std::vector<double> & /* Block */, const uint64_t /*blockPosition*/,const size_t /*BlockSize*/)const=0;

/** flush the IO buffers */
virtual void flushData()const=0;
/** Close the file */
virtual void closeFile()=0;

virtual ~IBoxControllerIO(){}
Expand All @@ -58,7 +72,7 @@ namespace API
* and the size of the data type in bytes (e.g. the class dependant physical meaning of the blockSize and blockPosition used
* by save/load operations */
virtual void setDataType(const size_t blockSize, const std::string &typeName) =0;
virtual void getDataType(size_t &blockSize, std::string &typeName) =0;
virtual void getDataType(size_t &blockSize, std::string &typeName)const =0;
};
}
}
Expand Down
64 changes: 46 additions & 18 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ namespace API

class IMDNode
{
/** This is an interface to MDBox or MDGridBox of an MDWorkspace
@date 01/03/2013
Copyright &copy; 2009-2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

public:
virtual ~IMDNode(){};
//---------------- ISAVABLE
Expand All @@ -26,25 +51,31 @@ class IMDNode
/**Return the pointer to the sconst tructure responsible for saving the box on disk if the workspace occupies too much memory */
virtual Kernel::ISaveable *const getISaveable()const=0;
/** initiate the structure responsible for swapping the box on HDD if out of memory. */
virtual void makeFileBacked(const uint64_t /*fileLocation*/,const size_t /*fileSize*/, const bool /*markSaved*/)=0;
virtual void setFileBacked(const uint64_t /*fileLocation*/,const size_t /*fileSize*/, const bool /*markSaved*/)=0;
/** initiate the structure responsible for swapping the box on HDD if out of memory with default parameters (it does not know its place on HDD and was not saved). */
virtual void makeFileBacked()=0;
/**Save the box at the position, specified by ISaveable. The IMDNode has to be file backed for this method to work */
virtual void save()=0;
/**Load the box from the location specified by ISaveable. The IMDNode has to be file backed for this method to work */
virtual void load()=0;
virtual void setFileBacked()=0;
/**Save the box at specific disk position using the class, respoinsible for the file IO. */
virtual void saveAt(API::IBoxControllerIO *const /* */, uint64_t /*position*/)=0;
/**Load the box data of specified size from the disk location provided using the class, respoinsible for the file IO. */
virtual void loadFrom(API::IBoxControllerIO *const /* */, uint64_t /*position*/, size_t /* Size */)=0;
virtual void saveAt(API::IBoxControllerIO *const /*saver */, uint64_t /*position*/)const=0;
/**Load the additional box data of specified size from the disk location provided using the class, respoinsible for the file IO and append them to the box */
virtual void loadAndAddFrom(API::IBoxControllerIO *const /*saver */, uint64_t /*position*/, size_t /* Size */)=0;
/// drop event data from memory but keep averages
virtual void clearDataFromMemory()=0;
//-------------------------------------------------------------
/// Clear all contained data including precalculated averages.
virtual void clear() = 0;

///@return the type of the event this box contains
virtual std::string getEventType()const =0;
///@return the length of the coordinates (in bytes), the events in the box contain.
virtual unsigned int getCoordType()const = 0;
//-------------------------------------------------------------
///@return The special ID which specify location of this node in the chain of ordered boxes (e.g. on a file)
virtual size_t getID()const=0;
/// sets the special id, which specify the position of this node in the chain linearly ordered nodes
virtual void setID(const size_t &newID)=0;

/// Get number of dimensions

/// Get number of dimensions, the box with this interface has
virtual size_t getNumDims() const = 0;

/// Getter for the masking
Expand Down Expand Up @@ -76,20 +107,19 @@ class IMDNode
virtual const IMDNode * getParent() const = 0;
// -------------------------------------------------------------------------------------------
// box-related
/// Fill a vector with all the boxes up to a certain depth
/// Fill a vector with all the boxes who are the childred of this one up to a certain depth
virtual void getBoxes(std::vector<IMDNode *> & boxes, size_t maxDepth, bool leafOnly) = 0;
/// Fill a vector with all the boxes up to a certain depth
/// Fill a vector with all the boxes who are the childred of this one up to a certain depth and selected by the function.
virtual void getBoxes(std::vector<IMDNode *> & boxes, size_t maxDepth, bool leafOnly, Mantid::Geometry::MDImplicitFunction * function) = 0;

// -------------------------------- Events-Related -------------------------------------------
/// Clear all contained data
virtual void clear() = 0;
/// Get total number of points both in memory and on file if present;
virtual uint64_t getNPoints() const = 0;
/// get size of the data located in memory, it is equivalent to getNPoints above for memory based workspace but may be different for file based one ;
virtual size_t getDataInMemorySize()const = 0;
/// @return the amount of memory that the object takes up in the MRU.
/// @return the amount of memory that the object takes up in the MRU.
virtual uint64_t getTotalDataSize() const=0;

/** The method to convert events in a box into a table of coodrinates/signal/errors casted into coord_t type
* Used to save events from plain binary file
* @returns coordTable -- vector of events parameters
Expand All @@ -114,7 +144,6 @@ class IMDNode


// -------------------------------------------------------------------------------------------

/** Perform centerpoint binning of events
* @param bin :: MDBin object giving the limits of events to accept.
* @param fullyContained :: optional bool array sized [nd] of which dimensions are known to be fully contained (for MDSplitBox)
Expand All @@ -137,7 +166,7 @@ class IMDNode
/** Calculate the centroid of this box and all sub-boxes. */
virtual void calculateCentroid(coord_t * /*centroid*/) const=0;
//----------------------------------------------------------------------------------------------------------------------------------
// MDBoxBase interface, related to average signals/box parameters
// MDBoxBase interface, related to average signals/error box parameters
virtual signal_t getSignal() const=0;
virtual signal_t getError() const=0;
virtual signal_t getErrorSquared() const=0;
Expand All @@ -150,7 +179,6 @@ class IMDNode


// -------------------------------- Geometry/vertexes-Related -------------------------------------------

virtual std::vector<Mantid::Kernel::VMD> getVertexes() const =0;
virtual coord_t * getVertexesArray(size_t & numVertices) const=0;
virtual coord_t * getVertexesArray(size_t & numVertices, const size_t outDimensions, const bool * maskDim) const=0;
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/API/src/BoxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace API
throw(Kernel::Exception::FileError("Can not open target file for filebased box controller ",fileName));
}

// kill old fileIO if any
if(this->m_fileIO) // should happen in destructor anyway but just to be carefull about it
this->m_fileIO->closeFile();

Expand All @@ -64,8 +65,7 @@ namespace API
m_addingEvents_numTasksPerBlock(other.m_addingEvents_numTasksPerBlock),
m_numMDBoxes(other.m_numMDBoxes),
m_numMDGridBoxes(other.m_numMDGridBoxes),
m_maxNumMDBoxes(other.m_maxNumMDBoxes),
m_bytesPerEvent(other.m_bytesPerEvent)
m_maxNumMDBoxes(other.m_maxNumMDBoxes)
{
}

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/DiskBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace Kernel

/** Set the length of the file that this MRU writes to.
* @param length :: length in the same units as the cache, etc. (not necessarily bytes) */
void setFileLength(const uint64_t length)
void setFileLength(const uint64_t length)const
{ m_fileLength = length; }

//-------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -167,7 +167,7 @@ namespace Kernel

// ----------------------- File object --------------------------------------
/// Length of the file. This is where new blocks that don't fit get placed.
uint64_t m_fileLength;
mutable uint64_t m_fileLength;

private:
/// Private Copy constructor: NO COPY ALLOWED
Expand Down
2 changes: 0 additions & 2 deletions Code/Mantid/Framework/Kernel/src/ISaveable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ namespace Kernel
void ISaveable::saveAt(uint64_t newPos, uint64_t newSize)
{

// load everything which is not in memory yet
this->load();
m_fileIndexStart= newPos;
m_fileNumEvents = newSize;
this->save();
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/SaveMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ namespace MDAlgorithms
// //Save box structure;
// BoxFlatStruct.saveBoxStructure(file);
//
// if (update || MakeFileBacked)
// if (update || setFileBacked)
// {
// // Need to keep the file open since it is still used as a back end.
// // Reopen the file
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set ( SRC_FILES
src/MDBoxIterator.cpp
src/MDBoxFlatTree.cpp
# src/MDBoxToChange.cpp
src/MDBoxNXSaveable.cpp
src/MDBoxSaveable.cpp
src/MDEventFactory.cpp
src/MDEventWSWrapper.cpp
src/MDEventWorkspace.cpp
Expand Down Expand Up @@ -94,7 +94,7 @@ set ( INC_FILES
inc/MantidMDEvents/MDBoxIterator.h
inc/MantidMDEvents/MDBoxFlatTree.h
# inc/MantidMDEvents/MDBoxToChange.h
inc/MantidMDEvents/MDBoxNXSaveable.h
inc/MantidMDEvents/MDBoxSaveable.h
inc/MantidMDEvents/MDDimensionStats.h
inc/MantidMDEvents/MDEvent.h
inc/MantidMDEvents/MDEventFactory.h
Expand Down Expand Up @@ -148,7 +148,7 @@ set ( TEST_FILES
MDBoxBaseTest.h
MDBoxIteratorTest.h
MDBoxTest.h
MDBoxNXSaveableTest.h
MDBoxSaveableTest.h
# MDBoxToChangeTest.h
MDDimensionStatsTest.h
MDEventFactoryTest.h
Expand Down

0 comments on commit 4cb721c

Please sign in to comment.