Changeset 19265
- Timestamp:
- Aug 28, 2008, 2:06:45 PM (18 years ago)
- Location:
- trunk/pstamp/scripts
- Files:
-
- 4 edited
-
pstamp_finish.pl (modified) (7 diffs)
-
pstamp_parser_run.pl (modified) (5 diffs)
-
pstamp_queue_requests.pl (modified) (4 diffs)
-
pstampparse.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_finish.pl
r19221 r19265 9 9 use Pod::Usage qw( pod2usage ); 10 10 11 use Time::Local; 11 12 use Sys::Hostname; 12 13 use IPC::Cmd 0.36 qw( can_run run ); … … 82 83 } 83 84 84 85 # this function is PStamp::RequestFile::read_request_file 85 if (! -e $req_file ) { 86 print STDERR "request file $req_file is missing\n"; 87 stop_request($req_id, $PS_EXIT_CONFIG_ERROR, $dbname); 88 exit $PS_EXIT_CONFIG_ERROR; 89 } 90 91 # this function is PStamp::RequestFile::read_request_file 86 92 my ($header, $rows) = read_request_file($req_file); 87 93 88 die "failed to read request_file $req_file" if !$header or !$rows; 94 if (!$header or !$rows) { 95 # Since a request got queued, the request file must have been readable at some 96 # point 97 print STDERR "failed to read request_file $req_file" 98 stop_request($req_id, $PS_EXIT_CONFIG_ERROR, $dbname); 99 exit $PS_EXIT_CONFIG_ERROR; 100 } 89 101 90 102 # at this point we need to find out what kind of request type it is and … … 144 156 my $rownum = $job->{rownum}; 145 157 my $fault = $job->{fault}; 146 147 my $row_info = get_request_info($rows, $rownum); 148 # rownum fault img_name job_id 158 my $exp_id = $job->{exp_id}; 159 160 # XXX: get the image_db from a table in the database, or maybe save it in the job 161 my $image_db = "ps_simtest"; 162 my $exp_info = get_exposure_info($image_db, $exp_id); 163 164 # unless $exp_id is null (e.g. stack images) get the metadata for this exposure 165 my ($row, $req_info) = get_request_info($rows, $rownum) if $exp_id; 166 149 167 if (($job_type eq "stamp") || ($job_type eq "get_image")) { 150 168 my $jreglist = "$out_dir/reglist$job_id"; … … 158 176 my ($img_name, undef) = split '\|', $line; 159 177 160 # XXX TODO: need to get these from somewhere. Maybe the stamp.161 #162 # ra_deg and dec_deg are the coordinates of center of the stamp163 # the rest of the metadata come from the original FPA.164 # we could get these out of the rawExp table in the database....165 #166 # Much of those data do not apply to stamps from Stack images.167 my ($ra_deg, $dec_deg, $mjd_obs, $ra_obs, $dec_obs, $filter, $exp_time, $fpa_id) =168 (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );169 170 178 # add line to the table definition file 171 179 print $tdf "$rownum|$fault|$img_name|$job_id|"; 172 print $tdf "$ra_deg|$dec_deg|$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id|"; 173 print $tdf "$row_info"; 180 181 # ra_deg and dec_deg are the coordinates of center of the stamp 182 # 183 # XXX we need to get the center coordinate of the stamp. 184 # if request used -skycenter then we have it in the request info 185 186 print $tdf "0.0|0.0|"; 187 print $tdf "$exp_info|"; 188 print $tdf "$req_info|"; 174 189 print $tdf "\n"; 175 190 } … … 178 193 print STDERR "no reglist file for job $job_id\n" if $verbose; 179 194 print $tdf "$rownum|$fault|0|$job_id|"; 180 print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n"; 195 print $tdf "0|0|"; # center of (non-existent) stamp 196 print $tdf "$exp_info|"; 197 print $tdf "$req_info|"; 181 198 } 182 199 } else { 183 200 # XXX do list jobs 201 # we can probably arange things to use the code as above and skip the fileset registration 184 202 print STDERR "Unknown jobType: $job_type"; 185 203 next; … … 226 244 } 227 245 } 246 228 247 sub stop_request { 229 248 my $req_id = shift; … … 252 271 $rowinfo .= "$row->{ID}|$row->{CLASS_ID}|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|"; 253 272 $rowinfo .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|"; 254 $rowinfo .= "$row->{WIDTH}|$row->{HEIGHT}|"; 255 256 return $rowinfo; 257 } 273 $rowinfo .= "$row->{WIDTH}|$row->{HEIGHT}"; 274 275 return ($row, $rowinfo); 276 } 277 278 sub get_exposure_info { 279 my $image_db= shift; 280 my $exp_id = shift; 281 282 if (!$exp_id) { 283 # no exposure id just return zeros 284 # XXX: we could put a value in for filter, but we don't have a good place to find it 285 286 #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id"; 287 return "0|0|0|0|0|0"; 288 } 289 290 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1); 291 if ($missing_tools) { 292 warn("Can't find required tools."); 293 exit ($PS_EXIT_CONFIG_ERROR); 294 } 295 296 my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id"; 297 298 # run the tool and parse the output 299 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 300 run(command => $command, verbose => $verbose); 301 unless ($success) { 302 # not sure if we should die here 303 die "cannot get exposure information for $exp_id from image database $image_db"; 304 } 305 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 306 307 my $output = join "", @$stdout_buf; 308 if (!$output) { 309 print STDERR "no output returned from $command\n" if $verbose; 310 return undef; 311 } 312 my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc"); 313 314 my $exposures = parse_md_list($metadata); 315 my $numExp = @$exposures; 316 317 die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1; 318 319 my $exp = $exposures->[0]; 320 321 #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id"; 322 323 use constant RADIANS_TO_DEGREES => 90. / atan2(1, 0); 324 my $ra_deg = $exp->{ra} * RADIANS_TO_DEGREES; 325 my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES; 326 my $mjd_obs = dateobs_to_mjd($exp->{dateobs}, $exp->{exp_time}); 327 328 my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}"; 329 330 return $info; 331 } 332 333 sub dateobs_to_mjd { 334 my $dateobs = shift; 335 my $exp_time = shift; 336 337 # dateobs is in format: 1970-01-01T00:00:00 338 339 my ($date, $time) = split "T", $dateobs; 340 my ($year, $mon, $day) = split "-", $date; 341 my ($hr, $min, $sec) = split ":", $time; 342 343 my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900); 344 345 $ticks += $exp_time / 2.0; 346 347 return 40587.0 + ($ticks/86400.); 348 } -
trunk/pstamp/scripts/pstamp_parser_run.pl
r19221 r19265 3 3 ### pstampparser_run.pl 4 4 ### Run the request parser for a given request id 5 ### This script should be called request_parser.pl since it handles more than postage 6 ### stamp requests 5 7 ### 6 7 #XXX see notes about error handling8 8 9 9 use warnings; … … 172 172 if (! -d $outProductDir); 173 173 174 175 # run the appropriate parse command to parse the queue the jobs for this request176 # first check the extension header to find the EXTNAME177 my $request_type = find_request_type($uri);178 179 print STDERR "request_type for $req_id is $request_type\n" if $verbose;180 181 174 my $parse_cmd; 175 my $request_type; 182 176 my $reqType; # for the database 183 if ($request_type eq "PS1_PS_REQUEST") { 184 $reqType = 'pstamp'; 185 $parse_cmd = $pstampparse; 186 } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") { 187 $reqType = 'dquery'; 188 $parse_cmd = $dqueryparse; 177 178 if (-r $uri) { 179 # run the appropriate parse command to parse the queue the jobs for this request 180 # first check the extension header to find the EXTNAME 181 $request_type = find_request_type($uri); 182 183 if ($request_type) { 184 print STDERR "request_type for $req_id is $request_type\n" if $verbose; 185 if ($request_type eq "PS1_PS_REQUEST") { 186 $reqType = 'pstamp'; 187 $parse_cmd = $pstampparse; 188 } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") { 189 $reqType = 'dquery'; 190 $parse_cmd = $dqueryparse; 191 } else { 192 print STDERR "Unknown request type $request_type found in $uri"; 193 } 194 } else { 195 print STDERR "No EXTNAME found keyword in $uri"; 196 } 197 } else { 198 if (-e $uri) { 199 print STDERR "Request file $uri is not readable"; 200 } else { 201 print STDERR "Request file $uri does not exist"; 202 } 189 203 } 190 204 191 205 if (!$parse_cmd) { 192 print STDERR "No EXTNAME found in $uri" if !$request_type; 193 print STDERR "Unknown request type $request_type found in $uri"; 206 # can't go any farther, set fault and set request state to run 207 # request_finish.pl will clean up, perhaps notifiying the operator of the input data store 208 # that they sent us a request file that we don't understand 194 209 195 210 my $command = "$pstamptool -updatereq -req_id $req_id -state run"; … … 211 226 { 212 227 my $error_file_name = "$workdir/parse_error.txt"; 213 # get rid of any error file from previous run228 # get rid of any error file from previous attempt to parse this request 214 229 unlink $error_file_name if (-e $error_file_name); 215 230 … … 219 234 220 235 # save the contents of stderr (if any) to a file. This is relevant if 221 # the file parsed properl but one of the rows in the request file generated an error236 # the file was parseable but one or more of the rows in the request file generated an error 222 237 my $errbuf = join "", @$stderr_buf; 223 238 if ($errbuf) { … … 258 273 exit 0; 259 274 275 260 276 sub find_request_type { 261 277 # find the EXTNAME in the input fits table 262 # TODO: do this right handling errors etc.263 278 my $file_name = shift; 264 279 my $out = `echo $file_name | fields -x 0 EXTNAME`; 265 280 266 # output from fields is filename value 267 my ($dummy, $extname) = split " ", $out; 268 269 return $extname; 270 } 281 if ($out) { 282 # output from fields is filename value 283 my ($dummy, $extname) = split " ", $out; 284 285 return $extname; 286 } else { 287 return undef; 288 } 289 } -
trunk/pstamp/scripts/pstamp_queue_requests.pl
r18623 r19265 22 22 'verbose' => \$verbose, 23 23 'dbname=s' => \$dbname, 24 'limit= s' => \$limit,24 'limit=i' => \$limit, 25 25 ); 26 26 … … 119 119 my $out_buf = join("", @$stdout_buf); 120 120 # split raw output into lines 121 # XXX: why do I think that i need the map?122 #my @lines = map {split "\n"} $raw_output;123 121 @lines = split /^/, $out_buf; 124 122 } … … 127 125 # each line contains a fileset 128 126 # 129 # XXX: we probably should set a limit on the number of these we process 130 # otherwise this could take a long time and the task could time out 127 128 # number that we've processed 129 my $numFilesets = 0; 131 130 foreach my $line (@lines) { 132 131 # parse the line into fields split by whitespace 133 132 my ($uri, $fs_name, $date, $type) = split " ", $line; 134 133 134 # skip comment lines 135 135 next if ( $uri =~ /^#.*/); 136 137 $numFilesets++; 136 138 137 139 my @files; … … 163 165 my $command = "$pstamptool -addreq -uri $req_uri -ds_id $ds_id"; 164 166 $command .= " -dbname $dbname" if $dbname; 167 165 168 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 166 169 run(command => $command, verbose => $verbose); 167 unless ($success) { 168 # XXX: what do we do now?169 die("Unable to perform $command: $error_code");170 }170 171 unless ($success) { 172 die("Unable to perform $command: $error_code"); 173 } 171 174 } 172 $lastFileset = $fs_name;173 175 } 176 $lastFileset = $fs_name; 177 last if ($numFilesets >= $limit); 174 178 } 175 179 176 180 ## now update the last_fileset column in pstampDataStore 177 ## XXX: we should probably do this before we process the fileset. Otherwise 178 ## if we get an error from pstamptool we'll get stuck processing it over and over. 181 ## XXX: we should perhaps do this while processing each fileset so that if a later 182 ## one has an error we don't get repeats. 183 179 184 if ($lastFileset) { 180 185 # print "last fileset: $lastFileset\n"; -
trunk/pstamp/scripts/pstampparse.pl
r19224 r19265 53 53 54 54 my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools = 1); 55 my $locateimages = can_run('locateimages') or (warn "Can't find locateimages" and $missing_tools = 1);56 55 my $pstampdump = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1); 57 56 my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
Note:
See TracChangeset
for help on using the changeset viewer.
