Changeset 28003 for branches/pap/ippToPsps/scripts/ippToPsps_run.pl
- Timestamp:
- May 18, 2010, 12:49:05 PM (16 years ago)
- Location:
- branches/pap
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippToPsps/scripts/ippToPsps_run.pl (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/ippToPsps/scripts/ippToPsps_run.pl
r27699 r28003 12 12 13 13 # globals 14 my ($verbose, $save_temps, $no_op, $no_update, $camera, $ product, $output, $dvodb, $label, $singleExpId, $no_publish);14 my ($verbose, $save_temps, $no_op, $no_update, $camera, $batchType, $output, $dvodb, $datastoreProduct, $label, $singleExpId, $no_publish); 15 15 16 16 # TODO temporary until we use database to store current jobid … … 26 26 $output = undef; 27 27 $singleExpId = undef; 28 $datastoreProduct = "PSPS_test"; 28 29 29 30 # get user args 30 31 GetOptions( 31 32 'output|o=s' => \$output, 32 ' product|p=s' => \$product,33 'batch|b=s' => \$batchType, 33 34 'dvodb|d=s' => \$dvodb, 34 35 'label|l=s' => \$label, 35 36 'expid|e=s' => \$singleExpId, 37 'product|p=s' => \$datastoreProduct, 36 38 'no_publish' => \$no_publish, 37 39 'verbose|v' => \$verbose, … … 46 48 pod2usage( 47 49 -msg => "\n Required options:\n\n". 48 "-- product<init|det|diff|stack>\n".50 "--batch <init|det|diff|stack>\n". 49 51 "--output <path>\n". 50 "--label <label> | --expid <expid>\n" . 51 "--dvodb <path>\n\n", 52 "--label <label> or --expid <expid>\n" . 53 "--dvodb <path>\n". 54 "\n Optional:\n\n". 55 "--product <datastoreProduct>\n". 56 "--no_publish - won't publish to datastore\n". 57 "--save_temps - will save temporary files\n". 58 "--no-op - ?\n". 59 "--no-update - will not update database\n", 52 60 -exitval => 3 53 61 ) unless 54 defined $ productand62 defined $batchType and 55 63 defined $output and 56 64 defined $dvodb and … … 68 76 69 77 close $resultsFile; 78 79 ####################################################################################### 80 # 81 # Generates a PSPS-suitable survey 'type' from the IPP distribution group 82 # 83 ####################################################################################### 84 sub getSurveyTypeFromDistGroup { 85 my ($distGroup) = @_; 86 87 if ($distGroup eq "MD01") {return $distGroup;} 88 if ($distGroup eq "MD02") {return $distGroup;} 89 if ($distGroup eq "MD03") {return $distGroup;} 90 if ($distGroup eq "MD04") {return $distGroup;} 91 if ($distGroup eq "MD05") {return $distGroup;} 92 if ($distGroup eq "MD06") {return $distGroup;} 93 if ($distGroup eq "MD07") {return $distGroup;} 94 if ($distGroup eq "MD08") {return $distGroup;} 95 if ($distGroup eq "MD09") {return $distGroup;} 96 if ($distGroup eq "MD10") {return $distGroup;} 97 if ($distGroup eq "M31") {return $distGroup;} 98 if ($distGroup eq "sts") {return "STS";} 99 if ($distGroup eq "SweetSpot") {return "SS";} 100 if ($distGroup eq "3PI") {return $distGroup;} 101 if ($distGroup eq "ThreePi") {return "3PI";} 102 if ($distGroup eq "SAS") {return "3PI";} 103 104 print "* Do not understand distribution group: '$distGroup'\n"; 105 return undef; 106 } 70 107 71 108 ####################################################################################### … … 91 128 92 129 # query to retrieve all exposures with the provided label 93 $query = 94 "SELECT DISTINCT rawExp.exp_id ". 95 "FROM camRun, chipRun, rawExp ". 96 "WHERE camRun.chip_id = chipRun.chip_id ". 97 "AND chipRun.exp_id = rawExp.exp_id ". 98 "AND camRun.label like '%$label%' ". 99 # "AND rawExp.decl >= '-0.157079633' AND rawExp.decl <= '0.157079633' ". # TODO Jim's decl range 100 "ORDER BY rawExp.exp_id ASC"; 130 $query = $db->prepare(<<SQL); 131 132 SELECT DISTINCT rawExp.exp_id, camRun.dist_group 133 FROM camRun, chipRun, rawExp 134 WHERE camRun.chip_id = chipRun.chip_id 135 AND chipRun.exp_id = rawExp.exp_id 136 AND camRun.label LIKE '%$label%' 137 ORDER BY rawExp.exp_id ASC 138 SQL 139 #AND rawExp.exp_id > 136561 140 #AND camRun.dist_group LIKE 'sas' 141 #AND rawExp.decl >= '-0.157079633' AND rawExp.decl <= '0.157079633' Jims Dec range 101 142 } 102 143 else { 103 144 104 $query = "SELECT DISTINCT exp_id FROM rawExp WHERE rawExp.exp_id = $singleExpId"105 106 }107 108 if ($verbose) { print"$query\n";}145 $query = $db->prepare(<<SQL); 146 147 SELECT DISTINCT rawExp.exp_id, dist_group FROM rawExp, chipRun WHERE chipRun.exp_id = rawExp.exp_id AND rawExp.exp_id = $singleExpId 148 SQL 149 } 109 150 110 151 my $batchId = 0; … … 114 155 my $jobId = getJobId(); 115 156 $jobId++; 116 if ($jobId < 0) { print " Cannot find sensible jobId ($jobId)\n";157 if ($jobId < 0) { print "* Cannot find sensible jobId ($jobId)\n"; 117 158 return 0; 118 159 } 119 160 120 print " ------------------------------------------------------------------------------------------\n\n";161 print "*******************************************************************************\n*\n"; 121 162 122 163 my $anyBatches = 0; 123 164 165 166 $query->execute; 167 124 168 # loop round exposures 125 my $expResults = $db->selectall_arrayref( $query ); 126 127 for my $expRow (@$expResults) { 128 129 my ($expId) = @$expRow; 130 131 print " *** Exposure ID = $expId ***\n"; 169 while (my @row = $query->fetchrow_array()) { 170 my ($expId, $distGroup) = @row; 171 172 print "* Exposure ID = $expId with dist group = '$distGroup'\n"; 173 174 my $surveyType = getSurveyTypeFromDistGroup($distGroup); 175 176 if (!$surveyType) {next;} 177 print "* Using survey type of $surveyType\n"; 132 178 133 179 # generate batch and job paths from job and batch IDs … … 137 183 my $batchOutputPath = sprintf("$jobOutputPath/%s", $batchDir); 138 184 139 print " Preparingjob '$job'...\n";185 print "* Preparing exposure $expId as job '$job'...\n"; 140 186 141 187 # make directories 142 188 mkdir($jobOutputPath, 0777); 143 189 mkdir($batchOutputPath, 0777); 190 setJobId($jobId); 144 191 145 192 # run IppToPsps program 146 if (runIppToPsps($db, $expId, $batchOutputPath, $ product)) {193 if (runIppToPsps($db, $expId, $batchOutputPath, $batchType)) { 147 194 148 195 # write batch manifest and tar and zip up 149 if (writeBatchManifest($batchOutputPath, $batchDir, $ product)) {196 if (writeBatchManifest($batchOutputPath, $batchDir, $batchType)) { 150 197 151 198 if (tarAndZipDirectory($jobOutputPath, $batchDir)) { … … 161 208 elsif ($anyBatches) { 162 209 163 if (writeJobManifest($output, $job )) {210 if (writeJobManifest($output, $job, $surveyType)) { 164 211 165 212 if (!$no_publish && !publishToDatastore($output, $job)) { … … 168 215 } 169 216 170 setJobId($jobId);171 217 $jobId++; 172 218 $batchId = 0; … … 175 221 else { 176 222 177 print " No batches to publish\n"223 print "* No batches to publish\n" 178 224 } 179 225 } 180 226 181 if ($product eq "init" ) {print "Wrote initialisation batch\n"; last;} 182 183 184 print "------------------------------------------------------------------------------------------\n\n"; 185 } 227 if ($batchType eq "init" ) {print "* Wrote initialisation batch\n"; last;} 228 229 230 print "*\n*******************************************************************************\n\n"; 231 } 232 233 $db->disconnect(); 186 234 187 235 return 1; … … 204 252 close (MYFILE); 205 253 206 if ($verbose) { print " Current jobId = $jobId\n"; }254 if ($verbose) { print "* Current jobId = $jobId\n"; } 207 255 208 256 return $jobId; … … 221 269 close (MYFILE); 222 270 223 if ($verbose) { print " New jobId = $jobId\n"; }271 if ($verbose) { print "* New jobId = $jobId\n"; } 224 272 } 225 273 … … 230 278 ####################################################################################### 231 279 sub runIppToPsps { 232 my ($db, $expId, $batchOutputPath, $ product) = @_;280 my ($db, $expId, $batchOutputPath, $batchType) = @_; 233 281 234 282 my $success = 0; 235 283 236 284 # before anything else, we can publish the init batch 237 if ($ product=~ /init/) {285 if ($batchType =~ /init/) { 238 286 $success = produceInit($batchOutputPath); 239 287 } 240 elsif ($ product=~ /det/) {288 elsif ($batchType =~ /det/) { 241 289 $success = produceDetections($db, $expId, $batchOutputPath); 242 290 } 243 elsif ($ product=~ /diff/) {291 elsif ($batchType =~ /diff/) { 244 292 $success = produceDiffs($db, $expId, $batchOutputPath); 245 293 } … … 265 313 run(command => $command, verbose => $verbose); 266 314 267 if (!$success) { print " Unable to tar up dir: $batch\n" and return 0 };315 if (!$success) { print "* Unable to tar up dir: $batch\n" and return 0 }; 268 316 269 317 # zip … … 272 320 run(command => $command, verbose => $verbose); 273 321 274 if (!$success) { print " Unable to gzip: $batchTar\n" and return 0 };322 if (!$success) { print "* Unable to gzip: $batchTar\n" and return 0 }; 275 323 276 324 $command = "rm $batchTar"; … … 278 326 run(command => $command, verbose => $verbose); 279 327 280 if (!$success) { print " Unable to remove: $batchTar\n" };328 if (!$success) { print "* Unable to remove: $batchTar\n" }; 281 329 282 330 $command = "rm -r $batchDir"; … … 284 332 run(command => $command, verbose => $verbose); 285 333 286 if (!$success) { print " Unable to remove: $batch\n"};334 if (!$success) { print "* Unable to remove: $batch\n"}; 287 335 288 336 return 1; … … 296 344 sub writeBatchManifest { 297 345 298 my ($path,$batch,$ product) = @_;346 my ($path,$batch,$batchType) = @_; 299 347 300 348 use XML::Writer; … … 311 359 # determine batch 'type' 312 360 my $type; 313 if($ producteq 'init') {$type = "IN";}314 elsif($ producteq 'det') {$type = "P2";}315 elsif ($ producteq 'stack') {$type = "ST";}316 elsif ($ producteq 'diff') {$type = "OB";}361 if($batchType eq 'init') {$type = "IN";} 362 elsif($batchType eq 'det') {$type = "P2";} 363 elsif ($batchType eq 'stack') {$type = "ST";} 364 elsif ($batchType eq 'diff') {$type = "OB";} 317 365 else {$type = "UNKNOWN";} 318 366 … … 325 373 my $maxObjId; 326 374 my $filename; 327 if($ producteq 'det') {375 if($batchType eq 'det') { 328 376 329 377 while (<MYFILE>) { … … 343 391 344 392 # open directory to hunt for FITS files 345 opendir(DIR, $path) or print " Cannot open '$path' to write batch manifest\n" and return 0;393 opendir(DIR, $path) or print "* Cannot open '$path' to write batch manifest\n" and return 0; 346 394 my @thefiles= readdir(DIR); 347 395 closedir(DIR); … … 353 401 if ($f =~ /\.FITS/) { 354 402 355 if ($foundFits) { print " More than one FITS file found for this batch\n"; return 0;}403 if ($foundFits) { print "* More than one FITS file found for this batch\n"; return 0;} 356 404 357 405 # get md5sum of file … … 362 410 363 411 # write manifest element TODO untidy 364 if($ producteq 'det' && $filename eq $f) {412 if($batchType eq 'det' && $filename eq $f) { 365 413 366 414 $writer->startTag('manifest', … … 389 437 #$writer->startTag('md5'); $writer->characters("$md5sum"); $writer->endTag(); 390 438 391 #if($ producteq 'det' && $filename eq $f) {439 #if($batchType eq 'det' && $filename eq $f) { 392 440 393 441 # $writer->startTag('minObjId'); $writer->characters("$minObjId"); $writer->endTag(); … … 404 452 405 453 406 if (!$foundFits) { print " Could not find any FITS files for this batch\n"; return 0;}454 if (!$foundFits) { print "* Could not find any FITS files for this batch\n"; return 0;} 407 455 return 1; 408 456 } … … 414 462 ####################################################################################### 415 463 sub writeJobManifest { 416 my ($path, $job ) = @_;464 my ($path, $job, $surveyType) = @_; 417 465 418 466 use XML::Writer; … … 433 481 $writer->startTag('manifest', 434 482 "name" => "$job", 435 "type" => "3PI", # TODO survey ID483 "type" => $surveyType, 436 484 "timestamp" => "$timeStamp"); 437 485 … … 439 487 440 488 # open directory to hunt for FITS files 441 opendir(DIR, $jobPath) or print " Cannot open '$path' to write job manifest\n" and return 0;489 opendir(DIR, $jobPath) or print "* Cannot open '$path' to write job manifest\n" and return 0; 442 490 my @thefiles= readdir(DIR); 443 491 closedir(DIR); … … 472 520 $writer->end(); 473 521 474 if (!$foundBatch) { print " Could not find any batches for this job\n"; return 0;}522 if (!$foundBatch) { print "* Could not find any batches for this job\n"; return 0;} 475 523 return 1; 476 524 } … … 489 537 490 538 # loop through all batch files in this job directory 491 opendir(DIR, $fullJobPath) or print " Cannot open '$fullJobPath' in order to publish to datastore\n" and return 0;539 opendir(DIR, $fullJobPath) or print "* Cannot open '$fullJobPath' in order to publish to datastore\n" and return 0; 492 540 my @thefiles= readdir(DIR); 493 541 closedir(DIR); … … 512 560 $command .= " --datapath $fullJobPath"; 513 561 $command .= " --type IPP_PSPS"; 514 $command .= " --product PSPS_test";562 $command .= " --product $datastoreProduct"; 515 563 $command .= " --list $tempName"; 516 564 … … 519 567 run(command => $command, verbose => $verbose); 520 568 521 if (!$success) { print " Unable to publish $job to datastore\n" and return 0 };522 523 print " Successfully published $job to datastore\n";569 if (!$success) { print "* Unable to publish $job to datastore\n" and return 0 }; 570 571 print "* Successfully published $job to datastore\n"; 524 572 525 573 close($tempFile); … … 536 584 my ($outputPath) = @_; 537 585 538 my $success = runProgram( "NULL", $outputPath, 0, $ product);586 my $success = runProgram( "NULL", $outputPath, 0, $batchType); 539 587 return $success; 540 588 } … … 558 606 "WHERE rawExp.exp_id = $expId AND camRun.magicked"; 559 607 560 if ($verbose) { print" $query\n";}608 if ($verbose) { print"* $query\n";} 561 609 562 610 … … 564 612 my $results = $db->selectall_arrayref( $query ); 565 613 my $size = @$results; 566 if ($size < 1) {print " No smf files found for this exposure\n"; return 0;}614 if ($size < 1) {print "* No smf files found for this exposure\n"; return 0;} 567 615 568 616 # loop round db results TODO should only be one result … … 580 628 close $tempFile; 581 629 582 $success = runProgram($tempName, $outputPath, $expId, $ product);630 $success = runProgram($tempName, $outputPath, $expId, $batchType); 583 631 return $success; 584 632 } … … 604 652 "WHERE rawExp.exp_id = $expId AND camRun.magicked"; 605 653 606 if ($verbose) { print" $query\n";}654 if ($verbose) { print"* $query\n";} 607 655 608 656 # execute query and check results 609 657 my $results = $db->selectall_arrayref( $query ); 610 658 my $size = @$results; 611 if ($size < 1) {print " No cmf files found for this exposure\n"; return 0;}659 if ($size < 1) {print "* No cmf files found for this exposure\n"; return 0;} 612 660 613 661 my ($tempFile, $tempName) = tempfile( "inputFileList.XXXX", UNLINK => !$save_temps); … … 629 677 } 630 678 631 my $ret = runProgram($tempName, $outputPath, $expId, $ product);679 my $ret = runProgram($tempName, $outputPath, $expId, $batchType); 632 680 633 681 close $tempFile; … … 642 690 ####################################################################################### 643 691 sub runProgram { 644 my ($input, $output, $expid, $ product) = @_;692 my ($input, $output, $expid, $batchType) = @_; 645 693 646 694 # build command … … 651 699 $command .= " -config config"; # TODO 652 700 $command .= " -expid $expid"; 653 $command .= " - product $product";701 $command .= " -batch $batchType"; 654 702 $command .= " -results $resultsFileName"; 655 703
Note:
See TracChangeset
for help on using the changeset viewer.
