Mantid
Loading...
Searching...
No Matches
MDHistoDimension.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 +
8#include <sstream>
9
10#include <boost/algorithm/string.hpp>
11#include <boost/format.hpp>
12
13#include <Poco/DOM/Attr.h>
14#include <Poco/DOM/AutoPtr.h>
15#include <Poco/DOM/DOMParser.h>
16#include <Poco/DOM/DOMWriter.h>
17#include <Poco/DOM/Document.h>
18#include <Poco/DOM/Element.h>
19#include <Poco/DOM/Text.h>
20
21namespace Mantid::Geometry {
22
23std::string MDHistoDimension::toXMLString() const {
24 using namespace Poco::XML;
25
26 // Create the root element for this fragment.
27 AutoPtr<Document> pDoc = new Document;
28 AutoPtr<Element> pDimensionElement = pDoc->createElement("Dimension");
29 pDoc->appendChild(pDimensionElement);
30
31 // Set the id.
32 AutoPtr<Attr> idAttribute = pDoc->createAttribute("ID");
33 idAttribute->setNodeValue(this->getDimensionId());
34 pDimensionElement->setAttributeNode(idAttribute);
35
36 // Set the name.
37 AutoPtr<Element> nameElement = pDoc->createElement("Name");
38 AutoPtr<Text> nameText = pDoc->createTextNode(this->getName());
39 nameElement->appendChild(nameText);
40 pDimensionElement->appendChild(nameElement);
41
42 // Set the units.
43 AutoPtr<Element> unitsElement = pDoc->createElement("Units");
44 AutoPtr<Text> unitsText = pDoc->createTextNode(this->getUnits());
45 unitsElement->appendChild(unitsText);
46 pDimensionElement->appendChild(unitsElement);
47
48 // Set the frame.
49 AutoPtr<Element> frameElement = pDoc->createElement("Frame");
50 AutoPtr<Text> frameText = pDoc->createTextNode(this->getMDFrame().name());
51 frameElement->appendChild(frameText);
52 pDimensionElement->appendChild(frameElement);
53
54 // Set the upper bounds
55 AutoPtr<Element> upperBoundsElement = pDoc->createElement("UpperBounds");
56 AutoPtr<Text> upperBoundsText = pDoc->createTextNode(boost::str(boost::format("%.4f") % this->getMaximum()));
57 upperBoundsElement->appendChild(upperBoundsText);
58 pDimensionElement->appendChild(upperBoundsElement);
59
60 // Set the lower bounds
61 AutoPtr<Element> lowerBoundsElement = pDoc->createElement("LowerBounds");
62 AutoPtr<Text> lowerBoundsText = pDoc->createTextNode(boost::str(boost::format("%.4f") % this->getMinimum()));
63 lowerBoundsElement->appendChild(lowerBoundsText);
64 pDimensionElement->appendChild(lowerBoundsElement);
65
66 // Set the number of bins
67 AutoPtr<Element> numberOfBinsElement = pDoc->createElement("NumberOfBins");
68 AutoPtr<Text> numberOfBinsText = pDoc->createTextNode(boost::str(boost::format("%.4d") % this->getNBins()));
69 numberOfBinsElement->appendChild(numberOfBinsText);
70 pDimensionElement->appendChild(numberOfBinsElement);
71
72 // Provide upper and lower limits for integrated dimensions.
73 if (this->getIsIntegrated()) {
74 AutoPtr<Element> integratedElement = pDoc->createElement("Integrated");
75 // Set the upper limit
76 AutoPtr<Element> upperLimitElement = pDoc->createElement("UpperLimit");
77 AutoPtr<Text> upperLimitText =
78 pDoc->createTextNode(boost::str(boost::format("%.4f") % this->getMaximum())); // Dimension does not yet
79 // provide integration
80 // ranges.
81 upperLimitElement->appendChild(upperLimitText);
82 integratedElement->appendChild(upperLimitElement);
83
84 // Set the lower limit
85 AutoPtr<Element> lowerLimitElement = pDoc->createElement("LowerLimit");
86 AutoPtr<Text> lowerLimitText =
87 pDoc->createTextNode(boost::str(boost::format("%.4f") % this->getMinimum())); // Dimension does not yet
88 // provide integration
89 // ranges.
90 lowerLimitElement->appendChild(lowerLimitText);
91 integratedElement->appendChild(lowerLimitElement);
92
93 pDimensionElement->appendChild(integratedElement);
94 }
95
96 // Create a string representation of the DOM tree.
97 std::stringstream xmlstream;
98 DOMWriter writer;
99 writer.writeNode(xmlstream, pDoc);
100
101 return xmlstream.str();
102}
103} // namespace Mantid::Geometry
virtual bool getIsIntegrated() const
Definition: IMDDimension.h:91
coord_t getMaximum() const override
Returns the maximum extent of this dimension.
coord_t getMinimum() const override
Returns the minimum extent of this dimension.
std::string toXMLString() const override
Dimensions must be xml serializable.
const MDFrame & getMDFrame() const override
Return the md frame.
const Kernel::UnitLabel getUnits() const override
Return the units of the dimension as a string.
std::string getName() const override
Return the name of the dimension as can be displayed along the axis.
const std::string & getDimensionId() const override
Short name which identify the dimension among other dimension.
size_t getNBins() const override
number of bins dimension have (an integrated has one).