XPRESS/Sweep/LogBlock.pm

filter: Statementstmt 90.9% 40 / 44 Branchbran 68.7% 11 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 84.8% 56 / 66 SCAR 22.3
CC
9
Cov
85%
LogBlock
9.6
BEGIN
1.0
BEGIN
1.0
CRAP 9.3
« XPRESS/Sweep/SignalRecoveryPhase.pm ↑ Summary Moose/Instrument/SCPIBlock.pm »
1 package Lab::XPRESS::Sweep::LogBlock;
2 #ABSTRACT: Sweep add-on for matrix logging
3 8 $Lab::XPRESS::Sweep::LogBlock::VERSION = '3.881';
4 8 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 requires qw/LOG write_LOG/;
8  
9  
10 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 8 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16 sub LogBlock {
17 11 ▶ my $sweep = shift;
Subroutine LogBlock: called CC=9 SCAR=22.6
Pod undocumented
18  
19 11 ▶ if ( @_ % 2 != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 != 0) 0 11 11
20 0 croak "expected hash";
21 }
22  
23 11 my %args = @_;
24  
25 11 my $block = $args{block};
26 11 ▶ if ( not defined $block ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $block) 0 11 11
27 0 croak "missing mandatory parameter 'block'";
28 }
29  
30 11 my $prefix = $args{prefix};
31 11 ▶ if ( not defined $prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prefix) 0 11 11
32 0 $prefix = [];
33 }
34  
35 11 my $prefix_len = @$prefix;
36  
37 11 my $file = $args{datafile};
38 11 ▶ if ( not defined $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 11 0 11
39 11 $file = 0;
40 }
41  
42 11 my $num_rows = @$block;
43 11 my $row_len = @{ $block->[0] };
44  
45 # Extract column header from the DataFile
46 11 my $datafile = $sweep->{DataFiles}[$file];
47 11 my $columns = $datafile->add_column();
48 11 my $columns_len = @$columns;
49  
50 11 ▶ if ( $row_len + $prefix_len != $columns_len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row_len + $prefix_len != $columns_len) 0 11 11
51 0 croak "The datafile expects $columns_len columns.\n"
52 . "You only supplied $prefix_len + $row_len columns.";
53 }
54  
55 # Write external parameters and block to datafile
56  
57 11 ▶ while ( my ( $i, $row ) = each(@$block) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$block) 33 11 44
58 33 my %log;
59 33 unshift @$row, @$prefix;
60  
61 33 ▶ while ( my ( $j, $key ) = each(@$columns) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each @$columns) 99 33 132
62 99 $log{$key} = $row->[$j];
63 }
64  
65 33 $sweep->LOG( {%log}, $file );
66  
67 33 ▶ if ( $i != $num_rows - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i != $num_rows - 1) 22 11 33
68  
69 # the last writeLOG is called in Sweep.pm
70 22 $sweep->write_LOG();
71 }
72  
73 }
74  
75 }
76  
77 8 1;
78  
79 __END__
80  
81 =pod
82  
83 =encoding UTF-8
84  
85 =head1 NAME
86  
87 Lab::XPRESS::Sweep::LogBlock - Sweep add-on for matrix logging
88  
89 =head1 VERSION
90  
91 version 3.881
92  
93 =head1 SYNOPSIS
94  
95 # define your columns
96  
97 # parameters controlled by the XPRESS sweeps
98 $DataFile->add_column('gate');
99 $DataFile->add_column('bias');
100  
101 # parameters in the block, here we have a block with 2 columns.
102 $DataFile->add_column('frequency');
103 $DataFile->add_column('transmission');
104  
105 # Define your sweeps ...
106  
107 # In your measurement subroutine: Get block and log
108 $matrix = $instrument->get_block(...)
109 $sweep->LogBlock(
110 prefix => [$gate, $bias],
111 block => $matrix);
112  
113 =head1 DESCRIPTION
114  
115 This role exports the single method C<LogBlock>. The valid parameters are:
116  
117 =over
118  
119 =item block (mandatory)
120  
121 List of rows (e.g. C<[[1, 2, 3], [2, 3, 4]]>), which shell be written
122 to the data file.
123  
124 =item prefix
125  
126 List of parameters which shell be prefixed to each row of the block.
127  
128 =item file
129  
130 Index of the target data file (default: 0).
131  
132 =back
133  
134 =head1 COPYRIGHT AND LICENSE
135  
136 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
137  
138 Copyright 2016 Simon Reinhardt
139 2017 Andreas K. Huettel
140 2020 Andreas K. Huettel
141  
142  
143 This is free software; you can redistribute it and/or modify it under
144 the same terms as the Perl 5 programming language system itself.
145  
146 =cut
« XPRESS/Sweep/SignalRecoveryPhase.pm ↑ Summary Moose/Instrument/SCPIBlock.pm »