IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26988


Ignore:
Timestamp:
Feb 18, 2010, 12:28:44 PM (16 years ago)
Author:
Paul Price
Message:

Stacks with less than 4 inputs are probably awful, given the maskiness of GPC1.

File:
1 edited

Legend:

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

    r26919 r26988  
    3030# my @filter_list = ('g.00000','r.00000','i.00000','z.00000','y.00000');
    3131# my @target_list = ('CMB','M31','MD01','MD02','MD03','MD04','MD05','MD06','MD07','MD08','MD09','MD10',
    32 #                  'STS','SVS','SweetSpot','ThreePi');
     32#                  'STS','SVS','SweetSpot','ThreePi');
    3333# my %tessID_list = ('CMB' => 'RINGS.V0', 'M31' => 'M31', 'MD01' => 'MD01', 'MD02' => 'MD02',
    34 #                  'MD03' => 'MD03', 'MD04' => 'MD04', 'MD05' => 'MD05', 'MD06' => 'MD06',
    35 #                  'MD07' => 'MD07', 'MD08' => 'MD08', 'MD09' => 'MD09', 'MD10' => 'MD10',
    36 #                  'STS' => 'STS', 'SVS' => 'RINGS.V0', 'SweetSpot' => 'RINGS.V0', 'ThreePi' => 'RINGS.V0');
     34#                  'MD03' => 'MD03', 'MD04' => 'MD04', 'MD05' => 'MD05', 'MD06' => 'MD06',
     35#                  'MD07' => 'MD07', 'MD08' => 'MD08', 'MD09' => 'MD09', 'MD10' => 'MD10',
     36#                  'STS' => 'STS', 'SVS' => 'RINGS.V0', 'SweetSpot' => 'RINGS.V0', 'ThreePi' => 'RINGS.V0');
    3737# my %comment_list = ('CMB' => 'CMB_Cold%', 'M31' => 'M31%', 'MD01' => 'MD01%', 'MD02' => 'MD02%',
    38 #                   'MD03' => 'MD03%', 'MD04' => 'MD04%', 'MD05' => 'MD05%', 'MD06' => 'MD06%',
    39 #                   'MD07' => 'MD07%', 'MD08' => 'MD08%', 'MD09' => 'MD09%', 'MD10' => 'MD10%',
    40 #                   'STS' => 'Stellar Transit%', 'SVS' => 'SVS%', 'SweetSpot' => 'Sweetspot%', 'ThreePi' => 'ThreePi%');
     38#                   'MD03' => 'MD03%', 'MD04' => 'MD04%', 'MD05' => 'MD05%', 'MD06' => 'MD06%',
     39#                   'MD07' => 'MD07%', 'MD08' => 'MD08%', 'MD09' => 'MD09%', 'MD10' => 'MD10%',
     40#                   'STS' => 'Stellar Transit%', 'SVS' => 'SVS%', 'SweetSpot' => 'Sweetspot%', 'ThreePi' => 'ThreePi%');
    4141# my %stackable_list = ('CMB' => 0, 'M31' => 1, 'MD01' => 1, 'MD02' => 1,
    42 #                   'MD03' => 1, 'MD04' => 1, 'MD05' => 1, 'MD06' => 1,
    43 #                   'MD07' => 1, 'MD08' => 1, 'MD09' => 1, 'MD10' => 1,
    44 #                   'STS' => 1, 'SVS' => 0, 'SweetSpot' => 0, 'ThreePi' => 0);
     42#                   'MD03' => 1, 'MD04' => 1, 'MD05' => 1, 'MD06' => 1,
     43#                   'MD07' => 1, 'MD08' => 1, 'MD09' => 1, 'MD10' => 1,
     44#                   'STS' => 1, 'SVS' => 0, 'SweetSpot' => 0, 'ThreePi' => 0);
    4545# my $retention_time = 9000;  # days.
    4646
     
    6363    'help|h'               => \$help,
    6464    'date=s'               => \$date, # night to make stacks for
    65     'camera=s'             => \$camera, # camera 
     65    'camera=s'             => \$camera, # camera
    6666    'dbname=s'             => \$dbname, # Database name
    67     'logfile=s'            => \$logfile, 
     67    'logfile=s'            => \$logfile,
    6868    'verbose'              => \$verbose,
    6969    'isburning'            => \$isburning,
     
    8383    'clean_old'            => \$clean_old,
    8484    ) or pod2usage ( 2 );
    85 pod2usage( -msg => 
     85pod2usage( -msg =>
    8686"USAGE: automate_stacks.pl <options...> <mode>
    8787        Options:
     
    9090           --camera <camera>      Default GPC1.
    9191           --dbname <db>          Default gpc1.
    92            --verbose             
     92           --verbose
    9393           --isburning            Signal that we are currently burntooling.
    9494           --force_stack_count    Force the chip/warp counts.
     
    106106           --queue_diffs          Issue difftool commands to queue diffs.
    107107           --clean_old            Mark old data 'goto_cleanup'.\n",
    108            -exitval => 2, ) if (defined($help));
     108           -exitval => 2, ) if (defined($help));
    109109pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    110110pod2usage(
     
    114114    defined $check_registration or defined $define_burntool or defined $queue_burntool or
    115115    defined $queue_chips or defined $queue_stacks or
    116     defined $check_chips or defined $check_stacks or 
     116    defined $check_chips or defined $check_stacks or
    117117    defined $test_mode or defined $clean_old;
    118118
     
    129129# Grab the configuration data.
    130130my $conf_cmd = "$ppConfigDump -dump-recipe NIGHTLY_SCIENCE -";
    131 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 
     131my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    132132    run(command => $conf_cmd, verbose => $verbose);
    133133unless ($success) {
     
    140140foreach my $entry (@{ $metadata }) {
    141141    if (${ $entry }{name} eq 'RETENTION_TIME') {
    142         $retention_time = ${ $entry }{value};
     142        $retention_time = ${ $entry }{value};
    143143    }
    144144    elsif (${ $entry }{name} eq 'FILTERS') {
    145         push @filter_list, ${ $entry }{value};
     145        push @filter_list, ${ $entry }{value};
    146146    }
    147147    elsif (${ $entry }{name} eq 'TARGETS') {
    148         my @target_data = @{ ${ $entry }{value} };
    149         my $this_target = '';
    150         foreach my $tentry (@target_data) {
    151             if (${ $tentry }{name} eq 'NAME') {
    152                 $this_target = ${ $tentry }{value};
    153                 push @target_list, $this_target;
    154             }
    155             elsif (${ $tentry }{name} eq 'TESS') {
    156                 $tessID_list{$this_target} = ${ $tentry }{value};
    157             }
    158             elsif (${ $tentry }{name} eq 'OBSMODE') {
    159                 $obsmode_list{$this_target} = ${ $tentry }{value};
    160             }
    161             elsif (${ $tentry }{name} eq 'OBJECT') {
    162                 $object_list{$this_target} = ${ $tentry }{value};
    163             }
    164             elsif (${ $tentry }{name} eq 'COMMENT') {
    165                 $comment_list{$this_target} = ${ $tentry }{value};
    166             }
    167             elsif (${ $tentry }{name} eq 'STACKABLE') {
    168                 $stackable_list{$this_target} = ${ $tentry }{value};
    169             }
    170         }
     148        my @target_data = @{ ${ $entry }{value} };
     149        my $this_target = '';
     150        foreach my $tentry (@target_data) {
     151            if (${ $tentry }{name} eq 'NAME') {
     152                $this_target = ${ $tentry }{value};
     153                push @target_list, $this_target;
     154            }
     155            elsif (${ $tentry }{name} eq 'TESS') {
     156                $tessID_list{$this_target} = ${ $tentry }{value};
     157            }
     158            elsif (${ $tentry }{name} eq 'OBSMODE') {
     159                $obsmode_list{$this_target} = ${ $tentry }{value};
     160            }
     161            elsif (${ $tentry }{name} eq 'OBJECT') {
     162                $object_list{$this_target} = ${ $tentry }{value};
     163            }
     164            elsif (${ $tentry }{name} eq 'COMMENT') {
     165                $comment_list{$this_target} = ${ $tentry }{value};
     166            }
     167            elsif (${ $tentry }{name} eq 'STACKABLE') {
     168                $stackable_list{$this_target} = ${ $tentry }{value};
     169            }
     170        }
    171171    }
    172172}
     
    190190if (defined($this_target_only)) {
    191191    foreach my $t (@target_list) {
    192         if ($t eq $this_target_only) {
    193             @target_list = ($this_target_only);
    194             last;
    195         }
     192        if ($t eq $this_target_only) {
     193            @target_list = ($this_target_only);
     194            last;
     195        }
    196196    }
    197197    die("$this_target_only is invalid.") if ($#target_list != 0);
     
    200200if (defined($this_filter_only)) {
    201201    foreach my $t (@filter_list) {
    202         if ($t eq $this_filter_only) {
    203             @filter_list = ($this_filter_only);
    204             last;
    205         }
     202        if ($t eq $this_filter_only) {
     203            @filter_list = ($this_filter_only);
     204            last;
     205        }
    206206    }
    207207    die("$this_filter_only is invalid.") if ($#filter_list != 0);
     
    209209
    210210#
    211 # Mode selection 
     211# Mode selection
    212212################################################################################
    213213if (defined($test_mode)) {
     
    236236    &execute_chips($date,"pretend");
    237237    if (($metadata_out{nsState} eq 'NEEDSBURNING')&&(defined($isburning))) {
    238         $metadata_out{nsState} = 'BURNING';
     238        $metadata_out{nsState} = 'BURNING';
    239239    }
    240240    return_metadata($date);
     
    251251    &execute_stacks($date,"pretend");
    252252    if ($metadata_out{nsState} eq 'FORCETOWARP') {
    253         $metadata_out{nsState} = 'TOWARP';
     253        $metadata_out{nsState} = 'TOWARP';
    254254    }
    255255    return_metadata($date);
     
    267267if (defined($clean_old) || defined($test_mode)) {
    268268    if (defined($test_mode)) {
    269         &execute_cleans($date,"pretend");
     269        &execute_cleans($date,"pretend");
    270270    }
    271271    else {
    272         &execute_cleans($date);
     272        &execute_cleans($date);
    273273    }
    274274    unless (defined($test_mode)) { exit(0); }
     
    276276exit(0);
    277277#
    278 # Registration 
     278# Registration
    279279################################################################################
    280280
     
    284284
    285285    # largely stolen from Bill's checkexp program.
    286    
     286
    287287    my $sth = " SELECT exp_name, summitExp.dateobs AS registered, rawExp.dateobs, summitExp.imfiles, ";
    288288    $sth .= " summitExp.fault AS summit_fault, pzDownloadExp.state AS download_state, ";
     
    294294
    295295    my $data_ref = $db->selectall_arrayref( $sth );
    296    
     296
    297297    my $Nsummit_exps = 0;
    298298    my $Nsummit_faults = 0;
     
    303303
    304304    foreach my $row_ref (@{ $data_ref }) {
    305         my ($exp_name,$registered,$dateobs,$imfiles,$summit_fault,
    306             $download_state,$download_count,$new_state,$exp_id,$exp_type) = @{ $row_ref };
    307         $Nsummit_exps++;
    308         if ($summit_fault) {
    309             print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";
    310             if ($exp_type ne 'OBJECT') {
    311                 print STDERR " (but I don't care).\n";
    312             }
    313             else {
    314                 print STDERR "\n";
    315                 $Nsummit_faults++;
    316             }
    317         }
    318         elsif (!$download_state or $download_state eq 'run') {
    319             print STDERR "check_summit_copy: $date $exp_name has download_state $download_state";
    320             if ($exp_type ne 'OBJECT') {
    321                 print STDERR " (but I don't care).\n";
    322             }
    323             else {
    324                 print STDERR "\n";
    325                 $Ndownload_faults++;
    326             }
    327         }
    328         elsif (!$new_state or $new_state eq 'run' ) {
    329             print STDERR "check_summit_copy: $date $exp_name has new_state $new_state";
    330             if ($exp_type ne 'OBJECT') {
    331                 print STDERR " (but I don't care).\n";
    332             }
    333             else {
    334                 print STDERR "\n";
    335                 $Nregister_faults++;
    336             }
    337         }
     305        my ($exp_name,$registered,$dateobs,$imfiles,$summit_fault,
     306            $download_state,$download_count,$new_state,$exp_id,$exp_type) = @{ $row_ref };
     307        $Nsummit_exps++;
     308        if ($summit_fault) {
     309            print STDERR "check_summit_copy: $date $exp_name has summit_fault $summit_fault";
     310            if ($exp_type ne 'OBJECT') {
     311                print STDERR " (but I don't care).\n";
     312            }
     313            else {
     314                print STDERR "\n";
     315                $Nsummit_faults++;
     316            }
     317        }
     318        elsif (!$download_state or $download_state eq 'run') {
     319            print STDERR "check_summit_copy: $date $exp_name has download_state $download_state";
     320            if ($exp_type ne 'OBJECT') {
     321                print STDERR " (but I don't care).\n";
     322            }
     323            else {
     324                print STDERR "\n";
     325                $Ndownload_faults++;
     326            }
     327        }
     328        elsif (!$new_state or $new_state eq 'run' ) {
     329            print STDERR "check_summit_copy: $date $exp_name has new_state $new_state";
     330            if ($exp_type ne 'OBJECT') {
     331                print STDERR " (but I don't care).\n";
     332            }
     333            else {
     334                print STDERR "\n";
     335                $Nregister_faults++;
     336            }
     337        }
    338338    }
    339339
    340340    my $Nfaults = $Nsummit_faults + $Ndownload_faults + $Nregister_faults;
    341341    if ($Nsummit_exps == 0) {
    342         print STDERR "No exposures were found on the summit for $date.\n";
    343         $metadata_out{nsState} = 'DROP';
     342        print STDERR "No exposures were found on the summit for $date.\n";
     343        $metadata_out{nsState} = 'DROP';
    344344    }
    345345    elsif ($Nfaults != 0) {
    346         print STDERR "There were faults while downloading the exposures for $date.\n";
    347         $metadata_out{nsState} = 'NEW';
     346        print STDERR "There were faults while downloading the exposures for $date.\n";
     347        $metadata_out{nsState} = 'NEW';
    348348    }
    349349    else {
    350         print STDERR "Summit copy and Registration have succeeded for $date.\n";
    351         $metadata_out{nsState} = 'REGISTERED';
    352     }
    353    
     350        print STDERR "Summit copy and Registration have succeeded for $date.\n";
     351        $metadata_out{nsState} = 'REGISTERED';
     352    }
     353
    354354    return($Nsummit_exps,$Nfaults);
    355 }       
     355}
    356356
    357357#
     
    364364    my $config_cmd = "$ppConfigDump -camera $camera -dump-camera - | grep BURNTOOL.STATE.GOOD | uniq";
    365365    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    366         run ( command => $config_cmd, verbose => $verbose);
     366        run ( command => $config_cmd, verbose => $verbose);
    367367    unless ($success) {
    368         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    369         &my_die("Unable to perform ppConfigDump: $error_code", 0, 0, 0, $PS_EXIT_SYS_ERROR);
     368        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     369        &my_die("Unable to perform ppConfigDump: $error_code", 0, 0, 0, $PS_EXIT_SYS_ERROR);
    370370    }
    371371    my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
    372         &my_die("Unable to parse metadata config doc", 0, 0, 0, $PS_EXIT_SYS_ERROR);
     372        &my_die("Unable to parse metadata config doc", 0, 0, 0, $PS_EXIT_SYS_ERROR);
    373373    my $burntoolStateGood = 999;
    374374    foreach my $cfg (@$recipeData) {
    375         if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') {
    376             $burntoolStateGood = $cfg->{value};
    377         }
     375        if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') {
     376            $burntoolStateGood = $cfg->{value};
     377        }
    378378    }
    379379    if ($burntoolStateGood == 999) {
    380         &my_die("Failed to determine BURNTOOL.STATE.GOOD", $burntoolStateGood, 0, 0, $PS_EXIT_SYS_ERROR);
     380        &my_die("Failed to determine BURNTOOL.STATE.GOOD", $burntoolStateGood, 0, 0, $PS_EXIT_SYS_ERROR);
    381381    }
    382382    return($burntoolStateGood);
     
    388388
    389389    my $db = init_gpc_db();
    390    
     390
    391391    my $sth = "SELECT exp_id,exp_name,obs_mode,dateobs,class_id,burntool_state,comment FROM rawImfile WHERE exp_id = $exp_id";
    392392    my $data_ref = $db->selectall_arrayref( $sth );
     
    397397    foreach my $row_ref (@{ $data_ref }) {
    398398        my ($exp_id,$exp_name, $obs_mode,$dateobs,$class_id,$burntool_state,$comment) = @{ $row_ref };
    399         $Nimfiles++;
    400         if (abs($burntool_state) == $burntoolStateGood) {
    401             $Nburntooled++;
    402         }
     399        $Nimfiles++;
     400        if (abs($burntool_state) == $burntoolStateGood) {
     401            $Nburntooled++;
     402        }
    403403    }
    404404    return($Nimfiles,$Nburntooled);
    405 }   
     405}
    406406
    407407sub find_burntool_ranges {
     
    410410    my $command = "$mkBTpcontrol -d $date -b";
    411411    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    412         run ( command => $command, verbose => $verbose );
     412        run ( command => $command, verbose => $verbose );
    413413    unless ($success) {
    414         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    415         &my_die("Unable to perform $command: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     414        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     415        &my_die("Unable to perform $command: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    416416    }
    417417
    418418    if ($#{ $stderr_buf } > -1) {
    419         $metadata_out{nsState} = 'ERROR';       
    420         return(1);
     419        $metadata_out{nsState} = 'ERROR';
     420        return(1);
    421421    }
    422422
     
    424424    my @burntool_entries = split /\n/, (join '', @$stdout_buf);
    425425    foreach my $row (@burntool_entries) {
    426         my ($trash,$start,$end);
    427         ($trash,$trash,$start,$end) = (split /\s+/,$row);
    428         $metadata_out{"btBegin${N}"} = $start;
    429         $metadata_out{"btEnd${N}"} = $end;
    430         $metadata_out{"btCounter${N}"} = 0;
    431         $N++;
    432         print STDERR "define_burntool: $row\n";
     426        my ($trash,$start,$end);
     427        ($trash,$trash,$start,$end) = (split /\s+/,$row);
     428        $metadata_out{"btBegin${N}"} = $start;
     429        $metadata_out{"btEnd${N}"} = $end;
     430        $metadata_out{"btCounter${N}"} = 0;
     431        $N++;
     432        print STDERR "define_burntool: $row\n";
    433433    }
    434434    $metadata_out{btN} = $N - 1;
     
    437437    return(0);
    438438}
    439    
     439
    440440#
    441441# Chips
     
    447447
    448448    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group) = get_tool_parameters($date,$target);
    449    
     449
    450450    my $select =  "-dateobs_begin ${date}T00:00:00 -dateobs_end ${date}T23:59:59 ";
    451451    $date =~ s/-//g;
     
    457457    $cmd .= " -set_tess_id $tess_id -set_data_group $data_group ";
    458458    if (defined($obs_mode)) {
    459         $cmd .= " -obs_mode '$obs_mode' ";
     459        $cmd .= " -obs_mode '$obs_mode' ";
    460460    }
    461461    if (defined($object)) {
    462         $cmd .= " -object '$object' ";
     462        $cmd .= " -object '$object' ";
    463463    }
    464464    if (defined($comment)) {
    465         $cmd .= " -comment '$comment' ";
     465        $cmd .= " -comment '$comment' ";
    466466    }
    467467    $cmd .= " $select ";
    468468    if ($debug == 1) {
    469         $cmd .= " -pretend ";
     469        $cmd .= " -pretend ";
    470470    }
    471471    print STDERR "$cmd\n";
     
    477477    my $date = shift;
    478478    my $target = shift;
    479    
     479
    480480    my $db = init_gpc_db();
    481481    $date =~ s/-//g;
     
    491491    my $date = shift;
    492492    my $target = shift;
    493    
     493
    494494    my $command = construct_chiptool_cmd($date,$target) . ' -pretend ';
    495495    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    496         run ( command => $command, verbose => $verbose );
     496        run ( command => $command, verbose => $verbose );
    497497    unless ($success) {
    498         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    499         &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     498        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     499        &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    500500    }
    501501
     
    506506    my @input_exposures = split /\n/, (join '', @$stdout_buf);
    507507    foreach my $entry (@input_exposures) {
    508         my ($exp_id, @trash) = split /\s+/, $entry;
    509         @trash = verify_burntool($exp_id,$burntoolStateGood);
    510         $Nimfiles += $trash[0];
    511         $Nburntooled += $trash[1];
    512 
    513         @trash = verify_uniqueness_chip($exp_id,$date,$target);
    514         $Nalready += $trash[0];
     508        my ($exp_id, @trash) = split /\s+/, $entry;
     509        @trash = verify_burntool($exp_id,$burntoolStateGood);
     510        $Nimfiles += $trash[0];
     511        $Nburntooled += $trash[1];
     512
     513        @trash = verify_uniqueness_chip($exp_id,$date,$target);
     514        $Nalready += $trash[0];
    515515    }
    516516    return($#input_exposures + 1,$Nimfiles,$Nburntooled,$Nalready);
     
    523523    my $command = construct_chiptool_cmd($date,$target);
    524524    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    525         run ( command => $command, verbose => $verbose );
     525        run ( command => $command, verbose => $verbose );
    526526    unless ($success) {
    527         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    528         &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     527        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     528        &my_die("Unable to perform chiptool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    529529    }
    530530    $metadata_out{nsState} = 'TOWARP';
     
    536536    my $pretend = shift;
    537537    foreach my $target (@target_list) {
    538         my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = pre_chip_queue($date,$target);
    539         if ($Nexposures == 0) {
    540             print STDERR "execute_chips: Target $target on $date had no exposures.\n";
    541             next;
    542         }
    543         if ($Nalready != 0) {
    544             print STDERR "execute_chips: Not queueing $target on $date due to already existing exposures.\n";
    545             next;
    546         }
    547         if ($Nimfiles != $Nburntooled) {
    548             print STDERR "execute_chips: Target $target on $date is not fully burntooled.\n";
    549             $metadata_out{nsState} = 'NEEDSBURNING';
    550             next;
    551         }
    552         unless(defined($pretend)) {
    553             chip_queue($date,$target);
    554         }
     538        my ($Nexposures,$Nimfiles,$Nburntooled,$Nalready) = pre_chip_queue($date,$target);
     539        if ($Nexposures == 0) {
     540            print STDERR "execute_chips: Target $target on $date had no exposures.\n";
     541            next;
     542        }
     543        if ($Nalready != 0) {
     544            print STDERR "execute_chips: Not queueing $target on $date due to already existing exposures.\n";
     545            next;
     546        }
     547        if ($Nimfiles != $Nburntooled) {
     548            print STDERR "execute_chips: Target $target on $date is not fully burntooled.\n";
     549            $metadata_out{nsState} = 'NEEDSBURNING';
     550            next;
     551        }
     552        unless(defined($pretend)) {
     553            chip_queue($date,$target);
     554        }
    555555    }
    556556}
     
    572572    my $cmd = "$stacktool";
    573573#    $cmd .= ' -pretend -simple -dbname gpc1 -definebyquery -min_new 4 ';  # Probably silly, but I want to be safe and not overwrite
    574     $cmd .= ' -simple -dbname gpc1 -definebyquery '; 
     574    $cmd .= ' -simple -dbname gpc1 -definebyquery ';
    575575    $cmd .= " -set_label $label -select_label $label ";
    576576    $cmd .= " -set_workdir $workdir -set_dist_group $dist_group ";
    577577    $cmd .= " -select_filter $filter -set_data_group $data_group ";
     578    $cmd .= " -min_num 4";
    578579    $cmd .= " $select ";
    579580    if ($debug == 1) {
    580         $cmd .= ' -pretend ';
     581        $cmd .= ' -pretend ';
    581582    }
    582583    print STDERR "$cmd\n";
    583584    return($cmd);
    584 }   
     585}
    585586
    586587sub verify_uniqueness_stack {
     
    596597    my $sth = "SELECT skycell_id from stackRun where data_group = '$data_group' AND skycell_id = '$skycell' AND filter = '$filter'";
    597598    my $data_ref = $db->selectall_arrayref( $sth );
    598    
     599
    599600    return($#{ $data_ref } + 1);
    600601}
     
    620621    # check that we will be able to queue them up
    621622    my $command = construct_stacktool_cmd($date,$target,$filter) . ' -pretend ';
    622     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 
    623         run ( command => $command, verbose => $verbose );
     623    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     624        run ( command => $command, verbose => $verbose );
    624625    unless ($success) {
    625         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    626         &my_die("Unable to perform stacktool: $error_code", $#{ $chip_ref },$#{ $warp_ref },$date, $PS_EXIT_SYS_ERROR);
    627     }
    628    
     626        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     627        &my_die("Unable to perform stacktool: $error_code", $#{ $chip_ref },$#{ $warp_ref },$date, $PS_EXIT_SYS_ERROR);
     628    }
     629
    629630    my $Nalready = 0;
    630631
    631     my @input_exposures = split /\n/, (join '', @$stdout_buf);   
     632    my @input_exposures = split /\n/, (join '', @$stdout_buf);
    632633    foreach my $entry (@input_exposures) {
    633         my ($skycell, @trash) = split /\s+/, $entry;
    634         @trash = verify_uniqueness_stack($skycell,$date,$target,$filter);
    635         $Nalready += $trash[0];
     634        my ($skycell, @trash) = split /\s+/, $entry;
     635        @trash = verify_uniqueness_stack($skycell,$date,$target,$filter);
     636        $Nalready += $trash[0];
    636637    }
    637638
     
    645646
    646647    my $command = construct_stacktool_cmd($date,$target,$filter);
    647     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 
    648         run ( command => $command, verbose => $verbose );
     648    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     649        run ( command => $command, verbose => $verbose );
    649650    unless ($success) {
    650         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    651         &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     651        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     652        &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    652653    }
    653654    return(0);
     
    658659    my $pretend = shift;
    659660    foreach my $target (@target_list) {
    660         if ($stackable_list{$target} == 1) {
    661             foreach my $filter (@filter_list) {
    662                 my ($Nexposures,$NprocChips,$NprocWarps,$Nalready) = pre_stack_queue($date,$target,$filter);
    663                 if ((!defined($force_stack_count))&&($NprocChips != $NprocWarps)) { # This makes me sad. :(
    664                     print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";
    665                     $metadata_out{nsState} = 'FORCETOWARP';
    666                     next;
    667                 }
    668                 if ($Nexposures == 0) {
    669                     print STDERR "execute_stacks: Target $target in filter $filter on $date has no exposures.\n";
    670                     next;
    671                 }
    672                 if ($Nalready != 0) {
    673                     print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n";
    674                     next;
    675                 }
    676                 unless ($metadata_out{nsState} eq 'FORCETOWARP') {
    677                     $metadata_out{nsState} = 'QUEUESTACKS';
    678                 }
    679                 unless(defined($pretend)) {
    680                     print STDERR "execute_stacks: Target $target in filter $filter on $date has exposures and will be queued.\n";
    681                     stack_queue($date,$target,$filter);
    682                 }
    683             }
    684         }
    685         else {
    686             print STDERR "execute_stacks: Target $target is not auto-stackable.\n";
    687         }
    688     }
    689    
     661        if ($stackable_list{$target} == 1) {
     662            foreach my $filter (@filter_list) {
     663                my ($Nexposures,$NprocChips,$NprocWarps,$Nalready) = pre_stack_queue($date,$target,$filter);
     664                if ((!defined($force_stack_count))&&($NprocChips != $NprocWarps)) { # This makes me sad. :(
     665                    print STDERR "execute_stacks: Target $target on $date is not fully processed. ($NprocChips $NprocWarps)\n";
     666                    $metadata_out{nsState} = 'FORCETOWARP';
     667                    next;
     668                }
     669                if ($Nexposures == 0) {
     670                    print STDERR "execute_stacks: Target $target in filter $filter on $date has no exposures.\n";
     671                    next;
     672                }
     673                if ($Nalready != 0) {
     674                    print STDERR "execute_stacks: Not queueing $target in filter $filter on $date due to already existing stacks.\n";
     675                    next;
     676                }
     677                unless ($metadata_out{nsState} eq 'FORCETOWARP') {
     678                    $metadata_out{nsState} = 'QUEUESTACKS';
     679                }
     680                unless(defined($pretend)) {
     681                    print STDERR "execute_stacks: Target $target in filter $filter on $date has exposures and will be queued.\n";
     682                    stack_queue($date,$target,$filter);
     683                }
     684            }
     685        }
     686        else {
     687            print STDERR "execute_stacks: Target $target is not auto-stackable.\n";
     688        }
     689    }
     690
    690691}
    691692
     
    697698    my $date = shift;
    698699    my $target = shift;
    699    
     700
    700701    my ($year,$month,$day) = split /-/,$date;
    701702    my $dt = DateTime->new(year => $year, month => $month, day => $day,
    702                                hour => 0, minute => 0, second => 0, nanosecond => 0,
    703                                time_zone => 'Pacific/Honolulu');
     703                               hour => 0, minute => 0, second => 0, nanosecond => 0,
     704                               time_zone => 'Pacific/Honolulu');
    704705    $dt->subtract(days => $retention_time);
    705706    my $cleaning_date = $dt->ymd;
     
    709710    my $args .= " -dbname gpc1 -updaterun -set_state goto_cleaned -state full -data_group $data_group ";
    710711    if ($debug == 1) {
    711         $args .= ' -pretend ';
     712        $args .= ' -pretend ';
    712713    }
    713714    return($cleaning_date,$args);
     
    719720
    720721    foreach my $target (@target_list) {
    721         my ($cleaning_date,$args) = construct_cleantool_args($date,$target);
    722 
    723         my $command = $chiptool . $args;
    724         print STDERR "$command\n";
    725         if (!(defined($pretend) || $debug == 1)) {
    726 #           print STDERR "BEAR IS DRIVING!?\n";
    727             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    728                 run ( command => $command, verbose => $verbose );
    729             unless ($success) {
    730                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    731                 &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    732             }
    733         }
    734         $command = $warptool . $args;
    735         print STDERR "$command\n";
    736         if (!(defined($pretend) || $debug == 1)) {
    737 #           print STDERR "BEAR IS DRIVING $pretend $debug!?\n";
    738             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    739                 run ( command => $command, verbose => $verbose );
    740             unless ($success) {
    741                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    742                 &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
    743             }
    744         }
     722        my ($cleaning_date,$args) = construct_cleantool_args($date,$target);
     723
     724        my $command = $chiptool . $args;
     725        print STDERR "$command\n";
     726        if (!(defined($pretend) || $debug == 1)) {
     727#           print STDERR "BEAR IS DRIVING!?\n";
     728            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     729                run ( command => $command, verbose => $verbose );
     730            unless ($success) {
     731                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     732                &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     733            }
     734        }
     735        $command = $warptool . $args;
     736        print STDERR "$command\n";
     737        if (!(defined($pretend) || $debug == 1)) {
     738#           print STDERR "BEAR IS DRIVING $pretend $debug!?\n";
     739            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     740                run ( command => $command, verbose => $verbose );
     741            unless ($success) {
     742                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     743                &my_die("Unable to perform stacktool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     744            }
     745        }
    745746    }
    746747    return(0);
    747748}
    748        
    749        
    750            
     749
     750
     751
    751752
    752753#
     
    779780    my $dbpass = 'ippuser';
    780781    $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
    781                        "mysql_socket=" . DB_SOCKET(),
    782                        ${dbuser},${dbpass},
    783                        { RaiseError => 1, AutoCommit => 1}
    784         ) or die "Unable to connect to database $DBI::errstr\n";
     782                       "mysql_socket=" . DB_SOCKET(),
     783                       ${dbuser},${dbpass},
     784                       { RaiseError => 1, AutoCommit => 1}
     785        ) or die "Unable to connect to database $DBI::errstr\n";
    785786    return($db);
    786787}
     
    792793    print STDOUT "   date                  STR          $date\n";
    793794    foreach my $k (keys %metadata_out) {
    794         print STDOUT "   $k                STR          $metadata_out{$k}\n";
     795        print STDOUT "   $k                STR          $metadata_out{$k}\n";
    795796    }
    796797    print STDOUT "END\n";
     
    810811sub my_trace {
    811812    if ($debug == 1) {
    812         foreach my $thing (@_) {
    813             carp($thing);
    814         }
    815     }
    816 }
     813        foreach my $thing (@_) {
     814            carp($thing);
     815        }
     816    }
     817}
Note: See TracChangeset for help on using the changeset viewer.