| 1 |
|
| package Lab::XPRESS::Sweep; |
| 2 |
|
| $Lab::XPRESS::Sweep::VERSION = '3.899'; |
| 3 |
|
| #ABSTRACT: Base sweep class |
| 4 |
|
| |
| 5 |
|
| use v5.20; |
| 6 |
|
| |
| 7 |
|
| use Role::Tiny::With; |
| 8 |
|
| |
| 9 |
|
| use Time::HiRes qw/usleep/, qw/time/; |
| 10 |
|
| use POSIX qw(ceil); |
| 11 |
|
| use Term::ReadKey; |
| 12 |
|
| use Storable qw(dclone); |
| 13 |
|
| use Lab::Generic; |
| 14 |
|
| use Lab::XPRESS::Sweep::Dummy; |
| 15 |
|
| use Lab::XPRESS::Utilities::Utilities; |
| 16 |
|
| use Lab::Exception; |
| 17 |
|
| use Carp; |
| 18 |
|
| use strict; |
| 19 |
|
| |
| 20 |
|
| use Storable qw(dclone); |
| 21 |
|
| $Storable::forgive_me = 1; |
| 22 |
|
| |
| 23 |
|
| use Carp qw(cluck croak); |
| 24 |
|
| |
| 25 |
|
| our @ISA = ('Lab::Generic'); |
| 26 |
|
| |
| 27 |
|
| our $PAUSE = 0; |
| 28 |
|
| our $ACTIVE_SWEEPS = (); |
| 29 |
|
| |
| 30 |
|
| our $AUTOLOAD; |
| 31 |
|
| |
| 32 |
|
| sub new { |
| 33 |
|
| my $proto = shift; |
| 34 |
|
| my $class = ref($proto) || $proto; |
| 35 |
|
| my $self = $class->SUPER::new(@_); |
| 36 |
|
| |
| 37 |
|
| $self->{default_config} = { |
| 38 |
|
| instrument => undef, |
| 39 |
|
| allowed_instruments => [undef], |
| 40 |
|
| |
| 41 |
|
| interval => 0, |
| 42 |
|
| mode => 'dummy', |
| 43 |
|
| delay_before_loop => 0, |
| 44 |
|
| delay_in_loop => 0, |
| 45 |
|
| delay_after_loop => 0, |
| 46 |
|
| before_loop => undef, |
| 47 |
|
| |
| 48 |
|
| points => [ undef, undef ], |
| 49 |
|
| |
| 50 |
|
| rate => [undef], |
| 51 |
|
| duration => [undef], |
| 52 |
|
| |
| 53 |
|
| stepwidth => [undef], |
| 54 |
|
| number_of_points => [undef], |
| 55 |
|
| |
| 56 |
|
| backsweep => 0, |
| 57 |
|
| repetitions => 1, |
| 58 |
|
| |
| 59 |
|
| separate_files => 0, |
| 60 |
|
| folders => 1, |
| 61 |
|
| |
| 62 |
|
| filename_extension => '#' |
| 63 |
|
| }; |
| 64 |
|
| |
| 65 |
|
| $self->{LOG} = (); |
| 66 |
|
| @{ $self->{LOG} }[0] = {}; |
| 67 |
|
| |
| 68 |
|
| # deep copy $default_config: |
| 69 |
|
| while ( my ( $k, $v ) = each %{ $self->{default_config} } ) { |
| 70 |
|
| if ( ref($v) eq 'ARRAY' ) { |
| 71 |
|
| $self->{config}->{$k} = (); |
| 72 |
|
| foreach ( @{$v} ) { |
| 73 |
|
| push( @{ $self->{config}->{$k} }, $_ ); |
| 74 |
|
| } |
| 75 |
|
| } |
| 76 |
|
| else { |
| 77 |
|
| $self->{config}->{$k} = $v; |
| 78 |
|
| } |
| 79 |
|
| } |
| 80 |
|
| |
| 81 |
|
| my $type = ref $_[0]; |
| 82 |
|
| |
| 83 |
|
| if ( $type =~ /HASH/ ) { |
| 84 |
|
| %{ $self->{config} } |
| 85 |
|
| = ( %{ $self->{config} }, %{ shift @_ }, %{ shift @_ } ); |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| #for debugging: print config parameters: |
| 89 |
|
| # while ( my ($k,$v) = each %{$self->{config}} ) |
| 90 |
|
| # { |
| 91 |
|
| # print "$k => $v\n"; |
| 92 |
|
| # } |
| 93 |
|
| # print "\n\n"; |
| 94 |
|
| |
| 95 |
|
| # print "\n\n"; |
| 96 |
|
| |
| 97 |
|
| $self->prepaire_config(); |
| 98 |
|
| |
| 99 |
|
| $self->{master} = undef; |
| 100 |
|
| $self->{slaves} = (); |
| 101 |
|
| $self->{slave_counter} = 0; |
| 102 |
|
| |
| 103 |
|
| $self->{DataFile_counter} = 0; |
| 104 |
|
| $self->{DataFiles} = (); |
| 105 |
|
| |
| 106 |
|
| $self->{filenamebase} = (); |
| 107 |
|
| $self->{filename_extensions} = []; |
| 108 |
|
| |
| 109 |
|
| $self->{pause} = 0; |
| 110 |
|
| $self->{active} = 0; |
| 111 |
|
| $self->{repetition} = 0; |
| 112 |
|
| |
| 113 |
|
| return bless $self, $class; |
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
|
| sub prepaire_config { |
| 117 |
|
| my $self = shift; |
| 118 |
|
| |
| 119 |
|
| # deep Copy original Config Data: |
| 120 |
|
| |
| 121 |
|
| # correct typing errors: |
| 122 |
|
| $self->{config}->{mode} =~ s/\s+//g; #remove all whitespaces |
| 123 |
|
| $self->{config}->{mode} =~ "\L$self->{config}->{mode}" |
| 124 |
|
| ; # transform all uppercase letters to lowercase letters |
| 125 |
|
| if ( $self->{config}->{mode} |
| 126 |
|
| =~ /continuous|contious|cont|continuouse|continouse|coninuos|continuose/ |
| 127 |
|
| ) { |
| 128 |
|
| $self->{config}->{mode} = 'continuous'; |
| 129 |
|
| } |
| 130 |
|
| |
| 131 |
|
| # make an Array out of single values if necessary: |
| 132 |
|
| if ( ref( $self->{config}->{points} ) ne 'ARRAY' ) { |
| 133 |
|
| $self->{config}->{points} = [ $self->{config}->{points} ]; |
| 134 |
|
| } |
| 135 |
|
| if ( ref( $self->{config}->{rate} ) ne 'ARRAY' ) { |
| 136 |
|
| $self->{config}->{rate} = [ $self->{config}->{rate} ]; |
| 137 |
|
| } |
| 138 |
|
| if ( ref( $self->{config}->{duration} ) ne 'ARRAY' ) { |
| 139 |
|
| $self->{config}->{duration} = [ $self->{config}->{duration} ]; |
| 140 |
|
| } |
| 141 |
|
| if ( ref( $self->{config}->{stepwidth} ) ne 'ARRAY' ) { |
| 142 |
|
| $self->{config}->{stepwidth} = [ $self->{config}->{stepwidth} ]; |
| 143 |
|
| } |
| 144 |
|
| if ( ref( $self->{config}->{number_of_points} ) ne 'ARRAY' ) { |
| 145 |
|
| $self->{config}->{number_of_points} |
| 146 |
|
| = [ $self->{config}->{number_of_points} ]; |
| 147 |
|
| } |
| 148 |
|
| if ( ref( $self->{config}->{interval} ) ne 'ARRAY' ) { |
| 149 |
|
| $self->{config}->{interval} = [ $self->{config}->{interval} ]; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
|
| $self->{config_original} = dclone( $self->{config} ); |
| 153 |
|
| |
| 154 |
|
| # calculate the length of each Array: |
| 155 |
|
| my $length_points = @{ $self->{config}->{points} }; |
| 156 |
|
| my $length_rate = @{ $self->{config}->{rate} }; |
| 157 |
|
| my $length_duration = @{ $self->{config}->{duration} }; |
| 158 |
|
| my $length_stepwidth = @{ $self->{config}->{stepwidth} }; |
| 159 |
|
| my $length_number_of_points = @{ $self->{config}->{number_of_points} }; |
| 160 |
|
| my $length_interval = @{ $self->{config}->{interval} }; |
| 161 |
|
| |
| 162 |
|
| # Look for inconsistent sweep parameters: |
| 163 |
|
| if ( $length_points < 2 and $self->{config}->{mode} ne 'list' ) { |
| 164 |
|
| die |
| 165 |
|
| "inconsistent definition of sweep_config_data: less than two elements defined in 'points'. You need at least a 'start' and a 'stop' point."; |
| 166 |
|
| } |
| 167 |
|
| |
| 168 |
|
| if ( $length_rate > $length_points ) { |
| 169 |
|
| die |
| 170 |
|
| "inconsistent definition of sweep_config_data: number of elements in 'rate' larger than number of elements in 'points'."; |
| 171 |
|
| } |
| 172 |
|
| if ( $length_duration > $length_points ) { |
| 173 |
|
| die |
| 174 |
|
| "inconsistent definition of sweep_config_data: number of elements in 'duration' larger than number of elements in 'points'."; |
| 175 |
|
| } |
| 176 |
|
| if ( $length_stepwidth > $length_points - 1 |
| 177 |
|
| and $self->{config}->{mode} ne 'list' ) { |
| 178 |
|
| die |
| 179 |
|
| "inconsistent definition of sweep_config_data: number of elements in 'stepwidth' larger than number of sweep sequences."; |
| 180 |
|
| } |
| 181 |
|
| if ( $length_number_of_points > $length_points - 1 |
| 182 |
|
| and $self->{config}->{mode} ne 'list' ) { |
| 183 |
|
| die |
| 184 |
|
| "inconsistent definition of sweep_config_data: number of elements in 'number_of_points' larger than number of sweep sequences."; |
| 185 |
|
| } # |
| 186 |
|
| if ( $length_interval > $length_points |
| 187 |
|
| and $self->{config}->{mode} ne 'list' ) { |
| 188 |
|
| die |
| 189 |
|
| "inconsistent definition of sweep_config_data: number of elements in 'interval' larger than number of sweep sequences."; |
| 190 |
|
| } |
| 191 |
|
| |
| 192 |
|
| # fill up Arrays to fit with given Points: |
| 193 |
|
| while ( ( $length_rate = @{ $self->{config}->{rate} } ) < $length_points ) |
| 194 |
|
| { |
| 195 |
|
| push( |
| 196 |
|
| @{ $self->{config}->{rate} }, |
| 197 |
|
| @{ $self->{config}->{rate} }[-1] |
| 198 |
|
| ); |
| 199 |
|
| } |
| 200 |
|
| |
| 201 |
|
| while ( ( $length_duration = @{ $self->{config}->{duration} } ) |
| 202 |
|
| < $length_points ) { |
| 203 |
|
| push( |
| 204 |
|
| @{ $self->{config}->{duration} }, |
| 205 |
|
| @{ $self->{config}->{duration} }[-1] |
| 206 |
|
| ); |
| 207 |
|
| } |
| 208 |
|
| |
| 209 |
|
| while ( ( $length_stepwidth = @{ $self->{config}->{stepwidth} } ) |
| 210 |
|
| < $length_points ) { |
| 211 |
|
| push( |
| 212 |
|
| @{ $self->{config}->{stepwidth} }, |
| 213 |
|
| @{ $self->{config}->{stepwidth} }[-1] |
| 214 |
|
| ); |
| 215 |
|
| } |
| 216 |
|
| |
| 217 |
|
| while ( |
| 218 |
|
| ( |
| 219 |
|
| $length_number_of_points |
| 220 |
|
| = @{ $self->{config}->{number_of_points} } |
| 221 |
|
| ) < $length_points |
| 222 |
|
| ) { |
| 223 |
|
| push( |
| 224 |
|
| @{ $self->{config}->{number_of_points} }, |
| 225 |
|
| @{ $self->{config}->{number_of_points} }[-1] |
| 226 |
|
| ); |
| 227 |
|
| } |
| 228 |
|
| |
| 229 |
|
| while ( ( $length_interval = @{ $self->{config}->{interval} } ) |
| 230 |
|
| < $length_points ) { |
| 231 |
|
| push( |
| 232 |
|
| @{ $self->{config}->{interval} }, |
| 233 |
|
| @{ $self->{config}->{interval} }[-1] |
| 234 |
|
| ); |
| 235 |
|
| } |
| 236 |
|
| |
| 237 |
|
| # calculate the length of each Array again: |
| 238 |
|
| my $length_points = @{ $self->{config}->{points} }; |
| 239 |
|
| my $length_rate = @{ $self->{config}->{rate} }; |
| 240 |
|
| my $length_duration = @{ $self->{config}->{duration} }; |
| 241 |
|
| my $length_stepwidth = @{ $self->{config}->{stepwidth} }; |
| 242 |
|
| my $length_number_of_points = @{ $self->{config}->{number_of_points} }; |
| 243 |
|
| |
| 244 |
|
| # evaluate sweep sign: |
| 245 |
|
| foreach my $i ( 0 .. $length_points - 2 ) { |
| 246 |
|
| if ( @{ $self->{config}->{points} }[$i] |
| 247 |
|
| - @{ $self->{config}->{points} }[ $i + 1 ] < 0 ) { |
| 248 |
|
| @{ $self->{config}->{sweepsigns} }[$i] = 1; |
| 249 |
|
| } |
| 250 |
|
| elsif ( @{ $self->{config}->{points} }[$i] |
| 251 |
|
| - @{ $self->{config}->{points} }[ $i + 1 ] > 0 ) { |
| 252 |
|
| @{ $self->{config}->{sweepsigns} }[$i] = -1; |
| 253 |
|
| } |
| 254 |
|
| else { |
| 255 |
|
| @{ $self->{config}->{sweepsigns} }[$i] = 0; |
| 256 |
|
| } |
| 257 |
|
| } |
| 258 |
|
| |
| 259 |
|
| # add current position to Points-Array: |
| 260 |
|
| unshift( @{ $self->{config}->{points} }, $self->get_value() ); |
| 261 |
|
| |
| 262 |
|
| # calculate duration from rate and vise versa: |
| 263 |
|
| if ( defined @{ $self->{config}->{rate} }[0] |
| 264 |
|
| and defined @{ $self->{config}->{duration} }[0] ) { |
| 265 |
|
| die |
| 266 |
|
| 'inconsistent definition of sweep_config_data: rate as well as duration defined. Use only one of both.'; |
| 267 |
|
| } |
| 268 |
|
| elsif ( defined @{ $self->{config}->{duration} }[0] |
| 269 |
|
| and @{ $self->{config}->{duration} }[0] == 0 ) { |
| 270 |
|
| die 'bad definition of sweep parameters: duration == 0 not allowed'; |
| 271 |
|
| } |
| 272 |
|
| elsif ( defined @{ $self->{config}->{rate} }[0] |
| 273 |
|
| and @{ $self->{config}->{rate} }[0] == 0 ) { |
| 274 |
|
| die 'bad definition of sweep parameters: rate == 0 not allowed'; |
| 275 |
|
| } |
| 276 |
|
| elsif ( defined @{ $self->{config}->{duration} }[0] ) { |
| 277 |
|
| foreach my $i ( 0 .. $length_points - 1 ) { |
| 278 |
|
| @{ $self->{config}->{rate} }[$i] |
| 279 |
|
| = abs(@{ $self->{config}->{points} }[ $i + 1 ] |
| 280 |
|
| - @{ $self->{config}->{points} }[$i] ) |
| 281 |
|
| / @{ $self->{config}->{duration} }[$i]; |
| 282 |
|
| } |
| 283 |
|
| } |
| 284 |
|
| elsif ( defined @{ $self->{config}->{rate} }[0] ) { |
| 285 |
|
| foreach my $i ( 0 .. $length_points - 1 ) { |
| 286 |
|
| @{ $self->{config}->{duration} }[$i] |
| 287 |
|
| = abs(@{ $self->{config}->{points} }[ $i + 1 ] |
| 288 |
|
| - @{ $self->{config}->{points} }[$i] ) |
| 289 |
|
| / @{ $self->{config}->{rate} }[$i]; |
| 290 |
|
| } |
| 291 |
|
| } |
| 292 |
|
| |
| 293 |
|
| # calculate stepwidth from Number_of_Points and vise versa: |
| 294 |
|
| if ( defined @{ $self->{config}->{stepwidth} }[0] |
| 295 |
|
| and defined @{ $self->{config}->{number_of_points} }[0] ) { |
| 296 |
|
| die |
| 297 |
|
| 'inconsistent definition of sweep_config_data: step as well as number_of_points defined. Use only one of both.'; |
| 298 |
|
| } |
| 299 |
|
| elsif ( defined @{ $self->{config}->{number_of_points} }[0] ) { |
| 300 |
|
| unshift( @{ $self->{config}->{number_of_points} }, 1 ); |
| 301 |
|
| foreach my $i ( 1 .. $length_points - 1 ) { |
| 302 |
|
| @{ $self->{config}->{stepwidth} }[ $i - 1 ] |
| 303 |
|
| = abs(@{ $self->{config}->{points} }[ $i + 1 ] |
| 304 |
|
| - @{ $self->{config}->{points} }[$i] ) |
| 305 |
|
| / @{ $self->{config}->{number_of_points} }[$i]; |
| 306 |
|
| } |
| 307 |
|
| } |
| 308 |
|
| elsif ( defined @{ $self->{config}->{stepwidth} }[0] ) { |
| 309 |
|
| foreach my $i ( 1 .. $length_points - 1 ) { |
| 310 |
|
| @{ $self->{config}->{number_of_points} }[ $i - 1 ] |
| 311 |
|
| = abs(@{ $self->{config}->{points} }[ $i + 1 ] |
| 312 |
|
| - @{ $self->{config}->{points} }[$i] ) |
| 313 |
|
| / @{ $self->{config}->{stepwidth} }[$i]; |
| 314 |
|
| } |
| 315 |
|
| } |
| 316 |
|
| shift @{ $self->{config}->{points} }; |
| 317 |
|
| |
| 318 |
|
| # Calculations and checks depending on the selected sweep mode: |
| 319 |
|
| if ( $self->{config}->{mode} eq 'continuous' ) { |
| 320 |
|
| if ( not defined @{ $self->{config}->{rate} }[0] |
| 321 |
|
| or not defined @{ $self->{config}->{duration} }[0] ) { |
| 322 |
|
| die |
| 323 |
|
| "inconsistent definition of sweep_config_data: for sweep_mode 'continuous' you have to define the rate or the duration for the sweep."; |
| 324 |
|
| } |
| 325 |
|
| } |
| 326 |
|
| elsif ( $self->{config}->{mode} eq 'step' ) { |
| 327 |
|
| $self->{config}->{interval} = [0]; |
| 328 |
|
| if ( not defined @{ $self->{config}->{stepwidth} }[0] |
| 329 |
|
| or not defined @{ $self->{config}->{number_of_points} }[0] ) { |
| 330 |
|
| die |
| 331 |
|
| "inconsistent definition of sweep_config_data: for sweep_mode 'step' you have to define the setp-size or the number_of_points."; |
| 332 |
|
| } |
| 333 |
|
| |
| 334 |
|
| # calculate each point/rate/stepsign/duration in step-sweep: |
| 335 |
|
| my $temp_points = (); |
| 336 |
|
| my $temp_rate = (); |
| 337 |
|
| my $temp_sweepsigns = (); |
| 338 |
|
| my $temp_duration = (); |
| 339 |
|
| |
| 340 |
|
| foreach my $i ( 0 .. $length_points - 2 ) { |
| 341 |
|
| my $nop = abs( |
| 342 |
|
| ( |
| 343 |
|
| @{ $self->{config}->{points} }[ $i + 1 ] |
| 344 |
|
| - @{ $self->{config}->{points} }[$i] |
| 345 |
|
| ) / @{ $self->{config}->{stepwidth} }[$i] |
| 346 |
|
| ); |
| 347 |
|
| $nop = ceil($nop); |
| 348 |
|
| |
| 349 |
|
| my $point = @{ $self->{config}->{points} }[$i]; |
| 350 |
|
| for ( my $j = 0; $j <= $nop; $j++ ) { |
| 351 |
|
| if ( $point != @{$temp_points}[-1] |
| 352 |
|
| or not defined @{$temp_points}[-1] ) { |
| 353 |
|
| push( @{$temp_points}, $point ); |
| 354 |
|
| push( |
| 355 |
|
| @{$temp_rate}, |
| 356 |
|
| @{ $self->{config}->{rate} }[ $i + 1 ] |
| 357 |
|
| ); |
| 358 |
|
| push( |
| 359 |
|
| @{$temp_duration}, |
| 360 |
|
| @{ $self->{config}->{duration} }[ $i + 1 ] |
| 361 |
|
| / @{ $self->{config}->{number_of_points} }[$i] |
| 362 |
|
| ); |
| 363 |
|
| push( |
| 364 |
|
| @{$temp_sweepsigns}, |
| 365 |
|
| @{ $self->{config}->{sweepsigns} }[$i] |
| 366 |
|
| ); |
| 367 |
|
| } |
| 368 |
|
| $point += @{ $self->{config}->{stepwidth} }[$i] |
| 369 |
|
| * @{ $self->{config}->{sweepsigns} }[$i]; |
| 370 |
|
| } |
| 371 |
|
| @{$temp_points}[-1] = @{ $self->{config}->{points} }[ $i + 1 ]; |
| 372 |
|
| } |
| 373 |
|
| pop @{$temp_rate}; |
| 374 |
|
| pop @{$temp_duration}; |
| 375 |
|
| pop @{$temp_sweepsigns}; |
| 376 |
|
| unshift( @{$temp_rate}, @{ $self->{config}->{rate} }[0] ); |
| 377 |
|
| unshift( @{$temp_duration}, @{ $self->{config}->{duration} }[0] ); |
| 378 |
|
| |
| 379 |
|
| #unshift ( @{$temp_sweepsigns}, @{$self->{config}->{sweepsigns}}[0]); |
| 380 |
|
| |
| 381 |
|
| $self->{config}->{points} = $temp_points; |
| 382 |
|
| $self->{config}->{rate} = $temp_rate; |
| 383 |
|
| $self->{config}->{duration} = $temp_duration; |
| 384 |
|
| $self->{config}->{sweepsigns} = $temp_sweepsigns; |
| 385 |
|
| } |
| 386 |
|
| elsif ( $self->{config}->{mode} eq 'list' ) { |
| 387 |
|
| $self->{config}->{interval} = [0]; |
| 388 |
|
| if ( not defined @{ $self->{config}->{rate} }[0] ) { |
| 389 |
|
| die |
| 390 |
|
| "inconsistent definition of sweep_config_data: 'rate' needs to be defined in sweep mode 'list'"; |
| 391 |
|
| } |
| 392 |
|
| } |
| 393 |
|
| |
| 394 |
|
| # check if instrument is supported: |
| 395 |
|
| if ( |
| 396 |
|
| defined @{ $self->{config}->{allowed_instruments} }[0] |
| 397 |
|
| and not( grep { $_ eq ref( $self->{config}->{instrument} ) } |
| 398 |
|
| @{ $self->{config}->{allowed_instruments} } ) |
| 399 |
|
| ) { |
| 400 |
|
| die |
| 401 |
|
| "inconsistent definition of sweep_config_data: Instrument (ref($self->{config}->{instrument})) is not supported by Sweep."; |
| 402 |
|
| } |
| 403 |
|
| |
| 404 |
|
| # check if sweep-mode is supported: |
| 405 |
|
| if ( |
| 406 |
|
| defined @{ $self->{config}->{allowed_sweep_modes} }[0] |
| 407 |
|
| and not( grep { $_ eq $self->{config}->{mode} } |
| 408 |
|
| @{ $self->{config}->{allowed_sweep_modes} } ) |
| 409 |
|
| ) { |
| 410 |
|
| die |
| 411 |
|
| "inconsistent definition of sweep_config_data: Sweep mode $self->{config}->{mode} is not supported by Sweep."; |
| 412 |
|
| } |
| 413 |
|
| |
| 414 |
|
| # adjust repetitions in case of Backsweep selected: |
| 415 |
|
| |
| 416 |
|
| if ( $self->{config}->{backsweep} == 1 ) { |
| 417 |
|
| $self->{config}->{repetitions} *= 2; |
| 418 |
|
| } |
| 419 |
|
| |
| 420 |
|
| } |
| 421 |
|
| |
| 422 |
|
| sub prepare_backsweep { |
| 423 |
|
| my $self = shift; |
| 424 |
|
| my $points = (); |
| 425 |
|
| my $rates = (); |
| 426 |
|
| my $durations = (); |
| 427 |
|
| foreach my $point ( @{ $self->{config}->{points} } ) { |
| 428 |
|
| unshift( @{$points}, $point ); |
| 429 |
|
| } |
| 430 |
|
| foreach my $rate ( @{ $self->{config}->{rate} } ) { |
| 431 |
|
| unshift( @{$rates}, $rate ); |
| 432 |
|
| } |
| 433 |
|
| foreach my $duration ( @{ $self->{config}->{duration} } ) { |
| 434 |
|
| unshift( @{$durations}, $duration ); |
| 435 |
|
| } |
| 436 |
|
| |
| 437 |
|
| unshift( @{$rates}, pop( @{$rates} ) ); |
| 438 |
|
| unshift( @{$durations}, 0 ); |
| 439 |
|
| pop( @{$durations} ); |
| 440 |
|
| |
| 441 |
|
| #print "Points @{$points} \n"; |
| 442 |
|
| #print "rate @{$rate} \n"; |
| 443 |
|
| #print "duration @{$duration} \n"; |
| 444 |
|
| $self->{config}->{points} = $points; |
| 445 |
|
| $self->{config}->{rate} = $rates; |
| 446 |
|
| $self->{config}->{duration} = $durations; |
| 447 |
|
| |
| 448 |
|
| } |
| 449 |
|
| |
| 450 |
|
| sub add_DataFile { |
| 451 |
|
| my $self = shift; |
| 452 |
|
| my $DataFile = shift; |
| 453 |
|
| |
| 454 |
|
| push( @{ $self->{filenamebase} }, $DataFile->{filenamebase} ); |
| 455 |
|
| |
| 456 |
|
| push( @{ $self->{DataFiles} }, $DataFile ); |
| 457 |
|
| $self->{DataFile_counter}++; |
| 458 |
|
| |
| 459 |
|
| @{ $self->{LOG} }[ $self->{DataFile_counter} ] = {}; |
| 460 |
|
| |
| 461 |
|
| return $self; |
| 462 |
|
| } |
| 463 |
|
| |
| 464 |
|
| sub start { |
| 465 |
|
| my $self = shift; |
| 466 |
|
| ReadMode('cbreak'); |
| 467 |
|
| |
| 468 |
|
| unshift( @{$ACTIVE_SWEEPS}, $self ); |
| 469 |
|
| |
| 470 |
|
| # calculate duration for the defined sweep: |
| 471 |
|
| #$self->estimate_sweep_duration(); |
| 472 |
|
| foreach my $slave ( @{ $self->{slaves} } ) { |
| 473 |
|
| |
| 474 |
|
| #$slave->estimate_sweep_duration(); |
| 475 |
|
| } |
| 476 |
|
| |
| 477 |
|
| # show estimated sweep duration: |
| 478 |
|
| #my $sweep_structure = $self->sweep_structure(); |
| 479 |
|
| |
| 480 |
|
| # create header for each DataFile: |
| 481 |
|
| foreach my $file ( @{ $self->{DataFiles} } ) { |
| 482 |
|
| foreach my $instrument ( @{ ${Lab::Instrument::INSTRUMENTS} } ) { |
| 483 |
|
| |
| 484 |
|
| #print $instrument."\n"; |
| 485 |
|
| $file->add_header( $instrument->create_header() ); |
| 486 |
|
| } |
| 487 |
|
| } |
| 488 |
|
| |
| 489 |
|
| if ( not defined @{ $self->{slaves} }[0] ) { |
| 490 |
|
| if ( $self->{DataFile_counter} <= 0 ) { |
| 491 |
|
| print new Lab::Exception::Warning( error => "Attention: " |
| 492 |
|
| . ref($self) |
| 493 |
|
| . " has no DataFile ! \n" ); |
| 494 |
|
| } |
| 495 |
|
| if ( defined @{ $self->{filename_extensions} }[0] ) { |
| 496 |
|
| foreach my $DataFile ( @{ $self->{DataFiles} } ) { |
| 497 |
|
| my $filenamebase = $DataFile->{filenamebase}; |
| 498 |
|
| my $new_filenamebase |
| 499 |
|
| = $self->add_filename_extensions($filenamebase); |
| 500 |
|
| if ( $new_filenamebase ne $DataFile->{file} ) { |
| 501 |
|
| $DataFile->change_filenamebase($new_filenamebase); |
| 502 |
|
| } |
| 503 |
|
| } |
| 504 |
|
| } |
| 505 |
|
| |
| 506 |
|
| # elsif ($self->{config}->{separate_files} == 1) { |
| 507 |
|
| # foreach my $DataFile (@{$self->{DataFiles}}) { |
| 508 |
|
| # my $filenamebase = $DataFile->{filenamebase}; |
| 509 |
|
| # $DataFile->change_filenamebase($filenamebase); |
| 510 |
|
| # } |
| 511 |
|
| # } |
| 512 |
|
| |
| 513 |
|
| } |
| 514 |
|
| |
| 515 |
|
| # link break signals to default functions: |
| 516 |
|
| $SIG{BREAK} = \&enable_pause; |
| 517 |
|
| |
| 518 |
|
| #$SIG{INT} = \&abort; |
| 519 |
|
| |
| 520 |
|
| for ( |
| 521 |
|
| my $i = 1; |
| 522 |
|
| ( $i <= $self->{config}->{repetitions} ) |
| 523 |
|
| or ( $self->{config}->{repetitions} < 0 ); |
| 524 |
|
| $i++ |
| 525 |
|
| ) { |
| 526 |
|
| $self->{repetition}++; |
| 527 |
|
| foreach my $file ( @{ $self->{DataFiles} } ) { |
| 528 |
|
| $file->start_block(); |
| 529 |
|
| } |
| 530 |
|
| $self->{iterator} = 0; |
| 531 |
|
| $self->{sequence} = 0; |
| 532 |
|
| $self->before_loop(); |
| 533 |
|
| $self->go_to_sweep_start(); |
| 534 |
|
| $self->delay( $self->{config}->{delay_before_loop} ); |
| 535 |
|
| my $before_loop = $self->{config}{before_loop}; |
| 536 |
|
| |
| 537 |
|
| if ($before_loop) { |
| 538 |
|
| if ( ref $before_loop ne 'CODE' ) { |
| 539 |
|
| croak "'before_loop' argument must be a coderef"; |
| 540 |
|
| } |
| 541 |
|
| $self->$before_loop(); |
| 542 |
|
| } |
| 543 |
|
| |
| 544 |
|
| # continuous sweep: |
| 545 |
|
| if ( $self->{config}->{mode} eq 'continuous' ) { |
| 546 |
|
| $self->start_continuous_sweep(); |
| 547 |
|
| } |
| 548 |
|
| $self->{Time_start} = time(); |
| 549 |
|
| $self->{Date_start}, $self->{TimeStamp_start} = timestamp(); |
| 550 |
|
| $self->{loop}->{t0} = $self->{Time_start}; |
| 551 |
|
| |
| 552 |
|
| $self->{active} = 1; |
| 553 |
|
| |
| 554 |
|
| while (1) { |
| 555 |
|
| $self->in_loop(); |
| 556 |
|
| |
| 557 |
|
| # step mode: |
| 558 |
|
| if ( $self->{config}->{mode} =~ /step|list/ ) { |
| 559 |
|
| $self->go_to_next_step(); |
| 560 |
|
| $self->delay( $self->{config}->{delay_in_loop} ); |
| 561 |
|
| } |
| 562 |
|
| $self->{Time} = time() - $self->{Time_start}; |
| 563 |
|
| $self->{Date}, $self->{TimeStamp} = timestamp(); |
| 564 |
|
| |
| 565 |
|
| # Master mode: call slave measurements if defined |
| 566 |
|
| if ( defined @{ $self->{slaves} }[0] ) { |
| 567 |
|
| my $extension = $self->get_filename_extension(); |
| 568 |
|
| foreach my $slave ( @{ $self->{slaves} } ) { |
| 569 |
|
| |
| 570 |
|
| my $extensions |
| 571 |
|
| = dclone( \@{ $self->{filename_extensions} } ); |
| 572 |
|
| push( @{$extensions}, $extension ); |
| 573 |
|
| |
| 574 |
|
| $slave->{filename_extensions} = $extensions; |
| 575 |
|
| |
| 576 |
|
| $slave->start($self); |
| 577 |
|
| } |
| 578 |
|
| } |
| 579 |
|
| |
| 580 |
|
| # Slave mode: do measurement |
| 581 |
|
| else { |
| 582 |
|
| my $i = 1; |
| 583 |
|
| foreach my $DataFile ( @{ $self->{DataFiles} } ) { |
| 584 |
|
| |
| 585 |
|
| $DataFile->{measurement}->($self); |
| 586 |
|
| if ( $DataFile->{autolog} == 1 ) { |
| 587 |
|
| $DataFile->LOG( $self->create_LOG_HASH($i) ); |
| 588 |
|
| } |
| 589 |
|
| |
| 590 |
|
| $i++; |
| 591 |
|
| } |
| 592 |
|
| } |
| 593 |
|
| |
| 594 |
|
| # exit loop: |
| 595 |
|
| if ( $self->exit_loop() or $self->{last} ) { |
| 596 |
|
| $self->{last} = 0; |
| 597 |
|
| last; |
| 598 |
|
| } |
| 599 |
|
| |
| 600 |
|
| # pause: |
| 601 |
|
| if ( $self->{config}->{mode} =~ /step|list/ and $PAUSE ) { |
| 602 |
|
| $self->pause(); |
| 603 |
|
| $PAUSE = 0; |
| 604 |
|
| } |
| 605 |
|
| |
| 606 |
|
| # check loop duratioin: |
| 607 |
|
| $self->{iterator}++; |
| 608 |
|
| $self->check_loop_duration(); |
| 609 |
|
| } |
| 610 |
|
| |
| 611 |
|
| $self->{active} = 0; |
| 612 |
|
| |
| 613 |
|
| $self->after_loop(); |
| 614 |
|
| if ($PAUSE) { |
| 615 |
|
| $self->pause(); |
| 616 |
|
| $PAUSE = 0; |
| 617 |
|
| } |
| 618 |
|
| $self->delay( $self->{config}->{delay_after_loop} ); |
| 619 |
|
| |
| 620 |
|
| # prepare_backsweep: |
| 621 |
|
| if ( $self->{config}->{backsweep} > 0 ) { |
| 622 |
|
| $self->prepare_backsweep(); |
| 623 |
|
| } |
| 624 |
|
| |
| 625 |
|
| } |
| 626 |
|
| |
| 627 |
|
| # finish measurement: |
| 628 |
|
| $self->finish(); |
| 629 |
|
| |
| 630 |
|
| return $self; |
| 631 |
|
| |
| 632 |
|
| } |
| 633 |
|
| |
| 634 |
|
| sub delay { |
| 635 |
|
| my $self = shift; |
| 636 |
|
| my $delay = shift; |
| 637 |
|
| |
| 638 |
|
| if ( $delay <= 0 ) { |
| 639 |
|
| return; |
| 640 |
|
| } |
| 641 |
|
| elsif ( $delay > 1 ) { |
| 642 |
|
| my_sleep( $delay, $self, \&user_command ); |
| 643 |
|
| } |
| 644 |
|
| else { |
| 645 |
|
| my_usleep( $delay * 1e6, $self, \&user_command ); |
| 646 |
|
| } |
| 647 |
|
| |
| 648 |
|
| } |
| 649 |
|
| |
| 650 |
|
| sub estimate_sweep_duration { |
| 651 |
|
| my $self = shift; |
| 652 |
|
| my $duration = 0; |
| 653 |
|
| |
| 654 |
|
| $duration += $self->{config}->{delay_before_loop}; |
| 655 |
|
| |
| 656 |
|
| if ( $self->{config}->{mode} =~ /conti/ ) { |
| 657 |
|
| foreach ( @{ $self->{config}->{duration} } ) { |
| 658 |
|
| $duration += $_; |
| 659 |
|
| } |
| 660 |
|
| } |
| 661 |
|
| elsif ( $self->{config}->{mode} =~ /step|list/ ) { |
| 662 |
|
| foreach ( @{ $self->{config}->{duration} } ) { |
| 663 |
|
| $duration += $_; |
| 664 |
|
| $duration += $self->{config}->{delay_in_loop}; |
| 665 |
|
| } |
| 666 |
|
| } |
| 667 |
|
| |
| 668 |
|
| $duration += $self->{config}->{delay_after_loop}; |
| 669 |
|
| $duration *= $self->{config}->{repetitions}; |
| 670 |
|
| |
| 671 |
|
| $self->{config}->{estimated_sweep_duration} = $duration; |
| 672 |
|
| return $duration; |
| 673 |
|
| |
| 674 |
|
| } |
| 675 |
|
| |
| 676 |
|
| sub estimate_total_sweep_duration { |
| 677 |
|
| my $self = shift; |
| 678 |
|
| |
| 679 |
|
| if ( not defined $self->{master} ) { |
| 680 |
|
| my $duration_total = 0; |
| 681 |
|
| foreach my $slave ( @{ $self->{slaves} } ) { |
| 682 |
|
| $duration_total += $slave->{config}->{estimated_sweep_duration}; |
| 683 |
|
| } |
| 684 |
|
| |
| 685 |
|
| #print "duration_total_1: $duration_total\n"; |
| 686 |
|
| my $number_of_steps = @{ $self->{config}->{duration} } - 1; |
| 687 |
|
| $duration_total *= $number_of_steps; |
| 688 |
|
| |
| 689 |
|
| #print "duration_total_2: $duration_total\n"; |
| 690 |
|
| $duration_total += $self->{config}->{estimated_sweep_duration}; |
| 691 |
|
| |
| 692 |
|
| #print "duration_total_3: $duration_total\n"; |
| 693 |
|
| $duration_total *= $self->{config}->{repetitions}; |
| 694 |
|
| |
| 695 |
|
| #print "duration_total_4: $duration_total\n"; |
| 696 |
|
| $self->{config}->{estimated_sweep_duration_total} = $duration_total; |
| 697 |
|
| } |
| 698 |
|
| |
| 699 |
|
| } |
| 700 |
|
| |
| 701 |
|
| sub sweep_structure { |
| 702 |
|
| my $self = shift; |
| 703 |
|
| my $text = ""; |
| 704 |
|
| |
| 705 |
|
| if ( not defined $self->{master} ) { |
| 706 |
|
| $self->estimate_total_sweep_duration(); |
| 707 |
|
| |
| 708 |
|
| $text |
| 709 |
|
| .= "\n\n\n=====================================================================\n"; |
| 710 |
|
| $text |
| 711 |
|
| .= "=================== Master/Slave Sweep ============================\n"; |
| 712 |
|
| $text |
| 713 |
|
| .= "=====================================================================\n\n\n"; |
| 714 |
|
| $text .= "=========================\n"; |
| 715 |
|
| $text .= " Master = $self->{config}->{id}\n"; |
| 716 |
|
| $text .= "=========================\n"; |
| 717 |
|
| $text .= "\t|\n"; |
| 718 |
|
| $text .= "\t|\n"; |
| 719 |
|
| $text .= "\t|--> Instrument = " |
| 720 |
|
| . ref( $self->{config}->{instrument} ) . "\n"; |
| 721 |
|
| |
| 722 |
|
| # while ( my ($key,$value) = each %{$self->{config}} ) |
| 723 |
|
| # { |
| 724 |
|
| # if ( ref($value) eq "ARRAY" ) |
| 725 |
|
| # { |
| 726 |
|
| # $text .= "\t|--> $key = @{$value}\n"; |
| 727 |
|
| # } |
| 728 |
|
| # elsif ( ref($value) eq "HASH" ) |
| 729 |
|
| # { |
| 730 |
|
| # $text .= "\t|--> $key = %{$value}\n"; |
| 731 |
|
| # } |
| 732 |
|
| # else |
| 733 |
|
| # { |
| 734 |
|
| # $text .= "\t|--> $key = $value\n"; |
| 735 |
|
| # } |
| 736 |
|
| # } |
| 737 |
|
| $text .= "\t|--> Mode = $self->{config}->{mode}\n"; |
| 738 |
|
| if ( $self->{config}->{mode} =~ /conti/ ) { |
| 739 |
|
| $text .= "\t|--> Interval = $self->{config}->{interval}\n"; |
| 740 |
|
| } |
| 741 |
|
| $text .= "\t|--> Points = @{$self->{config_original}->{points}}\n"; |
| 742 |
|
| if ( $self->{config}->{mode} =~ /step/ ) { |
| 743 |
|
| $text .= "\t|--> stepwidth = @{$self->{config}->{stepwidth}}\n"; |
| 744 |
|
| } |
| 745 |
|
| $text .= "\t|--> rate = @{$self->{config_original}->{rate}}\n"; |
| 746 |
|
| $text |
| 747 |
|
| .= "\t|--> duration = @{$self->{config_original}->{duration}}\n"; |
| 748 |
|
| $text |
| 749 |
|
| .= "\t|--> Delays (before, in, after) loop = $self->{config}->{delay_before_loop}, $self->{config}->{delay_in_loop}, $self->{config}->{delay_after_loop}\n"; |
| 750 |
|
| $text .= "\t|--> Backsweep = $self->{config}->{backsweep}\n"; |
| 751 |
|
| $text |
| 752 |
|
| .= "\t|--> Repetitions = $self->{config_original}->{repetitions}\n"; |
| 753 |
|
| $text |
| 754 |
|
| .= "\t|--> Estimated Duration = " |
| 755 |
|
| . seconds2time( $self->{config}->{estimated_sweep_duration} ) |
| 756 |
|
| . "\n"; |
| 757 |
|
| $text .= "\t|----------------------------------------------------\n"; |
| 758 |
|
| |
| 759 |
|
| foreach my $slave ( @{ $self->{slaves} } ) { |
| 760 |
|
| $text .= "\t\t|\n"; |
| 761 |
|
| $text .= "\t\t|\n"; |
| 762 |
|
| $text .= "\t=========================\n"; |
| 763 |
|
| $text .= "\t Slave = $slave->{config}->{id}\n"; |
| 764 |
|
| $text .= "\t=========================\n"; |
| 765 |
|
| $text .= "\t\t|\n"; |
| 766 |
|
| $text .= "\t\t|\n"; |
| 767 |
|
| $text .= "\t\t|--> Instrument = " |
| 768 |
|
| . ref( $slave->{config}->{instrument} ) . "\n"; |
| 769 |
|
| $text .= "\t\t|--> Mode = $slave->{config}->{mode}\n"; |
| 770 |
|
| |
| 771 |
|
| if ( $slave->{config}->{mode} =~ /conti/ ) { |
| 772 |
|
| $text .= "\t\t|--> Interval = $slave->{config}->{interval}\n"; |
| 773 |
|
| } |
| 774 |
|
| $text |
| 775 |
|
| .= "\t\t|--> Points = @{$slave->{config_original}->{points}}\n"; |
| 776 |
|
| if ( $slave->{config}->{mode} =~ /step/ ) { |
| 777 |
|
| $text |
| 778 |
|
| .= "\t\t|--> stepwidth = @{$slave->{config}->{stepwidth}}\n"; |
| 779 |
|
| } |
| 780 |
|
| $text .= "\t\t|--> rate = @{$slave->{config_original}->{rate}}\n"; |
| 781 |
|
| $text |
| 782 |
|
| .= "\t\t|--> duration = @{$slave->{config_original}->{duration}}\n"; |
| 783 |
|
| $text |
| 784 |
|
| .= "\t\t|--> Delays (before, in, after) loop = $slave->{config}->{delay_before_loop}, $slave->{config}->{delay_in_loop}, $slave->{config}->{delay_after_loop}\n"; |
| 785 |
|
| $text .= "\t\t|--> Backsweep = $slave->{config}->{backsweep}\n"; |
| 786 |
|
| $text |
| 787 |
|
| .= "\t\t|--> Repetitions = $slave->{config_original}->{repetitions}\n"; |
| 788 |
|
| $text |
| 789 |
|
| .= "\t\t|--> Estimated Duration = " |
| 790 |
|
| . seconds2time( $slave->{config}->{estimated_sweep_duration} ) |
| 791 |
|
| . "\n"; |
| 792 |
|
| $text |
| 793 |
|
| .= "\t\t|----------------------------------------------------\n"; |
| 794 |
|
| } |
| 795 |
|
| $text .= "\n\n"; |
| 796 |
|
| $text |
| 797 |
|
| .= "Estimated Duration for Master/Slave-Sweep: " |
| 798 |
|
| . seconds2time( |
| 799 |
|
| $self->{config}->{estimated_sweep_duration_total} ) |
| 800 |
|
| . "\n\n\n"; |
| 801 |
|
| $text |
| 802 |
|
| .= "=====================================================================\n"; |
| 803 |
|
| $text |
| 804 |
|
| .= "=====================================================================\n\n"; |
| 805 |
|
| |
| 806 |
|
| foreach my $slave ( @{ $self->{slaves} } ) { |
| 807 |
|
| foreach my $file ( @{ $slave->{DataFiles} } ) { |
| 808 |
|
| $file->add_header($text); |
| 809 |
|
| } |
| 810 |
|
| } |
| 811 |
|
| print $text; |
| 812 |
|
| } |
| 813 |
|
| else { |
| 814 |
|
| return undef; |
| 815 |
|
| } |
| 816 |
|
| |
| 817 |
|
| } |
| 818 |
|
| |
| 819 |
|
| sub add_filename_extensions { |
| 820 |
|
| my $self = shift; |
| 821 |
|
| |
| 822 |
|
| my $filenamebase = shift; |
| 823 |
|
| |
| 824 |
|
| $filenamebase =~ /(.+)(\/|\/\/|\\|\\\\)(.+)\b/; |
| 825 |
|
| |
| 826 |
|
| my $directory = $1; |
| 827 |
|
| my $filename = $3; |
| 828 |
|
| my $filetype = ".dat"; |
| 829 |
|
| if ( $filename =~ /(.+)(\..+)\b/ ) { |
| 830 |
|
| $filename = $1; |
| 831 |
|
| $filetype = $2; |
| 832 |
|
| } |
| 833 |
|
| |
| 834 |
|
| my $extension_length = @{ $self->{filename_extensions} }; |
| 835 |
|
| |
| 836 |
|
| if ( $self->{config}->{separate_files} == 0 ) { |
| 837 |
|
| |
| 838 |
|
| for ( my $i = 0; $i < $extension_length - 2; $i++ ) { |
| 839 |
|
| $directory .= "/" . @{ $self->{filename_extensions} }[$i]; |
| 840 |
|
| } |
| 841 |
|
| |
| 842 |
|
| for ( my $i = 0; $i < $extension_length - 1; $i++ ) { |
| 843 |
|
| $filename .= "_" . @{ $self->{filename_extensions} }[$i]; |
| 844 |
|
| } |
| 845 |
|
| } |
| 846 |
|
| elsif ( $self->{config}->{separate_files} == 1 ) { |
| 847 |
|
| |
| 848 |
|
| for ( my $i = 0; $i < $extension_length - 1; $i++ ) { |
| 849 |
|
| $directory .= "/" . @{ $self->{filename_extensions} }[$i]; |
| 850 |
|
| } |
| 851 |
|
| for ( my $i = 0; $i < $extension_length; $i++ ) { |
| 852 |
|
| $filename .= "_" . @{ $self->{filename_extensions} }[$i]; |
| 853 |
|
| } |
| 854 |
|
| } |
| 855 |
|
| |
| 856 |
|
| if ( $self->{config}->{folders} == 0 ) { |
| 857 |
|
| $directory = $1; #do not create folder |
| 858 |
|
| } |
| 859 |
|
| |
| 860 |
|
| return $directory . "/" . $filename . $filetype; |
| 861 |
|
| } |
| 862 |
|
| |
| 863 |
|
| sub get_value { |
| 864 |
|
| my $self = shift; |
| 865 |
|
| return @{ $self->{config}->{points} }[ $self->{iterator} ]; |
| 866 |
|
| } |
| 867 |
|
| |
| 868 |
|
| sub enable_pause { |
| 869 |
|
| print "Sweep will be paused after finishing this sweep. \n"; |
| 870 |
|
| $PAUSE = 1; |
| 871 |
|
| } |
| 872 |
|
| |
| 873 |
|
| sub pause { |
| 874 |
|
| my $self = shift; |
| 875 |
|
| print "\n\nPAUSE: continue with <ENTER>\n"; |
| 876 |
|
| ReadMode('normal'); |
| 877 |
|
| <>; |
| 878 |
|
| ReadMode('cbreak'); |
| 879 |
|
| $PAUSE = 0; |
| 880 |
|
| } |
| 881 |
|
| |
| 882 |
|
| sub finish { |
| 883 |
|
| my $self = shift; |
| 884 |
|
| |
| 885 |
|
| # delete entry in ACTIVE_SWEEPS: |
| 886 |
|
| foreach my $i ( 0 .. ( my $length = @{$ACTIVE_SWEEPS} ) - 1 ) { |
| 887 |
|
| |
| 888 |
|
| #print "$i FINISH: ".$self."\t".@{$ACTIVE_SWEEPS}[$i]."\n"; |
| 889 |
|
| #print "active array before: {@{$ACTIVE_SWEEPS}}\n"; |
| 890 |
|
| if ( $self eq @{$ACTIVE_SWEEPS}[$i] ) { |
| 891 |
|
| |
| 892 |
|
| #@LIST = splice(@ARRAY, OFFSET, LENGTH, @REPLACE_WITH); |
| 893 |
|
| @{$ACTIVE_SWEEPS} = splice( @{$ACTIVE_SWEEPS}, $i + 1, 1 ); |
| 894 |
|
| |
| 895 |
|
| #print "active array after: {@{$ACTIVE_SWEEPS}}\n"; |
| 896 |
|
| } |
| 897 |
|
| } |
| 898 |
|
| |
| 899 |
|
| # save plot image for all defined measurements: |
| 900 |
|
| foreach my $file ( @{ $self->{DataFiles} } ) { |
| 901 |
|
| foreach ( 0 .. $file->{plot_count} - 1 ) { |
| 902 |
|
| if ( $file->{logger}->{plots}->[$_]->{autosave} eq 'always' ) { |
| 903 |
|
| $file->save_plot($_); |
| 904 |
|
| } |
| 905 |
|
| } |
| 906 |
|
| } |
| 907 |
|
| |
| 908 |
|
| # close DataFiles for all defined slaves: |
| 909 |
|
| foreach my $slave ( @{ $self->{slaves} } ) { |
| 910 |
|
| foreach my $file ( @{ $slave->{DataFiles} } ) { |
| 911 |
|
| foreach ( 0 .. $file->{plot_count} - 1 ) { |
| 912 |
|
| |
| 913 |
|
| if ( $file->{logger}->{plots}->[$_]->{autosave} eq 'last' ) { |
| 914 |
|
| $file->save_plot($_); |
| 915 |
|
| } |
| 916 |
|
| } |
| 917 |
|
| } |
| 918 |
|
| } |
| 919 |
|
| |
| 920 |
|
| # close DataFiles of Master: |
| 921 |
|
| if ( not defined $self->{master} ) { |
| 922 |
|
| foreach my $file ( @{ $self->{DataFiles} } ) { |
| 923 |
|
| foreach ( 0 .. $file->{plot_count} - 1 ) { |
| 924 |
|
| if ( $file->{logger}->{plots}->[$_]->{autosave} eq 'last' ) { |
| 925 |
|
| $file->save_plot($_); |
| 926 |
|
| } |
| 927 |
|
| } |
| 928 |
|
| } |
| 929 |
|
| } |
| 930 |
|
| |
| 931 |
|
| ReadMode('normal'); |
| 932 |
|
| } |
| 933 |
|
| |
| 934 |
|
| sub active { |
| 935 |
|
| my $self = shift; |
| 936 |
|
| return $self->{active}; |
| 937 |
|
| } |
| 938 |
|
| |
| 939 |
|
| sub abort { |
| 940 |
|
| |
| 941 |
|
| foreach my $sweep ( @{$ACTIVE_SWEEPS} ) { |
| 942 |
|
| $sweep->exit(); |
| 943 |
|
| } |
| 944 |
|
| |
| 945 |
|
| while ( @{$ACTIVE_SWEEPS}[0] ) { |
| 946 |
|
| my $sweep = @{$ACTIVE_SWEEPS}[0]; |
| 947 |
|
| $sweep->finish(); |
| 948 |
|
| } |
| 949 |
|
| |
| 950 |
|
| exit; |
| 951 |
|
| } |
| 952 |
|
| |
| 953 |
|
| sub stop { |
| 954 |
|
| |
| 955 |
|
| print "Sweep stopped by User!\n"; |
| 956 |
|
| foreach my $sweep ( @{$ACTIVE_SWEEPS} ) { |
| 957 |
|
| $sweep->exit(); |
| 958 |
|
| } |
| 959 |
|
| |
| 960 |
|
| } |
| 961 |
|
| |
| 962 |
|
| sub exit { |
| 963 |
|
| return shift; |
| 964 |
|
| } |
| 965 |
|
| |
| 966 |
|
| sub last { |
| 967 |
|
| my $self = shift; |
| 968 |
|
| $self->{last} = 1; |
| 969 |
|
| return; |
| 970 |
|
| } |
| 971 |
|
| |
| 972 |
|
| sub before_loop { |
| 973 |
|
| return shift; |
| 974 |
|
| } |
| 975 |
|
| |
| 976 |
|
| sub go_to_sweep_start { |
| 977 |
|
| return shift; |
| 978 |
|
| } |
| 979 |
|
| |
| 980 |
|
| sub start_continuous_sweep { |
| 981 |
|
| return shift; |
| 982 |
|
| } |
| 983 |
|
| |
| 984 |
|
| sub in_loop { |
| 985 |
|
| return shift; |
| 986 |
|
| } |
| 987 |
|
| |
| 988 |
|
| sub go_to_next_step { |
| 989 |
|
| return shift; |
| 990 |
|
| } |
| 991 |
|
| |
| 992 |
|
| sub after_loop { |
| 993 |
|
| return shift; |
| 994 |
|
| } |
| 995 |
|
| |
| 996 |
|
| sub exit_loop { |
| 997 |
|
| return shift; |
| 998 |
|
| } |
| 999 |
|
| |
| 1000 |
|
| sub check_loop_duration { |
| 1001 |
|
| |
| 1002 |
|
| my $self = shift; |
| 1003 |
|
| |
| 1004 |
|
| my $char = ReadKey(1e-5); |
| 1005 |
|
| if ( defined $char ) { |
| 1006 |
|
| $self->user_command($char); |
| 1007 |
|
| } |
| 1008 |
|
| |
| 1009 |
|
| if ( @{ $self->{config}->{interval} }[ $self->{sequence} ] == 0 ) { |
| 1010 |
|
| return 0; |
| 1011 |
|
| } |
| 1012 |
|
| |
| 1013 |
|
| if ( $self->{config}->{mode} =~ /step|list/ ) { |
| 1014 |
|
| return 0; |
| 1015 |
|
| } |
| 1016 |
|
| |
| 1017 |
|
| $self->{loop}->{t1} = time(); |
| 1018 |
|
| |
| 1019 |
|
| if ( not defined $self->{loop}->{t0} ) { |
| 1020 |
|
| $self->{loop}->{t0} = time(); |
| 1021 |
|
| return 0; |
| 1022 |
|
| } |
| 1023 |
|
| |
| 1024 |
|
| if ( ( $self->{loop}->{t1} - $self->{loop}->{t0} ) |
| 1025 |
|
| > @{ $self->{config}->{interval} }[ $self->{sequence} ] ) { |
| 1026 |
|
| carp( "WARNING: Measurement Loop takes more time (" |
| 1027 |
|
| . ( $self->{loop}->{t1} - $self->{loop}->{t0} ) |
| 1028 |
|
| . ") than specified by measurement intervall (@{$self->{config}->{sequence}}[$self->{iterator}]).\n" |
| 1029 |
|
| ); |
| 1030 |
|
| } |
| 1031 |
|
| my $delta_time = ( $self->{loop}->{t1} - $self->{loop}->{t0} ) |
| 1032 |
|
| + $self->{loop}->{overtime}; |
| 1033 |
|
| |
| 1034 |
|
| if ( defined $self->{config}->{instrument} |
| 1035 |
|
| and $self->{config}->{instrument}->can("active") ) { |
| 1036 |
|
| while ( |
| 1037 |
|
| ( |
| 1038 |
|
| @{ $self->{config}->{interval} }[ $self->{sequence} ] |
| 1039 |
|
| - $delta_time |
| 1040 |
|
| ) > 0.2 |
| 1041 |
|
| ) { |
| 1042 |
|
| my $time0 = time(); |
| 1043 |
|
| $self->{config}->{instrument}->active(); |
| 1044 |
|
| $delta_time = $delta_time + ( ( time() - $time0 ) ); |
| 1045 |
|
| } |
| 1046 |
|
| } |
| 1047 |
|
| |
| 1048 |
|
| if ( $delta_time > @{ $self->{config}->{interval} }[ $self->{sequence} ] ) |
| 1049 |
|
| { |
| 1050 |
|
| $self->{loop}->{overtime} = $delta_time |
| 1051 |
|
| - @{ $self->{config}->{interval} }[ $self->{sequence} ]; |
| 1052 |
|
| $delta_time = @{ $self->{config}->{interval} }[ $self->{sequence} ]; |
| 1053 |
|
| |
| 1054 |
|
| #warn "WARNING: Measurement Loop takes more time ($self->{loop}->{overtime}) than specified by measurement intervall (@{$self->{config}->{sequence}}[$self->{iterator}]).\n"; |
| 1055 |
|
| } |
| 1056 |
|
| else { |
| 1057 |
|
| $self->{loop}->{overtime} = 0; |
| 1058 |
|
| } |
| 1059 |
|
| |
| 1060 |
|
| usleep( |
| 1061 |
|
| ( |
| 1062 |
|
| @{ $self->{config}->{interval} }[ $self->{sequence} ] |
| 1063 |
|
| - $delta_time |
| 1064 |
|
| ) * 1e6 |
| 1065 |
|
| ); |
| 1066 |
|
| |
| 1067 |
|
| $self->{loop}->{t0} = time(); |
| 1068 |
|
| return $delta_time; |
| 1069 |
|
| |
| 1070 |
|
| } |
| 1071 |
|
| |
| 1072 |
|
| sub user_command { |
| 1073 |
|
| my $self = shift; |
| 1074 |
|
| my $cmd = shift; |
| 1075 |
|
| |
| 1076 |
|
| print "user_command = " . $cmd . "\n"; |
| 1077 |
|
| |
| 1078 |
|
| if ( $cmd eq "g" ) { |
| 1079 |
|
| foreach my $datafile ( @{ $self->{DataFiles} } ) { |
| 1080 |
|
| $datafile->gnuplot_restart(); |
| 1081 |
|
| } |
| 1082 |
|
| } |
| 1083 |
|
| elsif ( $cmd eq "p" ) { |
| 1084 |
|
| |
| 1085 |
|
| #foreach my $datafile (@{$self->{DataFiles}}) |
| 1086 |
|
| # { |
| 1087 |
|
| @{ $self->{DataFiles} }[0]->gnuplot_pause(); |
| 1088 |
|
| |
| 1089 |
|
| # } |
| 1090 |
|
| } |
| 1091 |
|
| |
| 1092 |
|
| return 1; |
| 1093 |
|
| |
| 1094 |
|
| } |
| 1095 |
|
| |
| 1096 |
|
| sub LOG { |
| 1097 |
|
| |
| 1098 |
|
| my $self = shift; |
| 1099 |
|
| my @args = @_; |
| 1100 |
|
| |
| 1101 |
|
| if ( ref( $args[0] ) eq "HASH" ) { |
| 1102 |
|
| my $file = ( defined $args[1] ) ? $args[1] : 0; |
| 1103 |
|
| if ( not defined @{ $self->{DataFiles} }[ $args[1] - 1 ] ) { |
| 1104 |
|
| Lab::Exception::Warning->throw( |
| 1105 |
|
| "DataFile $file is not defined! \n"); |
| 1106 |
|
| } |
| 1107 |
|
| while ( my ( $key, $value ) = each %{ $args[0] } ) { |
| 1108 |
|
| @{ $self->{LOG} }[$file]->{$key} = $value; |
| 1109 |
|
| } |
| 1110 |
|
| } |
| 1111 |
|
| else { |
| 1112 |
|
| # for old style: LOG("column_name", "value", "File") |
| 1113 |
|
| my $file = ( defined $args[2] ) ? $args[2] : 0; |
| 1114 |
|
| if ( not defined @{ $self->{DataFiles} }[ $args[2] - 1 ] ) { |
| 1115 |
|
| Lab::Exception::Warning->throw( |
| 1116 |
|
| "DataFile $file is not defined! \n"); |
| 1117 |
|
| } |
| 1118 |
|
| @{ $self->{LOG} }[$file]->{ $args[0] } = $args[1]; |
| 1119 |
|
| } |
| 1120 |
|
| } |
| 1121 |
|
| |
| 1122 |
|
| sub set_autolog { |
| 1123 |
|
| my $self = shift; |
| 1124 |
|
| my $value = shift; |
| 1125 |
|
| my $file = shift; |
| 1126 |
|
| |
| 1127 |
|
| if ( not defined $file or $file == 0 ) { |
| 1128 |
|
| foreach my $DataFile ( @{ $self->{DataFiles} } ) { |
| 1129 |
|
| $DataFile->set_autolog($value); |
| 1130 |
|
| } |
| 1131 |
|
| } |
| 1132 |
|
| elsif ( defined @{ $self->{DataFiles} }[ $file - 1 ] ) { |
| 1133 |
|
| @{ $self->{DataFiles} }[ $file - 1 ]->set_autolog($value); |
| 1134 |
|
| } |
| 1135 |
|
| else { |
| 1136 |
|
| print new Lab::Exception::Warning( |
| 1137 |
|
| "DataFile $file is not defined! \n"); |
| 1138 |
|
| } |
| 1139 |
|
| |
| 1140 |
|
| return $self; |
| 1141 |
|
| } |
| 1142 |
|
| |
| 1143 |
|
| sub skip_LOG { |
| 1144 |
|
| my $self = shift; |
| 1145 |
|
| my $file = shift; |
| 1146 |
|
| |
| 1147 |
|
| if ( not defined $file or $file == 0 ) { |
| 1148 |
|
| foreach my $DataFile ( @{ $self->{DataFiles} } ) { |
| 1149 |
|
| $DataFile->skiplog(); |
| 1150 |
|
| } |
| 1151 |
|
| } |
| 1152 |
|
| elsif ( defined @{ $self->{DataFiles} }[ $file - 1 ] ) { |
| 1153 |
|
| @{ $self->{DataFiles} }[ $file - 1 ]->skiplog(); |
| 1154 |
|
| } |
| 1155 |
|
| else { |
| 1156 |
|
| print new Lab::Exception::Warning( |
| 1157 |
|
| "DataFile $file is not defined! \n"); |
| 1158 |
|
| } |
| 1159 |
|
| |
| 1160 |
|
| return $self; |
| 1161 |
|
| } |
| 1162 |
|
| |
| 1163 |
|
| sub write_LOG { |
| 1164 |
|
| my $self = shift; |
| 1165 |
|
| my $file = shift; |
| 1166 |
|
| |
| 1167 |
|
| if ( not defined $file or $file == 0 ) { |
| 1168 |
|
| my $i = 1; |
| 1169 |
|
| foreach my $DataFile ( @{ $self->{DataFiles} } ) { |
| 1170 |
|
| $DataFile->LOG( $self->create_LOG_HASH($i) ); |
| 1171 |
|
| $i++; |
| 1172 |
|
| } |
| 1173 |
|
| } |
| 1174 |
|
| elsif ( defined @{ $self->{DataFiles} }[ $file - 1 ] ) { |
| 1175 |
|
| @{ $self->{DataFiles} }[ $file - 1 ] |
| 1176 |
|
| ->LOG( $self->create_LOG_HASH($file) ); |
| 1177 |
|
| } |
| 1178 |
|
| else { |
| 1179 |
|
| print new Lab::Exception::Warning( |
| 1180 |
|
| "DataFile $file is not defined! \n"); |
| 1181 |
|
| } |
| 1182 |
|
| |
| 1183 |
|
| return $self; |
| 1184 |
|
| |
| 1185 |
|
| } |
| 1186 |
|
| |
| 1187 |
|
| sub create_LOG_HASH { |
| 1188 |
|
| my $self = shift; |
| 1189 |
|
| my $file = shift; |
| 1190 |
|
| |
| 1191 |
|
| my $LOG_HASH = {}; |
| 1192 |
|
| |
| 1193 |
|
| foreach |
| 1194 |
|
| my $column ( @{ @{ $self->{DataFiles} }[ $file - 1 ]->{COLUMNS} } ) { |
| 1195 |
|
| if ( defined @{ $self->{LOG} }[$file]->{$column} ) { |
| 1196 |
|
| $LOG_HASH->{$column} = @{ $self->{LOG} }[$file]->{$column}; |
| 1197 |
|
| } |
| 1198 |
|
| elsif ( defined @{ $self->{LOG} }[0]->{$column} ) { |
| 1199 |
|
| $LOG_HASH->{$column} = @{ $self->{LOG} }[0]->{$column}; |
| 1200 |
|
| } |
| 1201 |
|
| else { |
| 1202 |
|
| if ( exists @{ $self->{LOG} }[$file]->{$column} |
| 1203 |
|
| or exists @{ $self->{LOG} }[0]->{$column} ) { |
| 1204 |
|
| print new Lab::Exception::Warning( |
| 1205 |
|
| "Value for Paramter $column undefined\n"); |
| 1206 |
|
| } |
| 1207 |
|
| else { |
| 1208 |
|
| print new Lab::Exception::Warning( |
| 1209 |
|
| "Paramter $column not found. Maybe a typing error??\n"); |
| 1210 |
|
| } |
| 1211 |
|
| $LOG_HASH->{$column} = '?'; |
| 1212 |
|
| } |
| 1213 |
|
| } |
| 1214 |
|
| |
| 1215 |
|
| return $LOG_HASH; |
| 1216 |
|
| |
| 1217 |
|
| } |
| 1218 |
|
| |
| 1219 |
|
| sub add_slave { |
| 1220 |
|
| my $self = shift; |
| 1221 |
|
| my $slave = shift; |
| 1222 |
|
| |
| 1223 |
|
| if ( not $self->{config}->{mode} =~ /step|list/ ) { |
| 1224 |
|
| Lab::Exception::Warning->throw( error => |
| 1225 |
|
| "Can't add slave to master-sweep which is not in mode list or step." |
| 1226 |
|
| ); |
| 1227 |
|
| } |
| 1228 |
|
| |
| 1229 |
|
| my $type = ref($slave); |
| 1230 |
|
| if ( $type =~ /^Lab::XPRESS::Sweep::Frame/ ) { |
| 1231 |
|
| if ( not defined $slave->{master} ) { |
| 1232 |
|
| Lab::Exception::Warning->throw( |
| 1233 |
|
| error => 'No master defined in Frame.' ); |
| 1234 |
|
| } |
| 1235 |
|
| elsif ( not defined @{ $slave->{master}->{slaves} }[0] ) { |
| 1236 |
|
| Lab::Exception::Warning->throw( |
| 1237 |
|
| error => 'No slave(s) defined in Frame.' ); |
| 1238 |
|
| } |
| 1239 |
|
| |
| 1240 |
|
| push( @{ $self->{slaves} }, $slave->{master} ); |
| 1241 |
|
| $slave = $slave->{master}; |
| 1242 |
|
| |
| 1243 |
|
| $self->{slave_counter}++; |
| 1244 |
|
| |
| 1245 |
|
| } |
| 1246 |
|
| elsif ( $type =~ /^Lab::XPRESS::Sweep/ ) { |
| 1247 |
|
| if ( defined $slave->{master} ) { |
| 1248 |
|
| Lab::Exception::Warning->throw( error => |
| 1249 |
|
| "Cannot add slave sweep with an already defined master sweep ." |
| 1250 |
|
| ); |
| 1251 |
|
| } |
| 1252 |
|
| |
| 1253 |
|
| if ( $slave->{DataFile_counter} <= 0 |
| 1254 |
|
| and not defined @{ $slave->{slaves} }[-1] ) { |
| 1255 |
|
| while (1) { |
| 1256 |
|
| print |
| 1257 |
|
| "\n XPRESS::FRAME: -- Added slave sweep has no DataFile! Continue anyway (y/n) ?\n"; |
| 1258 |
|
| my $answer = <>; |
| 1259 |
|
| if ( $answer =~ /y|Y/ ) { |
| 1260 |
|
| last; |
| 1261 |
|
| } |
| 1262 |
|
| elsif ( $answer =~ /n|N/ ) { |
| 1263 |
|
| exit; |
| 1264 |
|
| } |
| 1265 |
|
| } |
| 1266 |
|
| } |
| 1267 |
|
| |
| 1268 |
|
| push( @{ $self->{slaves} }, $slave ); |
| 1269 |
|
| $self->{slave_counter}++; |
| 1270 |
|
| } |
| 1271 |
|
| elsif ( $type eq 'CODE' ) { |
| 1272 |
|
| $slave = new Lab::XPRESS::Sweep::Dummy($slave); |
| 1273 |
|
| push( @{ $self->{slaves} }, $slave ); |
| 1274 |
|
| $self->{slave_counter}++; |
| 1275 |
|
| } |
| 1276 |
|
| else { |
| 1277 |
|
| Lab::Exception::Warning->throw( |
| 1278 |
|
| error => "slave object is of type $type. Cannot add slave." ); |
| 1279 |
|
| } |
| 1280 |
|
| |
| 1281 |
|
| $slave->{master} = $self; |
| 1282 |
|
| $self->{DataFile_counter} = 0; |
| 1283 |
|
| $self->{DataFiles} = (); |
| 1284 |
|
| |
| 1285 |
|
| return $self; |
| 1286 |
|
| } |
| 1287 |
|
| |
| 1288 |
|
| sub get_filename_extension { |
| 1289 |
|
| my $self = shift; |
| 1290 |
|
| return $self->{config}->{filename_extension} . $self->get_value(); |
| 1291 |
|
| } |
| 1292 |
|
| |
| 1293 |
|
| sub deep_copy { |
| 1294 |
|
| |
| 1295 |
|
| # if not defined then return it |
| 1296 |
|
| return undef if $#_ < 0 || !defined( $_[0] ); |
| 1297 |
|
| |
| 1298 |
|
| # if not a reference then return the parameter |
| 1299 |
|
| return $_[0] if !ref( $_[0] ); |
| 1300 |
|
| my $obj = shift; |
| 1301 |
|
| if ( UNIVERSAL::isa( $obj, 'SCALAR' ) ) { |
| 1302 |
|
| my $temp = deepcopy($$obj); |
| 1303 |
|
| return \$temp; |
| 1304 |
|
| } |
| 1305 |
|
| elsif ( UNIVERSAL::isa( $obj, 'HASH' ) ) { |
| 1306 |
|
| my $temp_hash = {}; |
| 1307 |
|
| foreach my $key ( keys %$obj ) { |
| 1308 |
|
| if ( !defined( $obj->{$key} ) || !ref( $obj->{$key} ) ) { |
| 1309 |
|
| $temp_hash->{$key} = $obj->{$key}; |
| 1310 |
|
| } |
| 1311 |
|
| else { |
| 1312 |
|
| $temp_hash->{$key} = deep_copy( $obj->{$key} ); |
| 1313 |
|
| } |
| 1314 |
|
| } |
| 1315 |
|
| return $temp_hash; |
| 1316 |
|
| } |
| 1317 |
|
| elsif ( UNIVERSAL::isa( $obj, 'ARRAY' ) ) { |
| 1318 |
|
| my $temp_array = []; |
| 1319 |
|
| foreach my $array_val (@$obj) { |
| 1320 |
|
| if ( !defined($array_val) || !ref($array_val) ) { |
| 1321 |
|
| push( @$temp_array, $array_val ); |
| 1322 |
|
| } |
| 1323 |
|
| else { |
| 1324 |
|
| push( @$temp_array, deep_copy($array_val) ); |
| 1325 |
|
| } |
| 1326 |
|
| } |
| 1327 |
|
| return $temp_array; |
| 1328 |
|
| } |
| 1329 |
|
| |
| 1330 |
|
| # ?? I am uncertain about this one |
| 1331 |
|
| elsif ( UNIVERSAL::isa( $obj, 'REF' ) ) { |
| 1332 |
|
| my $temp = deepcopy($$obj); |
| 1333 |
|
| return \$temp; |
| 1334 |
|
| } |
| 1335 |
|
| |
| 1336 |
|
| # I guess that it is either CODE, GLOB or LVALUE |
| 1337 |
|
| else { |
| 1338 |
|
| return $obj; |
| 1339 |
|
| } |
| 1340 |
|
| } |
| 1341 |
|
| |
| 1342 |
|
| # Need to provide this or AUTOLOAD cannot find it and will die on object destruction. |
| 1343 |
|
| sub DESTROY { |
| 1344 |
|
| |
| 1345 |
|
| # do nothing |
| 1346 |
|
| } |
| 1347 |
|
| |
| 1348 |
|
| sub AUTOLOAD { |
| 1349 |
|
| |
| 1350 |
|
| my $self = shift; |
| 1351 |
|
| my $type = ref($self) or croak "\$self is not an object"; |
| 1352 |
|
| my $value = undef; |
| 1353 |
|
| |
| 1354 |
|
| my $name = $AUTOLOAD; |
| 1355 |
|
| $name =~ s/.*://; # strip fully qualified portion |
| 1356 |
|
| |
| 1357 |
|
| if ( exists $self->{_permitted}->{$name} ) { |
| 1358 |
|
| if (@_) { |
| 1359 |
|
| return $self->{$name} = shift; |
| 1360 |
|
| } |
| 1361 |
|
| else { |
| 1362 |
|
| return $self->{$name}; |
| 1363 |
|
| } |
| 1364 |
|
| } |
| 1365 |
|
| elsif ( $name =~ qr/^(set_)(.*)$/ ) { |
| 1366 |
|
| |
| 1367 |
|
| # There is a problem with deep copying of the instrument hash. |
| 1368 |
|
| # The elements of the hash could not be accessed correctly. |
| 1369 |
|
| # The workaround is to tempsave the hashref and put it back in |
| 1370 |
|
| # place. This should be only temporary though. |
| 1371 |
|
| |
| 1372 |
|
| # NOTE: changed the creation of config_original (in prepare_config function), so it is a copy |
| 1373 |
|
| # of {config} unsing dclone instead of deep_copy. I think this adresses the issue above. |
| 1374 |
|
| |
| 1375 |
|
| my $instrument = $self->{config}->{instrument}; |
| 1376 |
|
| |
| 1377 |
|
| if ( exists $self->{config_original}->{$2} ) { |
| 1378 |
|
| if ( $self->active() ) { |
| 1379 |
|
| print Lab::Exception::Warning->new( error => |
| 1380 |
|
| "WARNING: Cannot set parameter while sweep is active \n" |
| 1381 |
|
| ); |
| 1382 |
|
| return; |
| 1383 |
|
| } |
| 1384 |
|
| if ( @_ == 1 ) { |
| 1385 |
|
| $self->{config_original}->{$2} = @_[0]; |
| 1386 |
|
| } |
| 1387 |
|
| else { |
| 1388 |
|
| $self->{config_original}->{$2} = deep_copy( \@_ ); |
| 1389 |
|
| } |
| 1390 |
|
| |
| 1391 |
|
| $self->{config} = deep_copy( $self->{config_original} ); |
| 1392 |
|
| |
| 1393 |
|
| #use Data::Dumper; |
| 1394 |
|
| |
| 1395 |
|
| #print Dumper $self->{config}; |
| 1396 |
|
| |
| 1397 |
|
| $self->{config}->{instrument} = $instrument; |
| 1398 |
|
| $self->prepaire_config(); |
| 1399 |
|
| } |
| 1400 |
|
| else { |
| 1401 |
|
| print Lab::Exception::Warning->new( |
| 1402 |
|
| error => "WARNING: Parameter $2 does not exist \n" ); |
| 1403 |
|
| } |
| 1404 |
|
| } |
| 1405 |
|
| |
| 1406 |
|
| else { |
| 1407 |
|
| Lab::Exception::Warning->throw( error => "AUTOLOAD in " |
| 1408 |
|
| . __PACKAGE__ |
| 1409 |
|
| . " couldn't access field '${name}'.\n" ); |
| 1410 |
|
| } |
| 1411 |
|
| } |
| 1412 |
|
| |
| 1413 |
|
| with 'Lab::XPRESS::Sweep::LogBlock'; |
| 1414 |
|
| |
| 1415 |
|
| # sub timestamp { |
| 1416 |
|
| |
| 1417 |
|
| # my $self = shift; |
| 1418 |
|
| # my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, |
| 1419 |
|
| # $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time); |
| 1420 |
|
| |
| 1421 |
|
| # $Monat+=1; |
| 1422 |
|
| # $Jahrestag+=1; |
| 1423 |
|
| # $Monat = $Monat < 10 ? $Monat = "0".$Monat : $Monat; |
| 1424 |
|
| # $Monatstag = $Monatstag < 10 ? $Monatstag = "0".$Monatstag : $Monatstag; |
| 1425 |
|
| # $Stunden = $Stunden < 10 ? $Stunden = "0".$Stunden : $Stunden; |
| 1426 |
|
| # $Minuten = $Minuten < 10 ? $Minuten = "0".$Minuten : $Minuten; |
| 1427 |
|
| # $Sekunden = $Sekunden < 10 ? $Sekunden = "0".$Sekunden : $Sekunden; |
| 1428 |
|
| # $Jahr+=1900; |
| 1429 |
|
| |
| 1430 |
|
| # return "$Monatstag.$Monat.$Jahr", "$Stunden:$Minuten:$Sekunden"; |
| 1431 |
|
| |
| 1432 |
|
| # } |
| 1433 |
|
| |
| 1434 |
|
| 1; |
| 1435 |
|
| |
| 1436 |
|
| __END__ |