Changeset 27859
- Timestamp:
- May 4, 2010, 4:10:59 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
-
dbconfig/changes.txt (modified) (1 diff)
-
ippTools/share/pstamptool_completedreq.sql (modified) (1 diff)
-
ippTools/share/pstamptool_pendingdependent.sql (modified) (1 diff)
-
pstamp/scripts/Makefile.am (modified) (1 diff)
-
pstamp/scripts/detectability_respond.pl (modified) (21 diffs)
-
pstamp/scripts/dquery_finish.pl (modified) (3 diffs)
-
pstamp/scripts/dqueryparse.pl (modified) (8 diffs)
-
pstamp/scripts/pstamp_job_run.pl (modified) (2 diffs)
-
pstamp/scripts/pstamp_parser_run.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dbconfig/changes.txt
r27856 r27859 1592 1592 ALTER TABLE pstampDependent CHANGE COLUMN no_magic need_magic TINYINT; 1593 1593 ALTER TABLE pstampDependent ADD COLUMN fault SMALLINT after need_magic; 1594 ALTER TABLE pstampDependent ADD COLUMN outdir VARCHAR(255) after imagedb; 1594 1595 ALTER TABLE pstampDependent ADD KEY (state); 1595 1596 ALTER TABLE pstampDependent ADD KEY (stage); -
trunk/ippTools/share/pstamptool_completedreq.sql
r27856 r27859 1 1 SELECT pstampRequest.* , 2 IFNULL( labels.priority, 0) AS priority2 IFNULL(Label.priority, 0) AS priority 3 3 FROM pstampRequest 4 LEFT JOIN labelsUSING(label)4 LEFT JOIN Label USING(label) 5 5 WHERE state = 'run' 6 6 AND ( -
trunk/ippTools/share/pstamptool_pendingdependent.sql
r27856 r27859 4 4 JOIN pstampJob USING(dep_id) 5 5 JOIN pstampRequest USING(req_id) 6 JOIN Label ON pstampRequest.label = Label.label6 LEFT JOIN Label ON pstampRequest.label = Label.label 7 7 WHERE pstampDependent.state = 'new' 8 8 AND pstampDependent.fault = 0 -
trunk/pstamp/scripts/Makefile.am
r27704 r27859 20 20 pstamp_checkdependent.pl \ 21 21 request_finish.pl \ 22 detectability_respond.pl \ 22 23 detect_query_read \ 23 24 detect_response_create \ -
trunk/pstamp/scripts/detectability_respond.pl
r27788 r27859 41 41 my $EXTVER = 1.0; 42 42 my $EXTNAME = 'MOPS_DETECTABILITY_RESPONSE'; 43 my ($req_id,$req_name,$product,$need_magic,$missing_tools );44 my ($request_file,$output,$ dbname,$verbose,$save_temps);43 my ($req_id,$req_name,$product,$need_magic,$missing_tools,$project); 44 my ($request_file,$output,$workdir,$dbname,$dbserver,$verbose,$save_temps); 45 45 GetOptions( 46 'input=s' =>\$request_file,46 'input=s' => \$request_file, 47 47 'output=s' => \$output, 48 'workdir=s' => \$workdir, 48 49 'dbname=s' => \$dbname, 50 'dbserver=s' => \$dbserver, 49 51 'verbose' => \$verbose, 50 52 'save-temps' => \$save_temps, … … 55 57 -exitval => 3, 56 58 ) unless 57 defined $request_file and defined $output and defined $ dbname;59 defined $request_file and defined $output and defined $workdir and defined $dbname; 58 60 59 61 my $detect_query_read = can_run('detect_query_read') or (warn "Can't find detect_query_read" and $missing_tools = 1); … … 71 73 72 74 my $ipprc = PS::IPP::Config->new(); 73 #my $tmp_dir = "/data/${host}.0/tmp/"; 74 75 my $project = resolve_project($ipprc,"project_name",$dbname); 75 76 if (!$dbserver) { 77 $dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER'); 78 } 79 # This is hardcoded in for the moment. 80 $project = resolve_project($ipprc,"gpc1",$dbname,$dbserver); 81 my $imagedb = $project->{dbname}; 82 if (!$imagedb) { 83 carp("failed to find imagedb for project: $project"); 84 } 85 76 86 # 77 87 # Parse input request file using detect_query_read (as it's already written). 78 88 # 79 80 89 my $dqr_command = "$detect_query_read --input $request_file"; 81 90 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 82 91 run(command => $dqr_command, verbose => $verbose); 83 92 unless ($success) { 84 my_die("Unable to perform $dqr_command error code: $error_code",-1,-1,-1,-1,-1,-1); 93 # This is a problem, because I'm not sure how we handle a failure to read something. 94 # We need to return a $PSTAMP_INVALID_REQUEST, I think, but if we can't read it, 95 # we can't send that response back. 96 die("Unable to perform $dqr_command error code: $error_code"); 85 97 } 86 98 my %query = (); … … 120 132 my %image_list_hash; 121 133 for (my $i = 1; $i < $Nrows; $i++) { 122 # print "$i $Nrows $query{CONTENT}{RA1_DEG}[$i] $query{CONTENT}{DEC1_DEG}[$i]\n"; 134 # This could use the fact that locate_images now accepts position arrays, but 135 # I'll save that for after I get the majority of things working. 123 136 my $image_set_tmp = find_image_set($query{HEADER}{FPA_ID}[0],$query{HEADER}{STAGE}[0], 124 137 $query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0], … … 126 139 $query{CONTENT}{ROWNUM}[$i],$verbose); 127 140 unless (%$image_set_tmp) { 128 my_die("No images were returned.",$query{HEADER}{QUERY_ID}[0],$query{HEADER}{FPA_ID}[0], 129 $query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0],$query{HEADER}{OBSCODE}[0], 130 $query{HEADER}{STAGE}[0]); 131 } 132 print "=== $image_set_tmp->{IMAGE}\n $image_set_tmp->{PSF}\n $image_set_tmp->{MASK}\n $image_set_tmp->{WEIGHT}\n $image_set_tmp->{SKY_COORDINATES}\n $image_set_tmp->{ROWNUM}\n"; 133 # This appends, assuming that if we get an image, we also get the identical psf/mask/weight/etc. 141 # No images were returned, so create a dummy entry that 142 $image_list_hash{'no_image'}{IMAGE} = 'no_image'; 143 $image_list_hash{'no_image'}{PSF} = 'no_psf'; 144 $image_list_hash{'no_image'}{MASK} = 'no_mask'; 145 $image_list_hash{'no_image'}{WEIGHT} = 'no_weight'; 146 $image_list_hash{'no_image'}{CATALOG} = 'no_catalog'; 147 $image_list_hash{'no_image'}{CLASS_ID} = 'no_class'; 148 $image_list_hash{'no_image'}{ERROR} = $PSTAMP_NO_IMAGE_MATCH; 149 push @{ $image_list_hash{'no_image'}{SKY_COORDINATES} }, "$query{CONTENT}{RA1_DEG}[$i] $query{CONTENT}{DEC1_DEG}[$i]"; 150 push @{ $image_list_hash{'no_image'}{ROWNUM} }, $query{CONTENT}{ROWNUM}[$i]; 151 next; 152 } 153 # print "=== $image_set_tmp->{IMAGE}\n $image_set_tmp->{PSF}\n"; 154 # print " $image_set_tmp->{MASK}\n $image_set_tmp->{WEIGHT}\n"; 155 # print " $image_set_tmp->{SKY_COORDINATES}\n $image_set_tmp->{ROWNUM}\n"; 156 157 # This indexes the results for identical images into the same hash. 134 158 $image_list_hash{$image_set_tmp->{IMAGE}}{IMAGE} = $image_set_tmp->{IMAGE}; 135 159 $image_list_hash{$image_set_tmp->{IMAGE}}{PSF} = $image_set_tmp->{PSF}; … … 138 162 $image_list_hash{$image_set_tmp->{IMAGE}}{CATALOG} = $image_set_tmp->{CATALOG}; 139 163 $image_list_hash{$image_set_tmp->{IMAGE}}{CLASS_ID} = $image_set_tmp->{CLASS_ID}; 164 $image_list_hash{$image_set_tmp->{IMAGE}}{ERROR} = $image_set_tmp->{ERROR}; 140 165 push @{ $image_list_hash{$image_set_tmp->{IMAGE}}{SKY_COORDINATES} }, $image_set_tmp->{SKY_COORDINATES}; 141 166 push @{ $image_list_hash{$image_set_tmp->{IMAGE}}{ROWNUM} }, $image_set_tmp->{ROWNUM}; 142 167 } 168 143 169 my $i = 0; 144 145 146 170 foreach my $k (keys %image_list_hash) { 171 # If we errored out on finding an image, we need to not try to run psphot here. 172 if ($image_list_hash{$k}{ERROR} != 0) { 173 next; 174 } 147 175 # Write coordinates of the requested targets to a file. 148 my ($coordfile,$coordname) = tempfile(" /tmp/detect.coords.$i.XXXX",176 my ($coordfile,$coordname) = tempfile("${workdir}/detect.coords.$i.XXXX", 149 177 UNLINK => !$save_temps); 150 my ($targetfile,$targetname) = tempfile(" /tmp/detect.targets.$i.XXXX",178 my ($targetfile,$targetname) = tempfile("${workdir}/detect.targets.$i.XXXX", 151 179 UNLINK => !$save_temps); 152 180 … … 154 182 print $coordfile "$image_list_hash{$k}{SKY_COORDINATES}[$j]\n"; 155 183 } 156 print "$k\n";184 # print "$k\n"; 157 185 # Convert the sky coordinates to image coordinates with ppCoord. 158 186 my $command = "ppCoord -astrom $image_list_hash{$k}{CATALOG} -radec $coordname"; … … 172 200 } 173 201 174 print "psphot $image_list_hash{$k}{PSF}\n";202 # print "psphot $image_list_hash{$k}{PSF}\n"; 175 203 # Run psphotForced on the target list. 176 my $tmpdir = tempdir("detect.$i.XXXX", DIR => " /tmp/", CLEANUP => !$save_temps);204 my $tmpdir = tempdir("detect.$i.XXXX", DIR => "${workdir}/", CLEANUP => !$save_temps); 177 205 $image_list_hash{$k}{OUTROOT} = "$tmpdir/detectability.$query{HEADER}{STAGE}[0].$query{HEADER}{FPA_ID}[0]"; 178 206 … … 186 214 run(command => $psphot_cmd, verbose => $verbose); 187 215 unless ($success) { 188 my_die("Unable to perform $psphot_cmd. Error_code: $error_code", 189 $query{HEADER}{QUERY_ID}[0],$query{HEADER}{FPA_ID}[0], 190 $query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0],$query{HEADER}{OBSCODE}[0], 191 $query{HEADER}{STAGE}[0],$error_code); 216 $image_list_hash{$k}{ERROR} = $PSTAMP_SYSTEM_ERROR; 192 217 } 193 218 } … … 197 222 # 198 223 my @rownums = (); 224 my @out_errors = (); 199 225 my @psphot_Npix = (); 200 226 my @psphot_Qfact= (); 201 227 my @psphot_flux = (); 228 202 229 foreach my $k (keys %image_list_hash) { 203 my $cmf = "$image_list_hash{$k}{OUTROOT}.$image_list_hash{$k}{CLASS_ID}.cmf"; 204 205 my ($tmp_Npix,$tmp_Qfact,$tmp_flux) = read_cmf_file($cmf,$image_list_hash{$k}{EXTENSION_BASE}); 206 207 push @rownums, @{ $image_list_hash{$k}{ROWNUM} }; 208 push @psphot_Npix, @{ $tmp_Npix }; 209 push @psphot_Qfact, @{ $tmp_Qfact }; 210 push @psphot_flux, @{ $tmp_flux }; 230 if ($image_list_hash{$k}{ERROR} == 0) { 231 my $cmf = "$image_list_hash{$k}{OUTROOT}.$image_list_hash{$k}{CLASS_ID}.cmf"; 232 233 my ($tmp_Npix,$tmp_Qfact,$tmp_flux) = read_cmf_file($cmf,$image_list_hash{$k}{EXTENSION_BASE}); 234 235 push @rownums, @{ $image_list_hash{$k}{ROWNUM} }; 236 push @out_errors, (map { $image_list_hash{$k}{ERROR} } @{ $image_list_hash{$k}{ROWNUM} }); 237 push @psphot_Npix, @{ $tmp_Npix }; 238 push @psphot_Qfact, @{ $tmp_Qfact }; 239 push @psphot_flux, @{ $tmp_flux }; 240 } 241 else { 242 push @rownums, @{ $image_list_hash{$k}{ROWNUM} }; 243 push @out_errors, (map { $image_list_hash{$k}{ERROR} } @{ $image_list_hash{$k}{ROWNUM} }); 244 push @psphot_Npix, (map { 0 } @{ $image_list_hash{$k}{ROWNUM} }); 245 push @psphot_Qfact, (map { 0.0 } @{ $image_list_hash{$k}{ROWNUM} }); 246 push @psphot_flux, (map { 0.0 } @{ $image_list_hash{$k}{ROWNUM} }); 247 } 211 248 } 212 249 … … 215 252 $query{HEADER}{MJD_OBS}[0],$query{HEADER}{filter}[0], 216 253 $query{HEADER}{obscode}[0], 217 \@rownums, \@ psphot_Npix, \@psphot_Qfact, \@psphot_flux);218 print "Wrote response file $output\n";254 \@rownums, \@out_errors, \@psphot_Npix, \@psphot_Qfact, \@psphot_flux); 255 # print "Wrote response file $output\n"; 219 256 # 220 257 # Add to datastore 221 258 # 222 # my $finish_command = "dquery_finish.pl --req_id $req_id --req_name $req_name --product $product"; 223 # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 224 # run(command => $finish_command, verbose => $verbose); 225 # unless ($success) { 226 # warn ("Unable to perform $finish_command error code: $error_code"); 227 # } 228 259 # Files are added to the datastore by dquery_finish.pl 229 260 # 230 261 # Cleanup 231 262 # 232 263 # Since everything is written to temporary files, there should be nothing to cleanup. 264 233 265 # 234 266 # Utilities … … 243 275 my $index = shift; 244 276 my $verbose = shift; 245 277 278 # This is the set of things that we need in order to run psphotForced 246 279 my $option_mask |= 1; 247 280 $option_mask |= $PSTAMP_SELECT_IMAGE; … … 253 286 my $mjd_max = $mjd + 1; 254 287 255 # Construct a row list: 256 288 # Construct a row list. 257 289 my @rowList; 258 290 $rowList[0]->{CENTER_X} = $ra; … … 261 293 $rowList[0]->{STAGE} = $stage; 262 294 $rowList[0]->{COORD_MASK} = 0; 263 print "$stage\n"; 295 296 # print "$stage\n"; 264 297 # Call the PStamp code to find the images that contain the target on the given MJD in the specified filter. 265 my @images = locate_images($ipprc,$ dbname,298 my @images = locate_images($ipprc,$imagedb, 266 299 \@rowList, 267 300 "bycoord",$stage, … … 284 317 } 285 318 elsif ($stage eq 'stack') { 286 # Stacks hide the exposure name very well, so I'm 287 # choosing the stack_id as the FPA_ID to match. This 288 # probably needs to be approved somehow. 319 # Stacks hide the exposure name very well, so we can only match against stage_id 289 320 if (${ $j }{stage_id} ne $FPA_ID) { 290 321 next; … … 299 330 } 300 331 # Debug prints of all the components of this image 301 foreach my $k (keys %{ $j }) { 302 print "$i $j $k ${ $j }{$k}\n"; 303 } 304 332 # foreach my $k (keys %{ $j }) { 333 # if ($k eq 'row_index') { 334 # print "$i $j $k @{${ $j }{$k} }\n"; 335 # } 336 # print "$i $j $k ${ $j }{$k}\n"; 337 # } 338 339 # Check for existance of the images. Drawn mostly from pstampparse.pl 340 my $run_state = ${ $j }{state}; 341 my $data_state = ${ $j }{data_state}; 342 $data_state = $run_state if $stage eq 'stack'; 343 my $fault = 0; 344 if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or 345 ($run_state eq 'drop') or 346 ($run_state eq 'error_cleaned') or 347 ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) { 348 # image is gone and it's not coming back 349 $fault = $PSTAMP_GONE; 350 } 351 elsif (($data_state ne 'full') or ($need_magic and (${ $j }{magicked} < 0))) { 352 if (($stage eq 'stack')||($stage eq 'diff')) { 353 # updating stacks and diffs isn't implemented 354 $fault = $PSTAMP_NOT_IMPLEMENTED; 355 } 356 if ($stage eq 'chip') { 357 my $burntool_state = ${ $j }{burntool_state}; 358 if ($burntool_state and (abs($burntool_state) < 14)) { 359 $fault = $PSTAMP_NOT_AVAILABLE; 360 } 361 } 362 363 if ($fault == 0) { 364 # This bombs us out to dqueryparse, which will then flag a job for this run to be updated. 365 my_die_for_update($data_state,$query{HEADER}{STAGE}[0], 366 ${ $j }{stage_id},${ $j }{class_id} || ${ $j }{skycell_id}, 367 $need_magic,$imagedb,$PSTAMP_NOT_AVAILABLE); 368 } 369 } 370 305 371 # This image matches, so we want to save the information into our output structure 306 372 $image_info{ROWNUM} = $index; … … 309 375 $image_info{MASK} = ${ $j }{mask}; 310 376 $image_info{WEIGHT} = ${ $j }{weight}; 377 $image_info{ERROR} = $fault; 311 378 $image_info{SKY_COORDINATES} = "$ra $dec"; 312 379 # To do sky->image coordinate transformations, we need to use the cmf/smf file. If … … 419 486 my $obscode = shift; 420 487 my $rownum_ref = shift; 488 my $out_err_ref = shift; 421 489 my $psphot_Npix_ref = shift; 422 490 my $psphot_Qfact_ref = shift; … … 427 495 my $columns = [ 428 496 # matching rownum from detectability original request 429 { name => 'ROWNUM', type => '20A', writetype => TSTRING }, 497 { name => 'ROWNUM', type => 'V', writetype => TULONG }, 498 # any errors that occurred during processing 499 { name => 'ERROR_CODE', type => 'V', writetype => TULONG }, 430 500 # number of pixels used in hypothetical PSF for the query detection 431 501 { name => 'DETECT_N', type => 'V', writetype => TULONG }, … … 469 539 for (my $i = 0; $i < $numRows; $i++) { 470 540 push @{$colData{'ROWNUM'}}, ${ $rownum_ref }[$i]; 541 push @{$colData{'ERROR_CODE'}}, ${ $out_err_ref }[$i]; 471 542 push @{$colData{'DETECT_N'}}, ${ $psphot_Npix_ref }[$i]; 472 543 push @{$colData{'DETECT_F'}}, ${ $psphot_Qfact_ref }[$i]; … … 543 614 544 615 } 616 617 sub my_die_for_update { 618 my $state = shift; 619 my $stage = shift; 620 my $stage_id = shift; 621 my $component = shift; 622 my $need_magic = shift; 623 my $imagedb = shift; 624 my $exit_code = shift; 625 626 print "$state $stage $stage_id $component $need_magic $imagedb\n"; 627 print STDERR "$state $stage $stage_id $component $need_magic $imagedb\n"; 628 exit($exit_code); 629 } -
trunk/pstamp/scripts/dquery_finish.pl
r27578 r27859 119 119 # XXX: have the jobs produce the reglist as with postage stamp requests 120 120 my ($REGLIST, $reg_list) = tempfile("$out_dir/reqlist.XXXX", UNLINK => !$save_temps); 121 121 122 foreach my $job (@jobs) { 122 123 my $job_id = $job->{job_id}; … … 127 128 # the job generated a response file put it into the Data Store 128 129 print $REGLIST "$response_file|||table|\n"; 130 131 # do the same if we have an error file. Should the parse data be uploaded as well? 132 my $err_file = "parse_error.txt"; 133 if (-e "$out_dir/$err_file") { 134 print $REGLIST "$err_file|||text|\n"; 135 } 129 136 } else { 130 137 print STDERR "detect_query response file for job $job_id not found\n" if $verbose; … … 138 145 $command .= " --copy --datapath $out_dir"; 139 146 $command .= " --type MOPS_DETECTABILITY_RESPONSE"; 147 $command .= " --ps0 $req_id"; 140 148 $command .= " --dbname $dbname" if $dbname; 141 149 -
trunk/pstamp/scripts/dqueryparse.pl
r27578 r27859 2 2 # 3 3 # parse a MOPS_DETCTABILITY_QUERY table and create a results file 4 #5 # Note: this file is currently only a placeholder which creates a fake response file6 # and adds a completed job to the database7 4 # 8 5 9 6 use strict; 10 7 use warnings; 11 8 use Carp; 12 9 use Getopt::Long qw( GetOptions ); 13 10 use Pod::Usage qw( pod2usage ); 14 11 use IPC::Cmd 0.36 qw( can_run run ); 15 12 13 use PS::IPP::PStamp::RequestFile qw( :standard ); 14 use PS::IPP::PStamp::Job qw( :standard ); 16 15 use PS::IPP::Config qw($PS_EXIT_SUCCESS 17 16 $PS_EXIT_UNKNOWN_ERROR … … 26 25 ); 27 26 27 my ($no_update, $imagedb, $label); 28 28 my ($req_file, $req_id, $out_dir, $product, $mode, $dbname, $dbserver, $verbose, $save_temps); 29 29 my ($job_id,$rownum); # stuff from the post-update world 30 30 # 31 31 # parse args … … 35 35 'file=s' => \$req_file, 36 36 'req_id=s' => \$req_id, 37 'job_id=s' => \$job_id, 38 'rownum=s' => \$rownum, 37 39 'out_dir=s' => \$out_dir, 40 'label=s' => \$label, 38 41 'product=s' => \$product, 39 42 'mode=s' => \$mode, … … 44 47 ) or pod2usage(2); 45 48 46 my $err = ""; 47 48 if (!$req_file) { 49 $err .= "--file is required\n"; 50 } 51 if (!$req_id) { 52 $err .= "--req_id is required\n"; 53 } 54 if (!$out_dir) { 55 $err .="--out_dir is required\n"; 56 } 57 if (!$product) { 58 $err .="--product is required\n"; 59 } 60 61 62 die $err if ($err); 63 49 die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "queue_job"); 50 die "--file or --job_id is required" if !$req_file; 51 52 if ($mode ne "list_uri") { 53 die "req_id is required" if !$req_id; 54 die "out_dir is required" if !$out_dir; 55 die "product is required" if !$product; 56 } 64 57 my $missing_tools; 65 58 my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools =1); 66 my $fakedresponse = can_run('fakedresponse.pl') or (warn "Can't find fakedresponse.pl" and $missing_tools =1); 59 my $detectresponse = can_run('detectability_respond.pl') or 60 (warn "Can't find detectability_respond.pl" and $missing_tools = 1); 67 61 my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools =1); 68 62 … … 77 71 } 78 72 73 # just deal with these arguments once and for all 74 $pstamptool .= " -dbname $dbname" if $dbname; 75 $pstamptool .= " -dbserver $dbserver" if $dbserver; 76 $detectresponse .= " --dbname $dbname" if $dbname; 77 78 $no_update = 1 if $mode eq "list_job"; 79 80 # Unless we're running as a job, write the parse arguments in case we need to rerun this parsing. 81 if (!$job_id) { 82 my $argslist = "$out_dir/parse.args"; 83 open ARGSLIST, ">$argslist" or my_die("failed to open argslist file $argslist", $job_id, $PS_EXIT_UNKNOWN_ERROR); 84 print ARGSLIST "--label $label --mode $mode --req_id $req_id --product $product --out_dir $out_dir --file $req_file\n"; 85 close ARGSLIST; 86 } 87 79 88 # get the query id and check the extname and version from the header 80 my $fields_output; 89 my $fields_output; 81 90 { 82 91 my $command = "echo $req_file | $fields -x 0 EXTNAME EXTVER QUERY_ID"; … … 84 93 run(command => $command, verbose => $verbose); 85 94 86 # fields doesn't return zero when it succeeds87 # unless ($success) {88 # print STDERR @$stderr_buf;89 # }90 95 $fields_output = join "", @$stdout_buf; 91 96 } 92 97 my (undef, $extname, $extver, $req_name) = split " ", $fields_output; 93 98 94 die "$req_file is missing one of EXTNAME EXTVER or QUERY_ID" 99 my_die("$req_file is missing one of EXTNAME EXTVER or QUERY_ID", $PS_EXIT_PROG_ERROR) 95 100 if !(defined($extname) and defined($extver) and defined($req_name)); 96 97 die "$req_file has EXTNAME $extname not MOPS_DETECTABILITY_QUERY table" 98 if $extname ne "MOPS_DETECTABILITY_QUERY"; 99 die "$req_file is version $extver expecting 1" if $extver ne 1; 100 101 if (0) { 102 $out_dir .= "/$req_name"; 103 } 101 my_die("$req_file has EXTNAME $extname not MOPS_DETECTABILITY_QUERY table", $PS_EXIT_PROG_ERROR) 102 if $extname ne "MOPS_DETECTABILITY_QUERY"; 103 my_die("$req_file is version $extver expecting 1", $PS_EXIT_PROG_ERROR) 104 if $extver ne 1; 105 106 # Set up the workdir for this query. 104 107 if (! -e $out_dir ) { 105 mkdir $out_dir or die "cannot create output directory $out_dir";108 mkdir $out_dir or my_die("cannot create output directory $out_dir", $PS_EXIT_PROG_ERROR); 106 109 } elsif (! -d $out_dir ) { 107 die "output fileset directory $out_dir exists but is not a directory"; 108 } 109 110 # 111 # XXX Eventually we will parse the file here, to look up the list of input images to be processed 112 # and queue a job for each image. 113 # The request file will be one of the arguments. Each job will look at all rows and create entries 114 # in the response file the coordinates that overlap the image. 115 # 116 # In the meantime we don't parse the file here, pass it to the program fakedresponse. 117 # It creates a response file with a line for each row in the request file 118 119 my $response_file = "$out_dir/response.fits"; 110 my_die ("output fileset directory $out_dir exists but is not a directory", $PS_EXIT_PROG_ERROR); 111 } 112 113 114 # Pass along the request file to the response generator. 115 my $response_file = "$out_dir/${req_name}.dresponse.${req_id}.fits"; 120 116 my $fault; 117 my $data_to_update = ''; 121 118 { 122 my $command = "$ fakedresponse --input $req_file --output $response_file --workdir $out_dir";119 my $command = "$detectresponse --input $req_file --output $response_file --workdir $out_dir"; 123 120 $command .= " --save-temps" if $save_temps; 124 121 $command .= " --verbose" if $verbose; … … 127 124 run(command => $command, verbose => $verbose); 128 125 unless ($success) { 129 warn("Unable to perform $command error code: $error_code"); 130 } 126 warn("Warn! Unable to perform $command error code: $error_code"); 127 } 128 # Use the fault code to see if we can regenerate the missing data. 131 129 $fault = $error_code >> 8; 132 } 133 134 my $job_id; 130 if ($fault == $PSTAMP_NOT_AVAILABLE) { 131 $data_to_update = (split /\n/, (join "", @$stdout_buf))[-1]; 132 } 133 } 134 135 135 my $result; 136 { 136 # If we returned correctly with a valid response file, get a job ID 137 # for the completed work, and move the response to a standardized name. 138 if ($fault == 0) { 137 139 my $command = "$pstamptool -addjob -req_id $req_id -outputBase $out_dir"; 138 $command .= " -job_type detect_query -state stop -fault $fault";140 $command .= " -job_type detect_query -state stop -fault 0"; 139 141 $command .= " -rownum 1"; 140 $command .= " -dbname $dbname" if $dbname; 141 $command .= " -dbserver $dbserver" if $dbserver; 142 143 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 144 run(command => $command, verbose => $verbose); 145 142 143 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 144 run(command => $command, verbose => $verbose); 146 145 if ($success) { 147 146 $job_id = join "", @$stdout_buf; … … 156 155 } 157 156 } 158 159 157 else { 158 # Failed to run correctly, which means that we need to queue a job and flag data for updating. 159 # Get the dependency id for the data we're requesting be updated. 160 my $dep_id = queue_update_run($req_id,$job_id,$out_dir,$label,$data_to_update); 161 162 # Link this request to a job and link that job to any dependency 163 my $command = "$pstamptool -addjob -req_id $req_id -outputBase $out_dir"; 164 $command .= " -job_type detect_query -state run -fault 0"; 165 $command .= " -rownum 1"; 166 $command .= " -dep_id $dep_id" if $dep_id; 167 168 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 169 run(command => $command, verbose => $verbose); 170 171 if ($success) { 172 $job_id = join "", @$stdout_buf; 173 chomp $job_id; 174 if ($job_id && -e $response_file) { 175 # We shouldn't have a response file at this stage. 176 rename $response_file, "$out_dir/response${job_id}.fits"; 177 } 178 $result = 0; 179 } else { 180 warn("Unable to perform $command error code: $error_code"); 181 $result = $error_code >> 8; 182 } 183 } 184 185 # This does not set the request state to stop. That will happen with the request_finish.pl script, 186 # which will notice that we've inserted the stopped job and decide we're finished. Easy enough. 160 187 { 161 188 my $command = "$pstamptool -updatereq -req_id $req_id -name $req_name -outProduct $product"; 162 189 $command .= " -fault $result" if $result; 163 $command .= " -dbname $dbname" if $dbname;164 $command .= " -dbserver $dbserver" if $dbserver;165 190 166 191 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 167 192 run(command => $command, verbose => $verbose); 168 193 unless ($success) { 169 die "$command failed";194 my_die("$command failed",$PS_EXIT_UNKNOWN_ERROR); 170 195 } 171 196 } 172 197 173 198 exit 0; 199 200 201 # If we have to queue an update run, do so and create a new dependent 202 sub queue_update_run { 203 my ($req_id, $job_id, $out_dir, $label, $data_to_update) = @_; 204 205 my ($state, $stage, $stage_id, $component, $need_magic, $imagedb) = split /\s+/, $data_to_update; 206 207 if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) { 208 # We should have received one of these states, so if not, signal that we have a problem. 209 my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR); 210 } 211 my $dep_id; 212 my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component "; 213 $command .= " -outdir $out_dir"; 214 $command .= " -need_magic" if $need_magic; 215 216 my $rlabel = "dq_ud_" . $label if $label; 217 $command .= " -rlabel $rlabel" if $rlabel; 218 219 if (!$no_update) { 220 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 221 run(command => $command, verbose => $verbose); 222 unless ($success) { 223 my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR); 224 } 225 my $output = join "", @$stdout_buf; 226 chomp $output; 227 $dep_id = $output; 228 229 my_die("pstamptool -getdependent returned invalid dep_id", $PS_EXIT_PROG_ERROR) if !$dep_id; 230 } 231 else { 232 print STDERR "skipping $command\n"; 233 $dep_id = 42; 234 } 235 236 return($dep_id); 237 } 238 239 240 241 sub my_die { 242 my $msg = shift; 243 my $fault = shift; 244 245 carp $msg; 246 247 # we don't fault the request here pstamp_parser_run.pl handles that if necessary 248 exit $fault; 249 } -
trunk/pstamp/scripts/pstamp_job_run.pl
r27751 r27859 74 74 my $ppstamp = can_run('ppstamp') or (warn "Can't find ppstamp" and $missing_tools = 1); 75 75 my $pstamp_get_image_job = can_run('pstamp_get_image_job.pl') or (warn "Can't find pstamp_get_image_job.pl" and $missing_tools = 1); 76 my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1); 76 77 77 78 if ($missing_tools) { … … 165 166 } 166 167 } elsif ($jobType eq "detect_query") { 167 my_die("detect_query jobs not supported yet", $job_id,$PS_EXIT_CONFIG_ERROR); 168 # detect_query jobs are basically holders to note that we need a file updated before we can continue. 169 # Load the argument list that dqueryparse should have created the first time it ran, so we know how to 170 # run it again the same way. 171 my $argslist = "$outputBase/parse.args"; 172 open ARGSLIST, "<$argslist" or my_die("failed to open argslist file $argslist", $job_id, $PS_EXIT_UNKNOWN_ERROR); 173 my $argString = <ARGSLIST>; 174 close ARGSLIST; 175 chomp $argString; 176 177 # XXX: should we do any other sanity checking? 178 my_die("arglist file $argslist is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString; 179 180 my $command = "$dqueryparse --job_id $job_id $argString"; 181 $command .= " --dbname $dbname" if $dbname; 182 $command .= " --dbserver $dbserver" if $dbserver; 183 $command .= " --verbose" if $verbose; 184 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 185 run(command => $command, verbose => $verbose); 186 187 # Although dqueryparse can potentially force more updates (and more jobs), it should still return success. 188 if ($success) { 189 $jobStatus = $PS_EXIT_SUCCESS; 190 } else { 191 $jobStatus = $error_code >> 8; 192 my_die("dqueryparse.pl failed with error code: $jobStatus", $job_id, $jobStatus); 193 } 168 194 } else { 169 195 my_die("unknown jobType $jobType found", $job_id, $PS_EXIT_PROG_ERROR); -
trunk/pstamp/scripts/pstamp_parser_run.pl
r27841 r27859 152 152 } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") { 153 153 $reqType = 'dquery'; 154 $parse_cmd = $dqueryparse; 154 $parse_cmd = "$dqueryparse"; 155 $parse_cmd .= " --label $label" if $label; 155 156 } else { 156 157 print STDERR "Unknown request type $request_type found in $uri";
Note:
See TracChangeset
for help on using the changeset viewer.
