Changeset 13979 for trunk/ippScripts/scripts/ipp_darkstats.pl
- Timestamp:
- Jun 26, 2007, 7:34:41 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/ipp_darkstats.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_darkstats.pl
r13848 r13979 1 1 #!/usr/bin/env perl 2 2 3 use warnings;4 use strict;3 # use warnings; 4 # use strict; 5 5 use Carp; 6 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 7 use Pod::Usage qw( pod2usage ); 8 use IPC::Cmd 0.36 qw( can_run run ); 6 9 7 # USAGE: ipp_darkstats.pl --dbname (name) --det_id (id) 10 use PS::IPP::Metadata::List qw( parse_md_list ); 11 12 use PS::IPP::Config qw($PS_EXIT_SUCCESS 13 $PS_EXIT_UNKNOWN_ERROR 14 $PS_EXIT_SYS_ERROR 15 $PS_EXIT_CONFIG_ERROR 16 $PS_EXIT_PROG_ERROR 17 $PS_EXIT_DATA_ERROR 18 $PS_EXIT_TIMEOUT_ERROR 19 caturi 20 ); # tools to parse the IPP configuration information 21 22 my $ipprc = PS::IPP::Config->new(); # IPP configuration 23 24 my ($dbname, $det_id, $camera); 25 26 GetOptions('dbname=s' => \$dbname, 27 'det_id=s' => \$det_id, 28 'camera|c=s' => \$camera, 29 ) or pod2usage( 2 ); 30 31 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 32 33 pod2usage( 34 -msg => "USAGE: ipp_darkstats.pl --dbname (name) --det_id (id) --camera (name)", 35 -exitval => 3, 36 ) unless defined $dbname and defined $det_id and defined $camera; 37 38 $ipprc->define_camera($camera); 8 39 9 40 ### Get list of dark imfile results 10 41 11 42 # define the dettool command 12 my $command = " $dettool -processedimfile -select_state stop"; # Command to run43 my $command = "dettool -processedimfile -select_state stop"; # Command to run 13 44 $command .= " -det_id $det_id"; 14 45 $command .= " -dbname $dbname" if defined $dbname; … … 16 47 # run the dettool command and catch the output 17 48 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 18 run(command => $command, verbose => 1);49 run(command => $command, verbose => 0); 19 50 unless ($success) { 20 51 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 21 &my_die("Unable to perform dettool: $error_code", $ det_id, $error_code);52 &my_die("Unable to perform dettool: $error_code", $error_code); 22 53 } 23 54 24 55 # parse the output into a list 56 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 25 57 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 26 &my_die("Unable to parse metadata config doc", $ det_id, $PS_EXIT_PROG_ERROR);27 my $ files= parse_md_list($metadata) or28 &my_die("Unable to parse metadata list", $ cam_id, $PS_EXIT_PROG_ERROR);58 &my_die("Unable to parse metadata config doc", $PS_EXIT_PROG_ERROR); 59 my $list = parse_md_list($metadata) or 60 &my_die("Unable to parse metadata list", $PS_EXIT_PROG_ERROR); 29 61 30 # XXX finish this off: 62 my @bg_data; 63 my @bg_stdev_data; 64 my @bg_name; 65 my @bg_exptime; 66 67 # we now have a list of imfiles; we need to extract the background for each cell 68 # from the stats files for each imfile 69 foreach my $item (@$list) { 70 my $path_base = $item->{path_base}; 71 my $class_id = $item->{class_id}; 72 my $exp_time = $item->{exp_time}; 73 74 my $rootName = $ipprc->file_resolve ($path_base); 75 my $statsName = "$rootName.$class_id.stats"; 76 77 # print STDERR "rootName: $rootName\n"; 78 # print STDERR "statsName: $statsName\n"; 79 80 my $statsFile; 81 open $statsFile, $statsName; 82 my @contents = <$statsFile>; 83 close ($statsFile); 84 85 # print STDERR "contents: @contents\n"; 86 87 my $parser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 88 my $statsList = $parser->parse(join "", @contents) or &my_die("Unable to parse metadata for imfile stats", $PS_EXIT_SYS_ERROR); 89 90 &parse_stats_table ($exp_time, $class_id, $statsList); 91 } 92 93 print STDERR "dumping stats\n"; 94 95 for (my $i = 0; $i < @bg_data; $i++) { 96 $name1 = "$bg_name[$i].bg"; 97 $name2 = "$bg_name[$i].exp"; 98 push @{$name1}, $bg_data[$i]; 99 push @{$name2}, $bg_exptime[$i]; 100 } 101 102 exit 0; 103 104 sub parse_stats_table 105 { 106 my ($exp_time, $tag, $md) = @_; 107 108 # descend through the fpa 109 foreach my $entry (@$md) { 110 # print STDERR "name: $entry->{name}, class: $entry->{class}\n"; 111 # recurse on nested metadata 112 if ($entry->{class} eq 'metadata') { 113 my $newtag = $tag . ":" . $entry->{name}; 114 &parse_stats_table ($exp_time, $newtag, $entry->{value}); 115 } 116 117 if ($entry->{name} =~ /^(SAMPLE|ROBUST|FITTED|CLIPPED)_/) { 118 # It's a statistic of some sort 119 if ($entry->{name} =~ /_STDEV$/) { 120 push @bg_stdev_data, $entry->{value}; 121 } else { 122 push @bg_data, $entry->{value}; 123 } 124 push @bg_name, $tag; 125 push @bg_exptime, $exp_time; 126 next; 127 } 128 } 129 return 1; 130 } 131 132 sub my_die 133 { 134 my $msg = shift; # Warning message on die 135 my $exit_code = shift; # Exit code to add 136 137 carp($msg); 138 exit $exit_code; 139 } 31 140 32 141 # - get the exp_time as well from dettool
Note:
See TracChangeset
for help on using the changeset viewer.
