Mantid
Loading...
Searching...
No Matches
CreateSampleShape.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//--------------------------------
12#include "MantidAPI/Sample.h"
17
18namespace Mantid::DataHandling {
19// Register the algorithm into the AlgorithmFactory
20DECLARE_ALGORITHM(CreateSampleShape)
21
22using namespace Mantid::DataHandling;
23using namespace Mantid::API;
24
30void CreateSampleShape::setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML) {
32 // Create the object
33 auto shape = sFactory.createShape(shapeXML);
34 // Check it's valid and attach it to the workspace sample but preserve any
35 // material
36 if (shape->hasValidShape()) {
37 const auto mat = expt.sample().getMaterial();
38 shape->setMaterial(mat);
39 expt.mutableSample().setShape(shape);
40 } else {
41 std::ostringstream msg;
42 msg << "Object has invalid shape.";
43 if (auto csgShape = dynamic_cast<Geometry::CSGObject *>(shape.get())) {
44 msg << " TopRule = " << csgShape->topRule() << ", number of surfaces = " << csgShape->getSurfacePtr().size()
45 << "\n";
46 }
47 throw std::runtime_error(msg.str());
48 }
49}
50
55 using namespace Mantid::Kernel;
56 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
57 "The workspace with which to associate the sample ");
58 declareProperty("ShapeXML", "", std::make_shared<MandatoryValidator<std::string>>(),
59 "The XML that describes the shape");
60}
61
66 // Get the input workspace
67 MatrixWorkspace_sptr workspace = getProperty("InputWorkspace");
69 // Done!
70 progress(1);
71}
72} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
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
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
This class is shared by a few Workspace types and holds information related to a particular experimen...
const Sample & sample() const
Sample accessors.
Sample & mutableSample()
Writable version of the sample object.
void setShape(const Geometry::IObject_sptr &shape)
Update the shape of the object.
Definition: Sample.cpp:116
const Kernel::Material & getMaterial() const
Return the material (convenience method)
Definition: Sample.cpp:127
A property class for workspaces.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm.
static void setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML)
Set the shape via an XML string on the given experiment.
Constructive Solid Geometry object.
Definition: CSGObject.h:51
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
Validator to check that a property is not left empty.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Input
An input workspace.
Definition: Property.h:53