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"
39using namespace Kernel;
40using namespace RunCombinationOptions;
41using namespace DataObjects;
42using namespace HistogramData;
45static const std::string INPUT_WORKSPACE_PROPERTY =
"InputWorkspaces";
46static const std::string OUTPUT_WORKSPACE_PROPERTY =
"OutputWorkspace";
47static const std::string SAMPLE_LOG_X_AXIS_PROPERTY =
"SampleLogAsXAxis";
74 return "Joins the input workspaces horizontally by appending their columns.";
83 "The names of the input workspaces or workspace groups as a list. At "
84 "least two point-data MatrixWorkspaces are "
85 "required, having the same instrument, same number of spectra and "
88 "The name of the numeric sample log to become the x-axis of the output. "
89 "Empty by default, in which case the x-axis of the input "
90 "workspaces are stitched. "
91 "If specified, this will be the x-axis. It has to be numeric, in which "
92 "case all the input workspaces must have only one point or numeric "
93 "time series, in which case the number "
94 "of elements in the series must match the number of points for each "
97 "The output workspace.");
109 "Choose whether to skip the workspace and continue, or stop and "
110 "throw and error, when encountering a failure on merging.");
112 "LinearizeAxis",
false,
113 "Choose to set a linear x-axis starting from 1, can be used only if the workspaces have common bins.");
117 std::map<std::string, std::string> issues;
119 const std::vector<std::string> inputs_given =
getProperty(INPUT_WORKSPACE_PROPERTY);
122 std::vector<std::string> workspaces;
125 }
catch (
const std::exception &e) {
126 issues[INPUT_WORKSPACE_PROPERTY] = std::string(e.what());
131 for (
const auto &input : workspaces) {
134 issues[INPUT_WORKSPACE_PROPERTY] +=
"Workspace " + input +
" is not a MatrixWorkspace\n";
135 }
else if (ws->isHistogramData()) {
136 issues[INPUT_WORKSPACE_PROPERTY] +=
"Workspace " + ws->
getName() +
" is not a point-data\n";
140 }
catch (std::length_error &) {
141 issues[INPUT_WORKSPACE_PROPERTY] +=
142 "Workspace " + ws->getName() +
" has different number of points per histogram\n";
149 issues[INPUT_WORKSPACE_PROPERTY] +=
"There are no point-data"
150 " MatrixWorkspaces in the input list\n";
158 if (!compatible.empty()) {
159 issues[INPUT_WORKSPACE_PROPERTY] +=
"Workspace " + ws->getName() +
" is not compatible: " + compatible +
"\n";
163 if (!logValid.empty()) {
164 issues[INPUT_WORKSPACE_PROPERTY] +=
"Invalid sample log entry for " + ws->getName() +
": " + logValid +
"\n";
169 auto notCommon = std::find_if(
m_inputWS.cbegin(),
m_inputWS.cend(), [](
auto ws) { return !ws->isCommonBins(); });
171 issues[INPUT_WORKSPACE_PROPERTY] +=
172 "Workspace " + (*notCommon)->getName() +
" is ragged, which is not allowed if linearize axis is requested.\n";
190 const auto &run = ws->run();
193 result =
"Log entry does not exist";
200 const auto blocksize =
static_cast<int>(ws->y(0).size());
207 if (timeSeriesDouble) {
208 if (blocksize != timeSeriesDouble->
size()) {
209 result =
"Size of the double time series does not match the blocksize";
211 }
else if (timeSeriesInt) {
212 if (blocksize != timeSeriesInt->
size()) {
213 result =
"Size of the int time series does not match the blocksize";
217 if (ws->blocksize() != 1) {
218 result =
"One bin workspaces is required if the log is numeric scalar";
221 }
catch (std::invalid_argument &) {
222 result =
"Log entry must be numeric or numeric time series";
236 std::vector<double> axis;
237 const size_t s = ws->y(0).
size();
239 auto &run = ws->run();
241 for (
double ix = xstart; ix < xstart + double(s); ++ix) {
247 const TimeROI &timeroi = run.getTimeROI();
251 if (timeSeriesDouble) {
260 axis = std::vector<double>(intAxis.begin(), intAxis.end());
263 axis.emplace_back(run.getPropertyAsSingleValue(
m_logEntry));
280 m_outWS->history().addHistory(inWS->getHistory());
296 std::vector<double> spectrum;
297 std::vector<double> errors;
298 std::vector<double> axis;
299 std::vector<double> xerrors;
300 const auto index =
static_cast<size_t>(wsIndex);
302 spectrum.reserve(ySize);
303 errors.reserve(ySize);
305 xerrors.reserve(ySize);
307 const auto &
y = input->y(
index);
308 spectrum.insert(spectrum.end(),
y.begin(),
y.end());
309 const auto &e = input->e(
index);
310 errors.insert(errors.end(), e.begin(), e.end());
313 axis.insert(axis.end(),
x.begin(),
x.end());
315 const auto &
x = input->x(
index);
316 axis.insert(axis.end(),
x.begin(),
x.end());
318 if (input->hasDx(
index)) {
319 const auto &dx = input->dx(
index);
320 xerrors.insert(xerrors.end(), dx.begin(), dx.end());
325 m_outWS->setCountStandardDeviations(
index, std::move(errors));
326 if (!xerrors.empty())
327 m_outWS->setPointStandardDeviations(
index, std::move(xerrors));
335 const std::vector<std::string> inputs_given =
getProperty(INPUT_WORKSPACE_PROPERTY);
346 const std::string sampleLogsFailBehaviour =
getProperty(
"FailBehaviour");
375 size_t outBlockSize = (*it)->y(0).size();
377 for (++it; it !=
m_inputWS.end(); ++it) {
382 outBlockSize += (*it)->y(0).size();
383 }
catch (std::invalid_argument &e) {
385 g_log.
error() <<
"Could not join workspace: " << (*it)->getName() <<
". Reason: \"" << e.what()
386 <<
"\". Skipping.\n";
392 throw std::invalid_argument(e);
398 g_log.
warning() <<
"Nothing left to join [after skipping the workspaces "
399 "that failed to merge the sample logs].";
412 size_t numSpec = first->getNumberHistograms();
414 m_outWS = create<MatrixWorkspace>(*first, Points(outBlockSize));
417 m_outWS->mutableRun() = temp->run();
419 m_progress = std::make_unique<Progress>(
this, 0.0, 1.0, numSpec);
423 for (int64_t
index = 0; index < static_cast<int64_t>(numSpec); ++
index) {
432 std::string unit = first->run().getLogData(
m_logEntry)->units();
434 m_outWS->getAxis(0)->unit() = UnitFactory::Instance().create(unit);
436 m_outWS->getAxis(0)->unit() = UnitFactory::Instance().create(
"Empty");
#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.
TimeROI : Object that holds information about when the time measurement was active.
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.
virtual std::vector< TYPE > filteredValuesAsVector(const Kernel::TimeROI *roi) 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.