IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 24, 2023, 11:45:27 AM (3 years ago)
Author:
eugene
Message:

working on xcstack

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20230313/ippScripts/scripts/xcstack_skycell.pl

    r42547 r42548  
    5555    'save-temps'        => \$save_temps, # Save temporary files?
    5656    'delete-convolved'  => \$delete_convolved_images,
    57 ) or pod2usage( 2 );
     57    ) or pod2usage( 2 );
    5858
    5959pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    6161    -msg => "Required options: --xcstack_id --outroot --run-state",
    6262    -exitval => 3,
    63           ) unless defined $xcstack_id
     63    ) unless defined $xcstack_id
    6464    and defined $outroot
    6565    and defined $run_state;
     
    6767# lists of file rules which we expect to produce output when convolving
    6868my @outputList = qw(
    69 PPXCSTACK.OUTPUT
    70 PPXCSTACK.OUTPUT.MASK
    71 PPXCSTACK.OUTPUT.VARIANCE
    72 PPXCSTACK.OUTPUT.EXP         
    73 PPXCSTACK.OUTPUT.EXPNUM       
    74 PPXCSTACK.OUTPUT.EXPWT
    75 PPXCSTACK.TARGET.PSF         
    76 );
    77 
    78 # produced if we run photometry
    79 my @outputListPhotom = qw(
    80 PSPHOT.OUT.CMF.MEF
    81 );
    82 
    83 # list of file rules produced if convolution is false
    84 my @outputListUnconv = qw(
    85 PPSTACK.UNCONV
    86 PPSTACK.UNCONV.MASK
    87 PPSTACK.UNCONV.VARIANCE
    88 PPSTACK.UNCONV.EXP         
    89 PPSTACK.UNCONV.EXPNUM       
    90 PPSTACK.UNCONV.EXPWT
    91 PPSTACK.OUTPUT.JPEG1       
    92 PPSTACK.OUTPUT.JPEG2       
    93 PPSTACK.CONFIG             
    94 );
    95 
     69    PPXCSTACK.OUTPUT
     70    PPXCSTACK.OUTPUT.MASK
     71    PPXCSTACK.OUTPUT.VARIANCE
     72    PPXCSTACK.OUTPUT.EXP         
     73    PPXCSTACK.OUTPUT.EXPNUM       
     74    PPXCSTACK.OUTPUT.EXPWT
     75    PPXCSTACK.TARGET.PSF         
     76    );
    9677
    9778my $ipprc = PS::IPP::Config->new() or my_die( "Unable to set up", $xcstack_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     
    10283# my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    10384my $logDest = "$outroot.log";
    104 
    105 if ($run_state eq 'update') {
    106     $logDest .= ".update";
    107 }
    10885
    10986$ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $xcstack_id, $PS_EXIT_SYS_ERROR ) if $redirect;
     
    11592}
    11693
    117 
    11894my $temp_images_exist = 0;
    11995my $image_id = $xcstack_id;
    12096my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_XCSTACK);
    12197
    122 # Get list of components for xcstacking
     98# Get list of cameras for this xcstack
    12399my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    124 my $files;
    125 {
    126     my $command = "$xcstacktool -inputskyfile -xcstack_id $xcstack_id";
     100my $cameras;
     101{
     102    my $command = "$xcstacktool -inputcameras -xcstack_id $xcstack_id";
    127103    $command .= " -dbname $dbname" if defined $dbname;
    128     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    129         run(command => $command, verbose => $verbose);
     104    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    130105    unless ($success) {
    131106        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    132         &my_die("Unable to perform xcstacktool -inputskyfile: $error_code", $xcstack_id, $error_code);
     107        &my_die("Unable to perform xcstacktool -inputcameras: $error_code", $xcstack_id, $error_code);
    133108    }
    134109
    135110    if (@$stdout_buf == 0) {
    136         &my_die("No input skyfiles selected", $xcstack_id, $PS_EXIT_PROG_ERROR);
    137     }
    138     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    139         &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
    140     $files = parse_md_list($metadata) or
    141         &my_die("Unable to parse metadata list", $xcstack_id, $PS_EXIT_PROG_ERROR);
    142 }
     111        &my_die("No input cameras selected", $xcstack_id, $PS_EXIT_PROG_ERROR);
     112    }
     113    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
     114    $cameras = parse_md_list($metadata) or &my_die("Unable to parse metadata list", $xcstack_id, $PS_EXIT_PROG_ERROR);
     115}
     116
     117&my_die("no cameras listed for xcstack", $xcstack_id, $PS_EXIT_DATA_ERROR) unless scalar @$files > 0;
     118
     119print "I've loaded my cameras: $xcstack_id\n";
     120
     121# Gather the list of input stacks from each of the cameras.  There may be multiple stacks per camera
     122foreach my $camera (@$cameras) {
     123    # Get list of components for xcstacking
     124    my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     125
     126    $camera_name = $camera->{camera};
     127   
     128    my $inputs;
     129    {
     130        my $command = "$xcstacktool -inputskyfile -xcstack_id $xcstack_id -xcamera $camera_name";
     131        $command .= " -dbname $dbname" if defined $dbname;
     132        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     133        unless ($success) {
     134            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     135            &my_die("Unable to perform xcstacktool -inputskyfile: $error_code", $xcstack_id, $error_code);
     136        }
     137
     138        if (@$stdout_buf == 0) {
     139            &my_die("No input skyfiles selected", $xcstack_id, $PS_EXIT_PROG_ERROR);
     140        }
     141        my $metadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
     142        $inputs = parse_md_list($metadata) or &my_die("Unable to parse metadata list", $xcstack_id, $PS_EXIT_PROG_ERROR);
     143    }
     144
     145    foreach my $input (@$inputs) {
     146        $stack_id = $input->{stack_id};
     147
     148        my $files;
     149        {
     150            my $command = "$stacktool -sumskyfile -dbname $camera_name -stack_id $stack_id";
     151            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     152                run(command => $command, verbose => $verbose);
     153            unless ($success) {
     154                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     155                &my_die("Unable to perform xcstacktool -inputskyfile: $error_code", $xcstack_id, $error_code);
     156            }
     157
     158            if (@$stdout_buf == 0) {
     159                &my_die("No input skyfiles selected", $xcstack_id, $PS_EXIT_PROG_ERROR);
     160            }
     161            my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     162                &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
     163            $files = parse_md_list($metadata) or
     164                &my_die("Unable to parse metadata list", $xcstack_id, $PS_EXIT_PROG_ERROR);
     165        }
     166
     167        foreach my $file (@$files) {
     168            # check for the input files
     169            my $image    = $ipprc->filename("PPSTACK.OUTPUT", $file->{path_base} ); # Image name
     170            my $mask     = $ipprc->filename( "PPSTACK.OUTPUT.MASK", $file->{path_base} ); # Mask name
     171            my $weight   = $ipprc->filename( "PPSTACK.OUTPUT.VARIANCE", $file->{path_base} ); # Weight name
     172            my $sources  = $ipprc->filename("PPSTACK.OUTPUT.SOURCES", $file->{path_base}); # Sources name
     173
     174            my $have_image   = $ipprc->file_exists( $image );
     175            my $have_mask    = $ipprc->file_exists( $mask );
     176            my $have_weight  = $ipprc->file_exists( $weight );
     177            my $have_sources = $ipprc->file_exists( $sources );
     178
     179            if ($skip_missing_inputs) {
     180                my $missing_inputs = 0;
     181                unless ($have_image)  { print "WARNING: MISSING INPUT $image  \n"; $missing_inputs = 1; }
     182                unless ($have_mask)   { print "WARNING: MISSING INPUT $mask   \n"; $missing_inputs = 1; }
     183                unless ($have_weight) { print "WARNING: MISSING INPUT $weight \n"; $missing_inputs = 1; }
     184                unless ($have_sources){ print "WARNING: MISSING INPUT $sources\n"; $missing_inputs = 1; }
     185                if ($missing_inputs) { next; }
     186            } else {
     187                &my_die("Image $image does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $have_image;
     188                &my_die("Mask $mask does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $have_mask;
     189                &my_die("Weight $weight does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $have_weight;
     190                &my_die("Sources $sources does not exist", $stack_id, $PS_EXIT_SYS_ERROR) unless $have_sources;
     191            }
     192
     193            print $listFile "INPUT$num\tMETADATA\n";
     194
     195            print $listFile "\tIMAGE\tSTR\t"    . $image    . "\n";
     196            print $listFile "\tMASK\tSTR\t"     . $mask     . "\n";
     197            print $listFile "\tVARIANCE\tSTR\t" . $weight   . "\n";
     198            print $listFile "\tPSF\tSTR\t"      . $psf      . "\n" if $convolve;
     199            print $listFile "\tSOURCES\tSTR\t"  . $sources  . "\n";
     200            print $listFile "\tBKGMODEL\tSTR\t" . $bkgmodel . "\n" if $ipprc->file_exists( $bkgmodel );
     201
     202            print $listFile "END\n\n";
     203            $num++;
     204        }
     205    }
     206}
     207close($listFile);
    143208
    144209&my_die("Xcstack list contains less than two elements", $xcstack_id, $PS_EXIT_DATA_ERROR) unless
     
    146211
    147212print "I've loaded my inputs: $xcstack_id\n";
    148 
    149 # Parse the list of input files to get the tesselation, skycell identifiers and camera
    150 my $skycell_id;                 # Skycell identifier
    151 my $tess_id;                    # Tesselation identifier
    152 my $camera;                     # Camera
    153 foreach my $file (@$files) {
    154     # skip warps which are specified as 'ignored'
    155     if ($file->{ignored}) { next; }
    156     if (defined $tess_id) {
    157         &my_die("Tesselation identifiers don't match", $xcstack_id, $PS_EXIT_DATA_ERROR) unless
    158             $file->{tess_id} eq $tess_id;
    159     } else {
    160         $tess_id = $file->{tess_id};
    161     }
    162     if (defined $skycell_id) {
    163         &my_die("Skycell identifiers don't match", $xcstack_id, $PS_EXIT_DATA_ERROR) unless
    164             $file->{skycell_id} eq $skycell_id;
    165     } else {
    166         $skycell_id = $file->{skycell_id};
    167     }
    168     if (defined $camera) {
    169         &my_die("Cameras don't match", $xcstack_id, $PS_EXIT_DATA_ERROR) unless $file->{camera} eq $camera;
    170     } else {
    171         $camera = $file->{camera};
    172     }
    173 }
    174213
    175214&my_die("Can't find camera", $xcstack_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
     
    181220$reduction = 'DEFAULT' unless defined $reduction;
    182221my $recipe_ppStack = $ipprc->reduction($reduction, 'STACK_PPSTACK'); # Recipe to use for ppStack
    183 my $recipe_ppSub = $ipprc->reduction($reduction, 'STACK_PPSUB'); # Recipe to use for ppSub
    184 my $recipe_psphot  = $ipprc->reduction($reduction, 'STACK_PSPHOT'); # Recipe to use for psphot
    185 my $recipe_ppstats = 'XCSTACKSTATS';
    186 if ($
    187 run_state eq 'update') {
    188      $recipe_ppstats = 'WARPSTATS';
    189 }
    190 unless ($recipe_ppStack and $recipe_ppSub and $recipe_psphot) {
    191     &my_die("Couldn't find selected reduction for XCSTACK_PPSTACK, STACK_PPSUB and STACK_PSPHOT: $reduction\n", $xcstack_id, $PS_EXIT_CONFIG_ERROR);
    192 }
    193 
     222unless ($recipe_ppStack) {
     223    &my_die("Couldn't find selected reduction for STACK_PPSTACK: $reduction\n", $xcstack_id, $PS_EXIT_CONFIG_ERROR);
     224}
     225
     226# XXX maybe have different reduction class name (XCSTACK?)
    194227my $recipe;
    195228{
    196229    my $command = "$ppConfigDump -camera $camera -recipe PPSTACK $recipe_ppStack -dump-recipe PPSTACK -";
    197230    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    198         run(command => $command, verbose => $verbose);
     231        run(command => $command, verbose => $verbose);
    199232    unless ($success) {
    200         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    201         &my_die("Unable to perform ppConfigDump: $error_code", $xcstack_id, $error_code);
     233        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     234        &my_die("Unable to perform ppConfigDump: $error_code", $xcstack_id, $error_code);
    202235    }
    203236    $recipe = $mdcParser->parse(join "", @$stdout_buf) or
    204         &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
    205 }
    206 my $convolve = metadataLookupBool($recipe, 'CONVOLVE'); # Convolve inputs?
    207 my $photometry = metadataLookupBool($recipe, 'PHOTOMETRY'); # perform photometry?
     237        &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
     238}
    208239my $output_nocomp = metadataLookupBool($recipe, 'OUTPUT.NOCOMP'); # change filerules to produced uncompressed output images
    209240my $output_logflux = metadataLookupBool($recipe, 'OUTPUT.LOGFLUX'); # change filerules to produce logflux compressed output images.
     
    217248    &my_die("Unable to not compress and use deepexp simultaneously. Check config.",$xcstack_id, $PS_EXIT_CONFIG_ERROR);
    218249}
    219 my $xcstack_type = metadataLookupStr($recipe, 'XCSTACK.TYPE');
    220 &my_die("XCSTACK.TYPE not found in recipe. Check config.",$xcstack_id, $PS_EXIT_CONFIG_ERROR) unless $xcstack_type;
     250my $stack_type = metadataLookupStr($recipe, 'STACK.TYPE');
     251&my_die("STACK.TYPE not found in recipe. Check config.",$xcstack_id, $PS_EXIT_CONFIG_ERROR) unless $stack_type;
     252## XXX not sure how stack type is used in ppStack
     253
     254## XXX first ask for the list of cameras relevant to this stack
    221255
    222256# Generate MDC file with the inputs
     
    321355    $command .= " -F SOURCE.PLOT.APRESID SOURCE.PLOT.SKY.APRESID";
    322356    if ($output_nocomp) {
    323         $command .= " -F PPSTACK.OUTPUT PPSTACK.OUTPUT.NOCOMP";
    324         $command .= " -F PPSTACK.OUTPUT.VARIANCE PPSTACK.OUTPUT.VARIANCE.NOCOMP";
    325         $command .= " -F PPSTACK.OUTPUT.EXPWT PPSTACK.OUTPUT.EXPWT.NOCOMP";
    326         $command .= " -F PPSTACK.OUTPUT.EXP PPSTACK.OUTPUT.EXP.NOCOMP";
    327         $command .= " -F PPSTACK.UNCONV PPSTACK.UNCONV.NOCOMP";
    328         $command .= " -F PPSTACK.UNCONV.VARIANCE PPSTACK.UNCONV.VARIANCE.NOCOMP";
    329         $command .= " -F PPSTACK.UNCONV.EXPWT PPSTACK.UNCONV.EXPWT.NOCOMP";
    330         $command .= " -F PPSTACK.UNCONV.EXP PPSTACK.UNCONV.EXP.NOCOMP";
     357        $command .= " -F PPSTACK.OUTPUT PPSTACK.OUTPUT.NOCOMP";
     358        $command .= " -F PPSTACK.OUTPUT.VARIANCE PPSTACK.OUTPUT.VARIANCE.NOCOMP";
     359        $command .= " -F PPSTACK.OUTPUT.EXPWT PPSTACK.OUTPUT.EXPWT.NOCOMP";
     360        $command .= " -F PPSTACK.OUTPUT.EXP PPSTACK.OUTPUT.EXP.NOCOMP";
     361        $command .= " -F PPSTACK.UNCONV PPSTACK.UNCONV.NOCOMP";
     362        $command .= " -F PPSTACK.UNCONV.VARIANCE PPSTACK.UNCONV.VARIANCE.NOCOMP";
     363        $command .= " -F PPSTACK.UNCONV.EXPWT PPSTACK.UNCONV.EXPWT.NOCOMP";
     364        $command .= " -F PPSTACK.UNCONV.EXP PPSTACK.UNCONV.EXP.NOCOMP";
    331365    }
    332366    if ($output_logflux) {
    333367        $command .= " -R PPSTACK.OUTPUT          FITS.TYPE STK_UNIONS_COMP";
    334368        $command .= " -R PPSTACK.OUTPUT.VARIANCE FITS.TYPE STK_UNIONS_COMP";
    335         $command .= " -R PPSTACK.UNCONV          FITS.TYPE STK_UNIONS_COMP";
     369        $command .= " -R PPSTACK.UNCONV          FITS.TYPE STK_UNIONS_COMP";
    336370        $command .= " -R PPSTACK.UNCONV.VARIANCE FITS.TYPE STK_UNIONS_COMP";
    337371    }
     
    354388
    355389    if ($run_state eq 'new') {
    356         $command .= " -dumpconfig $configuration";
     390        $command .= " -dumpconfig $configuration";
    357391    } else {
    358         $command .= " -ipprc $configuration";
     392        $command .= " -ipprc $configuration";
    359393    }
    360394
    361395
    362396    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    363         run(command => $command, verbose => $verbose);
     397        run(command => $command, verbose => $verbose);
    364398    unless ($success) {
    365         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    366         &my_die("Unable to perform ppStack: $error_code", $xcstack_id, $error_code);
     399        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     400        &my_die("Unable to perform ppStack: $error_code", $xcstack_id, $error_code);
    367401    }
    368402
    369403    my $quality;                # Quality flag
    370404    if ($do_stats) {
    371         my $outputStatsReal = $ipprc->file_resolve($outputStats);
    372         &my_die("Couldn't find expected output file: $outputStats", $xcstack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
    373 
    374         # measure stats
    375         $command = "$ppStatsFromMetadata $outputStatsReal - XCSTACK_SKYCELL";
    376         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    377             run(command => $command, verbose => $verbose);
    378         unless ($success) {
    379             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    380             &my_die("Unable to perform ppStatsFromMetadata: $error_code", $xcstack_id, $error_code);
    381         }
    382         foreach my $line (@$stdout_buf) {
    383             $cmdflags .= " $line";
    384         }
    385         chomp $cmdflags;
    386 
    387         ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
     405        my $outputStatsReal = $ipprc->file_resolve($outputStats);
     406        &my_die("Couldn't find expected output file: $outputStats", $xcstack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
     407
     408        # measure stats
     409        $command = "$ppStatsFromMetadata $outputStatsReal - XCSTACK_SKYCELL";
     410        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     411            run(command => $command, verbose => $verbose);
     412        unless ($success) {
     413            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     414            &my_die("Unable to perform ppStatsFromMetadata: $error_code", $xcstack_id, $error_code);
     415        }
     416        foreach my $line (@$stdout_buf) {
     417            $cmdflags .= " $line";
     418        }
     419        chomp $cmdflags;
     420
     421        ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
    388422    }
    389423
     
    391425       
    392426
    393         check_outputs(\@outputFiles, $replicate_outputs);
     427        check_outputs(\@outputFiles, $replicate_outputs);
    394428
    395429        if (($convolve)&&($delete_convolved_images)) { # We made convolved products, but do not wish to keep them anymore
     
    421455    # Add the stack result
    422456    {
    423         my $command = "$xcstacktool";
    424         my $mode;
    425         if ($run_state eq 'new') {
    426             $mode = "-addsumskyfile";
    427             $command .= " -uri $outputName -path_base $outroot";
    428             $command .= " -hostname $host" if defined $host;
    429             $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    430         } else {
    431             $mode = "-updaterun -set_state full";
    432         }
    433         $command .= " $mode -xcstack_id $xcstack_id";
    434         $command .= " $cmdflags" if $do_stats;
    435         $command .= " -dbname $dbname" if defined $dbname;
    436 
    437         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    438             run(command => $command, verbose => $verbose);
    439         unless ($success) {
    440             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    441             &my_die("Unable to perform xcstacktool $mode $error_code", $xcstack_id, $error_code);
    442         }
     457        my $command = "$xcstacktool";
     458        my $mode;
     459        if ($run_state eq 'new') {
     460            $mode = "-addsumskyfile";
     461            $command .= " -uri $outputName -path_base $outroot";
     462            $command .= " -hostname $host" if defined $host;
     463            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     464        } else {
     465            $mode = "-updaterun -set_state full";
     466        }
     467        $command .= " $mode -xcstack_id $xcstack_id";
     468        $command .= " $cmdflags" if $do_stats;
     469        $command .= " -dbname $dbname" if defined $dbname;
     470
     471        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     472            run(command => $command, verbose => $verbose);
     473        unless ($success) {
     474            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     475            &my_die("Unable to perform xcstacktool $mode $error_code", $xcstack_id, $error_code);
     476        }
    443477    }
    444478
     
    460494
    461495    unless ($my_die_called) {
    462         $my_die_called = 1;
    463         delete_temps() unless ($save_temps);
     496        $my_die_called = 1;
     497        delete_temps() unless ($save_temps);
    464498    }
    465499
    466500    if (defined $xcstack_id and not $no_update) {
    467         my $command = "$xcstacktool -xcstack_id $xcstack_id -fault $exit_code";
    468         if ($run_state eq 'new') {
    469             $command .= " -addsumskyfile";
    470             $command .= " -hostname $host" if defined $host;
    471             $command .= " -path_base $outroot" if defined $outroot;
    472             $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    473         } else {
    474             $command .= " -updatesumskyfile";
    475         }
    476         $command .= " -dbname $dbname" if defined $dbname;
    477         system ($command);
     501        my $command = "$xcstacktool -xcstack_id $xcstack_id -fault $exit_code";
     502        if ($run_state eq 'new') {
     503            $command .= " -addsumskyfile";
     504            $command .= " -hostname $host" if defined $host;
     505            $command .= " -path_base $outroot" if defined $outroot;
     506            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     507        } else {
     508            $command .= " -updatesumskyfile";
     509        }
     510        $command .= " -dbname $dbname" if defined $dbname;
     511        system ($command);
    478512    }
    479513    exit $exit_code;
     
    484518{
    485519    unless ($temp_images_exist) {
    486         print "No temporary images yet generated\n";
    487         return 1;
     520        print "No temporary images yet generated\n";
     521        return 1;
    488522    }
    489523
     
    492526    my $temp_delete = defined($recipe) and metadataLookupBool($recipe, 'TEMP.DELETE'); # Delete temp files?
    493527    if ($temp_delete) {
    494         my $temp_dir = metadataLookupStr($ipprc->{_siteConfig}, 'TEMP.DIR') or &my_die("Unable to find temporary directory in site configuration", $xcstack_id, $PS_EXIT_CONFIG_ERROR); # Directory with temporary files
    495         my $temp_image = metadataLookupStr($recipe, 'TEMP.IMAGE'); # Suffix for image
    496         my $temp_mask = metadataLookupStr($recipe, 'TEMP.MASK'); # Suffix for mask
    497         my $temp_weight = metadataLookupStr($recipe, 'TEMP.VARIANCE'); # Suffix for weight
    498         my $temp_root = basename($outroot); # Root name for temporary files
    499 
    500         if (not defined $temp_dir or not defined $temp_image or not defined $temp_mask or
    501             not defined $temp_weight) {
    502             &my_die("Unable to find details for temporary images.", $xcstack_id, $PS_EXIT_CONFIG_ERROR);
    503         }
    504 
    505         for (my $i = 0; $i < $num; $i++) {
    506             foreach my $ext ( $temp_image, $temp_mask, $temp_weight ) {
    507                 my $file = $temp_dir . '/' . $temp_root . '.' . $i . '.' . $ext;
    508                 unlink $file if -e $file;
    509             }
    510         }
     528        my $temp_dir = metadataLookupStr($ipprc->{_siteConfig}, 'TEMP.DIR') or &my_die("Unable to find temporary directory in site configuration", $xcstack_id, $PS_EXIT_CONFIG_ERROR); # Directory with temporary files
     529        my $temp_image = metadataLookupStr($recipe, 'TEMP.IMAGE'); # Suffix for image
     530        my $temp_mask = metadataLookupStr($recipe, 'TEMP.MASK'); # Suffix for mask
     531        my $temp_weight = metadataLookupStr($recipe, 'TEMP.VARIANCE'); # Suffix for weight
     532        my $temp_root = basename($outroot); # Root name for temporary files
     533
     534        if (not defined $temp_dir or not defined $temp_image or not defined $temp_mask or
     535            not defined $temp_weight) {
     536            &my_die("Unable to find details for temporary images.", $xcstack_id, $PS_EXIT_CONFIG_ERROR);
     537        }
     538
     539        for (my $i = 0; $i < $num; $i++) {
     540            foreach my $ext ( $temp_image, $temp_mask, $temp_weight ) {
     541                my $file = $temp_dir . '/' . $temp_root . '.' . $i . '.' . $ext;
     542                unlink $file if -e $file;
     543            }
     544        }
    511545    }
    512546}
     
    520554    my $error;
    521555    my $output = $ipprc->prepare_output($filerule, $outroot, undef, $delete, \$error)
    522                     or &my_die("failed to prepare output file for: $filerule", $xcstack_id, $error);
     556        or &my_die("failed to prepare output file for: $filerule", $xcstack_id, $error);
    523557    return $output;
    524558}
     
    531565   
    532566    foreach my $rule (@$ruleList) {
    533         push @$fileList, prepare_output($rule, $outroot, 1);
     567        push @$fileList, prepare_output($rule, $outroot, 1);
    534568    }
    535569}
     
    541575
    542576    if (!defined $file) {
    543         return;
     577        return;
    544578    }
    545579
     
    549583    my $diskfile = $ipprc->file_resolve($file);
    550584    if ($diskfile =~ /fits/) {
    551         my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $xcstack_id, $PS_EXIT_SYS_ERROR);
     585        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $xcstack_id, $PS_EXIT_SYS_ERROR);
    552586        my $check_command = "$funpack -S $diskfile > /dev/null";
    553587        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    560594
    561595    if ($replicate and $neb) {
    562         $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $xcstack_id, $PS_EXIT_SYS_ERROR);
     596        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $xcstack_id, $PS_EXIT_SYS_ERROR);
    563597    }
    564598}
     
    569603    my $replicate = shift;
    570604    foreach my $file (@$fileList) {
    571         check_output($file, $replicate);
    572     }
    573 }
    574 
     605        check_output($file, $replicate);
     606    }
     607}
     608
     609sub run_command {
     610
     611    my $command = shift;
     612    my $result;
     613
     614    # Get list of cameras for this xcstack
     615    my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     616    {
     617        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     618        unless ($success) {
     619            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     620            &my_die("Unable to perform $command: $error_code");
     621        }
     622
     623        if (@$stdout_buf == 0) {
     624            &my_die("No input cameras selected", $xcstack_id, $PS_EXIT_PROG_ERROR);
     625        }
     626        my $metadata = $mdcParser->parse(join "", @$stdout_buf) or &my_die("Unable to parse metadata config doc", $xcstack_id, $PS_EXIT_PROG_ERROR);
     627        $cameras = parse_md_list($metadata) or &my_die("Unable to parse metadata list", $xcstack_id, $PS_EXIT_PROG_ERROR);
     628    }
     629
     630
     631
     632}
    575633print "I've reached the end of processing with a code of $?: $xcstack_id\n";
    576634
Note: See TracChangeset for help on using the changeset viewer.