Mantid
Loading...
Searching...
No Matches
MergeRuns.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
12#include "MantidAlgorithms/DllConfig.h"
15
16#include <list>
17#include <optional>
18
19namespace Mantid {
20namespace API {
21class WorkspaceGroup;
22}
23namespace HistogramData {
24class HistogramX;
25}
26namespace Algorithms {
52namespace MergeRunsParameter {
54static const std::string SUM_MERGE = "sample_logs_sum";
55static const std::string TIME_SERIES_MERGE = "sample_logs_time_series";
56static const std::string LIST_MERGE = "sample_logs_list";
57static const std::string WARN_MERGE = "sample_logs_warn";
58static const std::string WARN_MERGE_TOLERANCES = "sample_logs_warn_tolerances";
59static const std::string FAIL_MERGE = "sample_logs_fail";
60static const std::string FAIL_MERGE_TOLERANCES = "sample_logs_fail_tolerances";
61} // namespace MergeRunsParameter
62
63class MANTID_ALGORITHMS_DLL MergeRuns : public API::MultiPeriodGroupAlgorithm {
64public:
66 const std::string name() const override { return "MergeRuns"; }
68 const std::string summary() const override {
69 return "Combines the data contained in an arbitrary number of input "
70 "workspaces.";
71 }
72
74 int version() const override { return 1; }
75 const std::vector<std::string> seeAlso() const override { return {"ConjoinWorkspaces"}; }
77 const std::string category() const override { return "Transforms\\Merging"; }
78 // Overriden MultiPeriodGroupAlgorithm method.
79 bool useCustomInputPropertyName() const override;
80
81protected:
84 void fillHistory() override;
85
86private:
87 // Overridden Algorithm methods
88 void init() override;
89 void exec() override;
90 void execEvent();
91 void execHistogram(const std::vector<std::string> &inputs);
92 void buildAdditionTables();
93 // Overriden MultiPeriodGroupAlgorithm method.
94 std::string fetchInputPropertyName() const override;
95
99 using AdditionTable = std::vector<std::pair<int, int>>;
101 template <typename Container> void copyHistoryFromInputWorkspaces(const Container &workspaces) {
102 API::Workspace_sptr outWS = this->getProperty("OutputWorkspace");
103
104 // this is not a child algorithm. Add the history algorithm to the
105 // WorkspaceHistory object.
106 if (!isChild()) {
107 // Loop over the input workspaces, making the call that copies their
108 // history to the output ones
109 // (Protection against copy to self is in
110 // WorkspaceHistory::copyAlgorithmHistory)
111 for (auto inWS = workspaces.begin(); inWS != workspaces.end(); ++inWS) {
112 outWS->history().addHistory((*inWS)->getHistory());
113 }
114 // Add the history for the current algorithm to all the output workspaces
115 outWS->history().addHistory(m_history);
116 }
117 // this is a child algorithm, but we still want to keep the history.
118 else if (isRecordingHistoryForChild() && m_parentHistory) {
119 m_parentHistory->addChildHistory(m_history);
120 }
121 }
122
123 // Methods called by exec()
125 bool validateInputsForEventWorkspaces(const std::vector<std::string> &inputWorkspaces);
126 std::optional<std::vector<double>> checkRebinning();
127 static std::vector<double> calculateRebinParams(const std::vector<double> &bins1, const std::vector<double> &bins2);
128 static void noOverlapParams(const HistogramData::HistogramX &X1, const HistogramData::HistogramX &X2,
129 std::vector<double> &params);
130 static void intersectionParams(const HistogramData::HistogramX &X1, size_t &i, const HistogramData::HistogramX &X2,
131 std::vector<double> &params);
132 static void inclusionParams(const HistogramData::HistogramX &X1, size_t &i, const HistogramData::HistogramX &X2,
133 std::vector<double> &params);
134 API::MatrixWorkspace_sptr rebinInput(const API::MatrixWorkspace_sptr &workspace, const std::vector<double> &params);
135 API::MatrixWorkspace_sptr buildScanningOutputWorkspace(const API::MatrixWorkspace_sptr &outWS,
136 const API::MatrixWorkspace_sptr &addee);
138 std::unique_ptr<API::Progress> m_progress;
139
141 std::vector<Mantid::DataObjects::EventWorkspace_sptr> m_inEventWS;
143 std::list<API::MatrixWorkspace_sptr> m_inMatrixWS;
145 std::vector<AdditionTable> m_tables;
147 size_t m_outputSize = 0;
148
149 std::vector<SpectrumDefinition> buildScanIntervals(const std::vector<SpectrumDefinition> &addeeSpecDefs,
150 const Geometry::DetectorInfo &addeeDetInfo,
151 const Geometry::DetectorInfo &newOutDetInfo);
152};
153
154} // namespace Algorithms
155} // namespace Mantid
IPeaksWorkspace_sptr workspace
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
MutliPeriodGroupAlgorithm : Abstract algorithm.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition MergeRuns.h:66
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
Definition MergeRuns.h:77
void copyHistoryFromInputWorkspaces(const Container &workspaces)
Copy the history from the input workspaces to the output workspaces.
Definition MergeRuns.h:101
std::vector< Mantid::DataObjects::EventWorkspace_sptr > m_inEventWS
List of input EVENT workspaces.
Definition MergeRuns.h:141
std::unique_ptr< API::Progress > m_progress
Progress reporting.
Definition MergeRuns.h:138
int version() const override
Algorithm's version for identification overriding a virtual method.
Definition MergeRuns.h:74
const std::string summary() const override
Summary of algorithms purpose.
Definition MergeRuns.h:68
std::vector< AdditionTable > m_tables
Addition tables for event workspaces.
Definition MergeRuns.h:145
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso algorithms related to this algorithm.
Definition MergeRuns.h:75
std::list< API::MatrixWorkspace_sptr > m_inMatrixWS
List of input matrix workspace.
Definition MergeRuns.h:143
std::vector< std::pair< int, int > > AdditionTable
An addition table is a list of pairs: First int = workspace index in the EW being added,...
Definition MergeRuns.h:99
Models a Container is used to hold a sample in the beam.
Definition Container.h:24
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
static const std::string FAIL_MERGE_TOLERANCES
Definition MergeRuns.h:60
static const std::string WARN_MERGE_TOLERANCES
Definition MergeRuns.h:58
static const std::string WARN_MERGE
Definition MergeRuns.h:57
static const std::string FAIL_MERGE
Definition MergeRuns.h:59
static const std::string SUM_MERGE
MergeRuns parameter names of the paramter file for sample log merging.
Definition MergeRuns.h:54
static const std::string TIME_SERIES_MERGE
Definition MergeRuns.h:55
static const std::string LIST_MERGE
Definition MergeRuns.h:56
Helper class which provides the Collimation Length for SANS instruments.