28 const std::string &workspacePropertyName)
34 if (nDomainColumns > 0) {
36 for (
size_t i = 1; i < nDomainColumns; ++i) {
42 if (nDataColumns > 0) {
45 for (
size_t i = 1; i < nDataColumns; ++i) {
80 auto tableWorkspace = std::dynamic_pointer_cast<API::ITableWorkspace>(ws);
81 if (!tableWorkspace) {
82 throw std::invalid_argument(
"InputWorkspace must be a TableWorkspace.");
84 return tableWorkspace;
95 std::shared_ptr<FunctionValues> &values,
size_t i0) {
105 size_t domainSize = 0;
112 auto column = tableWorkspace->getColumn(columnName);
113 generalDomain.addColumn(column);
115 domainSize = domain->size();
121 if (!tableWorkspace) {
125 if (domainSize == 0) {
126 domainSize = tableWorkspace->rowCount();
130 if (domainSize == 0) {
137 for (
size_t i = 0; i < nDataColumns; ++i) {
140 auto dataColumn = tableWorkspace->getColumn(columnName);
141 values->expand(i0 + domainSize);
142 for (
size_t j = 0; j < domainSize; ++j) {
143 values->setFitData(i0 + j, dataColumn->toDouble(j));
147 if (!columnName.empty()) {
148 auto weightsColumn = tableWorkspace->getColumn(columnName);
149 for (
size_t j = 0; j < domainSize; ++j) {
150 values->setFitWeight(i0 + j, weightsColumn->toDouble(j));
153 for (
size_t j = 0; j < domainSize; ++j) {
154 values->setFitWeight(i0 + j, 1.0);
174 std::shared_ptr<FunctionDomain> domain,
175 std::shared_ptr<FunctionValues> values,
176 const std::string &outputWorkspacePropertyName) {
177 if (function->getValuesSize(*domain) != values->size()) {
178 throw std::runtime_error(
"Failed to create output workspace: domain and "
179 "values object don't match.");
181 size_t rowCount = domain->size();
191 if (inputWorkspace) {
193 std::vector<std::string> columnsToClone;
196 columnsToClone.emplace_back(columnName);
200 columnsToClone.emplace_back(columnName);
202 outputWorkspace = inputWorkspace->cloneColumns(columnsToClone);
203 if (rowCount != outputWorkspace->rowCount()) {
204 throw std::runtime_error(
"Cloned workspace has wrong number of rows.");
211 auto calcColumnName = dataColumnName +
"_calc";
212 auto column = outputWorkspace->addColumn(
"double", calcColumnName);
213 for (
size_t row = 0; row < rowCount; ++row) {
214 auto value = values->getCalculated(i0 + row);
215 column->fromDouble(row,
value);
221 outputWorkspace->setRowCount(rowCount);
225 if (calcColumnName.empty()) {
226 calcColumnName = propName;
228 auto column = outputWorkspace->addColumn(
"double", calcColumnName);
229 for (
size_t row = 0; row < rowCount; ++row) {
230 auto value = values->getCalculated(i0 + row);
231 column->fromDouble(row,
value);
237 if (!outputWorkspacePropertyName.empty()) {
240 "Name of the output Workspace holding resulting simulated values");
245 return outputWorkspace;
254 size_t domainSize = 0;
257 domainSize = inputWorkspace->rowCount();
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Represent a domain of a very general type.
A class to store values calculated by a function.
An base class for domain creators for use in Fit.
std::vector< std::string > m_workspacePropertyNames
Property names for workspaces to get the data from.
Kernel::IPropertyManager * m_manager
Pointer to a property manager.
void declareProperty(Kernel::Property *prop, const std::string &doc)
Declare a property to the algorithm.
IFunctionGeneral: a very general function definition.
virtual size_t getNumberDomainColumns() const =0
Get number of columns that the domain must have.
virtual size_t getDefaultDomainSize() const
Get the default size of a domain.
virtual size_t getNumberValuesPerArgument() const =0
Get number of values per argument in the domain.
A property class for workspaces.
void createDomain(std::shared_ptr< API::FunctionDomain > &domain, std::shared_ptr< API::FunctionValues > &values, size_t i0=0) override
Creates a domain corresponding to the assigned MatrixWorkspace.
std::vector< std::string > m_weightsColumnNames
Property names for columns in a TableWorkspace to be used as the fitting weights.
std::vector< std::string > m_dataColumnNames
Property names for columns in a TableWorkspace to be used as the data to fit to.
size_t getDomainSize() const override
Returns the domain size.
GeneralDomainCreator(const API::IFunctionGeneral &fun, Kernel::IPropertyManager &manager, const std::string &workspacePropertyName)
Constructor.
API::Workspace_sptr createOutputWorkspace(const std::string &baseName, API::IFunction_sptr function, std::shared_ptr< API::FunctionDomain > domain, std::shared_ptr< API::FunctionValues > values, const std::string &outputWorkspacePropertyName="OutputWorkspace") override
Creates an output workspace using the given function and domain.
std::vector< std::string > m_domainColumnNames
Property names for columns in a TableWorkspace to be passed to the domain.
void declareDatasetProperties(const std::string &suffix="", bool addProp=true) override
Declare properties that specify the dataset within the workspace to fit to.
std::shared_ptr< API::ITableWorkspace > getInputWorkspace() const
Retrive the input workspace from the property manager.
size_t m_defaultValuesSize
Default number of values.
Interface to PropertyManager.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
virtual bool existsProperty(const std::string &name) const =0
Checks whether the named property is already in the list of managed property.
virtual TypedValue getProperty(const std::string &name) const =0
Get the value of a property.
virtual std::string getPropertyValue(const std::string &name) const =0
Get the value of a property as a string.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Output
An output workspace.