Changeset 19561 for trunk/ippScripts/scripts/ipp_cleanup.pl
- Timestamp:
- Sep 15, 2008, 2:24:27 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/ipp_cleanup.pl (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_cleanup.pl
r19397 r19561 50 50 } 51 51 52 my %stages = ( chip => 1, camera => 1, fake => 1, warp => 1, stack => 1, diff => 1); 53 unless ($stages{$stage}) { 54 die "unknown stage $stage for ipp_cleanup.pl\n"; 55 } 56 52 57 $ipprc->define_camera($camera); 53 58 54 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 55 56 my $fault = 0;57 60 58 61 # choice of files to delete depends on the stage 59 62 if ($stage eq "chip") { 60 63 64 die "--stage_id required for stage chip\n" if !$stage_id; 61 65 ### select the imfiles for this entry 62 66 … … 85 89 my $class_id = $imfile->{class_id}; 86 90 my $path_base = $imfile->{path_base}; 87 88 # array of actual filenames to delete 89 my @files = (); 90 91 # delete the temporary image datafiles 92 addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id); 93 addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id); 94 addFilename (\@files, "PPIMAGE.OUTPUT.WEIGHT", $path_base, $class_id); 95 addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id); 96 addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id); 97 addFilename (\@files, "PPIMAGE.CHIP.WEIGHT", $path_base, $class_id); 98 if ($mode eq "goto_purged") { 99 # additional files to remove for 'purge' mode 100 addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base, $class_id); 101 addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base, $class_id); 102 addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id); 103 addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id); 104 addFilename (\@files, "PPIMAGE.JPEG1", $path_base, $class_id); 105 addFilename (\@files, "PPIMAGE.JPEG", $path_base, $class_id); 106 addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id); 107 } 91 my $status = 1; 92 93 # don't clean up unless the data needed to update is available 94 if ($mode eq "goto_cleaned") { 95 my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id); 96 97 if (!$config_file or ! -e $config_file) { 98 print STDERR "skipping cleanup for chipRun $stage_id $class_id " 99 . " because config file is missing\n"; 100 $status = 0; 101 } 102 } 103 104 if ($status) { 105 # array of actual filenames to delete 106 my @files = (); 107 108 # delete the temporary image datafiles 109 addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id); 110 addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id); 111 addFilename (\@files, "PPIMAGE.OUTPUT.WEIGHT", $path_base, $class_id); 112 addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id); 113 addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id); 114 addFilename (\@files, "PPIMAGE.CHIP.WEIGHT", $path_base, $class_id); 115 if ($mode eq "goto_purged") { 116 # additional files to remove for 'purge' mode 117 addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base, $class_id); 118 addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base, $class_id); 119 addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id); 120 addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id); 121 addFilename (\@files, "PPIMAGE.JPEG1", $path_base, $class_id); 122 addFilename (\@files, "PPIMAGE.JPEG", $path_base, $class_id); 123 addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id); 124 addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id); 125 } 108 126 109 # actual command to delete the files 110 my $status = &delete_files (\@files); 127 # actual command to delete the files 128 $status = &delete_files (\@files); 129 } 111 130 112 131 if ($status) { … … 119 138 $command .= " -dbname $dbname" if defined $dbname; 120 139 121 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 140 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 141 run(command => $command, verbose => $verbose); 122 142 unless ($success) { 123 143 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); … … 125 145 } 126 146 } else { 127 my $command = "$chiptool -update imfile -chip_id $stage_id -class_id $class_id -code 1";147 my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1"; 128 148 $command .= " -dbname $dbname" if defined $dbname; 129 149 130 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 150 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 151 run(command => $command, verbose => $verbose); 131 152 unless ($success) { 132 153 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 133 154 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 134 155 } 135 $fault = 1;136 156 } 137 157 } 138 158 139 if (0) { 140 # This block is not necessary 141 # chiptool -tocleanedimfile and -topurgedimfile automatically update chipRun when the 142 # last image gets set to purged or cleaned 143 144 if (! $fault) { 145 # set the state of the chipRun entry to "cleaned" or "purged" as needed 146 my $command = "$chiptool -updaterun -chip_id $stage_id"; 147 if ($mode eq "goto_purged") { 148 $command .= " -state purged"; 149 } else { 150 $command .= " -state cleaned"; 151 } 152 $command .= " -dbname $dbname" if defined $dbname; 153 154 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 155 unless ($success) { 156 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 157 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code); 158 } 159 } 160 } 161 exit 0; 162 } 163 164 # choice of files to delete depends on the stage 165 if ($stage eq "camera") { 159 } elsif ($stage eq "camera") { 160 die "--stage_id required for stage camera\n" if !$stage_id; 166 161 # this stage uses 'camtool' 167 162 my $camtool = can_run('camtool') or die "Can't find camtool"; … … 169 164 # Get list of component imfiles 170 165 # XXX may need a different my_die for each stage 171 my $ imfiles; # Array of component files166 my $exps; # Array of component files 172 167 my $command = "$camtool -pendingcleanupexp -cam_id $stage_id"; # Command to run 173 168 $command .= " -dbname $dbname" if defined $dbname; … … 175 170 unless ($success) { 176 171 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 177 &my_die("Unable to perform camtool: $error_code", "cam ", $stage_id, $error_code);172 &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code); 178 173 } 179 174 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 180 &my_die("Unable to parse metadata config doc", "cam", $stage_id, $PS_EXIT_PROG_ERROR); 181 175 &my_die("Unable to parse metadata config doc", "camera", $stage_id, $PS_EXIT_PROG_ERROR); 176 177 $exps = parse_md_list($metadata) or 178 &my_die("Unable to parse metadata list", "camera", $stage_id, $PS_EXIT_PROG_ERROR); 179 180 my $n_exps = @$exps; 181 &my_die("unexpected number of exposures $n_exps", "camera", $stage_id, $PS_EXIT_PROG_ERROR) 182 if $n_exps != 1; 183 184 my $exp = $exps->[0]; 185 my $path_base = $exp->{path_base}; 186 187 my $status = 1; 188 # don't clean up unless the data needed to update is available 189 if ($mode eq "goto_cleaned") { 190 my $config_file = $ipprc->filename("PSASTRO.CONFIG", $path_base); 191 192 if (!$config_file or ! -e $config_file) { 193 print STDERR "skipping cleanup for camRun $stage_id because config file is missing\n"; 194 $status = 0; 195 } 196 } 197 if ($status) { 198 my @files = (); 199 # delete the temporary image datafiles 200 addFilename (\@files, "PSASTRO.OUTPUT", $path_base); 201 if ($mode eq "goto_purged") { 202 # additional files to remove for 'purge' mode 203 addFilename (\@files, "PPIMAGE.JPEG1", $path_base); 204 addFilename (\@files, "PPIMAGE.JPEG2", $path_base); 205 addFilename (\@files, "PSASTRO.STATS", $path_base); 206 } 207 # actual command to delete the files 208 $status = &delete_files (\@files); 209 } 210 211 if ($status) { 212 my $command = "$camtool -cam_id $stage_id -updaterun"; 213 if ($mode eq "goto_cleaned") { 214 $command .= " -state cleaned"; 215 } else { 216 $command .= " -state purged"; 217 } 218 $command .= " -dbname $dbname" if defined $dbname; 219 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 220 run(command => $command, verbose => $verbose); 221 unless ($success) { 222 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 223 &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code); 224 } 225 } else { 226 my $command = "$camtool -updateprocessedexp -cam_id $stage_id -code 1"; 227 $command .= " -dbname $dbname" if defined $dbname; 228 229 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 230 run(command => $command, verbose => $verbose); 231 unless ($success) { 232 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 233 &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code); 234 } 235 exit $PS_EXIT_UNKNOWN_ERROR; 236 } 182 237 exit 0; 183 } 184 238 } elsif ($stage eq "warp") { 239 die "--stage_id required for stage warp\n" if !$stage_id; 240 # this stage uses 'warptool' 241 my $warptool = can_run('warptool') or die "Can't find warptool"; 242 243 # Get list of component imfiles 244 # XXX may need a different my_die for each stage 245 my $skyfiles; # Array of component files 246 my $command = "$warptool -pendingcleanupskyfile -warp_id $stage_id"; # Command to run 247 $command .= " -dbname $dbname" if defined $dbname; 248 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 249 run(command => $command, verbose => $verbose); 250 unless ($success) { 251 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 252 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code); 253 } 254 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 255 &my_die("Unable to parse metadata config doc", "warp", $stage_id, $PS_EXIT_PROG_ERROR); 256 257 $skyfiles = parse_md_list($metadata) or 258 &my_die("Unable to parse metadata list", "warp", $stage_id, $PS_EXIT_PROG_ERROR); 259 260 my @files = (); 261 foreach my $skyfile (@$skyfiles) { 262 my $path_base = $skyfile->{path_base}; 263 my $skycell_id = $skyfile->{skycell_id}; 264 265 my $status = 1; 266 if ($mode eq "goto_cleaned") { 267 my $config_file = $ipprc->filename("PSWARP.CONFIG", $path_base, $skycell_id); 268 269 if (!$config_file or ! -e $config_file) { 270 print STDERR "skipping cleanup for warpRun $stage_id $skycell_id" . 271 " because config file is missing\n"; 272 $status = 0; 273 } 274 } 275 if ($status) { 276 # delete the temporary image datafiles 277 addFilename(\@files, "PSWARP.OUTPUT", $path_base, $skycell_id ); 278 addFilename(\@files, "PSWARP.OUTPUT.MASK", $path_base, $skycell_id); 279 addFilename(\@files, "PSWARP.OUTPUT.WEIGHT", $path_base, $skycell_id); 280 addFilename(\@files, "PSWARP.OUTPUT.SOURCES", $path_base, $skycell_id); 281 282 if ($mode eq "goto_purged") { 283 # additional files to remove for 'purge' mode 284 addFilename(\@files, "PSWARP.BIN1", $path_base, $skycell_id ); 285 addFilename(\@files, "PSWARP.BIN2", $path_base, $skycell_id ); 286 addFilename(\@files, "SKYCELL.STATS", $path_base, $skycell_id ); 287 # addFilename(\@files, "PSPHOT.PSF.SKY.SAVE", $path_base); 288 289 # XXX: do we want to delete these? 290 # addFilename(\@files, "TRACE.EXP", $path_base, $skycell_id); 291 # addFilename(\@files, "PSWARP.CONFIG", $path_base, $skycell_id); 292 } 293 # actual command to delete the files 294 $status = &delete_files (\@files); 295 } 296 297 if ($status) { 298 my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id"; 299 if ($mode eq "goto_purged") { 300 $command .= " -topurgedskyfile"; 301 } else { 302 $command .= " -tocleanedskyfile"; 303 } 304 $command .= " -dbname $dbname" if defined $dbname; 305 306 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 307 run(command => $command, verbose => $verbose); 308 unless ($success) { 309 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 310 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code); 311 } 312 } else { 313 # XXX: -updateskyfile mode does not exist, need to add it 314 my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1"; 315 $command .= " -dbname $dbname" if defined $dbname; 316 317 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 318 run(command => $command, verbose => $verbose); 319 unless ($success) { 320 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 321 &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code); 322 } 323 exit $PS_EXIT_UNKNOWN_ERROR; 324 } 325 } 326 exit 0; 327 } 328 329 # left TODO 185 330 # fake : faketool : -pendingcleanupimfile (loop over imfiles) 186 # warp : warptool : -pendingcleanupskyfile (loop over skyfiles)187 188 die "unknown stage for ipp_cleanup.pl\n"; 189 exit 1;331 # stack: stacktool : -pendingcleanupskyfile (loop over skyfiles) 332 # diff: difftool : -pendingcleanupskyfile 333 334 die "ipp_cleanup.pl -stage $stage not yet implemented\n"; 190 335 191 336 sub delete_files … … 196 341 foreach my $file (@$files) { 197 342 print STDERR "unlinking $file\n"; 343 # XXX: need to handle files in nebulous 198 344 unlink $file; 199 345 } … … 217 363 { 218 364 my $msg = shift; # Warning message on die 219 my $stage = shift; # Chiptool identifier220 my $stage_id = shift; # Chiptoolidentifier221 my $exit_code = shift; # Exit code to add222 # outputImage and outrootare globals365 my $stage = shift; # stage name 366 my $stage_id = shift; # identifier 367 my $exit_code = shift; # Exit code 368 # outputImage and path_base are globals 223 369 224 370 carp($msg);
Note:
See TracChangeset
for help on using the changeset viewer.
