Skip to content
Snippets Groups Projects
Commit 37e6b708 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

OAR: simplified previous commit

parent aa23e294
No related branches found
No related tags found
No related merge requests found
...@@ -88,34 +88,32 @@ function oarparams = gtBatchUpdate(oarparams, records) ...@@ -88,34 +88,32 @@ function oarparams = gtBatchUpdate(oarparams, records)
end end
function oarparams = gtBatchClean(oarparams) function oarparams = gtBatchClean(oarparams)
if (~isempty(oarparams)) fnames = fieldnames(oarparams);
fnames = fieldnames(oarparams); for fname = fnames'
for fname = fnames' funcRecord = oarparams.(fname{1});
funcRecord = oarparams.(fname{1}); arrayNames = fieldnames(funcRecord);
arrayNames = fieldnames(funcRecord); for arrayName = arrayNames'
for arrayName = arrayNames' arrayRecord = funcRecord.(arrayName{1});
arrayRecord = funcRecord.(arrayName{1}); for n = 1:numel(arrayRecord.job)
for n = 1:numel(arrayRecord.job) jobs = arrayRecord.job(n);
jobs = arrayRecord.job(n); states = {jobs(:).state};
states = {jobs(:).state}; codes = {jobs(:).exit_code};
codes = {jobs(:).exit_code}; matchesStates = strcmp(states, 'Terminated');
matchesStates = strcmp(states, 'Terminated'); matchesCodes = strcmp(codes, '0 (0,0,0)');
matchesCodes = strcmp(codes, '0 (0,0,0)'); matches = matchesStates | matchesCodes;
matches = matchesStates | matchesCodes; arrayRecord.job(n) = jobs(matches);
arrayRecord.job(n) = jobs(matches);
end
if (isempty(arrayRecord.job))
funcRecord = rmfield(funcRecord, arrayName{1});
fprintf('All the jobs from array %s are terminated with exit_code ''0 (0,0,0)''\n', ...
arrayName{1}(6:end))
end
end end
if (isempty(fieldnames(funcRecord))) if (isempty(arrayRecord.job))
oarparams = rmfield(oarparams, fname{1}); funcRecord = rmfield(funcRecord, arrayName{1});
fprintf('All arrays of function %s are terminated with exit_code ''0 (0,0,0)''\n', ... fprintf('All the jobs from array %s are terminated with exit_code ''0 (0,0,0)''\n', ...
fname{1}) arrayName{1}(6:end))
end end
end end
if (isempty(fieldnames(funcRecord)))
oarparams = rmfield(oarparams, fname{1});
fprintf('All arrays of function %s are terminated with exit_code ''0 (0,0,0)''\n', ...
fname{1})
end
end end
end end
...@@ -216,17 +214,13 @@ function [records, selectionType] = getRecords(oarparams, args) ...@@ -216,17 +214,13 @@ function [records, selectionType] = getRecords(oarparams, args)
gtError('gtBatch:wrong_argument', 'Too many arguments'); gtError('gtBatch:wrong_argument', 'Too many arguments');
end end
if (~isempty(oarparams)) switch(lower(selectionType))
switch(lower(selectionType)) case 'name'
case 'name' records = getJobRecordsByName(oarparams, selectionValue);
records = getJobRecordsByName(oarparams, selectionValue); case 'array'
case 'array' records = getJobRecordsByArrayIDs(oarparams, selectionValue);
records = getJobRecordsByArrayIDs(oarparams, selectionValue); case 'job'
case 'job' records = getJobRecordsByJobIDs(oarparams, selectionValue);
records = getJobRecordsByJobIDs(oarparams, selectionValue);
end
else
records = makeEmptyRecord();
end end
end end
......
function oarparams = gtReadParamsOARfromXML(filename) function oarparams = gtReadParamsOARfromXML(filename)
tree = xmlread(filename); tree = xmlread(filename);
oarElem = tree.getFirstChild(); oarElem = tree.getFirstChild();
oarparams = []; oarparams = struct();
funcElements = oarElem.getElementsByTagName('function'); funcElements = oarElem.getElementsByTagName('function');
for numFunc = 1:funcElements.getLength() for numFunc = 1:funcElements.getLength()
funcElem = funcElements.item(numFunc-1); funcElem = funcElements.item(numFunc-1);
......
function gtWriteParamsOARtoXML(filename, oarparams) function gtWriteParamsOARtoXML(filename, oarparams)
docNode = com.mathworks.xml.XMLUtils.createDocument('oarparameters'); docNode = com.mathworks.xml.XMLUtils.createDocument('oarparameters');
docRootNode = docNode.getDocumentElement(); docRootNode = docNode.getDocumentElement();
if (~isempty(oarparams)) funcNames = fieldnames(oarparams);
funcNames = fieldnames(oarparams); for funcName = funcNames'
for funcName = funcNames' funcElement = docNode.createElement('function');
funcElement = docNode.createElement('function'); funcElement.setAttribute('name', funcName{1});
funcElement.setAttribute('name', funcName{1}); func = oarparams.(funcName{1});
func = oarparams.(funcName{1}); arrayNames = fieldnames(func);
arrayNames = fieldnames(func); for arrayName = arrayNames'
for arrayName = arrayNames' arrayElement = docNode.createElement('array');
arrayElement = docNode.createElement('array'); arrayElement.setAttribute('id', arrayName{1}(6:end));
arrayElement.setAttribute('id', arrayName{1}(6:end)); array = func.(arrayName{1});
array = func.(arrayName{1}); for n = 1:numel(array.job)
for n = 1:numel(array.job) jobElement = docNode.createElement('job');
jobElement = docNode.createElement('job'); jobElement.setAttribute('id', num2str(array.job(n).jobId));
jobElement.setAttribute('id', num2str(array.job(n).jobId));
% Using reflection, but avoiding duplication of Job ID info % Using reflection, but avoiding duplication of Job ID info
fields = fieldnames(array.job(n)); fields = fieldnames(array.job(n));
fields = setdiff(fields, {'jobId'}); fields = setdiff(fields, {'jobId'});
for field = fields' for field = fields'
fieldElement = docNode.createElement(field{1}); fieldElement = docNode.createElement(field{1});
fieldElement.appendChild( ... fieldElement.appendChild( ...
docNode.createTextNode(array.job(n).(field{1}))); docNode.createTextNode(array.job(n).(field{1})));
jobElement.appendChild(fieldElement); jobElement.appendChild(fieldElement);
end
arrayElement.appendChild(jobElement);
end end
funcElement.appendChild(arrayElement); arrayElement.appendChild(jobElement);
end end
docRootNode.appendChild(funcElement); funcElement.appendChild(arrayElement);
end end
docRootNode.appendChild(funcElement);
end end
xmlwrite(filename, docNode); xmlwrite(filename, docNode);
end end
...@@ -61,7 +61,7 @@ try ...@@ -61,7 +61,7 @@ try
fprintf(' Done.\n') fprintf(' Done.\n')
catch mexc catch mexc
gtPrintException(mexc) gtPrintException(mexc)
oarparameters = []; oarparameters = struct();
fprintf(' it doesn''t exist! Creating a new one!\n') fprintf(' it doesn''t exist! Creating a new one!\n')
end end
......
...@@ -15,26 +15,25 @@ function updateOar(queryname, action) ...@@ -15,26 +15,25 @@ function updateOar(queryname, action)
%[sub]- updateArray %[sub]- updateArray
% %
if (~exist('queryname', 'var') || isempty(queryname)) if (~exist('queryname', 'var') || isempty(queryname))
queryname = 'gt*'; queryname = 'gt*';
end end
if (~exist('action', 'var') || isempty(action)) if (~exist('action', 'var') || isempty(action))
action = 'update'; action = 'update';
end end
oarparameters = gtOarLoadParameters('oarparameters'); oarparameters = gtOarLoadParameters('oarparameters');
% Needed for compatibility with old files % Needed for compatibility with old files
oarparameters = clean(oarparameters); oarparameters = clean(oarparameters);
if ischar(queryname) if ischar(queryname)
lookfunc = true; lookfunc = true;
funcname = queryname; funcname = queryname;
else else
lookfunc = false; lookfunc = false;
arrayid = queryname; arrayid = queryname;
end end
if (~isempty(oarparameters) && ~isempty(fieldnames(oarparameters)))
fnames = fieldnames(oarparameters); fnames = fieldnames(oarparameters);
if (lookfunc) if (lookfunc)
...@@ -131,10 +130,8 @@ if (~isempty(oarparameters) && ~isempty(fieldnames(oarparameters))) ...@@ -131,10 +130,8 @@ if (~isempty(oarparameters) && ~isempty(fieldnames(oarparameters)))
end % end for jj end % end for jj
end end
end % end lookfunc end % end lookfunc
end % end if
gtOarSaveParameters('oarparameters', oarparameters);
gtOarSaveParameters('oarparameters', oarparameters);
end % end of function end % end of function
% Sub-functions % Sub-functions
......
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