Newer
Older
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
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidAlgorithms/ClearMaskedSpectra.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/SpectrumInfo.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
namespace Mantid {
namespace Algorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ClearMaskedSpectra)
/// Algorithms name for identification. @see Algorithm::name
const std::string ClearMaskedSpectra::name() const {
return "ClearMaskedSpectra";
}
/// Algorithm's version for identification. @see Algorithm::version
int ClearMaskedSpectra::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string ClearMaskedSpectra::category() const {
return "Transforms\\Masking";
}
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string ClearMaskedSpectra::summary() const {
return "Clear counts and/or events in all fully masked spectra.";
}
void ClearMaskedSpectra::init() {
declareProperty(Kernel::make_unique<WorkspaceProperty<>>(
"InputWorkspace", "The input workspace", Direction::Input));
declareProperty(
Kernel::make_unique<WorkspaceProperty<>>("OutputWorkspace", "",
Direction::Output),
"Name of the output workspace (can be same as InputWorkspace)");
}
void ClearMaskedSpectra::exec() {
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
if (outputWS != inputWS) {
outputWS = inputWS->clone();
setProperty("OutputWorkspace", outputWS);
}
const auto &spectrumInfo = outputWS->spectrumInfo();
for (size_t i = 0; i < spectrumInfo.size(); ++i)
if (spectrumInfo.hasDetectors(i) && spectrumInfo.isMasked(i))
outputWS->getSpectrum(i).clearData();
if (auto event = dynamic_cast<DataObjects::EventWorkspace *>(outputWS.get()))
event->clearMRU();
}
} // namespace Algorithms
} // namespace Mantid