68 const bool saveLocationParams =
getProperty(
"LocationParameters");
69 const std::string filename =
getProperty(
"Filename");
73 const auto params = instrument->legacyParameters();
75 const auto &componentInfo = ws->componentInfo();
76 const auto &detectorInfo = ws->detectorInfo();
79 std::map<size_t, std::vector<boost::tuple<std::string, std::string, std::string>>> toSave;
82 Progress prog(
this, 0.0, 0.3, params.size());
85 for (
auto const ¶msIt : params) {
88 prog.
report(
"Generating parameters");
89 const size_t cID = paramsIt.first;
90 const std::string pName = paramsIt.second->name();
91 const std::string pType = paramsIt.second->type();
92 const std::string pValue = paramsIt.second->asString();
94 if (pName ==
"x" || pName ==
"y" || pName ==
"z" || pName ==
"r-position" || pName ==
"t-position" ||
95 pName ==
"p-position" || pName ==
"rotx" || pName ==
"roty" || pName ==
"rotz") {
96 g_log.
warning() <<
"The parameter name '" << pName <<
"' is reserved and has not been saved. "
97 <<
"Please contact the Mantid team for more information.";
101 if (pName ==
"pos") {
102 if (saveLocationParams) {
104 std::istringstream pValueSS(pValue);
106 toSave[cID].emplace_back(
"x",
"double", boost::lexical_cast<std::string>(pos.
X()));
107 toSave[cID].emplace_back(
"y",
"double", boost::lexical_cast<std::string>(pos.
Y()));
108 toSave[cID].emplace_back(
"z",
"double", boost::lexical_cast<std::string>(pos.
Z()));
110 }
else if (pName ==
"rot") {
111 if (saveLocationParams) {
113 std::istringstream pValueSS(pValue);
115 toSave[cID].emplace_back(
"rotx",
"double", boost::lexical_cast<std::string>(rot.
X()));
116 toSave[cID].emplace_back(
"roty",
"double", boost::lexical_cast<std::string>(rot.
Y()));
117 toSave[cID].emplace_back(
"rotz",
"double", boost::lexical_cast<std::string>(rot.
Z()));
123 if (pType ==
"fitting") {
127 const auto &fitParam = paramsIt.second->value<
FitParameter>();
128 const std::string fpName = fitParam.
getFunction() +
":" + fitParam.getName();
129 std::stringstream fpValue;
130 fpValue <<
"<formula";
131 fpValue <<
" eq=\"" << fitParam.getFormula() <<
"\"";
132 fpValue <<
" unit=\"" << fitParam.getFormulaUnit() <<
"\"";
133 fpValue <<
" result-unit=\"" << fitParam.getResultUnit() <<
"\"";
135 toSave[cID].emplace_back(boost::make_tuple(fpName,
"fitting", fpValue.str()));
137 toSave[cID].emplace_back(boost::make_tuple(pName, pType, pValue));
142 std::ofstream file(filename.c_str(), std::ofstream::trunc);
143 file <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
144 file <<
"<parameter-file instrument=\"" << ws->getInstrumentName() <<
"\"";
145 file <<
" valid-from=\"" << ws->instrumentMetadata().validFromDate().toISO8601String() <<
"\">\n";
147 prog.
resetNumSteps(
static_cast<int64_t
>(toSave.size()), 0.6, 1.0);
150 for (
const auto &comp : toSave) {
153 prog.
report(
"Saving parameters");
155 const size_t cID = comp.first;
156 const std::string cFullName = componentInfo.fullName(cID);
157 const detid_t cDetID = componentInfo.isDetector(cID) ? detectorInfo.detectorIDs()[cID] : 0;
159 file <<
" <component-link";
161 file <<
" id=\"" << cDetID <<
"\"";
162 file <<
" name=\"" << cFullName <<
"\">\n";
163 for (
const auto ¶m : comp.second) {
164 const std::string pName = param.get<0>();
165 const std::string pType = param.get<1>();
166 const std::string pValue = param.get<2>();
170 if (pType ==
"fitting") {
171 file <<
" <parameter name=\"" << pName <<
"\" type=\"fitting\" >\n";
172 file <<
" " << pValue <<
"\n";
173 file <<
" </parameter>\n";
175 file <<
" <parameter name=\"" << pName <<
"\"" << (pType ==
"string" ?
" type=\"string\"" :
"")
177 file <<
" <value val=\"" << pValue <<
"\"/>\n";
178 file <<
" </parameter>\n";
181 file <<
" </component-link>\n";
183 file <<
"</parameter-file>\n";