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
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
#include "MantidAPI/Algorithm.h"
// ArrayProperty Implementation
#include "MantidAPI/IndexProperty.h"
#include "MantidAPI/WorkspaceProperty.h"
#include <MantidKernel/ArrayProperty.tcc>
namespace Mantid {
namespace API {
/** Declare a property which defines the workspace and allowed index types, as
* well as a property for capturing the indices all at once. This method is
* only enabled if T is convertible to MatrixWorkspace.
@param propertyName Name of property which will be reserved
@param allowedIndexTypes combination of allowed index types. Default
IndexType::WorkspaceIndex
@param optional Determines if workspace property is optional. Default
PropertyMode::Type::Mandatory
@param lock Determines whether or not the workspace is locked. Default
LockMode::Type::Lock
@param doc Property documentation string.
*/
template <typename T, typename>
void Algorithm::declareIndexProperty(const std::string &propertyName,
const int allowedIndexTypes,
PropertyMode::Type optional,
LockMode::Type lock,
const std::string &doc) {
declareProperty(
Kernel::make_unique<WorkspaceProperty<T>>(
propertyName, "", Kernel::Direction::Input, optional, lock),
doc);
declareProperty(Kernel::make_unique<IndexTypeProperty>(
propertyName + "IndexType", allowedIndexTypes));
auto *wsProp =
dynamic_cast<WorkspaceProperty<T> *>(getPointerToProperty(propertyName));
auto *indexTypeProp = dynamic_cast<IndexTypeProperty *>(
getPointerToProperty(propertyName + "IndexType"));
declareProperty(Kernel::make_unique<IndexProperty>(propertyName + "IndexSet",
*wsProp, *indexTypeProp));
m_reservedList.push_back(propertyName);
m_reservedList.push_back(propertyName + "IndexType");
m_reservedList.push_back(propertyName + "IndexSet");
}
/** Mechanism for setting the index property with a workspace shared pointer.
* This method can only be used if T1 is convertible to a MatrixWorkspace and
* T2 is either std::string or std::vector<int>
@param name Property name
@param wksp Workspace as a pointer
@param type Index type IndexType::WorkspaceIndex or IndexType::SpectrumNum
@param list List of indices to be used.
*/
template <typename T1, typename T2, typename, typename>
void Algorithm::setIndexProperty(const std::string &name,
const boost::shared_ptr<T1> &wksp,
IndexType type, const T2 &list) {
if (!isCompoundProperty(name))
throw std::runtime_error("Algorithm::setIndexProperty can only be used "
"with properties declared using "
"declareIndexProperty.");
auto *wsProp =
dynamic_cast<WorkspaceProperty<T1> *>(getPointerToProperty(name));
auto *indexTypeProp = dynamic_cast<IndexTypeProperty *>(
getPointerToProperty(name + "IndexType"));
auto *indexProp =
dynamic_cast<IndexProperty *>(getPointerToProperty(name + "IndexSet"));
*wsProp = wksp;
*indexTypeProp = type;
*indexProp = list;
}
/** Mechanism for setting the index property with a workspace shared pointer.
* This method can only be used if T1 is convertible to a MatrixWorkspace and
* T2 is either std::string or std::vector<int>
@param name Property name
@param wsName Workspace as a pointer
@param type Index type IndexType::WorkspaceIndex or IndexType::SpectrumNum
@param list List of indices to be used.
*/
template <typename T1, typename T2, typename, typename>
void Algorithm::setIndexProperty(const std::string &name,
const std::string &wsName, IndexType type,
const T2 &list) {
if (!isCompoundProperty(name))
throw std::runtime_error("Algorithm::setIndexProperty can only be used "
"with properties declared using "
"declareIndexProperty.");
auto *wsProp =
dynamic_cast<WorkspaceProperty<T1> *>(getPointerToProperty(name));
auto *indexTypeProp = dynamic_cast<IndexTypeProperty *>(
getPointerToProperty(name + "IndexType"));
auto *indexProp =
dynamic_cast<IndexProperty *>(getPointerToProperty(name + "IndexSet"));
wsProp->setValue(wsName);
*indexTypeProp = type;
*indexProp = list;
}
/** Mechanism for retriving the index property. This method can only be used
if T is convertible to a MatrixWorkspace.
@param name Property name
@returns Tuple containing Workspace shared pointer and SpectrumIndexSet
*/
template <typename T, typename>
std::tuple<boost::shared_ptr<T>, Indexing::SpectrumIndexSet>
Algorithm::getIndexProperty(const std::string &name) const {
if (!isCompoundProperty(name))
throw std::runtime_error("Algorithm::getIndexProperty can only be used "
"with properties declared using "
"declareIndexProperty.");
auto *wsProp =
dynamic_cast<WorkspaceProperty<T> *>(getPointerToProperty(name));
auto *indexProp =
dynamic_cast<IndexProperty *>(getPointerToProperty(name + "IndexSet"));
return std::make_tuple(boost::dynamic_pointer_cast<T>(wsProp->getWorkspace()),
indexProp->getIndices());
}
} // namespace API
} // namespace Mantid