0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % ADDHISTORY Add a history-object to the ltpda_uo object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: Add a history-object to the ltpda_uoh object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % CALL: obj = addHistory(obj, minfo, h_pl, var_name, inhists, ...);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % obj = addHistory(obj, minfo, h_pl, var_name, ismodifier, inhists, ...);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % VERSION: $Id: addHistory.m,v 1.32 2011/08/16 05:16:04 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 function varargout = addHistory(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 persistent lastProcTime;
|
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 % The object to add history to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 obj = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 %%% Decide on a deep copy or a modify
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 obj = copy(obj, nargout);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % Copy the history plist because we may modify it below
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 if isa(varargin{3}, 'plist')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 pl = copy(varargin{3},1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 pl = varargin{3};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 %%% Add history to all objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 for ii = 1:numel(obj)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 if ~isempty(pl)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 % 1. replace ltpda_uoh in pl with their history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % 2. empty the description field of a parameter ('desc')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % 3. remove the options
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 N = pl.nparams;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 for jj=1:N
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 p = pl.params(jj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 if isa(p.getVal, 'ltpda_uoh')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 p.setVal([p.getVal.hist]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 p.setVal(p.getVal);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 p.setDesc('');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 % Remove Password from the history-plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 if isa(pl, 'plist') && pl.isparam('password')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 pl = pl.remove('password');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 % Remove Username from the history-plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 if isa(pl, 'plist') && pl.isparam('username')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 pl = pl.remove('username');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 % Remove the 'sets' and the corresponding 'plists' from the minfo
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % object. They are not important for the history step.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 varargin{2}.clearSets();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % handle processing time
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 t0 = time();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 proctime = t0.utc_epoch_milli;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 if isempty(lastProcTime)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 lastProcTime = proctime;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 if proctime == lastProcTime
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 proctime = proctime+1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 lastProcTime = proctime;
|
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 % set UUID
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 uuid = char(java.util.UUID.randomUUID);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 obj(ii).UUID = uuid;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 h = history(proctime, varargin{2}, pl, varargin{4}, uuid, varargin{5:end});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 h.setObjectClass(class(obj(ii)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 obj(ii).setHist(h);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 %%% Prepare output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 varargout{1} = obj;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|