IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 11, 2011, 4:29:48 PM (15 years ago)
Author:
watersc1
Message:

Trying to merge back into trunk.

Location:
branches/czw_branch/20101203
Files:
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/ippScripts/Build.PL

    r30018 r30586  
    5858        scripts/magic_tree.pl
    5959        scripts/magic_process.pl
     60        scripts/magic_cleanup.pl
    6061        scripts/magic_destreak.pl
    6162        scripts/magic_destreak_revert.pl
  • branches/czw_branch/20101203/ippScripts/scripts/addstar_run.pl

    r29006 r30586  
    7171    defined $camera;
    7272if ($minidvodb && !defined($minidvodb_group)) {
    73                 my_die( "missing minidvodb_group", $add_id, 3 );
    74             }
     73                my_die( "missing minidvodb_group", $add_id, 3 );
     74            }
    7575my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $add_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    7676
     
    113113
    114114if (defined $dvodbReal) {
    115         if ($minidvodb) {
    116            
    117             if (!defined($minidvodb_name)) {
    118                 #take the active one, if it's not defined on the command line
    119                 #reverts would have this already set, for example.
    120                 my $command = "addtool -listminidvodbrun ";
    121                 $command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group;
    122                 $command .= " -state 'active' -limit 1";
    123                 $command .= " -dbname $dbname" if defined $dbname;
    124                 print $command;
    125                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    126                     run(command => $command, verbose => $verbose);
    127                 &my_die( "Unable to get active minidvodb_name", $add_id, $PS_EXIT_SYS_ERROR) unless $success;
    128                 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    129                     &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR);
    130 
    131                 my $components = parse_md_list($metadata) or
    132                     &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);
    133                 my $comp = $$components[0];
    134                 $minidvodb_path = $comp->{minidvodb_path};
    135                 $minidvodb_name = $comp->{minidvodb_name};
    136        
    137                 if (!defined($minidvodb_path)) {
    138                     &my_die("Unable to parse minidvodb_path", $add_id, $PS_EXIT_PROG_ERROR);
    139                 }
    140                 if (!defined($minidvodb_name)) {
    141                     &my_die("Unable to parse minidvodb_name", $add_id, $PS_EXIT_PROG_ERROR);
    142                 }
    143             }
    144             # tack on the minidvodb part to the db.
    145 #           $dvodbReal = $dvodbReal . '/' . $minidvodb_name . '/';
    146 #we don't need this now that I fixed the paths     
    147            
    148         }
     115        if ($minidvodb) {
     116
     117            #if (!defined($minidvodb_name)) {
     118                #take the active one, if it's not defined on the command line
     119                #reverts would have this already set, for example.
     120                my $command = "addtool -listminidvodbrun ";
     121                $command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group;
     122                $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name;
     123                $command .= " -state 'active' -limit 1";
     124                $command .= " -dbname $dbname" if defined $dbname;
     125                print $command;
     126                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     127                    run(command => $command, verbose => $verbose);
     128                &my_die( "Unable to get active minidvodb_name", $add_id, $PS_EXIT_SYS_ERROR) unless $success;
     129                my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     130                    &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR);
     131
     132                my $components = parse_md_list($metadata) or
     133                    &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);
     134                my $comp = $$components[0];
     135                $minidvodb_path = $comp->{minidvodb_path};
     136                $minidvodb_name = $comp->{minidvodb_name};
     137
     138                if (!defined($minidvodb_path)) {
     139                    &my_die("Unable to parse minidvodb_path", $add_id, $PS_EXIT_PROG_ERROR);
     140                }
     141                if (!defined($minidvodb_name)) {
     142                    &my_die("Unable to parse minidvodb_name", $add_id, $PS_EXIT_PROG_ERROR);
     143                }
     144            #}
     145            # tack on the minidvodb part to the db.
     146#           $dvodbReal = $dvodbReal . '/' . $minidvodb_name . '/';
     147#we don't need this now that I fixed the paths
     148
     149        }
    149150        else {
    150151
     
    153154
    154155unless ($no_op) {
    155             print $dvodbReal;
     156            print $dvodbReal;
    156157
    157158        ## addstar can either save the full set of detections, or just
     
    222223        $command .= " -addprocessedexp";
    223224        $command .= " -fault $exit_code";
    224         $command .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path;
     225        $command .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path;
    225226        $command .= " -path_base $outroot" if defined $outroot;
    226227        $command .= (" -dtime_addstar " . ((DateTime->now->mjd - $mjd_start) * 86400));
    227         $fpaCommand .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name;
     228        $fpaCommand .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name;
    228229        $command .= " -dbname $dbname" if defined $dbname;
    229230        system ($command);
  • branches/czw_branch/20101203/ippScripts/scripts/dist_advancerun.pl

    r28963 r30586  
    2323use PS::IPP::Config 1.01 qw( :standard );
    2424
    25 my $ipprc = PS::IPP::Config->new(); # IPP configuration
    2625
    2726use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    2928
    3029# Parse the command-line arguments
    31 my ($dist_id, $stage, $stage_id, $outdir, $clean);
     30my ($dist_id, $stage, $stage_id, $outdir, $clean, $camera);
    3231my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
    3332
    3433GetOptions(
    35            'dist_id=s'  => \$dist_id,# Magic destreak run identifier
     34           'dist_id=s'      => \$dist_id,# Magic destreak run identifier
     35           'camera=s'       => \$camera,
    3636           'stage=s'        => \$stage,      # raw, chip, warp, or diff
    3737           'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
     
    5353    defined $stage_id and
    5454    defined $outdir;
     55
     56my $ipprc = PS::IPP::Config->new($camera); # IPP configuration
    5557
    5658$ipprc->redirect_output($logfile) if $logfile;
     
    134136}
    135137
    136 # XXX should we create a file rule for this?
    137 my $dbinfo_file = "$outdir/dbinfo.$stage.$stage_id.mdc";
    138 
    139 {
    140     my $command = "$tool_cmd $exportarg -outfile $dbinfo_file";
     138
     139# work around the fact that $ipprc->file_create does not actually create a file on disk
     140# unless the scheme is nebulous
     141sub create_file {
     142    my $rule = shift;
     143    my $path_base = shift;
     144    my $ref = shift;
     145
     146    my $file;
     147
     148    my $error;
     149    $file = $ipprc->prepare_output($rule, $path_base, undef, 1, \$error)
     150        or &my_die("Unable to prepare outut for $rule", $dist_id, $PS_EXIT_SYS_ERROR);
     151
     152    my $scheme = file_scheme($file);
     153    $scheme = "" if !$scheme;
     154
     155    my $resolved;
     156    if ($scheme) {
     157        $ipprc->file_create($file)
     158            or &my_die("Unable to create $file", $dist_id, $PS_EXIT_SYS_ERROR);
     159
     160        $resolved = $ipprc->file_resolve($file)
     161            or &my_die("Unable to resolve $file", $dist_id, $PS_EXIT_SYS_ERROR);
     162
     163        if ($scheme eq 'neb') {
     164            &my_die("$resolved not found", $dist_id, $PS_EXIT_SYS_ERROR) unless ($resolved and -e $resolved);
     165    }
     166    } else {
     167        $resolved = $file;
     168    }
     169    $$ref = $resolved;
     170
     171    return $file
     172}
     173
     174my $dbinfo_root = "$outdir/dbinfo.$stage.$stage_id";
     175my $resolved;
     176my $dbinfo_file = create_file("DIST.OUTPUT.DBINFO", $dbinfo_root, \$resolved);
     177
     178{
     179    my $command = "$tool_cmd $exportarg -outfile $resolved";
    141180    $command .= " -clean" if ((defined $clean) and ($stage ne "raw"));
    142181    $command .= " -dbname $dbname" if defined $dbname;
     
    149188    }
    150189}
    151 my $dirinfo = "$outdir/dirinfo.$stage.$stage_id.mdc";
     190
     191my $dirinfo_root = "$outdir/dirinfo.$stage.$stage_id";
     192my $dirinfo = create_file("DIST.OUTPUT.DIRINFO", $dirinfo_root, \$resolved);
     193
    152194{
    153195    my $command = "$tool_cmd $list_mode";
     
    168210        &my_die("Unable to parse metadata list", $dist_id, $PS_EXIT_UNKNOWN_ERROR);
    169211
    170     open MANIFEST, ">$dirinfo" or
    171         &my_die("Unable to open dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     212    open MANIFEST, ">$resolved" or
     213        &my_die("Unable to open dirinfo file $resolved",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
    172214
    173215    my $destdir;
     
    197239        &my_die("unable to find path",  $dist_id, $PS_EXIT_UNKNOWN_ERROR) if !$path;
    198240        my $component_dir = find_componentdir($destdir, $path);
    199 #        print MANIFEST "$component METADATA\n";
    200241        print MANIFEST "\t" , "$component", "\tSTR\t", $component_dir, "\n";
    201242    }
     
    217258    }
    218259}
    219 
    220260
    221261exit 0;
  • branches/czw_branch/20101203/ippScripts/scripts/dist_bundle.pl

    r30118 r30586  
    1616
    1717use IPC::Cmd 0.36 qw( can_run run );
    18 use File::Temp qw( tempfile );
     18use File::Temp qw( tempfile tempdir );
    1919use File::Basename qw( basename );
    2020use Digest::MD5::File qw( file_md5_hex );
     
    7171# Parse the command-line arguments
    7272my ($camera, $stage, $stage_id, $component, $path_base, $chip_path_base, $alt_path_base, $clean);
    73 my ($outdir, $run_state, $data_state, $magicked, $no_magic, $poor_quality, $results_file, $prefix);
     73my ($outroot, $run_state, $data_state, $magicked, $no_magic, $poor_quality, $results_file, $prefix);
    7474my ($dbname, $save_temps, $verbose, $no_update, $logfile);
    7575
     
    8888           'magicked'       => \$magicked,   # magicked state for this component
    8989           'alt_path_base=s'=> \$alt_path_base,  # path to alternate inputs
    90            'outdir=s'       => \$outdir,     # "directory" for outputs
     90           'outroot=s'      => \$outroot,    # outroot
    9191           'prefix=s'       => \$prefix,     # "prefix" to apply to filenames
    9292           'clean'          => \$clean,      # create clean distribution
     
    9999
    100100pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    101 pod2usage( -msg => "Required options: --camera --stage --stage_id --component --path_base --outdir",
     101pod2usage( -msg => "Required options: --camera --stage --stage_id --component --path_base --outroot",
    102102           -exitval => 3) unless
    103103    defined $camera and
     
    106106    defined $component and
    107107    defined $path_base and
    108     defined $outdir;
     108    defined $outroot;
    109109
    110110$ipprc->redirect_output($logfile) if $logfile;
     
    116116$ipprc->define_camera($camera);
    117117
    118 # create the output directories if it is not a nebulous path and it doesn't exist
    119 if (index($outdir, "neb://") != 0) {
    120     if (! -e $outdir ) {
    121         my $code = system "mkdir -p $outdir";
    122         &my_die("cannot create output directory $outdir", $component,
    123                 $code >> 8) if $code;
    124     }
    125 }
     118$ipprc->outroot_prepare($outroot);
    126119
    127120# Get the list of data products for this component
     
    138131# set up directory for temporary files
    139132
    140 my $tmpdir  = "$outdir/tmpdir.$component.$$";
    141 if (-e $tmpdir) {
    142     if (-d $tmpdir) {
    143         my $rc = system "rm -r $tmpdir";
    144         &my_die("cannot rm $tmpdir return code: $rc", $component, $PS_EXIT_UNKNOWN_ERROR) if $rc;
    145     } else {
    146         unlink $tmpdir or &my_die("cannot delete $tmpdir", $component, $PS_EXIT_UNKNOWN_ERROR);
    147     }
    148 }
    149 mkdir $tmpdir or &my_die("cannot create temporary directory $tmpdir", $component,
    150                        $PS_EXIT_UNKNOWN_ERROR);
     133my $temproot = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR");
     134$temproot = "/tmp" if !defined $temproot;
     135&my_die("directory for TEMP.DIR $temproot does not exist", $component, $PS_EXIT_CONFIG_ERROR) if ! -e $temproot;
     136
     137my $tmpdir  = tempdir("$temproot/dist.XXXX", CLEANUP => !$save_temps);
    151138
    152139#
     
    349336if ($num_files) {
    350337    # create the tarfile
    351     # XXX TODO: create a file rule for the tar file name
    352     my $tbase = basename($path_base);
    353     $tbase .= ".$component" if $component;
    354     $file_name = ($prefix ? $prefix : "") . "$tbase.tgz";
    355     my $tarfile = "$outdir/$file_name";
     338#    my $tbase = basename($path_base);
     339#    $tbase .= ".$component" if $component;
     340#    $file_name = ($prefix ? $prefix : "") . "$tbase.tgz";
     341    my $error;
     342    my $output_tarfile;
     343    my $rule;
     344    if ($stage eq 'chip' or $stage eq 'chip_bg' or $stage eq 'raw') {
     345        $rule = "DIST.OUTPUT.CHIP.BUNDLE";
     346    } else {
     347        $rule = "DIST.OUTPUT.BUNDLE";
     348    }
     349    $output_tarfile = $ipprc->prepare_output($rule, $outroot, $component, 1, \$error)
     350            or &my_die("Failed to prepare output tarfile: $error", $component, $error);
     351    $file_name = basename($output_tarfile);
     352
     353
     354    my $scheme = file_scheme($output_tarfile);
     355
     356    my $tarfile;
     357    if ($scheme) {
     358        $ipprc->file_create($output_tarfile)
     359            or &my_die("Failed to create $output_tarfile: $error", $component, $error);
     360        $tarfile = $ipprc->file_resolve($output_tarfile);
     361
     362        if ($scheme eq 'neb') {
     363            &my_die("output file $output_tarfile not found", $component, $PS_EXIT_SYS_ERROR)
     364                unless ($tarfile and -e $tarfile);
     365        }
     366    } else {
     367        # no scheme the filename and the resolved filename are the same
     368        $tarfile = $output_tarfile;
     369    }
    356370
    357371    my $command = "tar -C $tmpdir --owner=ipp --group=users -czhf $tarfile .";
  • branches/czw_branch/20101203/ippScripts/scripts/dist_component.pl

    r27718 r30586  
    2121use PS::IPP::Metadata::Config;
    2222use PS::IPP::Metadata::List qw( parse_md_list );
    23 
    2423use PS::IPP::Config 1.01 qw( :standard );
    25 
    26 my $ipprc = PS::IPP::Config->new(); # IPP configuration
    2724
    2825use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    7774    defined $outdir;
    7875
     76my $ipprc = PS::IPP::Config->new($camera); # IPP configuration
    7977$ipprc->redirect_output($logfile) if $logfile;
     78
     79my $temproot = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR");
     80
     81$temproot = "/tmp" if !defined $temproot;
    8082
    8183if (($stage eq 'raw') and !$clean and !defined $chip_path_base) {
     
    8587my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    8688
    87 my ($rf, $rf_name) = tempfile("/tmp/bundleresults.$dist_id.$component.XXXX", UNLINK => !$save_temps);
     89my ($rf, $rf_name) = tempfile("$temproot/bundleresults.$dist_id.$component.XXXX", UNLINK => !$save_temps);
    8890close $rf;
     91
     92my $basename = basename($path_base);
     93my $outroot = "$outdir/$basename";
    8994
    9095my ($file_name, $bytes, $md5sum);
     
    9297    my $command = "$dist_make_bundle --camera $camera --stage $stage --stage_id $stage_id";
    9398    $command .= " --results_file $rf_name";
    94     $command .= " --component $component --path_base $path_base --outdir $outdir";
     99    $command .= " --component $component --path_base $path_base --outroot $outroot";
    95100    $command .= " --chip_path_base $chip_path_base" if $chip_path_base;
    96101    $command .= " --state $run_state" if defined $run_state;
     
    136141    &my_die("undefined file md5sum from dist_bundle.pl", $dist_id, $component, $outdir, $PS_EXIT_PROG_ERROR) unless defined $md5sum;
    137142}
     143
    138144
    139145{
  • branches/czw_branch/20101203/ippScripts/scripts/dist_defineruns.pl

    r29068 r30586  
    4242
    4343# Parse the command-line arguments
    44 my ($stage, $stage_limit, $dist_root, $no_magic);
     44my ($stage, $stage_limit, $dist_root, $workdir, $no_magic);
    4545my ($dbname, $save_temps, $verbose, $no_update, $logfile);
    4646my @labels;
     
    4949           'stage=s'        => \$stage,      # stage to queue
    5050           'label=s'        => \@labels,     # labels
     51           'workdir=s'      => \$workdir,     # workdir
    5152           'stage_limit=s'  => \$stage_limit,# maximum number of runs queued for each stage
    52            'dist_root=s'    => \$dist_root,  # root of distribution work area
     53#           'dist_root=s'    => \$dist_root,  # root of distribution work area
    5354           'no_magic'       => \$no_magic,   # queue runs without requiring magic (for testing only)
    5455           'dbname=s'       => \$dbname,     # Database name
     
    6667$ipprc->redirect_output($logfile) if $logfile;
    6768
    68 if (!$dist_root) {
    69     $dist_root = metadataLookupStr($ipprc->{_siteConfig}, "DISTRIBUTION_ROOT");
    70     &my_die("failed to find DISTRIBUTION_ROOT in site configuration", $PS_EXIT_CONFIG_ERROR) if !$dist_root;
     69if (!$workdir) {
     70    print "workdir not supplied will use DISTRIBUTION_ROOT\n";
     71    # old method where we set workdir based on a config file
     72    if (!$dist_root) {
     73        $dist_root = metadataLookupStr($ipprc->{_siteConfig}, "DISTRIBUTION_ROOT");
     74        &my_die("failed to find DISTRIBUTION_ROOT in site configuration", $PS_EXIT_CONFIG_ERROR) if !$dist_root;
     75    }
     76
     77    my ($day, $month, $year) = (gmtime)[3,4,5];
     78    my $datestr = sprintf "%04d%02d%02d", $year+1900, $month + 1, $day;
     79
     80    $workdir = $dist_root . "/$datestr";
     81
     82    print "workdir is $workdir\n";
    7183}
    72 
    73 my ($day, $month, $year) = (gmtime)[3,4,5];
    74 my $datestr = sprintf "%04d%02d%02d", $year+1900, $month + 1, $day;
    75 
    76 my $workdir = "$dist_root/$datestr";
    77 
    78 print "workdir is $workdir\n";
    7984
    8085# if stage is not supplied as an argument, loop over all stages
     
    9095        my $command = "$disttool -definebyquery -stage $stage -workdir $workdir -label $label";
    9196        $command .= " -no_magic" if $no_magic;
    92         $command .= " -dry_run" if $no_update;
     97        $command .= " -pretend" if $no_update;
    9398        $command .= " -limit $stage_limit" if $stage_limit;
    9499        $command .= " -set_label $label";
  • branches/czw_branch/20101203/ippScripts/scripts/dist_make_fileset.pl

    r28963 r30586  
    9696# make sure that the database info file for this run exists
    9797my $dbinfo_file = "$dist_dir/dbinfo.$stage.$stage_id.mdc";
    98 if (! -e "$dbinfo_file" ) {
     98if (! $ipprc->file_exists($dbinfo_file) ) {
    9999    &my_die("dbinfo file for dist run $dbinfo_file not found", $dist_id, $dest_id, $PS_EXIT_UNKNOWN_ERROR);
    100100}
     
    103103# make sure that the dirinfo file for this run exists
    104104my $dirinfo_file = "$dist_dir/dirinfo.$stage.$stage_id.mdc";
    105 if (! -e "$dirinfo_file" ) {
     105if (!$ipprc->file_exists($dirinfo_file)) {
    106106    &my_die("dirinfo file for dist run $dirinfo_file not found", $dist_id, $dest_id, $PS_EXIT_UNKNOWN_ERROR);
    107107}
     
    277277    $command .= " -dbname $dbname" if $dbname;
    278278
    279     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    280         run(command => $command, verbose => $verbose);
    281     unless ($success) {
    282         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    283         print STDERR "Unable to perform $command error_code: $error_code\n";
     279    if (!$no_update) {
     280        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     281            run(command => $command, verbose => $verbose);
     282        unless ($success) {
     283            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     284            print STDERR "Unable to perform $command error_code: $error_code\n";
     285        }
     286    } else {
     287        print STDERR "skipping $command\n";
    284288    }
    285289    exit $fault;
  • branches/czw_branch/20101203/ippScripts/scripts/ipp_apply_burntool_single.pl

    r29982 r30586  
    7474unless ($success) {
    7575    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    76     &my_die("Unable to perform ppConfigDump: $error_code", 0, 0, $class_id, $PS_EXIT_SYS_ERROR);
     76    &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    7777}
    7878
    7979my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    80     &my_die("Unable to parse metadata config doc", 0, 0, $class_id, $PS_EXIT_SYS_ERROR);
     80    &my_die("Unable to parse metadata config doc", $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    8181
    8282my $burntoolStateGood = 999;
     
    8787}
    8888if ($burntoolStateGood == 999) {
    89     &my_die("Failed to determine BURNTOOL.STATE.GOOD", $burntoolStateGood, $class_id, 0, $PS_EXIT_SYS_ERROR);
     89    &my_die("Failed to determine BURNTOOL.STATE.GOOD", $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    9090}
    9191my $outState = -1 * abs($burntoolStateGood);
     
    178178        my $exp_id = shift;
    179179        my $class_id = shift;
    180         vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
     180        vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state 0 -set_state pending_burntool",1);
    181181    }
    182182    printf STDERR "$message\n";
  • branches/czw_branch/20101203/ippScripts/scripts/ipp_cleanup.pl

    r29892 r30586  
    167167#            addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id);
    168168#            addFilename (\@files, "PPIMAGE.OUTPUT.VARIANCE", $path_base, $class_id);
    169             addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id);
    170             addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id);
    171             addFilename (\@files, "PPIMAGE.CHIP.VARIANCE", $path_base, $class_id);
     169            addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id, 1);
     170            addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id, 1);
     171            addFilename (\@files, "PPIMAGE.CHIP.VARIANCE", $path_base, $class_id, 1);
    172172            if ($mode eq "goto_purged") {
    173173                # additional files to remove for 'purge' mode
     
    429429
    430430                # delete the temporary image datafiles
    431                 addFilename(\@files, "PSWARP.OUTPUT", $path_base, $skycell_id );
    432                 addFilename(\@files, "PSWARP.OUTPUT.MASK", $path_base, $skycell_id);
    433                 addFilename(\@files, "PSWARP.OUTPUT.VARIANCE", $path_base, $skycell_id);
     431                addFilename(\@files, "PSWARP.OUTPUT", $path_base, $skycell_id, 1);
     432                addFilename(\@files, "PSWARP.OUTPUT.MASK", $path_base, $skycell_id, 1);
     433                addFilename(\@files, "PSWARP.OUTPUT.VARIANCE", $path_base, $skycell_id, 1);
    434434#            addFilename(\@files, "PSWARP.OUTPUT.SOURCES", $path_base, $skycell_id);
    435435                if ($mode eq "goto_purged") {
     
    706706            my @files = ();
    707707            # delete the temporary image datafiles
    708             addFilename(\@files, "PPSUB.OUTPUT", $path_base, $skycell_id);
    709             addFilename(\@files, "PPSUB.OUTPUT.MASK", $path_base, $skycell_id);
    710             addFilename(\@files, "PPSUB.OUTPUT.VARIANCE", $path_base, $skycell_id);
    711 
    712             addFilename(\@files, "PPSUB.INVERSE", $path_base, $skycell_id);
    713             addFilename(\@files, "PPSUB.INVERSE.MASK", $path_base, $skycell_id);
    714             addFilename(\@files, "PPSUB.INVERSE.VARIANCE", $path_base, $skycell_id);
     708            addFilename(\@files, "PPSUB.OUTPUT", $path_base, $skycell_id, 1);
     709            addFilename(\@files, "PPSUB.OUTPUT.MASK", $path_base, $skycell_id, 1);
     710            addFilename(\@files, "PPSUB.OUTPUT.VARIANCE", $path_base, $skycell_id, 1);
     711
     712            addFilename(\@files, "PPSUB.INVERSE", $path_base, $skycell_id, 1);
     713            addFilename(\@files, "PPSUB.INVERSE.MASK", $path_base, $skycell_id, 1);
     714            addFilename(\@files, "PPSUB.INVERSE.VARIANCE", $path_base, $skycell_id, 1);
    715715
    716716            addFilename(\@files, "PPSUB.INPUT.CONV", $path_base, $skycell_id);
     
    20482048    my $path_base  = shift; # base filename
    20492049    my $class_id   = shift; # class_id, if needed
     2050    my $recovery   = shift; # is there is a recovery file to clean?
    20502051
    20512052    my $file = $ipprc->filename($filerule, $path_base, $class_id);
    20522053
    20532054    push @$files, $file;
     2055   
     2056    if ($recovery) {
     2057        # need to clean up the recovery file (the pixels censored by streaksremove)
     2058        $file = $ipprc->recovery_filename($file);
     2059        push @$files, $file;
     2060    }
    20542061    return 1;
    20552062}
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak.pl

    r30118 r30586  
    6565           'cam_reduction=s'=> \$cam_reduction,  # reduction class from camera stage (for chip and raw)
    6666           'outroot=s'      => \$outroot,     # "directory" for temporary images (may be nebulous)
    67            'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels
     67           'recoveryroot=s' => \$recoveryroot,# "prefix" for saving the images of excised pixels
    6868           'replace=s'      => \$replace,    # replace the input images with the results.
    6969           'magicked=s'     => \$magicked,   # magicked state of the run
     
    190190my $recovery_path_base;
    191191if ($recoveryroot) {
    192     if (!inNebulous($recoveryroot)) {
    193         if (! -e $recoveryroot ) {
    194             my $code = system "mkdir -p $recoveryroot";
    195             &my_die("cannot create output directory $recoveryroot", $magic_ds_id, $component,
    196                     $code >> 8) if $code;
    197         }
    198     }
    199     # note: trailing / is necessary
    200     $recovery_path_base = "$recoveryroot/$basename/";
     192    # recoveryroot is a path to prepend to the basenames of the input files
     193    if (inNebulous($recoveryroot)) {
     194        # if recoveryroot is a nebulous path we ignore the actual path and put the files in the
     195        # the same "directory" as the input files
     196        $recoveryroot = "$dirname/REC_";
     197        $recovery_path_base = $recoveryroot . $basename;
     198    } else {
     199        # otherwise we put the files in recoveryroot.
     200        # Regardless, we prefix the basename with 'REC_'
     201        $ipprc->outroot_prepare($recoveryroot);
     202        $recovery_path_base = "$recoveryroot/REC_$basename";
     203    }
    201204}
    202205
     
    601604    $command   .= " -magic_ds_id $magic_ds_id";
    602605    $command   .= " -component $component";
     606    $command .= " -backup_path_base $backup_path_base" if $backup_path_base;
     607    $command .= " -recovery_path_base $recovery_path_base" if $recovery_path_base;
    603608    $command   .= " -fault $exit_code";
    604609    $command   .= " -dbname $dbname" if defined $dbname;
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_cleanup.pl

    r29829 r30586  
    233233                $bmask   = $ipprc->filename("$name.MASK", $backup_path_base);
    234234                $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
    235                 $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
     235                # bills 2011-01-24
     236                # don't clean up the uncensored sources file
     237                # $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
    236238            }
    237239            if ($recovery_path_base) {
     
    251253                $bmask   = $ipprc->filename("$name.MASK", $backup_path_base);
    252254                $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
    253                 $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
     255                # bills 2011-01-24
     256                # don't clean up the uncensored sources file
     257                # $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
    254258            }
    255259            if ($recovery_path_base) {
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_defineruns.pl

    r30118 r30586  
    4242
    4343# Parse the command-line arguments
    44 my ($stage, $stage_limit, $workdir);
     44my ($stage, $stage_limit, $workdir, $recoveryroot);
    4545my ($dbname, $save_temps, $verbose, $no_update, $logfile);
    4646my @labels;
     
    5151           'stage_limit=s'  => \$stage_limit,# maximum number of runs queued for each stage
    5252           'workdir=s'      => \$workdir,    # output destination
     53           'recoveryroot=s' => \$recoveryroot, # recovery pixels destination
    5354           'dbname=s'       => \$dbname,     # Database name
    5455           'verbose'        => \$verbose,    # Print stuff?
     
    7879    foreach my $label (@labels) {
    7980        my $command = "$magicdstool -definebyquery -stage $stage -workdir $workdir -label $label";
     81        $command .= " -recoveryroot $recoveryroot" if $recoveryroot;
    8082        $command .= " -pretend" if $no_update;
    8183        $command .= " -limit $stage_limit" if $stage_limit;
  • branches/czw_branch/20101203/ippScripts/scripts/magic_destreak_revert.pl

    r30118 r30586  
    3939# Parse the command-line arguments
    4040my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction, $magicked, $run_state);
    41 my ($outroot, $recoveryroot, $replace, $release, $bytes, $md5sum);
     41my ($outroot, $recovery_path_base, $replace, $release, $bytes, $md5sum);
    4242my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
    4343
     
    5353           'cam_reduction=s'=> \$cam_reduction,  # reduction class of the associated camera run
    5454           'outroot=s'      => \$outroot,     # "directory" for temporary images (may be nebulous)
    55            'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels
     55           'recovery_path_base=s' => \$recovery_path_base,# "directory" for saving the images of excised pixels
    5656           'replace=s'      => \$replace,    # replace the input images with the results.
    5757           'bothways=s'     => \$bothways,   # run has inverse files (bothways diff)
     
    130130
    131131# default value is "NULL" do not use it
    132 if (defined($recoveryroot) and ($recoveryroot eq "NULL")) {
    133     $recoveryroot = undef;
     132if (defined($recovery_path_base) and ($recovery_path_base eq "NULL")) {
     133    $recovery_path_base = undef;
    134134}
    135135
     
    149149}
    150150
    151 my $recovery_path_base;
    152 if ($recoveryroot) {
    153     # note: trailing / is necessary
    154     $recovery_path_base = "$recoveryroot/$basename/";
    155 }
    156 
    157151
    158152my ($image, $mask, $ch_mask, $weight, $sources, $astrom);
    159153my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom);
     154my ($rimage, $rmask, $rch_mask, $rweight);
    160155
    161156if ($stage eq "raw") {
     
    214209    $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $class_id);
    215210    $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $class_id);
     211
     212    $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $class_id);
     213    # This is somewhat kludgey but it works whether the mask is camera mask or chip mask
     214    $rmask   = dirname($recovery_path_base) . "/REC_" . basename($mask);
     215    $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $class_id);
     216    $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $class_id);
    216217} elsif ($stage eq "camera") {
    217218    $astrom =  $ipprc->filename("PSASTRO.OUTPUT", $path_base);
     
    226227    $bweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $backup_path_base);
    227228    $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base);
     229    $rimage  = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base);
     230    $rmask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $recovery_path_base);
     231    $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base);
    228232} elsif ($stage eq "diff") {
    229233    my $name = "PPSUB.OUTPUT";
     
    236240    $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
    237241    $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
     242    if ($recovery_path_base) {
     243        $rimage  = $ipprc->filename($name, $recovery_path_base);
     244        $rmask   = $ipprc->filename("$name.MASK", $recovery_path_base);
     245        $rweight = $ipprc->filename("$name.VARIANCE", $recovery_path_base);
     246    }
    238247}
    239248
    240249revert_files($replace, $image, $mask, $weight, $sources, $astrom, $bimage, $bmask, $bweight, $bsources, $bastrom);
     250if ($recovery_path_base) {
     251    delete_recovery_files($rimage, $rmask, $rweight, $rch_mask);
     252}
    241253
    242254if ($stage eq "diff" and $bothways) {
     
    251263    $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
    252264    revert_files($replace, $image, $mask, $weight, $sources, undef, $bimage, $bmask, $bweight, $bsources, undef);
     265    if ($recovery_path_base) {
     266        $rimage  = $ipprc->filename($name, $recovery_path_base);
     267        $rmask   = $ipprc->filename("$name.MASK", $recovery_path_base);
     268        $rweight = $ipprc->filename("$name.VARIANCE", $recovery_path_base);
     269        delete_recovery_files($rimage, $rmask, $rweight);
     270    }
    253271}
    254272
     
    426444
    427445
    428 sub file_check
    429 {
    430     my $file = shift;           # Name of file
    431     &my_die("Unable to find output file: $file", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR) unless
    432         $ipprc->file_exists($file);
     446sub delete_recovery_files
     447{
     448    foreach my $file (@_) {
     449        if ($ipprc->file_exists($file)) {
     450            if (!$ipprc->file_delete($file)) {
     451                &my_die("failed to delete recovery file $file", $magic_ds_id, $component, $PS_EXIT_UNKNOWN_ERROR);
     452            }
     453        }
     454    }
    433455}
    434456
  • branches/czw_branch/20101203/ippScripts/scripts/nightly_science.pl

    r30017 r30586  
    4444my ( $date, $datetime, $camera, $dbname, $logfile, $verbose, $manual);
    4545my ( $help, $isburning, $force_stack_count, $force_diff_count, $test_mode, $this_target_only, $this_filter_only, $this_mode_only, $check_mode);
    46 my ( $registration_status, $burntool_status, $observing_status);
     46my ( $registration_status, $burntool_status, $observing_status, $old_date);
    4747my ( $check_registration, $define_burntool, $queue_burntool, $check_chips, $queue_chips);
    4848my ( $check_stacks, $queue_stacks, $check_sweetspot, $queue_sweetspot, $check_diffs, $queue_diffs, $clean_old);
     
    6666    'registraion_status'   => \$registration_status,
    6767    'burntool_status'      => \$burntool_status,
     68    'old_date=s'           => \$old_date,
    6869    'check_stacks'         => \$check_stacks,
    6970    'queue_stacks'         => \$queue_stacks,
     
    134135unless ($success) {
    135136    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    136     &my_die("Unable to perform ppConfigDump: $error_code", $date, $PS_EXIT_SYS_ERROR);
     137    &my_die("Unable to perform ppConfigDump: $error_code", 0, 0, $date, $PS_EXIT_SYS_ERROR);
    137138}
    138139
     
    278279
    279280$metadata_out{nsObservingState} = &get_observing_state($date);
     281$metadata_out{nsRegistrationState} = &get_registration_state($date);
    280282#
    281283# Mode selection
     
    396398    exit(0);
    397399}
    398 exit(10);
     400
    399401if (defined($check_confirm_stacks) || defined($test_mode)) {
    400402    $metadata_out{nsStackState} = 'CONFIRM_STACKING';
     
    409411    exit(0);
    410412}
    411 
     413exit(10);
    412414if (defined($check_sweetspot) || defined($test_mode) || defined($check_mode)) {
    413415    $metadata_out{nsSSState} = 'CHECKSWEETSPOT';
     
    10971099    my $pretend = shift;
    10981100
     1101    my $Npotential = 0;
     1102    my $Nqueued = 0;
     1103    my $is_processing = 0;
     1104    my $is_registering;
     1105    if ($metadata_out{nsRegistrationState} eq 'REGISTERED') {
     1106        $is_registering = 0;
     1107    }
     1108    else {
     1109        $is_registering = 1;
     1110    }
     1111
    10991112    foreach my $target (sort (keys %science_config)) {
    11001113        if ($science_config{$target}{STACKABLE} == 1) {
     
    11051118                        print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";
    11061119                    }
     1120                    $is_processing = 1;
    11071121                    $metadata_out{nsStackState} = 'FORCETOWARP';
    11081122                    next;
     
    11201134                    next;
    11211135                }
     1136                $Npotential++;
    11221137                if ($Nalready != 0) {
     1138                    $Nqueued++;
    11231139                    if ($debug == 1) {
    11241140                        print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n";
     
    11371153                    }
    11381154                    stack_queue($date,$target,$filter);
     1155                    $Nqueued ++;
    11391156                }
    11401157                if (defined($pretend)) {
     
    11521169        }
    11531170    }
     1171    $metadata_out{nsStackPotential} = $Npotential;
     1172    $metadata_out{nsStackQueued}    = $Nqueued;
     1173    if (($Npotential == $Nqueued)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)&&($is_registering == 0)) {
     1174        $metadata_out{nsStackState} = 'FINISHED_STACKS';
     1175    }   
    11541176}
    11551177
     
    12311253    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
    12321254
    1233     my $sth = "SELECT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where data_group = '$data_group' AND warp1 = $warp_id_1 AND warp2 = $warp_id_2";
     1255    my $count = 0;
     1256   
     1257    my $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where data_group = '$data_group' AND warp1 = $warp_id_1 AND warp2 = $warp_id_2";
    12341258    my $data_ref = $db->selectall_arrayref( $sth );
    1235 
    1236     return($#{ $data_ref } + 1);
     1259    $count += $#{ $data_ref } + 1;
     1260
     1261    $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where data_group = '$data_group' AND warp1 = $warp_id_2 AND warp2 = $warp_id_1";
     1262    $data_ref = $db->selectall_arrayref( $sth );
     1263    $count += $#{ $data_ref } + 1;
     1264
     1265    return($count);
    12371266}
    12381267
     
    12721301    my $pretend = shift;
    12731302
     1303    my $Npotential = 0;
     1304    my $Nnoexp     = 0;
     1305    my $is_processing = 0;
     1306    my $is_registering;
     1307    if ($metadata_out{nsRegistrationState} eq 'REGISTERED') {
     1308        $is_registering = 0;
     1309    }
     1310    else {
     1311        $is_registering = 1;
     1312    }
     1313
    12741314    foreach my $target (sort (keys %science_config)) {
    12751315        if ($science_config{$target}{DIFFABLE} == 1) {
    12761316            foreach my $filter (@filter_list) {
     1317                $Npotential ++;
    12771318                my ($NprocChips,$NprocWarps) = pre_diff_queue($date,$observing_state,$target,$filter);
    12781319                if ((!defined($force_diff_count))&&($NprocChips != $NprocWarps)) {
     
    12801321                        print STDERR "execute_diffs: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";
    12811322                    }
    1282                     $metadata_out{nsDiffState} = 'FORCETOWARP';
    1283                     next;
    1284                 }
     1323                    $is_processing = 1;
     1324                }
    12851325                if ($NprocChips == 0) {
     1326                    $Nnoexp ++;
    12861327                    if ($debug == 1) {
    12871328                        print STDERR "execute_diffs: Target $target in filter $filter on $date has no exposures.\n";
     
    13111352        }
    13121353    }
     1354    if ($debug == 1) {
     1355        print "$metadata_out{nsObservingState} $metadata_out{nsDiffPotential} $metadata_out{nsDiffQueued} $is_processing $is_registering\n";
     1356    }
     1357
     1358    if ($metadata_out{nsObservingState} eq 'END_OF_NIGHT') {
     1359        if ($is_processing == 1) {
     1360            $metadata_out{nsDiffState} = 'DIFFING';
     1361        }
     1362        elsif ($is_registering == 0) {
     1363            if ($Npotential == $Nnoexp) {
     1364                $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1365            }
     1366            elsif ($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued}) {
     1367                $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1368            }
     1369        }
     1370        else {
     1371            $metadata_out{nsDiffState} = 'DIFFING';
     1372        }
     1373    }
     1374    else {
     1375        $metadata_out{nsDiffState} = 'DIFFING';
     1376    }
     1377
     1378#     if (($Npotential == $Nnoexp)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)) {
     1379#       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1380#     }
     1381
     1382#     if ($is_processing == 1) {
     1383#       $metadata_out{nsDiffState} = 'DIFFING';
     1384#     }
    13131385}
    13141386
     
    13261398
    13271399    my $object_ref = $db->selectall_arrayref( $obj_sth );
     1400
     1401    my $Npotential = 0;
     1402    my $Nqueued = 0;
    13281403   
    13291404    foreach my $object_row (@{ $object_ref }) {
    13301405        my $this_object = shift @{ $object_row };
    1331         my $input_sth = "select exp_id,warp_id,dateobs from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
    1332         $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
    1333         $input_sth .= " ORDER BY dateobs ";
     1406#       my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
     1407#       $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1408#       $input_sth .= " ORDER BY dateobs ";
    13341409       
     1410        my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM ";
     1411        $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     1412        $input_sth .=   " WHERE chipRun.label = '$label' AND chipRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1413        $input_sth .=   " ORDER BY dateobs ";
     1414
    13351415        my $warps = $db->selectall_arrayref( $input_sth );
     1416
     1417        # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     1418        my %comment_hash = ();
     1419        foreach my $this_warp (@{ $warps }) {
     1420            my $this_comment = ${ $this_warp }[3];
     1421            my $this_exp_id  = ${ $this_warp }[0];
     1422            $comment_hash{$this_comment} = $this_exp_id;
     1423        }
    13361424       
    13371425        if (($#{ $warps } + 1) % 2 != 0) {
    1338             print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps }\n";
    1339             next;
     1426            print STDERR "diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     1427            if ($#{ $warps} + 1 == 1) {
     1428                print STDERR ": I can do no diffs with only one exposure.\n";
     1429                next;
     1430            }
     1431            else {
     1432                print STDERR ": I should declare an exposure to be faulty.\n";
     1433                my @keep_warps = ();
     1434#               print "@{ $warps }\n";
     1435                foreach my $this_warp (@{ $warps }) {
     1436                    my $this_comment = ${ $this_warp }[3];
     1437                    my $this_exp_id  = ${ $this_warp }[0];
     1438                    if ($comment_hash{$this_comment} == $this_exp_id) {
     1439                        push @keep_warps, $this_warp;
     1440                    }
     1441                    else {
     1442                        print STDERR "diff_queue: excluding $this_exp_id for $this_object\n";
     1443                    }
     1444                }
     1445                @{ $warps } = @keep_warps;
     1446#               print "@{ $warps }\n";
     1447            }
    13401448        }
    13411449       
    13421450        while ($#{ $warps } > -1) {
    13431451            my $input_warp = shift @{ $warps };
     1452            my $input_exp_id = ${ $input_warp }[0];
     1453            my $input_comment = ${ $input_warp }[3];
     1454
     1455           
    13441456            my $template_warp = shift @{ $warps };
    1345             my $input_exp_id = ${ $input_warp }[0];
     1457
    13461458            my $template_exp_id = ${ $template_warp }[0];
    13471459           
    13481460            my $input_warp_id = ${ $input_warp }[1];
    13491461            my $template_warp_id = ${ $template_warp }[1];
     1462
     1463            my $input_warp_state = ${ $input_warp }[4];
     1464            my $template_warp_state = ${ $template_warp }[4];
    13501465           
     1466            $Npotential++;
     1467
     1468            unless (defined($input_warp_id) && defined($template_warp_id) &&
     1469                    ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     1470                print STDERR "Diff for this $date $target $input_exp_id $template_exp_id not fully processed\n";
     1471                next;
     1472            }
     1473
    13511474            if (verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
    1352                 print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id\n";
     1475                $Nqueued++;
     1476                print STDERR "Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
    13531477                next;
    13541478            }
     
    13661490                $cmd .= ' -pretend ';
    13671491                print STDERR "diff_queue: $cmd\n";
     1492                print STDERR " $input_warp_id $template_warp_id\n";
    13681493            }
    13691494           
     
    13751500                    &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    13761501                }
    1377             }
    1378         }
    1379     }
     1502                $Nqueued++;
     1503            }
     1504        }
     1505    }
     1506    $metadata_out{nsDiffPotential} += $Npotential;
     1507    $metadata_out{nsDiffQueued}    += $Nqueued;
     1508#      if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {
     1509#       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1510#      }       
     1511
    13801512}
    13811513           
     
    14931625        }
    14941626    }   
    1495 
     1627#    print "$datetime $eon_dt\n";
    14961628    if (DateTime->compare($datetime,$eon_dt) < 1) {
    14971629        return("OBSERVING");
     
    15011633    }
    15021634}
     1635
     1636# This basically does the end of night check, but does it "the hard way," to prevent the time from fooling us.
     1637sub get_registration_state {
     1638    my $date = shift;
     1639
     1640    foreach my $eon (keys %eon_config) {
     1641        my $command = "$regtool -processedexp -simple ";
     1642        $command .= " -dbname $dbname ";
     1643        $command .= " -dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
     1644        $command .= " -object $eon_config{$eon}{OBJECT} " if defined($eon_config{$eon}{OBJECT});
     1645        $command .= " -obs_mode $eon_config{$eon}{OBSMODE} " if defined($eon_config{$eon}{OBSMODE});
     1646        $command .= " -exp_type $eon_config{$eon}{EXPTYPE} " if defined($eon_config{$eon}{EXPTYPE});
     1647        $command .= " -comment $eon_config{$eon}{COMMENT} " if defined($eon_config{$eon}{COMMENT});
     1648
     1649        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1650            run ( command => $command, verbose => $verbose );
     1651        unless ($success) {
     1652            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1653            &my_die("Unable to perform regtool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     1654        }
     1655        my @eon_exposures = split /\n/, (join '', @$stdout_buf);
     1656        if ($#eon_exposures >= 0) {
     1657            return("REGISTERED");
     1658        }
     1659    }   
     1660    return("NOT_REGISTERED");
     1661}
     1662
     1663   
    15031664
    15041665sub get_tool_parameters {
     
    16201781    my $stage = shift; # stage name
    16211782    my $stage_id = shift; #  identifier
     1783    my $date = shift;
    16221784    my $exit_code = shift; # Exit code
    1623     # outputImage and path_base are globals
    16241785
    16251786    carp($msg);
  • branches/czw_branch/20101203/ippScripts/scripts/publish_file.pl

    r30118 r30586  
    4242
    4343# Parse the command-line arguments
    44 my ( $pub_id, $camera, $stage, $stage_id, $fileset, $format, $product, $workdir );
     44my ( $pub_id, $camera, $stage, $stage_id, $fileset, $format, $product, $workdir, $need_magic );
    4545my ( $dbname, $verbose, $no_update, $no_op, $save_temps, $redirect );
    4646my ( $output_format );
     
    5454    'fileset=s'         => \$fileset,     # Fileset name
    5555    'workdir=s'         => \$workdir,     # Working directory
     56    'need-magic'        => \$need_magic,  # do we require censored detections?
    5657    'dbname=s'          => \$dbname,    # Database name
    5758    'verbose'           => \$verbose,   # Print to stdout
     
    166167    foreach my $comp ( @$components ) {
    167168        my $path_base = $comp->{path_base}; # Base name for file
     169        if (!$need_magic and $comp->{magicked}) {
     170            # This client is authorized to receive uncensored detections
     171            # Get the uri for the "backup" files
     172            print "Using uncensored input from $path_base\n";
     173            $path_base = $ipprc->destreaked_filename($path_base);
     174        }
    168175        next if defined $comp->{quality} and $comp->{quality} > 0;
    169176        print "Warning: mis-matched comments\n" if defined $comment and $comment ne $comp->{comment};
     
    181188            $filename = $ipprc->filename( "PSPHOT.OUT.CMF.MEF", "$path_base.pos" );
    182189        }
    183         $filename = $ipprc->file_resolve($filename);
     190        &my_die("input file does not exist: $filename", $pub_id, $PS_EXIT_SYS_ERROR) if !$ipprc->file_exists($filename);
     191        my $resolved = $ipprc->file_resolve($filename);
     192       
     193        &my_die("unable to resolve input file: $filename", $pub_id, $PS_EXIT_SYS_ERROR) if !$resolved;
     194
     195        $filename = $resolved;
    184196
    185197        my $data = { zp => $zp,
  • branches/czw_branch/20101203/ippScripts/scripts/register_exp.pl

    r30047 r30586  
    348348    if (defined $exp_id and not $no_update) {
    349349        my $command = "$regtool -addprocessedexp -exp_id $exp_id -fault $exit_code";
     350        $command .= " -exp_tag $exp_tag";
     351        $command .= " -exp_name UNKNOWN";
     352        $command .= " -inst UNKNOWN";
     353        $command .= " -telescope UNKNOWN";
     354        $command .= " -telescope UNKNOWN";
     355        $command .= " -filelevel UNKNOWN";
    350356        $command .= " -hostname $host" if defined $host;
    351357        $command .= " -dbname $dbname" if defined $dbname;
  • branches/czw_branch/20101203/ippScripts/scripts/register_imfile.pl

    r30118 r30586  
    1010my $date = `date`;
    1111print "\n\n";
    12 print "Starting script $0 on $host at $date\n\n";
     12my $cmd_line = join ' ', @ARGV;
     13print "Starting script $0 $cmd_line on $host at $date\n\n";
    1314
    1415use vars qw( $VERSION );
     
    3940
    4041my ($cache, $exp_id, $tmp_class_id, $tmp_exp_name, $uri, $bytes, $md5sum, $dbname, $verbose, $no_update, $no_op, $logfile);
     42my ($sunrise, $sunset);
    4143GetOptions(
    4244    'caches'           => \$cache,
     
    4749    'bytes=s'          => \$bytes,
    4850    'md5sum=s'         => \$md5sum,
     51    'sunrise=s'        => \$sunrise,
     52    'sunset=s'         => \$sunset,
    4953    'dbname|d=s'       => \$dbname,    # Database name
    5054    'verbose'          => \$verbose,   # Print to stdout
     
    5458) or pod2usage( 2 );
    5559
    56 my $ipprc = PS::IPP::Config->new() or my_die( "Unable to set up", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    57 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_SYS_ERROR ) if $logfile;
     60my $ipprc = PS::IPP::Config->new() or my_die_for_add( "Unable to set up", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     61$ipprc->redirect_output($logfile) or my_die_for_add( "Unable to redirect output", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_SYS_ERROR ) if $logfile;
    5862
    5963pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    6569    defined $uri;
    6670
     71unless (defined($sunset)) {
     72    $sunset = '03:30:00';
     73}
     74unless (defined($sunrise)) {
     75    $sunrise = '17:30:00';
     76}
    6777
    6878my $RECIPE = "REGISTER"; # Recipe to use for ppStats
     
    8494
    8595my $cmdflags;
    86 my $burntoolStateGood;
     96my $burntoolStateTarget;
     97my $burntoolStateCurrent;
    8798# Run ppStats on the input file
    8899{
     
    101112    print "STDOUT:\n$out1";
    102113    print "STDERR:\n$err1";
    103     &my_die("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h1->result() or $PS_EXIT_PROG_ERROR) ) unless $result1;
     114    &my_die_for_add("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h1->result() or $PS_EXIT_PROG_ERROR) ) unless $result1;
    104115
    105116    print "[Running " . join(' ', @command2) . "]\n";
     
    110121    print "STDOUT:\n$out2";
    111122    print "STDERR:\n$err2";
    112     &my_die("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h2->result() or $PS_EXIT_PROG_ERROR) ) unless $result2;
     123    &my_die_for_add("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h2->result() or $PS_EXIT_PROG_ERROR) ) unless $result2;
    113124    chomp $out2;
    114125    $cmdflags = $out2;
    115126
    116127    # Manually parse the burntool_state entry.
    117     my $burntoolState = 0;
     128    $burntoolStateCurrent = 0;
    118129    my $isGPC1 = 0;
    119     $burntoolStateGood = 0;
     130    $burntoolStateTarget = 0;
    120131    foreach my $line (split /\n/, $out1) {
    121132        if ($line =~ /FPA.BURNTOOL.APPLIED/) {
    122133            $line =~ s/^\s+//;
    123             $burntoolState = (split /\s+/, $line)[2];
     134            $burntoolStateCurrent = (split /\s+/, $line)[2];
    124135        }
    125136        if ($line =~ /FPA.CAMERA/) {
     
    131142    }
    132143    if ($isGPC1 != 1) {
    133         $burntoolState = 0; # If it's not GPC1, you shouldn't have run burntool.
    134     }
    135     elsif (($isGPC1 == 1) && ($burntoolState == 1)) {
    136 #       print STDERR "In the good region: >>$burntoolState<<\n";
     144        $burntoolStateCurrent = 0; # If it's not GPC1, you shouldn't have run burntool.
     145    }
     146    elsif (($isGPC1 == 1) && ($burntoolStateCurrent == 1)) {
     147#       print STDERR "In the good region: >>$burntoolStateCurrent<<\n";
    137148        my $ppConfigDump_cmd = "$ppConfigDump -camera GPC1 -dump-camera -";
    138149        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    148159            if ($line =~ /BURNTOOL.STATE.GOOD/) {
    149160                $line =~ s/^\s+//;
    150                 $burntoolStateGood = (split /\s+/, $line)[2];
     161                $burntoolStateTarget = (split /\s+/, $line)[2];
    151162                last;
    152163            }
    153164        }
    154         $burntoolState = $burntoolStateGood; # Positive because this has the header table.
    155 
    156     }
    157     $cmdflags .= " -burntool_state $burntoolState ";
     165        # XXX why was this being equated??
     166        # $burntoolState = $burntoolStateGood; # Positive because this has the header table.
     167
     168    }
     169    $cmdflags .= " -burntool_state $burntoolStateTarget ";
    158170}
    159171
    160172$now_time = localtime();
    161173printf STDERR "\ndone with ppStats: %s\n", $now_time if $verbose;
     174printf STDERR "\nburntool state current: %d target: %d\n", $burntoolStateCurrent, $burntoolStateTarget;
    162175
    163176# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
    164 if (uc(&value_for_flag ($cmdflags, "NULL", "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    165 if (uc(&value_for_flag ($cmdflags, "NULL", "-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    166 if (uc(&value_for_flag ($cmdflags, "NULL", "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    167 if (uc(&value_for_flag ($cmdflags, "NULL", "-class_id"))  eq "NULL") { &my_die ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    168 if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     177if (uc(&value_for_flag ($cmdflags, "NULL", "-telescope")) eq "NULL") { &my_die_for_add ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     178if (uc(&value_for_flag ($cmdflags, "NULL", "-inst"))      eq "NULL") { &my_die_for_add ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     179if (uc(&value_for_flag ($cmdflags, "NULL", "-filelevel")) eq "NULL") { &my_die_for_add ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     180if (uc(&value_for_flag ($cmdflags, "NULL", "-class_id"))  eq "NULL") { &my_die_for_add ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     181if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die_for_add ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     182my $dateobs   = &value_for_flag($cmdflags, 0.0, "-dateobs");
    169183
    170184my $command = "$regtool -addprocessedimfile";
     
    177191$command .= " -hostname $host" if defined $host;
    178192$command .= " -dbname $dbname" if defined $dbname;
    179 $command .= " -data_state check_burntool";
     193if (abs($burntoolStateCurrent) == $burntoolStateTarget) {
     194    printf STDERR "This has already been burned.\n";
     195    $command .= " -data_state full";
     196}
     197elsif (is_daytime($dateobs,$sunrise,$sunset)) {
     198    printf STDERR "This is a daytime exposure.\n";
     199    $command .= " -data_state full";
     200}
     201else {
     202    printf STDERR "Need to check burntool.\n";
     203    $command .= " -data_state check_burntool";
     204}
    180205$command .= " $cmdflags";
    181206
     
    187212my $ra        = &value_for_flag($cmdflags, 0.0, "-ra");
    188213my $dec       = &value_for_flag($cmdflags, 0.0, "-decl");
    189 my $dateobs   = &value_for_flag($cmdflags, 0.0, "-dateobs");
     214
    190215
    191216# if the needed data is available, pass it to sunmoon:
     
    216241# lock file?
    217242# if exp_type = DARK and date > MIDNIGHT HST { wait }
    218 # system("ipp_apply_burntool.pl --class_id $class_id --dateobs_begin $date_start --dateobs_end $date_end --dbname gpc1 --logfile /data/$host.0/burntool_logs/$class_id.$start_date.log"); 
     243# system("ipp_apply_burntool.pl --class_id $class_id --dateobs_begin $date_start --dateobs_end $date_end --dbname gpc1 --logfile /data/$host.0/burntool_logs/$class_id.$start_date.log");
    219244
    220245$now_time = localtime();
     
    236261# We now have an imfile in the database, check if we can burntool it.  If not, continue on.
    237262
    238 {
     263if ((abs($burntoolStateCurrent) != $burntoolStateTarget)&&
     264    (!is_daytime($dateobs,$sunrise,$sunset))) {
    239265    my $mdcParser  = PS::IPP::Metadata::Config->new;
    240266
     
    243269    $check_date =~ s/T.*$//;
    244270    my $exp_name   = $tmp_exp_name;
    245    
     271
    246272
    247273    my $bt_check_command = "$regtool -checkburntoolimfile ";
    248274    $bt_check_command .= " -class_id $class_id ";
    249     $bt_check_command .= " -date $check_date ";
    250     $bt_check_command .= " -valid_burntool $burntoolStateGood ";
     275    $bt_check_command .= " -dateobs_begin ${check_date}T${sunset} ";
     276    $bt_check_command .= " -dateobs_end ${check_date}T${sunrise} ";
     277    $bt_check_command .= " -valid_burntool $burntoolStateTarget ";
    251278    $bt_check_command .= " -exp_name $exp_name ";
    252279    $bt_check_command .= " -dbname $dbname" if defined $dbname;
    253280
    254281    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    255         run ( command => $bt_check_command, verbose => $verbose);
     282        run ( command => $bt_check_command, verbose => $verbose);
    256283    unless ($success) {
    257         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    258         &my_die("Unable to perform regtool: $error_code",
    259                 $class_id, $exp_name, $date, $PS_EXIT_SYS_ERROR);
     284        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     285        &my_die_for_update("Unable to perform regtool: $error_code",
     286                           $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    260287    }
    261288
     
    264291    my $exposures;
    265292    while ( scalar @whole > 0 ) {
    266         my $value = shift @whole;
    267         push @single, $value;
    268         if ($value =~ /^\s*END\s*$/) {
    269             push @single, "\n";
    270            
    271             my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
    272             &my_die("Unable to parse output from regtool",
    273                     $class_id, $exp_name, $date, $PS_EXIT_SYS_ERROR) unless
    274                         defined $list;
    275             push @{ $exposures }, @$list;
    276             @single = ();
    277         }
    278     }
    279    
     293        my $value = shift @whole;
     294        push @single, $value;
     295        if ($value =~ /^\s*END\s*$/) {
     296            push @single, "\n";
     297
     298            my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
     299            &my_die_for_update("Unable to parse output from regtool",
     300                               $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless
     301                                   defined $list;
     302            push @{ $exposures }, @$list;
     303            @single = ();
     304        }
     305    }
     306
    280307    # We only care about the final entry, as that contains the exposure we are.
    281    
     308
    282309    my $regtool_update = "$regtool -updateprocessedimfile ";
    283310    $regtool_update .= "-dbname $dbname " if defined $dbname;
     
    286313    my $burntool_data = pop(@{ $exposures });
    287314    if ($burntool_data->{burnable} == 0) {
    288         $regtool_update .= " -burntool_state 0 -set_state pending_burntool ";
    289         unless ($no_update) {
    290             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    291                 IPC::Cmd::run(command => $regtool_update, verbose => $verbose);
    292             unless ($success) {
    293                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    294                 warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    295                 exit($error_code);
    296             }
    297         } else {
    298             print "skipping command: $command\n";
    299         }
     315        $regtool_update .= " -burntool_state 0 -set_state pending_burntool ";
     316        unless ($no_update) {
     317            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     318                IPC::Cmd::run(command => $regtool_update, verbose => $verbose);
     319            unless ($success) {
     320                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     321                warn ("Unable to perform regtool -addprocessedimfile: $error_code");
     322                exit($error_code);
     323            }
     324        } else {
     325            print "skipping command: $command\n";
     326        }
    300327    }
    301328    else {
    302         my $apply_command = "$ippApplyBurntoolSingle --dbname $dbname ";
    303         $apply_command .= " --class_id $class_id --exp_id $exp_id ";
    304         $apply_command .= " --this_uri $burntool_data->{uri} ";
    305         $apply_command .= " --previous_uri $burntool_data->{previous_uri} " if defined $burntool_data->{previous_uri};
    306         $apply_command .= " --imfile_state $burntool_data->{imfile_state} ";
    307         $apply_command .= " --verbose " if $verbose;
    308         print "$apply_command\n";
    309         unless ($no_update) {
    310             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    311                 IPC::Cmd::run(command => $apply_command, verbose => $verbose);
    312             unless ($success) {
    313                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    314                 warn ("Unable to perform ipp_apply_burntool_single.pl: $error_code");
    315                 exit($error_code);
    316             }
    317         }
    318     }   
     329        my $apply_command = "$ippApplyBurntoolSingle --dbname $dbname ";
     330        $apply_command .= " --class_id $class_id --exp_id $exp_id ";
     331        $apply_command .= " --this_uri $burntool_data->{uri} ";
     332        $apply_command .= " --previous_uri $burntool_data->{previous_uri} " if defined $burntool_data->{previous_uri};
     333        $apply_command .= " --imfile_state $burntool_data->{imfile_state} ";
     334        $apply_command .= " --verbose " if $verbose;
     335        print "$apply_command\n";
     336        unless ($no_update) {
     337            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     338                IPC::Cmd::run(command => $apply_command, verbose => $verbose);
     339            unless ($success) {
     340                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     341                &my_die_for_update("Unable to perform ipp_apply_burntool_single.pl: $error_code",
     342                               $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
     343            }
     344        }
     345    }
    319346
    320347
     
    353380}
    354381
    355 sub my_die
     382sub is_daytime
     383{
     384    my $dateobs = shift;
     385    my $sunset  = shift;
     386    my $sunrise = shift;
     387
     388    my ($date,$time);
     389
     390    if ($dateobs =~ /T/) {
     391        ($date,$time) = split /T/, $dateobs;
     392    }
     393    else {
     394        ($date,$time) = split / /, $dateobs;
     395    }
     396    my ($hour,$minute,$second) = split /\:/, $time; # /;
     397    my ($ss_hour,$ss_minute,$ss_second) = split /\:/, $sunset; # /;
     398    my ($sr_hour,$sr_minute,$sr_second) = split /\:/, $sunrise; # /;
     399    if ($second =~ /Z/) {
     400        $second =~ s/Z//;
     401    }
     402#     print "this exposure: $hour $minute $second\n";
     403#     print "sunset:        $ss_hour $ss_minute $ss_second\n";
     404#     print "sunrise:       $sr_hour $sr_minute $sr_second\n";
     405#     printf "Hss: %d Mss: %d Sss: %d\n",($hour >= $ss_hour),($minute >= $ss_minute),($second >= $ss_second);
     406#     printf "Hsr: %d Msr: %d Ssr: %d\n",($hour <= $sr_hour),($minute <= $sr_minute),($second <= $sr_second);
     407
     408    if (($hour > $ss_hour)&&($hour <= 24)) {
     409        return(1); # After sunset by more than an hour, before midnight
     410    }
     411    elsif ($hour == $ss_hour) {
     412        if ($minute > $ss_minute) {
     413            return(1); # After sunset by more than a minute
     414        }
     415        elsif ($minute == $ss_minute) {
     416            if ($second >= $ss_second) {
     417                return(1); # After sunset by more than a second
     418            }
     419            else {
     420                return(0);
     421            }
     422        }
     423        else {
     424            return(0);
     425        }
     426    }
     427    elsif (($hour < $sr_hour)&&($hour >= 0)) {
     428        return(1); # Before sunrise by more than an hour, but after midnight
     429    }
     430    elsif ($hour == $sr_hour) {
     431        if ($minute < $sr_minute) {
     432            return(1); # Before sunrise by more than a minute
     433        }
     434        elsif ($minute == $sr_minute) {
     435            if ($second <= $sr_second) {
     436                return(1); # Before sunrise by more than a second
     437            }
     438            else {
     439                return(0);
     440            }
     441        }
     442        else {
     443            return(0);
     444        }
     445    }
     446    else {
     447        return(0); # We should never get here.
     448    }
     449}
     450
     451sub my_die_for_add
    356452{
    357453    my $msg = shift; # Warning message on die
     
    384480    exit $exit_code;
    385481}
     482sub my_die_for_update
     483{
     484    my $msg = shift; # Warning message on die
     485    my $exp_id = shift;
     486    my $class_id = shift;
     487    my $exit_code = shift;
     488
     489    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
     490
     491    carp($msg);
     492    if (defined $exp_id && defined $tmp_class_id and not $no_update) {
     493        my $command = "$regtool -updateprocessedimfile";
     494        $command .= " -exp_id $exp_id";
     495        $command .= " -class_id $class_id";
     496        $command .= " -fault $exit_code";
     497        $command .= " -hostname $host" if defined $host;
     498        $command .= " -dbname $dbname" if defined $dbname;
     499        print "Running: $command\n";
     500        system($command);
     501    }
     502    exit $exit_code;
     503}
    386504
    387505# Pau.
Note: See TracChangeset for help on using the changeset viewer.