Skip to content

Commit

Permalink
refs #5052 Improved query outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Apr 3, 2012
1 parent 00ecddb commit 0559104
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
31 changes: 25 additions & 6 deletions Code/Mantid/Framework/MDEvents/src/QueryMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,28 @@ namespace MDEvents
/// Run the algorithm
void QueryMDWorkspace::exec()
{
IMDWorkspace_sptr input = getProperty("InputWorkspace");
// Define a table workspace with a specific column schema.
ITableWorkspace_sptr output = WorkspaceFactory::Instance().createTable();
output->addColumn("double", "Signal");
output->addColumn("double", "Error");
output->addColumn("int", "Number of Events");
output->addColumn("str", "Center");

IMDWorkspace_sptr input = getProperty("InputWorkspace");
const size_t ndims = input->getNumDims();
for(size_t index = 0; index < ndims; ++index)
{
Mantid::Geometry::IMDDimension_const_sptr dim = input->getDimension(index);
std::string dimInUnit = dim->getName()+"/"+dim->getUnits();
output->addColumn("double",dimInUnit);
//Magic numbers required to configure the X axis.
output->getColumn(dimInUnit)->setPlotType(1);
}

//Magic numbers required to configure the Y axis.
output->getColumn("Signal")->setPlotType(2);
output->getColumn("Error")->setPlotType(5);


IMDIterator* it = input->createIterator();

bool bLimitRows = getProperty("LimitRows");
Expand All @@ -172,12 +186,17 @@ namespace MDEvents
Progress progress(this, 0, 1, int64_t(input->getNPoints()));
while(true)
{
size_t cellIndex = 0;
output->appendRow();
output->cell<double>(rowCounter, 0) = it->getNormalizedSignal();
output->cell<double>(rowCounter, 1) = std::sqrt(it->getNormalizedError());
output->cell<int>(rowCounter, 2) = int(it->getNumEvents());
output->cell<double>(rowCounter, cellIndex++) = it->getNormalizedSignal();
output->cell<double>(rowCounter, cellIndex++) = std::sqrt(it->getNormalizedError());
output->cell<int>(rowCounter, cellIndex++) = int(it->getNumEvents());
VMD center = it->getCenter();
output->cell<std::string>(rowCounter, 3) = center.toString(",");
for(size_t index = 0; index < ndims; ++index)
{
output->cell<double>(rowCounter, cellIndex++) = center[index];
}

progress.report();
if(!it->next() || (bLimitRows && ((rowCounter+1) >= maxRows)))
{
Expand Down
25 changes: 23 additions & 2 deletions Code/Mantid/Framework/MDEvents/test/QueryMDWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,30 @@ class QueryMDWorkspaceTest : public CxxTest::TestSuite
ITableWorkspace_sptr table = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("QueryWS");

TSM_ASSERT("Workspace output is not an ITableWorkspace", table !=NULL);
TSM_ASSERT_EQUALS("Four columns expected", 4, table->columnCount());
size_t expectedCount = 3 + in_ws->getNumDims(); //3 fixed columns are Signal, Error, nEvents
TSM_ASSERT_EQUALS("Four columns expected", expectedCount, table->columnCount());
TSM_ASSERT_EQUALS("Wrong number of rows", 1000, table->rowCount());
}

void testNumberOfColumnsDependsOnDimensionality()
{
MDEventWorkspace2Lean::sptr in_ws = MDEventsTestHelper::makeMDEW<2>(10, -10.0, 20.0, 3);
QueryMDWorkspace query;
query.initialize();
query.setProperty("InputWorkspace", in_ws);
query.setPropertyValue("OutputWorkspace", "QueryWS");
query.execute();

TS_ASSERT(AnalysisDataService::Instance().doesExist("QueryWS"));

ITableWorkspace_sptr table = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("QueryWS");

TSM_ASSERT("Workspace output is not an ITableWorkspace", table !=NULL);
size_t expectedCount = 3 + in_ws->getNumDims(); //3 fixed columns are Signal, Error, nEvents
TSM_ASSERT_EQUALS("Five columns expected", expectedCount, table->columnCount());
}


void testLimitRows()
{
MDEventWorkspace3Lean::sptr in_ws = MDEventsTestHelper::makeMDEW<3>(10, -10.0, 20.0, 3);
Expand All @@ -95,7 +115,8 @@ class QueryMDWorkspaceTest : public CxxTest::TestSuite
ITableWorkspace_sptr table = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("QueryWS");

TSM_ASSERT("Workspace output is not an ITableWorkspace", table !=NULL);
TSM_ASSERT_EQUALS("Four columns expected", 4, table->columnCount());
size_t expectedCount = 3 + in_ws->getNumDims(); //3 fixed columns are Signal, Error, nEvents
TSM_ASSERT_EQUALS("Six columns expected", expectedCount, table->columnCount());
TSM_ASSERT_EQUALS("Wrong number of rows", 3, table->rowCount());
}

Expand Down

0 comments on commit 0559104

Please sign in to comment.