Skip to content

Commit

Permalink
refs #6449 enabling new box interface (not finished)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 16, 2013
1 parent 405f9a3 commit de0fbdb
Show file tree
Hide file tree
Showing 22 changed files with 1,092 additions and 1,107 deletions.
49 changes: 40 additions & 9 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
#define IMD_NODE_H_

#include <vector>
#include <algorithm>
#include "MantidKernel/ThreadScheduler.h"
#include "MantidKernel/INode.h"
#include "MantidGeometry/MDGeometry/MDImplicitFunction.h"
#include "MantidAPI/BoxController.h"
#include "MantidAPI/CoordTransform.h"

namespace Mantid
{
namespace API
{

class IMDNode : public Kernel::INode
class IMDNode
{
public:
//---------------- ISAVABLE
virtual Kernel::ISaveable *const getISaveable(){return NULL;}
virtual Kernel::ISaveable *const getISaveable()const{return NULL;}

virtual void clearDataFromMemory()=0;
virtual size_t getFileID()const=0;
virtual Kernel::ISaveable *const getISaveable()=0;
virtual Kernel::ISaveable *const getISaveable()const=0;
//-------------------------------------------------------------
/// Get number of dimensions
virtual size_t getNumDims() const = 0;
Expand All @@ -34,15 +36,16 @@ class IMDNode : public Kernel::INode
virtual void unmask() = 0;

/// get box controller
virtual Mantid::API::BoxController *getBoxController() const=0;
virtual Mantid::API::BoxController *const getBoxController() const=0;
virtual Mantid::API::BoxController *const getBoxController() =0;

/** Set the box controller used.
* @param controller :: Mantid::API::BoxController *
*/
virtual void setBoxController(Mantid::API::BoxController *controller)=0;
//virtual void setBoxController(Mantid::API::BoxController *controller)=0;

// -------------------------------- Parents/Children-Related -------------------------------------------
/// Avoid rtti
/// Avoid rtti ?
virtual bool isBox()const=0;
/// Get the total # of unsplit MDBoxes contained.
virtual size_t getNumMDBoxes() const = 0;
Expand Down Expand Up @@ -151,10 +154,38 @@ class IMDNode : public Kernel::INode

virtual void transformDimensions(std::vector<double> & scaling, std::vector<double> & offset)=0;

// ----------------------------- Helper Methods --------------------------------------------------------
//-----------------------------------------------------------------------------------------------
/** Helper method for sorting MDBoxBasees by file position.
* MDGridBoxes return 0 for file position and so aren't sorted.
*
* @param a :: an MDBoxBase pointer
* @param b :: an MDBoxBase pointer
* @return
*/

static inline bool CompareFilePosition (const IMDNode * const a, const IMDNode * const b)
{

return (a->getFileID() < b->getFileID());
}

//-----------------------------------------------------------------------------------------------
/** Static method for sorting a list of MDBoxBase pointers by their file position,
* ascending. This should optimize the speed of loading a bit by
* reducing the amount of disk seeking.
*
* @param boxes :: ref to a vector of boxes. It will be sorted in-place.
*/
static void sortObjByFileID(std::vector<IMDNode *const> & boxes)
{
std::sort( boxes.begin(), boxes.end(), CompareFilePosition);
}

};



};

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ namespace Mantid
*/
#define TMDE_CLASS template <typename MDE, size_t nd>

#define UNDEF_SIZET std::numeric_limits<size_t>::max()
#define UNDEF_COORDT std::numeric_limits<coord_t>::quiet_NaN()

}

#endif //MANTID_GEOMETRY_MDTYPES_H_
1 change: 0 additions & 1 deletion Code/Mantid/Framework/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ set ( INC_FILES
inc/MantidKernel/FreeBlock.h
inc/MantidKernel/FunctionTask.h
inc/MantidKernel/Glob.h
inc/MantidKernel/INode.h
inc/MantidKernel/IPropertyManager.h
inc/MantidKernel/IPropertySettings.h
inc/MantidKernel/ISaveable.h
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/INode.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ namespace Mantid
class DLLExport INode
{
public:
virtual ISaveable *const getISaveable()=0;
virtual ISaveable *const getISaveable()const=0;

virtual ~INode(){};
};
}
Expand Down
28 changes: 13 additions & 15 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/ISaveable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MANTID_KERNEL_ISAVEABLE_H_

#include "MantidKernel/System.h"
#include <forward_list>
#include <list>
#include <vector>
#include <algorithm>
#include <boost/optional.hpp>
Expand Down Expand Up @@ -46,20 +46,20 @@ namespace Kernel
{
public:
ISaveable();
ISaveable(const size_t id);
//ISaveable(const ISaveable &other); --> no pointers, standard CC
virtual ~ISaveable(){};

//-----------------------------------------------------------------------------------------------
/** Returns the unique ID for this object/box */
size_t getFileId() const
{ return m_FileId; }
////-----------------------------------------------------------------------------------------------
///** Returns the unique ID for this object/box */
//size_t getFileId() const
//{ return m_FileId; }

/** Sets the unique ID for this object/box
* @param newId :: new ID value. */
virtual void setFileId(size_t newId)
{ m_FileId = newId; }
///** Sets the unique ID for this object/box
// * @param newId :: new ID value. */
//virtual void setFileId(size_t newId)
//{ m_FileId = newId; }

/** @return the position in the file where the data will be stored. This is used to optimize file writing. */
///** @return the position in the file where the data will be stored. This is used to optimize file writing. */
virtual uint64_t getFilePosition() const
{ return m_fileIndexStart; }
/**Return the number of units this block occipies on file */
Expand Down Expand Up @@ -92,14 +92,12 @@ namespace Kernel
virtual uint64_t getTotalDataSize() const=0;
/// the data size kept in memory
virtual size_t getDataMemorySize()const=0;

// ----------------------------- Helper Methods --------------------------------------------------------
static void sortObjByFileID(std::vector<INode *const> & boxes);

protected:
/** Unique, sequential ID of the object/box within the containing workspace.
This ID also relates to boxes order as the boxes with adjacent
ID should usually occupy adjacent places on HDD */
size_t m_FileId;
// size_t m_FileId;
/// Start point in the NXS file where the events are located
uint64_t m_fileIndexStart;
/// Number of events saved in the file, after the start index location
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/Saveable.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Kernel
{
public:
Saveable();
Saveable(const size_t id);
//Saveable(const size_t id);
Saveable(const Saveable & other);
virtual ~Saveable();

Expand Down
51 changes: 11 additions & 40 deletions Code/Mantid/Framework/Kernel/src/ISaveable.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MantidKernel/ISaveable.h"
#include "MantidKernel/System.h"
#include <limits>
#include "MantidKernel/INode.h"
//#include "MantidKernel/INode.h"

namespace Mantid
{
Expand All @@ -10,52 +10,23 @@ namespace Kernel

/** Constructor
*/
ISaveable::ISaveable()
: m_FileId(0),m_fileIndexStart(std::numeric_limits<uint64_t>::max() ),m_fileNumEvents(0),m_BufMemorySize(0)
ISaveable::ISaveable():
// m_FileId(0),
m_fileIndexStart(std::numeric_limits<uint64_t>::max() ),m_fileNumEvents(0),m_BufMemorySize(0)
{}

//----------------------------------------------------------------------------------------------
/** Copy constructor --> needed? for std containers.
*/
/*ISaveable::ISaveable(const ISaveable & other)
: m_FileId(other.m_FileId),m_fileIndexStart(other.m_fileIndexStart),m_fileNumEvents(other.m_fileNumEvents)
{ }*/
//ISaveable::ISaveable(const ISaveable & other):
////m_FileId(other.m_FileId),
// m_fileIndexStart(other.m_fileIndexStart),m_fileNumEvents(other.m_fileNumEvents)
//{ }

ISaveable::ISaveable(const size_t fileId)
: m_FileId(fileId),m_fileIndexStart(std::numeric_limits<uint64_t>::max() ),m_fileNumEvents(0),m_BufMemorySize(0)
{}


//-----------------------------------------------------------------------------------------------
/** Helper method for sorting MDBoxBasees by file position.
* MDGridBoxes return 0 for file position and so aren't sorted.
*
* @param a :: an MDBoxBase pointer
* @param b :: an MDBoxBase pointer
* @return
*/

inline bool CompareFilePosition (const INode * const a, const INode * const b)
{
const ISaveable *const as = a->getISaveable();
if(!as)return false;
const ISaveable *const bs = b->getISaveable();
if(!bs)return false;
//ISaveable::ISaveable(const size_t fileId):
// m_FileId(fileId),m_fileIndexStart(std::numeric_limits<uint64_t>::max() ),m_fileNumEvents(0),m_BufMemorySize(0)
//{}

return (as->getFileId() < bs->getFileId());
}

//-----------------------------------------------------------------------------------------------
/** Static method for sorting a list of MDBoxBase pointers by their file position,
* ascending. This should optimize the speed of loading a bit by
* reducing the amount of disk seeking.
*
* @param boxes :: ref to a vector of boxes. It will be sorted in-place.
*/
void ISaveable::sortObjByFileID(std::vector<INode *const> & boxes)
{
std::sort( boxes.begin(), boxes.end(), CompareFilePosition);
}

/** Method stores the position of the object in Disc buffer and returns the size of this object for disk buffer to store
* @param bufPosition -- the allocator which specifies the position of the object in the list of objects to write
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/Kernel/src/Saveable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ namespace Kernel
{
}

Saveable::Saveable(const size_t id)
/* Saveable::Saveable(const size_t id)
:ISaveable(id),
m_Busy(false),m_dataChanged(false),m_wasSaved(false),m_isLoaded(false)
{
}
}*/

//----------------------------------------------------------------------------------------------
/** Destructor
Expand Down
8 changes: 5 additions & 3 deletions Code/Mantid/Framework/Kernel/test/DiskBufferISaveableTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ using Mantid::Kernel::CPUTimer;
//====================================================================================
class ISaveableTester : public ISaveable
{
size_t id;
bool _isBusy;
public:
ISaveableTester(size_t id) : ISaveable(id),
ISaveableTester(size_t idIn) : ISaveable(),
id(idIn),
_isBusy(false)
{}
virtual ~ISaveableTester(){}

size_t getFileId()const{return id;}
// temporary functions
virtual bool isBusy()const{return _isBusy;}
virtual bool isDataChanged()const{return true;}
Expand All @@ -45,7 +47,7 @@ class ISaveableTester : public ISaveable
{
// Fake writing to a file
std::ostringstream out;
out << getFileId() <<",";
out << id <<",";
streamMutex.lock();
fakeFile += out.str();
streamMutex.unlock();
Expand Down
9 changes: 6 additions & 3 deletions Code/Mantid/Framework/Kernel/test/DiskBufferTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ using Mantid::Kernel::CPUTimer;
/** An ISaveable that fakes writing to a fixed-size file */
class SaveableTesterWithFile : public Saveable
{
size_t ID;
public:
SaveableTesterWithFile(size_t id, uint64_t pos, uint64_t size, char ch,bool wasSaved=true) : Saveable(id),
m_memory(size),m_ch(ch)
SaveableTesterWithFile(size_t id, uint64_t pos, uint64_t size, char ch,bool wasSaved=true) : Saveable(),
ID(id),m_memory(size),m_ch(ch)
{
// the object knows its place on file
this->setFilePosition(pos,size,wasSaved);
Expand Down Expand Up @@ -665,9 +666,11 @@ class DiskBufferTest : public CxxTest::TestSuite
/** An Saveable that will fake seeking to disk */
class SaveableTesterWithSeek : public Saveable
{
size_t ID;
size_t m_memory;
public:
SaveableTesterWithSeek(size_t id) : Saveable(id)
SaveableTesterWithSeek(size_t id) : Saveable(),
ID(id)
{
m_memory=1;
this->setFilePosition(10+id,this->m_memory);
Expand Down

0 comments on commit de0fbdb

Please sign in to comment.