Mantid
Loading...
Searching...
No Matches
CopyDetectorMapping.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
13
14namespace Mantid::Algorithms {
15
16DECLARE_ALGORITHM(CopyDetectorMapping)
17
18using namespace Kernel;
19using namespace API;
20
22 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("WorkspaceToMatch", "", Direction::Input));
23
24 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("WorkspaceToRemap", "", Direction::InOut));
25
26 declareProperty(std::make_unique<PropertyWithValue<bool>>("IndexBySpectrumNumber", false, Direction::Input),
27 "Will use mapping indexed by spectrum number rather than the default of"
28 "Workspace Index (recommended when both workspaces have a vertical axis "
29 "in spectrum number).");
30}
31
33 MatrixWorkspace_const_sptr wsToMatch = getProperty("WorkspaceToMatch");
34 MatrixWorkspace_sptr wsToRemap = getProperty("WorkspaceToRemap");
35 bool indexBySpecNumber = getProperty("IndexBySpectrumNumber");
36
37 // Copy detector mapping
38 SpectrumDetectorMapping detMap(wsToMatch, indexBySpecNumber);
39 wsToRemap->updateSpectraUsing(detMap);
40
41 setProperty("WorkspaceToRemap", wsToRemap);
42}
43
44std::map<std::string, std::string> CopyDetectorMapping::validateInputs() {
45 std::map<std::string, std::string> issues;
46
47 MatrixWorkspace_sptr wsToMatch = getProperty("WorkspaceToMatch");
48 MatrixWorkspace_sptr wsToRemap = getProperty("WorkspaceToRemap");
49
50 // Check that the workspaces actually are MatrixWorkspaces
51 bool validWorkspaces = true;
52
53 if (wsToMatch == nullptr) {
54 issues["WorkspaceToMatch"] = "Must be a MatrixWorkspace";
55 validWorkspaces = false;
56 }
57
58 if (wsToRemap == nullptr) {
59 issues["WorkspaceToRemap"] = "Must be a MatrixWorkspace";
60 validWorkspaces = false;
61 }
62
63 // Check histohram counts match (assuming both are MatrixWorkspaces)
64 if (validWorkspaces && wsToMatch->getNumberHistograms() != wsToRemap->getNumberHistograms())
65 issues["WorkspaceToRemap"] = "Number of histograms must match WorkspaceToMatch";
66
67 return issues;
68}
69
70} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
A property class for workspaces.
void init() override
Initialisation code.
std::map< std::string, std::string > validateInputs() override
Input property validation.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The concrete, templated class for properties.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53