-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re #6809. Implemented ClearMaskFlag.
- Loading branch information
1 parent
d825dbd
commit 5edcbf0
Showing
4 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/ClearMaskFlag.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef MANTID_ALGORITHMS_CLEARMASKFLAG_H_ | ||
#define MANTID_ALGORITHMS_CLEARMASKFLAG_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
/** ClearMaskFlag : TODO: DESCRIPTION | ||
Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport ClearMaskFlag : public API::Algorithm | ||
{ | ||
public: | ||
ClearMaskFlag(); | ||
virtual ~ClearMaskFlag(); | ||
|
||
virtual const std::string name() const; | ||
virtual int version() const; | ||
virtual const std::string category() const; | ||
|
||
private: | ||
virtual void initDocs(); | ||
void init(); | ||
void exec(); | ||
|
||
|
||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_CLEARMASKFLAG_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*WIKI* | ||
This algorithm clears the mask flag/bit on all spectra of a workspace. It does not restore masked data. | ||
*WIKI*/ | ||
|
||
#include "MantidAlgorithms/ClearMaskFlag.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
using namespace API; | ||
using Kernel::Direction; | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(ClearMaskFlag) | ||
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
ClearMaskFlag::ClearMaskFlag() {} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
ClearMaskFlag::~ClearMaskFlag() {} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Algorithm's name for identification. @see Algorithm::name | ||
const std::string ClearMaskFlag::name() const { return "ClearMaskFlag";}; | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int ClearMaskFlag::version() const { return 1;}; | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string ClearMaskFlag::category() const { return "Utility";} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Sets documentation strings for this algorithm | ||
void ClearMaskFlag::initDocs() | ||
{ | ||
std::string summary("Delete the mask flag/bit on all spectra in a workspace."); | ||
this->setWikiSummary(summary); | ||
this->setOptionalMessage(summary); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void ClearMaskFlag::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<>("Workspace","",Direction::InOut), "Workspace to clear the mask flag of."); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void ClearMaskFlag::exec() | ||
{ | ||
MatrixWorkspace_sptr ws = getProperty("Workspace"); | ||
|
||
// Clear the mask flags | ||
Geometry::ParameterMap & pmap = ws->instrumentParameters(); | ||
pmap.clearParametersByName("masked"); | ||
} | ||
|
||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#ifndef MANTID_ALGORITHMS_CLEARMASKFLAGTEST_H_ | ||
#define MANTID_ALGORITHMS_CLEARMASKFLAGTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
#include "MantidAlgorithms/ClearMaskFlag.h" | ||
#include "MantidDataObjects/Workspace2D.h" | ||
#include "MantidGeometry/Instrument.h" | ||
#include "MantidGeometry/Instrument/Detector.h" | ||
#include "MantidTestHelpers/ComponentCreationHelper.h" | ||
|
||
using namespace Mantid::API; | ||
using namespace Mantid::DataObjects; | ||
using namespace Mantid::Geometry; | ||
using Mantid::Algorithms::ClearMaskFlag; | ||
using Mantid::MantidVecPtr; | ||
|
||
class ClearMaskFlagTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static ClearMaskFlagTest *createSuite() { return new ClearMaskFlagTest(); } | ||
static void destroySuite( ClearMaskFlagTest *suite ) { delete suite; } | ||
|
||
|
||
void test_Init() | ||
{ | ||
ClearMaskFlag alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
} | ||
|
||
void test_exec() | ||
{ | ||
// create a workspace | ||
const int numspec = 9; | ||
const int nummask = 5; | ||
Instrument_sptr instr = boost::dynamic_pointer_cast<Instrument>(ComponentCreationHelper::createTestInstrumentCylindrical(1, false)); | ||
Detector *d = new Detector("det",0,0); | ||
instr->markAsDetector(d); | ||
|
||
// create the workspace | ||
MatrixWorkspace_sptr space = WorkspaceFactory::Instance().create("Workspace2D",numspec,6,5); | ||
Workspace2D_sptr space2D = boost::dynamic_pointer_cast<Workspace2D>(space); | ||
MantidVecPtr x,vec; | ||
x.access().resize(6,10.0); | ||
vec.access().resize(5,1.0); | ||
for (int j = 0; j < numspec; ++j) | ||
{ | ||
space2D->setX(j,x); | ||
space2D->setData(j,vec,vec); | ||
space2D->getSpectrum(j)->setSpectrumNo(j); | ||
space2D->getSpectrum(j)->setDetectorID(j); | ||
} | ||
space->setInstrument(instr); | ||
space->generateSpectraMap(); | ||
|
||
// set the mask on a bunch of spectra | ||
Mantid::Geometry::ParameterMap& pmap = space->instrumentParameters(); | ||
for (int j = 0; j < nummask; ++j) | ||
{ | ||
pmap.addBool(instr->getDetector(j)->getComponentID(), "masked", true); | ||
} | ||
|
||
|
||
// register the workspace in the data service | ||
std::string wsName("ClearMaskFlagTest_WS"); | ||
AnalysisDataService::Instance().addOrReplace(wsName, space); | ||
|
||
// run the algorithm with nothing masked | ||
ClearMaskFlag alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Workspace", wsName) ); | ||
TS_ASSERT_THROWS_NOTHING( alg.execute(); ); | ||
TS_ASSERT( alg.isExecuted() ); | ||
|
||
// retrieve the workspace from data service. TODO: Change to your desired type | ||
Workspace2D_sptr ws; | ||
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<Workspace2D>(wsName) ); | ||
TS_ASSERT(ws); | ||
if (!ws) return; | ||
|
||
// check the results | ||
Instrument_const_sptr out_instr = ws->getInstrument(); | ||
for (int j = 0; j < numspec; ++j) | ||
{ | ||
TS_ASSERT(!out_instr->isDetectorMasked(j)); | ||
} | ||
|
||
// remove workspace from the data service. | ||
AnalysisDataService::Instance().remove(wsName); | ||
} | ||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_ALGORITHMS_CLEARMASKFLAGTEST_H_ */ |