Data/Analysis.pm

filter: Statementstmt 55.5% 350 / 630 Branchbran 38.9% 152 / 390 Conditioncond 25.2% 25 / 99 MC/DCmcdc 4.8% 3 / 62 Subroutinesub 83.3% 20 / 24 Podpod 100% 12 / 12 totaltotal 46.1% 562 / 1217 SCAR 91.4
CC
247
Cov
47%
FindEvent
918.9
ReadRunHeader
506.0
PrintIndex
420.0
CRAP 9280.8
« Instrument/WR640.pm ↑ Summary Bus/VICP.pm »
1 package Lab::Data::Analysis;
2 #ABSTRACT: Analyze data from 'Trace' files
3 2 $Lab::Data::Analysis::VERSION = '3.881';
4 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # default config values, copied to $self->{CONFIG} initially
13  
14 2 our $DEFAULT_CONFIG = {
15 use_ftell => 0, # use ftell/fsetpos for positioning
16 clone_headers => 1, # clone run/file headers into events
17 combined_gpib => 0, # also combine GPIB from all streams
18 };
19  
20 2 our $_DefaultAnalyzer = {
21 1 => { # order in which to check for match
22 MATCH =>
23 '(?i)^Lab::Instrument::(TDS|TPS|TBS)(1\d\d\d|2\d\d\d?)(B|C)?::',
24 TYPE => 'Lab::Data::Analysis::TekTDS',
25 COMMENT =>
26 'Tektronix TDS/TPS/TBS 1000 and 2000 series, TDS200 series, oscilloscopes'
27 },
28 2 => {
29 MATCH => '(?i)^Lab::Instrument::DPO4\d\d\d(A-C)?::',
30 TYPE => 'Lab::Data::Analysis::TekDPO',
31 COMMENT => 'Tektronix DPO4000 series oscilloscopes',
32 },
33  
34 3 => {
35 MATCH => '(?i)^Lab::Instrument::WR\d+::',
36 TYPE => 'Lab::Data::Analysis::WaveRunner',
37 COMMENT => 'LeCroy WaveRunner series oscilloscopes',
38 },
39 };
40  
41 2 our $_LOADED = {};
42  
43  
44 sub new {
45 1 ▶ my $proto = shift;
Subroutine new: called CC=6 SCAR=18.9
Pod documented
46 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
47 1 my $self = {};
48 1 bless $self, $class;
49  
50 1 my ( $file, $tail ) = $self->_check_args( \@_, qw(file) );
51 1 $self->{FILE} = undef;
52 1 $self->{FH} = undef;
53 1 $self->{INDEX} = undef;
54 1 $self->{CONFIG} = {};
55 1 $self->{FILEHEADER} = undef;
56 1 $self->{RUNHEADER} = undef;
57  
58 # set up the default config variables
59 1 foreach my $k ( keys( %{$DEFAULT_CONFIG} ) ) {
60 3 $self->{CONFIG}->{$k} = $DEFAULT_CONFIG->{$k};
61 }
62  
63 # override default config with user-provided parameters
64 1 foreach my $k ( keys( %{$tail} ) ) {
65 0 ▶ next unless exists $self->{CONFIG}->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"CONFIG"}{$k} 0 0 0
66 0 $self->{CONFIG}->{$k} = $tail->{$k};
67 }
68  
69 1 ▶ $self->open($file) if defined($file);
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 1 0 1
70  
71 1 return $self;
72 }
73  
74 ################ internal routines ########################
75  
76 # calling argument parsing; this is an extension of the
77 # _check_args and _check_args_strict routines in Instrument.pm,
78 # allowing more flexibility in how routines are called.
79 # In particular routine(a=>1,b=>2,..) and
80 # routine({a=>1,b=>2,..}) can both be used.
81  
82 # note: if this code does not properly recognize the syntax,
83 # then you have to use the {key=>value...} form.
84  
85 # calling:
86 # ($par1,$par2,$par3,$tail) = $self->_check_args(\@_,qw(par1 par2 par3));
87 # or, for compatibility:
88 # ($par1,$par2,$par3,$tail) = $self->_check_args(\@_,[qw(par1 par2 par3)]);
89  
90 # can also call without the $self-> pointer, since not used.
91  
92 sub _check_args {
93 10 ▶ my $self = shift;
Subroutine _check_args: called CC=17 SCAR=29.5
94 10 my $args;
95  
96 10 ▶ if ( ref($self) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq 'ARRAY') { } 9 1 10
97 9 $args = $self;
98 }
99 else {
100 1 $args = shift;
101 }
102 10 my $params = [@_];
103 10 ▶ $params = $params->[0] if ref( $params->[0] ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $params->[0] eq "ARRAY" 1 9 10
104 10 my $arguments = {};
105  
106 10 ▶ if ( $#{$args} == 0 && ref( $args->[0] ) eq 'HASH' ) { # case 3
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$args;} == 0 and ref $args->[0] eq 'HASH') { } 0 10 10
Condition66%2/3
$#{$args;} == 0 and ref $args->[0] eq "HASH"
!ll&&!rl&&r
820
MC/DC0%0/2
$#{$args;} == 0 and ref $args->[0] eq "HASH"
$#{$args;} == 0 ref $args->[0] eq "HASH"
Truth table66%2/3
A and B
A= $#{$args;} == 0B= ref $args->[0] eq "HASH"
ABresult
0X0
100
111
107 0 %{$arguments} = ( %{ $args->[0] } );
108 }
109 else {
110 10 my $simple = 1;
111 10 ▶ if ( $#{$args} & 1 == 1 ) { # must have even # arguments
Branch: 1 branch
BranchTrueFalseTotal
if () 8 2 10
112 8 my $found = {};
113 8 ▶ for ( my $j = 0; $j <= $#{$args}; $j += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $#{$args;}) 6 8 14
114 6 ▶ if ( ref( $args->[$j] ) ne '' ) { # a ref for a key? no
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args->[$j] ne "") 0 6 6
115 0 $simple = 1;
116 0 last;
117 }
118 6 foreach my $p ( @{$params} ) { # named param
119 14 ▶ $simple = 0 if $p eq $args->[$j];
Branch: 1 branch
BranchTrueFalseTotal
if $p eq $args->[$j] 6 8 14
120 }
121 6 ▶ if ( exists( $found->{ $args->[$j] } ) ) { # key used 2x? no
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$found{$args->[$j]}) 0 6 6
122 0 $simple = 1;
123 0 last;
124 }
125 6 $found->{ $args->[$j] } = 1;
126 }
127 }
128  
129 10 ▶ if ($simple) { # case 1
Branch: 1 branch
BranchTrueFalseTotal
if ($simple) { } 6 4 10
130 6 my $i = 0;
131 6 my $j = 0;
132 6 foreach my $arg ( @{$args} ) {
133 2 ▶ if ( defined @{$params}[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined @{$params;}[$i]) { } 2 0 2
134 2 $arguments->{ @{$params}[$i] } = $arg;
135 2 $i++;
136 }
137 else {
138 0 $arguments->{"_tail$j"} = $arg;
139 0 $j++;
140 }
141 }
142 }
143 else { # case 2
144 4 %{$arguments} = ( @{$args} );
145 }
146 }
147  
148 10 my @return_args = ();
149  
150 10 foreach my $param ( @{$params} ) {
151 17 ▶ if ( exists $arguments->{$param} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $arguments->{$param}) { } 8 9 17
152 8 push( @return_args, $arguments->{$param} );
153 8 delete $arguments->{$param};
154 }
155 else {
156 9 push( @return_args, undef );
157 }
158 }
159  
160 10 push( @return_args, $arguments );
161  
162 10 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 10 0 10
163 10 return @return_args;
164 }
165 else {
166 0 return $return_args[0];
167 }
168 }
169  
170 sub _check_args_strict {
171 1 ▶ my $self = shift;
Subroutine _check_args_strict: called CC=6 SCAR=19.2
172 1 my $args;
173  
174 1 ▶ if ( ref($self) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self eq 'ARRAY') { } 1 0 1
175 1 $args = $self;
176 }
177 else {
178 0 $args = shift;
179 }
180 1 my $params = [@_];
181 1 ▶ $params = $params->[0] if ref( $params->[0] ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $params->[0] eq "ARRAY" 0 1 1
182  
183 1 my @result = _check_args( $args, $params );
184  
185 1 my $num_params = @result - 1;
186  
187 1 ▶ for ( my $i = 0; $i < $num_params; ++$i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_params) 1 1 2
188 1 ▶ if ( not defined $result[$i] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result[$i]) 0 1 1
189 0 croak("missing mandatory argument '$params->[$i]'");
190 }
191 }
192  
193 1 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 0 1
194 1 return @result;
195 }
196 else {
197 0 return $result[0];
198 }
199 }
200  
201 # get file position, make use of CONFIG option
202  
203 sub _tell {
204 380 ▶ my $self = shift;
Subroutine _tell: called CC=3 SCAR=12.0
205 380 ▶ croak("no file open") unless defined $self->{FH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FH"} 0 380 380
206 380 ▶ if ( $self->{CONFIG}->{use_ftell} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'CONFIG'}{'use_ftell'}) { } 0 380 380
207 0 return $self->{FH}->getpos();
208 }
209 else {
210 380 return $self->{FH}->tell();
211 }
212 }
213  
214 # set file absolute position, making use of CONFIG option
215 # ignores any 'whence' parameter
216  
217 sub _seek {
218 9 ▶ my $self = shift;
Subroutine _seek: called CC=3 SCAR=11.8
219 9 my $p = shift;
220 9 ▶ croak("no file open") unless defined $self->{FH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FH"} 0 9 9
221 9 ▶ if ( $self->{CONFIG}->{use_ftell} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'CONFIG'}{'use_ftell'}) { } 0 9 9
222 0 return $self->{FH}->setpos($p);
223 }
224 else {
225 9 return $self->{FH}->seek( $p, 0 );
226 }
227 }
228  
229  
230 sub open {
231 1 ▶ my $self = shift;
Subroutine open: called CC=5 SCAR=16.6
Pod documented
232 1 my ( $file, $tail ) = _check_args_strict( \@_, 'file' );
233  
234 1 ▶ croak("input file '$file' does not exist") unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 1 1
235 1 ▶ croak("input file '$file' not readable") unless -r $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 1 1
236  
237 1 ▶ $self->{FH}->close() if defined $self->{FH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"FH"} 0 1 1
238  
239 1 $self->{FH} = IO::File->new( $file, "r" );
240 croak("unable to open file '$file' for reading")
241 1 ▶ unless defined $self->{FH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FH"} 0 1 1
242 1 $self->{FILE} = $file;
243 1 $self->{FILE_BEGIN} = $self->_tell(); # beginning position
244 1 $self->{INDEX} = undef;
245 1 $self->{FSTAT} = [ ( $self->{FH}->stat() ) ];
246  
247 }
248  
249  
250 sub rewind {
251 0 ▶ my $self = shift;
Subroutine rewind: not called CC=2 SCAR=17.9
Pod documented
252 0 my ($tail) = _check_args( \@_ );
253  
254 0 ▶ croak("tracefile not opened") unless defined $self->{FH};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FH"} 0 0 0
255  
256 0 $self->_seek( $self->{FILE_BEGIN} );
257 }
258  
259  
260 sub MakeIndex {
261 1 ▶ my $self = shift;
Subroutine MakeIndex: called CC=18 SCAR=29.5
Pod documented
262 1 my ($tail) = _check_args( \@_ );
263  
264 1 my $fh = $self->{FH};
265 1 ▶ croak("no tracefile opened") unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 1 1
266  
267 1 my $iloc = $self->_tell();
268 1 my $p = $self->{FILE_BEGIN};
269  
270 1 $self->_seek($p); # beginning
271 1 $self->{INDEX} = {};
272 1 $self->{INDEX}->{RUN} = {};
273 1 $self->{INDEX}->{STREAM} = {};
274 1 $self->{RUN} = undef;
275 1 $self->{EVENT} = undef;
276 1 my $run = 0;
277 1 my $n = 1;
278  
279 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 152 1 153
280 152 my $pnext = $self->_tell();
281 152 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 152 152
282 0 carp("Error parsing trace file at line $n: $_");
283 0 $p = $pnext;
284 0 next;
285 }
286 152 my $str = $1 + 0;
287 152 my $cc = $2;
288 152 my $rest = eval($3);
289  
290 152 ▶ if ( !exists( $self->{INDEX}->{STREAM}->{$str} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"INDEX"}{"STREAM"}{$str}) 2 150 152
291 2 $self->{INDEX}->{STREAM}->{$str} = {};
292 2 $self->{INDEX}->{STREAM}->{$str}->{COMMENT} = {};
293 2 $self->{INDEX}->{STREAM}->{$str}->{NUMBER} = $str;
294 }
295  
296 152 ▶ if ( $cc ne '<' && $cc ne '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc ne "<" and $cc ne ">") 6 146 152
Condition100%3/3
$cc ne "<" and $cc ne ">"
!ll&&!rl&&r
63836
MC/DC100%2/2
$cc ne "<" and $cc ne ">"
$cc ne "<" $cc ne ">"
Truth table100%3/3
A and B
A= $cc ne "<"B= $cc ne ">"
ABresult
0X0
100
111
297  
298 6 ▶ if ( $cc eq '*' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc eq '*') { } 5 1 6
elsif ($cc eq '|') { } 1 0 1
299 5 ▶ if ( $rest =~ /^Lab::[\w\:]+::new\s/i ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($rest =~ /^Lab::[\w\:]+::new\s/iu) { } 1 4 5
elsif ($rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) { } 1 3 4
elsif ($rest =~ /^event\s*(\d+)\s*run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) { } 2 1 3
elsif ($rest =~ /^stop\s+run(\d+)\s.*\\?\@\s*([\d\.]+)/iu) { } 1 0 1
300 1 $self->{INDEX}->{STREAM}->{$str}->{CONNECT} = $rest;
301 }
302 elsif ( $rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i )
303 {
304 1 $run = $1 + 0;
305 1 my $t0 = $2;
306 carp("duplicate run '$run' at line $n")
307 1 ▶ if exists $self->{INDEX}->{RUN}->{$run};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"INDEX"}{"RUN"}{$run} 0 1 1
308 1 ▶ if ( !defined( $self->{RUN} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"RUN"}) 1 0 1
309 1 $self->{RUN} = $run;
310 1 $self->{EVENT} = 0;
311 }
312 1 $self->{INDEX}->{RUN}->{$run} = {};
313 1 $self->{INDEX}->{RUN}->{$run}->{POSITION} = $p;
314 1 $self->{INDEX}->{RUN}->{$run}->{STARTTIME} = $t0;
315 1 $self->{INDEX}->{RUN}->{$run}->{EVENT} = {};
316 }
317 elsif ( $rest
318 =~ /^event\s*(\d+)\s*run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i ) {
319 2 ▶ carp("event found outside of its run at line $n")
Branch: 1 branch
BranchTrueFalseTotal
unless $run == $2 + 0 0 2 2
320 unless $run == $2 + 0;
321 2 my $event = $1 + 0;
322 2 my $te = $3;
323 carp("duplicate event '$event', run '$run' at line $n")
324 if exists $self->{INDEX}->{RUN}->{$run}->{EVENT}
325 2 ▶ ->{$event};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"INDEX"}{"RUN"}{$run}{"EVENT"}{$event} 0 2 2
326 2 $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event} = {};
327 $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event}
328 2 ->{POSITION} = $p;
329 $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event}->{TIME}
330 2 = $te;
331 }
332 elsif ( $rest =~ /^stop\s+run(\d+)\s.*\\?\@\s*([\d\.]+)/i ) {
333 1 ▶ carp("run # mismatch at start/stop at line $n")
Branch: 1 branch
BranchTrueFalseTotal
unless $run == $1 + 0 0 1 1
334 unless $run == $1 + 0;
335 1 $run = $1 + 0;
336 1 my $t1 = $2;
337 1 $self->{INDEX}->{RUN}->{$run}->{STOPTIME} = $t1;
338 1 $run = 0;
339 }
340 else {
341 0 carp(
342 "ignoring unknown control sequence at line $n: $rest"
343 );
344 }
345 }
346 elsif ( $cc eq '|' ) {
347 1 $self->{INDEX}->{STREAM}->{$str}->{COMMENT}->{$p} = $rest;
348 }
349 else {
350 0 carp("unknown trace control char at line $n\n");
351 }
352 }
353 152 $p = $pnext;
354 152 $n++;
355 }
356 1 $self->_seek($iloc);
357 }
358  
359  
360 sub PrintIndex {
361 0 ▶ my $self = shift;
Subroutine PrintIndex: not called CC=20 SCAR=60.4
Pod documented
362 0 my ( $print_events, $tail ) = _check_args( \@_, qw(print_events) );
363  
364 0 ▶ if ( !defined( $self->{INDEX} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"INDEX"}) 0 0 0
365 0 carp "No index generated yet";
366 0 return;
367 }
368  
369 0 my $dirty = 0;
370 0 foreach my $str ( sort( keys( %{ $self->{INDEX}->{STREAM} } ) ) ) {
371 0 ▶ next if $str == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $str == 0 0 0 0
372 0 ▶ if ( !$dirty ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirty) 0 0 0
373 0 print "======= DATA STREAMS ==========\n";
374 0 $dirty = 1;
375 }
376 0 my $text = $self->{INDEX}->{STREAM}->{$str}->{CONNECT};
377 0 $text =~ s/\\"/"/g;
378  
379 0 my $len = length($text);
380 0 my $j = 0;
381 0 ▶ while ( $j == 0 || $j < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j == 0 or $j < $len) 0 0 0
Condition0%0/3
$j == 0 or $j < $len
l!l&&r!l&&!r
000
MC/DC0%0/2
$j == 0 or $j < $len
$j == 0 $j < $len
Truth table0%0/3
A or B
A= $j == 0B= $j < $len
ABresult
1X1
011
000
382 0 ▶ print "$str :" if $j == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $j == 0 0 0 0
383 0 ▶ print "\t", substr( $text, $j, 64 ) if $j < $len;
Branch: 1 branch
BranchTrueFalseTotal
if $j < $len 0 0 0
384 0 print "\n";
385 0 $j += 64;
386 }
387  
388 # print "$str\t",$self->{INDEX}->{STREAM}->{$str}->{CONNECT},"\n";
389 0 my $d2 = 0;
390 0 foreach my $c (
391 0 sort( keys( %{ $self->{INDEX}->{STREAM}->{$str}->{COMMENT} } ) ) )
392 {
393 0 $d2 = 1;
394 0 print "\t", $self->{INDEX}->{STREAM}->{$str}->{COMMENT}->{$c},
395 "\n";
396 }
397 0 ▶ print "\n" if $d2;
Branch: 1 branch
BranchTrueFalseTotal
if $d2 0 0 0
398 }
399 0 ▶ print "\n" if $dirty;
Branch: 1 branch
BranchTrueFalseTotal
if $dirty 0 0 0
400 0 $dirty = 0;
401  
402 0 foreach my $run ( sort( keys( %{ $self->{INDEX}->{RUN} } ) ) ) {
403 0 ▶ if ( !$dirty ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirty) 0 0 0
404 0 print "======= RUNS ==========\n";
405 0 $dirty = 1;
406 }
407 0 my (@e) = ( keys( %{ $self->{INDEX}->{RUN}->{$run}->{EVENT} } ) );
408 0 my $t0 = localtime( $self->{INDEX}->{RUN}->{$run}->{STARTTIME} );
409 0 my $t1;
410 $t1 = localtime( $self->{INDEX}->{RUN}->{$run}->{STOPTIME} )
411 0 ▶ if exists( $self->{INDEX}->{RUN}->{$run}->{STOPTIME} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"INDEX"}{"RUN"}{$run}{"STOPTIME"} 0 0 0
412 0 ▶ if ( !defined($t1) ) { # use file modification time
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t1) 0 0 0
413 0 $t1 = localtime( $self->{FSTAT}->[9] ) . '?';
414 }
415 printf(
416 0 "RUN %08d :\t% 8d events\t(%s)..(%s)\n", $run, $#e + 1, $t0,
417 $t1
418 );
419  
420 0 ▶ if ( defined($print_events) && $print_events ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $print_events and $print_events) 0 0 0
Condition0%0/3
defined $print_events and $print_events
!ll&&!rl&&r
000
MC/DC0%0/2
defined $print_events and $print_events
defined $print_events $print_events
Truth table0%0/3
A and B
A= defined $print_eventsB= $print_events
ABresult
0X0
100
111
421 0 print "\t EVENT\t FILE POSITION \t TIME\n";
422 0 foreach my $ev ( sort(@e) ) {
423 $t0 = localtime(
424 0 $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$ev}->{TIME} );
425 my $pos = $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$ev}
426 0 ->{POSITION};
427 0 printf( "\t% 8d\t% 16d\t%s\n", $ev, $pos, $t0 );
428 }
429 0 print "\n";
430 }
431  
432 }
433 0 ▶ print "\n" if $dirty;
Branch: 1 branch
BranchTrueFalseTotal
if $dirty 0 0 0
434  
435 }
436  
437  
438 sub ReadEvent {
439 2 ▶ my $self = shift;
Subroutine ReadEvent: called CC=52 SCAR=52.1
Pod documented
440 2 my ( $stream, $inrun, $inevent, $tail )
441 = _check_args( \@_, qw(stream run event) );
442  
443 # turn stream selection into an array ref, however passed.
444 2 my $streams = {};
445 2 ▶ if ( defined($stream) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stream) 0 2 2
446 0 ▶ if ( ref($stream) eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $stream eq "") 0 0 0
447 0 $stream = [$stream];
448 }
449  
450 0 foreach my $s ( @{$stream} ) {
451 0 $streams->{$s} = 1;
452 }
453 $streams->{0} = 1
454 0 ▶ unless exists( $tail->{no_global} ) && !$tail->{no_global};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tail->{"no_global"} and not $tail->{"no_global"} 0 0 0
Condition0%0/3
exists $tail->{"no_global"} and not $tail->{"no_global"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $tail->{"no_global"} and not $tail->{"no_global"}
exists $tail->{"no_global"} not $tail->{"no_global"}
Truth table0%0/3
A and not(B)
A= exists $tail->{"no_global"}B= not $tail->{"no_global"}
ABresult
0X0
100
111
455 }
456  
457 2 my $fh = $self->{FH};
458 2 ▶ croak("data file is not open") unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 2 2
459  
460 2 ▶ if ( defined($inrun) || defined($inevent) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inrun or defined $inevent) 1 1 2
Condition66%2/3
defined $inrun or defined $inevent
l!l&&r!l&&!r
101
MC/DC50%1/2
defined $inrun or defined $inevent
defined $inrun defined $inevent
Truth table66%2/3
A or B
A= defined $inrunB= defined $inevent
ABresult
1X1
011
000
461 return undef
462 unless
463 1 ▶ defined( $self->FindEvent( run => $inrun, event => $inevent ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->FindEvent("run", $inrun, "event", $inevent) 0 1 1
464 }
465  
466 2 my $p = $self->_tell();
467 my $ev = {
468 GPIB => [],
469 COMMENT => [],
470 STREAM => {},
471 FILEHEADER => undef,
472 RUNHEADER => undef,
473 2 CONFIG => clone( $self->{CONFIG} ),
474 };
475  
476 2 ▶ if ( !defined( $self->{INDEX} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'INDEX'}) { } 1 1 2
477  
478 1 my $inevent = 0;
479  
480 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 116 0 116
481 116 chomp;
482 116 my $pnext = $self->_tell();
483 116 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 116 116
484 0 carp("Error parsing trace file: $_");
485 0 $p = $pnext;
486 0 next;
487 }
488 116 my $str = $1 + 0;
489 116 my $cc = $2;
490 116 my $rest = eval($3);
491  
492 116 ▶ if ( $cc eq '*' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($cc eq '*') { } 4 112 116
elsif ($cc eq '|') { } 1 111 112
elsif ($cc eq '<' or $cc eq '>') { } 111 0 111
493 4 ▶ if ( $rest =~ /^Lab::[\w\:]+::new\s/i ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($rest =~ /^Lab::[\w\:]+::new\s/iu) { } 1 3 4
elsif ($rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) { } 1 2 3
elsif ($rest =~ /^event\s*(\d+)\s*run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) { } 2 0 2
elsif ($rest =~ /^stop\s+run(\d+)\s.*\\?\@\s*([\d\.]+)/iu) { } 0 0 0
494 ;
495 }
496 elsif ( $rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i )
497 {
498 1 ▶ last if $inevent;
Branch: 1 branch
BranchTrueFalseTotal
if $inevent 0 1 1
499 }
500 elsif ( $rest
501 =~ /^event\s*(\d+)\s*run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i ) {
502 2 ▶ last if $inevent;
Branch: 1 branch
BranchTrueFalseTotal
if $inevent 1 1 2
503  
504 1 $inevent = 1;
505 1 $ev->{EVENT} = $1 + 0;
506 1 $ev->{RUN} = $2 + 0;
507 1 $ev->{TIME} = $3;
508 1 $ev->{POSITION} = $p;
509 1 ▶ if ( $self->{CONFIG}->{clone_headers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CONFIG"}{"clone_headers"}) 1 0 1
510 $ev->{FILEHEADER} = clone( $self->{FILEHEADER} )
511 1 ▶ if defined $self->{FILEHEADER};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"FILEHEADER"} 0 1 1
512 $ev->{RUNHEADER} = clone( $self->{RUNHEADER} )
513 1 ▶ if defined $self->{RUNHEADER};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"RUNHEADER"} 0 1 1
514 }
515 }
516 elsif ( $rest =~ /^stop\s+run(\d+)\s.*\\?\@\s*([\d\.]+)/i ) {
517 0 ▶ last if $inevent;
Branch: 1 branch
BranchTrueFalseTotal
if $inevent 0 0 0
518 }
519 else {
520 0 carp("ignoring unknown control sequence: $rest");
521 }
522 }
523 elsif ( $cc eq '|' ) {
524 1 ▶ if ( $inevent
Branch: 1 branch
BranchTrueFalseTotal
if ($inevent and !defined($stream) || exists $streams->{$str}) 0 1 1
Condition16%1/6
$inevent and !defined($stream) || exists $streams->{$str}
!ll&&!rl&&r
100
not defined $stream or exists $streams->{$str}
l!l&&r!l&&!r
000
MC/DC0%0/3
$inevent and !defined($stream) || exists $streams->{$str}
$inevent not defined $stream exists $streams->{$str}
Truth table25%1/4
A and not(B) or C
A= $ineventB= not defined $streamC= exists $streams->{$str}
ABCresult
0XX0
1000
11X1
1011
525 && ( !defined($stream) || exists( $streams->{$str} ) ) ) {
526  
527 0 push( @{ $ev->{COMMENT} }, $rest );
528 $ev->{STREAM}->{$str} = {
529 COMMENT => [],
530 GPIB => [],
531 NUMBER => $str,
532 CONFIG => clone( $self->{CONFIG} ),
533 0 ▶ } unless exists $ev->{STREAM}->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ev->{"STREAM"}{$str} 0 0 0
534 0 push( @{ $ev->{STREAM}->{$str}->{COMMENT} }, $rest );
535 }
536 }
537 ▶ elsif ( $cc eq '<' || $cc eq '>' ) {
Condition66%2/3
$cc eq "<" or $cc eq ">"
l!l&&r!l&&!r
49620
MC/DC0%0/2
$cc eq "<" or $cc eq ">"
$cc eq "<" $cc eq ">"
Truth table66%2/3
A or B
A= $cc eq "<"B= $cc eq ">"
ABresult
1X1
011
000
538 111 ▶ if ( $inevent
Branch: 1 branch
BranchTrueFalseTotal
if ($inevent and !defined($stream) || exists $streams->{$str}) 21 90 111
Condition50%3/6
$inevent and !defined($stream) || exists $streams->{$str}
!ll&&!rl&&r
90210
not defined $stream or exists $streams->{$str}
l!l&&r!l&&!r
2100
MC/DC0%0/3
$inevent and !defined($stream) || exists $streams->{$str}
$inevent not defined $stream exists $streams->{$str}
Truth table25%1/4
A and not(B) or C
A= $ineventB= not defined $streamC= exists $streams->{$str}
ABCresult
0XX0
1000
11X1
1011
539 && ( !defined($stream) || exists( $streams->{$str} ) ) ) {
540 0 push( @{ $ev->{GPIB} }, $cc . $rest )
541 21 ▶ if $self->{CONFIG}->{combine_gpib};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CONFIG"}{"combine_gpib"} 0 21 21
542 $ev->{STREAM}->{$str} = {
543 COMMENT => [],
544 GPIB => [],
545 NUMBER => $str,
546 CONFIG => clone( $self->{CONFIG} ),
547 21 ▶ } unless exists $ev->{STREAM}->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ev->{"STREAM"}{$str} 1 20 21
548 21 push( @{ $ev->{STREAM}->{$str}->{GPIB} }, $cc . $rest );
549 }
550 }
551 else {
552 0 carp("unknown trace control char '$cc'\n");
553 }
554 115 $p = $pnext;
555 }
556  
557 1 ▶ return undef unless $inevent;
Branch: 1 branch
BranchTrueFalseTotal
unless $inevent 0 1 1
558 1 $self->_seek($p);
559 1 $self->{RUN} = $ev->{RUN};
560 1 $self->{EVENT} = $ev->{EVENT};
561  
562 }
563 else {
564 1 my $run = $self->{RUN};
565 1 my $event = $self->{EVENT} + 1;
566 1 ▶ return undef unless exists $self->{INDEX}->{RUN}->{$run};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"INDEX"}{"RUN"}{$run} 0 1 1
567 return undef
568 1 ▶ unless exists $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"INDEX"}{"RUN"}{$run}{"EVENT"}{$event} 0 1 1
569 my $pev
570 1 = $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event}->{POSITION};
571 1 $ev->{RUN} = $run;
572 1 $ev->{EVENT} = $self->{EVENT} = $event;
573 1 $ev->{POSITION} = $pev;
574 $ev->{TIME}
575 1 = $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event}->{TIME};
576 1 $ev->{STREAM} = {};
577 1 $ev->{GPIB} = [];
578 1 $ev->{COMMENT} = [];
579 1 $ev->{CONFIG} = clone( $self->{CONFIG} );
580  
581 1 ▶ if ( $self->{CONFIG}->{clone_headers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CONFIG"}{"clone_headers"}) 1 0 1
582 $ev->{FILEHEADER} = clone( $self->{FILEHEADER} )
583 1 ▶ if defined $self->{FILEHEADER};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"FILEHEADER"} 0 1 1
584 $ev->{RUNHEADER} = clone( $self->{RUNHEADER} )
585 1 ▶ if defined $self->{RUNHEADER};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"RUNHEADER"} 0 1 1
586 }
587  
588 1 $self->_seek($pev);
589 1 my $foo = <$fh>;
590 1 my $p;
591 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 22 0 22
592 22 $p = $self->_tell();
593 22 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 22 22
594 0 carp("Error parsing trace file at line : $_");
595 0 next;
596 }
597 22 my $str = $1 + 0;
598 22 my $cc = $2;
599 22 my $rest = eval($3);
600  
601 22 ▶ last if $cc eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $cc eq "*" 1 21 22
602 21 ▶ next unless !defined($stream) || exists( $streams->{$str} );
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $stream or exists $streams->{$str} 0 21 21
Condition33%1/3
not defined $stream or exists $streams->{$str}
l!l&&r!l&&!r
2100
MC/DC0%0/2
not defined $stream or exists $streams->{$str}
not defined $stream exists $streams->{$str}
Truth table33%1/3
not(A) or B
A= not defined $streamB= exists $streams->{$str}
ABresult
1X1
011
000
603 $ev->{STREAM}->{$str} = {
604 COMMENT => [],
605 GPIB => [],
606 NUMBER => $str,
607 CONFIG => clone( $self->{CONFIG} ),
608 21 ▶ } unless exists $ev->{STREAM}->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ev->{"STREAM"}{$str} 1 20 21
609  
610 21 ▶ if ( $cc eq '|' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc eq '|') { } 0 21 21
elsif ($cc eq '>' or $cc eq '<') { } 21 0 21
611 0 push( @{ $ev->{COMMENT} }, $rest );
612 0 push( @{ $ev->{STREAM}->{$str}->{COMMENT} }, $rest );
613 }
614 ▶ elsif ( $cc eq '>' || $cc eq '<' ) {
Condition66%2/3
$cc eq ">" or $cc eq "<"
l!l&&r!l&&!r
1290
MC/DC0%0/2
$cc eq ">" or $cc eq "<"
$cc eq ">" $cc eq "<"
Truth table66%2/3
A or B
A= $cc eq ">"B= $cc eq "<"
ABresult
1X1
011
000
615 0 push( @{ $ev->{GPIB} }, $cc . $rest )
616 21 ▶ if $self->{CONFIG}->{combine_gpib};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CONFIG"}{"combine_gpib"} 0 21 21
617 21 push( @{ $ev->{STREAM}->{$str}->{GPIB} }, $cc . $rest );
618 }
619 else {
620 0 carp("unknown trace control char '$cc'\n");
621 }
622 }
623 }
624 2 $self->_seek($p); # position at start of next event/control line
625 2 return $ev;
626 }
627  
628  
629 sub ReadFileHeader {
630 1 ▶ my $self = shift;
Subroutine ReadFileHeader: called CC=16 SCAR=30.1
Pod documented
631 1 my ( $in, $tail ) = _check_args( \@_, 'shift' );
632  
633 1 my $fh = $self->{FH};
634 1 ▶ croak("No trace file open") unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 1 1
635  
636 1 my $shift = 0;
637 1 ▶ if ( defined($in) && $in =~ /^\s*(Y|T|[1-9])/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $in and $in =~ /^\s*(Y|T|[1-9])/iu) 0 1 1
Condition33%1/3
defined $in and $in =~ /^\s*(Y|T|[1-9])/iu
!ll&&!rl&&r
100
MC/DC0%0/2
defined $in and $in =~ /^\s*(Y|T|[1-9])/iu
defined $in $in =~ /^\s*(Y|T|[1-9])/iu
Truth table33%1/3
A and B
A= defined $inB= $in =~ /^\s*(Y|T|[1-9])/iu
ABresult
0X0
100
111
638 0 $shift = 1;
639 }
640 1 $self->{FILEHEADER} = undef;
641  
642 1 my $ipos = $self->_tell();
643  
644 1 my $p = $self->{FILE_BEGIN};
645 1 $self->_seek($p);
646 1 my $hdr = {};
647  
648 1 $hdr->{POSITION} = $p;
649 1 $hdr->{STREAM} = {};
650  
651 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 85 0 85
652 85 my $pnext = $self->_tell();
653 85 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 85 85
654 0 carp("Error parsing trace file : $_");
655 0 $p = $pnext;
656 0 next;
657 }
658 85 my $str = $1 + 0;
659 85 my $cc = $2;
660 85 my $rest = eval($3);
661  
662 $hdr->{STREAM}->{$str} = {
663 COMMENT => [],
664 GPIB => [],
665 NUMBER => $str,
666 CONNECT => undef,
667 85 ▶ } unless exists $hdr->{STREAM}->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hdr->{"STREAM"}{$str} 2 83 85
668  
669 85 ▶ if ( $cc eq '*' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($cc eq '*') { } 2 83 85
elsif ($cc eq '|') { } 1 82 83
elsif ($cc eq '<' or $cc eq '>') { } 82 0 82
670 2 ▶ last if $rest =~ /^start\s+run/i;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /^start\s+run/iu 1 1 2
671 1 ▶ last if $rest =~ /^event/i;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /^event/iu 0 1 1
672 1 ▶ last if $rest =~ /^stop/i;
Branch: 1 branch
BranchTrueFalseTotal
if $rest =~ /^stop/iu 0 1 1
673 1 ▶ if ( $rest =~ /^Lab::/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^Lab::/iu) { } 1 0 1
674 1 $hdr->{STREAM}->{$str}->{CONNECT} = $rest;
675 }
676 else {
677 0 carp("ignoring unknown control sequence: $rest");
678 }
679 }
680 elsif ( $cc eq '|' ) {
681 1 push( @{ $hdr->{STREAM}->{$str}->{COMMENT} }, $rest );
682 }
683 ▶ elsif ( $cc eq '<' || $cc eq '>' ) {
Condition66%2/3
$cc eq "<" or $cc eq ">"
l!l&&r!l&&!r
37450
MC/DC0%0/2
$cc eq "<" or $cc eq ">"
$cc eq "<" $cc eq ">"
Truth table66%2/3
A or B
A= $cc eq "<"B= $cc eq ">"
ABresult
1X1
011
000
684 82 push( @{ $hdr->{STREAM}->{$str}->{GPIB} }, $cc . $rest );
685 }
686 else {
687 0 carp("unknown trace control char '$cc' at line\n");
688 }
689 84 $p = $pnext;
690 }
691 1 ▶ if ($shift) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shift) { } 0 1 1
692 0 $self->_seek($p);
693 }
694 else {
695 1 $self->_seek($ipos);
696 }
697 1 $self->{FILEHEADER} = $hdr;
698 1 return $hdr;
699 }
700  
701  
702 sub ReadRunHeader {
703 0 ▶ my $self = shift;
Subroutine ReadRunHeader: not called CC=22 SCAR=62.3
Pod documented
704 0 my ( $selrun, $tail ) = _check_args( \@_, qw(run) );
705  
706 0 my $fh = $self->{FH};
707 0 ▶ croak("no tracefile opened") unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
708  
709 0 my $hdr = {
710 STREAM => {},
711 };
712 0 my $ipos = $self->_tell();
713  
714 0 ▶ if ( defined( $self->{INDEX} ) && defined($selrun) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'INDEX'} and defined $selrun) { } 0 0 0
Condition0%0/3
defined $self->{"INDEX"} and defined $selrun
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"INDEX"} and defined $selrun
defined $self->{"INDEX"} defined $selrun
Truth table0%0/3
A and B
A= defined $self->{"INDEX"}B= defined $selrun
ABresult
0X0
100
111
715 0 ▶ if ( exists( $self->{INDEX}->{RUN}->{$selrun} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'INDEX'}{'RUN'}{$selrun}) { } 0 0 0
716 0 $self->_seek( $self->{INDEX}->{RUN}->{$selrun}->{POSITION} );
717 0 $self->{RUN} = $selrun;
718 }
719 else {
720 0 return undef;
721 }
722 }
723 else {
724  
725 0 my $p = $ipos;
726 0 my $foundrun = 0;
727  
728 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
729 0 my $pnext = $self->_tell();
730  
731 0 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 0 0
732 0 carp("Error parsing trace file : $_");
733 0 next;
734 }
735 0 my $str = $1 + 0;
736 0 my $cc = $2;
737 0 my $rest = eval($3);
738  
739 0 ▶ if ( $cc eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc eq "*") 0 0 0
740 0 ▶ if ( $rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) 0 0 0
741 0 my $run = $1 + 0;
742 0 ▶ if ( !defined($selrun) || $selrun == $run ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $selrun or $selrun == $run) 0 0 0
Condition0%0/3
not defined $selrun or $selrun == $run
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $selrun or $selrun == $run
not defined $selrun $selrun == $run
Truth table0%0/3
not(A) or B
A= not defined $selrunB= $selrun == $run
ABresult
1X1
011
000
743 0 $foundrun = 1;
744 0 $self->{RUN} = $run;
745 0 last;
746 }
747 }
748 }
749 0 $p = $pnext;
750 }
751 0 ▶ if ( !$foundrun ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($foundrun) 0 0 0
752 0 $self->_seek($ipos);
753 0 return undef;
754 }
755 0 $self->_seek($p);
756 }
757  
758 0 my $p = $self->_tell();
759 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
760 0 my $pnext = $self->_tell();
761  
762 0 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 0 0
763 0 carp("Error parsing trace file: $_");
764 0 next;
765 }
766 0 my $str = $1 + 0;
767 0 my $cc = $2;
768 0 my $rest = eval($3);
769  
770 $hdr->{STREAM}->{$str} = {
771 COMMENT => [],
772 GPIB => [],
773 NUMBER => $str,
774 0 ▶ } unless exists $hdr->{STREAM}->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hdr->{"STREAM"}{$str} 0 0 0
775  
776 0 ▶ if ( $cc eq '*' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($cc eq '*') { } 0 0 0
elsif ($cc eq '|') { } 0 0 0
elsif ($cc eq '>' or $cc eq '<') { } 0 0 0
777 0 ▶ if ( $rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) { } 0 0 0
elsif ($rest =~ /^(event|stop|Lab::)/iu) { } 0 0 0
778 0 my $run = $1 + 0;
779 0 ▶ last if $self->{RUN} != $run;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"RUN"} != $run 0 0 0
780  
781 0 $hdr->{RUN} = $run;
782 0 $hdr->{POSITION} = $p;
783 0 $hdr->{STARTTIME} = $2;
784  
785 }
786 elsif ( $rest =~ /^(event|stop|Lab::)/i ) {
787 0 last;
788 }
789 else {
790 0 carp("ignoring unknown control sequence : $rest");
791 }
792 }
793 elsif ( $cc eq '|' ) {
794 0 push( @{ $hdr->{STREAM}->{$str}->{COMMENT} }, $rest );
795 }
796 ▶ elsif ( $cc eq '>' || $cc eq '<' ) {
Condition0%0/3
$cc eq ">" or $cc eq "<"
l!l&&r!l&&!r
000
MC/DC0%0/2
$cc eq ">" or $cc eq "<"
$cc eq ">" $cc eq "<"
Truth table0%0/3
A or B
A= $cc eq ">"B= $cc eq "<"
ABresult
1X1
011
000
797 0 push( @{ $hdr->{STREAM}->{$str}->{GPIB} }, $cc . $rest );
798 }
799 else {
800 0 carp("unknown trace control char '$cc'\n");
801 }
802 0 $p = $pnext;
803 }
804 0 $self->_seek($p);
805  
806 0 $self->{RUNHEADER} = $hdr;
807 0 return $hdr;
808 }
809  
810  
811 sub FindEvent {
812 1 ▶ my $self = shift;
Subroutine FindEvent: called CC=38 SCAR=68.2
Pod documented
813 1 my ( $run, $event, $tail ) = _check_args( \@_, 'run', 'event' );
814  
815 1 ▶ if ( !defined($run) || $run <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $run or $run <= 0) 0 1 1
Condition33%1/3
not defined $run or $run <= 0
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $run or $run <= 0
not defined $run $run <= 0
Truth table33%1/3
not(A) or B
A= not defined $runB= $run <= 0
ABresult
1X1
011
000
816 0 $run = $self->{RUN};
817 }
818 1 ▶ if ( !defined($run) || $run <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $run or $run <= 0) 0 1 1
Condition33%1/3
not defined $run or $run <= 0
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $run or $run <= 0
not defined $run $run <= 0
Truth table33%1/3
not(A) or B
A= not defined $runB= $run <= 0
ABresult
1X1
011
000
819 0 carp("invalid run (undef? <=0?)");
820 0 return undef;
821 }
822  
823 1 ▶ if ( exists( $self->{INDEX} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'INDEX'}) { } 1 0 1
824 1 ▶ return undef unless exists $self->{INDEX}->{RUN}->{$run};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"INDEX"}{"RUN"}{$run} 0 1 1
825 my (@ev)
826 1 = ( sort( keys( %{ $self->{INDEX}->{RUN}->{$run}->{EVENT} } ) ) );
827 1 ▶ if ( !defined($event) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $event) 0 1 1
828 0 ▶ if ( defined( $self->{EVENT} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'EVENT'}) { } 0 0 0
829 0 $event = $self->{EVENT} + 1;
830 }
831 else {
832 0 $event = 0;
833 }
834 }
835 1 ▶ if ( $event == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($event == 0) { } 0 1 1
elsif ($event < 0) { } 0 1 1
836 0 $event = $ev[0];
837 }
838 elsif ( $event < 0 ) {
839 0 $event = $ev[$event];
840 }
841 return undef
842 1 ▶ unless exists $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"INDEX"}{"RUN"}{$run}{"EVENT"}{$event} 0 1 1
843 1 my $p = $self->{INDEX}->{RUN}->{$run}->{EVENT}->{$event}->{POSITION};
844 1 $self->_seek($p);
845 1 return $p;
846 }
847 else {
848 0 my $fh = $self->{FH};
849 0 ▶ croak("no file opened") unless defined $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fh 0 0 0
850  
851 0 my $p = $self->_tell();
852 0 my $pstart = $p;
853 0 my $foundrun = 0;
854 0 my $foundevent = 0;
855 0 my $wrapped = 0;
856  
857 0 ▶ if ( !defined($event) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $event) 0 0 0
858 0 ▶ if ( defined( $self->{EVENT} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'EVENT'}) { } 0 0 0
859 0 $event = $self->{EVENT} + 1;
860 }
861 else {
862 0 $event = 0;
863 }
864 }
865 0 ▶ $event = 0 if $event < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $event < 0 0 0 0
866  
867 0 ▶ while ( !$wrapped ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($wrapped) 0 0 0
868 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
869 0 my $pnext = $self->_tell();
870 0 ▶ last if $pnext == $pstart; # wrapped the file
Branch: 1 branch
BranchTrueFalseTotal
if $pnext == $pstart 0 0 0
871  
872 0 ▶ if ( !/^(\d+)(.)(.*)\s*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^(\d+)(.)(.*)\s*$/u) 0 0 0
873 0 carp("Error parsing trace file: $_");
874 0 next;
875 }
876 0 my $str = $1 + 0;
877 0 my $cc = $2;
878 0 my $rest = eval($3);
879  
880 0 ▶ if ( $cc eq '*' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc eq "*") 0 0 0
881 0 ▶ if (
Branch: 3 branches
BranchTrueFalseTotal
if ($rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/iu) { } 0 0 0
elsif ($rest =~ /^event\s*(\d+)\s*run\s*(\d+)/iu) { } 0 0 0
elsif ($rest =~ /^stop\s+run\s*(\d+)/iu) { } 0 0 0
882 $rest =~ /^start\s+run\s*(\d+)\s*\\?\@\s*([\d\.]+)/i )
883 {
884 0 my $gotrun = $1 + 0;
885 0 ▶ if ( $foundrun && ( $gotrun != $run ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($foundrun and $gotrun != $run) 0 0 0
Condition0%0/3
$foundrun and $gotrun != $run
!ll&&!rl&&r
000
MC/DC0%0/2
$foundrun and $gotrun != $run
$foundrun $gotrun != $run
Truth table0%0/3
A and B
A= $foundrunB= $gotrun != $run
ABresult
0X0
100
111
886 { # ran off the end of desired run, wrap
887 0 $foundrun = 0;
888 0 last;
889 }
890 0 $foundrun = ( $gotrun == $run );
891 }
892 elsif ( $rest =~ /^event\s*(\d+)\s*run\s*(\d+)/i ) {
893 0 my $gotev = $1 + 0;
894 0 my $gotrun = $2 + 0;
895 0 ▶ if ( $foundrun && ( $gotrun != $run ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($foundrun and $gotrun != $run) 0 0 0
Condition0%0/3
$foundrun and $gotrun != $run
!ll&&!rl&&r
000
MC/DC0%0/2
$foundrun and $gotrun != $run
$foundrun $gotrun != $run
Truth table0%0/3
A and B
A= $foundrunB= $gotrun != $run
ABresult
0X0
100
111
896 { # ran off the end of desired run, wrap
897 0 $foundrun = 0;
898 0 last;
899 }
900 0 $foundrun = ( $gotrun == $run );
901 0 ▶ if ($foundrun) {
Branch: 1 branch
BranchTrueFalseTotal
if ($foundrun) 0 0 0
902 0 ▶ $foundevent = 1
Branch: 1 branch
BranchTrueFalseTotal
if $event == 0 or $event == $gotev 0 0 0
Condition0%0/3
$event == 0 or $event == $gotev
l!l&&r!l&&!r
000
MC/DC0%0/2
$event == 0 or $event == $gotev
$event == 0 $event == $gotev
Truth table0%0/3
A or B
A= $event == 0B= $event == $gotev
ABresult
1X1
011
000
903 if $event == 0 || $event == $gotev;
904 0 ▶ last if $foundevent;
Branch: 1 branch
BranchTrueFalseTotal
if $foundevent 0 0 0
905 }
906 }
907 elsif ( $rest =~ /^stop\s+run\s*(\d+)/i ) {
908 0 my $gotrun = $1 + 0;
909 0 ▶ if ($foundrun)
Branch: 1 branch
BranchTrueFalseTotal
if ($foundrun) 0 0 0
910 { # ran off the end of desired run, wrap
911 0 $foundrun = 0;
912 0 last; # wrap the file
913 }
914 }
915 }
916 0 $p = $pnext;
917 }
918 0 ▶ last if $wrapped;
Branch: 1 branch
BranchTrueFalseTotal
if $wrapped 0 0 0
919 0 ▶ last if $foundrun && $foundevent;
Branch: 1 branch
BranchTrueFalseTotal
if $foundrun and $foundevent 0 0 0
Condition0%0/3
$foundrun and $foundevent
!ll&&!rl&&r
000
MC/DC0%0/2
$foundrun and $foundevent
$foundrun $foundevent
Truth table0%0/3
A and B
A= $foundrunB= $foundevent
ABresult
0X0
100
111
920 0 $wrapped = 1;
921 0 $p = $self->{FILE_BEGIN};
922 0 $self->_seek($p);
923 }
924 0 ▶ if ( !$foundrun || !$foundevent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($foundrun and $foundevent) 0 0 0
Condition0%0/3
$foundrun and $foundevent
!ll&&!rl&&r
000
MC/DC0%0/2
$foundrun and $foundevent
$foundrun $foundevent
Truth table0%0/3
A and B
A= $foundrunB= $foundevent
ABresult
0X0
100
111
925 0 $self->_seek($pstart);
926 0 return undef;
927 }
928 0 $self->{RUN} = $run;
929 0 $self->{EVENT} = $event;
930 0 $self->_seek($p);
931 0 return $p;
932 }
933 }
934  
935  
936 sub PrintDefaultAnalyzer {
937 0 ▶ my $self = shift;
Subroutine PrintDefaultAnalyzer: not called CC=14 SCAR=53.5
Pod documented
938 0 my ( $in, $tail ) = _check_args( \@_, 'stream' );
939  
940 0 my $stream;
941 0 ▶ if ( defined($in) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $in) 0 0 0
942 0 $stream = {};
943 0 ▶ if ( ref($in) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $in eq 'ARRAY') { } 0 0 0
elsif (ref $in eq '') { } 0 0 0
944 0 $stream->{$in} = 1;
945 }
946 elsif ( ref($in) eq '' ) {
947 0 $stream->{$in} = 1;
948 0 foreach my $k ( keys( %{$tail} ) ) {
949 0 ▶ next unless $k =~ /^_tail\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^_tail\d+$/u 0 0 0
950 0 $stream->{ $tail->{$k} } = 1;
951 }
952 }
953 else {
954 0 croak("parameter type mismatch");
955 }
956 }
957  
958 0 ▶ $self->ReadFileHeader() unless defined $self->{FILEHEADER};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FILEHEADER"} 0 0 0
959  
960 0 my $dirty = 0;
961 0 foreach my $s ( sort( keys( %{ $self->{FILEHEADER}->{STREAM} } ) ) ) {
962 0 ▶ next if $s == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s == 0 0 0 0
963 0 ▶ next if defined($stream) && !exists( $stream->{$s} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $stream and not exists $stream->{$s} 0 0 0
Condition0%0/3
defined $stream and not exists $stream->{$s}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stream and not exists $stream->{$s}
defined $stream not exists $stream->{$s}
Truth table0%0/3
A and not(B)
A= defined $streamB= not exists $stream->{$s}
ABresult
0X0
100
111
964 0 my $aType = $self->_findDefAnalyzer($s);
965 0 ▶ next unless defined $aType;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $aType 0 0 0
966  
967 0 ▶ print "Stream\tAnalyzer\n" unless $dirty;
Branch: 1 branch
BranchTrueFalseTotal
unless $dirty 0 0 0
968 0 $dirty = 1;
969 0 print " $s \t$aType\n";
970 }
971 0 ▶ print "\n" if $dirty;
Branch: 1 branch
BranchTrueFalseTotal
if $dirty 0 0 0
972 }
973  
974  
975 sub ConnectAnalyzer {
976 1 ▶ my $self = shift;
Subroutine ConnectAnalyzer: called CC=16 SCAR=35.2
Pod documented
977 1 my ( $instr, $inmod, $tail ) = _check_args( \@_, qw(stream module) );
978  
979 1 ▶ $self->ReadFileHeader() unless defined $self->{FILEHEADER};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FILEHEADER"} 1 0 1
980 1 foreach my $str ( keys( %{ $self->{FILEHEADER}->{STREAM} } ) ) {
981 2 ▶ next if $str == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $str == 0 1 1 2
982 1 ▶ if ( !defined($instr) || $instr == $str ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $instr or $instr == $str) 1 0 1
Condition33%1/3
not defined $instr or $instr == $str
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $instr or $instr == $str
not defined $instr $instr == $str
Truth table33%1/3
not(A) or B
A= not defined $instrB= $instr == $str
ABresult
1X1
011
000
983 1 my $defmod = $self->_findDefAnalyzer($str);
984 1 ▶ if ( defined($inmod) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $inmod) { } 0 1 1
985 0 ▶ if ( $inmod !~ /::/
Branch: 1 branch
BranchTrueFalseTotal
if (not $inmod =~ /::/u || -e "$inmod.pm" and defined $defmod and $defmod =~ /::$inmod$/u) 0 0 0
Condition0%0/9
not $inmod =~ /::/u || -e "$inmod.pm" and defined $defmod and $defmod =~ /::$inmod$/u
!ll&&!rl&&r
000
not $inmod =~ /::/u || -e "$inmod.pm" and defined $defmod
!ll&&!rl&&r
000
$inmod =~ /::/u || -e "$inmod.pm"
l!l&&r!l&&!r
000
MC/DC0%0/4
not $inmod =~ /::/u || -e "$inmod.pm" and defined $defmod and $defmod =~ /::$inmod$/u
$inmod =~ /::/u -e "$inmod.pm" defined $defmod $defmod =~ /::$inmod$/u
Truth table0%0/5
not(A || B) and C and D
A= $inmod =~ /::/uB= -e "$inmod.pm"C= defined $defmodD= $defmod =~ /::$inmod$/u
ABCDresult
1XXX0
01XX0
000X0
00100
00111
986 && !-e "$inmod.pm"
987 && defined($defmod)
988 && $defmod =~ /::${inmod}$/ ) { # default short name
989 0 $inmod = $defmod;
990 }
991 }
992 else {
993 1 $inmod = $self->_findDefAnalyzer($str);
994 }
995 1 ▶ if ( !defined($inmod) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $inmod) 0 1 1
996 0 carp("No analysis module defined for stream $str");
997 0 return;
998 }
999 1 ▶ if ( !exists( $_LOADED->{$inmod} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lab::Data::Analysis::_LOADED->{$inmod}) 1 0 1
1000 1 ▶ eval("use $inmod;");
Subroutine BEGIN: called CC=1 SCAR=0.0
1001 1 ▶ croak($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
1002 1 $_LOADED->{$inmod} = 1;
1003 }
1004 1 my $strhdr = $self->{FILEHEADER}->{STREAM}->{$str};
1005  
1006 $self->{FILEHEADER}->{STREAM}->{$str}->{ANALYSIS} = []
1007 unless
1008 1 ▶ exists $self->{FILEHEADER}->{STREAM}->{$str}->{ANALYSIS};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"FILEHEADER"}{"STREAM"}{$str}{"ANALYSIS"} 1 0 1
1009  
1010 1 my $a;
1011 1 eval( '$a = ' . $inmod . '->new(stream=>$strhdr);' );
1012 1 ▶ croak("error connecting analyzer $inmod") unless defined $a;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a 0 1 1
1013 push(
1014 1 @{ $self->{FILEHEADER}->{STREAM}->{$str}->{ANALYSIS} },
1015 $a
1016 );
1017 }
1018 }
1019 }
1020  
1021 sub _findDefAnalyzer {
1022 2 ▶ my $self = shift;
Subroutine _findDefAnalyzer: called CC=6 SCAR=18.7
1023 2 my $str = shift;
1024 2 ▶ return undef if $str == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $str == 0 0 2 2
1025 2 ▶ $self->ReadFileHeader() unless defined $self->{FILEHEADER};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"FILEHEADER"} 0 2 2
1026 2 ▶ return undef unless exists $self->{FILEHEADER}->{STREAM}->{$str};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"FILEHEADER"}{"STREAM"}{$str} 0 2 2
1027  
1028 2 my $con = $self->{FILEHEADER}->{STREAM}->{$str}->{CONNECT};
1029  
1030 2 foreach my $aNum ( sort( keys( %{$_DefaultAnalyzer} ) ) ) {
1031 2 my $aMatch = $_DefaultAnalyzer->{$aNum}->{MATCH};
1032 2 ▶ next unless $con =~ /$aMatch/;
Branch: 1 branch
BranchTrueFalseTotal
unless $con =~ /$aMatch/u 0 2 2
1033 2 my $aType = $_DefaultAnalyzer->{$aNum}->{TYPE};
1034 2 return $aType;
1035 }
1036 0 return undef;
1037 }
1038  
1039  
1040 sub Analyze {
1041 1 ▶ my $self = shift;
Subroutine Analyze: called CC=19 SCAR=44.2
Pod documented
1042 1 my ( $event, $opts, $str, $tail )
1043 = _check_args( \@_, 'event', 'options', 'stream' );
1044  
1045 1 ▶ if ( !defined($event) || ref($event) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $event or ref $event ne "HASH") 0 1 1
Condition33%1/3
not defined $event or ref $event ne "HASH"
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $event or ref $event ne "HASH"
not defined $event ref $event ne "HASH"
Truth table33%1/3
not(A) or B
A= not defined $eventB= ref $event ne "HASH"
ABresult
1X1
011
000
1046 0 carp("bad/missing event");
1047 0 return undef;
1048 }
1049 1 ▶ return undef unless exists $self->{FILEHEADER};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"FILEHEADER"} 0 1 1
1050 1 ▶ return undef unless exists $self->{FILEHEADER}->{STREAM};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"FILEHEADER"}{"STREAM"} 0 1 1
1051 1 ▶ $opts = {} unless defined $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts 1 0 1
1052  
1053 1 my $stream;
1054  
1055 1 ▶ if ( defined($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $str) 0 1 1
1056 0 ▶ if ( ref($str) eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $str eq 'ARRAY') { } 0 0 0
elsif (ref $str eq '') { } 0 0 0
1057 0 $stream = {};
1058 0 foreach my $s ( @{$str} ) {
1059 0 $stream->{$s} = 1;
1060 }
1061 }
1062 elsif ( ref($str) eq '' ) {
1063 0 $stream = { $str => 1 };
1064 0 foreach my $k ( sort( keys( %{$tail} ) ) ) {
1065 0 ▶ next unless $k =~ /^_tail\d+/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^_tail\d+/iu 0 0 0
1066 0 ▶ next unless $tail->{$k} =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tail->{$k} =~ /^\d+$/u 0 0 0
1067 0 $stream->{ $tail->{$k} } = 1;
1068 0 delete( $tail->{$k} );
1069 }
1070 }
1071 else {
1072 0 carp("bad stream parameter");
1073 }
1074 }
1075  
1076 #
1077 # scan through the streams, skipping ones we don't analyze
1078 #
1079  
1080 1 foreach my $s ( sort( keys( %{ $self->{FILEHEADER}->{STREAM} } ) ) ) {
1081 2 ▶ if ( !defined($stream) || exists( $stream->{$s} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $stream or exists $stream->{$s}) 2 0 2
Condition33%1/3
not defined $stream or exists $stream->{$s}
l!l&&r!l&&!r
200
MC/DC0%0/2
not defined $stream or exists $stream->{$s}
not defined $stream exists $stream->{$s}
Truth table33%1/3
not(A) or B
A= not defined $streamB= exists $stream->{$s}
ABresult
1X1
011
000
1082 next
1083 2 ▶ unless exists $self->{FILEHEADER}->{STREAM}->{$s}->{ANALYSIS};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"FILEHEADER"}{"STREAM"}{$s}{"ANALYSIS"} 1 1 2
1084  
1085 # if multiple analyses are connected, do them in sequence
1086  
1087 1 foreach
1088 1 my $a ( @{ $self->{FILEHEADER}->{STREAM}->{$s}->{ANALYSIS} } )
1089 {
1090 1 $event = $a->Analyze( $event, $opts );
1091 1 ▶ if ( !defined($event) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $event) 0 1 1
1092 0 carp( "Stream $s analysis " . ref($a) . " failed" );
1093 0 return undef;
1094 }
1095 }
1096 }
1097 }
1098  
1099 1 return $event;
1100 }
1101  
1102 2 1; # End of Lab::Data::Analysis
1103  
1104 __END__
1105  
1106 =pod
1107  
1108 =encoding UTF-8
1109  
1110 =head1 NAME
1111  
1112 Lab::Data::Analysis - Analyze data from 'Trace' files
1113  
1114 =head1 VERSION
1115  
1116 version 3.881
1117  
1118 =head1 SYNOPSIS
1119  
1120 use Lab::Data::Analysis;
1121  
1122 my $t = Lab::Data::Analysis->new();
1123  
1124 $t->open($tracefile);
1125  
1126 RANDOM ACCESS:
1127  
1128 $t->MakeIndex();
1129
1130 $t->PrintIndex();
1131  
1132 my $fhdr = $t->ReadFileHeader();
1133  
1134 my $rhdr = $t->ReadRunHeader(run=>3);
1135  
1136 my $ev = $t->ReadEvent(run=>3, event=>77);
1137  
1138
1139 ... do analysis...
1140  
1141  
1142  
1143 SEQUENTIAL:
1144  
1145 my $fhdr = $t->ReadFileHeader();
1146  
1147 while (defined($rhdr = $t->ReadRunHeader()) {
1148
1149 print "Run: ",$rhdr->{RUN},"\n";
1150  
1151 while (defined($ev = $t->ReadEvent()) {
1152
1153 print "Event: ", $ev->{EVENT}, "\n";
1154  
1155 do analysis...
1156 }
1157 }
1158  
1159  
1160 Note that "random access" and "sequential" can be mixed,
1161 if you keep track of the file position.
1162  
1163 =head1 SUBROUTINES/METHODS
1164  
1165 =head2 new
1166  
1167 my $t = Lab::Data::Analysis->new(); # do 'open' later
1168  
1169 my $t = Lab::Data::Analysis->new($tracefile);
1170  
1171 my $t = Lab::Data::Analysis->new( file => $tracefile,
1172 ...options );
1173  
1174 =head2 open
1175  
1176 $t->open($file);
1177  
1178 $t->open(file=>$file, ...);
1179  
1180 Open a trace file for reading.
1181  
1182 =head2 rewind
1183  
1184 $t->rewind();
1185  
1186 Position to beginning of file for sequential access.
1187  
1188 Not sure that this is really needed: ReadFileHeader() automatically
1189 goes to the beginning of the file; ReadRunHeader(run=>firstrun) should
1190 read the header of the first run in the file, and leave the file
1191 positioned to start reading events.
1192  
1193 =head2 MakeIndex
1194  
1195 $t->MakeIndex();
1196  
1197 Compile an index of Runs/Events in a tracefile, for later use.
1198  
1199 Be warned: this may take some time for large files.
1200  
1201 =head2 PrintIndex
1202  
1203 $t->PrintIndex();
1204  
1205 Print an index of the tracefile, showing locations of runs/events, etc.
1206  
1207 =head2 ReadEvent
1208  
1209 my $event = $t->ReadEvent();
1210  
1211 my $event = $t->ReadEvent($stream);
1212  
1213 my $event = $t->ReadEvent([$stream1[, $stream2...]]);
1214  
1215 my $event = $t->ReadEvent(stream=>$stream);
1216  
1217 my $event = $t->ReadEvent(stream=>[$stream1[,$stream2...]]);
1218  
1219 Also can use a no_global=>1 option to exclude the 'global' (stream=0) stream,
1220 which just has comments. Adding run=>$run, event=>$event parameters causes
1221 FindEvent(run=>..., event=>...) to be called before reading the event.
1222  
1223 Read an event, starting at the current file position. This may
1224 involve skipping over (and ignoring) lines until reaching the next EVENT
1225 line. The event is returned in a hash structure, containing the
1226 raw data in all data streams for the event, up to the following EVENT
1227 marker, the "STOP RUN" marker, or the end of the file.
1228  
1229 Returns 'undef' if no more events remain in the file.
1230  
1231 Data streams can be selected by passing $stream parameter,
1232 and multiple streams by passing reference to an array.
1233  
1234 =head2 ReadFileHeader
1235  
1236 my $hdr = $t->ReadFileHeader([$shift]);
1237  
1238 my $hdr = $t->ReadFileHeader(shift=>$shift);
1239  
1240 Read the header of the data file (before the start of the
1241 first run), and store in a hashref. If '$shift' is true
1242 (=1,'yes', 'true') then leave the file positioned after
1243 the file header. The 'shift' parameter is usually not
1244 needed, because ReadRunHeader will just read from the
1245 start of the file to the first run.
1246  
1247 If 'shift' is not specified, then the file position is
1248 restored to where it was prior to the ReadFileHeader
1249 call, which can be useful if the file header is
1250 read later in the analysis.
1251  
1252 =head2 ReadRunHeader
1253  
1254 my $rhdr = $t->ReadRunHeader();
1255  
1256 my $rhdr = $t->ReadRunHeader($run);
1257  
1258 my $rhdr = $t->ReadRunHeader(run=>$run);
1259  
1260 Reads the header information between the start of run and the first
1261 event. If the run number is not given, reads from the current file
1262 position until the run is found. Returns undef if the file is not
1263 found.
1264  
1265 Returns a hashref with the information, and leaves the file
1266 positioned at the first event of the run.
1267  
1268 =head2 FindEvent
1269  
1270 $t->FindEvent($run,$event);
1271  
1272 $t->FindEvent(run=>$run, event=>$event);
1273  
1274 Find the specified event in the specified run (if run=undef or <=0, then
1275 use current run). Returns undef if the event is not found, otherwise
1276 returns the file position and leaves the file positioned so that ReadEvent
1277 will read the specified event.
1278  
1279 If event is undefined, defaults to the 'next event'; for files that
1280 have been indexed event=-1 returns the LAST event (-2 next to last, etc).
1281 Without an index event < 0 is treated as event=0.
1282  
1283 Note that this routine is MUCH more efficient if an index is created.
1284  
1285 =head2 PrintDefaultAnalyzer
1286  
1287 $t->PrintDefaultAnalyzer([$stream, $stream,...]);
1288  
1289 $t->PrintDefaultAnalyzer(stream=>[$stream1,$stream2,...]);
1290  
1291 Print the 'default' analyzer modules for the selected streams
1292 (default = 'all streams'). If the file header has not yet been
1293 read, this routine reads the file header to get the setup information
1294 about the data streams.
1295  
1296 =head2 ConnectAnalyzer
1297  
1298 $t->ConnectAnalyzer([[$stream],$module]);
1299  
1300 $t->ConnectAnalyzer(stream=>$stream, module=>$module);
1301  
1302 Connect an analysis module to a data stream. If the stream
1303 is unspecified, try to connect to all data streams. If
1304 the module is unspecified, try to use a 'default' module
1305 for the stream. Note that connecting multiple analysis
1306 modules to a stream results in the module being called
1307 in sequence, using the result from the previous
1308 analysis module.
1309  
1310 Default modules are in Lab::Data::Analysis:: ...
1311  
1312 =head2 Analyze
1313  
1314 my $ev = $t->Analyze($ev[,$options,[,$stream1,$stream2,...]);
1315  
1316 my $ev = $t->Analyze(event=>$ev[, stream=>$stream1][,analyzeroptions=>..]);
1317  
1318 my $ev = $t->Analyze(event=>$ev[, stream=>[$stream1,$stream2,...]
1319 [, analyzeroptions=>]);
1320  
1321 runs the analysis chain on the given event, for the given streams
1322 (default: all streams). The event is returned with analysis
1323 data added to the hashref. Options for the analyzer (in the
1324 key=>value form) can be passed if the hash calling form is used.
1325  
1326 =head1 COPYRIGHT AND LICENSE
1327  
1328 This software is copyright (c) 2023 by the Lab::Measurement team; in detail:
1329  
1330 Copyright 2016 Charles Lane
1331 2017 Andreas K. Huettel
1332 2020 Andreas K. Huettel
1333  
1334  
1335 This is free software; you can redistribute it and/or modify it under
1336 the same terms as the Perl 5 programming language system itself.
1337  
1338 =cut
« Instrument/WR640.pm ↑ Summary Bus/VICP.pm »