Changeset 27865 for trunk/ippScripts/scripts/make_burntool_pcontrol.pl
- Timestamp:
- May 5, 2010, 3:42:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/make_burntool_pcontrol.pl
r27033 r27865 1 #!/usr/bin/ perl -w1 #!/usr/bin/env perl 2 2 # script to generate a pcontrol.pro file to run burntool on a set of data. 3 3 4 4 use DBI; 5 use warnings; 5 6 use DateTime; 6 7 use Getopt::Std; 8 use PS::IPP::Metadata::List qw( parse_md_list ); 9 use PS::IPP::Config 1.01 qw( :standard ); 10 use IPC::Cmd 0.36 qw( can_run run); 7 11 8 12 use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock'; … … 35 39 ) or die "Unable to connect to database $DBI::errstr\n"; 36 40 41 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 42 if ($missing_tools) { 43 die "Cannot find required tools."; 44 } 37 45 # Determine what the value of "BURNTOOL.STATE.GOOD" currently is: 38 46 $burntoolStateGood = 999; 39 open(LAZY," ppConfigDump -camera GPC1 -dump-camera - |") || die "Can't run ppConfigDump\n";47 open(LAZY,"$ppConfigDump -camera GPC1 -dump-camera - |") || die "Can't run ppConfigDump\n"; 40 48 while(<LAZY>) { 41 49 chomp; … … 46 54 } 47 55 close(LAZY); 48 #unless( $burntoolStateGood == 999) { 49 # print STDERR "GOOD == $burntoolStateGood\n"; 50 #} 51 52 53 # List of which obs_modes are "science" and which are something else. 54 %science = ('MD' => 1, '3PI' => 1, 'STS' => 1, 'CAL' => 1, 'M31' => 1, 'SS' => 1, 55 'ENGINEERING' => 0, 'NULL' => 0, 'Unknown' => 1, ' ' => 0); 56 57 # Read the nightly science config file and use that to determine which data is science 58 my $verbose = 0; 59 my $conf_cmd = "$ppConfigDump -dump-recipe NIGHTLY_SCIENCE -"; 60 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 61 run(command => $conf_cmd, verbose => $verbose); 62 unless ($success) { 63 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 64 &my_die("Unable to perform ppConfigDUmp: $error_code", $date, $PS_EXIT_SYS_ERROR); 65 } 66 67 my @target_list; 68 my %object_list; 69 my $comment_list; 70 71 my $mdcParser = PS::IPP::Metadata::Config->new; 72 my $metadata = $mdcParser->parse(join "", @$stdout_buf); 73 foreach my $entry (@{ $metadata }) { 74 if (${ $entry }{name} eq 'TARGETS') { 75 my @target_data = @{ ${ $entry }{value} }; 76 my $this_target = ''; 77 78 foreach my $tentry (@target_data) { 79 if (${ $tentry }{name} eq 'NAME') { 80 $this_target = ${ $tentry }{value}; 81 push @target_list, $this_target; 82 $obsmode_list{$this_target} = '.*'; 83 $object_list{$this_target} = '.*'; 84 $comment_list{$this_target} = '.*'; 85 } 86 elsif (${ $tentry }{name} eq 'OBSMODE') { 87 $obsmode_list{$this_target} = ${ $tentry }{value}; 88 $obsmode_list{$this_target} =~ s/%//; 89 } 90 elsif (${ $tentry }{name} eq 'OBJECT') { 91 $object_list{$this_target} = ${ $tentry }{value}; 92 $object_list{$this_target} =~ s/%//; 93 } 94 elsif (${ $tentry }{name} eq 'COMMENT') { 95 $comment_list{$this_target} = ${ $tentry }{value}; 96 $comment_list{$this_target} =~ s/%//; 97 } 98 } 99 } 100 } 56 101 if (exists($opt{P})) { 57 $science{Unknown} = 1; 102 push @target_list, 'PR'; 103 $obsmode_list{'PR'} = 'Unknown'; 104 $object_list{'PR'} = '.*'; 105 $comment_list{'PR'} = '.*'; 58 106 } 59 107 … … 119 167 120 168 # Find _ALL_ observations within the date range we care about 121 $sth = "SELECT exp_id,dateobs,pon_time,exp_type,obs_mode,comment FROM rawExp WHERE " .169 $sth = "SELECT exp_id,dateobs,pon_time,exp_type,obs_mode,comment,object FROM rawExp WHERE " . 122 170 "dateobs >= '${date_min}' AND dateobs <= '${date_max}' order by dateobs"; 123 171 … … 133 181 foreach $row_ref (@{ $data_ref }) { 134 182 135 ($exp_id,$dateobs,$pontime,$exp_type,$obs_mode,$comment ) = @{ $row_ref };183 ($exp_id,$dateobs,$pontime,$exp_type,$obs_mode,$comment,$object) = @{ $row_ref }; 136 184 # Fix nulls in the database 137 185 if (!defined($obs_mode)) { 138 186 $obs_mode = ' '; 139 187 } 188 if (!defined($object)) { 189 $object = ' '; 190 } 140 191 if (!defined($comment)) { 141 192 $comment = ' '; … … 144 195 ($date,$time) = split / /, $dateobs; 145 196 ($year,$month,$day) = split /-/, $date; 146 ($hour,$minute,$second) = split /:/, $time; 197 ($hour,$minute,$second) = split /:/, $time; # / # This stops emacs run-on syntax highlights. 147 198 148 199 $dt = DateTime->new( year => $year, month => $month, day => $day, … … 155 206 $et = $dt->epoch(); 156 207 157 158 if (!exists($science{$obs_mode})) { 159 $science{$obs_mode} = 0; 160 } 161 if ((($science{$obs_mode} == 1)&&($comment !~ /Daytime/))|| 162 (($science{$obs_mode} == 0)&&( 163 ($comment =~ /MD/)||($comment =~ /ThreePi/)|| 164 ($comment =~ /STS/i)||($comment =~ /M31/)||($comment =~ /Stellar Transit/)|| 165 ($comment =~ /CAL/i)||($comment =~ /SS/)||($comment =~ /SVS/)|| 166 ($comment =~ /Sweetspot/)||($comment =~ /virgo/i)||($comment =~ /kepler/)|| 167 ($comment =~ /sdss/)))) 168 { 208 if (is_science($exp_type,$obs_mode,$object,$comment)) { 169 209 if ($start_s[-1] == 0) { 170 210 $start_s[-1] = $et - 1800; … … 194 234 # Scan again and count how many exposures are between windows 195 235 foreach $row_ref (@{ $data_ref }) { 196 ($exp_id,$dateobs,$pontime,$exp_type,$obs_mode,$comment ) = @{ $row_ref };236 ($exp_id,$dateobs,$pontime,$exp_type,$obs_mode,$comment,$object) = @{ $row_ref }; 197 237 if (!defined($obs_mode)) { 198 238 $obs_mode = ' '; … … 204 244 ($date,$time) = split / /, $dateobs; 205 245 ($year,$month,$day) = split /-/, $date; 206 ($hour,$minute,$second) = split /:/, $time; 246 ($hour,$minute,$second) = split /:/, $time; # / # another emacs syntax highlight bug. 207 247 208 248 $dt = DateTime->new( year => $year, month => $month, day => $day, … … 215 255 $et = $dt->epoch(); 216 256 217 if (!exists($science{$obs_mode})) {218 die "No mode >>$obs_mode<<\n";219 }220 221 257 for ($i = 0; $i <= $#start_s; $i++) { 222 if (($et < $start_s[$i])&&( $science{$obs_mode}== 0)) {258 if (($et < $start_s[$i])&&(is_science($exp_type,$obs_mode,$object,$comment) == 0)) { 223 259 if ($i == 0) { 224 260 $skips[$i]++; … … 278 314 unless(exists($opt{b}) || ($N_ranges == 0)) { 279 315 print_epilogue(); 316 } 317 318 319 # Subroutine to use the configuration file data and the exposure data to determine whether or not something is "science" 320 sub is_science { 321 # if (is_science($exp_type,$obs_mode,$object,$comment)) { 322 my ($exp_type,$obs_mode,$object,$comment) = @_; 323 my $return_value = 0; 324 if ($exp_type eq 'OBJECT') { 325 foreach my $target (@target_list) { 326 if (($obs_mode =~ /$obsmode_list{$target}/)&& 327 ($object =~ /$object_list{$target}/)&& 328 ($comment =~ /$comment_list{$target}/)) { 329 $return_value = 1; 330 } 331 # print ">$return_value $exp_type $obs_mode $object $comment $target $obsmode_list{$target} $object_list{$target} $comment_list{$target}\n"; 332 if ($return_value) { 333 return($return_value); 334 } 335 } 336 } 337 return(0); 280 338 } 281 339
Note:
See TracChangeset
for help on using the changeset viewer.
