Changeset 18985
- Timestamp:
- Aug 8, 2008, 3:47:34 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstampparse.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstampparse.pl
r18743 r18985 11 11 use Sys::Hostname; 12 12 use Getopt::Long qw( GetOptions ); 13 use PStamp::RequestFile qw( :standard ); 14 use PStamp::Job qw( :standard ); 13 15 14 16 my $verbose; … … 19 21 my $out_dir; 20 22 my $product; 21 22 # values for COORD_MASK23 use constant PSTAMP_CENTER_IN_PIXELS => 1;24 use constant PSTAMP_RANGE_IN_PIXELS => 2;25 26 # values for OPTION_MASK27 use constant PSTAMP_SELECT_IMAGE => 1;28 use constant PSTAMP_SELECT_MASK => 2;29 use constant PSTAMP_SELECT_WEIGHT => 4;30 23 31 24 GetOptions( … … 40 33 41 34 die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "list_job") or ($mode eq "queue_job"); 42 die "req_id is required" if (!defined($req_id) && ($mode ne "list_uri"));43 35 die "file is required" if !defined($request_file_name); 44 die "out_dir is required" if !defined($out_dir); 45 die "product is required" if !defined($product); 46 36 37 if ($mode ne "list_uri") { 38 die "req_id is required" if !$req_id; 39 die "out_dir is required" if !$out_dir; 40 die "product is required" if !$product; 41 } 47 42 48 43 use IPC::Cmd 0.36 qw( can_run run ); … … 52 47 use PS::IPP::Metadata::List qw( parse_md_list ); 53 48 54 use PS::IPP::Config qw($PS_EXIT_SUCCESS 55 $PS_EXIT_UNKNOWN_ERROR 56 $PS_EXIT_SYS_ERROR 57 $PS_EXIT_CONFIG_ERROR 58 $PS_EXIT_PROG_ERROR 59 $PS_EXIT_DATA_ERROR 60 $PS_EXIT_TIMEOUT_ERROR 61 metadataLookupStr 62 metadataLookupBool 63 caturi 64 ); 65 49 use PS::IPP::Config qw( :standard ); 66 50 my $ipprc = PS::IPP::Config->new(); # IPP Configuration 67 51 … … 102 86 die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1"); 103 87 104 $out_dir .= "/$req_name"; 105 if (! -e $out_dir ) { 106 mkdir $out_dir or die "cannot create output directory $out_dir"; 107 } elsif (! -d $out_dir ) { 108 die "output fileset directory $out_dir exists but is not a directory"; 109 } 110 111 { 112 my $command = "$pstamptool -processedreq -req_id $req_id -name $req_name -outProduct $product"; 113 $command .= " -dbname $dbname"; 88 if ($out_dir) { 89 $out_dir .= "/$req_name"; 90 if (! -e $out_dir ) { 91 mkdir $out_dir or die "cannot create output directory $out_dir"; 92 } elsif (! -d $out_dir ) { 93 die "output fileset directory $out_dir exists but is not a directory"; 94 } 95 } 96 97 if ($req_id) { 98 my $command = "$pstamptool -processedreq -req_id $req_id -name $req_name"; 99 $command .= " -outProduct $product"; 100 $command .= " -dbname $dbname" if $dbname; 114 101 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 115 102 run(command => $command, verbose => $verbose); … … 158 145 $stamp_name = "" if $stamp_name eq "null"; 159 146 160 161 # XXX: TODO: don't die in this loop. If we encounter an error add a job with the proper fault 162 # code 163 # todo this needs some implementation work 147 # XXX: TODO: sanity check all parameters 148 149 # XXX: TODO: We shouldn't just die in this loop. 150 # If we encounter an error for a particular row 151 # add a job with the proper fault code. If there is a db or config error we should probably just 152 # trash the request. 164 153 die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri"); 165 154 166 # TODO: sanity check all arguments 167 168 my ($image_db, $lookup_class_id ) = resolve_project($project, $img_type, $class_id); 155 156 my ($image_db, $lookup_class_id, $camera, $magic_required ) = resolve_project($project, $img_type, $class_id); 169 157 170 158 my $roi_string; 171 159 # XXX we're depending on other code to insure valid values for roi components 172 # this is checked in pstamprequest and ppstamp173 # I should check here tobut not today160 # this is checked in and ppstamp but I should check here so that we don't get that far, 161 # but not today 174 162 if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) { 175 if ($coord_mask & PSTAMP_CENTER_IN_PIXELS) {163 if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) { 176 164 $roi_string = "-pixcenter $x $y"; 177 165 } else { 178 166 $roi_string = "-skycenter $x $y"; 179 167 } 180 if ($coord_mask & PSTAMP_RANGE_IN_PIXELS) {168 if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) { 181 169 $roi_string .= " -pixrange $w $h"; 182 170 } else { … … 193 181 die "region of interest is required for request type bycoord" if !defined($roi_string) ; 194 182 die "center must be specified in sky coordintes for bycoord" 195 if ($coord_mask & PSTAMP_CENTER_IN_PIXELS); 196 # replace the id with center coordinates 197 $id = "$x $y"; 198 } 199 200 # XXX: replace the invokcation of the hacked locateimages with a new ippTool that finds 201 # images/runs and prints out the uri and other metadata as a metadata config doc 202 203 my $command = "$locateimages -dbname $image_db -$req_type $img_type $id $lookup_class_id"; 204 $command .= " -mjd_min $mjd_min" if ($mjd_min); 205 $command .= " -mjd_max $mjd_max" if ($mjd_max); 206 207 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 208 run(command => $command, verbose => $verbose); 209 unless ($success) { 210 print STDERR @$stderr_buf; 211 exit 1; 212 } 213 my @uris = split "^", join("", @$stdout_buf); 183 if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS); 184 } 185 186 # Call PStamp::Job's locate_images routinte to get the parameters for this request specification 187 my $images = locate_images($ipprc, $image_db, $req_type, $img_type, $id, $lookup_class_id, 188 $x, $y, $mjd_min, $mjd_max, $filter); 214 189 215 190 if ($mode eq "list_uri") { 216 foreach my $ uri (@uris) {217 print $uri;191 foreach my $image (@$images) { 192 print "$image->{image}\n"; 218 193 } 219 194 } elsif ($job_type eq "get_image") { 195 # XXX TODO: Get rid of this block and use the same code as the stamp jobs 196 # XXX This doesn't work to get the mask and weight images 220 197 my $listfile = "$out_dir/filelist"; 221 198 … … 223 200 or die "failed to open file list: $listfile while parsing get_image request $req_id"; 224 201 225 # XXX TODO: how do we expand URIS to include wt and mk images 226 # I've been assuming that ppstamp would just know what to do based on flags and file rules. 227 # Actually if we change the code that lists images to list outputBase's instead we can 228 # translate the rules here 229 foreach my $uri (@uris) { 230 chomp $uri; 231 print LISTFILE "$uri|$img_type\n"; 202 foreach my $image (@$images) { 203 print LISTFILE "$image->{image}|$img_type\n"; 232 204 } 233 205 close LISTFILE; 234 $command = "$pstamptool -dbname $dbname-addjob -req_id $req_id -job_type get_image"206 my $command = "$pstamptool -addjob -req_id $req_id -job_type get_image" 235 207 . " -uri $listfile -outputBase $out_dir -rownum $rownum"; 208 $command .= " -dbname $dbname" if $dbname; 236 209 if ($mode eq "list_job") { 237 210 print "$command\n"; … … 249 222 $args .= " -class_id $class_id" if ($class_id and ($class_id ne "null")); 250 223 251 # my $numJobs = @uris; 252 my $num = 0; 253 foreach my $uri (@uris) { 254 chomp $uri; 255 256 $num++; 257 my $output_base = "$out_dir/${rownum}_${num}"; 258 $output_base .= "_${stamp_name}" if $stamp_name; 224 # sequence number for the the job for a request spec. Not to be confused with job_id 225 my $job_num = 0; 226 227 # XXX for raw and chip level images and class_id "null" if there are multiple images 228 # use -list instead of -file 229 foreach my $image (@$images) { 230 my $uri = $image->{image}; 231 232 $job_num++; 233 234 my $output_base = "$out_dir/${rownum}_${job_num}"; 235 236 # By commenting out the next line, I hereby drop the use of STAMP_NAME 237 # $output_base .= "_${stamp_name}" if $stamp_name; 238 239 # add astrometry file for raw and chip images if one is available 240 if (($img_type eq "chip") || ($img_type eq "raw")) { 241 $args .= " -astrom $image->{astrom}" if $image->{astrom}; 242 } 243 244 if ($option_mask & $PSTAMP_SELECT_IMAGE) { 245 $args .= " -mask $image->{mask}"; 246 } 247 if ($option_mask & $PSTAMP_SELECT_WEIGHT) { 248 $args .= " -weight $image->{weight}"; 249 } 250 251 # XXX sounds like magic will be handled outside of the postage stamp server 252 #if ($magic_required) { 253 # die "no magic mask available" if ! $image->{magic_mask}; 254 # $args .= " -magic_mask $image->{magic_mask}" 255 #} 256 259 257 260 258 # XXX: TODO: here is where we need to check whether or not the source inputs still exist 261 259 # and if not, queue a regeneration job and set the job state appropriately. 262 # a simpler but slower option would be to set state to 'staged' and have a new task do 263 # the checking. This would add latency to the processing when the images are available. 264 # just share code. 265 266 $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type $job_type" 260 261 262 # # XXX TEMPORARY HACK won't work in general don't commit this 263 # if (($img_type eq "chip") && ($image_db eq "gpc1")) { 264 # my $astrom = $uri; 265 # $astrom =~ s/.ch.fits/.smf/; 266 # if ( -e $astrom ) { 267 # $astrom_args .= " -astrom $astrom"; 268 # } 269 # } 270 271 my $command = "$pstamptool -addjob -req_id $req_id -job_type $job_type" 267 272 . " -uri $uri -outputBase $output_base -args '$args' -rownum $rownum"; 273 $command .= " -dbname $dbname" if $dbname; 274 268 275 if ($mode eq "list_job") { 269 276 # this is a debugging mode, just print the pstamptool that would have run … … 288 295 exit 0; 289 296 297 290 298 # resolve_project() 291 299 # get project specific information … … 308 316 my $ret_dbname; 309 317 my $ret_class_id; 318 my $ret_inst; 319 my $ret_magic; 320 my $ret_camera; 310 321 311 322 if ($project_name eq "megacam-mops") { 312 323 $ret_dbname = "mops"; 313 324 $ret_class_id = "null"; 325 $ret_camera = "MEGACAM"; 326 $ret_magic = 0; 314 327 } elsif ($project_name eq "simtest") { 315 328 $ret_dbname = "simtest"; 316 329 $ret_class_id = "null"; 330 $ret_camera = "SIMTEST"; 331 $ret_magic = 0; 317 332 } elsif ($project_name eq "gpc1") { 318 333 $ret_dbname = "gpc1"; 319 334 $ret_class_id = $class_id; 335 $ret_camera = "GPC1"; 336 $ret_magic = 0; # switch this to 1 when we're ready 320 337 } else { 321 338 die "unknown project $project_name"; … … 327 344 } 328 345 329 return ($ret_dbname, $ret_class_id );330 } 346 return ($ret_dbname, $ret_class_id, $ret_camera, $ret_magic); 347 }
Note:
See TracChangeset
for help on using the changeset viewer.
