IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2012, 5:19:48 PM (14 years ago)
Author:
mhuber
Message:

merging latest r33407 trunk changes to meh_branches/ppstack_test

Location:
branches/meh_branches/ppstack_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/ippScripts/scripts/lap_science.pl

    r32099 r33415  
    2727my ( $camera, $dbname);
    2828my ( $lap_id );
     29my ( $queue_list );
    2930my ( $chip_mode, $monitor_mode, $cleanup_mode);
    3031
     
    3233# Global configuration constants that probably should be read from elsewhere. 
    3334my $qstack_threshold     = 0.05; # Only make a quickstack if more than 5% of the exposures require it.
    34 my $minimum_stack_inputs = 6;    # We can avoid magicking stack inputs if we have more than this number.
     35my $minimum_stack_inputs = 4;    # We can avoid magicking stack inputs if we have more than this number.
    3536
    3637GetOptions(
     
    4445   
    4546    'lap_id=s'     => \$lap_id,
     47    'queue_list=s' => \$queue_list,
    4648
    4749    'chip_mode'    => \$chip_mode,
     
    200202    return($exposure);
    201203}
     204
     205sub remake_this_exposure_by_update {
     206    my $exposure = shift;
     207
     208    my @utctime = gmtime();
     209    $utctime[5] += 1900;
     210    $utctime[4] += 1;
     211
     212    my $label = $exposure->{label};
     213
     214    my $date = sprintf("%4d%02d%02d",$utctime[5],$utctime[4],$utctime[3]);
     215    my $workdir_date = sprintf("%4d/%02d/%02d",$utctime[5],$utctime[4],$utctime[3]);
     216    my $workdir = "neb://\@HOST\@.0/${dbname}/${label}/${workdir_date}";
     217    my $data_group = "${label}.${date}";
     218
     219    my $chiptool_info_cmd = "chiptool -listrun -exp_id $exposure->{exp_id} -chip_id $exposure->{chip_id} ";
     220    $chiptool_info_cmd   .= " -dbname $dbname " if defined $dbname;
     221
     222    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     223        run(command => $chiptool_info_cmd, verbose => $verbose);
     224    unless ($success) {
     225        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     226        &my_die("Unable to perform chiptool -listrun: $error_code", $exposure->{exp_id}, $data_group);
     227    }
     228    my $chips = $mdcParser->parse_list(join "", @$stdout_buf) or
     229        &my_die("Unable to parse metadata from chiptool -listrun", $exposure->{exp_id}, $data_group);
     230    # There should be only one.
     231    my $chip = ${ $chips }[0];
     232    my $chip_magicDS_id = 0;
     233    if ($chip) {
     234        $chip_magicDS_id = $chip->{magic_ds_id};
     235    }
     236    if ($chip_magicDS_id == 0) {
     237#       return(&remake_this_exposure($exposure));
     238    }
     239
     240    my $warptool_info_cmd = "warptool -listrun -exp_id $exposure->{exp_id} -chip_id $exposure->{chip_id} ";
     241    $warptool_info_cmd   .= " -dbname $dbname " if defined $dbname;
     242    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     243        run(command => $warptool_info_cmd, verbose => $verbose);
     244    unless ($success) {
     245        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     246        &my_die("Unable to perform warptool -listrun: $error_code", $exposure->{exp_id}, $data_group);
     247    }
     248    my $warps = $mdcParser->parse_list(join "", @$stdout_buf) or
     249        &my_die("Unable to parse metadata from warptool -listrun", $exposure->{exp_id}, $data_group);
     250    # There should be only one.
     251    my $warp = ${ $warps }[0];
     252    my $warp_id = 0;
     253    if ($warp) {
     254        $warp_id = $warp->{warp_id};
     255    }
     256    else {
     257        $exposure->{data_state} = 'drop';
     258        return($exposure);
     259    }   
     260    if ($warp_id == 0) {
     261        # Handle this correctly. Probably want to drop the exposure here.
     262        $exposure->{data_state} = 'drop';
     263        return($exposure);
     264    }
     265
     266    if (($chip->{state} eq 'goto_cleaned')||
     267        ($warp->{state} eq 'goto_cleaned')||
     268        ($chip->{dsRun_state} eq 'goto_cleaned')) {
     269        $exposure->{data_state} = 'pending_update';
     270        &update_this_exposure($exposure);
     271        return($exposure);
     272    }
     273
     274   
     275    my $chiptool_update_cmd = "chiptool -setimfiletoupdate -chip_id $exposure->{chip_id} -set_label $label";
     276    $chiptool_update_cmd   .= " -dbname $dbname " if defined $dbname;
     277    my $magicDS_update_cmd  = "magicdstool -setfiletoupdate -magic_ds_id $chip_magicDS_id -set_label $label";
     278    $magicDS_update_cmd    .= " -dbname $dbname " if defined $dbname;
     279    my $warptool_update_cmd = "warptool -setskyfiletoupdate -warp_id $warp_id -set_label $label";
     280    $warptool_update_cmd   .= " -dbname $dbname " if defined $dbname;
     281
     282    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     283        run(command => $chiptool_update_cmd, verbose => $verbose);
     284    unless ($success) {
     285        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     286        &my_die("Unable to perform chiptool -setimfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
     287    }
     288#     if ($chip_magicDS_id != 0) {   
     289#       ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     290#           run(command => $magicDS_update_cmd, verbose => $verbose);
     291#       unless ($success) {
     292#           $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     293#           &my_die("Unable to perform magicdstool -setfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
     294#       }
     295#     }
     296
     297    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     298        run(command => $warptool_update_cmd, verbose => $verbose);
     299    unless ($success) {
     300        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     301        &my_die("Unable to perform warptool -setskyfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
     302    }
     303   
     304    $exposure->{active} = 1;
     305    return($exposure);
     306}
     307       
     308sub determine_if_can_update {
     309    my $exposure = shift;
     310   
     311    if (S64_IS_NOT_NULL($exposure->{chip_id})) {
     312        if (($exposure->{chip_state} eq 'cleaned')||
     313            ($exposure->{chip_state} eq 'goto_cleaned')||
     314            ($exposure->{chip_state} eq 'error_cleaned')) {
     315            return(1);
     316        }
     317    }
     318
     319    return(0);
     320}
     321       
    202322
    203323# This is the "user level" subroutine.
     
    240360        my $comment = $exposure->{comment};
    241361
    242         # This is a hack to fix old exposures that have no object.
     362        my $updateable = determine_if_can_update($exposure);
     363
     364        # This is a hack to fix old exposures that have no usable object/comment data.
    243365        unless(defined($comment)) {
    244366            $comment = '';
     
    247369            if ($comment =~ /3pi_/) {
    248370                $object = $comment;
    249                 $object =~ s/^.*?(3pi_\d\d_\d\d\d\d).*?$/$1/;
     371                $object =~ s/^.*?(3pi_\d\d_\d\d\d\d).*?$/F1 $1/;
    250372            }
    251373            elsif ($comment =~ / ps1_/) {
    252374                $object = $comment;
    253                 $object =~ s/^.*?(ps1_\d\d_\d\d\d\d).*$/$1/;
    254             }
    255             else {
    256                 $exposure->{data_state} = 'new';
     375                $object =~ s/^.*?(ps1_\d\d_\d\d\d\d).*$/F2 $1/;
     376            }
     377            elsif ($comment =~ /ThreePi.*3pi_/) {
     378                $object = $comment;
     379                $object =~ s/^ThreePi . (\S+? 3pi_\d\d_\d\d\d\d) .*$/F3 $1/;
     380            }           
     381            elsif ($comment =~ /ThreePi.*ps1_/) {
     382                $object = $comment;
     383                $object =~ s/^ThreePi . (\S+? ps1_\d\d_\d\d\d\d) .*$/F4 $1/;
     384            }           
     385            elsif ($comment =~ /ThreePi /) {
     386                $object = $comment;
     387                $object =~ s/^ThreePi . (\S+? \d\d\d\d) .*$/F5 $1/;
     388            }           
     389            elsif (($comment =~ /focus/i)||
     390                   ($comment =~ /test/i)||
     391                   ($comment =~ /hyster/i)||
     392                   ($comment =~ /dither/i)||
     393                   ($comment =~ /camera/i)
     394                ){
     395                # This is junk that shouldn't exist.
     396                $object = 'DROP';
     397                $exposure->{data_state} = 'drop';
    257398                $exposure->{pairwise} = 0;
    258                 $exposure->{private} = 1;
    259                 $exposure->{pair_id} = 9223372036854775807;
    260                 update_this_exposure($exposure);
    261                 $exposure = remake_this_exposure($exposure);
    262                 $counter++;
     399                $exposure->{pair_id} =  9223372036854775807;
     400                $exposure->{active} = 0;
     401                &update_this_exposure($exposure);
     402                $counter++; # To ensure everyone else is consistent
    263403                next;
    264404            }
    265405        }
    266406
     407        # Determine the current state of chipRuns for these exposures, and update/remake as needed.
    267408        if (S64_IS_NOT_NULL($chip_id)) { # We already have a defined chip_id
    268409            if (($pairwise) && !($pair_id)) {
     
    270411                &my_die("Exposure $exp_id for $lap_id is declared pairwise without a defined pair", $lap_id);
    271412            }
     413            $exposure->{data_state} = 'exists';
     414            if ($updateable) { # We know about this run, but the data needs to be regenerated.
     415                $exposure->{data_state} = 'update';
     416                $exposure = remake_this_exposure_by_update($exposure);
     417            }
     418            &update_this_exposure($exposure);
    272419            $matching{$object}{$comment} = $exp_id;
    273420            $indexing{$exp_id} = $counter;
    274421            $counter++;
    275             next;
    276422        }
    277423        else { # We do not already have a chip_id. 
    278424            # Make a chipRun, and update the exposure.
     425            $exposure->{data_state} = 'run';
    279426            $exposure = remake_this_exposure($exposure);
    280            
    281427            # Save our information for diff pairing.
     428            &update_this_exposure($exposure);
    282429            $matching{$object}{$comment} = $exp_id;
    283430            $indexing{$exp_id} = $counter;
    284431            $counter++;
    285432        }
     433
    286434        if ($verbose) {
    287435            print "ZZ: $exp_id $object $comment $matching{$object}{$comment}\n";
     
    296444            print "$object $comment $matching{$object}{$comment} $indexing{$matching{$object}{$comment}} $exp_ids_to_diff[-1]\n";
    297445        }
    298         @exp_ids_to_diff = sort { $indexing{$a} <=> $indexing{$b} } @exp_ids_to_diff;
     446        @exp_ids_to_diff = sort { $indexing{$a} <=> $indexing{$b} } @exp_ids_to_diff; # This is effectively a sort by dateobs.
    299447       
    300448        if (( $#exp_ids_to_diff + 1) % 2 != 0) { # We have an odd number of exposures, even after comment filtering
     
    309457            my $exp_B = ${ $exposures }[$indexing{$exp_id_B}];
    310458            print "$exp_A $exp_B $exp_id_A $exp_id_B $indexing{$exp_id_A} $indexing{$exp_id_B}\n";
    311             $exp_A->{pairwise} = 1;
    312             $exp_A->{private} = 0;
    313             $exp_A->{pair_id} = $exp_B->{chip_id};
    314            
    315             $exp_B->{pairwise} = 1;
    316             $exp_B->{private} = 0;
    317             $exp_B->{pair_id} = $exp_A->{chip_id};
    318            
    319             if ($verbose) {
    320                 print "LAP_DIFFS: $object: $exp_A->{exp_id} and $exp_B->{exp_id} are a pair\n";
     459            if ($exp_A->{diff_id} == $exp_B->{diff_id}) {
     460                $exp_A->{pairwise} = 1;
     461                $exp_A->{pair_id} = $exp_B->{chip_id};
     462               
     463                $exp_B->{pairwise} = 1;
     464                $exp_B->{pair_id} = $exp_A->{chip_id};
     465                if ($verbose) {
     466                    print "LAP_DIFFS: $object: $exp_A->{exp_id} and $exp_B->{exp_id} are a pair\n";
     467                }
     468            }
     469            else {
     470                $exp_A->{pairwise} = 0;
     471                $exp_B->{pairwise} = 0;
    321472            }
    322473        }
     
    331482            $exposure->{pairwise} = 0; # We marked it for pairwise diffs, but didn't match it. Probably an error.
    332483        }
    333         if (!($exposure->{pairwise})) {
    334             $exposure->{private} = 1; # If this isn't being pairwise diffed, it needs to be private
    335         }
    336 
     484       
    337485        update_this_exposure($exposure);
    338486    }
     
    403551            $complete_fstacks++;
    404552        }
     553        elsif (($stack->{final_state})&&
     554               ($stack->{final_state} eq 'drop')) {
     555            $complete_fstacks++;
     556        }
    405557        elsif (($stack->{final_state})&&($stack->{final_state} eq 'new')&&
    406558               ($stack->{final_fault} >= 4)&&($stack->{final_fault} != 32767)) {
     
    457609    # Things I want to know before I'm through
    458610#     my $needs_qstack = 0;
    459     my $needs_something_remade = 0;
    460     my $needs_something_private = 0;
     611    my $needs_something_remade = 0;  # I never need something remade, because we're committed to one-exp=one-chip
     612    my $needs_something_private = 0; # I never need something private, as that is calculated by the difference engine.
    461613#     my $can_qstack = 0;
    462614     my $have_diff = 0;
     
    468620    my $are_warped = 0;
    469621    my $are_magicked = 0;
    470 
    471622    foreach my $exposure (@$exposures) {
    472623        $total_exposures++;
     
    480631            else { # We claimed to be pairwise, but do not have a valid pair_id.
    481632                $exposure->{pairwise} = 0;
    482                 $exposure->{private} = 1;
    483633                &update_this_exposure($exposure);
    484634            }
     
    487637        if  ($exposure->{data_state} eq 'drop') { # This exposure is impossible, so fudge the counts so we get through.
    488638            $are_warped++;
    489 #           $can_qstack ++;
    490639            $can_diff ++;
    491640            $have_diff ++;
    492641            $are_magicked ++;
    493 #           $can_fstack ++;         
     642            next;
     643        }
     644
     645        if ($exposure->{data_state} eq 'pending_update') {
     646            $exposure->{data_state} = 'update';
     647            $exposure = &remake_this_exposure_by_update($exposure);
     648            &update_this_exposure($exposure);
    494649            next;
    495650        }
    496651       
    497652        if ($exposure->{private}) { # I've declared this exposure private to this lapRun.
    498 #           $needs_qstack++;
    499653            push @lonely_exposures, $exposure;
    500 #           $lonely_exposures++;
    501654        }
    502655       
    503         if ($exposure->{needs_remade}) { # This does the check that private = false for other lapRun
    504             $needs_something_remade = 1;
    505             $exposure = remake_this_exposure($exposure);
    506         }
     656#       if ($exposure->{needs_remade}) { # This does the check that private = false for other lapRun
     657#           $needs_something_remade = 1;
     658#           $exposure = remake_this_exposure($exposure);
     659#       }
    507660        # Do quality checks here
    508661        my $is_bad_quality = 0;
     
    536689                    ($exposure->{diffRun_state} eq 'full')) {
    537690                $are_warped++;
    538 #               $needs_qstack++;
    539                 $needs_something_private = 1;
    540691                if ($companion) {
    541                     $companion->{private} = 1;
    542692                    $companion->{pairwise} = 0;
    543693                    &update_this_exposure($companion);
    544                     push @lonely_exposures, $companion;
    545 #                   $lonely_exposures++;
     694#                   push @lonely_exposures, $companion;
    546695                }
    547                 $exposure->{private} = 1;
    548696                $exposure->{pairwise} = 0;
    549697            }
    550698            $exposure->{data_state} = 'drop';
    551699            &update_this_exposure($exposure);
     700            next;
    552701        }
    553702       
     
    558707#           $can_qstack ++;
    559708            $can_diff ++;
    560         }
    561         if (($exposure->{magicked}&&
    562              &S64_IS_NOT_NULL($exposure->{magicked}))) {  # This exposure has been magicked, so it is through with diff.
     709            $exposure->{data_state} = 'to_diff';
     710        }
     711        if (($exposure->{diff_id})&&
     712            (&S64_IS_NOT_NULL($exposure->{diff_id}))&&
     713            (($exposure->{diffRun_state} eq 'full')||
     714             ($exposure->{diffRun_state} eq 'error_cleaned')||
     715             ($exposure->{diffRun_state} eq 'cleaned'))
     716            ) {
    563717            $are_magicked++;
    564 #           $can_fstack ++;
    565         }
    566         if (($exposure->{diff_id})&&(&S64_IS_NOT_NULL($exposure->{diff_id}))) {
    567718            $have_diff ++;
     719#           $exposure->{data_state} = 'to_magic';
     720            $exposure->{data_state} = 'full';
     721        }
     722        # We no longer need to care about magic
     723#       if (($exposure->{magicked})&&
     724#           ($exposure->{warpRun_state})&&
     725#           ($exposure->{warpRun_state} eq 'full')&&
     726#           (&S64_IS_NOT_NULL($exposure->{magicked}))) { # This exposure has been magicked, so it is through with diff.
     727#           $are_magicked++;
     728#           $exposure->{data_state} = 'full';
     729# #         $can_fstack ++;
     730#       }
     731        unless ($debug) {
     732            &update_this_exposure($exposure);
    568733        }
    569734    }
     
    575740    print "STATUS: HAVE_FSTACK:     $have_fstack\n";
    576741
    577 #    print "STATUS: NEEDS_QSTACK:    $needs_qstack\n";
    578742    print "STATUS: NEEDS_REMADE:    $needs_something_remade\n";
    579743    print "STATUS: NEEDS PRIVATIZE: $needs_something_private\n";
    580744    print "STATUS: ARE WARPED:      $are_warped\n";
    581745    print "STATUS: ARE MAGICKED:    $are_magicked\n";
    582 #    print "STATUS: CAN_QSTACK:      $can_qstack\n";
    583746    print "STATUS: CAN_DIFF:        $can_diff\n";
    584747    print "STATUS: HAVE_DIFF:       $have_diff\n";
    585 #    print "STATUS: CAN_FSTACK:      $can_fstack\n";
    586748
    587749    print "STATUS: TOTAL_EXPOSURES: $total_exposures\n";
     
    595757        if ($defined_fstack == 0) {        # We have not yet made any stacks.
    596758            print "STATUS: We can attempt to queue deep final stacks.\n";
    597             my $Nstacks_made = &queue_muggle_finalstack($exposures);
     759            my $Nstacks_made;
     760            unless ($debug) {
     761                $Nstacks_made = &queue_muggle_finalstack($exposures);
     762            }
    598763            print "STATUS: Made $Nstacks_made final stacks.\n";
    599764            exit($Nstacks_made);
     
    603768            if ($have_fstack == $defined_fstack) { # We have made all the stacks we have asked for (so far)
    604769                if ($are_magicked < $total_exposures) { # But we have not yet made diffs
     770#               if ($have_diff < $total_exposures) { # We have not yet made diffs
    605771                    if (($can_diff == $total_exposures)&& # And we have exposures that should be diffed.
    606772                        ($have_diff < $can_diff)) {       # and we haven't made them all yet, either.
    607773                        print "STATUS: Dropping unpaired exposures and making pairwise diffs.\n";
    608                         foreach my $exposure (@lonely_exposures) {
    609                             $exposure->{data_state} = 'drop';
    610                             &update_this_exposure($exposure);
     774#                       foreach my $exposure (@lonely_exposures) {
     775#                           $exposure->{data_state} = 'drop';
     776#                           &update_this_exposure($exposure);
     777#                       }
     778                        unless ($debug) {
     779                            &queue_diffs($exposures);
    611780                        }
    612                         &queue_diffs($exposures);
    613781                        exit(0);
    614782                    }
     
    621789                }
    622790                elsif ($are_magicked == $total_exposures) { # We have made all of the diffs, and propagated through magic
    623                     print "STATUS: We can create all remaining stacks possible.\n";
    624                     my $Nstacks_made = &queue_magic_finalstack($exposures);
    625                     if ($Nstacks_made == 0) { # We have made all the stacks that we will ever make.
     791                    print "STATUS: We would create all remaining stacks possible, but no longer require magic.\n";
     792#                   my $Nstacks_made = -1;
     793#                   unless ($debug) {
     794#                       $Nstacks_made = &queue_muggle_finalstack($exposures);
     795#                   }
     796#                   if ($Nstacks_made == 0) { # We have made all the stacks that we will ever make.
    626797                        print "STATUS: No more stacks generated. Deactivating exposures for this complete lapRun.\n";
    627                         &deactivate_exposures($exposures);
    628                         $command = "$laptool -updaterun -lap_id $lap_id";
    629                         $command .= " -dbname $dbname " if defined $dbname;
    630                         $command .= " -set_state full ";
    631                         my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    632                             run(command => $command, verbose => $verbose);
    633                         unless ($success) {
    634                             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    635                             &my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
    636                         }
     798                        unless ($debug) {
     799                            &deactivate_exposures($exposures);
     800                       
     801                            $command = "$laptool -updaterun -lap_id $lap_id";
     802                            $command .= " -dbname $dbname " if defined $dbname;
     803                            $command .= " -set_state full ";
     804                            my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     805                                run(command => $command, verbose => $verbose);
     806                            unless ($success) {
     807                                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     808                                &my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
     809                            }
     810#                       }
    637811                        exit(0);
    638812                    }
    639                     else {
    640                         print "STATUS: $Nstacks_made stacks made.\n";
    641                         exit(0);
    642                     }
     813#                   else {
     814#                       print "STATUS: $Nstacks_made stacks made.\n";
     815#                       exit(0);
     816#                   }
    643817                }
    644818                else { # What?
     
    8421016    foreach $exposure (@$exposures) {
    8431017        if (($exposure->{data_state} ne 'drop')&&
    844             (S64_IS_NOT_NULL($exposure->{magicked}))&&
     1018#           (S64_IS_NOT_NULL($exposure->{magicked}))&&
    8451019            (S64_IS_NOT_NULL($exposure->{warp_id}))) {
    8461020            $warps .= " -warp_id $exposure->{warp_id} ";
     
    9241098            next;
    9251099        }
    926         if ($exposure->{diff_id}&&S64_IS_NOT_NULL($exposure->{diff_id})) { # Not sure how this would happen, but still. ## This happens when we inherit a complete exposure.
     1100        if ($exposure->{diff_id}&&S64_IS_NOT_NULL($exposure->{diff_id})) { # This happens when we inherit a complete exposure.
    9271101            next;
    9281102        }
     
    9641138        }
    9651139        else { # warp-qstack
    966             next; # We no longer wish to make these, and should never get here.
    967             $command .= '-pretend';
    968 #           $command .= " -definewarpstack -set_reduction NOCONVDIFF -available -good_frac 0.2 ";
    969 #           $command .= " -warp_id $exposure->{warp_id} -stack_label ${label}.quick ";
    970 #           $already_queued{$exposure->{warp_id}} = 1;
     1140            # We need to decide if we can make a warp-stack diff:
     1141            if (&can_warp_stack_diff_be_made($exposure)) {
     1142#           next;
     1143#           $command .= '-pretend';
     1144                $command .= " -definewarpstack -available -good_frac 0.2 ";
     1145                $command .= " -warp_id $exposure->{warp_id} -stack_label ${label} ";
     1146                $already_queued{$exposure->{warp_id}} = 1;
     1147                $exposure->{private} = 0;
     1148                &update_this_exposure($exposure);
     1149            }
     1150            else {
     1151                $exposure->{private} = 1;
     1152                $exposure->{data_state} = 'drop';
     1153                $already_queued{$exposure->{warp_id}} = 1;
     1154                &update_this_exposure($exposure);
     1155                next;
     1156            }
    9711157        }
    9721158       
     
    10061192}
    10071193
     1194sub can_warp_stack_diff_be_made {
     1195    my $exposure = shift;
     1196    my $lap_id   = $exposure->{lap_id};
     1197    my $warp_id  = $exposure->{warp_id};
     1198
     1199    my $command = "$laptool -diffcheck -lap_id $lap_id -warp_id $warp_id";
     1200    $command .= " -dbname $dbname " if defined $dbname;
     1201
     1202    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1203        run(command => $command, verbose => $verbose);
     1204    unless ($success) {
     1205        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1206        &my_die("Unable to perform laptool -diffcheck: $error_code", $lap_id, $warp_id);
     1207    }
     1208    if (@$stdout_buf == 0) {
     1209        return(0);
     1210    }
     1211    my $skycells = $mdcParser->parse_list(join "", @$stdout_buf) or
     1212        &my_die("Unable to parse metadata from laptool -diffcheck", $lap_id, $warp_id);
     1213    foreach my $skycell (@$skycells) {
     1214        unless (defined($skycell->{stack_state})) {
     1215            return(0);
     1216        }
     1217        if ($skycell->{stack_state} ne 'full') {
     1218            return(0);
     1219        }
     1220        if ($skycell->{warp_state} ne 'full') {
     1221            return(0);
     1222        }
     1223        unless (S64_IS_NOT_NULL($skycell->{stack_id})) {
     1224            return(0);
     1225        }
     1226    }
     1227    return(1);
     1228}
     1229
     1230
    10081231# Deactivate all exposures in this run.
    10091232sub deactivate_exposures {
    10101233    my $exposures = shift;
    10111234    foreach my $exposure (@$exposures) {
    1012         $exposure->{active} = 0;
    1013         update_this_exposure($exposure);
     1235        if ($exposure->{private} == 1) {  # This can probably be relaxed since we can update an undestreaked warp.
     1236            $exposure->{active} = 1;
     1237        }
     1238        else {
     1239            $exposure->{active} = 0;
     1240        }
     1241        update_this_exposure($exposure);       
    10141242    }
    10151243}
     
    10221250sub cleanup_mode {
    10231251    my $lap_id = shift;
     1252
     1253    if (defined($queue_list)) {
     1254        my $successful = 1;
     1255        open(Q,$queue_list) or ($successful = 0);
     1256        if ($successful == 1) {
     1257            while(<Q>) {
     1258                chomp;
     1259                my $cmd = $_;
     1260                my ($projection_cell,$seq_id,$filter,$label);
     1261                $projection_cell = $cmd;
     1262                $projection_cell =~ s/.*?-projection_cell (skycell.\w+?) .*/$1/;
     1263                $seq_id = $cmd;
     1264                $seq_id =~ s/.*-seq_id (\d+?) .*/$1/;
     1265                $filter = $cmd;
     1266                $filter =~ s/.*-filter (\w\.00000) .*/$1/;
     1267                if ($filter =~ /\s+?/) {
     1268                    $filter =~ s/.*-filter (\w\.00000)$/$1/;
     1269                }
     1270                $label = $cmd;
     1271                $label =~ s/.*-label (.+?) .*/$1/;
     1272               
     1273                my $response;
     1274                chomp($response =
     1275                      `laptool -dbname gpc1 -listrun -projection_cell $projection_cell -seq_id $seq_id -filter $filter -label $label -simple`);
     1276                my $state = (split /\s+/, $response)[5];
     1277               
     1278                unless (defined($state)) {
     1279                    if ($verbose) {
     1280                        print "Queuing: $cmd\n";
     1281                    }
     1282                    system($cmd);
     1283                   
     1284                    my $i = 0;
     1285                    do {
     1286                        sleep(5);
     1287                        chomp($response =
     1288                              `laptool -dbname gpc1 -listrun -projection_cell $projection_cell -seq_id $seq_id -filter $filter -label $label -simple`);
     1289                        $state = (split /\s+/, $response)[5];
     1290                        $i++;
     1291                        unless(defined($state)) {
     1292                            $successful = 0;
     1293                        }
     1294                    } while (($state ne 'run')&&($i < 20)&&($successful));
     1295                    last;
     1296                }
     1297            }
     1298            close(Q);
     1299        }
     1300    }
     1301
    10241302    my $command = "$laptool -inactiveexp -lap_id $lap_id ";
    10251303    $command .= " -dbname $dbname " if defined $dbname;
     
    10331311    if (@$stdout_buf == 0) {
    10341312        # Nothing to do.
     1313        $command = "$laptool -updaterun -lap_id $lap_id";
     1314        $command .= " -dbname $dbname " if defined $dbname;
     1315        $command .= " -set_state done ";
     1316        ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1317            run(command => $command, verbose => $verbose);
     1318        unless ($success) {
     1319            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1320            &my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
     1321        }
     1322
    10351323        return(0);
    10361324    }
     
    10431331        'warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -warp_id @WARP_ID@',
    10441332        'difftool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -diff_id @DIFF_ID@',
     1333        'magictool -dbname @DBNAME@ -updaterun -set_state full -set_label @LABEL@.old -magic_id @MAGIC_ID@',
    10451334        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage chip -stage_id @CHIP_ID@',
    10461335        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage warp -stage_id @WARP_ID@',
    10471336        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage diff -stage_id @DIFF_ID@');
     1337   
    10481338    foreach my $exposure (@$exposures) {
    10491339        if ($exposure->{is_in_use}) {
     
    10771367                }
    10781368            }
     1369            if ($command =~ /\@MAGIC_ID\@/) {
     1370                if ((S64_IS_NOT_NULL($exposure->{magicked}))&&
     1371                     ($exposure->{magicked} > 0)) {
     1372                    $command =~ s/\@MAGIC_ID\@/$exposure->{magicked}/;
     1373                }
     1374                else {
     1375                    next;
     1376                }
     1377            }
    10791378            $command =~ s/\@LABEL\@/$exposure->{label}/;
    10801379           
     
    11391438        &my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
    11401439    }
    1141 
     1440    return(0);
    11421441}
    11431442   
     
    12101509        $command .= " -set_data_state $exposure->{data_state} ";
    12111510    }
    1212 
    1213     my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    1214         run(command => $command, verbose => $verbose);
    1215     unless ($success) {
    1216         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    1217         &my_die("Unable to perform laptool -updateexp: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
     1511    unless ($do_nothing) {
     1512        my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1513            run(command => $command, verbose => $verbose);
     1514       
     1515        unless ($success) {
     1516            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1517            &my_die("Unable to perform laptool -updateexp: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
     1518        }
    12181519    }
    12191520}   
Note: See TracChangeset for help on using the changeset viewer.