11#include <Poco/AutoPtr.h>
12#include <Poco/DOM/DOMParser.h>
13#include <Poco/DOM/Document.h>
14#include <Poco/DOM/Element.h>
15#include <Poco/DOM/NamedNodeMap.h>
16#include <Poco/NumberParser.h>
17#include <Poco/XML/XMLException.h>
28 Poco::XML::DOMParser pParser;
29 Poco::AutoPtr<Poco::XML::Document> pDoc;
31 pDoc = pParser.parseString(dimensionXMLString);
33 }
catch (Poco::XML::XMLException &ex) {
35 throw std::invalid_argument(std::string(
"Invalid string passed to createDimension: ") + ex.what());
42 Poco::AutoPtr<Poco::XML::NamedNodeMap> attributes = dimensionXML.attributes();
46 const std::string
id = dimensionXML.getAttribute(
"ID");
48 throw std::invalid_argument(
"Invalid string passed to createDimension: No ID attribute");
51 Poco::XML::Element *nameElement = dimensionXML.getChildElement(
"Name");
52 if (
nullptr == nameElement) {
53 throw std::invalid_argument(
"Invalid string passed to createDimension: No Name element");
55 const std::string name = nameElement->innerText();
57 Poco::XML::Element *unitsElement = dimensionXML.getChildElement(
"Units");
58 std::string units =
"None";
59 if (
nullptr != unitsElement) {
61 units = unitsElement->innerText();
64 Poco::XML::Element *frameElement = dimensionXML.getChildElement(
"Frame");
65 std::string frame =
"Unknown frame";
66 if (
nullptr != frameElement) {
68 frame = frameElement->innerText();
71 Poco::XML::Element *upperBoundsElement = dimensionXML.getChildElement(
"UpperBounds");
72 if (
nullptr == upperBoundsElement) {
73 throw std::invalid_argument(
"Invalid string passed to createDimension: No UpperBounds element");
75 Poco::XML::Element *lowerBoundsElement = dimensionXML.getChildElement(
"LowerBounds");
76 if (
nullptr == lowerBoundsElement) {
77 throw std::invalid_argument(
"Invalid string passed to createDimension: No LowerBounds element");
80 double upperBounds, lowerBounds;
82 upperBounds = Poco::NumberParser::parseFloat(upperBoundsElement->innerText());
83 lowerBounds = Poco::NumberParser::parseFloat(lowerBoundsElement->innerText());
84 }
catch (Poco::SyntaxException &ex) {
85 throw std::invalid_argument(std::string(
"Invalid string passed to createDimension: ") + ex.what());
88 Poco::XML::Element *numBinsElement = dimensionXML.getChildElement(
"NumberOfBins");
89 if (
nullptr == numBinsElement) {
90 throw std::invalid_argument(
"Invalid string passed to createDimension: No NumberOfBins element");
94 nBins = Poco::NumberParser::parseUnsigned(numBinsElement->innerText());
95 }
catch (Poco::SyntaxException &ex) {
96 throw std::invalid_argument(std::string(
"Invalid string passed to createDimension: ") + ex.what());
99 Poco::XML::Element *integrationXML = dimensionXML.getChildElement(
"Integrated");
100 if (
nullptr != integrationXML) {
101 double upperLimit = std::stod(integrationXML->getChildElement(
"UpperLimit")->innerText());
102 double lowerLimit = std::stod(integrationXML->getChildElement(
"LowerLimit")->innerText());
107 upperBounds = upperLimit;
108 lowerBounds = lowerLimit;
114 return std::make_shared<MDHistoDimension>(name,
id, *mdframe,
static_cast<coord_t>(lowerBounds),
115 static_cast<coord_t>(upperBounds), nBins);
129 dimension->setRange(nBins, min, max);
Input argument type for MDFrameFactory chainable factory.
MANTID_GEOMETRY_DLL IMDDimension_sptr createDimension(const std::string &dimensionXMLString)
Creates IMDDimension objects based on input XML.
std::shared_ptr< IMDDimension > IMDDimension_sptr
Shared Pointer for IMDDimension. Frequently used type in framework.
std::unique_ptr< const MDFrame > MDFrame_const_uptr
MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain()
Make a complete factory chain.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...