Skip to content

Commit

Permalink
Refs #5048: sortEvents inside LoadLiveData to help the GUI cope
Browse files Browse the repository at this point in the history
with PreserveEvents. This will slow down the adding but prevent the GUI from locking up.
  • Loading branch information
Janik Zikovsky committed Apr 3, 2012
1 parent d293ef6 commit 769af33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace DataHandling
void addChunk(Mantid::API::Workspace_sptr chunkWS);
void appendChunk(Mantid::API::Workspace_sptr chunkWS);

void doSortEvents(Mantid::API::Workspace_sptr ws);

/// The "accumulation" workspace = after adding, but before post-processing
Mantid::API::Workspace_sptr m_accumWS;
Expand Down
22 changes: 22 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/LoadLiveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ namespace DataHandling
m_accumWS = temp;
}

//----------------------------------------------------------------------------------------------
/** Perform SortEvents on the output workspaces (accumulation or output)
* but only if they are EventWorkspaces. This will help the GUI
* cope with redrawing.
*
* @param ws :: any Workspace. Does nothing if not EventWorkspace.
*/
void LoadLiveData::doSortEvents(Mantid::API::Workspace_sptr ws)
{
EventWorkspace_sptr eventWS = boost::dynamic_pointer_cast<EventWorkspace>(ws);
if (!eventWS)
return;
Algorithm_sptr alg = this->createSubAlgorithm("SortEvents");
alg->setProperty("InputWorkspace", eventWS);
alg->setPropertyValue("SortBy", "X Value");
alg->executeAsSubAlg();
}


//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
Expand Down Expand Up @@ -369,15 +387,19 @@ namespace DataHandling
// Set both output workspaces
this->setProperty("AccumulationWorkspace", m_accumWS);
this->setProperty("OutputWorkspace", m_outputWS);
doSortEvents(m_accumWS);
doSortEvents(m_outputWS);
}
else
{
// ----------- No post-processing -------------
m_outputWS = m_accumWS;
// We DO NOT set AccumulationWorkspace.
this->setProperty("OutputWorkspace", m_outputWS);
doSortEvents(m_outputWS);
}


}


Expand Down
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/DataHandling/test/LoadLiveDataTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class LoadLiveDataTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws2->getNumberEvents(), 200);
TSM_ASSERT( "Workspace changed when replaced", ws1 != ws2 );
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TSM_ASSERT( "Events are sorted", ws2->getEventList(0).isSortedByTof());
}

//--------------------------------------------------------------------------------------------
Expand All @@ -122,6 +123,7 @@ class LoadLiveDataTest : public CxxTest::TestSuite
ws2 = doExec<EventWorkspace>("Append");
TS_ASSERT_EQUALS(ws2->getNumberHistograms(), 4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TSM_ASSERT( "Events are sorted", ws2->getEventList(0).isSortedByTof());
}

//--------------------------------------------------------------------------------------------
Expand All @@ -140,6 +142,7 @@ class LoadLiveDataTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws2->getNumberEvents(), 400);

TSM_ASSERT( "Workspace being added stayed the same pointer", ws1 == ws2 );
TSM_ASSERT( "Events are sorted", ws2->getEventList(0).isSortedByTof());
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
}

Expand Down Expand Up @@ -248,6 +251,9 @@ class LoadLiveDataTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->blocksize(), 20);
TS_ASSERT_DELTA(ws->dataX(0)[0], 40e3, 1e-4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 2);

TSM_ASSERT( "Events are sorted", ws_accum->getEventList(0).isSortedByTof());
TSM_ASSERT( "Events are sorted", ws->getEventList(0).isSortedByTof());
}

//--------------------------------------------------------------------------------------------
Expand All @@ -272,6 +278,9 @@ class LoadLiveDataTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->blocksize(), 20);
TS_ASSERT_DELTA(ws->dataX(0)[0], 40e3, 1e-4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 2);

TSM_ASSERT( "Events are sorted", ws_accum->getEventList(0).isSortedByTof());
TSM_ASSERT( "Events are sorted", ws->getEventList(0).isSortedByTof());
}

//--------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 769af33

Please sign in to comment.