Skip to content

Commit

Permalink
Merge pull request #1728 from pace-neutrons/1727_runid_in_nxspe
Browse files Browse the repository at this point in the history
runid in nxspe
  • Loading branch information
abuts authored Aug 15, 2024
2 parents 8ddbdea + 89e0d22 commit 3af77a9
Show file tree
Hide file tree
Showing 24 changed files with 395 additions and 293 deletions.
Binary file not shown.
Binary file modified _test/common_data/inst_let_ei3p7_240_120.nxspe
Binary file not shown.
Binary file modified _test/common_data/inst_maps_ei400_600hz.nxspe
Binary file not shown.
Binary file modified _test/common_data/inst_merlin_ei120_600hz.nxspe
Binary file not shown.
27 changes: 17 additions & 10 deletions _test/test_data_loaders/a_loader_tester.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
classdef a_loader_tester< a_loader
%
%

methods(Static)
% static methods
function [is,fh] = can_load(file_name)
Expand All @@ -11,34 +11,41 @@
error('A_LOADER:abstract_method_called','')
end
function descr=get_file_description()
error('A_LOADER:abstract_method_called','')
error('A_LOADER:abstract_method_called','')
end
function fext=get_file_extension()
fext = {'.altf'};
%error('A_LOADER:abstract_method_called','')
end
end
end
methods
% dynamic methods
function [varargout]=load_data(this,varargin)
error('A_LOADER:abstract_method_called','');
error('A_LOADER:abstract_method_called','');
end

function this=init(this,data_file_name,varargin)
error('A_LOADER:abstract_method_called','');
error('A_LOADER:abstract_method_called','');
end
function this=set_data_info(this,data_file_name,varargin)
error('A_LOADER:abstract_method_called','');
error('A_LOADER:abstract_method_called','');
end

function this=a_loader_tester(varargin)
% test constructor
this=this@a_loader(varargin{:});
end

function this=set_defined_fields(this,fields)
this.loader_define_ = fields;
end

end
methods(Access=protected)
function obj = set_info_fields(obj,fh,field_names)
error('A_LOADER:abstract_method_called','')
end
function flds = get_data_info_fields(obj)
error('A_LOADER:abstract_method_called','')
end
end
end
25 changes: 25 additions & 0 deletions _test/test_data_loaders/test_a_loader.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ function test_abstract_methods(~)
assertExceptionThrown(f,'A_LOADER:abstract_method_called');

end

function test_extract_runid_long_complex_from_fname(~)
fname =fullfile('cycle20201','MAR1044one2oneEi4.5.nxs');
id = a_loader.extract_id_from_filename(fname);
assertEqual(1044,id);
end

function test_extract_runid_complex(~)
fname = 'MAR1044one2oneEi4.5.nxs';
id = a_loader.extract_id_from_filename(fname);
assertEqual(1044,id);
end

function test_extract_runid_simple(~)
fname = 'MAR1044.nxs';
id = a_loader.extract_id_from_filename(fname);
assertEqual(1044,id);
end

function test_extract_runid_empty(~)
fname = 'nlalflalel';
id = a_loader.extract_id_from_filename(fname);
assertTrue(isnan(id));
end

%
function test_constructors(this)
par_file = fullfile(this.test_data_path,'demo_par.par');
Expand Down
29 changes: 19 additions & 10 deletions _test/test_data_loaders/test_loader_ascii.m
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,12 @@ function test_loader_ASCII_readsNAN(obj)

function test_get_data_info(obj)
spe_file_name = fullfile(obj.test_data_path,'MAP10001.spe');
[ndet,en,file_name]=loader_ascii.get_data_info(spe_file_name);
%[ndet,en,file_name]=loader_ascii.get_data_info(spe_file_name);
fi =loader_ascii.get_data_info(spe_file_name);

assertEqual([31,1],size(en));
assertEqual(obj.EXPECTED_DET_NUM,ndet);
assertEqual(spe_file_name,file_name);
assertEqual([31,1],size(fi.en));
assertEqual(obj.EXPECTED_DET_NUM,fi.n_detindata_);
assertEqual(spe_file_name,fi.file_name_);
end

function test_can_load_and_init(obj)
Expand All @@ -272,19 +273,21 @@ function test_can_load_and_init(obj)
la = loader_ascii();
la=la.init(spe_file_name,fh);

[ndet,en,file_name]=loader_ascii.get_data_info(spe_file_name);
assertEqual(en,la.en);
assertEqual(file_name,la.file_name);
%[ndet,en,file_name]=loader_ascii.get_data_info(spe_file_name);
fi = loader_ascii.get_data_info(spe_file_name);

assertEqual(fi.en,la.en);
assertEqual(fi.file_name_,la.file_name);

f=@()la.get_run_info();
assertExceptionThrown(f,'A_LOADER:runtime_error');

par_file_name =fullfile(obj.test_data_path,obj.test_par_file);
la.par_file_name = par_file_name;
[ndet1,en1] = la.get_run_info();
[ndet_l,en_l] = la.get_run_info();

assertEqual(en,en1);
assertEqual(ndet,ndet1);
assertEqual(fi.en,en_l);
assertEqual(fi.n_detindata_,ndet_l);

end

Expand Down Expand Up @@ -347,6 +350,12 @@ function test_is_loader_defined(obj)
assertEqual('',mess);
end

function test_runid_from_filename(obj)
dat_file = fullfile(obj.test_data_path,'MAP10001.spe');
lx = loader_ascii(dat_file);
assertEqual(lx.run_id,10001)
end

function test_mex_nomex(obj)
if isempty(which('get_ascii_file'))
skipTest('no get_ascii_file.mex found so the test has been disabled')
Expand Down
Loading

0 comments on commit 3af77a9

Please sign in to comment.