Skip to content

Commit

Permalink
refs #6449 LoadMD works fine in all modes.
Browse files Browse the repository at this point in the history
enabled its test and fixed (I believe unnoticed earlier) errors with file-backed operations.
  • Loading branch information
abuts committed Apr 16, 2013
1 parent 97e5561 commit bc05d6c
Show file tree
Hide file tree
Showing 35 changed files with 506 additions and 415 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/BoxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ namespace API
{
return m_numMDBoxes;
}


/** Return the vector giving the MAXIMUM number of MD Boxes as a function of depth */
const std::vector<double> & getMaxNumMDBoxes() const
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDEventWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ namespace API
/// Split all boxes that exceed the split threshold.
virtual void splitAllIfNeeded(Kernel::ThreadScheduler * ts) = 0;

// bool fileNeedsUpdating() const;
bool fileNeedsUpdating() const;

//void setFileNeedsUpdating(bool value);
void setFileNeedsUpdating(bool value);

virtual bool threadSafe() const;

virtual void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem) = 0;

protected:
/// Marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
//bool m_fileNeedsUpdating;
bool m_fileNeedsUpdating;

};

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IMDNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class IMDNode
/** 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 setFileBacked()=0;
/// if node was fileBacked, it should clear file-backed information
virtual void clearFileBacked()=0;
virtual void clearFileBacked(bool loadFileData)=0;

/**Save the box at specific disk position using the class, respoinsible for the file IO. */
virtual void saveAt(API::IBoxControllerIO *const /*saver */, uint64_t /*position*/)const=0;
Expand Down
36 changes: 18 additions & 18 deletions Code/Mantid/Framework/API/src/IMDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace API
//-----------------------------------------------------------------------------------------------
/** Empty constructor */
IMDEventWorkspace::IMDEventWorkspace()
: IMDWorkspace()
//m_fileNeedsUpdating(false)
: IMDWorkspace(),
m_fileNeedsUpdating(false)
{
}

Expand All @@ -27,22 +27,22 @@ namespace API
}


////-----------------------------------------------------------------------------------------------
///** @return the marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
// */
//bool IMDEventWorkspace::fileNeedsUpdating() const
//{
// return m_fileNeedsUpdating;
//}

////-----------------------------------------------------------------------------------------------
///** Sets the marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
// * @param value :: marker value
// */
//void IMDEventWorkspace::setFileNeedsUpdating(bool value)
//{
// m_fileNeedsUpdating = value;
//}
//-----------------------------------------------------------------------------------------------
/** @return the marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
*/
bool IMDEventWorkspace::fileNeedsUpdating() const
{
return m_fileNeedsUpdating;
}

//-----------------------------------------------------------------------------------------------
/** Sets the marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
* @param value :: marker value
*/
void IMDEventWorkspace::setFileNeedsUpdating(bool value)
{
m_fileNeedsUpdating = value;
}

//-----------------------------------------------------------------------------------------------
/** Is the workspace thread-safe. For MDEventWorkspaces, this means operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class CheckWorkspacesMatchTest : public CxxTest::TestSuite
MDEventWorkspace3Lean::sptr mdews1 = MDEventsTestHelper::makeAnyMDEW<MDLeanEvent<3>, 3>(2, 0.0, 10.0, 1000, "A");
MDEventWorkspace3Lean::sptr mdews2 = MDEventsTestHelper::makeAnyMDEW<MDLeanEvent<3>, 3>(2, 0.0, 10.0, 1000, "B");
MDBoxBase<MDLeanEvent<3>, 3> *parentBox = dynamic_cast<MDBoxBase<MDLeanEvent<3>, 3> *>(mdews2->getBox());
std::vector<MDBoxBase<MDLeanEvent<3>, 3> *> boxes;
std::vector<IMDNode *> boxes;
parentBox->getBoxes(boxes, 1000, true);
MDBox<MDLeanEvent<3>, 3> *box = dynamic_cast<MDBox<MDLeanEvent<3>, 3> *>(boxes[0]);
std::vector<MDLeanEvent<3> > &events = box->getEvents();
Expand All @@ -304,7 +304,7 @@ class CheckWorkspacesMatchTest : public CxxTest::TestSuite
MDEventWorkspace3Lean::sptr mdews1 = MDEventsTestHelper::makeAnyMDEW<MDLeanEvent<3>, 3>(2, 0.0, 10.0, 1000, "A");
MDEventWorkspace3Lean::sptr mdews2 = MDEventsTestHelper::makeAnyMDEW<MDLeanEvent<3>, 3>(2, 0.0, 10.0, 1000, "B");
MDBoxBase<MDLeanEvent<3>, 3> *parentBox = dynamic_cast<MDBoxBase<MDLeanEvent<3>, 3> *>(mdews2->getBox());
std::vector<MDBoxBase<MDLeanEvent<3>, 3> *> boxes;
std::vector<IMDNode *> boxes;
parentBox->getBoxes(boxes, 1000, true);
MDBox<MDLeanEvent<3>, 3> *box = dynamic_cast<MDBox<MDLeanEvent<3>, 3> *>(boxes[0]);
std::vector<MDLeanEvent<3> > &events = box->getEvents();
Expand Down
5 changes: 3 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,9 @@ namespace Kernel
void ISaveable::saveAt(uint64_t newPos, uint64_t newSize)
{
m_setter.lock();
// load old contents
this->load();
// load old contents if it was there
if(this->wasSaved())
this->load();
// set new position, derived by the disk buffer
m_fileIndexStart= newPos;
m_fileNumEvents = newSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace MDAlgorithms
if (!bc) throw std::runtime_error("Error with InputWorkspace: no BoxController!");
if (bc->isFileBacked())
{
//if (ws->fileNeedsUpdating())
if (ws->fileNeedsUpdating())
{
// Data was modified! You need to save first.
g_log.notice() << "InputWorkspace's file-backend being updated. " << std::endl;
Expand Down
19 changes: 18 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/DivideMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,19 @@ namespace MDAlgorithms
std::vector<API::IMDNode *> boxes;
parentBox->getBoxes(boxes, 1000, true);

bool fileBackedTarget(false);
Kernel::DiskBuffer *dbuff(NULL);
if(ws->isFileBacked())
{
fileBackedTarget = true;
dbuff = ws->getBoxController()->getFileIO();
}


for (size_t i=0; i<boxes.size(); i++)
{
MDBox<MDE,nd> * box = dynamic_cast<MDBox<MDE,nd> *>(boxes[i]);
size_t ic(0);
if (box)
{
typename std::vector<MDE> & events = box->getEvents();
Expand All @@ -123,14 +133,21 @@ namespace MDAlgorithms
float errorSquared = signal * signal * (it->getErrorSquared() / (oldSignal * oldSignal) + scalarRelativeErrorSquared);
it->setSignal(signal);
it->setErrorSquared(errorSquared);
ic++;
}

box->releaseEvents();
if(fileBackedTarget && ic>0)
{
Kernel::ISaveable *const pSaver(box->getISaveable());
dbuff->toWrite(pSaver);
}
}
}
// Recalculate the totals
ws->refreshCache();
// Mark file-backed workspace as dirty
//ws->setFileNeedsUpdating(true);
ws->setFileNeedsUpdating(true);
}


Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/FakeMDEventData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ namespace MDAlgorithms
CALL_MDEVENT_FUNCTION(this->addFakeUniformData, in_ws)

// Mark that events were added, so the file back end (if any) needs updating
//in_ws->setFileNeedsUpdating(true);
in_ws->setFileNeedsUpdating(true);
}

/**
Expand Down

0 comments on commit bc05d6c

Please sign in to comment.