Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of CopyDetectorMapping algorithm
Refs #11125
- Loading branch information
Showing
7 changed files
with
210 additions
and
5 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
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
69 changes: 69 additions & 0 deletions
69
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/CopyDetectorMapping.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,69 @@ | ||
#ifndef MANTID_ALGORITHMS_COPYDETECTORMAPPING_H_ | ||
#define MANTID_ALGORITHMS_COPYDETECTORMAPPING_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid { | ||
namespace Algorithms { | ||
|
||
/** | ||
Algorithm to copy spectra-detector mapping from one matrix workspace | ||
to another. | ||
@author Dan Nixon | ||
Copyright © 2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge | ||
National Laboratory & European Spallation Source | ||
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 CopyDetectorMapping : public API::Algorithm { | ||
public: | ||
/// (Empty) Constructor | ||
CopyDetectorMapping() : API::Algorithm() {} | ||
/// Virtual destructor | ||
virtual ~CopyDetectorMapping() {} | ||
/// Algorithm's name | ||
virtual const std::string name() const { return "CopyDetectorMapping"; } | ||
/// Summary of algorithms purpose | ||
virtual const std::string summary() const { | ||
return ""; | ||
} | ||
|
||
/// Algorithm's version | ||
virtual int version() const { return (1); } | ||
/// Algorithm's category for identification | ||
virtual const std::string category() const { | ||
return "DataHandling"; | ||
} | ||
|
||
private: | ||
/// Initialisation code | ||
void init(); | ||
/// Execution code | ||
void exec(); | ||
}; | ||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_ALGORITHMS_COPYDETECTORMAPPING_H_*/ |
40 changes: 40 additions & 0 deletions
40
Code/Mantid/Framework/Algorithms/src/CopyDetectorMapping.cpp
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,40 @@ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAlgorithms/CopyDetectorMapping.h" | ||
#include "MantidAPI/SpectrumDetectorMapping.h" | ||
|
||
namespace Mantid { | ||
namespace Algorithms { | ||
|
||
DECLARE_ALGORITHM(CopyDetectorMapping) | ||
|
||
using namespace Kernel; | ||
using namespace API; | ||
|
||
void CopyDetectorMapping::init() { | ||
declareProperty( | ||
new WorkspaceProperty<>("WorkspaceToMatch", "", Direction::Input)); | ||
|
||
declareProperty( | ||
new WorkspaceProperty<>("WorkspaceToRemap", "", Direction::InOut)); | ||
|
||
declareProperty( | ||
new PropertyWithValue<bool>("IndexBySpectrumNumber", false, Direction::Input), | ||
"Will use mapping indexed by spectrum number rather than the default of" | ||
"spectrum index (typically not recommended)."); | ||
} | ||
|
||
void CopyDetectorMapping::exec() { | ||
MatrixWorkspace_const_sptr wsToMatch = getProperty("WorkspaceToMatch"); | ||
MatrixWorkspace_sptr wsToRemap = getProperty("WorkspaceToRemap"); | ||
bool indexBySpecNumber = getProperty("IndexBySpectrumNumber"); | ||
|
||
SpectrumDetectorMapping detMap(wsToMatch.get(), indexBySpecNumber); | ||
wsToRemap->updateSpectraUsing(detMap); | ||
|
||
setProperty("WorkspaceToRemap", wsToRemap); | ||
} | ||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |
63 changes: 63 additions & 0 deletions
63
Code/Mantid/Framework/Algorithms/test/CopyDetectorMappingTest.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,63 @@ | ||
#ifndef COPYDETECTORMAPPINGTEST_H_ | ||
#define COPYDETECTORMAPPINGTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
#include "MantidAlgorithms/CopyDetectorMapping.h" | ||
#include "MantidTestHelpers/WorkspaceCreationHelper.h" | ||
|
||
using Mantid::MantidVec; | ||
|
||
class CopyDetectorMappingTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
void testInit() | ||
{ | ||
TS_ASSERT_THROWS_NOTHING( copyMapping.initialize() ) | ||
TS_ASSERT( copyMapping.isInitialized() ) | ||
} | ||
|
||
void testAdd() | ||
{ | ||
using namespace Mantid; | ||
using namespace Mantid::API; | ||
using namespace Mantid::Kernel; | ||
|
||
auto toMatch = WorkspaceCreationHelper::Create2DWorkspace(10, 10); | ||
|
||
// Set the detector map for a spectra in the to match workspace | ||
std::set<detid_t> detIDs; | ||
detIDs.insert(5); | ||
detIDs.insert(9); | ||
detIDs.insert(6); | ||
detIDs.insert(2); | ||
toMatch->getSpectrum(0)->setDetectorIDs(detIDs); | ||
|
||
// Add workspaces to ADS | ||
AnalysisDataService::Instance().add("to_match", toMatch); | ||
AnalysisDataService::Instance().add("to_remap", WorkspaceCreationHelper::Create2DWorkspace(10, 10)); | ||
|
||
// Run algorithm | ||
TS_ASSERT_THROWS_NOTHING( copyMapping.setPropertyValue("WorkspaceToMatch", "to_match") ); | ||
TS_ASSERT_THROWS_NOTHING( copyMapping.setPropertyValue("WorkspaceToRemap", "to_remap") ); | ||
|
||
TS_ASSERT_THROWS_NOTHING( copyMapping.execute() ); | ||
TS_ASSERT( copyMapping.isExecuted() ); | ||
|
||
// Check the detector map in the to remap workspace matches that of the to match workspace | ||
MatrixWorkspace_const_sptr result; | ||
TS_ASSERT_THROWS_NOTHING( result = boost::dynamic_pointer_cast<MatrixWorkspace> | ||
(AnalysisDataService::Instance().retrieve("to_remap")) ); | ||
std::set<detid_t> resultDetIDs = result->getSpectrum(0)->getDetectorIDs(); | ||
TS_ASSERT( detIDs == resultDetIDs ); | ||
|
||
// Clean up workspace | ||
AnalysisDataService::Instance().remove("to_match"); | ||
AnalysisDataService::Instance().remove("to_remap"); | ||
} | ||
|
||
private: | ||
Mantid::Algorithms::CopyDetectorMapping copyMapping; | ||
|
||
}; | ||
|
||
#endif /*COPYDETECTORMAPPINGTEST_H_*/ |