-
Notifications
You must be signed in to change notification settings - Fork 122
/
ClearUB.cpp
106 lines (94 loc) · 3.87 KB
/
ClearUB.cpp
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
#include "MantidCrystal/ClearUB.h"
#include "MantidAPI/ExperimentInfo.h"
#include "MantidAPI/MultipleExperimentInfos.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
namespace Mantid {
namespace Crystal {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ClearUB)
//----------------------------------------------------------------------------------------------
/// Algorithm's name for identification. @see Algorithm::name
const std::string ClearUB::name() const { return "ClearUB"; }
/// Algorithm's version for identification. @see Algorithm::version
int ClearUB::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string ClearUB::category() const { return "Crystal\\UBMatrix"; }
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ClearUB::init() {
declareProperty(make_unique<WorkspaceProperty<Workspace>>("Workspace", "",
Direction::InOut),
"Workspace to clear the UB from.");
declareProperty(
make_unique<PropertyWithValue<bool>>("DoesClear", false,
Direction::Output),
"Indicates action performed. DoesClear returns true only if one or more "
"OrientedLattices have been removed.");
}
/**
* Clear the Oriented Lattice from a single experiment info.
* @param experimentInfo : Experiment info to clear.
* @param dryRun : Flag to indicate that this is a dry run, and that no clearing
* should take place.
* @return true only if the UB was cleared.
*/
bool ClearUB::clearSingleExperimentInfo(ExperimentInfo *const experimentInfo,
const bool dryRun) const {
bool doesClear = false;
Sample &sampleObject = experimentInfo->mutableSample();
if (!sampleObject.hasOrientedLattice()) {
this->g_log.notice("Experiment Info has no oriented lattice.");
} else {
this->g_log.notice("Experiment Info has an oriented lattice.");
// Only actually clear the orientedlattice if this is NOT a dry run.
if (!dryRun) {
sampleObject.clearOrientedLattice();
}
doesClear = true;
}
return doesClear;
}
/**
* Perform the working for the algorithm.
* @param ws : Input or input/output workspace
* @param dryRun : Flag to indicate that this is a dry run.
* @return : True if the algorithm does result in the clearing of at least one
* UB.
*/
bool ClearUB::doExecute(Workspace *const ws, bool dryRun) {
bool doesClear = false;
ExperimentInfo *experimentInfo = dynamic_cast<ExperimentInfo *>(ws);
if (experimentInfo) {
doesClear = clearSingleExperimentInfo(experimentInfo, dryRun);
} else {
MultipleExperimentInfos *experimentInfos =
dynamic_cast<MultipleExperimentInfos *>(ws);
if (!experimentInfos) {
if (!dryRun) {
throw std::invalid_argument("Input workspace is neither of type "
"ExperimentInfo or MultipleExperimentInfo, "
"cannot process.");
}
} else {
const uint16_t nInfos = experimentInfos->getNumExperimentInfo();
for (uint16_t i = 0; i < nInfos; ++i) {
ExperimentInfo_sptr info = experimentInfos->getExperimentInfo(i);
doesClear = clearSingleExperimentInfo(info.get(), dryRun) || doesClear;
}
}
}
return doesClear;
}
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ClearUB::exec() {
Workspace_sptr ws = getProperty("Workspace");
bool doesClear = doExecute(ws.get(), false /* Not a dry run*/);
this->setProperty("DoesClear", doesClear);
}
} // namespace Crystal
} // namespace Mantid