10#include "MantidMuon/MuonAlgorithmHelper.h"
12#include <Poco/DOM/DOMParser.h>
13#include <Poco/DOM/DOMWriter.h>
14#include <Poco/DOM/Document.h>
15#include <Poco/DOM/NodeList.h>
16#include <Poco/DOM/Text.h>
17#include <Poco/XML/XMLWriter.h>
33 std::string fileContents(
"");
34 fileContents +=
"<detector-grouping description=\"test XML file\"> \n";
35 fileContents +=
"\t<group name=\"" + groupName +
"\"> \n";
36 fileContents +=
"\t\t<ids val=\"" + group +
"\"/>\n";
37 fileContents +=
"\t</group>\n";
38 fileContents +=
"\t<default name=\"" + groupName +
"\"/>\n";
39 fileContents +=
"</detector-grouping>";
54 std::string fileContents(
"");
56 fileContents +=
"<detector-grouping description=\"test XML file\"> \n";
57 fileContents +=
"\t<group name=\"group1\"> \n";
58 fileContents +=
"\t\t<ids val=\"1\"/>\n";
59 fileContents +=
"\t</group>\n";
61 fileContents +=
"<detector-grouping description=\"test XML file\"> \n";
62 fileContents +=
"\t<group name=\"group2\"> \n";
63 fileContents +=
"\t\t<ids val=\"2\"/>\n";
64 fileContents +=
"\t</group>\n";
66 fileContents +=
"\t<pair name=\"" + pairName +
"\"> \n";
67 fileContents +=
"\t\t<forward-group val=\"group1\"/>\n";
68 fileContents +=
"\t\t<backward-group val=\"" + groupName +
"\"/>\n";
69 fileContents +=
"\t\t<alpha val=\"1\"/>\n";
70 fileContents +=
"\t</pair>\n";
72 fileContents +=
"\t<default name=\"" + groupName +
"\"/>\n";
73 fileContents +=
"</detector-grouping>";
93 for (
auto group = 1; group <= nGroups; group++) {
102 grouping.
groups.emplace_back(groupIDs);
105 for (
auto pair = 1; pair < nGroups; pair++) {
107 std::pair<size_t, size_t> pairIndices;
108 pairIndices.first = 0;
109 pairIndices.second = pair;
110 grouping.
pairNames.emplace_back(pairName);
112 grouping.
pairs.emplace_back(pairIndices);
126 Poco::XML::DOMWriter writer;
127 writer.setNewLine(
"\n");
128 writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT);
130 Poco::AutoPtr<Poco::XML::Document> mDoc =
new Poco::XML::Document();
133 Poco::AutoPtr<Poco::XML::Element> rootElem = mDoc->createElement(
"detector-grouping");
134 rootElem->setAttribute(
"description", grouping.
description);
135 mDoc->appendChild(rootElem);
138 for (
size_t gi = 0; gi < grouping.
groups.size(); gi++) {
139 Poco::AutoPtr<Poco::XML::Element> gElem = mDoc->createElement(
"group");
140 gElem->setAttribute(
"name", grouping.
groupNames[gi]);
141 rootElem->appendChild(gElem);
143 Poco::AutoPtr<Poco::XML::Element> idsElem = mDoc->createElement(
"ids");
144 idsElem->setAttribute(
"val", grouping.
groups[gi]);
145 gElem->appendChild(idsElem);
149 for (
size_t pi = 0; pi < grouping.
pairs.size(); pi++) {
150 Poco::AutoPtr<Poco::XML::Element> gElem = mDoc->createElement(
"pair");
151 gElem->setAttribute(
"name", grouping.
pairNames[pi]);
152 rootElem->appendChild(gElem);
154 Poco::AutoPtr<Poco::XML::Element> fwElem = mDoc->createElement(
"forward-group");
155 fwElem->setAttribute(
"val", grouping.
groupNames[grouping.
pairs[pi].first]);
156 gElem->appendChild(fwElem);
158 Poco::AutoPtr<Poco::XML::Element> bwElem = mDoc->createElement(
"backward-group");
159 bwElem->setAttribute(
"val", grouping.
groupNames[grouping.
pairs[pi].second]);
160 gElem->appendChild(bwElem);
162 Poco::AutoPtr<Poco::XML::Element> alphaElem = mDoc->createElement(
"alpha");
163 alphaElem->setAttribute(
"val", boost::lexical_cast<std::string>(grouping.
pairAlphas[pi]));
164 gElem->appendChild(alphaElem);
168 Poco::AutoPtr<Poco::XML::Element> gElem = mDoc->createElement(
"default");
170 rootElem->appendChild(gElem);
172 std::stringstream stream;
173 writer.writeNode(stream, mDoc);
Structure to represent grouping information.
std::vector< std::pair< size_t, size_t > > pairs
std::vector< std::string > groupNames
std::vector< double > pairAlphas
std::vector< std::string > pairNames
std::vector< std::string > groups
Helper class which provides the Collimation Length for SANS instruments.
ScopedFileHelper::ScopedFile createGroupingXMLSinglePair(const std::string &pairName, const std::string &groupName)
Create an XML with two simple groups and a pair made from them.
DLLExport std::string groupingToXML(const Mantid::API::Grouping &grouping)
Create an XML file (as a string) containing muon grouping information.
ScopedFileHelper::ScopedFile createGroupingXMLSingleGroup(const std::string &groupName, const std::string &group)
Simplest possible grouping file, with only a single group.
ScopedFileHelper::ScopedFile createXMLwithPairsAndGroups(const int &nGroups=1, const int &nDetectorsPerGroup=1)
Create an XML file with grouping/pairing information.
std::string to_string(const wide_integer< Bits, Signed > &n)