Changeset 18541
- Timestamp:
- Jul 15, 2008, 10:06:26 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/scripts/pstampparse.pl (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstampparse.pl
r18380 r18541 17 17 my $request_file_name; 18 18 my $mode = "list_uri"; 19 my $out_dir = "."; 19 my $out_dir; 20 my $product; 20 21 21 22 # values for COORD_MASK … … 24 25 25 26 # values for OPTION_MASK 26 use constant PSTAMP_SELECT_IMAGE => 1;27 use constant PSTAMP_SELECT_MASK => 2;27 use constant PSTAMP_SELECT_IMAGE => 1; 28 use constant PSTAMP_SELECT_MASK => 2; 28 29 use constant PSTAMP_SELECT_WEIGHT => 4; 29 30 … … 32 33 'req_id=s' => \$req_id, 33 34 'out_dir=s' => \$out_dir, 35 'product=s' => \$product, 34 36 'mode=s' => \$mode, 35 37 'dbname=s' => \$dbname, … … 37 39 ); 38 40 39 die "req_id is required" if !defined($req_id); 41 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")); 40 43 die "file is required" if !defined($request_file_name); 41 44 die "out_dir is required" if !defined($out_dir); 42 43 die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "list_job") or ($mode eq "queue_job"); 45 die "product is required" if !defined($product); 46 44 47 45 48 use IPC::Cmd 0.36 qw( can_run run ); … … 66 69 67 70 my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools = 1); 68 my $ pstampparse= can_run('pstampparse') or (warn "Can't find pstampparse" and $missing_tools = 1);71 my $lookup_images = can_run('pstampparse') or (warn "Can't find pstampparse" and $missing_tools = 1); 69 72 my $pstampdump = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1); 73 my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1); 70 74 71 75 if ($missing_tools) { … … 77 81 78 82 # 79 # convert the request table to an array of metadata config docs 80 # 81 # TODO: check the header for the correct EXTNAME 83 # get the data from the extension header 84 # 85 my $fields_output; 86 { 87 my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME"; 88 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 89 run(command => $command, verbose => $verbose); 90 unless ($success) { 91 print STDERR @$stderr_buf; 92 } 93 $fields_output = join "", @$stdout_buf; 94 } 95 my (undef, $extname, $extver, $req_name) = split " ", $fields_output; 96 97 # make sure the file contains what we are expecting 98 99 die "$request_file_name is not a PS1_PS_REQEST" if $extname ne "PS1_PS_REQUEST"; 100 die "REQ_NAME not found in $request_file_name" if (!$req_name); 101 die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1"); 102 103 $out_dir .= "/$req_name"; 104 if (! -e $out_dir ) { 105 mkdir $out_dir or die "cannot create output directory $out_dir"; 106 } elsif (! -d $out_dir ) { 107 die "output fileset directory $out_dir exists but is not a directory"; 108 } 109 110 { 111 my $command = "$pstamptool -processedreq -req_id $req_id -name $req_name -outProduct $product"; 112 $command .= " -dbname $dbname"; 113 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 114 run(command => $command, verbose => $verbose); 115 unless ($success) { 116 die "$command failed"; 117 } 118 } 119 120 # 121 # now convert the request table to an array of metadata config docs 82 122 # 83 123 … … 96 136 } 97 137 98 # TODO: Make sure that the output directory exists99 100 138 foreach my $row (@$rows) { 139 my $rownum = $row->{ROWNUM}; 101 140 my $job_type = $row->{JOB_TYPE}; 102 141 my $project = $row->{PROJECT}; … … 105 144 my $id = $row->{ID}; 106 145 my $class_id = $row->{CLASS_ID}; 107 my $stamp_select = $row->{STAMP_SELECT};108 146 my $stamp_name = $row->{STAMP_NAME}; 109 147 my $filter = $row->{FILTER}; … … 117 155 my $option_mask= $row->{OPTION_MASK}; 118 156 157 # XXX: TODO: don't die in this loop. If we encounter an error add a job with the proper fault 158 # code 159 # todo this needs some implementation work 160 die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri"); 161 162 # TODO: sanity check all arguments 163 164 my ($image_db, $lookup_class_id ) = resolve_project($project, $img_type, $class_id); 165 119 166 my $roi_string; 120 167 # XXX we're depending on other code to insure valid values for roi components 121 168 # this is checked in pstamprequest and ppstamp 122 # arguablyI should check here to but not today169 # I should check here to but not today 123 170 if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) { 124 171 if ($coord_mask & PSTAMP_CENTER_IN_PIXELS) { … … 140 187 if (($job_type eq "stamp") && !defined($roi_string)); 141 188 142 my $args = $roi_string ? $roi_string : "";143 144 189 # find the uris for this request 145 190 … … 147 192 # images/runs and prints out the uri and other metadata as a metadata config doc 148 193 149 my $command = "$pstampparse -dbname $project -$req_type $img_type $id $class_id"; 194 my $command = "$lookup_images -dbname $image_db -$req_type $img_type $id $lookup_class_id"; 195 150 196 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 151 197 run(command => $command, verbose => $verbose); 152 198 unless ($success) { 153 199 print STDERR @$stderr_buf; 200 exit 1; 154 201 } 155 202 my @uris = split "^", join("", @$stdout_buf); 156 203 157 foreach my $uri (@uris) { 158 chomp $uri; 159 if ($mode eq "list_uri") { 160 print "$uri\n"; 204 if ($mode eq "list_uri") { 205 foreach my $uri (@uris) { 206 print $uri; 207 } 208 } elsif ($job_type eq "get_image") { 209 my $listfile = "$out_dir/filelist"; 210 211 open LISTFILE, ">$listfile" 212 or die "failed to open file list: $listfile while parsing get_image request $req_id"; 213 214 # XXX TODO: how do we expand URIS to include wt and mk images 215 # I've been assuming that ppstamp would just know what to do based on flags and file rules. 216 # Actually if we change the code that lists images to list outputBase's instead we can 217 # translate the rules here 218 foreach my $uri (@uris) { 219 chomp $uri; 220 print LISTFILE "$uri|$img_type\n"; 221 } 222 close LISTFILE; 223 $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type get_image" 224 . " -uri $listfile -outputBase $out_dir -rownum $rownum"; 225 if ($mode eq "list_job") { 226 print "$command\n"; 161 227 } else { 162 163 # TODO: here is where we need to check whether or not the source image still exists 164 # and queue a regeneration job. Also remove streaks here ??? 228 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 229 run(command => $command, verbose => $verbose); 230 unless ($success) { 231 print STDERR @$stderr_buf; 232 # XXX TODO: now what? Should we mark the error state for the request? 233 die "failed to queue job for request $req_id: rownum: $rownum"; 234 } 235 } 236 } else { 237 my $args = $roi_string ? $roi_string : ""; 238 $args .= " -class_id $class_id" if ($class_id and ($class_id ne "null")); 239 240 # my $numJobs = @uris; 241 my $num = 0; 242 foreach my $uri (@uris) { 243 chomp $uri; 244 245 $num++; 246 my $output_base = "$out_dir/${rownum}_${num}_${stamp_name}"; 247 248 # XXX: TODO: here is where we need to check whether or not the source inputs still exist 249 # and if not, queue a regeneration job and set the job state appropriately. 250 # a simpler but slower option would be to set state to 'staged' and have a new task do 251 # the checking. This would add latency to the processing when the images are available. 252 # just share code. 165 253 166 254 $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type $job_type" 167 . " -uri $uri -outputBase $out _dir/$stamp_name -args '$args'";255 . " -uri $uri -outputBase $output_base -args '$args' -rownum $rownum"; 168 256 if ($mode eq "list_job") { 169 257 # this is a debugging mode, just print the pstamptool that would have run … … 179 267 # should we keep going for other uris? If so how do we report that some 180 268 # of the work that the request wanted isn't going to get done 181 die "failed to queue job ";269 die "failed to queue job for request $req_id"; 182 270 } 183 271 } … … 188 276 exit 0; 189 277 278 # resolve_project() 279 # get project specific information 280 # This is a placeholder final implementation will use configuration file and database to 281 # map from "project" to image database, dvo database, telescope, camera, etc 282 # 283 # For now just get the database and the class_id that will be used for image lookup 284 285 sub resolve_project { 286 my $project_name = shift; 287 my $img_type = shift; 288 my $class_id = shift; 289 die "project is not defined" if !$project_name; 290 291 # for megacam and simtest since images are at the fpa level, leave out the 292 # class_id at the lookup stage 293 # 294 # TODO: get this information from a database or a configuration file 295 296 my $ret_dbname; 297 my $ret_class_id; 298 299 if ($project_name eq "megacam-mops") { 300 $ret_dbname = "mops"; 301 $ret_class_id = "null"; 302 } elsif ($project_name eq "simtest") { 303 $ret_dbname = "simtest"; 304 $ret_class_id = "null"; 305 } elsif ($project_name eq "gpc1") { 306 $ret_dbname = "gpc1"; 307 $ret_class_id = $class_id; 308 } else { 309 die "unknown project $project_name"; 310 } 311 312 if (($img_type ne "raw") and ($img_type ne "chip")) { 313 # don't need class_id 314 $ret_class_id = ""; 315 } 316 317 return ($ret_dbname, $ret_class_id); 318 }
Note:
See TracChangeset
for help on using the changeset viewer.
