15#include "boost/algorithm/string.hpp"
16#include "boost/math/special_functions/round.hpp"
35 :
API::
Algorithm(), m_profileParamMap(), m_profileTableWS(), m_outIrfFilename(), m_bankID(-1),
36 m_fpProfileNumber(-1), m_append(false) {}
43 "Input TableWorkspace containing the parameters for .irf file.");
45 std::vector<std::string> exts{
".irf"};
47 "Name of the output .irf file.");
49 std::shared_ptr<BoundedValidator<int>> bankboundval = std::make_shared<BoundedValidator<int>>();
50 bankboundval->setLower(0);
53 vector<string> supportedfunctions;
54 supportedfunctions.emplace_back(
"Back-to-back exponential convoluted with pseudo-voigt (profile 9)");
55 supportedfunctions.emplace_back(
"Jason Hodge's function (profile 10)");
56 auto funcvalidator = std::make_shared<StringListValidator>(supportedfunctions);
57 declareProperty(
"ProfileFunction",
"Jason Hodge's function (profile 10)", funcvalidator,
58 "Profile number defined in Fullprof.");
61 "If true and the output file exists, the "
62 "bank will be appended to the existing "
88 throw runtime_error(
"Profile number is not supported yet.");
95 ofile.open(
m_outIrfFilename.c_str(), std::ofstream::out | std::ofstream::app);
99 ofile.open(
m_outIrfFilename.c_str(), std::ofstream::out | std::ofstream::trunc);
117 throw runtime_error(
"Input file name invalid. ");
130 string proffunction =
getProperty(
"ProfileFunction");
131 if (proffunction ==
"Back-to-back exponential convoluted with pseudo-voigt (profile 9)")
133 else if (proffunction ==
"Jason Hodge's function (profile 10)")
137 errmsg <<
"It is impossible to have profile function " << proffunction <<
" input. ";
139 throw runtime_error(errmsg.str());
150 size_t numcols = colnames.size();
152 stringstream dbmsgss(
"Input table's column names: ");
153 for (
auto &colname : colnames) {
154 dbmsgss << setw(20) << colname;
158 if (colnames[0] !=
"Name")
159 throw runtime_error(
"First colunm must be 'Name'");
163 vector<string> vec_parnames(numpars);
164 int rowbankindex = -1;
165 for (
size_t i = 0; i < numpars; ++i) {
167 vec_parnames[i] = parname;
168 if (parname ==
"BANK")
169 rowbankindex =
static_cast<int>(i);
174 if (rowbankindex < 0) {
177 for (
size_t i = 1; i < numcols; ++i) {
178 if (boost::starts_with(colnames[i],
"Value")) {
179 colindex =
static_cast<int>(i);
186 for (
size_t i = 1; i < numcols; ++i) {
187 if (boost::starts_with(colnames[i],
"Value")) {
188 int bankid = boost::math::iround(
m_profileTableWS->cell<
double>(rowbankindex, i));
190 colindex =
static_cast<int>(i);
198 throw runtime_error(
"Unable to find column");
200 throw runtime_error(
"Impossible to have this situation.");
207 for (
size_t ir = 0; ir < numpars; ++ir) {
208 double parvalue =
m_profileTableWS->cell<
double>(ir,
static_cast<size_t>(colindex));
213 stringstream dbss(
"Imported Parameter Table: \n");
214 map<string, double>::iterator mit;
216 dbss << setw(20) << mit->first <<
" = " << setprecision(5) << mit->second <<
'\n';
253 if (profindex == 0) {
255 }
else if (profindex != 10) {
257 errmsg <<
"This column in table has profile number " << profindex <<
" other than 10.";
259 throw runtime_error(errmsg.str());
262 stringstream content;
267 content <<
" Instrumental resolution function for POWGEN/SNS ireso: 6"
269 content <<
"! To be used with function NPROF=" << profindex <<
" in FullProf (Res=6)"
274 content <<
"! ---------------------------------------------- Bank " <<
m_bankID <<
" ";
278 content <<
"CWL = " << setprecision(4) << cwl <<
"A"
287 content <<
"! Type of profile function: back-to-back exponentials * pseudo-Voigt"
289 content <<
"NPROF " << profindex <<
"\n";
291 content <<
"! Tof-min(us) step Tof-max(us)"
293 content <<
"TOFRG " << setprecision(3) << tofmin <<
" " << setw(16) << setprecision(5) << tofstep <<
" " << setw(16)
294 << setprecision(3) << tofmax <<
"\n";
296 content <<
"! Zero Dtt1"
298 content <<
"ZD2TOF " << setw(16) << setprecision(5) << zero << setw(16) << setprecision(5) << dtt1 <<
"\n";
300 content <<
"! Zerot Dtt1t Dtt2t x-cross Width"
302 content <<
"ZD2TOT " << setprecision(5) << zerot << setw(16) << setprecision(5) << dtt1t << setw(16)
303 << setprecision(5) << dtt2t << setw(16) << setprecision(10) << xcross << setw(16) << setprecision(5) << width
306 content <<
"! TOF-TWOTH of the bank"
308 content <<
"TWOTH " << setprecision(3) << twotheta <<
"\n";
313 content <<
"! Sig-2 Sig-1 Sig-0"
315 content <<
"SIGMA " << setprecision(6) << sig2 * sig2 << setw(16) << setprecision(6) << sig1 * sig1 << setw(16)
316 << setprecision(6) << sig0 * sig0 <<
"\n";
318 content <<
"! Gam-2 Gam-1 Gam-0"
320 content <<
"GAMMA " << setw(16) << setprecision(6) << gam2 <<
" " << setw(16) << setprecision(6) << gam1 <<
" "
321 << setw(16) << setprecision(6) << gam0 <<
"\n";
323 content <<
"! alph0 beta0 alph1 beta1"
325 content <<
"ALFBE " << setprecision(6) << alph0 <<
" " << setw(16) << setprecision(6) << beta0 <<
" "
326 << setw(16) << setprecision(6) << alph1 <<
" " << setw(16) << setprecision(6) << beta1 <<
"\n";
328 content <<
"! alph0t beta0t alph1t beta1t"
330 content <<
"ALFBT " << setprecision(6) << alph0t <<
" " << setw(16) << setprecision(6) << beta0t <<
" "
331 << setw(16) << setprecision(6) << alph1t <<
" " << setw(16) << setprecision(6) << beta1t <<
"\n";
335 return content.str();
365 if (profindex == 0) {
367 }
else if (profindex != 9) {
369 errmsg <<
"This column in table has profile number " << profindex <<
" other than 9.";
371 throw runtime_error(errmsg.str());
374 stringstream content;
379 content <<
"Instrumental resolution function for HRPD/ISIS L. Chapon "
382 content <<
"! To be used with function NPROF=" << profindex <<
" in FullProf (Res=5)"
387 content <<
"! ---------------------------------------------- Bank " <<
m_bankID <<
" ";
391 content <<
"CWL = " << setprecision(4) << cwl <<
"A"
400 content <<
"! Type of profile function: back-to-back exponentials * pseudo-Voigt"
402 content <<
"NPROF " << profindex <<
"\n";
403 content <<
"! Tof-min(us) step Tof-max(us)"
405 content <<
"TOFRG " << setprecision(3) << tofmin <<
" " << setw(16) << setprecision(5) << tofstep <<
" " << setw(16)
406 << setprecision(3) << tofmax <<
"\n";
408 content <<
"! Dtt1 Dtt2 Zero"
410 content <<
"D2TOF " << setw(16) << setprecision(5) << dtt1 << setw(16) << setprecision(5) << dtt2 << setw(16)
411 << setprecision(5) << zero <<
"\n";
413 content <<
"! TOF-TWOTH of the bank"
415 content <<
"TWOTH " << setprecision(3) << twotheta <<
"\n";
420 content <<
"! Sig-2 Sig-1 Sig-0"
422 content <<
"SIGMA " << setprecision(6) << sig2 * sig2 << setw(16) << setprecision(6) << sig1 * sig1 << setw(16)
423 << setprecision(6) << sig0 * sig0 <<
"\n";
425 content <<
"! Gam-2 Gam-1 Gam-0"
427 content <<
"GAMMA " << setw(16) << setprecision(6) << gam2 <<
" " << setw(16) << setprecision(6) << gam1 <<
" "
428 << setw(16) << setprecision(6) << gam0 <<
"\n";
430 content <<
"! alph0 beta0 alph1 beta1"
432 content <<
"ALFBE " << setprecision(6) << alph0 <<
" " << setw(16) << setprecision(6) << beta0 <<
" "
433 << setw(16) << setprecision(6) << alph1 <<
" " << setw(16) << setprecision(6) << beta1 <<
"\n";
438 return content.str();
445 map<string, double>::iterator fiter;
446 fiter = profmap.find(key);
448 if (fiter == profmap.end())
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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
A property class for workspaces.
SaveFullprofResolution : TODO: DESCRIPTION.
void parseTableWorkspace()
Parse input workspace to map of parameters.
void exec() override
Execution code.
int m_bankID
Bank to write.
std::string m_outIrfFilename
Output Irf file name.
void processProperties()
Write the header information.
std::string toProf10IrfString()
Write out string for profile 10 .irf file.
int m_fpProfileNumber
Profile number.
DataObjects::TableWorkspace_sptr m_profileTableWS
Input table workspace.
void init() override
Initialisation code.
std::string toProf9IrfString()
Write out string for profile 9 .irf file.
bool has_key(std::map< std::string, double > profmap, const std::string &key)
Check wether a profile parameter map has the parameter.
std::map< std::string, double > m_profileParamMap
Map containing the name of value of each parameter required by .irf file.
bool m_append
Append to existing file.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
@ Input
An input workspace.