comparison m-toolbox/classes/@LTPDAworkbench/run.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % RUN runs all, or some of the pipelines in the given Workbench file.
2 %
3 % CALL:
4 %
5 % id = LTPDAworkbench.run('foo.lwb') % run all
6 % id = LTPDAworkbench.run('foo.lwb', 'pipeline1') % run 'pipeline1'
7 %
8 %
9 % Hewitson 20-07-10
10 %
11 % $Id: run.m,v 1.6 2011/04/07 14:52:22 hewitson Exp $
12 %
13
14 % TODO
15 % LTPDAworkbench.run('foo.lwb', 'plan') % run the plan (if there is one)
16
17
18 function UUID = run(varargin)
19
20 % Sort out the filename
21 filename = varargin{1};
22 [path, name, ext] = fileparts(filename);
23
24 if isempty(path)
25 filename = fullfile(pwd, filename);
26 end
27
28 if exist(filename, 'file') == 0
29 error(['File not found at ' filename]);
30 end
31
32 % Parse the XML file
33 f = java.io.File(filename);
34 parserFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
35 parserFactory.setValidating(false);
36 db = javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
37 doc = db.parse(f);
38
39 % Get the main document node
40 node = doc.getDocumentElement();
41
42 % Create a workbench instance
43 prefs = getappdata(0, 'LTPDApreferences');
44 mp = javaObjectEDT('mpipeline.main.MainWindow', prefdir, prefs);
45 UUID = ['LWB_' num2str(round(cputime.*100))];
46 javaMethodEDT('setInstanceIdentifier', mp, UUID);
47
48 disp(['Processing pipeline: ' filename]);
49 disp([' results will be in: ' UUID]);
50
51 % Read the pipelines
52 pipelines = mp.readPipelines(f, node);
53 pipelines = pipelines.toArray();
54
55 % read plan
56
57 % If execute plan
58
59 % else we do the stuff below
60
61 pnames = {};
62 if nargin == 2
63 if strcmpi(varargin{2}, 'plan')
64
65 plan = mp.readExecutionPlan(f, node);
66
67 error('LTPDA:LTPDAworkbench:Run', 'Plan execution needs to be written!');
68 else
69 pnames = varargin(2);
70 end
71 end
72
73 if nargin > 2
74 pnames = varargin(2:end);
75 end
76
77 % Run over the pipelines
78 for kk=1:numel(pipelines)
79
80
81 % Get the pipeline and canvas
82 pl = pipelines(kk);
83 canvas = pl.getCanvas;
84
85 if ~isempty(pnames)
86 if ~ismember(char(pl.getTitle), pnames)
87 continue;
88 end
89 end
90
91 % Reset all blocks
92 canvas.resetAllBlocks
93
94 % Execute constant blocks
95 LTPDAworkbench.executeConstants(canvas);
96
97 % Run until all blocks are executed
98 while canvas.getReadyBlocks.size > 0
99
100 % Get the blocks ready to run
101 blocks = canvas.getReadyBlocks;
102
103 % parse the ready blocks
104 [cmds, rbs] = LTPDAworkbench.parseBlocks(blocks, pl, genvarname(name));
105
106 % Execute commands
107 LTPDAworkbench.executeCommands(pl, cmds);
108
109 % Move forward
110 canvas.stepForwards();
111
112 % Clear old variables
113 LTPDAworkbench.clearBlockVariables(rbs);
114
115 end % End while blocks not executed
116 end % End loop over pipelines
117
118 % Dispose of the pipeline
119 mp.setLtpdaPreferences2([]);
120 mp.dispose();
121
122 disp(['Completed processing pipeline: ' filename]);
123 disp([' results are in: ' UUID]);
124
125
126 end
127