Moose/Sweep/Step/Magnet.pm

filter: Statementstmt 37.5% 21 / 56 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 3 totaltotal 29.6% 24 / 81 SCAR 31.4
CC
7
Cov
31%
BUILD
12.0
_field_setter
12.0
set_persistent_mode
6.0
CRAP 23.2
« Moose/Instrument/OI_Mercury/Magnet.pm ↑ Summary Moose/Sweep/Step.pm »
1 package Lab::Moose::Sweep::Step::Magnet;
2 1 $Lab::Moose::Sweep::Step::Magnet::VERSION = '3.881';
3 #ABSTRACT: Step/list sweep of magnetic field
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Lab::Moose::Countdown;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 extends 'Lab::Moose::Sweep::Step';
12 1 has instrument =>
13 ( is => 'ro', isa => 'Lab::Moose::Instrument', required => 1 );
14  
15 1 has start_rate =>
16 ( is => 'ro', isa => 'Lab::Moose::PosNum', writer => '_start_rate' );
17 1 has rate => ( is => 'ro', isa => 'Lab::Moose::PosNum', required => 1 );
18  
19 1 has _current_rate => ( is => 'rw', isa => 'Lab::Moose::PosNum' );
20  
21 1 has filename_extension => ( is => 'ro', isa => 'Str', default => 'Field=' );
22  
23 1 has setter => ( is => 'ro', isa => 'CodeRef', builder => '_build_setter' );
24  
25 1 has persistent_mode => ( is => 'ro', isa => 'Bool', default => 0 );
26  
27 sub BUILD {
28 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod undocumented
29 0 ▶ if ( not defined $self->start_rate ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->start_rate) 0 0 0
30 0 $self->_start_rate( $self->rate );
31 }
32  
33 0 ▶ if ( $self->persistent_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->persistent_mode) 0 0 0
34 0 $self->_current_rate( $self->start_rate );
35  
36 # the _field_setter needs a well-defined initial state
37 0 $self->set_persistent_mode();
38 }
39 }
40  
41 before 'go_to_sweep_start' => sub {
42 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 0 $self->_current_rate( $self->start_rate );
44 1 };
45  
46 after 'go_to_sweep_start' => sub {
47 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 $self->_current_rate( $self->rate );
49 1 };
50  
51 sub _build_setter {
52 0 ▶ return \&_field_setter;
Subroutine _build_setter: not called CC=1 SCAR=6.9
53 }
54  
55 sub set_persistent_mode {
56 0 ▶ my $self = shift;
Subroutine set_persistent_mode: not called CC=2 SCAR=17.9
Pod undocumented
57 0 my $instrument = $self->instrument();
58 0 ▶ if ( $instrument->in_persistent_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($instrument->in_persistent_mode) 0 0 0
59 0 return;
60 }
61  
62 0 $instrument->heater_off();
63 0 my $rate = $self->_current_rate;
64 0 $instrument->sweep_to_field( target => 0, rate => $rate );
65 0 countdown( 10, "Set persistent mode: " );
66 }
67  
68 sub unset_persistent_mode {
69 0 ▶ my $self = shift;
Subroutine unset_persistent_mode: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my $instrument = $self->instrument();
71 0 ▶ if ( not $instrument->in_persistent_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($instrument->in_persistent_mode) 0 0 0
72 0 return;
73 }
74 0 my $persistent_field = $instrument->get_persistent_field();
75 0 my $rate = $self->_current_rate;
76 0 $instrument->sweep_to_field( target => $persistent_field, rate => $rate );
77 0 $instrument->heater_on();
78 }
79  
80 sub _field_setter {
81 0 ▶ my $self = shift;
Subroutine _field_setter: not called CC=3 SCAR=24.8
82 0 my $value = shift;
83 0 my $rate = $self->_current_rate;
84 0 ▶ if ( $self->persistent_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->persistent_mode) 0 0 0
85 0 $self->unset_persistent_mode();
86 }
87  
88 0 $self->instrument->sweep_to_field( target => $value, rate => $rate );
89  
90 0 ▶ if ( $self->persistent_mode ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->persistent_mode) 0 0 0
91 0 $self->set_persistent_mode();
92 }
93 }
94  
95 1 __PACKAGE__->meta->make_immutable();
96 1 1;
97  
98 __END__
99  
100 =pod
101  
102 =encoding UTF-8
103  
104 =head1 NAME
105  
106 Lab::Moose::Sweep::Step::Magnet - Step/list sweep of magnetic field
107  
108 =head1 VERSION
109  
110 version 3.881
111  
112 =head1 SYNOPSIS
113  
114 my $sweep = sweep(
115 type => 'Step::Magnet',
116 instrument => $ips,
117 from => -1, # Tesla
118 to => 1, # Tesla
119 step => 0.1, # Tesla
120 rate => 1, # Tesla/min, mandatory, always positive,
121 # used to change the magnetic field
122 start_rate => 1, # Tesla/min, default equals rate, always positive,
123 # used when switch heater is off
124 persistent_mode => 1, # use persistent mode, default 0
125 );
126  
127 =head1 Description
128  
129 Step sweep with following properties:
130  
131 =over
132  
133 =item *
134  
135 Uses instruments C<sweep_to_field> method to set the field.
136  
137 =item *
138  
139 Uses instruments C<in_persistent_mode> and C<get_persistent_field> methods to query persistent mode status
140  
141 =item *
142  
143 Uses instruments C<heater_off> and C<heater_on> to control persistent mode switch
144  
145 =item *
146  
147 Default filename extension: C<'Field='>
148  
149 =back
150  
151 =head1 COPYRIGHT AND LICENSE
152  
153 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
154  
155 Copyright 2018-2019 Simon Reinhardt
156 2020 Andreas K. Huettel, Simon Reinhardt
157 2021 Andreas K. Huettel, Fabian Weinelt
158  
159  
160 This is free software; you can redistribute it and/or modify it under
161 the same terms as the Perl 5 programming language system itself.
162  
163 =cut
« Moose/Instrument/OI_Mercury/Magnet.pm ↑ Summary Moose/Sweep/Step.pm »