1 | from mantid.simpleapi import _set_properties |
---|
2 | |
---|
3 | class SubAlg(PythonAlgorithm): |
---|
4 | |
---|
5 | def PyInit(self): |
---|
6 | pass |
---|
7 | |
---|
8 | def PyExec(self): |
---|
9 | #this algorithm should never show up in history! |
---|
10 | pass |
---|
11 | |
---|
12 | AlgorithmFactory.subscribe(SubAlg) |
---|
13 | |
---|
14 | |
---|
15 | class BasicAlg(PythonAlgorithm): |
---|
16 | |
---|
17 | def PyInit(self): |
---|
18 | pass |
---|
19 | |
---|
20 | def PyExec(self): |
---|
21 | alg = self.createChildAlgorithm('SubAlg') |
---|
22 | alg.initialize() |
---|
23 | args = {} |
---|
24 | kwargs = {} |
---|
25 | _set_properties(alg, *args, **kwargs) |
---|
26 | alg.execute() |
---|
27 | |
---|
28 | |
---|
29 | AlgorithmFactory.subscribe(BasicAlg) |
---|
30 | |
---|
31 | class ChildAlg(DataProcessorAlgorithm): |
---|
32 | |
---|
33 | def PyInit(self): |
---|
34 | pass |
---|
35 | |
---|
36 | def PyExec(self): |
---|
37 | alg = self.createChildAlgorithm('BasicAlg') |
---|
38 | alg.initialize() |
---|
39 | args = {} |
---|
40 | kwargs = {} |
---|
41 | _set_properties(alg, *args, **kwargs) |
---|
42 | alg.execute() |
---|
43 | |
---|
44 | |
---|
45 | AlgorithmFactory.subscribe(ChildAlg) |
---|
46 | |
---|
47 | class ParentAlg(DataProcessorAlgorithm): |
---|
48 | |
---|
49 | def PyInit(self): |
---|
50 | self.declareProperty(MatrixWorkspaceProperty('OutputWorkspace', '', Direction.Output), |
---|
51 | doc="Name to give the output workspace.") |
---|
52 | |
---|
53 | def PyExec(self): |
---|
54 | ws_name = self.getPropertyValue("OutputWorkspace") |
---|
55 | alg = self.createChildAlgorithm('ChildAlg') |
---|
56 | alg.initialize() |
---|
57 | args = {} |
---|
58 | kwargs = {} |
---|
59 | _set_properties(alg, *args, **kwargs) |
---|
60 | alg.execute() |
---|
61 | |
---|
62 | ws = CreateWorkspace([0, 1, 2], [0, 1, 2], OutputWorkspace=ws_name) |
---|
63 | self.setProperty('OutputWorkspace', ws) |
---|
64 | |
---|
65 | AlgorithmFactory.subscribe(ParentAlg) |
---|
66 | |
---|
67 | ############################################################# |
---|
68 | |
---|
69 | ws_name = '__tmp_test_algorithm_history' |
---|
70 | |
---|
71 | alg = AlgorithmManager.createUnmanaged('ParentAlg') |
---|
72 | alg.initialize() |
---|
73 | alg.setProperty("OutputWorkspace", ws_name) |
---|
74 | alg.execute() |
---|
75 | history = mtd[ws_name].getHistory() |
---|
76 | |
---|
77 | alg_hists = history.getAlgorithmHistories() |
---|
78 | assert history.size() == 1 |
---|
79 | assert len(alg_hists) == 1 |
---|
80 | |
---|
81 | alg_history = history.getAlgorithmHistory(0) |
---|
82 | assert alg_history.name() == "ParentAlg" |
---|
83 | assert alg_history.childHistorySize() == 2 |
---|
84 | |
---|
85 | child_history = alg_history.getChildAlgorithmHistory(0) |
---|
86 | assert child_history.name() == "ChildAlg" |
---|
87 | assert child_history.childHistorySize() == 1 |
---|
88 | |
---|
89 | create_workspace_history = alg_history.getChildAlgorithmHistory(1) |
---|
90 | assert create_workspace_history.name() == "CreateWorkspace" |
---|
91 | assert len(create_workspace_history.getProperties()) == 12 |
---|
92 | assert create_workspace_history.childHistorySize() == 0 |
---|
93 | |
---|
94 | basic_history = child_history.getChildAlgorithmHistory(0) |
---|
95 | assert basic_history.name() == "BasicAlg" |
---|
96 | assert basic_history.childHistorySize() == 0 |
---|