Mantid
Loading...
Searching...
No Matches
DefineGaugeVolume.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 +
9#include "MantidAPI/Run.h"
13
14namespace Mantid::DataHandling {
15
16using namespace Mantid::API;
17
18// Register the algorithm into the AlgorithmFactory
20
21
24void DefineGaugeVolume::init() {
25 declareProperty(std::make_unique<WorkspaceProperty<>>("Workspace", "", Kernel::Direction::InOut),
26 "The workspace with which to associate the defined gauge volume");
27 declareProperty("ShapeXML", "", std::make_shared<Kernel::MandatoryValidator<std::string>>(),
28 "The XML that describes the shape of the gauge volume");
29}
30
35 // Get the XML definition
36 const std::string shapeXML = getProperty("ShapeXML");
37 // Try creating the shape to make sure the input's valid
38 auto shape_sptr = Geometry::ShapeFactory().createShape(shapeXML);
39 if (!shape_sptr->hasValidShape()) {
40 g_log.error("Invalid shape definition provided. Gauge Volume NOT added to "
41 "workspace.");
42 throw std::invalid_argument("Invalid shape definition provided.");
43 }
44
45 // Should we check that the volume defined is within the sample? Is this
46 // necessary?
47 // Do we even have a way to do this?
48
49 progress(0.5);
50
51 // Add as an entry in the workspace's Run object, just as text. Overwrite if
52 // already present.
53 const MatrixWorkspace_sptr workspace = getProperty("Workspace");
54 workspace->mutableRun().addProperty("GaugeVolume", shapeXML, true);
55
56 progress(1);
57}
58
59} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
A property class for workspaces.
This class allows the shape of the sample to be defined by using the allowed XML expressions.
void exec() override
Execution code.
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...
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
Validator to check that a property is not left empty.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ InOut
Both an input & output workspace.
Definition: Property.h:55