20using namespace Kernel;
21using namespace Geometry;
32 "The name of the workspace for which the new instrument "
33 "configuration will have an effect. Any other workspaces "
34 "stored in the analysis data service will be unaffected.");
36 "The name of the component to move. Component names are "
37 "defined in the instrument definition files. A pathname "
38 "delited by '/' may be used for non-unique name.");
40 "The ID of the detector to move. If both "
41 "the component name and the detector ID "
42 "are set the latter will be used.");
47 "The property defining how the (X,Y,Z) vector should be "
48 "interpreted. If true it is a vector relative to the initial "
49 "component's position. Otherwise it is a new position in the "
50 "absolute co-ordinates.");
52 "Whether to allow moving of individual detector pixels located within a structured bank. "
53 "If set to false then a request to move a detector pixel within a structured bank will be ignored. "
54 "The default value for this property is set to false to maintain backwards compatibility.");
70 inst = inputW->getInstrument();
72 throw std::runtime_error(
"Could not get a valid instrument from the "
73 "MatrixWorkspace provided as input");
75 inst = inputP->getInstrument();
77 throw std::runtime_error(
"Could not get a valid instrument from the "
78 "PeaksWorkspace provided as input");
81 throw std::runtime_error(
"Could not get a valid instrument from the "
82 "workspace and it does not seem to be valid as "
83 "input (must be either MatrixWorkspace or "
86 const std::string ComponentName =
getProperty(
"ComponentName");
91 const bool relativePosition =
getProperty(
"RelativePosition");
92 const bool moveFixedDetectors =
getProperty(
"MoveFixedDetectors");
97 comp = inst->getDetector(DetID);
98 if (comp ==
nullptr) {
99 std::ostringstream mess;
100 mess <<
"Detector with ID " << DetID <<
" was not found.";
102 throw std::runtime_error(mess.str());
104 }
else if (!ComponentName.empty()) {
105 comp = inst->getComponentByName(ComponentName);
106 if (comp ==
nullptr) {
107 std::ostringstream mess;
108 mess <<
"Component with name " << ComponentName <<
" was not found.";
110 throw std::runtime_error(mess.str());
113 g_log.
error(
"DetectorID or ComponentName must be given.");
114 throw std::invalid_argument(
"DetectorID or ComponentName must be given.");
117 auto &componentInfo = inputW ? inputW->mutableComponentInfo() : inputP->mutableComponentInfo();
118 auto compIndex = componentInfo.indexOf(comp->getComponentID());
122 g_log.
warning(
"Component is fixed within a structured bank, moving is not "
123 "possible, doing nothing.");
129 if (relativePosition)
132 const auto componentId = comp->getComponentID();
133 componentInfo.setPosition(componentInfo.indexOf(componentId),
position);
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
MoveInstrumentComponent()
Default constructor.
void exec() override
Overwrites Algorithm method.
void init() override
Overwrites Algorithm method.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
MANTID_GEOMETRY_DLL bool isDetectorFixedInBank(const ComponentInfo &compInfo, const size_t detIndex)
Tests whether or not the detector is within a fixed bank.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
@ InOut
Both an input & output workspace.