15#include <boost/lexical_cast.hpp>
26template <
class Type> Type
lexCast(std::string input,
const std::string &errorMessage) {
28 return boost::lexical_cast<Type>(input);
29 }
catch (boost::bad_lexical_cast &) {
30 throw std::runtime_error(errorMessage + input);
35 if (
index.size() > 1) {
38 if (range.
count() < 1) {
40 }
else if (range.
count() == 1) {
42 start = boost::lexical_cast<double>(range[0]);
43 }
catch (boost::bad_lexical_cast &) {
44 throw std::runtime_error(std::string(
"Provided incorrect range values. Range is "
45 "specfifed by start_value:stop_value, but "
54 std::string errorMessage = std::string(
"Provided incorrect range values. Range is "
55 "specfifed by start_value:stop_value, but "
57 range[0] + std::string(
" and ") + range[1];
58 start = lexCast<double>(range[0], errorMessage);
59 end = lexCast<double>(range[1], errorMessage);
62 std::swap(start, end);
71void addGroupWorkspace(std::vector<InputSpectraToFit> &nameList,
double start,
double end,
int wi,
int spec,
int period,
72 const std::shared_ptr<API::WorkspaceGroup> &wsg);
73void addMatrixworkspace(std::vector<InputSpectraToFit> &nameList,
double start,
double end, std::string &name,
int wi,
74 int spec,
int period,
const boost::optional<API::Workspace_sptr> &workspaceOptional,
75 const std::shared_ptr<API::MatrixWorkspace> &wsMatrix);
77std::vector<InputSpectraToFit>
makeNames(
const std::string &inputList,
int default_wi,
int default_spec) {
78 std::vector<InputSpectraToFit> nameList;
85 for (
const auto &input : names) {
87 std::string name = params[0];
89 int spec = default_spec;
90 if (params.
count() > 1) {
91 std::string
index = params[1];
92 if (
index.size() > 2 &&
index.substr(0, 2) ==
"sp") {
93 spec = boost::lexical_cast<int>(
index.substr(2));
94 wi = SpecialIndex::NOT_SET;
95 }
else if (
index.size() > 1 &&
index[0] ==
'i') {
96 wi = boost::lexical_cast<int>(
index.substr(1));
97 spec = SpecialIndex::NOT_SET;
98 }
else if (!
index.empty() &&
index[0] ==
'v') {
105 if (params.
count() > 2 && !params[2].empty()) {
106 period = lexCast<int>(params[2],
"Incorrect value for a period: " + params[2]);
110 if (!workspaceOptional)
113 auto wsg = std::dynamic_pointer_cast<API::WorkspaceGroup>(workspaceOptional.value());
114 auto wsMatrix = std::dynamic_pointer_cast<API::MatrixWorkspace>(workspaceOptional.value());
118 }
else if (wsMatrix) {
119 addMatrixworkspace(nameList, start, end, name, wi, spec, period, workspaceOptional, wsMatrix);
124void addMatrixworkspace(std::vector<InputSpectraToFit> &nameList,
double start,
double end, std::string &name,
int wi,
125 int spec,
int period,
const boost::optional<API::Workspace_sptr> &workspaceOptional,
126 const std::shared_ptr<API::MatrixWorkspace> &wsMatrix) {
129 for (
auto workspaceIndex : workspaceIndices) {
130 nameList.emplace_back(name, workspaceIndex, period);
131 if (workspaceOptional) {
132 nameList.back().ws = wsMatrix;
136void addGroupWorkspace(std::vector<InputSpectraToFit> &nameList,
double start,
double end,
int wi,
int spec,
int period,
137 const std::shared_ptr<API::WorkspaceGroup> &wsg) {
138 const std::vector<std::string> wsNames = wsg->getNames();
140 for (
const auto &wsName : wsNames) {
145 for (
auto workspaceIndex : workspaceIndices) {
146 nameList.emplace_back(wsName, workspaceIndex, period);
162 double start,
double end) {
163 if (workspaceIndex >= 0) {
164 return std::vector<int>({workspaceIndex});
166 std::vector<int> out;
169 if (spectrumNumber < 0) {
170 for (
size_t i = 0; i < axis->
length(); ++i) {
172 if (s >= start && s <= end) {
173 out.emplace_back(
static_cast<int>(i));
178 for (
size_t i = 0; i < axis->
length(); ++i) {
180 if (j == spectrumNumber) {
181 out.emplace_back(
static_cast<int>(i));
187 if (workspaceIndex <= SpecialIndex::WHOLE_RANGE) {
189 end = (*axis)(axis->
length() - 1);
191 for (
size_t i = 0; i < axis->
length(); ++i) {
192 double s = (*axis)(i);
193 if (s >= start && s <= end) {
194 out.emplace_back(
static_cast<int>(i));
202boost::optional<API::Workspace_sptr>
getWorkspace(
const std::string &workspaceName,
int period) {
206 std::string::size_type i = workspaceName.find_last_of(
'.');
207 if (i == std::string::npos) {
208 g_log.
warning() <<
"Cannot open file " << workspaceName <<
"\n";
212 load->setChild(
true);
214 load->setPropertyValue(
"FileName", workspaceName);
215 load->setProperty(
"OutputWorkspace",
"__NotUsed");
216 load->setRethrows(
false);
218 if (load->isExecuted()) {
221 if (std::dynamic_pointer_cast<DataObjects::Workspace2D>(rws)) {
226 std::string propName =
"OUTPUTWORKSPACE_" +
std::to_string(period);
227 if (load->existsProperty(propName)) {
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
Class to represent the axis of a workspace.
virtual specnum_t spectraNo(const std::size_t &index) const
Get the spectrum number.
virtual std::size_t length() const =0
Get the length of the axis.
virtual bool isSpectra() const
Returns true is the axis is a Spectra axis.
Base MatrixWorkspace Abstract Class.
virtual Axis * getAxis(const std::size_t &axisIndex) const
Get a non owning pointer to a workspace axis.
The Logger class is in charge of the publishing messages from the framework through various channels.
void warning(const std::string &msg)
Logs at warning level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
std::size_t count() const
Get the total number of tokens.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
Type lexCast(std::string input, const std::string &errorMessage)
void parseValueRange(const std::string &index, double &start, double &end, int &wi, int &spec)
void addGroupWorkspace(std::vector< InputSpectraToFit > &nameList, double start, double end, int wi, int spec, int period, const std::shared_ptr< API::WorkspaceGroup > &wsg)
MANTID_CURVEFITTING_DLL std::vector< InputSpectraToFit > makeNames(const std::string &inputList, int default_wi, int default_spec)
Create a list of input workspace names.
MANTID_CURVEFITTING_DLL boost::optional< API::Workspace_sptr > getWorkspace(const std::string &name, int period)
void addMatrixworkspace(std::vector< InputSpectraToFit > &nameList, double start, double end, std::string &name, int wi, int spec, int period, const boost::optional< API::Workspace_sptr > &workspaceOptional, const std::shared_ptr< API::MatrixWorkspace > &wsMatrix)
MANTID_CURVEFITTING_DLL std::vector< int > getWorkspaceIndicesFromAxes(API::MatrixWorkspace &ws, int workspaceIndex, int spectrumNumber, double start, double end)
Get a workspace.
std::string to_string(const wide_integer< Bits, Signed > &n)