From: Jan Michel Date: Fri, 2 Aug 2013 16:07:18 +0000 (+0200) Subject: performance optimization on unpack_hld.pl X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=ebc9db1a8f5ae2f8b5add754d55b3f1704d4ec0c;p=mvdsensorcontrol.git performance optimization on unpack_hld.pl --- diff --git a/tools/preview/unpack_hld.pl b/tools/preview/unpack_hld.pl index e164d5f..cd1e2e5 100755 --- a/tools/preview/unpack_hld.pl +++ b/tools/preview/unpack_hld.pl @@ -89,7 +89,7 @@ while(1){ @subEvtHeader_list = (); - my $decoding = &getSubEvtHeader($fh,$subEvtHeader_aref); + my $endian = &getSubEvtHeader($fh,$subEvtHeader_aref); &printSubEvtHeader($subEvtHeader_aref) if($opt_verb); my $subEvtSize = $subEvtHeader_aref->[0]; @@ -101,7 +101,7 @@ while(1){ next if($subEvtSize == 16); @data_list = (); - &getSubEvtData($fh, $data_aref, $subEvtSize, $decoding); + &getSubEvtData($fh, $data_aref, $subEvtSize, $endian); &printData($data_aref) if($opt_verb); my $paddedSize = &padding($fh, $subEvtSize); @@ -185,7 +185,7 @@ sub getEvtHeader() my $header; read($fh, $header, 4); - &checkEndOfFile($fh, $header); +# &checkEndOfFile($fh, $header); push(@tmp_list, $header); } @@ -229,15 +229,15 @@ sub getSubEvtHeader() my $header; read($fh, $header, 4); - &checkEndOfFile($fh, $header); +# &checkEndOfFile($fh, $header); push(@tmp_list, $header); } my $decoding = unpack("V*", $tmp_list[1]); - + my $endian = &getEndianess($decoding); if($opt_debug){ - if(&getEndianess($decoding)){ + if($endian){ printf("\n SubEvent Decoding: %08x Byte Order: Little Endian\n", $decoding); } else{ @@ -248,7 +248,7 @@ sub getSubEvtHeader() foreach my $tmp (@tmp_list){ my $word; - if(&getEndianess($decoding)){ + if($endian){ $word = unpack("V*", $tmp); # Small Endian } else{ @@ -258,7 +258,7 @@ sub getSubEvtHeader() push(@$data_aref, $word); } - return &getEndianess($decoding); + return $endian; } sub getEndianess() @@ -281,31 +281,25 @@ sub getEndianess() return $retVal; } -sub getSubEvtData() -{ - my ($fh, $data_aref, $size, $decoding) = @_; - - #- Subtract subevent header size and devide by word size - my $nrOfWords = ($size - 16)/4; - - foreach my $i (1..$nrOfWords){ - - my $tmp; - read($fh, $tmp, 4); - &checkEndOfFile($fh, $tmp); +sub getSubEvtData() { + my ($fh, $data_aref, $size, $endian) = @_; - my $word; + #- Subtract subevent header size and devide by word size + my $nrOfWords = ($size - 16)/4; - if(&getEndianess($decoding)){ - $word = unpack("V*", $tmp); # Little Endian - } - else{ - $word = unpack("N*", $tmp); # Big Endian - } - - push(@$data_aref, $word); + my $tmp; + my $word; + foreach my $i (1..$nrOfWords){ + read($fh, $tmp, 4); + if($endian){ + $word = unpack("V*", $tmp); # Little Endian + } + else{ + $word = unpack("N*", $tmp); # Big Endian + } + push(@$data_aref, $word); } -} + } sub padding() { @@ -317,18 +311,6 @@ sub padding() unless( ($size%8) == 0){ my $tmp; read($fh, $tmp, 4); - - my $word; - $word = unpack("V*", $tmp); # Little Endian - - unless($word == 0){ - #- Padding word is not zero - - printf("\n Padding word is not zero: %08x! \n", $word) if($opt_debug); - #$fh->close(); - #exit(0); - } - $retVal = 4; # Bytes } @@ -396,8 +378,13 @@ sub analyzeData() { my $SensorError = $data->[$pos++]; my $SensorDebug = $data->[$pos++]; my $SensorTime = sprintf("%08x%08x",$data->[$pos+1],$data->[$pos]); + + $PMap->{$SensorId}->[575]->[1151] = 0 unless defined $PMap->{$SensorId}->[575]->[1151]; + my $matrix = $PMap->{$SensorId}; + $pos+= 2; + printf("ID\t%8x\tStatus\t%08x\tError\t%08x\tDebug\t%08x\tTime\t%s\n", $SensorId, $SensorStatus, $SensorError, $SensorDebug, $SensorTime) if $opt_frameinfo; @@ -430,10 +417,10 @@ sub analyzeData() { $SensorDummy, $SensorNumber, $SensorLength) if $opt_frameinfo; my $FrameEndPos = $pos + $SensorLength; - my ($i, $d, $line, $column, $pixels, $statecnt, $ovf) = (0,0,0,0,0,0,0); + my ($i, $d, $line, $column, $pixels, $statecnt, $ovf) = (1,0,0,0,0,0,0); while(1) { #Disentangle 16 Bit words - if($i++%2) {$d = $data->[$pos++] & 0xffff;} + if($i=1-$i) {$d = $data->[$pos++] & 0xffff;} else {$d = ($data->[$pos] >> 16) & 0xffff;} #Is new line? @@ -447,10 +434,10 @@ sub analyzeData() { $column = ($d >> 2) & 0x7FF; printf("\t$line, $column x $pixels\n") if $opt_frameinfo; - $PMap->{$SensorId}->[$line]->[$column]++; - $PMap->{$SensorId}->[$line]->[$column+1]++ if $pixels > 1; - $PMap->{$SensorId}->[$line]->[$column+2]++ if $pixels > 2; - $PMap->{$SensorId}->[$line]->[$column+3]++ if $pixels > 3; + $matrix->[$line]->[$column]++; + $matrix->[$line]->[$column+1]++ if $pixels > 1; + $matrix->[$line]->[$column+2]++ if $pixels > 2; + $matrix->[$line]->[$column+3]++ if $pixels > 3; } last if $pos >= $FrameEndPos; @@ -492,19 +479,18 @@ sub WriteResults { print $fh "set output './image_recalibrated_$s.png';\n"; print $fh "plot '-' matrix with image\n"; + my @matrix; for(my $y = 0; $y < 576; $y++) { - my $l = ""; - for(my $x = 0; $x < 1152; $x++) { - if (defined $PMap->{$id}->[$y]->[$x]) { - $l .= $PMap->{$id}->[$y]->[$x]." " ; - } - else { - $l .= "0 "; - } - } + #Define lengths of all arrays + $PMap->{$id}->[$y]->[1151] = 0 unless defined $PMap->{$id}->[$y]->[1151]; + #Fill undef with 0 + @matrix = map {defined $_ ? $_ : 0 } @{$PMap->{$id}->[$y]}; + #Join lines + my $l = join(" ",@matrix); print $fh $l."\n"; } + print $fh "e\nexit\n"; $fh->close(); }