IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30317


Ignore:
Timestamp:
Jan 20, 2011, 10:28:02 AM (15 years ago)
Author:
bills
Message:

Implement extraction of postage stamps from uncensored images either by using the backup images
or by replacing the censored pixels from destreak recovery images.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r29424 r30317  
    1717                    resolve_project
    1818                    getCamRunByCamID
     19                    runToolAndParse
    1920                    parse_md_fast
    2021                    );
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r28048 r30317  
    2929                    $PSTAMP_SELECT_INVERSE
    3030                    $PSTAMP_SELECT_UNCONV
     31                    $PSTAMP_REQUEST_UNCENSORED
     32                    $PSTAMP_REQUIRE_UNCENSORED
    3133                    $PSTAMP_USE_IMFILE_ID
    3234                    $PSTAMP_NO_WAIT_FOR_UPDATE
     
    4446                    $PSTAMP_NO_JOBS_QUEUED
    4547                    $PSTAMP_NO_OVERLAP
     48                    $PSTAMP_NOT_AUTHORIZED
    4649                    );
    4750our %EXPORT_TAGS = (standard => [@EXPORT_OK]);
     
    6467our $PSTAMP_USE_IMFILE_ID    = 16384;
    6568
    66 our $PSTAMP_NO_WAIT_FOR_UPDATE  = 32768;
     69our $PSTAMP_NO_WAIT_FOR_UPDATE = 32768;
     70our $PSTAMP_REQUEST_UNCENSORED = 1 << 16;
     71our $PSTAMP_REQUIRE_UNCENSORED = 1 << 17;
    6772
    6873# job and result codes
     
    8287our $PSTAMP_NO_JOBS_QUEUED   = 27;
    8388our $PSTAMP_NO_OVERLAP       = 28;
     89our $PSTAMP_NOT_AUTHORIZED   = 29;
    8490
    8591
     
    119125PSTAMP_NO_JOBS_QUEUED
    120126PSTAMP_NO_OVERLAP
     127PSTAMP_NOT_AUTHORIZED
    121128);
    122129
  • trunk/ippTasks/pstamp.pro

    r29719 r30317  
    258258        book getword pstampRequest $pageName ds_outProduct -var PRODUCT
    259259        book getword pstampRequest $pageName outdir -var OUTDIR
     260        book getword pstampRequest $pageName need_magic -var NEED_MAGIC
    260261        book getword pstampRequest $pageName label -var LABEL
    261262
     
    263264
    264265        $run = pstamp_parser_run.pl --req_id $REQ_ID --uri $URI --product $PRODUCT --outdir $OUTDIR --label $LABEL --redirect-output
     266
     267        if ($NEED_MAGIC != 0)
     268            $run = $run --need_magic
     269        end
    265270
    266271        add_standard_args run
  • trunk/pstamp/scripts/pstamp_checkdependent.pl

    r29624 r30317  
    680680            foreach my $c (@$components) {
    681681                my $command = "$magicdstool -destreakedfile -magic_ds_id $magic_ds_id -component $c";
     682                # XXX: get this from a config file
     683                $command .= " -set_recoveryroot neb://any/gpc1/destreak/recover";
    682684                my $dsfile = runToolAndParseExpectOne($command, $verbose);
    683685                if (!$dsfile) {
  • trunk/pstamp/scripts/pstamp_job_run.pl

    r30001 r30317  
    1414use File::Basename;
    1515use File::Copy;
     16use File::Temp qw(tempfile);
    1617use Digest::MD5::File qw( file_md5_hex );
    1718use PS::IPP::PStamp::RequestFile qw( :standard );
     19use PS::IPP::PStamp::Job qw( :standard );
    1820use IPC::Cmd 0.36 qw( can_run run );
    1921use POSIX;
     
    2628
    2729my ($job_id, $redirect_output, $outputBase, $rownum, $jobType, $options);
    28 my ($verbose, $dbname, $dbserver, $no_update);
     30my ($verbose, $dbname, $dbserver, $no_update, $save_temps);
    2931
    3032GetOptions(
     
    3941    'verbose'           =>  \$verbose,
    4042    'no-update'         =>  \$no_update,
     43    'save-temps'        =>  \$save_temps,
    4144);
    4245
     
    7578my $pstamp_get_image_job    = can_run('pstamp_get_image_job.pl') or (warn "Can't find pstamp_get_image_job.pl" and $missing_tools = 1);
    7679my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1);
     80my $streaksreplace = can_run('streaksreplace')  or (warn "Can't find streaksreplace"  and $missing_tools = 1);
     81my $magicdstool = can_run('magicdstool')  or (warn "Can't find magicdstool"  and $missing_tools = 1);
    7782
    7883if ($missing_tools) {
     
    8893    my $argString;
    8994    $argString = $params->{job_args};
     95    my $stage = $params->{stage};
    9096
    9197    # XXX: should we do any other sanity checking?
    9298    my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
    9399
    94     $argString .= " -file $params->{image}";
     100    my $nan_masked = 1;
     101    my $muggle = 0;
     102    if (!$params->{magicked}) {
     103        $nan_masked = 0;
     104    } elsif ($params->{magicked} and ($options & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED))) {
     105        # Attempt to find or create a muggle image
     106        $nan_masked = 0;
     107        $muggle = 1;
     108    }
     109
     110    my $image = $params->{image};
     111    my $mask;
     112    my $variance;
     113    my $fileArgs = " -file $params->{image}";
    95114    my @file_list = ($params->{image});
    96115   
    97     my $nan_masked = 1;
    98     if (!$params->{magicked}) {
    99         $nan_masked = 0;
    100     }
    101116    if ($nan_masked or ($options & $PSTAMP_SELECT_MASK)) {
    102         $argString .= " -mask $params->{mask}";
    103         push @file_list, $params->{mask};
     117        $mask = $params->{mask};
     118        $fileArgs .= " -mask $mask";
     119        push @file_list, $mask;
    104120    }
    105121    if ($options & $PSTAMP_SELECT_VARIANCE) {
    106         $argString .= " -variance $params->{weight}";
    107         push @file_list, $params->{weight};
     122        $variance = $params->{weight};
     123        $fileArgs .= " -variance $variance";
     124        push @file_list, $variance;
    108125    }
    109126
     
    113130    }
    114131
    115     check_files(@file_list);
    116 
    117     my $command = "$ppstamp $outputBase $argString";
     132    # check that actual input files exist
     133    check_files($PSTAMP_GONE, @file_list);
     134
     135    # find our output directory
     136    my $outdir = dirname($outputBase);
     137    my ($tmpImage, $tmpMask, $tmpVariance, $tmproot);
     138   
     139    if ($muggle) {
     140        # first see if the original uncensored images are around
     141        if (check_for_backups($params, \$fileArgs)) {
     142            # We're good to go. fileArgs has been edited to contain the paths for the original uncensored images
     143            print "Making stamps from backup images\n";
     144        } elsif (($options & $PSTAMP_REQUIRE_UNCENSORED) and ($stage ne 'chip')) {
     145            # user required uncensored but since stage isn't chip we can't rebuild them
     146            my_die("uncensored inputs not available for job $job_id", $job_id, $PSTAMP_NOT_AVAILABLE);
     147        } elsif (($options & $PSTAMP_REQUEST_UNCENSORED) and ($stage ne 'chip')) {
     148            # make stamps from uncensored images
     149            $muggle = 0;
     150        } else {
     151            # Try and replace the streaks from the recovery images
     152
     153            @file_list = ();
     154            $tmproot = "$outdir/$job_id";
     155            mkdir $tmproot or
     156                my_die( "failed to create temporary directory $tmproot", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     157            my $muggle_command = "$streaksreplace -stage $stage -tmproot $tmproot";
     158            # find the "directory" of the input path_base
     159            my $inputdir = dirname($image);
     160            my $base = basename($image);
     161            $tmpImage = "$tmproot/$base";
     162
     163            # XXX: We should get the recovery_path_base from the magicDSFile but that requires a bunch of file rule and
     164            # stage work. Import the rule here.
     165            my $recImage = "$inputdir/REC_$base";
     166            my $newFileArgs = " -file $tmpImage";
     167            $muggle_command .= " -image $image -recimage $recImage";
     168            push @file_list, $recImage;
     169
     170            if ($mask) {
     171                $base = basename($mask);
     172                $tmpMask = "$tmproot/$base";
     173                $newFileArgs .= " -mask $tmpMask";
     174                my $recMask = "$inputdir/REC_$base";
     175                $muggle_command .= " -mask $mask -recmask $recMask";
     176                push @file_list, $recMask;
     177            }
     178
     179            if ($variance) {
     180                $base = basename($variance);
     181                $tmpVariance = "$tmproot/$base";
     182                $newFileArgs .= " -weight $tmpVariance";
     183                my $recVariance = "$inputdir/REC_$base";
     184                $muggle_command .= " -weight $variance -recweight $recVariance";
     185                push @file_list, $recVariance;
     186            }
     187            if (check_files(0, @file_list)) {
     188                # recovery files exist and are accessible restore the excised pixels
     189
     190                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     191                    run(command => $muggle_command, verbose => $verbose);
     192                unless ($success) {
     193                    my $exitStatus = WEXITSTATUS($error_code);
     194                    my_die( "streaksreplace failed with error code: $exitStatus", $job_id, $exitStatus);
     195                }
     196
     197                # set the ppstamp file arguments
     198                $fileArgs = $newFileArgs;
     199            } else {
     200                if ($options & $PSTAMP_REQUIRE_UNCENSORED) {
     201                    my_die( "unable to restore uncensored images", $job_id, $PSTAMP_NOT_AVAILABLE);
     202                }
     203                # just make stamps from the censored images
     204                print "Unable to restore uncensored images, will extract stamps from censored images\n";
     205                # these files won't be used so zap them
     206                ($tmpImage, $tmpMask, $tmpVariance, $tmproot) = (undef, undef, undef, undef);
     207            }
     208        }
     209    }
     210
     211    my $command = "$ppstamp $outputBase $argString $fileArgs";
    118212    $command .= " -dbname $dbname" if $dbname;
    119213    $command .= " -dbserver $dbserver" if $dbserver;
    120     $command .= " -stage $params->{stage}" if $params->{stage};
     214    $command .= " -stage $stage";
    121215    $command .= " -no_censor_masked" unless $nan_masked;
    122216    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    131225    }
    132226
     227    if (!$save_temps) {
     228        unlink $tmpImage if $tmpImage;
     229        unlink $tmpMask if $tmpMask;
     230        unlink $tmpVariance if $tmpVariance;
     231        rmdir $tmproot if $tmproot;
     232    }
     233
    133234    if ($exitStatus == 0) {
    134         my $dir = dirname($outputBase);
    135 
    136         my $reglist = "$dir/reglist$job_id";
     235        my $reglist = "$outdir/reglist$job_id";
    137236
    138237        my $F;
     
    363462
    364463sub check_files {
     464    my $error_code = shift;
     465    my $return_code = 1;
    365466    foreach my $f (@_) {
    366467        if (!$ipprc->file_exists($f)) {
    367             my_die( "file $f does not exist:", $job_id, $PSTAMP_GONE, 'stop');
    368         }
    369     }
     468            if ($error_code) {
     469                my_die( "file $f does not exist:", $job_id, $error_code, 'stop');
     470            } else {
     471                print STDERR "file $f does not exist\n";
     472                $return_code = 0;
     473            }
     474        }
     475    }
     476    return $return_code;
     477}
     478
     479sub check_for_backups {
     480    my $params = shift;
     481    my $r_fileArgs = shift;
     482
     483    my $command = "$magicdstool -destreakedfile -stage $params->{stage} -stage_id $params->{stage_id} -component $params->{component} -dbname $params->{imagedb}";
     484    my $results = runToolAndParse($command, $verbose);
     485    my $dsComponent  = $results->[0];
     486
     487    if ($dsComponent and ($dsComponent->{data_state} eq 'full')) {
     488
     489        print "magicDSFile state is full. Backup images should exist\n";
     490
     491        # replace the file names with the backup paths
     492        # fileArgs has the form:  -file imagename [-mask maskname] [-weight weightname]
     493        my @args = split " ", $$r_fileArgs;
     494
     495        my $newFileArgs;
     496        while (@args) {
     497            my $a = shift @args;
     498            my $f = shift @args;
     499            my_die( "unexpected fileArg list $$r_fileArgs", $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$a or !$f;
     500
     501            my $backup_image_name = $ipprc->destreaked_filename($f);
     502            my_die( "failed to extract backup image name from $f", $job_id, $PS_EXIT_PROG_ERROR, 'run') if !$backup_image_name;
     503            $newFileArgs .= " $a $backup_image_name";
     504        }
     505        $$r_fileArgs = $newFileArgs;
     506
     507        return 1;
     508    }
     509
     510    return 0;
    370511}
    371512
  • trunk/pstamp/scripts/pstamp_parser_run.pl

    r29576 r30317  
    3131my $outdir;
    3232my $label;
     33my $need_magic;
    3334my $verbose;
    3435my $dbname;
     
    4142    'outdir=s'          =>  \$outdir,
    4243    'label=s'           =>  \$label,
     44    'need_magic'        =>  \$need_magic,
    4345    'redirect-output'   =>  \$redirect_output,
    4446    'verbose'           =>  \$verbose,
     
    160162            $parse_cmd = "$pstampparse";
    161163            $parse_cmd .= " --label $label" if $label;
     164            $parse_cmd .= " --need_magic" if $need_magic;
    162165            $request_fault = 0;
    163166        } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
  • trunk/pstamp/scripts/pstamp_server_status

    r29572 r30317  
    4444chdir $rundir or die "failed to cd to $rundir";
    4545
     46
     47my $down = 0;
     48if ($down) {
     49    print "Postage Stamp Server will be down for maintenance it will back at approximately 00:00 2010-12-11 UTC\n";
     50    exit 0;
     51}
    4652
    4753my ($pts, $pantasks_script) = tempfile ('/tmp/pts.XXXX', UNLINK => !$save_temps);
  • trunk/pstamp/scripts/pstampparse.pl

    r30016 r30317  
    3030my $save_temps;
    3131my $no_update;
     32my $dest_requires_magic;
    3233
    3334GetOptions(
     
    3839    'label=s'   =>  \$label,
    3940    'mode=s'    =>  \$mode,
     41    'need_magic'=>  \$dest_requires_magic,
    4042    'dbname=s'  =>  \$dbname,
    4143    'dbserver=s'=>  \$dbserver,
     
    126128}
    127129
    128 # Adjust the label for requests coming in over the web interaface
     130
     131# Adjust the label for requests coming in over the web interface
    129132
    130133my $label_changed = 0;
     
    384387    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
    385388    if (!$proj_hash) {
    386         foreach $row (@$rowList) {
    387             insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PRODUCT);
     389        foreach my $r (@$rowList) {
     390            insertFakeJobForRow($r, 1, $PSTAMP_UNKNOWN_PRODUCT);
    388391            $num_jobs++;
    389392        }
     
    409412    $need_magic    = $proj_hash->{need_magic};
    410413
    411     # Temporary hack so that IFA can get at non-magicked data
    412     my $allow_mops_unmagicked = 1;
    413     if ($allow_mops_unmagicked) {
    414         if ($product and (($product eq "mops-pstamp-results") or
    415                           ($product eq "mops-pstamp-results2") or
    416                           ($product eq "ifa-pstamp-results"))) {
    417             $need_magic = 0;
    418         }
    419     }
    420 
    421414    $need_magic = 0 if $stage eq 'stack';
     415
     416    if ($need_magic) {
     417
     418        # this project requires that postage stamps be extracted from destreaked images
     419
     420        if ($option_mask & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED)) {
     421            # The user has requested uncensored stamps
     422
     423            if (!$dest_requires_magic) {
     424                # and this user's data store destination is allowed uncensored stamps, so accept the request
     425                $need_magic = 0;
     426            } else {
     427                print STDERR "Error row $rownum: User not authorized to to request uncensored stamps.\n";
     428                if ($option_mask & $PSTAMP_REQUIRE_UNCENSORED) {
     429                    # user required uncensored stamps. Can't do it so fail.
     430                    foreach my $r (@$rowList) {
     431                        insertFakeJobForRow($r, 1, $PSTAMP_NOT_AUTHORIZED);
     432                        $num_jobs++;
     433                    }
     434                    return $num_jobs;
     435                }
     436
     437                # user will accept censored stamps. alter OPTION_MASK and continue
     438
     439                print STDERR "    Will attempt to make destreaked stamps\n";
     440                # zap the offending bit in the option mask
     441                $option_mask = $option_mask ^ ($PSTAMP_REQUEST_UNCENSORED);
     442                foreach my $r (@$rowList) {
     443                    $r->{OPTION_MASK} = $option_mask;
     444                }
     445            }
     446        }
     447    }
    422448   
    423449    my $numRows = scalar @$rowList;
Note: See TracChangeset for help on using the changeset viewer.