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
31void CreateSampleShape::setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML, bool addTypeTag) {
33 // Create the object
34 auto shape = sFactory.createShape(shapeXML, addTypeTag);
35 // Check it's valid and attach it to the workspace sample but preserve any
36 // material
37 if (shape->hasValidShape()) {
38 const auto mat = expt.sample().getMaterial();
39 shape->setMaterial(mat);
40 expt.mutableSample().setShape(shape);
41 } else {
42 std::ostringstream msg;
43 msg << "Object has invalid shape.";
44 if (auto csgShape = dynamic_cast<Geometry::CSGObject *>(shape.get())) {
45 msg << " TopRule = " << csgShape->topRule() << ", number of surfaces = " << csgShape->getSurfacePtr().size()
46 << "\n";
47 }
48 throw std::runtime_error(msg.str());
49 }
50}
51
56 using namespace Mantid::Kernel;
57 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
58 "The workspace with which to associate the sample ");
59 declareProperty("ShapeXML", "", std::make_shared<MandatoryValidator<std::string>>(),
60 "The XML that describes the shape");
61}
62
67 // Get the input workspace
68 MatrixWorkspace_sptr workspace = getProperty("InputWorkspace");
70 // Done!
71 progress(1);
72}
73} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
IPeaksWorkspace_sptr workspace
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
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:115
const Kernel::Material & getMaterial() const
Return the material (convenience method)
Definition Sample.cpp:126
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, bool addTypeTag=true)
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.
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