-
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.
New algorithm called HasUB formed from the generic parts of ClearUB. Tests added.
- Loading branch information
1 parent
f48a18a
commit fbeff8d
Showing
4 changed files
with
304 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
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,58 @@ | ||
#ifndef MANTID_CRYSTAL_HASUB_H_ | ||
#define MANTID_CRYSTAL_HASUB_H_ | ||
|
||
#include "MantidKernel/System.h" | ||
#include "MantidAPI/Algorithm.h" | ||
#include "MantidCrystal/ClearUB.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Crystal | ||
{ | ||
|
||
/** HasUB : Determine if a workspace has a UB matrix on any of it's samples. Returns True if one is found. Returns false if none can be found, or if the | ||
* workspace type is incompatible. | ||
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 HasUB : public ClearUB | ||
{ | ||
public: | ||
HasUB(); | ||
virtual ~HasUB(); | ||
|
||
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 Crystal | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CRYSTAL_HASUB_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,77 @@ | ||
/*WIKI* | ||
Determine if a workspace has a UB matrix on any of it's samples. Returns True if one is found. Returns false if none can be found, or if the | ||
workspace type is incompatible. | ||
*WIKI*/ | ||
|
||
#include "MantidCrystal/HasUB.h" | ||
|
||
using namespace Mantid::API; | ||
using namespace Mantid::Kernel; | ||
|
||
namespace Mantid | ||
{ | ||
namespace Crystal | ||
{ | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(HasUB) | ||
|
||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Constructor | ||
*/ | ||
HasUB::HasUB() | ||
{ | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Destructor | ||
*/ | ||
HasUB::~HasUB() | ||
{ | ||
} | ||
|
||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Algorithm's name for identification. @see Algorithm::name | ||
const std::string HasUB::name() const { return "HasUB";}; | ||
|
||
/// Algorithm's version for identification. @see Algorithm::version | ||
int HasUB::version() const { return 1;}; | ||
|
||
/// Algorithm's category for identification. @see Algorithm::category | ||
const std::string HasUB::category() const { return "crystal";} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Sets documentation strings for this algorithm | ||
void HasUB::initDocs() | ||
{ | ||
this->setWikiSummary("Determines whether the workspace has one or more UB Matrix."); | ||
this->setOptionalMessage("Determines whether the workspace has one or more UB Matrix"); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void HasUB::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<Workspace>("Workspace", "", Direction::Input), | ||
"Workspace to clear the UB from."); | ||
declareProperty(new PropertyWithValue<bool>("HasUB", "", Direction::Output), | ||
"Indicates action performed, or predicted to perform if DryRun."); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void HasUB::exec() | ||
{ | ||
Workspace_sptr ws = getProperty("Workspace"); | ||
bool hasUB = ClearUB::doExecute(ws.get(), true /*DryRun*/); | ||
setProperty("HasUB", hasUB); | ||
} | ||
|
||
|
||
} // namespace Crystal | ||
} // 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,166 @@ | ||
#ifndef MANTID_CRYSTAL_HASUBTEST_H_ | ||
#define MANTID_CRYSTAL_HASUBTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidCrystal/HasUB.h" | ||
#include "MantidAPI/MatrixWorkspace.h" | ||
#include "MantidGeometry/Crystal/OrientedLattice.h" | ||
#include "MantidTestHelpers/WorkspaceCreationHelper.h" | ||
#include "MantidTestHelpers/MDEventsTestHelper.h" | ||
#include "MantidDataObjects/TableWorkspace.h" | ||
|
||
using namespace Mantid::Crystal; | ||
using namespace Mantid::MDEvents; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Geometry; | ||
|
||
class HasUBTest: public CxxTest::TestSuite | ||
{ | ||
|
||
private: | ||
|
||
// Helper method to create a matrix workspace. | ||
std::string createMatrixWorkspace(const bool withOrientedLattice = true) | ||
{ | ||
auto ws = WorkspaceCreationHelper::Create2DWorkspace(1, 2); | ||
if (withOrientedLattice) | ||
{ | ||
OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); | ||
ws->mutableSample().setOrientedLattice(latt); | ||
} | ||
const std::string wsName = "TestWorkspace"; | ||
AnalysisDataService::Instance().addOrReplace(wsName, ws); | ||
|
||
return wsName; | ||
} | ||
|
||
// Helper method to create a MDHW | ||
std::string createMDHistoWorkspace(const int nExperimentInfosToAdd = 2) | ||
{ | ||
const std::string wsName = "TestWorkspace"; | ||
auto ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1, 10, 10, 1, wsName); | ||
ws->getExperimentInfo(0)->mutableSample().setOrientedLattice( | ||
new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90)); | ||
|
||
for (int i = 1; i < nExperimentInfosToAdd; ++i) | ||
{ | ||
ExperimentInfo_sptr experimentInfo = boost::make_shared<ExperimentInfo>(); | ||
ws->addExperimentInfo(experimentInfo); | ||
ws->getExperimentInfo(i)->mutableSample().setOrientedLattice( | ||
new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90)); | ||
} | ||
|
||
AnalysisDataService::Instance().addOrReplace(wsName, ws); | ||
return wsName; | ||
} | ||
|
||
// Execute the algorithm | ||
bool doExecute(const std::string& wsName) | ||
{ | ||
// Create and run the algorithm | ||
HasUB alg; | ||
alg.setRethrows(true); | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize()) | ||
TS_ASSERT( alg.isInitialized()) | ||
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Workspace", wsName)); | ||
alg.execute(); | ||
TS_ASSERT( alg.isExecuted()); | ||
|
||
return alg.getProperty("HasUB"); | ||
} | ||
|
||
// Execute the algorithm | ||
bool doExecuteMultiInfo(const std::string& wsName) | ||
{ | ||
// Create and run the algorithm | ||
HasUB alg; | ||
alg.setRethrows(true); | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize()) | ||
TS_ASSERT( alg.isInitialized()) | ||
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Workspace", wsName)); | ||
alg.execute(); | ||
TS_ASSERT( alg.isExecuted()); | ||
|
||
return alg.getProperty("HasUB"); | ||
} | ||
|
||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static HasUBTest *createSuite() | ||
{ | ||
return new HasUBTest(); | ||
} | ||
static void destroySuite(HasUBTest *suite) | ||
{ | ||
delete suite; | ||
} | ||
|
||
void test_Init() | ||
{ | ||
HasUB alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize()) | ||
TS_ASSERT( alg.isInitialized()) | ||
} | ||
|
||
void test_safely_continue_if_noOrientedLattice() | ||
{ | ||
// Name of the output workspace. | ||
const bool createOrientedLattice = false; | ||
const std::string wsName = createMatrixWorkspace(createOrientedLattice); | ||
auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName); | ||
TSM_ASSERT("No oriented lattice to begin with", !ws->sample().hasOrientedLattice()); | ||
|
||
bool hasUB; | ||
TSM_ASSERT_THROWS_NOTHING("Should safely handle this.", hasUB = doExecute(wsName)); | ||
TS_ASSERT(!hasUB); | ||
|
||
// Clean up. | ||
AnalysisDataService::Instance().remove(wsName); | ||
} | ||
|
||
void test_dry_run_with_intput_workspace_not_expeirmentinfo() | ||
{ | ||
using Mantid::DataObjects::TableWorkspace; | ||
Workspace_sptr inws = boost::make_shared<TableWorkspace>(); | ||
const std::string wsName = "tablews"; | ||
AnalysisDataService::Instance().addOrReplace(wsName, inws); | ||
|
||
bool hasUB; | ||
TSM_ASSERT_THROWS_NOTHING("Should safely handle this.", hasUB = doExecute(wsName)); | ||
TS_ASSERT(!hasUB); | ||
|
||
AnalysisDataService::Instance().remove(wsName); | ||
} | ||
|
||
void test_check_MatrixWorkspace() | ||
{ | ||
// Name of the output workspace. | ||
const std::string wsName = createMatrixWorkspace(); | ||
auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName); | ||
TSM_ASSERT("OrientedLattice should be present to begin with", ws->sample().hasOrientedLattice()); | ||
|
||
bool hasUB = doExecute(wsName); | ||
|
||
TSM_ASSERT("OutputFlag should indicate possible removal", hasUB); | ||
|
||
// Clean up. | ||
AnalysisDataService::Instance().remove(wsName); | ||
} | ||
|
||
void test_check_OrientedLatticeMDHW() | ||
{ | ||
// Name of the output workspace. | ||
const std::string wsName = createMDHistoWorkspace(); | ||
|
||
bool hasUB = doExecuteMultiInfo(wsName); | ||
|
||
TSM_ASSERT("OutputFlag should indicate potential removal", hasUB); | ||
// Clean up. | ||
AnalysisDataService::Instance().remove(wsName); | ||
} | ||
|
||
}; | ||
|
||
#endif /* MANTID_CRYSTAL_HASUBTEST_H_ */ |