48 std::string parameterName =
"Default grouping file";
49 auto loadedGrouping = std::make_shared<Grouping>();
56 std::vector<std::string> groupingFiles =
m_instrument->getStringParameter(parameterName);
58 if (groupingFiles.size() == 1) {
59 const std::string groupingFile = groupingFiles[0];
62 std::string directoryName = Kernel::ConfigService::Instance().getInstrumentDirectory();
66 throw std::runtime_error(
"Multiple groupings specified for the instrument");
68 return loadedGrouping;
80 Poco::AutoPtr<Document> pDoc;
82 pDoc = pParser.parse(filename);
88 Element *pRootElem = pDoc->documentElement();
89 if (!pRootElem->hasChildNodes())
93 Poco::AutoPtr<NodeList> groups = pRootElem->getElementsByTagName(
"group");
94 if (groups->length() == 0)
99 grouping.
groups.resize(groups->length());
101 for (
size_t ig = 0; ig < groups->length(); ig++) {
102 auto *pGroupElem =
static_cast<Element *
>(groups->item(
static_cast<long>(ig)));
104 if (!pGroupElem->hasAttribute(
"name"))
107 grouping.
groupNames[ig] = pGroupElem->getAttribute(
"name");
109 Element *idlistElement = pGroupElem->getChildElement(
"ids");
113 grouping.
groups[ig] = idlistElement->getAttribute(
"val");
117 Poco::AutoPtr<NodeList> pairs = pRootElem->getElementsByTagName(
"pair");
120 grouping.
pairNames.resize(pairs->length());
121 grouping.
pairs.resize(pairs->length());
124 for (
size_t ip = 0; ip < pairs->length(); ip++) {
125 auto *pPairElem =
static_cast<Element *
>(pairs->item(
static_cast<long>(ip)));
127 if (!pPairElem->hasAttribute(
"name"))
130 grouping.
pairNames[ip] = pPairElem->getAttribute(
"name");
132 size_t fwdGroupId, bwdGroupId;
135 if (Element *fwdElement = pPairElem->getChildElement(
"forward-group")) {
136 if (!fwdElement->hasAttribute(
"val"))
140 auto it = std::find(grouping.
groupNames.begin(), grouping.
groupNames.end(), fwdElement->getAttribute(
"val"));
146 fwdGroupId = it - grouping.
groupNames.begin();
152 if (Element *bwdElement = pPairElem->getChildElement(
"backward-group")) {
153 if (!bwdElement->hasAttribute(
"val"))
157 auto it = std::find(grouping.
groupNames.begin(), grouping.
groupNames.end(), bwdElement->getAttribute(
"val"));
163 bwdGroupId = it - grouping.
groupNames.begin();
168 grouping.
pairs[ip] = std::make_pair(fwdGroupId, bwdGroupId);
171 if (Element *aElement = pPairElem->getChildElement(
"alpha")) {
172 if (!aElement->hasAttribute(
"val"))
177 grouping.
pairAlphas[ip] = boost::lexical_cast<double>(aElement->getAttribute(
"val"));
178 }
catch (boost::bad_lexical_cast &) {
189 if (pRootElem->hasAttribute(
"description")) {
190 grouping.
description = pRootElem->getAttribute(
"description");
194 if (Element *defaultElement = pRootElem->getChildElement(
"default")) {
195 if (!defaultElement->hasAttribute(
"name"))
198 grouping.
defaultName = defaultElement->getAttribute(
"name");
MANTID_KERNEL_DLL std::vector< int > parseRange(const std::string &str, const std::string &elemSep=",", const std::string &rangeSep="-")
Parses a number range, e.g.