Skip to content

Commit

Permalink
Utility Class
Browse files Browse the repository at this point in the history
  • Loading branch information
balajisriram committed Apr 5, 2016
1 parent bdddeca commit 8f34ce6
Show file tree
Hide file tree
Showing 41 changed files with 158 additions and 156 deletions.
6 changes: 3 additions & 3 deletions bootstrap/BCoreServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
setupEnvironment;
addJavaComponents();
checkForUpdate; % 9/24/08 - check current code version
dataPath=fullfile(fileparts(fileparts(getBCorePath)),'BCoreData',filesep);
dataPath=fullfile(fileparts(fileparts(BCoreUtil.getBCorePath)),'BCoreData',filesep);

diary off
warning('off','MATLAB:MKDIR:DirectoryExists')
Expand Down Expand Up @@ -310,13 +310,13 @@ function buttonC(source,eventdata)
closeConn(conn);
% finished writing stop time of this heat to oracle
[r, rx, sys]=stopServer(r,rx,servePump,sys,er,subjects);
rp=getBCorePath;
rp=BCoreUtil.getBCorePath;
rp=fullfile(rp,'analysis','eflister');

% ==============================================================================================================
% FIX THIS PART TO ONLY COMPILE SUBJECTS OWNED BY THIS SERVER
% we need to compile records for every rack used here
cmdStr=sprintf('matlab -automation -r "cd(''%s'');setupEnvironment;cd(''%s'');compileDetailedRecords(''%s'');quit" &',fullfile(getBCorePath,'bootstrap'),rp,server_name);
cmdStr=sprintf('matlab -automation -r "cd(''%s'');setupEnvironment;cd(''%s'');compileDetailedRecords(''%s'');quit" &',fullfile(BCoreUtil.getBCorePath,'bootstrap'),rp,server_name);
system(cmdStr); %testing only
% END EDITS
% ==============================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setupEnvironment;
addJavaComponents(); %might conflict with dbconn

dataPath=fullfile(fileparts(fileparts(getBCorePath)),'BCoreData',filesep);
dataPath=fullfile(fileparts(fileparts(BCoreUtil.getBCorePath)),'BCoreData',filesep);

diary off
warning('off','MATLAB:MKDIR:DirectoryExists')
Expand Down
6 changes: 0 additions & 6 deletions bootstrap/getBCorePath.m
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
% this returns the path to the directory above this directory
function BCorePath=getBCorePath()
% DO U SEE ME?
[pathstr, ~, ~] = fileparts(mfilename('fullpath'));
BCorePath = fileparts(pathstr);
BCorePath = [BCorePath filesep];
2 changes: 1 addition & 1 deletion bootstrap/setupEnvironment.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
lastwarn('')

warning('off','MATLAB:dispatcher:nameConflict')
addpath((genpath(getBCorePath)));
addpath((genpath(BCoreUtil.getBCorePath)));
warning('on','MATLAB:dispatcher:nameConflict')

% intwarning('on');
Expand Down
99 changes: 28 additions & 71 deletions bootstrap/standAloneRun.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function standAloneRun(subjectID,BCorePath,setupFile)
function standAloneRun(subjectID,BCoreServerPath,setupFile)
%standAloneRun([BCorePath],[setupFile],[subjectID],[recordInOracle],[backupToServer])
%
% BCorePath (optional, string path to preexisting BCore 'db.mat' file)
Expand All @@ -16,81 +16,43 @@ function standAloneRun(subjectID,BCorePath,setupFile)
%
setupEnvironment;

if exist('BCorePath','var') && ~isempty(BCorePath)
if isdir(BCorePath)
rx=BCore(BCorePath,0);
else
BCorePath
error('if BCorePath supplied, it must be a path to a preexisting BCore ''db.mat'' file')
end
% create ratrix if necessary
if exist('BCorePath','var') && ~isempty(BCoreServerPath)
assert(isdir(BCoreServerPath),'standAloneRun:incorrectValue','if BCorePath supplied, it must be a path to a preexisting BCore ''db.mat'' file')
rx=BCore(BCoreServerPath,0);
else
dataPath=fullfile(fileparts(fileparts(getBCorePath)),'BCoreData',filesep);
defaultLoc=fullfile(dataPath, 'ServerData');
d=dir(fullfile(defaultLoc, 'db.mat'));

if length(d)==1
rx=BCore(defaultLoc,0);
fprintf('loaded BCore from default location\n')
else
try
[success mac]=getMACaddress();
if ~success
mac='000000000000';
end
catch
mac='000000000000';
end

machines={{'1U',mac,[1 1 1]}};
rx=createBCoreWithDefaultStations(machines,dataPath,'localTimed');
permStorePath=fullfile(dataPath,'PermanentTrialRecordStore');
mkdir(permStorePath);
rx.standAlonePath=permStorePath;
fprintf('created new BCore\n')
d=dir(fullfile(BCoreUtil.getServerDataPath, 'db.mat'));
switch length(d)
case 0
rx = BCoreUtil.createDefaultBCore();
case 1
rx=BCore(defaultLoc,0);
otherwise
error('standAloneRun:unknownError','either a single db.mat exists or none exist. We found %d. Clean your database',length(d));
end
end

needToAddSubject=false;
needToCreateSubject=false;
if ~exist('subjectID','var') || isempty(subjectID)
ids=getSubjectIDs(rx);
if length(ids)>0
subjectID=ids{1};
else
subjectID='demo1';
needToCreateSubject=true;
needToAddSubject=true;
end
else
subjectID=lower(subjectID);
try
isSubjectInBCore=getSubjectFromID(rx,subjectID);
catch ex
if ~isempty(strfind(ex.message,'request for subject id not contained in BCore'))

needToCreateSubject=true;
needToAddSubject=true;
else
rethrow(ex)
end
end
end

if needToCreateSubject
warning('creating dummy subject')
sub = rat(subjectID, 'male', 'long-evans', datetime(2005,05,10), datetime(2006,05,10), 'unknown', 'wild caught');
end
auth='bas';

if needToAddSubject
rx=addSubject(rx,sub,auth);
% should we add the subject to the ratrix?
if ~exist('subjectID','var') || isempty(subjectID)
subjectID='demo1';
end
switch rx.subjectIDInRatrix(lower(subjectID))
case true
sub = rx.getSubjectFromID(subjectID);
case false
sub = virtual(subjectID, 'unknown');
auth = 'bas';
rx=rx.addSubject(sub,auth);
end

if (~exist('setupFile','var') || isempty(setupFile)) && ~isa(getProtocolAndStep(getSubjectFromID(rx,subjectID)),'protocol')
setupFile='setProtocolMINBS';
if ~exist('setupFile','var') || isempty(setupFile)
setupFile=@setProtocolMINBS;
elseif ~isa(setupFile,'function_handle') ||
error('standAloneRun:incompatibleInput','you input setupFile thats not a function handle');
end

if exist('setupFile','var') && ~isempty(setupFile)
x=what(fileparts(which(setupFile)));
if isempty(x) || isempty({x.m}) || ~any(ismember(lower({setupFile,[setupFile '.m']}),lower(x.m)))
setupFile
Expand All @@ -99,11 +61,6 @@ function standAloneRun(subjectID,BCorePath,setupFile)

su=str2func(setupFile); %weird, str2func does not check for existence!
rx=su(rx,{subjectID});
%was: r=feval(setupFile, r,{getID(sub)});
%but edf notes: eval is bad style
%http://www.mathworks.com/support/tech-notes/1100/1103.html
%http://blogs.mathworks.com/loren/2005/12/28/evading-eval/
end

%[isExperimentSubject, xtraExptBackupPath, experiment] = identifySpecificExperiment(subjectID);

Expand Down
2 changes: 1 addition & 1 deletion classes/analysis/@neuronDB/process.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
%start building a parameters of the calls to runAnalysis
p.channels={db.data{neurons(i)}.channels}; % all singleUnits have only a single set of channels
p.analysisMode=mode;
p.standardParams = fullfile(getBCorePath,'analysis','bsriram','analysisParameters','getBasicParams.m'); % warning... this is just a record and has no effect
p.standardParams = fullfile(BCoreUtil.getBCorePath,'analysis','bsriram','analysisParameters','getBasicParams.m'); % warning... this is just a record and has no effect
p.cellBoundary={'trialRange',minmax(trials),'trialMask',mask};

%default parameters are faster and no inspect for pre-processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
channels = {getChannels(s)};
thrV = [NaN NaN NaN];
cellBoundary = {'trialRange',trialRange,'trialMask',trialMask};
standardParams = fullfile(getBCorePath,'analysis','bsriram','analysisParameters','params_01_06_2011.m');
standardParams = fullfile(BCoreUtil.getBCorePath,'analysis','bsriram','analysisParameters','params_01_06_2011.m');
analysisMode = 'onlyAnalyze'; % most important
forceNoInspect = true;
intelligentUpdate = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
channels = {getChannels(s)};
thrV = [NaN NaN NaN];
cellBoundary = {'trialRange',trialRange,'trialMask',trialMask};
standardParams = fullfile(getBCorePath,'analysis','bsriram','analysisParameters','params_01_06_2011.m');
standardParams = fullfile(BCoreUtil.getBCorePath,'analysis','bsriram','analysisParameters','params_01_06_2011.m');
analysisMode = 'onlyAnalyze'; % most important
forceNoInspect = true;
intelligentUpdate = false;
Expand Down
68 changes: 68 additions & 0 deletions classes/core/BCoreUtil.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
classdef BCoreUtil
properties
end

methods (Static)

function BCorePath=getBCorePath()
[pathstr, ~, ~] = fileparts(mfilename('fullpath'));
[pathstr, ~, ~] = fileparts(pathstr);
BCorePath = fileparts(pathstr);
BCorePath = [BCorePath filesep];
end

function BasePath = getBasePath()
p = BCoreUtil.getBCorePath();
[BasePath, ~, ~] = fileparts(p);
end

function ServerDataPath = getServerDataPath()
p = BCoreUtil.getBasePath();
p = fullfile(p,'BCoreData');
ServerDataPath = fullfile(p,'ServerData');
end

function rx = createDefaultBCore()
try
[success, mac]=getMACaddress();
if ~success
mac='000000000000';
end
catch
mac='000000000000';
end

machines={{'1U',mac,[1 1 1]}};
rx=createBCoreWithDefaultStations(machines,dataPath,'localTimed');
permStorePath=fullfile(dataPath,'PermanentTrialRecordStore');
mkdir(permStorePath);
rx.standAlonePath=permStorePath;
fprintf('created new BCore\n')
end

function [success, mac]=getMACaddress()
success=false;
switch computer
case {'PCWIN64','PCWIN32'}
macidcom = fullfile(PsychtoolboxRoot,'PsychContributed','macid');
[rc, mac] = system(macidcom);
mac=mac(~isstrprop(mac,'wspace'));
if rc==0 && isMACaddress(mac)
success=true;
end
case {'GLNXA64','MACI64'}
error('BCoreUtil:getMACAddress:unsupportedSystem','This system: %s is not supported', computer);
compinfo = Screen('Computer');
if isfield(compinfo, 'MACAddress')
mac = compinfo.MACAddress;
% Remove the : that are a part of the string
mac = mac(mac~=':');
if isMACaddress(mac)
success = true;
end
end
otherwise
error('BCoreUtil:getMACAddress:unsupportedSystem','In getMACaddress() unknown OS');
end
end
end
2 changes: 1 addition & 1 deletion classes/core/protocols/stimManagers/afcCoherentDots.m
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@

case 'localCalibStore'
try
temp = load(fullfile(getBCorePath,'monitorCalibration','tempCLUT.mat'));
temp = load(fullfile(BCoreUtil.getBCorePath,'monitorCalibration','tempCLUT.mat'));
uncorrected = temp.linearizedCLUT;
useUncorrected=1;
catch ex
Expand Down
2 changes: 1 addition & 1 deletion classes/core/protocols/stimManagers/afcGratings.m
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@

case 'localCalibStore'
try
temp = load(fullfile(getBCorePath,'monitorCalibration','tempCLUT.mat'));
temp = load(fullfile(BCoreUtil.getBCorePath,'monitorCalibration','tempCLUT.mat'));
uncorrected = temp.linearizedCLUT;
useUncorrected=1;
catch ex
Expand Down
2 changes: 1 addition & 1 deletion classes/core/protocols/stimManagers/afcGratingsPDPhases.m
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@

case 'localCalibStore'
try
temp = load(fullfile(getBCorePath,'monitorCalibration','tempCLUT.mat'));
temp = load(fullfile(BCoreUtil.getBCorePath,'monitorCalibration','tempCLUT.mat'));
uncorrected = temp.linearizedCLUT;
useUncorrected=1;
catch ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@

case 'localCalibStore'
try
temp = load(fullfile(getBCorePath,'monitorCalibration','tempCLUT.mat'));
temp = load(fullfile(BCoreUtil.getBCorePath,'monitorCalibration','tempCLUT.mat'));
uncorrected = temp.linearizedCLUT;
useUncorrected=1;
catch ex
Expand Down
2 changes: 1 addition & 1 deletion classes/core/protocols/stimManagers/afcObjects.m
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@

case 'localCalibStore'
try
temp = load(fullfile(getBCorePath,'monitorCalibration','tempCLUT.mat'));
temp = load(fullfile(BCoreUtil.getBCorePath,'monitorCalibration','tempCLUT.mat'));
uncorrected = temp.linearizedCLUT;
useUncorrected=1;
catch ex
Expand Down
9 changes: 7 additions & 2 deletions classes/core/ratrices/BCore.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
end
end

function out = subjectIDInBCore(r,id)
assert(ischar(id),'BCore:subjectIDInBCore:incorrectValue','''id'' needs to be a char. instead is of class:%s',class(id));
ids = r.getSubjectIDs();
out = any(ismember(id,ids));
end

function r = set.standAlonePath(r,path)
assert(isdir(path),'BCore:set.standAlonePath:incorrectValue','Argument to permanentStorePath (%s) is not a directory',path)
r.standAlonePath = path;
Expand Down Expand Up @@ -1351,7 +1357,7 @@ function recordInLog(r,s,str,author)
end
end

function out = testBoxSubjectDirs(r,b)
function out =testBoxSubjectDirs(r,b)
validateattributes(b,{'box'},{'nonempty'})
subIDs=getSubjectIDsForBoxID(r,b.id);
success=1;
Expand Down Expand Up @@ -1510,6 +1516,5 @@ function recordInLog(r,s,str,author)
error('not a station object')
end
end

end
end
4 changes: 2 additions & 2 deletions classes/core/rnet/rnet.m
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function clearTemporaryFiles(r)
quit=false;
constants = getConstants(r);

BCoreDataPath=fullfile(fileparts(fileparts(getBCorePath)),'testdata',filesep);
BCoreDataPath=fullfile(fileparts(fileparts(BCoreUtil.getBCorePath)),'testdata',filesep);
%BCoreDataPath='C:\Documents and Settings\rlab\Desktop\testdata\';
%figure out where to store this
%actually, this is an ok place -- there's nothing persistent
Expand Down Expand Up @@ -1654,7 +1654,7 @@ function removeAllDisconnectedClients(r)
svnPath = GetSubversionPath;

% Construct svn update command
info.updateCommand=[svnPath 'svn update ' targetRevision getBCorePath ];
info.updateCommand=[svnPath 'svn update ' targetRevision BCoreUtil.getBCorePath ];
save('info.mat','info');

% Clear java classes
Expand Down
4 changes: 2 additions & 2 deletions util/calibration/linearization/calibrateMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
CLUT=fread(fid,'*uint8');
fclose(fid);
timestamp=datestr(now,'mm-dd-yyyy HH:MM');
svnRev=getSVNRevisionFromXML(getBCorePath);
svnRev=getSVNRevisionFromXML(BCoreUtil.getBCorePath);
addCalibrationData(CLUT,mac,timestamp,svnRev,comment,calibrationString)
closeConn(conn);
catch ex
Expand All @@ -263,7 +263,7 @@
% data is always stored on the local BCore folder currently overwrites
% old calibration data.
disp('saving calibration to local store...')
BCoreFolder = getBCorePath;
BCoreFolder = BCoreUtil.getBCorePath;
if ~exist(fullfile(BCoreFolder,'monitorCalibration'),'dir')
mkdir(fullfile(BCoreFolder,'monitorCalibration'));
end
Expand Down
2 changes: 1 addition & 1 deletion util/infrastructure/calibrateLocal.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function calibrateLocal( numReps, amts, timeBtw, requiredAccuracy )

clc

dataPath=fullfile(fileparts(fileparts(getBCorePath)),'BCoreData',filesep);
dataPath=fullfile(fileparts(fileparts(BCoreUtil.getBCorePath)),'BCoreData',filesep);

rewardMethod = 'localTimed';

Expand Down
Loading

0 comments on commit 8f34ce6

Please sign in to comment.