comparison m-toolbox/test/aorepo_proto_test/UTN_repo_test_func.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 function varargout = UTN_repo_test_func(varargin)
2
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %
5 % DESCRIPTION: UTN_REPO_TEST_FUNC Tests the submit and retrieve of LTPDA objs in
6 % the AEI LTPDA database, from UTN, measuring the submit/retrieve time.
7 %
8 % CALL: s = UTN_repo_test_func(pl)
9 %
10 % INPUTS: pl - parameter list(s)
11 %
12 % OUTPUTS: s - a struct containing the results of the test. In detail:
13 %
14 % ret_time - time for retrieval (s)
15 % sub_time - time for submission (s)
16 % t - absolute time of test execution
17 % test_ID - test identifier, also repeated in saved file
18 % status - result of comparison between submitted and
19 % retrieved objs
20 % OBJids - submitted objs IDs assigned by database
21 % cid - submitted objs collection ID assigned by database
22 % start_time - beginning time of test execution
23 % stop_time - ending time of test execution
24 % obj_size - length (in s) of submitted tsdata AO (if applicable)
25 % sinfo - a struct with infos about the connection
26 %
27 % PARAMETER LIST:
28 % <key> <default value> <description>
29 % 'N_OBJ' 1 produces N_OBJ objects at a time.
30 % Insert 0 for random number of objects
31 % 'OBJ_TYPE 'ao' defines the object(s) to produce
32 % If empty or 'RAND', it will pick at random within
33 % the ltpda_uo class
34 % 'NSECS' 100 sets time series lenght for aos
35 % 'FS' 10 sets time series sampling frequency for aos
36 % 'SUBMIT' false actually performs the submit/retrieve test
37 % 'CONN' empty a conn struct if the connection was
38 % already open (for group tests)
39 % 'HOSTNAME' '130.75.117.67' the repository host IP (for individual tests)
40 % 'DBASE' 'ltpda_test' the database name (for individual tests)
41 % 'COLL_RETRIEVE' false retrieves via the submitted collection ID
42 % 'SAVE_OBJS' false saves the first produced obj
43 % 'OBJ_FILENAME' 'submit_trial_ao.xml' filename to save first produced obj
44 % 'SAVE_RESULTS' true saves the individual test results
45 % 'RESULTS_FILENAME' 'repo_test_UTN' filename to save results in
46 %
47 % VERSION: $Id: UTN_repo_test_func.m,v 1.14 2008/11/18 17:29:40 mauro Exp $
48 %
49 % HISTORY: 23-11-2007 M Hueller
50 % Creation
51 % 18-11-2008 M Hueller
52 % Formatted for OO toolbox
53 % Default plist extended
54 %
55 % M-FILE INFO: Get information about this methods by calling
56 % >> ao.getInfo('UTN_repo_test_func')
57 %
58 % Get information about a specified set-plist by calling:
59 % >> ao.getInfo('UTN_repo_test_func', 'None')
60 %
61 % SEE ALSO: run_UTN_repo_test
62 %
63 % SEE: <a href="matlab: help ao/Contents;">HELP: All Analysis Object Functions:</a>
64 % <a href="matlab: helpwin ao/Contents;">DOC: All Analysis Object Functions:</a>
65 %
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
68
69 %% Check if this is a call for parameters
70 if utils.helper.isinfocall(varargin{:})
71 varargout{1} = getInfo(varargin{3});
72 return
73 end
74
75 % Collect input variable names
76 in_names = cell(size(varargin));
77 for ii = 1:nargin
78 in_names{ii} = inputname(ii);
79 end
80
81 % Collect all plists
82 pls = utils.helper.collect_objects(varargin(:), 'plist', in_names);
83
84 %% ---------------- Produce one plist
85 if isa(pls, 'plist')
86 pls = combine(pls, getDefaultPL());
87 else
88 pls = getDefaultPL();
89 end
90
91
92 %% ---------------- Gathers the settings
93 % Number of submitted objects during the test
94 N_OBJ = find(pls, 'N_OBJ');
95
96 if N_OBJ < 1
97 % Pick a random rumber between 1 and 5
98 N_OBJ = randsample(5,1);
99 end
100
101 % Collects the conn struct. If empty, the test is individual, with
102 % connection opened and closed
103 conn = find(pls, 'conn');
104 if isempty(conn)
105 single_conn = true;
106 else
107 single_conn = false;
108 end
109
110 %% Builds the trial objects
111
112 objs = {};
113 obj_type = find(pls, 'obj_type');
114 user_class_list = utils.helper.ltpda_userclasses;
115
116 if strcmpi(obj_type, 'RAND') || isempty(obj_type)
117 % Empty class name or explicitely asked random value
118 rand_type = true;
119 else
120 % Checks if user entered a user class name
121 chk_ind = false;
122 for kk = 1:length(user_class_list)
123 if strcmpi(user_class_list{kk}, obj_type)
124 chk_ind = true;
125 end
126 end
127
128 % Invalid class name, go for random
129 if ~chk_ind
130 disp('Invalid object type, picking up random')
131 rand_type = true;
132 else
133 rand_type = false;
134 end
135 end
136
137 for kk = 1:N_OBJ
138 if rand_type
139 % Picks up at random one user class name
140 index = ceil(length(user_class_list)*rand(1));
141 obj_type = user_class_list{index};
142 end
143
144 % Test ID based on time elapsed since a reference time
145 ref_time = time('2008-01-01 00:00:00');
146 test_ID = floor(time - ref_time);
147
148 switch obj_type
149 case 'ao'
150 % Makes the trial object(s)
151 nsecs = find(pls, 'NSECS');
152 fs = find(pls, 'FS');
153 f_m = 0.01;
154 phi = 0;
155 noise_type = 'Normal';
156
157 pl_w = plist('fs', fs, 'nsecs', nsecs, ...
158 'waveform', 'sine wave','f', f_m, 'phi', phi, 'test_ID', test_ID);
159 pl_n = plist('fs', fs, 'nsecs', nsecs, ...
160 'waveform', 'noise', 'type', noise_type, 'test_ID', test_ID);
161
162 % Puts the trial object(s) in a cell array
163 objs{kk} = ao(pl_w) + ao(pl_n);
164
165 case 'plist'
166 % Puts the trial object(s) in a cell array
167 objs{kk} = plist('a', 'val', 'b', 3);
168
169 case 'mfir'
170 pl_f = plist('type', 'lowpass', 'order', 1, 'gain', 2.0, ...
171 'fs', 10, 'fc', 0.2);
172 % Puts the trial object(s) in a cell array
173 objs{kk} = mfir(pl_f);
174
175 case 'miir'
176 pl_f = plist('type', 'lowpass', 'order', 1, 'gain', 2.0, ...
177 'fs', 10, 'fc', 0.2);
178 % Puts the trial object(s) in a cell array
179 objs{kk} = miir(pl_f);
180
181 case 'pzmodel'
182 pl_pzm = plist('gain', 1, ...
183 'poles', [pz(1) pz(2,10)], 'zeros', [pz(4.3)]);
184 % Puts the trial object(s) in a cell array
185 objs{kk} = pzmodel(pl_pzm);
186
187 case 'timespan'
188 t1 = time();
189 % Puts the trial object(s) in a cell array
190 objs{kk} = timespan(t1, t1 + 100);
191
192 case 'ssm'
193 pl_ssm = plist('built-in', 'Interferometer_readout');
194 % Puts the trial object(s) in a cell array
195 objs{kk} = ssm(pl_ssm);
196
197 case 'parfrac'
198 % A small example from help
199 % Puts the trial object(s) in a cell array
200 % objs{kk} = parfrac([1 2], {4, [6 2]}, []);
201 disp('For the time being, use a timespan obj rather than parfrac')
202 t1 = time();
203 objs{kk} = timespan(t1, t1 + 100);
204
205 case 'rational'
206 % A small example from help
207 % Puts the trial object(s) in a cell array
208 % objs{kk} = rational([1 2], [6 2]);
209 disp('For the time being, use a timespan obj rather than rational')
210 t1 = time();
211 objs{kk} = timespan(t1, t1 + 100);
212
213 otherwise
214 disp(['Object ' obj_type ' not coded already, use timespan instead'])
215 t1 = time();
216 % Puts the trial object(s) in a cell array
217 objs{kk} = timespan(t1, t1 + 100);
218 end
219 end
220
221
222 %% Executes the submit/retrieve test
223 if find(pls, 'SUBMIT')
224
225 start_time = now;
226
227 disp(' ')
228 disp(sprintf('*===== Test %d =========', test_ID))
229 disp(' ')
230
231 % Connection
232 if single_conn
233
234 % Get the hostname
235 hostname = find(pls, 'hostname');
236
237 % Get the database name
238 database_name = find(pls, 'dbase');
239
240 % Opens the connection
241 conn = utils.mysql.connect(hostname, database_name);
242 end
243
244 % Submission and retrieval
245 results = submitretrieve(conn, objs, test_ID, find(pls, 'coll_retrieve'));
246
247 if single_conn
248 % Close connection
249 close(conn);
250 end
251
252 % Includes time for start and stop in serial form
253 stop_time = now;
254 results.start = start_time;
255 results.stop = stop_time;
256 if exist('fs','var') && exist('nsecs','var')
257 results.obj_size = nsecs * fs;
258 else
259 results.obj_size = 0;
260 end
261
262 if find(pls, 'save_results')
263 % Saves the test results
264 save([find(pls,'results_filename') '_' num2str(test_ID) '.mat'], 'results');
265 end
266
267 varargout{1} = results;
268 else
269 varargout{1} = struct();
270 end
271
272 %% Saves on disk the first trial data object, for future comparison
273 if find(pls,'save_objs')
274 save(objs{1}, find(pls,'obj_filename'));
275 end
276 end
277
278 %--------------------------------------------------------------------------
279 % Executes the submit/receive actions
280 %--------------------------------------------------------------------------
281 function sr_report = submitretrieve(conn, sub_obj, test_ID, coll_retr)
282
283 % Get the current time
284 t1 = char(time());
285
286 % Put togehter the information struct
287 sinfo.conn = conn;
288 sinfo.username = conn.username;
289 sinfo.experiment_title = ['Repository Test from UTN ' t1(1:10)];
290 sinfo.experiment_description = sprintf('Submit/retrieve test # %d', test_ID);
291 sinfo.analysis_description = 'Nothing serious, just playing with submit and retrieve';
292 sinfo.quantity = 'none';
293 sinfo.keywords = 'none';
294 sinfo.reference_ids = '';
295 sinfo.additional_comments = 'Trial data for submission and retrieval';
296 sinfo.additional_authors = 'M Hewitson';
297
298
299 % Submit the object
300 tic;
301 [OBJids, cid] = submit(sub_obj{:}, sinfo);
302 st = toc;
303
304 % Retrieve the object(s)
305 if coll_retr
306 % Retrieve the object(s) by collection ID
307 disp(['Retrieve object with collection ID ' num2str(cid)]);
308 tic;
309 ret_obj = ltpda_uo.retrieve(conn, 'Collection', cid);
310 else
311 % retrieve the object(s) by obj IDs
312 disp(['Retrieve object with obj ID ' num2str(OBJids)]);
313 tic;
314 ret_obj = ltpda_uo.retrieve(conn, OBJids);
315 end
316
317 % Single retrieval will give an object, not a cell array
318 if ~isa(ret_obj, 'cell')
319 ret_obj = {ret_obj};
320 end
321 rt = toc;
322
323
324 % Check consistency of retrieved/submitted object(s)
325 status = zeros(1,length(sub_obj));
326
327 for kk = 1:length(sub_obj)
328 status(kk) = status(kk) + ne(sub_obj{kk}, ret_obj{kk}, 'invars', 'hist');
329 end
330
331 % Build a report struct
332 sr_report.ret_time = rt;
333 sr_report.sub_time = st;
334 sr_report.t = t1(1:19); % Skip milliseconds
335 sr_report.t(strfind(sr_report.t,':')) = '_'; % These are correct fieldnames
336 sr_report.test_ID = test_ID;
337 sr_report.status = status;
338 sr_report.OBJids = OBJids;
339 sr_report.cid = cid;
340 sr_report.sinfo = rmfield(sinfo, 'conn'); % Remove the non-serializable substructs
341 end
342
343 %--------------------------------------------------------------------------
344 % Get Info Object
345 %--------------------------------------------------------------------------
346 function ii = getInfo(varargin)
347 if nargin == 1 && strcmpi(varargin{1}, 'None')
348 sets = {};
349 pl = [];
350 else
351 sets = {'Default'};
352 pl = getDefaultPlist;
353 end
354 % Build info object
355 ii = minfo(mfilename, 'ao', '', utils.const.categories.helper, '$Id: UTN_repo_test_func.m,v 1.14 2008/11/18 17:29:40 mauro Exp $', sets, pl);
356 end
357
358 %--------------------------------------------------------------------------
359 % Get Default Plist
360 %--------------------------------------------------------------------------
361 function plo = getDefaultPlist()
362
363 disp('* creating default plist...');
364 plo = plist('RAND', false, ...
365 'OBJ_TYPE', 'ao', ...
366 'N_OBJ', 1, ...
367 'NSECS', 100, ...
368 'FS', 10, ...
369 'SAVE_OBJS', false, ...
370 'OBJ_FILENAME', 'submit_trial_ao.xml', ...
371 'SUBMIT', false, ...
372 'HOSTNAME', '130.75.117.67', ...
373 'DBASE', 'ltpda_test', ...
374 'CONN', [], ...
375 'COLL_RETRIEVE', false, ...
376 'SAVE_RESULTS', true, ...
377 'RESULTS_FILENAME', 'repo_test_UTN');
378
379 disp('* done.');
380 end
381
382 % END