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.");
66 inst = inputW->getInstrument();
68 throw std::runtime_error(
"Could not get a valid instrument from the "
69 "MatrixWorkspace provided as input");
71 inst = inputP->getInstrument();
73 throw std::runtime_error(
"Could not get a valid instrument from the "
74 "PeaksWorkspace provided as input");
77 throw std::runtime_error(
"Could not get a valid instrument from the "
78 "workspace and it does not seem to be valid as "
79 "input (must be either MatrixWorkspace or "
82 const std::string ComponentName =
getProperty(
"ComponentName");
87 const bool relativePosition =
getProperty(
"RelativePosition");
92 comp = inst->getDetector(DetID);
93 if (comp ==
nullptr) {
94 std::ostringstream mess;
95 mess <<
"Detector with ID " << DetID <<
" was not found.";
97 throw std::runtime_error(mess.str());
99 }
else if (!ComponentName.empty()) {
100 comp = inst->getComponentByName(ComponentName);
101 if (comp ==
nullptr) {
102 std::ostringstream mess;
103 mess <<
"Component with name " << ComponentName <<
" was not found.";
105 throw std::runtime_error(mess.str());
108 g_log.
error(
"DetectorID or ComponentName must be given.");
109 throw std::invalid_argument(
"DetectorID or ComponentName must be given.");
112 auto &componentInfo = inputW ? inputW->mutableComponentInfo() : inputP->mutableComponentInfo();
113 auto compIndex = componentInfo.indexOf(comp->getComponentID());
117 g_log.
warning(
"Component is fixed within a structured bank, moving is not "
118 "possible, doing nothing.");
124 if (relativePosition)
127 const auto componentId = comp->getComponentID();
128 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.