Mantid
Loading...
Searching...
No Matches
MDHistoDimensionBuilder.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#include <utility>
8
13
14namespace Mantid::Geometry {
15
18 : m_units(Kernel::Units::Symbol::EmptyLabel), m_min(0), m_max(0), m_nbins(0), m_minSet(false), m_maxSet(false),
19 m_frameName("") {}
20
21/*
22Setter for the dimension name
23@param name : friendly name of dimension
24*/
25void MDHistoDimensionBuilder::setName(const std::string &name) {
26 // String any spaces
28}
29
30/*
31Setter for the dimension id
32@param id : id of the dimension
33*/
34void MDHistoDimensionBuilder::setId(std::string id) { m_id = std::move(id); }
35
36/*
37Setter for the dimension units
38@param units : unit type of dimension
39*/
41
42/*
43Setter for the dimension min
44@param min : min boundary of dimension
45*/
47 m_min = min;
48 m_minSet = true;
49}
50
51/*
52Setter for the dimension max
53@param max : max boundary of dimension
54*/
56 m_max = max;
57 m_maxSet = true;
58}
59
60/*
61Setter for the dimension nbins
62@param nbins : number of bins of dimension
63*/
64void MDHistoDimensionBuilder::setNumBins(size_t nbins) { m_nbins = nbins; }
65
70void MDHistoDimensionBuilder::setFrameName(std::string frameName) { m_frameName = std::move(frameName); }
71
72/*
73Creational method
74@return fully constructed MDHistoDimension instance.
75*/
77 if (m_name.empty()) {
78 throw std::invalid_argument("Cannot create MDHistogramDimension without setting a name.");
79 }
80 if (m_id.empty()) {
81 throw std::invalid_argument("Cannot create MDHistogramDimension without setting a id.");
82 }
83 if (m_units.ascii().empty()) {
84 throw std::invalid_argument("Cannot create MDHistogramDimension without setting a unit type.");
85 }
86 if (!m_minSet) {
87 throw std::invalid_argument("Cannot create MDHistogramDimension without setting min.");
88 }
89 if (!m_maxSet) {
90 throw std::invalid_argument("Cannot create MDHistogramDimension without setting max.");
91 }
92 if (m_min >= m_max) {
93 throw std::invalid_argument("Cannot create MDHistogramDimension with min >= max.");
94 }
95 if (m_nbins == 0) {
96 throw std::invalid_argument("Cannot create MDHistogramDimension without setting a n bins.");
97 }
98
99 // Select a Mantid Frame. Use FrameName if available else just use name.
100 auto frameFactory = Mantid::Geometry::makeMDFrameFactoryChain();
101 std::string frameNameForFactory = m_frameName.empty() ? m_name : m_frameName;
102 Mantid::Geometry::MDFrameArgument frameArgument(frameNameForFactory, m_units);
103 auto frame = frameFactory->create(frameArgument);
104
105 return new MDHistoDimension(m_name, m_id, *frame, coord_t(m_min), coord_t(m_max), m_nbins);
106}
107
108/*
109Creational method
110@return fully constructed MDHistoDimension instance wrapped in a boost shared
111pointer.
112*/
114} // namespace Mantid::Geometry
specnum_t m_min
specnum_t m_max
Input argument type for MDFrameFactory chainable factory.
bool m_maxSet
Flag indicating that max has been set.
bool m_minSet
Flag indicating that min has been set.
void setFrameName(std::string frameName)
Setter for the frame name.
void setUnits(const Kernel::UnitLabel &units)
A base-class for the a class that is able to return unit labels in different representations.
Definition: UnitLabel.h:20
const AsciiString & ascii() const
Return an ascii label for unit.
Definition: UnitLabel.cpp:105
std::shared_ptr< IMDDimension > IMDDimension_sptr
Shared Pointer for IMDDimension. Frequently used type in framework.
Definition: IMDDimension.h:98
MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain()
Make a complete factory chain.
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
Definition: Strings.cpp:397
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Definition: MDTypes.h:27