-
Notifications
You must be signed in to change notification settings - Fork 122
/
MergeRuns.h
168 lines (150 loc) · 6.76 KB
/
MergeRuns.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef MANTID_ALGORITHMS_MERGERUNS_H_
#define MANTID_ALGORITHMS_MERGERUNS_H_
#include <list>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <MantidAPI/MatrixWorkspace.h>
#include "MantidAPI/MultiPeriodGroupAlgorithm.h"
#include "MantidAPI/WorkspaceHistory.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidKernel/System.h"
#include <boost/shared_ptr.hpp>
#include <list>
#include <vector>
namespace Mantid {
namespace API {
class WorkspaceGroup;
}
namespace HistogramData {
class HistogramX;
}
namespace Algorithms {
/** Combines the data contained in an arbitrary number of input workspaces.
If the input workspaces do not have common binning, the bins in the output
workspace
will cover the entire range of all the input workspaces, with the largest
bin widths
used in areas of overlap.
The input workspaces must contain histogram data with the same number of
spectra,
units and instrument name in order for the algorithm to succeed.
Other than this it is currently left to the user to ensure that the
combination of the
workspaces is a valid operation.
Required Properties:
<UL>
<LI> InputWorkspaces - The names of the input workspace as a comma
separated list. </LI>
<LI> OutputWorkspace - The name of the output workspace which will contain
the combined inputs. </LI>
</UL>
@author Russell Taylor, Tessella Support Services plc
@date 22/09/2008
Copyright © 2008-9 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport MergeRuns : public API::MultiPeriodGroupAlgorithm {
public:
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "MergeRuns"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Combines the data contained in an arbitrary number of input "
"workspaces.";
}
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 1; }
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "Transforms\\Merging"; }
// Overriden MultiPeriodGroupAlgorithm method.
bool useCustomInputPropertyName() const override;
protected:
/// Overriden fillHistory method to correctly store history from merged
/// workspaces
void fillHistory() override;
private:
// Overridden Algorithm methods
void init() override;
void exec() override;
void execEvent();
void buildAdditionTables();
// Overriden MultiPeriodGroupAlgorithm method.
std::string fetchInputPropertyName() const override;
/// test the compatibility of the given workspace with others
void testCompatibility(API::MatrixWorkspace_const_sptr ws,
const std::string &xUnitID, const std::string &YUnit,
const bool dist, const std::string instrument) const;
/// An addition table is a list of pairs: First int = workspace index in the
/// EW being added, Second int = workspace index to which it will be added in
/// the OUTPUT EW. -1 if it should add a new entry at the end.
typedef std::vector<std::pair<int, int>> AdditionTable;
/// Copy the history from the input workspaces to the output workspaces
template <typename Container>
void copyHistoryFromInputWorkspaces(const Container &workspaces) {
API::Workspace_sptr outWS = this->getProperty("OutputWorkspace");
// this is not a child algorithm. Add the history algorithm to the
// WorkspaceHistory object.
if (!isChild()) {
// Loop over the input workspaces, making the call that copies their
// history to the output ones
// (Protection against copy to self is in
// WorkspaceHistory::copyAlgorithmHistory)
for (auto inWS = workspaces.begin(); inWS != workspaces.end(); ++inWS) {
outWS->history().addHistory((*inWS)->getHistory());
}
// Add the history for the current algorithm to all the output workspaces
outWS->history().addHistory(m_history);
}
// this is a child algorithm, but we still want to keep the history.
else if (isRecordingHistoryForChild() && m_parentHistory) {
m_parentHistory->addChildHistory(m_history);
}
}
// Methods called by exec()
using Mantid::API::Algorithm::validateInputs;
std::list<API::MatrixWorkspace_sptr>
validateInputs(const std::vector<std::string> &inputWorkspaces);
bool validateInputsForEventWorkspaces(
const std::vector<std::string> &inputWorkspaces);
void calculateRebinParams(const API::MatrixWorkspace_const_sptr &ws1,
const API::MatrixWorkspace_const_sptr &ws2,
std::vector<double> ¶ms) const;
void noOverlapParams(const HistogramData::HistogramX &X1,
const HistogramData::HistogramX &X2,
std::vector<double> ¶ms) const;
void intersectionParams(const HistogramData::HistogramX &X1, int64_t &i,
const HistogramData::HistogramX &X2,
std::vector<double> ¶ms) const;
void inclusionParams(const HistogramData::HistogramX &X1, int64_t &i,
const HistogramData::HistogramX &X2,
std::vector<double> ¶ms) const;
API::MatrixWorkspace_sptr
rebinInput(const API::MatrixWorkspace_sptr &workspace,
const std::vector<double> ¶ms);
/// Progress reporting
std::unique_ptr<API::Progress> m_progress;
/// List of input EVENT workspaces
std::vector<Mantid::DataObjects::EventWorkspace_sptr> m_inEventWS;
/// List of input matrix workspace
std::list<API::MatrixWorkspace_sptr> m_inMatrixWS;
/// Addition tables for event workspaces
std::vector<AdditionTable> m_tables;
/// Total number of histograms in the output workspace
size_t m_outputSize = 0;
};
} // namespace Algorithm
} // namespace Mantid
#endif /* MANTID_ALGORITHMS_MERGERUNS_H_ */