- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/magic_destreak_cleanup.pl (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippScripts/scripts/magic_destreak_cleanup.pl
r25837 r27838 8 8 use Sys::Hostname; 9 9 my $host = hostname(); 10 my $date = `date`; 10 11 print "\n\n"; 11 print "Starting script $0 on $host \n\n";12 print "Starting script $0 on $host at $date\n\n"; 12 13 13 14 use vars qw( $VERSION ); … … 30 31 my $missing_tools; 31 32 my $magicdstool = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1); 33 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 32 34 if ($missing_tools) { 33 35 warn("Can't find required tools."); … … 61 63 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $PS_EXIT_SYS_ERROR ) if $logfile; 62 64 63 if (0) {64 my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' );65 &my_die("cannot find NEB_SERVER in site configuration", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if !$nebulousServer;66 67 my $nebulous = eval { Nebulous::Client->new( proxy => $nebulousServer ); };68 if ($@ or not defined $nebulous) {69 &my_die ("Unable to create a Nebulous::Client object with proxy $nebulousServer", $magic_ds_id, $PS_EXIT_CONFIG_ERROR);70 }71 }72 65 73 66 $dbname = metadataLookupStr( $ipprc->{_siteConfig}, 'DBNAME' ) if !$dbname; … … 86 79 my $dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n"; 87 80 88 my $q1 = "SELECT magicDSRun.*, camera, camProcessedExp.path_base AS cam_path_base, magicRun.inverse"89 . " FROM magicDSRun JOIN magicRun USING(magic_id) JOIN rawExp USING(exp_id) LEFT JOIN camProcessedExp USING(cam_id) "81 my $q1 = "SELECT magicDSRun.*, camera, camProcessedExp.path_base AS cam_path_base, camRun.reduction AS cam_reduction, magicRun.inverse" 82 . " FROM magicDSRun JOIN magicRun USING(magic_id) JOIN rawExp USING(exp_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN camRun USING(cam_id)" 90 83 . " WHERE magic_ds_id = $magic_ds_id"; 91 84 my $q2 = "SELECT * from magicDSFile where magic_ds_id = $magic_ds_id"; 92 93 # my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files94 85 95 86 my $stmt1 = $dbh->prepare($q1); … … 103 94 my $stage_id = $run->{stage_id}; 104 95 my $cam_path_base = $run->{cam_path_base}; 96 my $cam_reduction = $run->{cam_reduction}; 97 $cam_reduction = 'DEFAULT' if !$cam_reduction or ($cam_reduction eq 'NULL'); 105 98 my $inverse = $run->{inverse}; 99 100 101 &my_die("cleanup not supported for camera stage", $magic_ds_id, $PS_EXIT_PROG_ERROR) if $stage eq "camera"; 106 102 107 103 … … 109 105 &my_die("clean not allowed for raw stage, use goto_restore", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $stage eq "raw"; 110 106 107 my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use 108 &my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro; 109 111 110 112 111 my $stmt2 = $dbh->prepare($q2); … … 114 113 115 114 my $num_components = 0; 115 my @components; 116 # save the data, so we can disconnect from the database 117 # deleting can take awhile 116 118 while (my $comp = $stmt2->fetchrow_hashref()) { 119 push @components, $comp; 117 120 $num_components++; 118 121 } 122 123 $stmt2->finish(); 124 $dbh->disconnect() or warn $dbh->errstr; 125 126 # We no longer clean up the camera stage mask files, but the code was left in place in case 127 # we change our minds. 128 my $cleanup_cam_mask = 0; 129 130 my $dynamicMasks; # Use dynamic masks? 131 foreach my $comp (@components) { 119 132 my $component = $comp->{component}; 120 133 my $backup_path_base = $comp->{backup_path_base}; … … 124 137 125 138 if ($stage eq "chip") { 126 # we use the mask output from the camera stage for input and replace 127 # the output of the chip stage with that mask as well. 128 my $cammask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component); 139 # Check to see if we're using dynamic masks 140 if ($cleanup_cam_mask && !defined $dynamicMasks) { 141 # Get the PSASTRO recipe 142 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 143 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 144 run(command => $command, verbose => $verbose); 145 unless ($success) { 146 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 147 &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component, 148 $PS_EXIT_CONFIG_ERROR); 149 } 150 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 151 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 152 &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, 153 $PS_EXIT_CONFIG_ERROR); 154 155 $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK'); 156 } 129 157 130 158 if ($backup_path_base) { 131 159 $bimage = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $component); 132 $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component); 160 161 if ($dynamicMasks) { 162 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component); 163 # This is kludgey but correct 164 $bmask = dirname($backup_path_base) . "/SR_" . basename($mask); 165 $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component); 166 } else { 167 $bmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component); 168 } 133 169 $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $component); 134 # This is kludgey but correct135 136 my $prefix;137 if ($backup_path_base =~ /\.SR/) {138 $prefix = "";139 } else {140 $prefix = "SR_";141 }142 143 $bmask = dirname($backup_path_base) . "/" . $prefix . basename($cammask);144 170 } 145 171 if ($recovery_path_base) { 146 172 $rimage = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $component); 147 $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component); 173 174 if ($dynamicMasks) { 175 my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component); 176 # This is kludgey but correct 177 $rmask = dirname($recovery_path_base) . "/" . basename($mask); 178 $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component); 179 } else { 180 $rmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component); 181 } 148 182 $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $component); 149 # This is kludgey but correct150 $rmask = dirname($recovery_path_base) . "/" . basename($cammask);151 183 } 152 184 } elsif ($stage eq "camera") { … … 160 192 $bweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $backup_path_base); 161 193 $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base); 162 } 194 } 163 195 if ($recovery_path_base) { 164 196 $rimage = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base); … … 166 198 $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base); 167 199 $rsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $recovery_path_base); 168 } 200 } 169 201 } elsif ($stage eq "diff") { 170 202 my $name = "PPSUB.OUTPUT"; … … 183 215 } 184 216 185 delete_files($rimage, $rmask, $rweight, $rsources, $rastrom, $bimage, $bmask, $bweight, $bsources, $bastrom );217 delete_files($rimage, $rmask, $rweight, $rsources, $rastrom, $bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask); 186 218 187 219 if ($stage eq "diff" and $inverse) { … … 199 231 $rsources = $ipprc->filename("$name.SOURCES", $recovery_path_base); 200 232 } 201 delete_files($rimage, $rmask, $rweight, $rsources, undef, $bimage, $bmask, $bweight, $bsources, undef); 233 # undef is not necessary, it's just to keep the lists in the same order. 234 delete_files($rimage, $rmask, $rweight, $rsources, undef, $bimage, $bmask, $bweight, $bsources); 202 235 } 203 236 } 237 238 $dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n"; 204 239 205 240 if (!$no_update and ($num_components > 0)) { … … 211 246 if (!$no_update) { 212 247 my $result = $dbh->do("UPDATE magicDSRun SET state = 'cleaned' WHERE magic_ds_id = ?", undef, $magic_ds_id); 213 my_die("attempt to update magicDSRun failed", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR) if $result eq "0E0";248 my_die("attempt to update magicDSRun.state failed", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR) if $result eq "0E0"; 214 249 } else { 215 250 print STDERR "skipping update of magicDSRun\n"; … … 225 260 if (!$no_update) { 226 261 print STDERR "deleting $file\n" if $verbose; 227 $ipprc->file_delete($file ) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);262 $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR); 228 263 } else { 229 264 print STDERR "skipping delete $file\n"; … … 246 281 $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code; 247 282 248 my $command = "$magicdstool -updaterun - fault $exit_code";283 my $command = "$magicdstool -updaterun -set_state failed_cleanup"; 249 284 $command .= " -magic_ds_id $magic_ds_id"; 250 285 $command .= " -dbname $dbname" if defined $dbname;
Note:
See TracChangeset
for help on using the changeset viewer.
