16#include <boost/lexical_cast.hpp>
17#include <boost/tuple/tuple.hpp>
26using namespace Kernel;
28using namespace Geometry;
50 "Workspace to save the instrument parameters from.");
53 "The name of the file into which the instrument parameters will be "
56 declareProperty(
"LocationParameters",
false,
"Save the location parameters used to calibrate the instrument.",
65 const bool saveLocationParams =
getProperty(
"LocationParameters");
66 const std::string filename =
getProperty(
"Filename");
74 std::map<ComponentID, std::vector<boost::tuple<std::string, std::string, std::string>>> toSave;
77 Progress prog(
this, 0.0, 0.3, params->size());
80 for (
auto ¶msIt : *params) {
83 prog.
report(
"Generating parameters");
85 const std::string pName = paramsIt.second->name();
86 const std::string pType = paramsIt.second->
type();
87 const std::string pValue = paramsIt.second->asString();
89 if (pName ==
"x" || pName ==
"y" || pName ==
"z" || pName ==
"r-position" || pName ==
"t-position" ||
90 pName ==
"p-position" || pName ==
"rotx" || pName ==
"roty" || pName ==
"rotz") {
91 g_log.
warning() <<
"The parameter name '" << pName <<
"' is reserved and has not been saved. "
92 <<
"Please contact the Mantid team for more information.";
97 if (saveLocationParams) {
99 std::istringstream pValueSS(pValue);
101 toSave[cID].emplace_back(
"x",
"double", boost::lexical_cast<std::string>(pos.
X()));
102 toSave[cID].emplace_back(
"y",
"double", boost::lexical_cast<std::string>(pos.
Y()));
103 toSave[cID].emplace_back(
"z",
"double", boost::lexical_cast<std::string>(pos.
Z()));
105 }
else if (pName ==
"rot") {
106 if (saveLocationParams) {
108 std::istringstream pValueSS(pValue);
110 toSave[cID].emplace_back(
"rotx",
"double", boost::lexical_cast<std::string>(rot.
X()));
111 toSave[cID].emplace_back(
"roty",
"double", boost::lexical_cast<std::string>(rot.
Y()));
112 toSave[cID].emplace_back(
"rotz",
"double", boost::lexical_cast<std::string>(rot.
Z()));
118 if (pType ==
"fitting") {
122 const auto &fitParam = paramsIt.second->value<
FitParameter>();
123 const std::string fpName = fitParam.
getFunction() +
":" + fitParam.getName();
124 std::stringstream fpValue;
125 fpValue <<
"<formula";
126 fpValue <<
" eq=\"" << fitParam.getFormula() <<
"\"";
127 fpValue <<
" unit=\"" << fitParam.getFormulaUnit() <<
"\"";
128 fpValue <<
" result-unit=\"" << fitParam.getResultUnit() <<
"\"";
130 toSave[cID].emplace_back(boost::make_tuple(fpName,
"fitting", fpValue.str()));
132 toSave[cID].emplace_back(boost::make_tuple(pName, pType, pValue));
137 std::ofstream file(filename.c_str(), std::ofstream::trunc);
138 file <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
139 file <<
"<parameter-file instrument=\"" << instrument->getName() <<
"\"";
140 file <<
" valid-from=\"" << instrument->getValidFromDate().toISO8601String() <<
"\">\n";
142 prog.
resetNumSteps(
static_cast<int64_t
>(toSave.size()), 0.6, 1.0);
145 for (
const auto &comp : toSave) {
148 prog.
report(
"Saving parameters");
155 file <<
" <component-link";
157 file <<
" id=\"" << cDetID <<
"\"";
158 file <<
" name=\"" << cFullName <<
"\">\n";
159 for (
const auto ¶m : comp.second) {
160 const std::string pName = param.get<0>();
161 const std::string pType = param.get<1>();
162 const std::string pValue = param.get<2>();
166 if (pType ==
"fitting") {
167 file <<
" <parameter name=\"" << pName <<
"\" type=\"fitting\" >\n";
168 file <<
" " << pValue <<
"\n";
169 file <<
" </parameter>\n";
171 file <<
" <parameter name=\"" << pName <<
"\"" << (pType ==
"string" ?
" type=\"string\"" :
"")
173 file <<
" <value val=\"" << pValue <<
"\"/>\n";
174 file <<
" </parameter>\n";
177 file <<
" </component-link>\n";
179 file <<
"</parameter-file>\n";
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ Save
to specify a file to write to, the file may or may not exist
Helper class for reporting progress from algorithms.
bool hasCancellationBeenRequested() const override
A property class for workspaces.
int version() const override
Algorithm's version for identification.
const std::string category() const override
Algorithm's category for identification.
void init() override
Initialize the algorithm's properties.
const std::string name() const override
Algorithm's name for identification.
void exec() override
Execute the algorithm.
Store information about a fitting parameter such as its value if it is constrained or tied.
const std::string & getFunction() const
get function
base class for Geometric IComponent
virtual std::string type() const
Returns a string representation of the IComponent type.
virtual std::string getFullName() const =0
Get the IComponent full path name.
Interface class for detector objects.
virtual detid_t getID() const =0
Get the detector ID.
void warning(const std::string &msg)
Logs at warning level.
void resetNumSteps(int64_t nsteps, double start, double end)
Change the number of steps between start/end.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
void readPrinted(std::istream &)
Read data from a stream in the format returned by printSelf ("[x,y,z]").
constexpr double Z() const noexcept
Get z.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< ParameterMap > ParameterMap_sptr
ParameterMap shared pointer typedef.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
int32_t detid_t
Typedef for a detector ID.
@ Input
An input workspace.