IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 21, 2011, 11:11:16 AM (15 years ago)
Author:
watersc1
Message:

Update to LAP code.

File:
1 edited

Legend:

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

    r32195 r32422  
    200200    return($exposure);
    201201}
     202
     203sub remake_this_exposure_by_update {
     204    my $exposure = shift;
     205
     206    my @utctime = gmtime();
     207    $utctime[5] += 1900;
     208    $utctime[4] += 1;
     209
     210    my $label = $exposure->{label};
     211
     212    my $date = sprintf("%4d%02d%02d",$utctime[5],$utctime[4],$utctime[3]);
     213    my $workdir_date = sprintf("%4d/%02d/%02d",$utctime[5],$utctime[4],$utctime[3]);
     214    my $workdir = "neb://\@HOST\@.0/${dbname}/${label}/${workdir_date}";
     215    my $data_group = "${label}.${date}";
     216
     217    my $chiptool_info_cmd = "chiptool -listrun -exp_id $exposure->{exp_id} -chip_id $exposure->{chip_id} ";
     218    $chiptool_info_cmd   .= " -dbname $dbname " if defined $dbname;
     219
     220    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     221        run(command => $chiptool_info_cmd, verbose => $verbose);
     222    unless ($success) {
     223        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     224        &my_die("Unable to perform chiptool -listrun: $error_code", $exposure->{exp_id}, $data_group);
     225    }
     226    my $chips = $mdcParser->parse_list(join "", @$stdout_buf) or
     227        &my_die("Unable to parse metadata from chiptool -listrun", $exposure->{exp_id}, $data_group);
     228    # There should be only one.
     229    my $chip = ${ $chips }[0];
     230    my $chip_magicDS_id = 0;
     231    if ($chip) {
     232        $chip_magicDS_id = $chip->{magic_ds_id};
     233    }
     234    if ($chip_magicDS_id == 0) {
     235        return(&remake_this_exposure($exposure));
     236    }
     237
     238    my $warptool_info_cmd = "warptool -listrun -exp_id $exposure->{exp_id} -chip_id $exposure->{chip_id} ";
     239    $warptool_info_cmd   .= " -dbname $dbname " if defined $dbname;
     240    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     241        run(command => $warptool_info_cmd, verbose => $verbose);
     242    unless ($success) {
     243        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     244        &my_die("Unable to perform warptool -listrun: $error_code", $exposure->{exp_id}, $data_group);
     245    }
     246    my $warps = $mdcParser->parse_list(join "", @$stdout_buf) or
     247        &my_die("Unable to parse metadata from warptool -listrun", $exposure->{exp_id}, $data_group);
     248    # There should be only one.
     249    my $warp = ${ $warps }[0];
     250    my $warp_id = 0;
     251    if ($warp) {
     252        $warp_id = $warp->{warp_id};
     253    }
     254    else {
     255        $exposure->{data_state} = 'drop';
     256        return($exposure);
     257    }   
     258    if ($warp_id == 0) {
     259        # Handle this correctly. Probably want to drop the exposure here.
     260        $exposure->{data_state} = 'drop';
     261        return($exposure);
     262    }
     263   
     264    my $chiptool_update_cmd = "chiptool -setimfiletoupdate -chip_id $exposure->{chip_id} -set_label $label";
     265    $chiptool_update_cmd   .= " -dbname $dbname " if defined $dbname;
     266    my $magicDS_update_cmd  = "magicdstool -setfiletoupdate -magic_ds_id $chip_magicDS_id -set_label $label";
     267    $magicDS_update_cmd    .= " -dbname $dbname " if defined $dbname;
     268    my $warptool_update_cmd = "warptool -setskyfiletoupdate -warp_id $warp_id -set_label $label";
     269    $warptool_update_cmd   .= " -dbname $dbname " if defined $dbname;
     270
     271    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     272        run(command => $chiptool_update_cmd, verbose => $verbose);
     273    unless ($success) {
     274        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     275        &my_die("Unable to perform chiptool -setimfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
     276    }
     277
     278    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     279        run(command => $magicDS_update_cmd, verbose => $verbose);
     280    unless ($success) {
     281        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     282        &my_die("Unable to perform magicdstool -setfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
     283    }
     284
     285    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     286        run(command => $warptool_update_cmd, verbose => $verbose);
     287    unless ($success) {
     288        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     289        &my_die("Unable to perform warptool -setskyfiletoupdate: $error_code", $exposure->{exp_id}, $data_group);
     290    }
     291   
     292    $exposure->{active} = 1;
     293    return($exposure);
     294}
     295       
     296sub determine_if_can_update {
     297    my $exposure = shift;
     298   
     299    if (S64_IS_NOT_NULL($exposure->{chip_id})) {
     300        if (($exposure->{chip_state} eq 'cleaned')||
     301            ($exposure->{chip_state} eq 'error_cleaned')) {
     302            return(1);
     303        }
     304    }
     305
     306    return(0);
     307}
     308       
    202309
    203310# This is the "user level" subroutine.
     
    240347        my $comment = $exposure->{comment};
    241348
    242         # This is a hack to fix old exposures that have no object.
     349        my $updateable = determine_if_can_update($exposure);
     350
     351        # This is a hack to fix old exposures that have no usable object/comment data.
    243352        unless(defined($comment)) {
    244353            $comment = '';
     
    247356            if ($comment =~ /3pi_/) {
    248357                $object = $comment;
    249                 $object =~ s/^.*?(3pi_\d\d_\d\d\d\d).*?$/$1/;
     358                $object =~ s/^.*?(3pi_\d\d_\d\d\d\d).*?$/F1 $1/;
    250359            }
    251360            elsif ($comment =~ / ps1_/) {
    252361                $object = $comment;
    253                 $object =~ s/^.*?(ps1_\d\d_\d\d\d\d).*$/$1/;
    254             }
    255             else {
    256                 $exposure->{data_state} = 'new';
     362                $object =~ s/^.*?(ps1_\d\d_\d\d\d\d).*$/F2 $1/;
     363            }
     364            elsif ($comment =~ /ThreePi.*3pi_/) {
     365                $object = $comment;
     366                $object =~ s/^ThreePi . (\S+? 3pi_\d\d_\d\d\d\d) .*$/F3 $1/;
     367            }           
     368            elsif ($comment =~ /ThreePi.*ps1_/) {
     369                $object = $comment;
     370                $object =~ s/^ThreePi . (\S+? ps1_\d\d_\d\d\d\d) .*$/F4 $1/;
     371            }           
     372            elsif ($comment =~ /ThreePi /) {
     373                $object = $comment;
     374                $object =~ s/^ThreePi . (\S+? \d\d\d\d) .*$/F5 $1/;
     375            }           
     376            elsif (($comment =~ /focus/i)||
     377                   ($comment =~ /test/i)||
     378                   ($comment =~ /hyster/i)||
     379                   ($comment =~ /dither/i)||
     380                   ($comment =~ /camera/i)
     381                ){
     382                # This is junk that shouldn't exist.
     383                $object = 'DROP';
     384                $exposure->{data_state} = 'drop';
    257385                $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++;
     386                $exposure->{pair_id} =  9223372036854775807;
     387                $exposure->{active} = 0;
     388                &update_this_exposure($exposure);
     389                $counter++; # To ensure everyone else is consistent
    263390                next;
    264391            }
    265392        }
    266393
     394        # Determine the current state of chipRuns for these exposures, and update/remake as needed.
    267395        if (S64_IS_NOT_NULL($chip_id)) { # We already have a defined chip_id
    268396            if (($pairwise) && !($pair_id)) {
     
    270398                &my_die("Exposure $exp_id for $lap_id is declared pairwise without a defined pair", $lap_id);
    271399            }
     400            $exposure->{data_state} = 'exists';
     401            if ($updateable) { # We know about this run, but the data needs to be regenerated.
     402                $exposure->{data_state} = 'update';
     403                $exposure = remake_this_exposure_by_update($exposure);
     404            }
     405            &update_this_exposure($exposure);
    272406            $matching{$object}{$comment} = $exp_id;
    273407            $indexing{$exp_id} = $counter;
    274408            $counter++;
    275             next;
    276409        }
    277410        else { # We do not already have a chip_id. 
    278411            # Make a chipRun, and update the exposure.
     412            $exposure->{data_state} = 'run';
    279413            $exposure = remake_this_exposure($exposure);
    280            
    281414            # Save our information for diff pairing.
     415            &update_this_exposure($exposure);
    282416            $matching{$object}{$comment} = $exp_id;
    283417            $indexing{$exp_id} = $counter;
    284418            $counter++;
    285419        }
     420
    286421        if ($verbose) {
    287422            print "ZZ: $exp_id $object $comment $matching{$object}{$comment}\n";
     
    296431            print "$object $comment $matching{$object}{$comment} $indexing{$matching{$object}{$comment}} $exp_ids_to_diff[-1]\n";
    297432        }
    298         @exp_ids_to_diff = sort { $indexing{$a} <=> $indexing{$b} } @exp_ids_to_diff;
     433        @exp_ids_to_diff = sort { $indexing{$a} <=> $indexing{$b} } @exp_ids_to_diff; # This is effectively a sort by dateobs.
    299434       
    300435        if (( $#exp_ids_to_diff + 1) % 2 != 0) { # We have an odd number of exposures, even after comment filtering
     
    310445            print "$exp_A $exp_B $exp_id_A $exp_id_B $indexing{$exp_id_A} $indexing{$exp_id_B}\n";
    311446            $exp_A->{pairwise} = 1;
    312             $exp_A->{private} = 0;
    313447            $exp_A->{pair_id} = $exp_B->{chip_id};
    314448           
    315449            $exp_B->{pairwise} = 1;
    316             $exp_B->{private} = 0;
    317450            $exp_B->{pair_id} = $exp_A->{chip_id};
    318451           
     
    331464            $exposure->{pairwise} = 0; # We marked it for pairwise diffs, but didn't match it. Probably an error.
    332465        }
    333         if (!($exposure->{pairwise})) {
    334             $exposure->{private} = 1; # If this isn't being pairwise diffed, it needs to be private
    335         }
    336 
     466       
    337467        update_this_exposure($exposure);
    338468    }
     
    457587    # Things I want to know before I'm through
    458588#     my $needs_qstack = 0;
    459     my $needs_something_remade = 0;
    460     my $needs_something_private = 0;
     589    my $needs_something_remade = 0;  # I never need something remade, because we're committed to one-exp=one-chip
     590    my $needs_something_private = 0; # I never need something private, as that is calculated by the difference engine.
    461591#     my $can_qstack = 0;
    462592     my $have_diff = 0;
     
    480610            else { # We claimed to be pairwise, but do not have a valid pair_id.
    481611                $exposure->{pairwise} = 0;
    482                 $exposure->{private} = 1;
    483612                &update_this_exposure($exposure);
    484613            }
     
    487616        if  ($exposure->{data_state} eq 'drop') { # This exposure is impossible, so fudge the counts so we get through.
    488617            $are_warped++;
    489 #           $can_qstack ++;
    490618            $can_diff ++;
    491619            $have_diff ++;
    492620            $are_magicked ++;
    493 #           $can_fstack ++;         
    494621            next;
    495622        }
    496623       
    497624        if ($exposure->{private}) { # I've declared this exposure private to this lapRun.
    498 #           $needs_qstack++;
    499625            push @lonely_exposures, $exposure;
    500 #           $lonely_exposures++;
    501626        }
    502627       
    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         }
     628#       if ($exposure->{needs_remade}) { # This does the check that private = false for other lapRun
     629#           $needs_something_remade = 1;
     630#           $exposure = remake_this_exposure($exposure);
     631#       }
    507632        # Do quality checks here
    508633        my $is_bad_quality = 0;
     
    536661                    ($exposure->{diffRun_state} eq 'full')) {
    537662                $are_warped++;
    538 #               $needs_qstack++;
    539                 $needs_something_private = 1;
    540663                if ($companion) {
    541                     $companion->{private} = 1;
    542664                    $companion->{pairwise} = 0;
    543665                    &update_this_exposure($companion);
    544                     push @lonely_exposures, $companion;
    545 #                   $lonely_exposures++;
     666#                   push @lonely_exposures, $companion;
    546667                }
    547                 $exposure->{private} = 1;
    548668                $exposure->{pairwise} = 0;
    549669            }
     
    558678#           $can_qstack ++;
    559679            $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.
    563             $are_magicked++;
    564 #           $can_fstack ++;
     680            $exposure->{data_state} = 'to_diff';
    565681        }
    566682        if (($exposure->{diff_id})&&(&S64_IS_NOT_NULL($exposure->{diff_id}))) {
    567683            $have_diff ++;
    568         }
     684            $exposure->{data_state} = 'to_magic';
     685        }
     686        if (($exposure->{magicked})&&
     687            ($exposure->{warpRun_state})&&
     688            ($exposure->{warpRun_state} eq 'full')&&
     689            (&S64_IS_NOT_NULL($exposure->{magicked}))) {  # This exposure has been magicked, so it is through with diff.
     690            $are_magicked++;
     691            $exposure->{data_state} = 'full';
     692#           $can_fstack ++;
     693        }
     694        &update_this_exposure($exposure);
    569695    }
    570696
     
    575701    print "STATUS: HAVE_FSTACK:     $have_fstack\n";
    576702
    577 #    print "STATUS: NEEDS_QSTACK:    $needs_qstack\n";
    578703    print "STATUS: NEEDS_REMADE:    $needs_something_remade\n";
    579704    print "STATUS: NEEDS PRIVATIZE: $needs_something_private\n";
    580705    print "STATUS: ARE WARPED:      $are_warped\n";
    581706    print "STATUS: ARE MAGICKED:    $are_magicked\n";
    582 #    print "STATUS: CAN_QSTACK:      $can_qstack\n";
    583707    print "STATUS: CAN_DIFF:        $can_diff\n";
    584708    print "STATUS: HAVE_DIFF:       $have_diff\n";
    585 #    print "STATUS: CAN_FSTACK:      $can_fstack\n";
    586709
    587710    print "STATUS: TOTAL_EXPOSURES: $total_exposures\n";
     
    9241047            next;
    9251048        }
    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.
     1049        if ($exposure->{diff_id}&&S64_IS_NOT_NULL($exposure->{diff_id})) { # This happens when we inherit a complete exposure.
    9271050            next;
    9281051        }
     
    9641087        }
    9651088        else { # warp-qstack
     1089            # We need to decide if we can make a warp-stack diff:
     1090            if (&can_warp_stack_diff_be_made($exposure)) {
    9661091#           next;
    9671092#           $command .= '-pretend';
    968             $command .= " -definewarpstack -available -good_frac 0.2 ";
    969             $command .= " -warp_id $exposure->{warp_id} -stack_label ${label} ";
    970             $already_queued{$exposure->{warp_id}} = 1;
     1093                $command .= " -definewarpstack -available -good_frac 0.2 ";
     1094                $command .= " -warp_id $exposure->{warp_id} -stack_label ${label} ";
     1095                $already_queued{$exposure->{warp_id}} = 1;
     1096                $exposure->{private} = 0;
     1097                &update_this_exposure($exposure);
     1098            }
     1099            else {
     1100                $exposure->{private} = 1;
     1101                $exposure->{data_state} = 'drop';
     1102                $already_queued{$exposure->{warp_id}} = 1;
     1103                &update_this_exposure($exposure);
     1104                next;
     1105            }
    9711106        }
    9721107       
     
    10061141}
    10071142
     1143sub can_warp_stack_diff_be_made {
     1144    my $exposure = shift;
     1145    my $lap_id   = $exposure->{lap_id};
     1146    my $warp_id  = $exposure->{warp_id};
     1147
     1148    my $command = "$laptool -diffcheck -lap_id $lap_id -warp_id $warp_id";
     1149    $command .= " -dbname $dbname " if defined $dbname;
     1150
     1151    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1152        run(command => $command, verbose => $verbose);
     1153    unless ($success) {
     1154        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1155        &my_die("Unable to perform laptool -diffcheck: $error_code", $lap_id, $warp_id);
     1156    }
     1157    if (@$stdout_buf == 0) {
     1158        return(0);
     1159    }
     1160    my $skycells = $mdcParser->parse_list(join "", @$stdout_buf) or
     1161        &my_die("Unable to parse metadata from laptool -diffcheck", $lap_id, $warp_id);
     1162    foreach my $skycell (@$skycells) {
     1163        if ($skycell->{stack_state} ne 'full') {
     1164            return(0);
     1165        }
     1166        if ($skycell->{warp_state} ne 'full') {
     1167            return(0);
     1168        }
     1169        unless (S64_IS_NOT_NULL($skycell->{stack_id})) {
     1170            return(0);
     1171        }
     1172    }
     1173    return(1);
     1174}
     1175
     1176
    10081177# Deactivate all exposures in this run.
    10091178sub deactivate_exposures {
    10101179    my $exposures = shift;
    10111180    foreach my $exposure (@$exposures) {
    1012         $exposure->{active} = 0;
    1013         update_this_exposure($exposure);
     1181        unless ($exposure->{private} == 1) {
     1182            $exposure->{active} = 0;
     1183            update_this_exposure($exposure);
     1184        }
    10141185    }
    10151186}
     
    10431214        'warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -warp_id @WARP_ID@',
    10441215        'difftool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -diff_id @DIFF_ID@',
     1216        'magictool -dbname @DBNAME@ -updaterun -set_state full -set_label @LABEL@.old -magic_id @MAGIC_ID@',
    10451217        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage chip -stage_id @CHIP_ID@',
    10461218        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage warp -stage_id @WARP_ID@',
    10471219        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage diff -stage_id @DIFF_ID@');
     1220   
    10481221    foreach my $exposure (@$exposures) {
    10491222        if ($exposure->{is_in_use}) {
     
    10771250                }
    10781251            }
     1252            if ($command =~ /\@MAGIC_ID\@/) {
     1253                if ((S64_IS_NOT_NULL($exposure->{magicked}))&&
     1254                     ($exposure->{magicked} > 0)) {
     1255                    $command =~ s/\@MAGIC_ID\@/$exposure->{magicked}/;
     1256                }
     1257                else {
     1258                    next;
     1259                }
     1260            }
    10791261            $command =~ s/\@LABEL\@/$exposure->{label}/;
    10801262           
Note: See TracChangeset for help on using the changeset viewer.