Skip to content
Snippets Groups Projects
Commit d97b522f authored by Federico Felici's avatar Federico Felici
Browse files

Refactor ref dictionary addition

parent bf606d74
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ classdef SCDclass_algo ...@@ -11,6 +11,7 @@ classdef SCDclass_algo
exportedtps % List of tunable parameters variable to be exported exportedtps % List of tunable parameters variable to be exported
datadictionary % Name of the used data dictionary datadictionary % Name of the used data dictionary
refdatadictionaries % Cell array of referenced data dictionaries refdatadictionaries % Cell array of referenced data dictionaries
refddparentalgo % Parent algorithm of referenced data dictionaries
stdinits % General initialization scripts stdinits % General initialization scripts
fpinits % inits scripts for fixed parameters fpinits % inits scripts for fixed parameters
timing % Timing info structure timing % Timing info structure
...@@ -18,7 +19,6 @@ classdef SCDclass_algo ...@@ -18,7 +19,6 @@ classdef SCDclass_algo
buslist % list of buses and their sources buslist % list of buses and their sources
modelslx % slx model file name modelslx % slx model file name
folder % folder containing algorithm folder % folder containing algorithm
parentalgos % algorithms on which this algo depends
end end
methods methods
...@@ -191,12 +191,6 @@ classdef SCDclass_algo ...@@ -191,12 +191,6 @@ classdef SCDclass_algo
fprintf('\n'); fprintf('\n');
end end
%% Parent algo getter and setter
function obj = addparentalgo(obj,parentalgo)
assert(isa(parentalgo,'SCDclass_algo'),'parent algorithm must be SCDclass_algo object')
obj.parentalgos{end+1} = parentalgo;
end
%% Data dictionary setter and getter %% Data dictionary setter and getter
function obj = setdatadictionary(obj, datadict) function obj = setdatadictionary(obj, datadict)
obj.datadictionary=datadict; obj.datadictionary=datadict;
...@@ -206,10 +200,15 @@ classdef SCDclass_algo ...@@ -206,10 +200,15 @@ classdef SCDclass_algo
out = obj.datadictionary; out = obj.datadictionary;
end end
function obj = setreferenceddatadictionaries(obj,refdd) function obj = addrefdd(obj,refdd,parentalgo)
if ischar(refdd) && ~iscell(refdd); refdd={refdd}; end % to cell % refdd: name of referenced data dictionary
assert(iscell(refdd) && isrow(refdd),'refdd must be a row cell array of data dictionary names') % parentalgo: (optional), SCDclass_algo object of algorithm
obj.refdatadictionaries = refdd; % generating this data dicationary.
if nargin<3, parentalgo=''; end
assert(isequal(refdd(end-4:end),'.sldd'),'refdd must end in .sldd')
obj.refddparentalgo{end+1} = parentalgo;
obj.refdatadictionaries{end+1} = refdd;
end end
function createdatadictionary(obj,varargin) function createdatadictionary(obj,varargin)
...@@ -238,7 +237,6 @@ classdef SCDclass_algo ...@@ -238,7 +237,6 @@ classdef SCDclass_algo
dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary); dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
designDataObj = getSection(dictionaryObj, 'Design Data'); designDataObj = getSection(dictionaryObj, 'Design Data');
busList = obj.getbuslist; busList = obj.getbuslist;
for ii=1:numel(busList) for ii=1:numel(busList)
mybusSource = busList(ii).source; mybusSource = busList(ii).source;
...@@ -273,23 +271,43 @@ classdef SCDclass_algo ...@@ -273,23 +271,43 @@ classdef SCDclass_algo
if dictionaryObj.HasUnsavedChanges, dictionaryObj.saveChanges; end % Save if necessary if dictionaryObj.HasUnsavedChanges, dictionaryObj.saveChanges; end % Save if necessary
end end
function addrefddtodd(obj)
function addrefdd(obj)
% add configurations.sldd as referenced data dictionary, plus % add configurations.sldd as referenced data dictionary, plus
% other optional data dictionaries (e.g. used by lower-level components of an algorithm) % other optional data dictionaries (e.g. used by lower-level components of an algorithm)
for refdd = ['configurations.sldd',obj.refdatadictionaries] % specified in refdatadictionaries
dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
if ~ismember(refdd{:},dictionaryObj.DataSources) dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
fprintf('adding referenced data dictionary %s to %s \n',refdd{:},obj.getdatadictionary) refddlist = [obj.refdatadictionaries,'configurations.sldd']; % list of referenced dds
refddpath = which(refdd{:});
assert(~isempty(refddpath),'could not find %s',refdd{:}); for ii=1:numel(refddlist)
dictionaryObj.addDataSource(refdd{:}); refdd = refddlist{ii};
if ~ismember(refdd,dictionaryObj.DataSources) % does not exist, try to add
fprintf('adding referenced data dictionary %s to %s \n',refdd,obj.getdatadictionary)
refddpath = which(refdd);
if isempty(refddpath) % data dictionary to link does not exist, try to generate it
parentalgo = obj.refddparentalgo{ii};
if isempty(parentalgo)
error('Data dictionary %s was not found but no parent algorithm is specified',refdd{ii})
else
fprintf('Data dictionary %s was not found, running init of parent algorithm %s to create it\n',parentalgo.getname)
% run parent algo init
parentalgo.init;
% check expected dd now exists
refddpath = which(refdd);
assert(~isempty(refddpath),...
'Data dictionary still not found despite running %s init, aborting',parentalgo.getname)
end
end
fprintf('Adding referenced data dictionary %s to %s\n',refdd,obj.getdatadictionary)
dictionaryObj.addDataSource(refdd);
else % already exists
fprintf('Data dictionary %s is already referenced in algo data dictionary, not adding',refdd);
end end
end end
if dictionaryObj.HasUnsavedChanges, dictionaryObj.saveChanges; end if dictionaryObj.HasUnsavedChanges, dictionaryObj.saveChanges; end
end end
function replaceorcreateddentry(obj,designDataObj,entry,value) function replaceorcreateddentry(obj,designDataObj,entry,value)
if designDataObj.exist(entry) if designDataObj.exist(entry)
oldEntry = designDataObj.getEntry(entry); oldEntry = designDataObj.getEntry(entry);
...@@ -512,25 +530,12 @@ classdef SCDclass_algo ...@@ -512,25 +530,12 @@ classdef SCDclass_algo
% populate with template tunable parameters % populate with template tunable parameters
obj.updatetemplatetp; obj.updatetemplatetp;
% add referenced data dictionaries to obj data dictionary
obj.addrefddtodd
% add buses % add buses
obj.addbusestodd; obj.addbusestodd;
% add referenced data dictionaries
obj.addrefdd
end
function callparentinits(obj)
for ii=1:numel(obj.parentalgos)
parentalgo = obj.parentalgos{ii};
% if ~isempty(which(parentalgo.getdatadictionary))
% fprintf('%s is present, not rerunning %s init\n',...
% parentalgo.getdatadictionary,parentalgo.getname)
% else
% fprintf('running inits for parent algorithm %s\n',parentalgo.getname);
parentalgo.init;
% end
end
end end
function callinits(obj) function callinits(obj)
...@@ -598,7 +603,6 @@ classdef SCDclass_algo ...@@ -598,7 +603,6 @@ classdef SCDclass_algo
%% generic operation methods %% generic operation methods
function init(obj) function init(obj)
SCDconf_setConf('SIM'); SCDconf_setConf('SIM');
obj.callparentinits;
obj.callinits; % call generic algorithm init functions obj.callinits; % call generic algorithm init functions
obj.initdd; % setup data dictionary obj.initdd; % setup data dictionary
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment