Skip to content

Commit

Permalink
Re #7673. Added output properties...
Browse files Browse the repository at this point in the history
...for the number of spectra in groups and the number of groups.
  • Loading branch information
peterfpeterson committed Aug 7, 2013
1 parent 960975f commit 68950aa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Code/Mantid/Framework/Algorithms/src/CreateGroupingWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ namespace Algorithms

declareProperty(new WorkspaceProperty<GroupingWorkspace>("OutputWorkspace","",Direction::Output),
"An output GroupingWorkspace.");

std::string inputs("Specify Instrument");
setPropertyGroup("InputWorkspace", inputs);
setPropertyGroup("InstrumentName", inputs);
setPropertyGroup("InstrumentFilename", inputs);

std::string groupby("Specify Grouping");
setPropertyGroup("GroupNames", groupby);
setPropertyGroup("GroupDetectorsBy", groupby);

// output properties
declareProperty("NumberGroupedSpectraResult", EMPTY_INT(), "The number of spectra in groups", Direction::Output);
declareProperty("NumberGroupsResult", EMPTY_INT(), "The number of groups", Direction::Output);
}


Expand Down Expand Up @@ -344,20 +357,26 @@ namespace Algorithms
readGroupingFile(OldCalFilename, detIDtoGroup, prog);

g_log.information() << detIDtoGroup.size() << " entries in the detectorID-to-group map.\n";
setProperty("NumberGroupedSpectraResult", static_cast<int>(detIDtoGroup.size()));



if (!detIDtoGroup.empty())
if (detIDtoGroup.empty())
{
g_log.warning() << "Creating empty group workspace\n";
setProperty("NumberGroupsResult", static_cast<int>(0));
}
else
{
size_t numNotFound = 0;

// Make the groups, if any
std::map<detid_t, int>::const_iterator it_end = detIDtoGroup.end();
std::map<detid_t, int>::const_iterator it;
std::set<int> groupCount;
for (it = detIDtoGroup.begin(); it != it_end; ++it)
{
int detID = it->first;
int group = it->second;
groupCount.insert(group);
try
{
outWS->setValue(detID, double(group));
Expand All @@ -367,6 +386,7 @@ namespace Algorithms
numNotFound++;
}
}
setProperty("NumberGroupsResult", static_cast<int>(groupCount.size()));

if (numNotFound > 0)
g_log.warning() << numNotFound << " detector IDs (out of " << detIDtoGroup.size() << ") were not found in the instrument\n.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class CreateGroupingWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );
doTest(outWSName);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupedSpectraResult")), 0);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupsResult")), 0);
}


Expand All @@ -78,6 +80,8 @@ class CreateGroupingWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );
doTest(outWSName);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupedSpectraResult")), 0);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupsResult")), 0);
}


Expand All @@ -102,6 +106,8 @@ class CreateGroupingWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT(ws);
if (!ws) return;

TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupedSpectraResult")), 4096);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupsResult")), 4);
TS_ASSERT_EQUALS( ws->getNumberHistograms(), 51200);
TS_ASSERT_EQUALS( ws->blocksize(), 1);
for (int i = 1; i <= 4; ++i)
Expand Down Expand Up @@ -137,6 +143,9 @@ class CreateGroupingWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT(ws);
if (!ws) return;

TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupedSpectraResult")), 18750);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupsResult")), 4);

AnalysisDataService::Instance().remove(outWSName);
}

Expand Down Expand Up @@ -187,6 +196,8 @@ class CreateGroupingWorkspaceTestPerformance : public CxxTest::TestSuite
TS_ASSERT(ws);
if (!ws) return;

TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupedSpectraResult")), 0);
TS_ASSERT_EQUALS(static_cast<int>(alg.getProperty("NumberGroupsResult")), 0);
TS_ASSERT_EQUALS( ws->getNumberHistograms(), 65536 * 15);
TS_ASSERT_EQUALS( ws->blocksize(), 1);
// Check one entry in each group
Expand Down

0 comments on commit 68950aa

Please sign in to comment.