Changeset 34447 for trunk/pstamp/scripts/pstamp_finish.pl
- Timestamp:
- Sep 18, 2012, 3:52:27 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstamp_finish.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_finish.pl
r33670 r34447 107 107 my ($header, $rows) = read_request_file($req_file); 108 108 109 if (!$header or !$rows) { 110 # Since a request got queued, the request file must have been readable at some 111 # point 109 my $action = $header->{ACTION}; 110 111 if (!$header or (($action eq 'PROCESS') and !$rows)) { 112 # Since a request got queued, the request file must have been readable at some point 112 113 my_die("failed to read request file $req_file", $req_id, $PS_EXIT_CONFIG_ERROR); 113 114 } … … 126 127 } 127 128 128 # The results table definition file 129 my ($tdf, $table_def_name) = tempfile ("$outdir/tabledef.XXXX", UNLINK => !$save_temps); 130 131 # data for the header 132 print $tdf "$req_name|$req_id|\n"; 133 134 # get the list of jobs generated for this request 135 my @jobs; 136 { 137 my $command = "$pstamptool -listjob -req_id $req_id"; 138 $command .= " -dbname $dbname" if $dbname; 139 $command .= " -dbserver $dbserver" if $dbserver; 140 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 141 run(command => $command, verbose => $verbose); 142 unless ($success) { 143 die("Unable to perform $command error code: $error_code"); 144 } 145 my $output = join "", @$stdout_buf; 146 if (!$output) { 147 # This should not happen. A fake job should have been entered 148 my_die("Request $req_id produced no jobs", $req_id, $PS_EXIT_PROG_ERROR); 149 } else { 150 my $jobs = parse_md_fast($mdcParser, $output); 151 152 @jobs = @$jobs; 153 } 154 } 155 156 my $exp_info; 157 foreach my $job (@jobs) { 158 my $job_id = $job->{job_id}; 159 my $job_type = $job->{jobType}; 160 my $rownum = $job->{rownum}; 161 my $fault = $job->{fault}; 162 my $exp_id = $job->{exp_id}; 163 164 my $error_string = get_error_string($fault); 165 166 if (($fault eq $PSTAMP_DUP_REQUEST) and ($req_name eq "NULL")) { 167 # this request had a duplicate request name yet the parser didn't give 168 # it an "ERROR style name. 169 my_die("duplicate request not given a request name", $req_id, $PS_EXIT_PROG_ERROR); 170 } 171 my ($row, $req_info, $project) = get_request_info($rows, $rownum); 172 173 my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver); 174 my $image_db = $proj_hash->{dbname}; 175 if (!$image_db and !$fault) { 176 # if project isn't resolvable, the paser should have faulted this job 177 my_die("failed to find imagedb for project $project", $req_id, $PS_EXIT_CONFIG_ERROR); 178 } 179 180 my $job_params = get_job_parameters($job); 181 my $stage = ""; 182 if ($job_params) { 183 $stage = $job_params->{stage}; 184 } 185 186 if ($stage ne 'stack') { 187 # get the metadata for the exposure (if any i.e. stack) 188 # returns an appropriate string if !$exp_id 189 $exp_info = get_exposure_info($job_params, $image_db, $exp_id); 190 } else { 191 my $filter = $job_params->{filter}; 192 $filter = "0" if !$filter; 193 my $mjd_obs = $job_params->{mjd_obs}; 194 $mjd_obs = "0" if !$mjd_obs; 195 $exp_info = "$mjd_obs|0|0|$filter|0|0"; 196 } 197 198 if (($job_type eq "stamp") || ($job_type eq "get_image") || ($job_type eq "none")) { 199 my $jreglist = "$outdir/reglist$job_id"; 200 if (open JRL, "<$jreglist") {; 201 # process the reglist file to get the list of files produced by this job 202 foreach my $line (<JRL>) { 203 204 # XXX: we are getting many cases where the size and/or md5sum calculated by 205 # the job has changed by the time the request_finish has run 206 # Don't 207 # add line to the requests's reglist 208 # .... 209 # print $rlf $line; 210 211 212 chomp $line; 213 my ($img_name, $reported_size, $reported_sum, $filetype) = split '\|', $line; 214 # ... instead let dsreg compute the paramters by leaving them blank 215 print $rlf "$img_name|||$filetype|\n"; 216 217 # add line to the table definition file 218 print $tdf "$rownum|$fault|$error_string|$img_name|$job_id|"; 219 220 # ra_deg and dec_deg are the coordinates of center of the stamp 221 # first assume that the image is compressed and check the first extension. 222 # If not found check the PHU. If that doesn't work just set them to zero. 223 # XXX do this more cleanly 224 my (undef, $ra_deg, $dec_deg) = split " ", `echo $outdir/$img_name | fields -x 0 RA_DEG DEC_DEG`; 225 if (!defined $ra_deg) { 226 (undef, $ra_deg, $dec_deg) = split " ", `echo $outdir/$img_name | fields RA_DEG DEC_DEG`; 129 my $request_fault = 0; 130 if ($action eq 'PROCESS') { 131 # The results table definition file 132 my ($tdf, $table_def_name) = tempfile ("$outdir/tabledef.XXXX", UNLINK => !$save_temps); 133 # data for the header 134 print $tdf "$req_name|$req_id|\n"; 135 # get the list of jobs generated for this request 136 my @jobs; 137 { 138 my $command = "$pstamptool -listjob -req_id $req_id"; 139 $command .= " -dbname $dbname" if $dbname; 140 $command .= " -dbserver $dbserver" if $dbserver; 141 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 142 run(command => $command, verbose => $verbose); 143 unless ($success) { 144 die("Unable to perform $command error code: $error_code"); 145 } 146 my $output = join "", @$stdout_buf; 147 if (!$output) { 148 # This should not happen. A fake job should have been entered 149 my_die("Request $req_id produced no jobs", $req_id, $PS_EXIT_PROG_ERROR); 150 } else { 151 my $jobs = parse_md_fast($mdcParser, $output); 152 153 @jobs = @$jobs; 154 } 155 } 156 157 my $exp_info; 158 foreach my $job (@jobs) { 159 my $job_id = $job->{job_id}; 160 my $job_type = $job->{jobType}; 161 my $rownum = $job->{rownum}; 162 my $fault = $job->{fault}; 163 my $exp_id = $job->{exp_id}; 164 165 my $error_string = get_error_string($fault); 166 167 if (($fault eq $PSTAMP_DUP_REQUEST) and ($req_name eq "NULL")) { 168 # this request had a duplicate request name yet the parser didn't give 169 # it an "ERROR style name. 170 my_die("duplicate request not given a request name", $req_id, $PS_EXIT_PROG_ERROR); 171 } 172 my ($row, $req_info, $project) = get_request_info($rows, $rownum); 173 174 my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver); 175 my $image_db = $proj_hash->{dbname}; 176 if (!$image_db and !$fault) { 177 # if project isn't resolvable, the paser should have faulted this job 178 my_die("failed to find imagedb for project $project", $req_id, $PS_EXIT_CONFIG_ERROR); 179 } 180 181 my $job_params = get_job_parameters($job); 182 my $stage = ""; 183 if ($job_params) { 184 $stage = $job_params->{stage}; 185 } 186 187 if ($stage ne 'stack') { 188 # get the metadata for the exposure (if any i.e. stack) 189 # returns an appropriate string if !$exp_id 190 $exp_info = get_exposure_info($job_params, $image_db, $exp_id); 191 } else { 192 my $filter = $job_params->{filter}; 193 $filter = "0" if !$filter; 194 my $mjd_obs = $job_params->{mjd_obs}; 195 $mjd_obs = "0" if !$mjd_obs; 196 $exp_info = "$mjd_obs|0|0|$filter|0|0"; 197 } 198 199 if (($job_type eq "stamp") || ($job_type eq "get_image") || ($job_type eq "none")) { 200 my $jreglist = "$outdir/reglist$job_id"; 201 if (open JRL, "<$jreglist") {; 202 # process the reglist file to get the list of files produced by this job 203 foreach my $line (<JRL>) { 204 205 # XXX: we are getting many cases where the size and/or md5sum calculated by 206 # the job has changed by the time the request_finish has run 207 # Don't 208 # add line to the requests's reglist 209 # .... 210 # print $rlf $line; 211 212 213 chomp $line; 214 my ($img_name, $reported_size, $reported_sum, $filetype) = split '\|', $line; 215 # ... instead let dsreg compute the paramters by leaving them blank 216 print $rlf "$img_name|||$filetype|\n"; 217 218 # add line to the table definition file 219 print $tdf "$rownum|$fault|$error_string|$img_name|$job_id|"; 220 221 # ra_deg and dec_deg are the coordinates of center of the stamp 222 # first assume that the image is compressed and check the first extension. 223 # If not found check the PHU. If that doesn't work just set them to zero. 224 # XXX do this more cleanly 225 my (undef, $ra_deg, $dec_deg) = split " ", `echo $outdir/$img_name | fields -x 0 RA_DEG DEC_DEG`; 226 if (!defined $ra_deg) { 227 (undef, $ra_deg, $dec_deg) = split " ", `echo $outdir/$img_name | fields RA_DEG DEC_DEG`; 228 } 229 $ra_deg = 0.0 if (!$ra_deg); 230 $dec_deg = 0.0 if (!$dec_deg); 231 print $tdf "$ra_deg|$dec_deg|"; 232 233 print $tdf "$exp_info|"; 234 print $tdf "$req_info|"; 235 print $tdf "\n"; 227 236 } 228 $ra_deg = 0.0 if (!$ra_deg); 229 $dec_deg = 0.0 if (!$dec_deg); 230 print $tdf "$ra_deg|$dec_deg|"; 231 237 close JRL; 238 } else { 239 my_die("No reglist for successful job: $job_id", $req_id, $PS_EXIT_PROG_ERROR) 240 if $fault eq $PSTAMP_SUCCESS; 241 print STDERR "no reglist file for job $job_id\n" if $verbose; 242 print $tdf "$rownum|$fault|$error_string|0|$job_id|"; 243 print $tdf "0|0|"; # center of (non-existent) stamp 232 244 print $tdf "$exp_info|"; 233 245 print $tdf "$req_info|"; 234 246 print $tdf "\n"; 235 247 } 236 close JRL;237 248 } else { 238 my_die("No reglist for successful job: $job_id", $req_id, $PS_EXIT_PROG_ERROR) 239 if $fault eq $PSTAMP_SUCCESS; 240 print STDERR "no reglist file for job $job_id\n" if $verbose; 241 print $tdf "$rownum|$fault|$error_string|0|$job_id|"; 242 print $tdf "0|0|"; # center of (non-existent) stamp 243 print $tdf "$exp_info|"; 244 print $tdf "$req_info|"; 245 print $tdf "\n"; 246 } 247 } else { 248 # XXX do list jobs 249 # we can probably arange things to use the code as above and skip the fileset registration 250 print STDERR "Unknown jobType: $job_type"; 251 next; 252 } 253 } 254 close $rlf; 255 close $tdf; 256 my $request_fault = 0; 257 # make the results file 258 { 259 my $command = "$pstamp_results --input $table_def_name --output $outdir/results.fits"; 260 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 261 run(command => $command, verbose => $verbose); 262 unless ($success) { 263 print STDERR "Unable to perform $command error code: $error_code\n"; 264 $request_fault = $error_code >> 8; 265 } else { 266 # dump a textual representation 267 my $command = "$pstampdump $outdir/results.fits > $outdir/results.mdc"; 249 # XXX do list jobs 250 # we can probably arange things to use the code as above and skip the fileset registration 251 print STDERR "Unknown jobType: $job_type"; 252 next; 253 } 254 } 255 close $tdf; 256 # make the results file 257 { 258 my $command = "$pstamp_results --input $table_def_name --output $outdir/results.fits"; 268 259 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 269 260 run(command => $command, verbose => $verbose); 270 261 unless ($success) { 262 print STDERR "Unable to perform $command error code: $error_code\n"; 271 263 $request_fault = $error_code >> 8; 272 my_die("Unable to perform $command error code: $error_code", $req_id, $request_fault); 273 } 274 } 275 } 264 } else { 265 # dump a textual representation 266 my $command = "$pstampdump $outdir/results.fits > $outdir/results.mdc"; 267 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 268 run(command => $command, verbose => $verbose); 269 unless ($success) { 270 $request_fault = $error_code >> 8; 271 my_die("Unable to perform $command error code: $error_code", $req_id, $request_fault); 272 } 273 } 274 } 275 } elsif ($action ne 'LIST') { 276 my_die("Unexpected action $action found", $req_id, $PS_EXIT_PROG_ERROR); 277 } else { 278 # pstampparse did all of the work 279 } 280 281 close $rlf; 282 276 283 if (!$request_fault) { 277 284 # register the fileset
Note:
See TracChangeset
for help on using the changeset viewer.
