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:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • 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);
Note: See TracChangeset for help on using the changeset viewer.