Skip to content

Commit

Permalink
Fix bug in writeData for ManagedRawFileWorkspace. Refs #5620
Browse files Browse the repository at this point in the history
The call up to ManagedWorkspace was clearing the changed flag
so that the blocks were not marked as changed in the
ManagedRawFileWorkspace. The test did not show this as it only wrote to
the workspace once which would have just used the block in the MRU.
  • Loading branch information
martyngigg committed Jul 16, 2012
1 parent dee7c44 commit cc3436f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ namespace Mantid
void ManagedRawFileWorkspace2D::writeDataBlock(DataObjects::ManagedDataBlock2D *toWrite) const
{
Poco::ScopedLock<Poco::FastMutex> mutex(m_mutex);
// ManagedWorkspace2D resets the hasChanges flag but we need to make sure we keep track of it here as well
const bool blockHasChanged = toWrite->hasChanges();
ManagedWorkspace2D::writeDataBlock(toWrite);
int blockIndex = static_cast<int>(toWrite->minIndex() / m_vectorsPerBlock);
m_changedBlock[blockIndex] = toWrite->hasChanges();
m_changedBlock[blockIndex] = blockHasChanged;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,23 @@ class ManagedRawFileWorkspace2DTest : public CxxTest::TestSuite
void testChanges()
{
ManagedRawFileWorkspace2D ws(file);

MantidVec& y0 = ws.dataY(0);
y0[100] = 1234.;

MantidVec& y1000 = ws.dataY(1000);
y1000[200] = 4321.;

TS_ASSERT_EQUALS( ws.dataY(0)[100], 1234. )
TS_ASSERT_EQUALS( ws.dataY(1000)[200], 4321. )
TS_ASSERT_EQUALS( ws.readY(0)[100], 1234. )
TS_ASSERT_EQUALS( ws.readY(1000)[200], 4321. )

// Need to ensure that the number of writes is greater than the MRUList size
// so that we check the read/write from the file
// There is no public API to find the size so this will have to do.
const size_t nhist = 400;
for(size_t i = 0; i < nhist; ++i)
{
MantidVec& y0 = ws.dataY(i);
y0[0] = 100.0;
}

// Check that we have actually changed it
for(size_t i = 0; i < nhist; ++i)
{
const MantidVec& y0 = ws.readY(i);
const std::string msg = "The first value at index " + boost::lexical_cast<std::string>(i) + " does not have the expected value.";
TSM_ASSERT_EQUALS(msg, y0[0], 100.0 );
}
}

// Test is taken from LoadRawTest
Expand Down

0 comments on commit cc3436f

Please sign in to comment.