- Timestamp:
- Aug 19, 2010, 6:50:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/ippToPsps/perl/ippToPsps_run.pl
r28794 r28980 6 6 use PS::IPP::Config 1.01 qw( :standard ); 7 7 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 8 use Pod::Usage qw( pod2usage );9 8 use IPC::Cmd 0.36 qw( can_run run ); 10 9 use File::Temp qw(tempfile); 11 10 use XML::LibXML; 11 use File::Basename; 12 12 13 13 # local classes 14 14 use ippToPsps::Gpc1Db; 15 15 use ippToPsps::IppToPspsDb; 16 use ippToPsps::Datastore; 16 17 17 18 # globals 18 19 my $camera = 'GPC1'; 19 20 my $batchType = undef; 20 my $survey = undef; 21 my $dvodb = undef; 21 my $dvoLocation = undef; 22 my $dvoDb = undef; 23 my $fullDvoPath = undef; 22 24 my $verbose = undef; 23 25 my $save_temps = undef; 24 my $no_update = undef;25 26 my $output = undef; 26 27 my $singleExpId = undef; … … 34 35 'output|o=s' => \$output, 35 36 'batch|b=s' => \$batchType, 36 'dvodb|d=s' => \$dvodb, 37 'survey|s=s' => \$survey, 37 'dvo|d=s' => \$fullDvoPath, 38 38 'expid|e=s' => \$singleExpId, 39 39 'product|p=s' => \$datastoreProduct, 40 40 'verbose|v' => \$verbose, 41 41 'save_temps|t' => \$save_temps, 42 'no-update|u' => \$no_update,43 42 'force|f' => \$force, 44 43 'tarnzip|z' => \$dontTarNZip, … … 49 48 print "* \n"; 50 49 if (@ARGV) { 51 print "* UNKNKOWN: option: @ARGV\n"; $quit=1;} 50 $quit=1; 51 print "* UNKNKOWN: option @ARGV\n"; 52 } 52 53 if (!defined $output) { 53 print "* REQUIRED: need to provide an output path: -o <path>\n"; $quit=1;} 54 $quit=1; 55 print "* REQUIRED: need to provide an output path -o <path>\n"; 56 } 54 57 if (!defined $batchType) { 55 print "* REQUIRED: need to define a batch type: -b <init|det|diff|stack>\n"; $quit=1;} 56 if (!defined $dvodb) { 57 print "* REQUIRED: need to provide a DVO Db path: -d <path>\n"; $quit=1;} 58 if (!defined $survey and !defined $singleExpId) { 59 print "* REQUIRED: need to provide a survey type: -s <ThreePi|STS|SAS|M31|MD01|MD02|etc> ***OR***\n"; 60 print "* an exposure ID -e <expID>\n"; $quit=1;} 58 $quit=1; 59 print "* REQUIRED: need to define a batch type -b <init|det|diff|stack>\n"; 60 } 61 if (!defined $fullDvoPath) { 62 $quit=1; 63 print "* REQUIRED: need to provide a DVO Db -d <pathToDVO>\n"; 64 } 65 if (!defined $singleExpId) { 66 67 print "* OPTIONAL: a single exposure ID -e <expID> (default = none)\n"; 68 } 61 69 if (!defined $datastoreProduct) { 62 print "* OPTIONAL: datastore product: -p <product>\n";} 70 71 print "* OPTIONAL: datastore product -p <product> (default = none, i.e. data will not be published)\n"; 72 } 63 73 if (!defined $verbose) { 64 print "* OPTIONAL: run in verbose mode: -v\n"; $verbose = 0;} 74 $verbose = 0; 75 print "* OPTIONAL: run in verbose mode -v (default = $verbose)\n"; 76 } 65 77 if (!defined $save_temps) { 66 print "* OPTIONAL: keep temp files: -t\n"; $save_temps = 0;}67 if (!defined $no_update) { 68 print "* OPTIONAL: don't update database: -u\n"; $no_update = 0;}78 $save_temps = 0; 79 print "* OPTIONAL: keep temp files -t (default = $save_temps)\n"; 80 } 69 81 if (!defined $force) { 70 print "* OPTIONAL: force if already processed : -f\n"; $force = 0;} 82 $force = 0; 83 print "* OPTIONAL: force if already processed -f (default = $force)\n"; 84 } 71 85 if (!defined $dontTarNZip) { 72 print "* OPTIONAL: don't tar and zip output : -z\n"; $dontTarNZip = 0;} 73 print "*\n*******************************************************************************\n"; 86 $dontTarNZip = 0; 87 print "* OPTIONAL: don't tar and zip output -z (default = $dontTarNZip)\n"; 88 } 89 print "*\n*******************************************************************************\n"; 74 90 75 91 if ($quit) { exit; } 92 93 # determine PSPS batch 'type' 94 my $pspsBatchType; 95 if ($batchType eq 'init') {$pspsBatchType = "IN";} 96 elsif ($batchType eq 'det') {$pspsBatchType = "P2";} 97 elsif ($batchType eq 'stack') {$pspsBatchType = "ST";} 98 elsif ($batchType eq 'diff') {$pspsBatchType = "OB";} 99 else {$pspsBatchType = "UNKNOWN";} 100 101 # spilt full DVO path into Db and path 102 $fullDvoPath =~ s/\/$//; # strip off trailing '\' 103 ($dvoDb, $dvoLocation) = fileparse($fullDvoPath); 76 104 77 105 my $gpc1Db = new ippToPsps::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser", $verbose, $save_temps); 78 106 my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps); 107 my $datastore = undef; 108 if ($datastoreProduct) {$datastore = new ippToPsps::Datastore($datastoreProduct, $verbose, $save_temps);} 79 109 80 110 # check we can run programs and get camera config 81 111 my $ippToPsps = can_run('ippToPsps') or (warn "Can't find 'ippToPsps' program" and exit($PS_EXIT_CONFIG_ERROR)); 82 my $dsreg = can_run('dsreg') or (warn "Can't find 'dsreg' program" and exit($PS_EXIT_CONFIG_ERROR));83 112 my $ipprc = PS::IPP::Config->new($camera) or (warn "Can't get camera configuration" and exit($PS_EXIT_CONFIG_ERROR)); 84 113 85 114 if ($batchType eq "init") {$initBatch = 1;} 86 115 else {$initBatch = 0;} 87 process(); 116 117 if (!process()) {print "* Finished unsuccessfully\n";} 118 else {print "* Finished successfully\n";} 88 119 89 120 ####################################################################################### … … 114 145 my ($resultsFile, $resultsFilePath) = tempfile( "/tmp/ippToPsps_results.XXXX", UNLINK => !$save_temps); 115 146 my $lastExpId = $ippToPspsDb->getLastExpId(); 116 my $ rows = undef;147 my $exposures; 117 148 118 149 my $query; 119 150 if ($initBatch) { 120 121 my @row = (0, 'NULL', 'ThreePi'); 122 @{$rows} = (\@row); 123 } 124 elsif ($singleExpId) { $rows = $gpc1Db->getExposureListFromExpId($singleExpId); } 125 else { $rows = $gpc1Db->getExposureListFromSurvey($survey); } 126 127 # TODO check if there are no exposures and give a warning 151 152 my @exposure = (0, 'NULL', 'ThreePi'); 153 @{$exposures} = (\@exposure); 154 } 155 # get single exposure 156 elsif ($singleExpId) { 157 158 if (!$gpc1Db->getSingleExposureFromDvoDb($dvoDb, $singleExpId, \$exposures)) {return 0;} 159 } 160 # get all exposures in this DVO Db 161 else { 162 163 if (!$gpc1Db->getExposureListFromDvoDb($dvoDb, \$exposures)) {return 0;} 164 } 128 165 129 166 my $batchId = 0; … … 132 169 133 170 #my $batchId = -1; 134 my $row; 135 foreach $row ( @{$rows} ) { 136 my ($expId, $expName, $distGroup) = @{$row}; 137 # print "JHGHGHGHGH2 $expId, $expName, $distGroup\n"; 138 139 # loop round exposures 140 #while (my @row = $query->fetchrow_array()) { 141 # my ($expId, $expName, $distGroup) = @row; 171 my $exposure; 172 foreach $exposure ( @{$exposures} ) { 173 my ($expId, $expName, $distGroup) = @{$exposure}; 142 174 143 175 if (!$initBatch && $ippToPspsDb->isExposureAlreadyProcessed($expId)) { 144 145 if ($force) {print "* Forcing....\n";}146 else {next};176 177 if ($force) {print "* Forcing....\n";} 178 else {next}; 147 179 } 148 180 … … 150 182 if (!$surveyType) {next;} 151 183 152 $batchId = $ippToPspsDb-> getNewBatchId($expId, $surveyType, $batchType);184 $batchId = $ippToPspsDb->createNewBatch($expId, $distGroup, $pspsBatchType, $dvoDb, (defined $datastore) ? $datastoreProduct : "NONE"); 153 185 154 186 # TODO quit here if no sensible batch ID … … 156 188 # generate batch path from batch IDs 157 189 my $batch = sprintf("B%08d", $batchId); 158 my $batchDir = sprintf("$output/$batch"); 190 my $dvoDir = "$output/$dvoDb"; 191 my $batchDir = "$dvoDir/$batch"; 192 193 # make directories 194 unless(-d $dvoDir) {mkdir($dvoDir, 0777);} 159 195 mkdir($batchDir, 0777); 196 160 197 $published = 0; 161 198 … … 171 208 if (writeBatchManifest($batchDir, $batch, $batchType, $surveyType, $filename, $minObjId, $maxObjId)) { 172 209 210 # tar n' zip 173 211 if (!$dontTarNZip) { 174 my $tarball = tarAndZipBatch($output, $batch); 175 if ($tarball && $datastoreProduct && publishToDatastore($batch, $output, $tarball)) {$published = 1;} 212 my $tarball = tarAndZipBatch($dvoDir, $batch); 213 214 # and publish 215 if ($tarball && defined $datastore ) { 216 217 $published = $datastore->register($batch, $dvoDir, $tarball, "IPP_PSPS", "tgz"); 218 } 176 219 } 177 220 } 178 221 179 $ippToPspsDb->update Db($batchId, $expId, 1, $published, $totalDetections);222 $ippToPspsDb->updateBatch($batchId, $expId, 1, $published, $totalDetections, $minObjId, $maxObjId); 180 223 } 181 224 … … 330 373 my $timeStamp = sprintf "%4d-%02d-%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec; 331 374 332 # determine batch 'type'333 my $type;334 if ($batchType eq 'init') {$type = "IN";}335 elsif ($batchType eq 'det') {$type = "P2";}336 elsif ($batchType eq 'stack') {$type = "ST";}337 elsif ($batchType eq 'diff') {$type = "OB";}338 else {$type = "UNKNOWN";}339 340 375 # create XML file 341 376 my $writer = new XML::Writer(OUTPUT => $output, DATA_MODE => 1, DATA_INDENT=>2); … … 372 407 $writer->startTag('manifest', 373 408 "name" => "$batch", 374 "type" => $ type,409 "type" => $pspsBatchType, 375 410 "survey" => $pspsSurvey, 376 411 "timestamp" => "$timeStamp", … … 382 417 $writer->startTag('manifest', 383 418 "name" => "$batch", 384 "type" => $ type,419 "type" => $pspsBatchType, 385 420 "timestamp" => "$timeStamp"); 386 421 } … … 404 439 405 440 ####################################################################################### 406 #407 # register new job with the datastore408 #409 ########################################################################################410 sub publishToDatastore {411 my ($batch, $path, $tarball) = @_;412 413 my ($tempFile, $tempName) = tempfile( "/tmp/ippToPsps_dsregList.XXXX", UNLINK => !$save_temps);414 415 print $tempFile $tarball . '|||tgz' . "\n";416 417 # build dsreg command command418 my $command = "$dsreg";419 $command .= " --add $batch";420 $command .= " --copy";421 $command .= " --datapath $path";422 $command .= " --type IPP_PSPS";423 $command .= " --product $datastoreProduct";424 $command .= " --list $tempName";425 426 # run command427 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =428 run(command => $command, verbose => $verbose);429 430 if (!$success) { print "* Unable to publish $tarball to datastore\n" and return 0 };431 432 print "* Successfully published $tarball to datastore\n";433 434 close($tempFile);435 436 return 1;437 }438 439 #######################################################################################440 441 # 441 442 # runs ippToPsps to produce init batch … … 457 458 my ($expId, $expName, $surveyType, $outputPath, $resultsFilePath) = @_; 458 459 459 my $nebPath = $gpc1Db->getCameraStageSmf ($expId);460 my $nebPath = $gpc1Db->getCameraStageSmfForThisDvoDb($dvoDb, $expId); 460 461 if (!$nebPath) { return 0; } 461 462 … … 527 528 $command .= " -input $input"; 528 529 $command .= " -output $output"; 529 $command .= " -D CATDIR $ dvodb";530 $command .= " -D CATDIR $fullDvoPath"; 530 531 $command .= " -config ../config"; # TODO 531 $command .= " -expid $expid";532 $command .= " -expid $expid"; 532 533 $command .= " -expname $expName"; 533 534 $command .= " -survey $surveyType";
Note:
See TracChangeset
for help on using the changeset viewer.
