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