21#include "MantidHistogramData/Histogram.h"
22#include "MantidHistogramData/HistogramDx.h"
23#include "MantidHistogramData/HistogramE.h"
24#include "MantidHistogramData/HistogramX.h"
25#include "MantidHistogramData/HistogramY.h"
26#include "MantidHistogramData/LinearGenerator.h"
38using namespace Kernel;
39using namespace RunCombinationOptions;
40using namespace DataObjects;
41using namespace HistogramData;
44static const std::string INPUT_WORKSPACE_PROPERTY =
"InputWorkspaces";
45static const std::string OUTPUT_WORKSPACE_PROPERTY =
"OutputWorkspace";
46static const std::string SAMPLE_LOG_X_AXIS_PROPERTY =
"SampleLogAsXAxis";
73 return "Joins the input workspaces horizontally by appending their columns.";
82 "The names of the input workspaces or workspace groups as a list. At "
83 "least two point-data MatrixWorkspaces are "
84 "required, having the same instrument, same number of spectra and "
87 "The name of the numeric sample log to become the x-axis of the output. "
88 "Empty by default, in which case the x-axis of the input "
89 "workspaces are stitched. "
90 "If specified, this will be the x-axis. It has to be numeric, in which "
91 "case all the input workspaces must have only one point or numeric "
92 "time series, in which case the number "
93 "of elements in the series must match the number of points for each "
96 "The output workspace.");
108 "Choose whether to skip the workspace and continue, or stop and "
109 "throw and error, when encountering a failure on merging.");
111 "LinearizeAxis",
false,
112 "Choose to set a linear x-axis starting from 1, can be used only if the workspaces have common bins.");
116 std::map<std::string, std::string> issues;
118 const std::vector<std::string> inputs_given =
getProperty(INPUT_WORKSPACE_PROPERTY);
121 std::vector<std::string> workspaces;
124 }
catch (
const std::exception &e) {
125 issues[INPUT_WORKSPACE_PROPERTY] = std::string(e.what());
130 for (
const auto &input : workspaces) {
133 issues[INPUT_WORKSPACE_PROPERTY] +=
"Workspace " + input +
" is not a MatrixWorkspace\n";
134 }
else if (ws->isHistogramData()) {
135 issues[INPUT_WORKSPACE_PROPERTY] +=
"Workspace " + ws->
getName() +
" is not a point-data\n";
139 }
catch (std::length_error &) {
140 issues[INPUT_WORKSPACE_PROPERTY] +=
141 "Workspace " + ws->getName() +
" has different number of points per histogram\n";
148 issues[INPUT_WORKSPACE_PROPERTY] +=
"There are no point-data"
149 " MatrixWorkspaces in the input list\n";
157 if (!compatible.empty()) {
158 issues[INPUT_WORKSPACE_PROPERTY] +=
"Workspace " + ws->getName() +
" is not compatible: " + compatible +
"\n";
162 if (!logValid.empty()) {
163 issues[INPUT_WORKSPACE_PROPERTY] +=
"Invalid sample log entry for " + ws->getName() +
": " + logValid +
"\n";
168 auto notCommon = std::find_if(
m_inputWS.cbegin(),
m_inputWS.cend(), [](
auto ws) { return !ws->isCommonBins(); });
170 issues[INPUT_WORKSPACE_PROPERTY] +=
171 "Workspace " + (*notCommon)->getName() +
" is ragged, which is not allowed if linearize axis is requested.\n";
189 const auto &run = ws->run();
192 result =
"Log entry does not exist";
199 const auto blocksize =
static_cast<int>(ws->y(0).size());
206 if (timeSeriesDouble) {
207 if (blocksize != timeSeriesDouble->
size()) {
208 result =
"Size of the double time series does not match the blocksize";
210 }
else if (timeSeriesInt) {
211 if (blocksize != timeSeriesInt->
size()) {
212 result =
"Size of the int time series does not match the blocksize";
216 if (ws->blocksize() != 1) {
217 result =
"One bin workspaces is required if the log is numeric scalar";
220 }
catch (std::invalid_argument &) {
221 result =
"Log entry must be numeric or numeric time series";
235 std::vector<double> axis;
236 const size_t s = ws->y(0).size();
238 auto &run = ws->run();
240 for (
double ix = xstart; ix < xstart + double(s); ++ix) {
248 if (timeSeriesDouble) {
257 axis = std::vector<double>(intAxis.begin(), intAxis.end());
260 axis.emplace_back(run.getPropertyAsSingleValue(
m_logEntry));
277 m_outWS->history().addHistory(inWS->getHistory());
293 std::vector<double> spectrum;
294 std::vector<double> errors;
295 std::vector<double> axis;
296 std::vector<double> xerrors;
297 const auto index =
static_cast<size_t>(wsIndex);
299 spectrum.reserve(ySize);
300 errors.reserve(ySize);
302 xerrors.reserve(ySize);
304 const auto &
y = input->y(
index);
305 spectrum.insert(spectrum.end(),
y.begin(),
y.end());
306 const auto &e = input->e(
index);
307 errors.insert(errors.end(), e.begin(), e.end());
310 axis.insert(axis.end(),
x.begin(),
x.end());
312 const auto &
x = input->x(
index);
313 axis.insert(axis.end(),
x.begin(),
x.end());
315 if (input->hasDx(
index)) {
316 const auto &dx = input->dx(
index);
317 xerrors.insert(xerrors.end(), dx.begin(), dx.end());
322 m_outWS->setCountStandardDeviations(
index, std::move(errors));
323 if (!xerrors.empty())
324 m_outWS->setPointStandardDeviations(
index, std::move(xerrors));
332 const std::vector<std::string> inputs_given =
getProperty(INPUT_WORKSPACE_PROPERTY);
343 const std::string sampleLogsFailBehaviour =
getProperty(
"FailBehaviour");
372 size_t outBlockSize = (*it)->y(0).size();
374 for (++it; it !=
m_inputWS.end(); ++it) {
379 outBlockSize += (*it)->y(0).size();
380 }
catch (std::invalid_argument &e) {
382 g_log.
error() <<
"Could not join workspace: " << (*it)->getName() <<
". Reason: \"" << e.what()
383 <<
"\". Skipping.\n";
389 throw std::invalid_argument(e);
395 g_log.
warning() <<
"Nothing left to join [after skipping the workspaces "
396 "that failed to merge the sample logs].";
409 size_t numSpec = first->getNumberHistograms();
411 m_outWS = create<MatrixWorkspace>(*first, Points(outBlockSize));
414 m_outWS->mutableRun() = temp->run();
416 m_progress = std::make_unique<Progress>(
this, 0.0, 1.0, numSpec);
420 for (int64_t
index = 0; index < static_cast<int64_t>(numSpec); ++
index) {
429 std::string unit = first->run().getLogData(
m_logEntry)->units();
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
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.
std::shared_ptr< AlgorithmHistory > m_parentHistory
Pointer to the parent history object (if set)
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
std::shared_ptr< AlgorithmHistory > m_history
Pointer to the history for the algorithm being executed.
bool isChild() const override
To query whether algorithm is a child.
bool isRecordingHistoryForChild()
Base MatrixWorkspace Abstract Class.
A property class for workspaces.
const std::string & getName() const override
Get the workspace name.
static const std::string WARN_MERGE
std::vector< double > getXAxis(const API::MatrixWorkspace_sptr &, double &) const
Return the to-be axis of the workspace dependent on the log entry.
static const std::string WARN_MERGE_TOLERANCES
void exec() override
Execute the algorithm.
std::unique_ptr< API::Progress > m_progress
Progress reporting.
static const std::string SUM_MERGE
ConjoinXRuns parameter names of the paramter file for sample log merging.
static const std::string TIME_SERIES_MERGE
std::string m_logEntry
Sample log entry name.
static const std::string FAIL_MERGE
std::list< API::MatrixWorkspace_sptr > m_inputWS
List of input matrix workspaces.
std::string checkLogEntry(const API::MatrixWorkspace_sptr &) const
Check if the log entry is valid.
const std::string category() const override
Algorithm's category for identification.
void fillHistory() override
Makes up the correct history of the output workspace.
const std::string name() const override
Algorithms name for identification.
static const std::string LIST_MERGE
void joinSpectrum(int64_t)
Joins the given spectrum for the list of workspaces.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
static const std::string FAIL_MERGE_TOLERANCES
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void init() override
Initialize the algorithm's properties.
API::MatrixWorkspace_sptr m_outWS
Output workspace.
std::map< std::string, std::vector< double > > m_axisCache
X-axis cache if sample log is given.
static std::vector< std::string > unWrapGroups(const std::vector< std::string > &)
Flattens the list of group workspaces (if any) into list of workspaces.
void setReferenceProperties(const API::MatrixWorkspace_sptr &)
Sets the properties of the reference (usually first) workspace, to later check the compatibility of t...
std::string checkCompatibility(const API::MatrixWorkspace_sptr &, bool checkNumberHistograms=false)
Compares the properties of the input workspace with the reference.
SampleLogsBehaviour : This class holds information relating to the behaviour of the sample log mergin...
static const std::string LIST_DOC
static const std::string FAIL_DOC
static const std::string WARN_DOC
static const std::string FAIL_PROP
static const std::string LIST_PROP
static const std::string TIME_SERIES_PROP
static const std::string TIME_SERIES_DOC
static const std::string SUM_DOC
static const std::string WARN_TOL_PROP
static const std::string FAIL_TOL_DOC
void setUpdatedSampleLogs(const API::MatrixWorkspace_sptr &outWS)
Set the values in the map to be the same as those in the output workspace.
static const std::string WARN_PROP
void resetSampleLogs(const API::MatrixWorkspace_sptr &ws)
Resets the sample logs in the workspace to the values in the map.
void mergeSampleLogs(const API::MatrixWorkspace_sptr &addeeWS, const API::MatrixWorkspace_sptr &outWS)
Create and update sample logs according to instrument parameters.
static const std::string FAIL_TOL_PROP
static const std::string SUM_PROP
static const std::string WARN_TOL_DOC
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
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...
A specialised Property class for holding a series of time-value pairs.
int size() const override
Returns the number of values at UNIQUE time intervals in the time series.
std::vector< TYPE > filteredValuesAsVector() const
Get filtered values as a vector.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
static const std::string STOP_BEHAVIOUR
static const std::string SKIP_BEHAVIOUR
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
std::string sampleLogsWarnTolerances
std::string sampleLogsWarn
std::string sampleLogsFail
std::string sampleLogsSum
std::string sampleLogsList
std::string sampleLogsTimeSeries
std::string sampleLogsFailTolerances
@ Output
An output workspace.