IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 19, 2010, 11:26:51 PM (16 years ago)
Author:
watersc1
Message:

Bug fix to add confirm stacks mode and macro code to nightly_stacks.pro

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/automate_stacks.pl

    r28916 r28982  
    4646my ( $check_stacks, $queue_stacks, $check_sweetspot, $queue_sweetspot, $check_diffs, $queue_diffs, $clean_old);
    4747my ( $check_detrends, $queue_detrends, $check_dqstats, $queue_dqstats);
     48my ( $confirm_stacks, $check_confirm_stacks );
    4849
    4950GetOptions(
     
    7071    'check_stacks'         => \$check_stacks,
    7172    'queue_stacks'         => \$queue_stacks,
     73    'confirm_stacks'       => \$confirm_stacks,
     74    'check_confirm_stacks' => \$check_confirm_stacks,
    7275    'check_sweetspot'      => \$check_sweetspot,
    7376    'queue_sweetspot'      => \$queue_sweetspot,
     
    132135my %stackable_list = ();
    133136my %reduction_class = ();
     137my %macro_formats = ();
    134138my @unrecoverable_quality = ();
    135139my @detrend_list = ();
     
    181185    elsif (${ $entry }{name} eq 'UNRECOVERABLE_QUALITY') {
    182186        push @unrecoverable_quality, ${ $entry }{value};
     187    }
     188    elsif (${ $entry }{name} eq 'MACRO_DEFINITIONS') {
     189        my @macro_data = @{ ${ $entry }{value} };
     190        my $this_mode = '';
     191        foreach my $mentry (@macro_data) {
     192            if (${ $mentry }{name} eq 'PROC_MODE') {
     193                $this_mode = ${ $mentry }{value};
     194            }
     195            elsif (${ $mentry }{name} eq 'MACRO') {
     196                $macro_formats{$this_mode} = ${ $mentry }{value};
     197            }
     198        }
    183199    }
    184200    elsif (${ $entry }{name} eq 'TARGETS') {
     
    306322        print "CLEAN: $z $clean_commands{$z} $clean_retention{$z}\n";
    307323    }
     324    foreach $z (keys (%macro_formats)) {
     325        print "MACROS: $z $macro_formats{$z}\n";
     326    }
    308327   
    309328}
     
    385404        $metadata_out{nsState} = 'STACKING_POSSIBLE_ERROR';
    386405    }
     406    return_metadata($date);
     407    exit(0);
     408}
     409
     410if (defined($check_confirm_stacks) || defined($test_mode) || defined($check_mode)) {
     411    $metadata_out{nsState} = 'CONFIRM_STACKING';
     412    &confirm_stacks($date,"pretend");
     413    return_metadata($date);
     414    unless (defined($test_mode) || defined($check_mode)) { exit(0); }
     415}
     416if (defined($confirm_stacks)) {
     417    $metadata_out{nsState} = 'CONFIRM_STACKING';
     418    &confirm_stacks($date);
    387419    return_metadata($date);
    388420    exit(0);
     
    582614    $metadata_out{btN} = $N - 1;
    583615    $metadata_out{btNCounter} = 0;
    584 
     616    add_to_macro_list('define_burntool',1,$date);
    585617    return(0);
    586618}
     
    589621# Chips
    590622################################################################################
     623
    591624
    592625sub construct_chiptool_cmd {
     
    680713    }
    681714    $metadata_out{nsState} = 'TOWARP';
     715
    682716    return(0);
    683717}
     
    696730        if ($Nexposures == 0) {
    697731            print STDERR "execute_chips: Target $target on $date had no exposures.\n";
    698             next;
     732#           next;
    699733        }
    700734        if ($Nalready != 0) {
    701735            print STDERR "execute_chips: Not queueing $target on $date due to already existing exposures.\n";
    702             next;
     736#            next;
    703737        }
    704738        if ($Nimfiles != $Nburntooled) {
     
    712746            chip_queue($date,$target);
    713747        }
     748        if (defined($pretend)) {
     749            add_to_macro_list('check_chips',$stackable_list{$target},$date,$target);
     750        }
     751        else {
     752            add_to_macro_list('queue_chips',$stackable_list{$target},$date,$target);
     753        }
     754                   
    714755    }
    715756    if ($exposures == 0) {
     
    717758    }
    718759}
     760
    719761
    720762#
     
    742784    my $date = shift;
    743785   
    744 #     my $db = init_gpc_db();
    745 #     my $trunc_date = $date; $trunc_date =~ s/-//g;
    746 
    747 #     my $where = " label LIKE '%.nightlyscience' AND data_group' ";
    748 #     my $chip_sth = "SELECT * from chipRun WHERE (state = 'full' OR state = 'new' OR state = 'cleaned') AND $where ";
    749 #     my $cam_sth = "SELECT * from camRun WHERE state = 'full' AND $where ";
    750 
    751 #     my $chip_ref = $db->selectall_arrayref( $chip_sth );
    752 #     my $cam_ref = $db->selectall_arrayref( $cam_sth );
    753    
    754786    my $command = construct_dqstats_cmd($date) . ' -pretend ';
    755787    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    762794    my @input_exposures = split /\n/, (join '', @$stdout_buf);
    763795
    764     return($#input_exposures + 1,1,1); # $#{ $chip_ref } + 1, $#{ $cam_ref } + 1);
     796    return($#input_exposures + 1,1,1);
    765797}
    766798 
     
    791823        unless(defined($pretend)) {
    792824            dqstats_queue($date);
     825        }
     826        if (defined($pretend)) {
     827            add_to_macro_list('check_dqstats',1,$date);
     828        }
     829        else {
     830            add_to_macro_list('queue_dqstats',1,$date);
    793831        }
    794832    }
     
    887925            detrend_queue($date,$target);
    888926        }
     927        if (defined($pretend)) {
     928            add_to_macro_list('check_detrends',1,$date,$target,"dettool");
     929        }
     930        else {
     931            add_to_macro_list('queue_detrends',1,$date,$target,"dettool");
     932        }
    889933    }
    890934    if ($exposures == 0) {
     
    10231067        $metadata_out{nsState} = 'SS_DONE';
    10241068        sweetspot_queue($date);
     1069    }
     1070    if (defined($pretend)) {
     1071        add_to_macro_list('check_sweetspot',1,$date);
     1072    }
     1073    else {
     1074        add_to_macro_list('queue_sweetspot',1,$date);
    10251075    }
    10261076}
     
    11731223                    stack_queue($date,$target,$filter);
    11741224                }
     1225                if (defined($pretend)) {
     1226                    add_to_macro_list('check_stacks',$stackable_list{$target},$date,$target,$filter);
     1227                }
     1228                else {
     1229                    add_to_macro_list('queue_stacks',$stackable_list{$target},$date,$target,$filter);
     1230                }
    11751231            }
    11761232        }
     
    11811237
    11821238}
     1239
     1240sub post_stack_queue {
     1241    my $date = shift;
     1242    my $target = shift;
     1243
     1244    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     1245    # check warp stage == chip stage
     1246    my $db = init_gpc_db();
     1247
     1248    my $trunc_date = $date; $trunc_date =~ s/-//g;
     1249
     1250    my $where = " label = '$label' AND data_group = '$data_group' ";
     1251
     1252    my $stack_full_sth = "SELECT * from stackRun where $where ";
     1253    my $stack_done_sth = "SELECT * from stackRun LEFT JOIN stackSumSkyfile USING(stack_id) WHERE $where ";
     1254    $stack_done_sth .= " AND ((state = 'full') OR (state = 'new' && fault != 0)) ";
     1255
     1256    my $stack_full_ref = $db->selectall_arrayref( $stack_full_sth );
     1257    my $stack_done_ref = $db->selectall_arrayref( $stack_done_sth );
     1258
     1259    return($#{ $stack_full_ref } + 1, $#{ $stack_done_ref } + 1);
     1260}
     1261
     1262sub confirm_stacks {
     1263    my $date = shift;
     1264    my $pretend = shift;
     1265   
     1266    foreach my $target (@target_list) {
     1267        if ($stackable_list{$target} == 1) {
     1268            my ($Nstacks, $Nattempted) = post_stack_queue($date,$target);
     1269            if ($Nstacks != $Nattempted) {
     1270                if ($debug == 1) {
     1271                    print STDERR "confirm_stacks: Target $target on $date is not done stacking. $Nstacks $Nattempted\n"
     1272                }
     1273                next;
     1274            }
     1275            if (defined($pretend)) {
     1276                add_to_macro_list('check_confirm_stacks',$stackable_list{$target},$date,$target);
     1277            }
     1278            else {
     1279                add_to_macro_list('confirm_stacks',$stackable_list{$target},$date,$target);
     1280            }
     1281        }
     1282    }
     1283}           
    11831284
    11841285#
     
    12331334
    12341335    foreach my $mode (@mode_list) {
    1235 #       if ((exists($clean_alternate{$mode})) && ($clean_alternate{$mode} eq 'A')) {
    1236 #           my ($cleaning_date,$command) = construct_cleantool_args($date,"",$mode);
    1237 #           if ($cleaning_date eq 'no clean') {
    1238 #               next;
    1239 #           }
    1240 #           print STDERR "$command\n";
    1241 #           if (!(defined($pretend) || $debug == 1)) {
    1242 # #           print STDERR "BEAR IS DRIVING!?\n";
    1243 #               my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    1244 #                   run ( command => $command, verbose => $verbose );
    1245 #               unless ($success) {
    1246 #                   $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1247 #                   &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    1248 #               }
    1249 #           }
    1250 #       }
    1251 #       else {
    1252             foreach my $target (@target_list) {
    1253                 if (exists($noclean_list{$target})) {
    1254                     next;
     1336        foreach my $target (@target_list) {
     1337            if (exists($noclean_list{$target})) {
     1338                next;
     1339            }
     1340            my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode);
     1341            if ($cleaning_date eq 'no clean') {
     1342                next;
     1343            }           
     1344            print STDERR "$command\n";
     1345            if (!(defined($pretend) || $debug == 1)) {
     1346#           print STDERR "BEAR IS DRIVING!?\n";
     1347                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1348                    run ( command => $command, verbose => $verbose );
     1349                unless ($success) {
     1350                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1351                    &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    12551352                }
    1256                 my ($cleaning_date,$command) = construct_cleantool_args($date,$target,$mode);
    1257                 if ($cleaning_date eq 'no clean') {
    1258                     next;
    1259                 }               
    1260                 print STDERR "$command\n";
    1261                 if (!(defined($pretend) || $debug == 1)) {
    1262 #           print STDERR "BEAR IS DRIVING!?\n";
    1263                     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    1264                         run ( command => $command, verbose => $verbose );
    1265                     unless ($success) {
    1266                         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1267                         &my_die("Unable to perform cleantool ($command): $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    1268                     }
    1269                 }
    1270             }
    1271 #       }
     1353                add_to_macro_list('clean_old',1,$date,$target,$mode);
     1354            }
     1355        }
    12721356    }
    12731357    return(0);
    12741358}
    1275 
    1276 
    1277 
    12781359
    12791360#
     
    13241405    my $workdir = 'neb://@HOST@.0/' . $dbname . "/detverify.nt/${workdir_date}/${lc_type}${internal_filter}";
    13251406    return($label,$workdir,$det_filter,$exp_type,$det_type,$ref_det_id,$ref_iter,$maxN);
     1407}
     1408
     1409sub add_to_macro_list {
     1410    my $proc_mode = shift;
     1411    my $do_or_do_not = shift;
     1412    my $date = shift;
     1413    my $target = shift;
     1414    my $mode = shift;
     1415
     1416    if ((defined($macro_formats{$proc_mode}))&&($do_or_do_not)) {
     1417        unless (defined($metadata_out{N_MACROS})) {
     1418            $metadata_out{N_MACROS} = 0;
     1419        }
     1420        my $N = $metadata_out{N_MACROS};
     1421        $metadata_out{"ns${N}Macro"} = $macro_formats{$proc_mode};
     1422        print STDERR "WORKING ON A MACRO: ns${N}Macro $proc_mode $macro_formats{$proc_mode}\n";
     1423        if (defined($date)&&(defined($target))) {
     1424
     1425            my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction)
     1426                = get_tool_parameters($date,$target);
     1427            $metadata_out{"ns${N}Macro"} =~ s/\@LABEL\@/$label/;
     1428            $metadata_out{"ns${N}Macro"} =~ s/\@WORKDIR\@/$workdir/;
     1429            $metadata_out{"ns${N}Macro"} =~ s/\@OBS_MODE\@/$obs_mode/;
     1430            $metadata_out{"ns${N}Macro"} =~ s/\@OBJECT\@/$object/;
     1431            $metadata_out{"ns${N}Macro"} =~ s/\@COMMENT\@/$comment/;
     1432            $metadata_out{"ns${N}Macro"} =~ s/\@TESS_ID\@/$tess_id/;
     1433            $metadata_out{"ns${N}Macro"} =~ s/\@DIST_GROUP\@/$dist_group/;
     1434            $metadata_out{"ns${N}Macro"} =~ s/\@DATA_GROUP\@/$data_group/;
     1435            $metadata_out{"ns${N}Macro"} =~ s/\@REDUCTION\@/$reduction/;
     1436        }
     1437        if (defined($mode)) {
     1438            $metadata_out{"ns${N}Macro"} =~ s/\@EXTRA\@/$mode/;
     1439        }
     1440        if (defined($date)) {
     1441            $metadata_out{"ns${N}Macro"} =~ s/\@DATE\@/$date/;
     1442        }
     1443        $metadata_out{N_MACROS} ++;
     1444    }
    13261445}
    13271446
Note: See TracChangeset for help on using the changeset viewer.