Skip to content

Commit

Permalink
refs #6449 Enabled MDBoxBase test all except FileID (TODO)
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts authored and martyngigg committed Apr 10, 2013
1 parent fb7fcc8 commit de5b4f5
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 61 deletions.
24 changes: 6 additions & 18 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IMDNode
//---------------- ISAVABLE
virtual size_t getFileID()const=0;
virtual Kernel::ISaveable *const getISaveable()=0;
virtual Kernel::ISaveable *const getISaveable()const=0;
virtual Kernel::ISaveable *const getISaveable()const=0;
//-------------------------------------------------------------
/// Get number of dimensions
virtual size_t getNumDims() const = 0;
Expand All @@ -40,14 +40,7 @@ class IMDNode
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;

// -------------------------------- Parents/Children-Related -------------------------------------------
/// Avoid rtti ?
//virtual bool isBox()const=0;
// -------------------------------- Parents/Children-Related -------------------------------------------
/// Get the total # of unsplit MDBoxes contained.
virtual size_t getNumMDBoxes() const = 0;
/// Get the # of children MDBoxBase'es (non-recursive)
Expand Down Expand Up @@ -120,25 +113,20 @@ class IMDNode

/** Sphere (peak) integration */
virtual void integrateSphere(Mantid::API::CoordTransform & radiusTransform, const coord_t radiusSquared, signal_t & signal, signal_t & errorSquared) const = 0;

/** Find the centroid around a sphere */
virtual void centroidSphere(Mantid::API::CoordTransform & radiusTransform, const coord_t radiusSquared, coord_t * centroid, signal_t & signal) const = 0;

// box-related
/** Split sub-boxes, if this is possible and neede for this box */
virtual void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = NULL)=0;


/** Split sub-boxes, if this is possible and neede for this box */
virtual void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = NULL)=0;
/** Recalculate signal etc. */
virtual void refreshCache(Kernel::ThreadScheduler * /*ts*/ = NULL)=0;

// -------------------------------------------------------------------------------------------
/** Cache the centroid of this box and all sub-boxes. */
virtual void refreshCentroid(Kernel::ThreadScheduler * /*ts*/ = NULL)= 0;

virtual void calculateCentroid(coord_t * /*centroid*/) const=0;


// -------------------------------------------------------------------------------------------
// box-related
/// Fill a vector with all the boxes 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
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/ISaveable.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Kernel
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
// forward declaration
class INode;


class DLLExport ISaveable
{
Expand Down
10 changes: 3 additions & 7 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ namespace MDEvents


// ----------------------------- ISaveable Methods ------------------------------------------------------
virtual Kernel::ISaveable *const getISaveable(){return m_Saveable;}
virtual Kernel::ISaveable *const getISaveable()const{return m_Saveable;}


/** returns true if it is box (avoid rtti?) */
//virtual bool isBox()const{return true;}
virtual Kernel::ISaveable *const getISaveable();
virtual Kernel::ISaveable *const getISaveable()const;
//-----------------------------------------------------------------------------------------------
void clear();

Expand Down Expand Up @@ -164,7 +160,7 @@ namespace MDEvents

protected:
// the pointer to the class, responsible for saving/restoring this class to the hdd
mutable MDBoxSaveable * m_Saveable;
mutable MDBoxSaveable *m_Saveable;
/// Mutex for modifying the event list
Mantid::Kernel::Mutex dataMutex;

Expand Down
3 changes: 0 additions & 3 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDGridBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ namespace MDEvents
// ----------------------------- ISaveable Methods ------------------------------------------------------
virtual Kernel::ISaveable *const getISaveable(){return NULL;}
virtual Kernel::ISaveable *const getISaveable()const{return NULL;}

/** returns true if it is box (avoid rtti?) */
//virtual bool isBox()const{return false;}
//-------------------------------------------------------------------------------------------------------
void clear();

Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ namespace MDEvents

}

TMDE(
Kernel::ISaveable *const MDBox)::getISaveable()
{
return m_Saveable;
}
TMDE(
Kernel::ISaveable *const MDBox)::getISaveable()const
{
return m_Saveable;
}

//-----------------------------------------------------------------------------------------------
/** Clear the data[] vector ONLY but does not change the file-backed settings.
* Used to free up the memory in a file-backed workspace without removing the events from disk. */
Expand Down
57 changes: 35 additions & 22 deletions Code/Mantid/Framework/MDEvents/test/MDBoxBaseTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,39 @@ class MDBoxBaseTester : public MDBoxBase<MDE,nd>
MDBoxBaseTester()
: MDBoxBase<MDE,nd>()
{
this->setFilePosition(0,1,false);
//this->setFilePosition(0,1,false);
}
virtual ~MDBoxBaseTester(){}
MDBoxBaseTester(uint64_t filePos)
: MDBoxBase<MDE,nd>()
{
this->setId(filePos);
this->setFilePosition(filePos,10,false);
//this->setId(filePos);
// this->setFilePosition(filePos,10,false);
}

MDBoxBaseTester(const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t> > & extentsVector)
: MDBoxBase<MDE,nd>(extentsVector)
: MDBoxBase<MDE,nd>(NULL,0,0,extentsVector)
{
this->setFilePosition(0,10,false);
//this->setFilePosition(0,10,false);
}
Kernel::ISaveable *const getISaveable(){return NULL;}
Kernel::ISaveable *const getISaveable()const{return NULL;}

/// Clear all contained data
virtual void clear()
{}

virtual uint64_t getNPoints()const
{
return this->getFileSize();
return 0;
// return this->getFileSize();
}
virtual size_t getDataInMemorySize()const
{return 0;}
/// @return the amount of memory that the object takes up in the MRU.
virtual uint64_t getTotalDataSize() const
{return 0;}

/// Get number of dimensions
virtual size_t getNumDims() const
{return nd;}
Expand All @@ -65,7 +74,7 @@ class MDBoxBaseTester : public MDBoxBase<MDE,nd>
{ throw std::runtime_error("MDBox does not have children."); }

/// Sets the children from a vector of children
void setChildren(const std::vector<MDBoxBase<MDE,nd> *> & /*boxes*/, const size_t /*indexStart*/, const size_t /*indexEnd*/)
void setChildren(const std::vector<API::IMDNode *> & /*boxes*/, const size_t /*indexStart*/, const size_t /*indexEnd*/)
{ throw std::runtime_error("MDBox cannot have children."); }

/// Return a copy of contained events
Expand All @@ -83,19 +92,22 @@ class MDBoxBaseTester : public MDBoxBase<MDE,nd>
/// Add a single event
virtual void addEventUnsafe(const MDE & /*point*/)
{}

virtual size_t addEvents(const std::vector<signal_t> & /*sigErrSq*/,const std::vector<coord_t> & /*Coord*/,const std::vector<uint16_t> & /*runIndex*/,const std::vector<uint32_t> & /*detectorId*/)
{return 0;}
/** Perform centerpoint binning of events
* @param bin :: MDBin object giving the limits of events to accept.
*/
virtual void centerpointBin(MDBin<MDE,nd> & /*bin*/, bool * ) const
{}
virtual void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = NULL){};
virtual void refreshCache(Kernel::ThreadScheduler * /*ts*/ = NULL){};
virtual void refreshCentroid(Kernel::ThreadScheduler * /*ts*/ = NULL){};
virtual void calculateCentroid(coord_t * /*centroid*/) const{};

virtual void integrateSphere(Mantid::API::CoordTransform & /*radiusTransform*/, const coord_t /*radiusSquared*/, signal_t & /*signal*/, signal_t & /*errorSquared*/) const {};
virtual void centroidSphere(Mantid::API::CoordTransform & /*radiusTransform*/, const coord_t /*radiusSquared*/, coord_t *, signal_t & ) const {};
virtual void getBoxes(std::vector<MDBoxBase<MDE,nd> *>& /*boxes*/, size_t /*maxDepth*/, bool) {};
virtual void getBoxes(std::vector<MDBoxBase<MDE,nd> *>& /*boxes*/, size_t /*maxDepth*/, bool, Mantid::Geometry::MDImplicitFunction *) {};
virtual void getBoxes(std::vector<Kernel::ISaveable *>& /*boxes*/, size_t /*maxDepth*/, bool) {};
virtual void getBoxes(std::vector<Kernel::ISaveable *>& /*boxes*/, size_t /*maxDepth*/, bool, Mantid::Geometry::MDImplicitFunction *) {};
virtual void getBoxes(std::vector<API::IMDNode *>& /*boxes*/, size_t /*maxDepth*/, bool) {};
virtual void getBoxes(std::vector<API::IMDNode *>& /*boxes*/, size_t /*maxDepth*/, bool, Mantid::Geometry::MDImplicitFunction *) {};

virtual void generalBin(MDBin<MDE,nd> & /*bin*/, Mantid::Geometry::MDImplicitFunction & /*function*/) const {}

Expand Down Expand Up @@ -248,7 +260,7 @@ class MDBoxBaseTest : public CxxTest::TestSuite
b.setExtents(1, -4.0, 6.0);
b.setSignal(123.0);
b.setErrorSquared(456.0);
b.setId(8765);
//TODO: b.setId(8765);
b.calcVolume();

// Perform the copy
Expand All @@ -260,7 +272,7 @@ class MDBoxBaseTest : public CxxTest::TestSuite
TS_ASSERT_DELTA( box.getSignal(), b.getSignal(), 1e-6);
TS_ASSERT_DELTA( box.getErrorSquared(), b.getErrorSquared(), 1e-6);
TS_ASSERT_DELTA( box.getInverseVolume(), b.getInverseVolume(), 1e-6);
TS_ASSERT_EQUALS( box.getId(), b.getId());
//TS_ASSERT_EQUALS( box.getId(), b.getId());
TS_ASSERT_EQUALS( box.getDepth(), b.getDepth());
}

Expand Down Expand Up @@ -402,20 +414,21 @@ class MDBoxBaseTest : public CxxTest::TestSuite

void test_sortBoxesByFilePos()
{
std::vector<Kernel::ISaveable *> boxes;
std::vector<API::IMDNode *> boxes;
// 10 to 1 in reverse order

for (uint64_t i=0; i<10; i++)
{
boxes.push_back(new MDBoxBaseTester<MDLeanEvent<1>,1>(10-i));
}
Kernel::ISaveable::sortObjByFilePos(boxes);
// After sorting, they are in the right order 1,2,3, etc.
for (uint64_t i=0; i<10; i++)
{
TS_ASSERT_EQUALS( boxes[i]->getFilePosition(), i+1);
delete boxes[i];
}
//TODO:
//Kernel::ISaveable::sortObjByFilePos(boxes);
//// After sorting, they are in the right order 1,2,3, etc.
//for (uint64_t i=0; i<10; i++)
//{
// TS_ASSERT_EQUALS( boxes[i]->getFilePosition(), i+1);
// delete boxes[i];
//}
}


Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/MDEvents/test/MDBoxToChangeTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void testSplitRootToGridbox()

void testSplitAMemberToGridbox()
{
MDBoxBase<MDEvent<2>,2>* aChildBox(NULL);
TS_ASSERT_THROWS_NOTHING(aChildBox = (dynamic_cast<MDGridBox<MDEvent<2>,2>*>(rootBox))->getChild(10));
API::IMDNode * aChildBox(NULL);
TS_ASSERT_THROWS_NOTHING(aChildBox = rootBox->getChild(10));

MDBoxToChange<MDEvent<2>,2> BoxToSplit(dynamic_cast<MDBox<MDEvent<2>,2>*>(aChildBox),10);

Expand Down Expand Up @@ -76,7 +76,7 @@ MDBox<MDEvent<2>,2> * makeMDBox2()
// Splits into 10 boxes
splitter->setSplitInto(10);
// Set the size
MDBox<MDEvent<2>,2> * out = new MDBox<MDEvent<2>,2>(splitter);
MDBox<MDEvent<2>,2> * out = new MDBox<MDEvent<2>,2>(splitter.get());
out->setExtents(0, 0.0, 10.0);
out->setExtents(1, 0.0, 10.0);
out->calcVolume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ namespace MDEventsTestHelper
//=====================================================================================

/** Generate an empty MDBox */
MDBox<MDLeanEvent<1>,1> * makeMDBox1(size_t splitInto=10);
MDBox<MDLeanEvent<1>,1> * makeMDBox1(size_t splitInto, API::BoxController *& splitter);

/** Generate an empty MDBox with 3 dimensions, split 10x5x2 */
MDBox<MDLeanEvent<3>,3> * makeMDBox3();
MDBox<MDLeanEvent<3>,3> * makeMDBox3(API::BoxController * & splitter);

/** Return a vector with this many MDEvents, spaced evenly from 0.5, 1.5, etc. */
std::vector<MDLeanEvent<1> > makeMDEvents1(size_t num);
Expand Down
13 changes: 8 additions & 5 deletions Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ namespace MDEventsTestHelper

//-------------------------------------------------------------------------------------
/** Generate an empty MDBox */
MDBox<MDLeanEvent<1>,1> * makeMDBox1(size_t splitInto)
MDBox<MDLeanEvent<1>,1> * makeMDBox1(size_t splitInto,API::BoxController *& splitter)
{
// Split at 5 events
BoxController_sptr splitter(new BoxController(1));
if(!splitter)
splitter=new BoxController(1);
// Split at 5 events
splitter->setSplitThreshold(5);
// Splits into 10 boxes
splitter->setSplitInto(splitInto);
Expand All @@ -164,10 +165,12 @@ namespace MDEventsTestHelper

//-------------------------------------------------------------------------------------
/** Generate an empty MDBox with 3 dimensions, split 10x5x2 */
MDBox<MDLeanEvent<3>,3> * makeMDBox3()
MDBox<MDLeanEvent<3>,3> * makeMDBox3(BoxController *& splitter)
{
// Split at 5 events
BoxController_sptr splitter(new BoxController(3));
if(!splitter)
splitter = new BoxController(3);

splitter->setSplitThreshold(5);
// Splits into 10x5x2 boxes
splitter->setSplitInto(10);
Expand Down

0 comments on commit de5b4f5

Please sign in to comment.