Skip to content

Commit

Permalink
Re #1790 Formally modified instrument-s to be hashable. Detectors inc…
Browse files Browse the repository at this point in the history
…omplete. Tests needed
  • Loading branch information
abuts committed Dec 16, 2024
1 parent 2ea421e commit fe8712f
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_aperture < serializable
classdef IX_aperture < hashable
% Aperture class definition
properties (Access=private)
% Stored properties - but kept private and accessible only through
Expand Down Expand Up @@ -85,14 +85,15 @@
% for the non-dependent properties. However, any interdependencies with
% other properties must be checked here.
function obj=set.name(obj,val)
if is_string(val)
obj.name_=val;
else
if ~is_string(val)
error('HERBERT:IX_apperture:invalid_argument',...
'Sample name must be a character string (or empty string)')
end

obj.name_=val;
if obj.do_check_combo_arg_
obj = obj.check_combo_arg();
end
end

function obj=set.distance(obj,val)
Expand All @@ -103,6 +104,10 @@
error('HERBERT:IX_apperture:invalid_argument',...
'Distance must be a numeric scalar')
end
if obj.do_check_combo_arg_
obj = obj.check_combo_arg();
end

end

function obj=set.width(obj,val)
Expand All @@ -113,16 +118,24 @@
error('HERBERT:IX_apperture:invalid_argument',...
'Aperture width must be a numeric scalar greater than or equal to zero')
end
if obj.do_check_combo_arg_
obj = obj.check_combo_arg();
end

end

function obj=set.height(obj,val)
if isscalar(val) && isnumeric(val) && val>=0
obj.height_=val;
obj.mandatory_field_set_(3)=true;

else
error('HERBERT:IX_apperture:invalid_argument',...
'Aperture height must be a numeric scalar greater than or equal to zero')
end
if obj.do_check_combo_arg_
obj = obj.check_combo_arg();
end
end

%------------------------------------------------------------------
Expand Down Expand Up @@ -176,7 +189,7 @@
% problem it they are not, after recomputing dependent variables
% if requested.


obj = obj.clear_hash();
if ~all(obj.mandatory_field_set_)
mandatory_field_names = obj.saveableFields('mandatory');
error('HERBERT:IX_aperture:invalid_argument', ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_divergence_profile < serializable
classdef IX_divergence_profile < hashable
% Divergence profile class definition

properties (Access=private)
Expand Down Expand Up @@ -117,6 +117,7 @@
'IX_divergence_profile: The profile values must all be finite and greater or equal to zero')
end
obj.name_ = val;
obj = obj.clear_hash();
end

% Currently do not permit any - it only makes sense to change the
Expand Down Expand Up @@ -185,6 +186,7 @@
% Compute the pdf
obj.pdf_ = pdf_table (obj.angles_, obj.profile_);
end
obj = obj.clear_hash();
end
end
methods(Access=protected)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_doubledisk_chopper < serializable
classdef IX_doubledisk_chopper < hashable
% Double disk chopper class definition

properties (Access=protected)
Expand Down Expand Up @@ -122,6 +122,7 @@
error('HERBERT:IX_doubledisk_chopper:invalid_argument', ...
'Disk chopper name must be a character string (or empty string)')
end
obj = obj.clear_hash();
end

function obj=set.distance(obj,val)
Expand All @@ -132,6 +133,7 @@
error('HERBERT:IX_doubledisk_chopper:invalid_argument', ...
'Distance must be a numeric scalar')
end
obj = obj.clear_hash();
end

function obj=set.frequency(obj,val)
Expand Down Expand Up @@ -182,6 +184,7 @@

function obj=set.aperture_height(obj,val)
obj = check_and_set_positive_scalar_(obj,'aperture_height_',val);
obj = obj.clear_hash();
end

function obj=set.jitter(obj,val)
Expand Down Expand Up @@ -290,6 +293,7 @@
if do_recompute_pdf
obj.pdf_ = recompute_pdf_(obj); % recompute the lookup table
end
obj = obj.clear_hash();
end
end
methods(Access=protected)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_fermi_chopper < serializable
classdef IX_fermi_chopper < hashable
% Fermi chopper class definition
properties (Constant, Access=private)
% Conversion constant. Should replace by a class that gives constants
Expand Down Expand Up @@ -146,6 +146,7 @@
'Fermi chopper name must be a character string (or empty string). It is %s', ...
disp2str(val));
end
obj = obj.clear_hash();
end
function obj=set.distance(obj,val)
if isscalar(val) && isnumeric(val)
Expand All @@ -156,6 +157,7 @@
'Distance must be a numeric scalar. It is: %s',...
disp2str(val));
end
obj = obj.clear_hash();
end
function obj=set.frequency(obj,val)
obj = check_and_set_frequency_(obj,val);
Expand Down Expand Up @@ -208,7 +210,7 @@
'Chopper aperture width must be a numeric scalar greater or equal to zero It is: %s', ...
disp2str(val));
end

obj = obj.clear_hash();
end

function obj=set.height(obj,val)
Expand All @@ -219,7 +221,7 @@
'Chopper aperture height must be a numeric scalar greater or equal to zero It is: %s', ...
disp2str(val));
end

obj = obj.clear_hash();
end

function obj=set.energy(obj,val)
Expand Down Expand Up @@ -394,6 +396,7 @@
if do_recompute_pdf
obj.pdf_ = recompute_pdf_(obj); % recompute the lookup table
end
obj = obj.clear_hash();
end
end
methods(Access=protected)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_mod_shape_mono < serializable
classdef IX_mod_shape_mono < hashable
% Moderator - shaping chopper - monochromating chopper as a single object

properties (Access=private)
Expand Down Expand Up @@ -226,6 +226,7 @@
obj.t_m_offset_ = obj.t_m_offset_calibrate_();
[obj.t_chop_cov_, obj.t_chop_av_] = obj.moments_ ();
end
obj = obj.clear_hash();
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_moderator < serializable
classdef IX_moderator < hashable
% Moderator class definition

properties (Constant, Access=private)
Expand Down Expand Up @@ -152,6 +152,7 @@
error('IX_moderator:invalid_argument',...
'Moderator name must be a character string (or empty string)')
end
obj = obj.clear_hash();
end

function obj=set.distance(obj,val)
Expand All @@ -162,6 +163,7 @@
error('IX_moderator:invalid_argument',...
'Distance must be a numeric scalar')
end
obj = obj.clear_hash();
end

function obj=set.angle(obj,val)
Expand All @@ -172,6 +174,7 @@
error('IX_moderator:invalid_argument',...
'Moderator face angle must be a numeric scalar')
end
obj = obj.clear_hash();
end
function obj=set.pulse_model(obj,val)
obj = check_and_set_pulse_model_(obj,val);
Expand All @@ -191,22 +194,27 @@

function obj=set.width(obj,val)
obj = check_and_set_nonnegative_scalar_(obj,'width',val);
obj = obj.clear_hash();
end

function obj=set.height(obj,val)
obj = check_and_set_nonnegative_scalar_(obj,'height',val);
obj = obj.clear_hash();
end

function obj=set.thickness(obj,val)
obj = check_and_set_nonnegative_scalar_(obj,'thickness',val);
obj = obj.clear_hash();
end

function obj=set.temperature(obj,val)
obj = check_and_set_nonnegative_scalar_(obj,'temperature',val);
obj = obj.clear_hash();
end

function obj=set.energy(obj,val)
obj = check_and_set_nonnegative_scalar_(obj,'energy',val);
obj = obj.clear_hash();
end

%------------------------------------------------------------------
Expand Down Expand Up @@ -294,6 +302,7 @@
do_recompute_pdf = true;
end
obj = check_combo_recalc_pdf_(obj,do_recompute_pdf);
obj = obj.clear_hash();
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_mosaic < serializable
classdef IX_mosaic < hashable
% Mosaic spread object
properties (Access=protected)
% Stored properties - but kept private and accessible only through
Expand Down Expand Up @@ -209,6 +209,7 @@
error('HERBERT:IX_mosaic:invalid_argument', ...
'Mosaic distribution function must be a function handle')
end
obj = obj.clear_hash();
end
function obj=set.mosaic_pdf_string(obj,val)
if ~(isstring(val)||ischar(val))
Expand All @@ -217,6 +218,7 @@
class(val))
end
obj.mosaic_pdf = str2func(val);
obj = obj.clear_hash();
end
function obj=set.parameters(obj,val)
obj.parameters_=val;
Expand Down Expand Up @@ -282,6 +284,7 @@
'"xaxis=%s" and "yaxis=%s" are colinear, or almost colinear',...
disp2str(obj.xaxis_),disp2str(obj.yaxis_));
end
obj = obj.clear_hash();
end
end
methods(Access=protected)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_samp < serializable
classdef IX_samp < hashable
% Base class for samples to include the null sample case defined from a
% structure with no fields (IX_null_sample) and the standard IX_sample

Expand Down Expand Up @@ -95,6 +95,7 @@
'Sample name must be a character string (or empty string)')
end
end
obj = obj.clear_hash();
end

function name=get.name(obj)
Expand All @@ -119,6 +120,7 @@
error('HERBERT:IX_samp:invalid_argument', ...
'Sample alatt must be a 1 or 3 compoment numeric vector')
end
obj = obj.clear_hash();
end
function alat=get.alatt(obj)
alat = get_lattice(obj);
Expand Down Expand Up @@ -147,6 +149,7 @@
end

obj.angdeg_=val(:)';
obj = obj.clear_hash();
end
end
methods(Access = protected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
error('HERBERT:IX_sample:invalid_argument',...
'Mosaic spread must be numeric or an IX_mosaic object')
end
obj = obj.clear_hash();
end

function obj=set.temperature(obj,val)
Expand All @@ -158,6 +159,7 @@
error('HERBERT:IX_sample:invalid_argument',...
'Temperature must be numeric scalar greater than or equal to zero')
end
obj = obj.clear_hash();
end

function obj=set.hall_symbol(obj,val)
Expand All @@ -171,6 +173,7 @@
'Sample Hall symbol must be a character string (or empty string)')
end
end
obj = obj.clear_hash();
end
function obj=set.xgeom(obj,val)
if isnumeric(val) && numel(val)==3 && ~all(val==0)
Expand Down Expand Up @@ -220,6 +223,7 @@
error('HERBERT:IX_sample:invalid_argument',...
'single_crystal must true or false (or 1 or 0)')
end
obj = obj.clear_hash();
end

function obj=set.shape(obj,val)
Expand Down Expand Up @@ -352,6 +356,7 @@
error('HERBERT:IX_sample:invalid_argument',...
'The number of shape parameters is not correct for the sample type')
end
obj = obj.clear_hash();
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef IX_source < serializable
classdef IX_source < hashable
% Neutron source information
% Basic information about the source, such as name, target_name and
% operating frequency
Expand Down Expand Up @@ -86,6 +86,7 @@
' Its type is: %s and value %s'], ...
class(val),disp2str(val))
end
obj = obj.clear_hash();
end

function obj=set.target_name(obj,val)
Expand All @@ -100,6 +101,7 @@
class(val),disp2str(val))
end
obj.target_name_ = char(val);
obj = obj.clear_hash();
end

function obj=set.frequency(obj,val)
Expand All @@ -111,6 +113,7 @@
'The target frequency must be a non-negative number')
end
obj.frequency_ = val;
obj = obj.clear_hash();
end
%------------------------------------------------------------------
% Get methods for dependent properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef (Abstract) IX_det_abstractType < serializable
classdef (Abstract) IX_det_abstractType < hashable
% Abstract class to be inherited by detector classes
% Defines one or more generic properties and required methods for all
% detector types.
Expand Down
Loading

0 comments on commit fe8712f

Please sign in to comment.