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
exportedtps % List of tunable parameters variable to be exported
datadictionary % Name of the used data dictionary
refdatadictionaries % Cell array of referenced data dictionaries
refddparentalgo % Parent algorithm of referenced data dictionaries
stdinits % General initialization scripts
fpinits % inits scripts for fixed parameters
timing % Timing info structure
......@@ -18,7 +19,6 @@ classdef SCDclass_algo
buslist % list of buses and their sources
modelslx % slx model file name
folder % folder containing algorithm
parentalgos % algorithms on which this algo depends
end
methods
......@@ -191,12 +191,6 @@ classdef SCDclass_algo
fprintf('\n');
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
function obj = setdatadictionary(obj, datadict)
obj.datadictionary=datadict;
......@@ -206,10 +200,15 @@ classdef SCDclass_algo
out = obj.datadictionary;
end
function obj = setreferenceddatadictionaries(obj,refdd)
if ischar(refdd) && ~iscell(refdd); refdd={refdd}; end % to cell
assert(iscell(refdd) && isrow(refdd),'refdd must be a row cell array of data dictionary names')
obj.refdatadictionaries = refdd;
function obj = addrefdd(obj,refdd,parentalgo)
% refdd: name of referenced data dictionary
% parentalgo: (optional), SCDclass_algo object of algorithm
% 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
function createdatadictionary(obj,varargin)
......@@ -238,7 +237,6 @@ classdef SCDclass_algo
dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
designDataObj = getSection(dictionaryObj, 'Design Data');
busList = obj.getbuslist;
for ii=1:numel(busList)
mybusSource = busList(ii).source;
......@@ -273,23 +271,43 @@ classdef SCDclass_algo
if dictionaryObj.HasUnsavedChanges, dictionaryObj.saveChanges; end % Save if necessary
end
function addrefdd(obj)
function addrefddtodd(obj)
% add configurations.sldd as referenced data dictionary, plus
% other optional data dictionaries (e.g. used by lower-level components of an algorithm)
for refdd = ['configurations.sldd',obj.refdatadictionaries]
dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
if ~ismember(refdd{:},dictionaryObj.DataSources)
fprintf('adding referenced data dictionary %s to %s \n',refdd{:},obj.getdatadictionary)
refddpath = which(refdd{:});
assert(~isempty(refddpath),'could not find %s',refdd{:});
dictionaryObj.addDataSource(refdd{:});
% specified in refdatadictionaries
dictionaryObj = Simulink.data.dictionary.open(obj.getdatadictionary);
refddlist = [obj.refdatadictionaries,'configurations.sldd']; % list of referenced dds
for ii=1:numel(refddlist)
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
if dictionaryObj.HasUnsavedChanges, dictionaryObj.saveChanges; end
end
function replaceorcreateddentry(obj,designDataObj,entry,value)
if designDataObj.exist(entry)
oldEntry = designDataObj.getEntry(entry);
......@@ -512,25 +530,12 @@ classdef SCDclass_algo
% populate with template tunable parameters
obj.updatetemplatetp;
% add referenced data dictionaries to obj data dictionary
obj.addrefddtodd
% add buses
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
function callinits(obj)
......@@ -598,7 +603,6 @@ classdef SCDclass_algo
%% generic operation methods
function init(obj)
SCDconf_setConf('SIM');
obj.callparentinits;
obj.callinits; % call generic algorithm init functions
obj.initdd; % setup data dictionary
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