Skip to content

Commit

Permalink
Refs #8250 fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Jan 14, 2014
2 parents 11d6558 + c89bd78 commit 101c7f5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 44 deletions.
59 changes: 48 additions & 11 deletions Code/Mantid/Framework/Algorithms/src/ExtractMaskToTable.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/*WIKI*
The masking from the InputWorkspace property is extracted by creating a new MatrixWorkspace with a single X bin where:
* 0 = masked;
* 1 = unmasked.
The spectra containing 0 are also marked as masked and the instrument link is preserved so that the instrument view functions correctly.
==== InputWorskpace ====
It can be either a MaskWorkspace, containing the masking information, or a Data workspace (EventWorkspace or Workspace2D), having
detectors masked.
==== Optional MaskTableWorkspace ====
If the optional input 'MaskTableWorkspace' is given, it must be a table workspace having the
same format as output TableWorkspace such that it contains 3 columns, XMin, XMax and DetectorIDsList.
The contents in this mask table workspace will be copied to output workspace.
If a detector is masked in this input 'MaskTableWorkspace', and it is also masked in input MaskWorkspace or data workspace,
the setup (Xmin and Xmax) in MaskTableWorkspace has higher priority, i.e., in the output mask table workspace,
the masked detector will be recorded in the row copied from input MaskTableWrokspace.
*WIKI*/

#include "MantidAlgorithms/ExtractMaskToTable.h"
Expand Down Expand Up @@ -56,11 +67,11 @@ namespace Algorithms
*/
void ExtractMaskToTable::init()
{
auto inwsprop = new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "Anonymous", Direction::Input);
declareProperty(inwsprop, "A workspace whose masking is to be extracted");
auto inwsprop = new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input);
declareProperty(inwsprop, "A workspace whose masking is to be extracted or a MaskWorkspace. ");

auto intblprop = new WorkspaceProperty<TableWorkspace>("MaskTableWorkspace", "", Direction::Input, PropertyMode::Optional);
declareProperty(intblprop, "A workspace containing the masked spectra as zeroes and ones. ");
declareProperty(intblprop, "A mask table workspace containing 3 columns: XMin, XMax and DetectorIDsList. ");

auto outwsprop = new WorkspaceProperty<TableWorkspace>("OutputWorkspace", "", Direction::Output);
declareProperty(outwsprop, "A comma separated list or array containing a list of masked detector ID's ");
Expand Down Expand Up @@ -108,7 +119,7 @@ namespace Algorithms
vector<detid_t> prevmaskeddetids;
if (m_inputTableWS)
{
g_log.notice("[To implement] Parse input table workspace.");
g_log.notice("Parse input masking table workspace.");
parseMaskTable(m_inputTableWS, prevmaskeddetids);
}
else
Expand Down Expand Up @@ -143,12 +154,37 @@ namespace Algorithms
//----------------------------------------------------------------------------------------------
/** Parse input TableWorkspace to get a list of detectors IDs of which detector are already masked
* @param masktablews :: TableWorkspace containing masking information
* @param maskeddetectorids :: List for holding masked detector IDs
* @param maskeddetectorids :: (output) vector of detector IDs that are masked
*/
void ExtractMaskToTable::parseMaskTable(DataObjects::TableWorkspace_sptr masktablews, std::vector<detid_t>& maskeddetectorids)
{
// Clear input
maskeddetectorids.clear();;
maskeddetectorids.clear();

// Check format of mask table workspace
if (masktablews->columnCount() != 3)
{
g_log.error("Mask table workspace must have more than 3 columns. First 3 must be Xmin, Xmax and Spectrum List.");
return;
}
else
{
vector<string> colnames = masktablews->getColumnNames();
vector<string> chkcolumans(3);
chkcolumans[0] = "XMin";
chkcolumans[1] = "XMax";
chkcolumans[2] = "DetectorIDsList";
for (int i = 0; i < 3; ++i)
{
if (colnames[i] != chkcolumans[i])
{
g_log.error() << "Mask table workspace " << masktablews->name() << "'s " << i << "-th column name is "
<< colnames[i] << ", while it should be " << chkcolumans[i] << ". MaskWorkspace is invalid"
<< " and thus not used.\n";
return;
}
}
}

// Parse each row
size_t numrows = masktablews->rowCount();
Expand Down Expand Up @@ -319,7 +355,8 @@ namespace Algorithms
}

//----------------------------------------------------------------------------------------------
/** Add a list of spectra (detector IDs) to the output table workspace
/** Add a list of spectra (detector IDs) to the output table workspace.
* If a detector is masked in input MaskTableWorkspace, then it will not be added to a new row
* @param outws :: table workspace to write
* @param maskeddetids :: vector of detector IDs of which detectors masked
* @param xmin :: minumim x
Expand Down
46 changes: 13 additions & 33 deletions Code/Mantid/Framework/Algorithms/test/ExtractMaskToTableTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
static ExtractMaskToTableTest *createSuite() { return new ExtractMaskToTableTest(); }
static void destroySuite( ExtractMaskToTableTest *suite ) { delete suite; }

/** Test a method
//----------------------------------------------------------------------------------------------
/** Test method 'subtractVector'
*/
void test_method()
{
Expand All @@ -40,7 +41,7 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
vector<int> vecA;
vector<int> vecB;

// All B's items are in A
// Case: A constains B
for (size_t i = 0; i < 20; ++i)
{
vecA.push_back(static_cast<int>(i)+5);
Expand All @@ -52,13 +53,10 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
}

vector<int> vecC = alg.subtractVector(vecA, vecB);
for (size_t i = 0;i < vecC.size(); ++i)
cout << "Item " << i << "\t = \t" << vecC[i] << ".\n";
cout << "\n";

TS_ASSERT_EQUALS(vecC.size(), vecA.size()-vecB.size());

// Not all B's item are in A
// Case: A does not contain B; but the intersection between A and B is not empty
vecA.clear();
vecB.clear();

Expand All @@ -70,13 +68,9 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite

vecC = alg.subtractVector(vecA, vecB);

for (size_t i = 0;i < vecC.size(); ++i)
cout << "Item " << i << "\t = \t" << vecC[i] << ".\n";
cout << "\n";

TS_ASSERT_EQUALS(vecC.size(), 7);

// B has a large range than A
// Case: B has a larger range than A
vecA.clear();
vecB.clear();

Expand All @@ -91,14 +85,13 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
vecB.push_back(30);

vecC = alg.subtractVector(vecA, vecB);
for (size_t i = 0;i < vecC.size(); ++i)
cout << "Item " << i << "\t = \t" << vecC[i] << ".\n";
cout << "\n";

TS_ASSERT_EQUALS(vecC.size(), 5);

return;
}

//----------------------------------------------------------------------------------------------
/** Test initialization of the algorithm
*/
void test_Init()
Expand All @@ -108,6 +101,7 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
TS_ASSERT(alg.isInitialized());
}

//----------------------------------------------------------------------------------------------
/** Test for writing a new line to a new table workspace
*/
void test_writeToNewTable()
Expand All @@ -130,27 +124,13 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite

AnalysisDataService::Instance().addOrReplace("TestWorkspace1", inputws);

/*
for (size_t i = 0; i < inputws->getNumberHistograms(); ++i)
{
IDetector_const_sptr det = inputws->getDetector(i);
cout << "WorkspaceIndex = " << i << " X Size = " << inputws->readX(i).size()
<< "; Detector ID = " << det->getID() << ".\n";
}
Instrument_const_sptr instrument = inputws->getInstrument();
vector<detid_t> detids = instrument->getDetectorIDs();
cout << "Number of detectors = " << detids.size() << ".\n";
for (size_t i = 0; i < detids.size(); ++i)
cout << "Detector " << i << ": ID = " << detids[i] << ".\n";
*/

// Call algorithms
ExtractMaskToTable alg;
alg.initialize();

// Set up properties
alg.setProperty("InputWorkspace", "TestWorkspace1");
alg.setProperty("OutputWorkspace", "MaskTable1");
alg.setPropertyValue("InputWorkspace", "TestWorkspace1");
alg.setPropertyValue("OutputWorkspace", "MaskTable1");
alg.setProperty("XMin", 1234.0);
alg.setProperty("XMax", 12345.6);

Expand All @@ -173,7 +153,6 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
string specstr;
therow >> xxmin >> xxmax >> specstr;

cout << "XMin = " << xxmin << ", XMax = " << xxmax << ", Spec list = " << specstr << ".\n";
string expectedspec(" 1, 6-8, 11, 21, 31, 41");
TS_ASSERT_EQUALS(specstr, expectedspec);
TS_ASSERT_DELTA(xxmin, 1234.0, 0.0001);
Expand All @@ -186,6 +165,7 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite
return;
}

//----------------------------------------------------------------------------------------------
/** Test for appending a new line to an existing table workspace
*/
void test_appendToExistingTable()
Expand Down Expand Up @@ -250,15 +230,15 @@ class ExtractMaskToTableTest : public CxxTest::TestSuite

TableRow therow = outws->getRow(2);
therow >> xxmin >> xxmax >> specstr;
cout << "XMin = " << xxmin << ", XMax = " << xxmax << ", Spec list = " << specstr << ".\n";

string expectedspec(" 1, 6-8, 11, 21, 31, 41");
TS_ASSERT_EQUALS(specstr, expectedspec);
TS_ASSERT_DELTA(xxmin, 1234.0, 0.0001);
TS_ASSERT_DELTA(xxmax, 12345.6, 0.0001);

TableRow therow1 = outws->getRow(1);
therow1 >> xxmin >> xxmax >> specstr;
cout << "XMin = " << xxmin << ", XMax = " << xxmax << ", Spec list = " << specstr << ".\n";

string expectedspec2("43");
TS_ASSERT_DELTA(xxmin, 2345.1, 0.0001);
TS_ASSERT_DELTA(xxmax, 78910.5, 0.0001);
Expand Down

0 comments on commit 101c7f5

Please sign in to comment.