IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 8, 2011, 2:44:12 PM (15 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20110906
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110906

  • branches/eam_branches/ipp-20110906/ippScripts/scripts/camera_exp.pl

    r31906 r32630  
    8888
    8989if ($redirect) {
    90     $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $cam_id, $PS_EXIT_SYS_ERROR );
     90    $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $cam_id, $PS_EXIT_SYS_ERROR );
    9191    print "\n\n";
    9292    print "Starting script $0 on $host\n\n";
     
    404404        $ipprc->file_exists($file);
    405405
     406    # Funpack to confirm we've really made things correctly
     407    my $diskfile = $ipprc->file_resolve($file);
     408    if ($diskfile =~ /fits/) {
     409        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack",  $cam_id, $PS_EXIT_SYS_ERROR);
     410        my $check_command = "$funpack -S $diskfile > /dev/null";
     411        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     412            run(command => $check_command, verbose => $verbose);
     413        if (!$success) {
     414            &my_die("Output file not a valid fits file: $file",  $cam_id, $PS_EXIT_SYS_ERROR);
     415        }
     416    }
     417    #####
     418
     419
    406420    my $scheme = file_scheme($file);
    407421    if ($replicate and $scheme and (file_scheme($file) eq 'neb')) {
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/chip_imfile.pl

    r32355 r32630  
    3434my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    3535my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     36my $nebrepair = can_run('neb-repair') or (warn "Can't find neb-repair" and $missing_tools = 1);
     37
    3638if ($missing_tools) {
    3739    warn("Can't find required tools.");
     
    4446my ( $exp_id, $chip_id, $class_id, $chip_imfile_id, $uri, $camera, $outroot, $dbname, $run_state, $reduction, $threads, $verbose,
    4547     $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned );
    46 
    47 my $zaplog = 0;
    4848
    4949GetOptions(
     
    6565    'no-op'             => \$no_op,     # Don't do any operations?
    6666    'redirect-output'   => \$redirect,
    67     'zaplog'            => \$zaplog,
    6867    'save-temps'        => \$save_temps, # Save temporary files?
    6968    ) or pod2usage( 2 );
     
    9291}
    9392
    94 my ($logDest, $traceDest);
     93my ($logRule, $traceDest);
    9594if ($run_state eq 'new') {
    96     $logDest = prepare_output("LOG.IMFILE", $outroot, $class_id, $zaplog);
     95    $logRule = "LOG.IMFILE";
    9796    $traceDest = prepare_output("TRACE.IMFILE",  $outroot, $class_id, 1);
    9897} else {
    99     $logDest = prepare_output("LOG.IMFILE.UPDATE", $outroot, $class_id, 1);
     98    $logRule = "LOG.IMFILE.UPDATE";
    10099    $traceDest = prepare_output("TRACE.IMFILE.UPDATE",  $outroot, $class_id, 1);
    101100}
    102101
    103102if ($redirect) {
    104     $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR );
     103    my $logDest = $ipprc->filename($logRule, $outroot, $class_id);
     104
     105    $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR );
     106
    105107    print STDOUT "\n\n";
    106108    print STDOUT "Starting script $0 on $host\n\n";
     
    330332        # get the UNIX version of the (possible) neb: or path: filename
    331333        my $uriReal = $ipprc->file_resolve( $uri );
     334        # Catch errors here
     335        if (!$uriReal) {
     336            my $repair_cmd = "$nebrepair $uri";
     337            my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     338            unless ($repair_success) {
     339                &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     340            }
     341            $uriReal = $ipprc->file_resolve( $uri );
     342        }
     343           
    332344        &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal;
    333345
     
    336348        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
    337349        unless ($success) {
     350            # Catch errors here
     351            my $repair_cmd = "$nebrepair $uri";
     352            my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     353            unless ($repair_success) {
     354                &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     355            }
     356            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
     357        }
     358        unless ($success) {
    338359            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    339360            &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     
    348369            $burntoolTable_uri =~ s/fits$/burn.tbl/;
    349370            $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     371            if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) {
     372                my $repair_cmd = "$nebrepair $burntoolTable_uri";
     373                my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
     374                unless ($repair_success) {
     375                    &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     376                }
     377                $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     378            }
    350379            unless ($ipprc->file_exists($burntoolTable_uri)) {
     380                # Catch errors here
    351381                &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
    352382            }
     
    451481    $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
    452482    $command .= " -source_id $source_id" if defined $source_id;
    453     $command .= " -tracedest $traceDest -log $logDest";
     483    $command .= " -tracedest $traceDest";
    454484    $command .= " -dbname $dbname" if defined $dbname;
    455485
     
    727757        &my_die("Couldn't find expected output file: $file",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    728758    }
     759    # Funpack to confirm we've really made things correctly
     760    my $diskfile = $ipprc->file_resolve($file);
     761    if ($diskfile =~ /fits/) {
     762        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     763        my $check_command = "$funpack -S $diskfile > /dev/null";
     764        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     765            run(command => $check_command, verbose => $verbose);
     766        if (!$success) {
     767            &my_die("Output file not a valid fits file: $file", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     768        }
     769    }
     770    #####
    729771
    730772    if ($replicate and $neb) {
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/diff_skycell.pl

    r31941 r32630  
    4040my ($skycell_id, $diff_skyfile_id);
    4141my ($use_convolved);
    42 my $zaplog = 0;
    4342
    4443GetOptions(
     
    5756    'no-op'             => \$no_op, # Don't do any operations?
    5857    'redirect-output'   => \$redirect,
    59     'zaplog'            => \$zaplog, # delete any previous log file
    6058) or pod2usage( 2 );
    6159
     
    7977
    8078# XXX camera is not known here; cannot use filerules...
    81 # bills 2011-03-07 This is unfortunate because it prevents us from using prepare_output ...
    82 # my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    8379my $logDest = "$outroot.log";
    8480if ($run_state eq 'update') {
    8581    $logDest .= '.update';
    86     # ... well we can just do the dirty work here
    87     $ipprc->kill_file($logDest);
    88 } elsif ($zaplog) {
    89     $ipprc->kill_file($logDest);
    90 }
    91 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
     82}
     83$ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
    9284
    9385my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
     
    468460    &my_die("Couldn't find expected output file: $file",  $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
    469461
     462    # Funpack to confirm we've really made things correctly
     463    my $diskfile = $ipprc->file_resolve($file);
     464    if ($diskfile =~ /fits/) {
     465        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
     466        my $check_command = "$funpack -S $diskfile > /dev/null";
     467        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     468            run(command => $check_command, verbose => $verbose);
     469        if (!$success) {
     470            &my_die("Output file not a valid fits file: $file", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
     471        }
     472    }
     473    #####
     474
     475
    470476    if ($replicate and $neb) {
    471477        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/dist_bundle.pl

    r31572 r32630  
    636636        $file{file_rule} = $key;
    637637        $file{name} = $val;
     638        if ($val eq "STDERR" or $val eq "STDOUT") {
     639            print STDERR "Skipping $key because filename is $val\n";
     640            next;
     641        }
    638642        push @file_list, \%file;
    639643    }
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/ipp_apply_burntool_single.pl

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/lap_science.pl

    r32195 r32630  
    2727my ( $camera, $dbname);
    2828my ( $lap_id );
     29my ( $queue_list );
    2930my ( $chip_mode, $monitor_mode, $cleanup_mode);
    3031
     
    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    }
     
    457605    # Things I want to know before I'm through
    458606#     my $needs_qstack = 0;
    459     my $needs_something_remade = 0;
    460     my $needs_something_private = 0;
     607    my $needs_something_remade = 0;  # I never need something remade, because we're committed to one-exp=one-chip
     608    my $needs_something_private = 0; # I never need something private, as that is calculated by the difference engine.
    461609#     my $can_qstack = 0;
    462610     my $have_diff = 0;
     
    480628            else { # We claimed to be pairwise, but do not have a valid pair_id.
    481629                $exposure->{pairwise} = 0;
    482                 $exposure->{private} = 1;
    483630                &update_this_exposure($exposure);
    484631            }
     
    487634        if  ($exposure->{data_state} eq 'drop') { # This exposure is impossible, so fudge the counts so we get through.
    488635            $are_warped++;
    489 #           $can_qstack ++;
    490636            $can_diff ++;
    491637            $have_diff ++;
    492638            $are_magicked ++;
    493 #           $can_fstack ++;         
     639            next;
     640        }
     641
     642        if ($exposure->{data_state} eq 'pending_update') {
     643            $exposure->{data_state} = 'update';
     644            $exposure = &remake_this_exposure_by_update($exposure);
     645            &update_this_exposure($exposure);
    494646            next;
    495647        }
    496648       
    497649        if ($exposure->{private}) { # I've declared this exposure private to this lapRun.
    498 #           $needs_qstack++;
    499650            push @lonely_exposures, $exposure;
    500 #           $lonely_exposures++;
    501651        }
    502652       
    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         }
     653#       if ($exposure->{needs_remade}) { # This does the check that private = false for other lapRun
     654#           $needs_something_remade = 1;
     655#           $exposure = remake_this_exposure($exposure);
     656#       }
    507657        # Do quality checks here
    508658        my $is_bad_quality = 0;
     
    536686                    ($exposure->{diffRun_state} eq 'full')) {
    537687                $are_warped++;
    538 #               $needs_qstack++;
    539                 $needs_something_private = 1;
    540688                if ($companion) {
    541                     $companion->{private} = 1;
    542689                    $companion->{pairwise} = 0;
    543690                    &update_this_exposure($companion);
    544                     push @lonely_exposures, $companion;
    545 #                   $lonely_exposures++;
    546                 }
    547                 $exposure->{private} = 1;
     691#                   push @lonely_exposures, $companion;
     692                }
    548693                $exposure->{pairwise} = 0;
    549694            }
    550695            $exposure->{data_state} = 'drop';
    551696            &update_this_exposure($exposure);
     697            next;
    552698        }
    553699       
     
    558704#           $can_qstack ++;
    559705            $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 ++;
     706            $exposure->{data_state} = 'to_diff';
    565707        }
    566708        if (($exposure->{diff_id})&&(&S64_IS_NOT_NULL($exposure->{diff_id}))) {
    567709            $have_diff ++;
    568         }
     710            $exposure->{data_state} = 'to_magic';
     711        }
     712        if (($exposure->{magicked})&&
     713            ($exposure->{warpRun_state})&&
     714            ($exposure->{warpRun_state} eq 'full')&&
     715            (&S64_IS_NOT_NULL($exposure->{magicked}))) {  # This exposure has been magicked, so it is through with diff.
     716            $are_magicked++;
     717            $exposure->{data_state} = 'full';
     718#           $can_fstack ++;
     719        }
     720        &update_this_exposure($exposure);
    569721    }
    570722
     
    575727    print "STATUS: HAVE_FSTACK:     $have_fstack\n";
    576728
    577 #    print "STATUS: NEEDS_QSTACK:    $needs_qstack\n";
    578729    print "STATUS: NEEDS_REMADE:    $needs_something_remade\n";
    579730    print "STATUS: NEEDS PRIVATIZE: $needs_something_private\n";
    580731    print "STATUS: ARE WARPED:      $are_warped\n";
    581732    print "STATUS: ARE MAGICKED:    $are_magicked\n";
    582 #    print "STATUS: CAN_QSTACK:      $can_qstack\n";
    583733    print "STATUS: CAN_DIFF:        $can_diff\n";
    584734    print "STATUS: HAVE_DIFF:       $have_diff\n";
    585 #    print "STATUS: CAN_FSTACK:      $can_fstack\n";
    586735
    587736    print "STATUS: TOTAL_EXPOSURES: $total_exposures\n";
     
    9241073            next;
    9251074        }
    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.
     1075        if ($exposure->{diff_id}&&S64_IS_NOT_NULL($exposure->{diff_id})) { # This happens when we inherit a complete exposure.
    9271076            next;
    9281077        }
     
    9641113        }
    9651114        else { # warp-qstack
     1115            # We need to decide if we can make a warp-stack diff:
     1116            if (&can_warp_stack_diff_be_made($exposure)) {
    9661117#           next;
    9671118#           $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;
     1119                $command .= " -definewarpstack -available -good_frac 0.2 ";
     1120                $command .= " -warp_id $exposure->{warp_id} -stack_label ${label} ";
     1121                $already_queued{$exposure->{warp_id}} = 1;
     1122                $exposure->{private} = 0;
     1123                &update_this_exposure($exposure);
     1124            }
     1125            else {
     1126                $exposure->{private} = 1;
     1127                $exposure->{data_state} = 'drop';
     1128                $already_queued{$exposure->{warp_id}} = 1;
     1129                &update_this_exposure($exposure);
     1130                next;
     1131            }
    9711132        }
    9721133       
     
    10061167}
    10071168
     1169sub can_warp_stack_diff_be_made {
     1170    my $exposure = shift;
     1171    my $lap_id   = $exposure->{lap_id};
     1172    my $warp_id  = $exposure->{warp_id};
     1173
     1174    my $command = "$laptool -diffcheck -lap_id $lap_id -warp_id $warp_id";
     1175    $command .= " -dbname $dbname " if defined $dbname;
     1176
     1177    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1178        run(command => $command, verbose => $verbose);
     1179    unless ($success) {
     1180        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1181        &my_die("Unable to perform laptool -diffcheck: $error_code", $lap_id, $warp_id);
     1182    }
     1183    if (@$stdout_buf == 0) {
     1184        return(0);
     1185    }
     1186    my $skycells = $mdcParser->parse_list(join "", @$stdout_buf) or
     1187        &my_die("Unable to parse metadata from laptool -diffcheck", $lap_id, $warp_id);
     1188    foreach my $skycell (@$skycells) {
     1189        unless (defined($skycell->{stack_state})) {
     1190            return(0);
     1191        }
     1192        if ($skycell->{stack_state} ne 'full') {
     1193            return(0);
     1194        }
     1195        if ($skycell->{warp_state} ne 'full') {
     1196            return(0);
     1197        }
     1198        unless (S64_IS_NOT_NULL($skycell->{stack_id})) {
     1199            return(0);
     1200        }
     1201    }
     1202    return(1);
     1203}
     1204
     1205
    10081206# Deactivate all exposures in this run.
    10091207sub deactivate_exposures {
    10101208    my $exposures = shift;
    10111209    foreach my $exposure (@$exposures) {
    1012         $exposure->{active} = 0;
    1013         update_this_exposure($exposure);
     1210        if ($exposure->{private} == 1) {  # This can probably be relaxed since we can update an undestreaked warp.
     1211            $exposure->{active} = 1;
     1212        }
     1213        else {
     1214            $exposure->{active} = 0;
     1215        }
     1216        update_this_exposure($exposure);       
    10141217    }
    10151218}
     
    10221225sub cleanup_mode {
    10231226    my $lap_id = shift;
     1227
     1228    if (defined($queue_list)) {
     1229        my $successful = 1;
     1230        open(Q,$queue_list) or ($successful = 0);
     1231        if ($successful == 1) {
     1232            while(<Q>) {
     1233                chomp;
     1234                my $cmd = $_;
     1235                my ($projection_cell,$seq_id,$filter,$label);
     1236                $projection_cell = $cmd;
     1237                $projection_cell =~ s/.*?-projection_cell (skycell.\w+?) .*/$1/;
     1238                $seq_id = $cmd;
     1239                $seq_id =~ s/.*-seq_id (\d+?) .*/$1/;
     1240                $filter = $cmd;
     1241                $filter =~ s/.*-filter (\w\.00000) .*/$1/;
     1242                if ($filter =~ /\s+?/) {
     1243                    $filter =~ s/.*-filter (\w\.00000)$/$1/;
     1244                }
     1245                $label = $cmd;
     1246                $label =~ s/.*-label (.+?) .*/$1/;
     1247               
     1248                my $response;
     1249                chomp($response =
     1250                      `laptool -dbname gpc1 -listrun -projection_cell $projection_cell -seq_id $seq_id -filter $filter -label $label -simple`);
     1251                my $state = (split /\s+/, $response)[5];
     1252               
     1253                unless (defined($state)) {
     1254                    if ($verbose) {
     1255                        print "Queuing: $cmd\n";
     1256                    }
     1257                    system($cmd);
     1258                   
     1259                    my $i = 0;
     1260                    do {
     1261                        sleep(5);
     1262                        chomp($response =
     1263                              `laptool -dbname gpc1 -listrun -projection_cell $projection_cell -seq_id $seq_id -filter $filter -label $label -simple`);
     1264                        $state = (split /\s+/, $response)[5];
     1265                        $i++;
     1266                        unless(defined($state)) {
     1267                            $successful = 0;
     1268                        }
     1269                    } while (($state ne 'run')&&($i < 20)&&($successful));
     1270                    last;
     1271                }
     1272            }
     1273            close(Q);
     1274        }
     1275    }
     1276
    10241277    my $command = "$laptool -inactiveexp -lap_id $lap_id ";
    10251278    $command .= " -dbname $dbname " if defined $dbname;
     
    10431296        'warptool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -warp_id @WARP_ID@',
    10441297        'difftool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -set_label goto_cleaned -label @LABEL@ -diff_id @DIFF_ID@',
     1298        'magictool -dbname @DBNAME@ -updaterun -set_state full -set_label @LABEL@.old -magic_id @MAGIC_ID@',
    10451299        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage chip -stage_id @CHIP_ID@',
    10461300        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage warp -stage_id @WARP_ID@',
    10471301        'magicdstool -dbname @DBNAME@ -updaterun -set_state goto_cleaned -state full -set_label goto_cleaned -stage diff -stage_id @DIFF_ID@');
     1302   
    10481303    foreach my $exposure (@$exposures) {
    10491304        if ($exposure->{is_in_use}) {
     
    10721327                if (S64_IS_NOT_NULL($exposure->{diff_id})) {
    10731328                    $command =~ s/\@DIFF_ID\@/$exposure->{diff_id}/;
     1329                }
     1330                else {
     1331                    next;
     1332                }
     1333            }
     1334            if ($command =~ /\@MAGIC_ID\@/) {
     1335                if ((S64_IS_NOT_NULL($exposure->{magicked}))&&
     1336                     ($exposure->{magicked} > 0)) {
     1337                    $command =~ s/\@MAGIC_ID\@/$exposure->{magicked}/;
    10741338                }
    10751339                else {
     
    11391403        &my_die("Unable to perform laptool -updaterun: $error_code", $lap_id);
    11401404    }
    1141 
     1405    return(0);
    11421406}
    11431407   
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/magic_destreak.pl

    r31435 r32630  
    3535my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    3636my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     37my $dvoImageOverlaps = can_run('dvoImageOverlaps') or (warn "Can't find dvoImageOverlaps" and $missing_tools = 1);
    3738if ($missing_tools) {
    3839    warn("Can't find required tools.");
     
    4546my ($outroot, $recoveryroot, $magicked);
    4647my ($replace, $release);
     48my ($diff_tess_id, $mismatched_tess);
    4749my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
    4850
     
    6062           'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
    6163           'component=s'    => \$component,  # the class_id or skycell_id
     64           'mismatched_tess'=> \$mismatched_tess, # true if tess_id of input does not match tess_id of the diff used for magic
     65           'diff_tess_id=s' => \$diff_tess_id, # tess_id of diffRun used to compute the streaks
    6266           'uri=s'          => \$uri,        # uri of the input image
    6367           'path_base=s'    => \$path_base,  # path_base of the input
     
    106110if (($stage eq "raw") or ($stage eq "chip") or $stage eq "chip_bg") {
    107111    $class_id = $component;
    108     $skycell_args = " -class_id $component";
     112    $skycell_args = " -class_id";
    109113} elsif ($stage eq "warp" or $stage eq "warp_bg") {
    110114    $skycell_id = $component;
    111     $skycell_args = " -skycell_id $component";
     115    $skycell_args = " -skycell_id";
    112116} elsif ($stage eq "diff") {
    113117    $skycell_id = $component;
     
    215219    my ($sfh, $skycell_list);
    216220    if ($skycell_args) {
    217         my $command = "$magicdstool -magic_ds_id $magic_ds_id -getskycells $skycell_args";
    218         $command .= " -dbname $dbname" if defined $dbname;
    219         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    220             run(command => $command, verbose => $verbose);
    221         unless ($success) {
    222             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    223             &my_die("Unable to perform magicdstool -diffskyfile $skycell_args: $error_code", $magic_ds_id, $component, $error_code);
    224         }
    225 
    226         my $getskycells_output = join "", @$stdout_buf;
    227         if ($getskycells_output) {
    228             my $metadata = $mdcParser->parse($getskycells_output) or
    229                 &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR);
    230 
    231             my $skycells = parse_md_list($metadata) or
    232                     &my_die("Unable to parse metadata list", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR);
    233 
    234             ($sfh, $skycell_list) = tempfile( "/tmp/skycell_list.XXXX", UNLINK => !$save_temps);
    235 
    236             foreach my $skycell (@$skycells) {
    237                 my $skycell_uri;
    238                 if ($skycell->{data_state} eq "full" and $skycell->{quality} = 0) {
    239                     $skycell_uri = $ipprc->filename("PPSUB.OUTPUT", $skycell->{path_base});
    240                 } else {
    241                     # diff run must have been cleaned up, need to create this skycell file on the fly
    242                     if (!defined $temp_dir ) {
    243                         $temp_dir = tempdir( CLEANUP => !$save_temps);
     221        my $command = "$magicdstool -magic_ds_id $magic_ds_id -getskycells";
     222        $command .= " $skycell_args";
     223        my @diff_components;
     224        if ($mismatched_tess) {
     225            # tessellation for this skycell does not match the tessellation used for the magic analysis
     226            # used to calculate the streaks file
     227            @diff_components = get_overlaps($path_base, $component, $diff_tess_id);
     228        } else {
     229            @diff_components = ($component);
     230        }
     231
     232        # hash of uris by skycell.
     233        my %diff_skycells;
     234        foreach my $component (@diff_components) {
     235            my $this_command = "$command $component";
     236            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     237                run(command => $this_command, verbose => $verbose);
     238            unless ($success) {
     239                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     240                &my_die("Unable to perform magicdstool -diffskyfile $skycell_args: $error_code", $magic_ds_id, $component, $error_code);
     241            }
     242
     243            my $getskycells_output = join "", @$stdout_buf;
     244            if ($getskycells_output) {
     245                my $metadata = $mdcParser->parse($getskycells_output) or
     246                    &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR);
     247
     248                my $skycells = parse_md_list($metadata) or
     249                        &my_die("Unable to parse metadata list", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR);
     250
     251                foreach my $skycell (@$skycells) {
     252                    my $skycell_uri;
     253                    if ($skycell->{data_state} eq "full" and $skycell->{quality} == 0) {
     254                        $skycell_uri = $ipprc->filename("PPSUB.OUTPUT", $skycell->{path_base});
     255                        $diff_skycells{$skycell_id} = $skycell_uri;
     256                    } else {
     257                        # diff run must have been cleaned up, need to create this skycell file on the fly
     258                        if (!defined $temp_dir ) {
     259                            $temp_dir = tempdir( CLEANUP => !$save_temps);
     260                        }
     261                        my $skycell_id = $skycell->{skycell_id};
     262                        if (!$diff_skycells{$skycell_id}) {
     263                            $skycell_uri = "$temp_dir/$skycell_id";
     264                            $ipprc->skycell_file($skycell->{tess_id}, $skycell_id, $skycell_uri, $verbose) or
     265                                &my_die("failed to create skycell file for $skycell_id", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR);
     266                        }
     267                        $diff_skycells{$skycell_id} = $skycell_uri;
    244268                    }
    245                     my $skycell_id = $skycell->{skycell_id};
    246                     $skycell_uri = "$temp_dir/$skycell_id";
    247                     $ipprc->skycell_file($skycell->{tess_id}, $skycell_id, $skycell_uri, $verbose) or
    248                         &my_die("failed to create skycell file for $skycell_id", $magic_ds_id, $component, $PS_EXIT_PROG_ERROR);
    249269                }
    250                 print $sfh "$skycell_uri\n";
    251             }
    252             close $sfh
    253         }
     270            }
     271        }
     272        # write the skycell list file
     273        ($sfh, $skycell_list) = tempfile( "/tmp/skycell_list.XXXX", UNLINK => !$save_temps);
     274        foreach my $skycell_id (keys %diff_skycells) {
     275            print $sfh $diff_skycells{$skycell_id} . "\n";
     276        }
     277        close $sfh
    254278    }
    255279
     
    360384        $command .= " -chip_mask $ch_mask" if defined $ch_mask;
    361385        $command .= " -weight $weight" if defined $weight;
    362         if ((defined($sources))&&($ipprc->file_exists($sources))) {
    363             $command .= " -sources $sources" if defined $sources;
    364         }
    365         else {
    366             print "Did not add sources because they do not appear to exist. This may be an error.\n";
    367         }
     386        $command .= " -sources $sources" if defined $sources;
    368387        $command .= " -skycelllist $skycell_list" if defined $skycell_list;
    369388        $command .= " -replace" if $replace;
     
    475494
    476495my $statsFlags;
    477 if ($stage ne "camera") {
     496if (!$no_op and $stage ne "camera") {
    478497    file_check($statsFile);
    479498    {
     
    595614}
    596615
     616            # @diff_components = get_overlaps($path_base, $component, $tess_id, $diff_tess_id);
     617sub get_overlaps {
     618    my $path_base = shift;
     619    my $component = shift;
     620    my $diff_tess_id = shift;
     621
     622    my $tess_dir = $ipprc->tessellation_catdir( $diff_tess_id );
     623    my $catdir = $ipprc->convert_filename_absolute($tess_dir);
     624
     625    my $cmf = $ipprc->file_resolve("$path_base.cmf");
     626    &my_die("Unable to resolve $path_base.$cmf", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR) unless $cmf;
     627
     628    my $command = "$dvoImageOverlaps -D CATDIR $catdir -accept-astrom $cmf";
     629    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     630        run(command => $command, verbose => $verbose);
     631    unless ($success) {
     632        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     633        &my_die("Unable to perform dvoImageOverlaps $error_code", $magic_ds_id, $component,
     634            $error_code);
     635    }
     636    my @list;
     637    my $output = join "\n", @$stdout_buf;
     638    if ($output) {
     639        foreach my $line (split "\n", $output) {
     640            my (undef, undef, $skycell_id) = split " ", $line;
     641            push @list, $skycell_id;
     642        }
     643    }
     644    return @list
     645}
     646
    597647
    598648sub my_die
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/nightly_science.pl

    r31906 r32630  
    17081708    $cmd .= "-input_label $label  -template_label $label ";
    17091709    $cmd .= "-set_workdir $workdir  -set_dist_group $new_dist_group  -set_data_group $new_data_group ";
     1710    $cmd .= " -mintimediff 40000 ";
    17101711    $cmd .= " -simple  -set_label $label -filter $filter ";
    17111712    $cmd .= " -dateobs_begin ${lunation_start}T00:00:00 -dateobs_end ${lunation_end}T23:59:59 -distance 1.5 ";
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/register_exp.pl

    r31043 r32630  
    5454
    5555my $ipprc = PS::IPP::Config->new() or my_die( "Unable to set up", $exp_id, $PS_EXIT_CONFIG_ERROR );
    56 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $exp_id, $PS_EXIT_SYS_ERROR ) if $logfile;
     56$ipprc->redirect_to_logfile($logfile) or my_die( "Unable to redirect output", $exp_id, $PS_EXIT_SYS_ERROR ) if $logfile;
    5757
    5858pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/register_imfile.pl

    r32298 r32630  
    6060
    6161my $ipprc = PS::IPP::Config->new() or my_die_for_add( "Unable to set up", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    62 $ipprc->redirect_output($logfile) or my_die_for_add( "Unable to redirect output", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_SYS_ERROR ) if $logfile;
     62$ipprc->redirect_to_logfile($logfile) or my_die_for_add( "Unable to redirect output", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_SYS_ERROR ) if $logfile;
    6363
    6464pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    404404        }
    405405    }
     406    if ($exp_name =~ /a$/) {
     407        return(1);
     408    }
    406409    return(0);
    407410}
     
    517520
    518521    carp($msg);
    519     if (defined $exp_id && defined $tmp_class_id and not $no_update) {
     522    if (defined $exp_id && defined $class_id and not $no_update) {
    520523        my $command = "$regtool -updateprocessedimfile";
    521524        $command .= " -exp_id $exp_id";
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/stack_skycell.pl

    r31676 r32630  
    104104}
    105105
    106 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $stack_id, $PS_EXIT_SYS_ERROR ) if $redirect;
     106$ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $stack_id, $PS_EXIT_SYS_ERROR ) if $redirect;
    107107
    108108my $neb;
     
    243243    print $listFile "END\n\n";
    244244}
     245close($listFile);
    245246
    246247print "I've checked everything: $stack_id\n";
     
    491492    &my_die("Couldn't find expected output file: $file",  $stack_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
    492493
     494    # Funpack to confirm we've really made things correctly
     495    my $diskfile = $ipprc->file_resolve($file);
     496    if ($diskfile =~ /fits/) {
     497        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $stack_id, $PS_EXIT_SYS_ERROR);
     498        my $check_command = "$funpack -S $diskfile > /dev/null";
     499        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     500            run(command => $check_command, verbose => $verbose);
     501        if (!$success) {
     502            &my_die("Output file not a valid fits file: $file", $stack_id, $PS_EXIT_SYS_ERROR);
     503        }
     504    }
     505    #####
     506
    493507    if ($replicate and $neb) {
    494508        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $stack_id, $PS_EXIT_SYS_ERROR);
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/videophot_process.pl

    r32125 r32630  
    88my $host = hostname();
    99my $date = `date`;
    10 print "\n\n";
    11 print "Starting script $0 on $host at $date\n\n";
    12 
    1310use DateTime;
    1411my $mjd_start = DateTime->now->mjd;   # MJD of starting script
     
    2522use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2623use Pod::Usage qw( pod2usage );
     24use File::Temp qw( tempfile );
     25use File::Basename qw( basename );
    2726
    2827# Look for programs we need
    2928my $missing_tools;
    3029my $vptool = can_run('vptool') or (warn "Can't find vptool" and $missing_tools = 1);
    31 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
    3230my $psvideophot = can_run('psvideophot') or (warn "Can't find psvideophot" and $missing_tools = 1);
     31my $dumpvideo = can_run('dumpvideo') or (warn "Can't find dumpvideo" and $missing_tools = 1);
    3332my $listvideocells = can_run('listvideocells.pl') or (warn "Can't find listvideocells.pl" and $missing_tools = 1);
     33my $dsreg = can_run('dsreg') or (warn "Can't find dsreg" and $missing_tools = 1);
    3434if ($missing_tools) {
    3535    warn("Can't find required tools.");
    3636    exit($PS_EXIT_CONFIG_ERROR);
    3737}
    38 my ($vp_id, $exp_id, $camera, $outroot, $dbname, $verbose, $no_update, $no_op, $redirect);
     38my ($vp_id, $camera, $outroot, $dest_id, $dbname, $verbose, $no_update, $no_op, $redirect, $save_temps);
     39my ($product, $ds_dbname, $ds_dbhost);
    3940
    4041GetOptions(
    4142    'vp_id=s'           => \$vp_id,
    42     'exp_id=s'          => \$exp_id,
    4343    'camera=s'          => \$camera,
    4444    'outroot=s'         => \$outroot,
     45    'dest_id=s'         => \$dest_id,
     46    'product=s'         => \$product,
     47    'ds_dbname=s'       => \$ds_dbname,
     48    'ds_dbhost=s'       => \$ds_dbhost,
    4549    'dbname|d=s'        => \$dbname,
    4650    'verbose'           => \$verbose,
     51    'save-temps'        => \$save_temps,
    4752    'no-update'         => \$no_update, # Don't update the database?
    4853    'no-op'             => \$no_op,     # Don't do any operations?
     
    5257pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5358pod2usage(
    54     -msg => "Required options: --vp_id --exp_id --outroot --camera",
     59    -msg => "Required options: --vp_id --outroot --camera",
    5560    -exitval => 3,
    5661          ) unless defined $vp_id
    57             and defined $exp_id
    5862            and defined $camera
    5963            and defined $outroot;
    6064
     65pod2usage(
     66    -msg => " --product -ds_dbname and --dsdbhost are required if --dest_id",
     67    -exitval => 3,
     68          ) if ($dest_id and !( defined $product and defined $ds_dbname and defined $ds_dbhost));
     69
    6170
    6271$no_update = 1 if $no_op;
    63 
    64 my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, 'nochip', 'nocell', $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     72$vptool .= " -dbname $dbname" if $dbname;
     73
     74my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    6575
    6676my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    67 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $vp_id, 'nochip', 'nocell', $PS_EXIT_SYS_ERROR ) if $redirect;
    68 
    69 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
    70 
    71 # Get list of components for subtraction
     77if ($redirect) {
     78    $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $vp_id, $PS_EXIT_SYS_ERROR );
     79
     80    print "\n\n";
     81    print "Starting script $0 on $host at $date\n\n";
     82}
     83
     84# Get list of chips with pending video cells
    7285my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    7386my $files;
    7487{
    75 #    my $command = "$vptool -pendingimfile -vp_id $vp_id";
    76 #    $command .= " -dbname $dbname" if defined $dbname;
    77     my $command = "$regtool -processedimfile -video_cells -exp_id $exp_id";
    78     $command .= " -dbname $dbname" if defined $dbname;
    79     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    80         run(command => $command, verbose => $verbose);
    81     unless ($success) {
    82         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    83         &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, 'nochip', 'nocell', $error_code);
    84     }
    85 
    86     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    87         &my_die("Unable to parse metadata config doc", $vp_id, 'nochip', 'nocell', $PS_EXIT_PROG_ERROR);
    88     $files = parse_md_list($metadata) or
    89         &my_die("Unable to parse metadata list", $vp_id, 'nochip', 'nocell', $PS_EXIT_PROG_ERROR);
    90 }
     88    my $command = "$vptool -pendingimfile -vp_id $vp_id";
     89    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     90        run(command => $command, verbose => $verbose);
     91    unless ($success) {
     92        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     93        &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code);
     94    }
     95
     96    my $output = join "", @$stdout_buf;
     97    if ($output) {
     98        my $metadata = $mdcParser->parse($output) or
     99            &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR);
     100        $files = parse_md_list($metadata) or
     101        &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR);
     102    }
     103}
     104
    91105
    92106foreach my $file (@$files) {
     
    95109
    96110    my $resolved = $ipprc->file_resolve($uri);
    97     &my_die("Unable to resolve $uri", $vp_id, $class_id, 'nocell', $PS_EXIT_UNKNOWN_ERROR) unless $resolved;
     111    &my_die("Unable to resolve $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless $resolved;
    98112
    99113    my $command = "$listvideocells --file $resolved";
     
    102116    unless ($success) {
    103117        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    104         &my_die("Unable to perform $command: $error_code", $vp_id, $class_id,
    105             'nocell', $error_code);
     118        &my_die("Unable to perform $command: $error_code", $vp_id, $error_code);
    106119    }
    107120
    108121    my @video_cells = split "\n", (join "", @$stdout_buf);
    109     &my_die("No video cells found in $uri", $vp_id, $class_id,
    110             'nocell', $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells;
     122    &my_die("No video cells found in $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells;
    111123
    112124    foreach my $cell_id (@video_cells) {
    113         my $command = "$psvideophot $outroot";
     125        my $path_base =  "$outroot.$class_id.$cell_id";
     126        my $output = $ipprc->filename("PSVIDEOPHOT.OUTPUT", $path_base);
     127        my $command = "$psvideophot $output";
    114128        $command .= " -file $uri";
     129        $command .= " -class_id $class_id";
    115130        $command .= " -cell_id $cell_id";
    116         $command .= " -dbname $dbname" if defined $dbname;
     131        my $vpstart = DateTime->now->mjd;
    117132        unless ($no_op) {
    118133            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    120135            unless ($success) {
    121136                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    122                 &my_die("Unable to perform ppSub: $error_code", $vp_id, $class_id, $cell_id, $error_code);
     137                &my_die("Unable to perform psvideophot: $error_code", $vp_id, $error_code);
    123138            }
    124 
    125             # check_output($outputStats, 1);
    126139        } else {
    127140            print "Not executing: $command\n";
    128141        }
     142        # dump the video cell and the video table to a file
     143        unless ($no_op) {
     144            my $output = $path_base . ".fits";
     145            my $extname = "$cell_id";
     146            my $command = "$dumpvideo $uri $extname $output -includetable";
     147            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     148                run(command => $command, verbose => $verbose);
     149            unless ($success) {
     150                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     151                &my_die("Unable to perform dumpvideo: $error_code", $vp_id, $error_code);
     152            }
     153        } else {
     154            print "Not executing: $command\n";
     155        }
     156
    129157        unless ($no_update) {
    130             my $command = "$vptool -addvpcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";
    131             $command .= " -path_base $outroot";
    132 
    133             $command .= " -dbname $dbname" if defined $dbname;
     158            my $command = "$vptool -addprocessedcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";
     159            $command .= " -path_base $path_base";
     160            $command .= " -hostname $host";
     161            $command .= " -dtime_photom " . ((DateTime->now->mjd - $vpstart) * 86400);
    134162
    135163            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    138166                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    139167                my $err_message = "Unable to perform vptool -addvpcell";
    140                 &my_die("$err_message: $error_code", $vp_id, $class_id, $cell_id, $error_code);
     168                &my_die("$err_message: $error_code", $vp_id, $error_code);
    141169            }
    142170        }
     171    }
     172}
     173if ($dest_id) {
     174    my $command = "$vptool -processedcell -vp_id $vp_id";
     175    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     176        run(command => $command, verbose => $verbose);
     177    unless ($success) {
     178        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     179        &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code);
     180    }
     181
     182    my $output = join "", @$stdout_buf;
     183    my $cells;
     184    if ($output) {
     185        my $metadata = $mdcParser->parse($output) or
     186            &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR);
     187        $cells = parse_md_list($metadata) or
     188            &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR);
     189    }
     190    my ($reglist, $reglistName) = tempfile("/tmp/filelist.$vp_id.XXXX", UNLINK => !$save_temps);
     191
     192    if ($redirect) {
     193        print $reglist "$logDest|||text|\n";
     194    }
     195    my @exts = qw( vpt fits );
     196    my @types = qw( table fits );
     197    foreach my $cell (@$cells) {
     198        my $path_base = $cell->{path_base};
     199        for (my $i = 0; $i < scalar @exts; $i++) {
     200            my $file = "$path_base.$exts[$i]";
     201            my $type = $types[$i];
     202
     203            print $reglist "$file|||$type|\n";
     204        }
     205           
     206    }
     207    close $reglist or &my_die("failed to close $reglistName", $vp_id, $PS_EXIT_UNKNOWN_ERROR);
     208    unless ($no_update or $no_op) {
     209        my $fileset = basename($outroot);
     210        my $command = "$dsreg --add $fileset --product $product --type dump --list $reglistName";
     211        $command .= " --abspath --link";
     212        $command .= " --dbname $ds_dbname --dbhost $ds_dbhost";
     213        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     214            run(command => $command, verbose => $verbose);
     215        unless ($success) {
     216            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     217             &my_die("Unable to perform $command error_code: $error_code", $vp_id, $error_code);
     218        }
     219    }
     220}
     221
     222unless ($no_update) {
     223    my $command = "$vptool -updaterun -vp_id $vp_id -set_state full";
     224    $command .= " -set_outroot $outroot";
     225    $command .= " -set_hostname $host";
     226    $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400);
     227
     228    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     229        run(command => $command, verbose => $verbose);
     230    unless ($success) {
     231        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     232        my $err_message = "Unable to perform vptool -updaterun";
     233        &my_die("$err_message: $error_code", $vp_id, $error_code);
    143234    }
    144235}
     
    149240{
    150241    my $msg = shift;            # Warning message on die
    151     my $vp_id = shift;
    152     my $class_id = shift;       # chip identifier
    153     my $cell_id = shift;       # chip identifier
     242    my $vp_id = shift;          # vpRun id
    154243    my $exit_code = shift;      # Exit code to add
    155244
     
    157246
    158247    warn($msg);
    159     if (defined $vp_id and defined $class_id and not $no_update) {
    160         my $command = "$vptool -vp_id $vp_id -class_id $class_id -cell_id -fault $exit_code";
    161         $command .= " -addvpcell";
    162         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    163         $command .= " -hostname $host" if defined $host;
    164         $command .= " -path_base $outroot" if defined $outroot;
    165         $command .= " -dbname $dbname" if defined $dbname;
     248    if (defined $vp_id and not $no_update) {
     249        my $command = "$vptool -vp_id $vp_id";
     250        $command .= " -updaterun";
     251        $command .= " -set_fault $exit_code";
     252        $command .= " -set_hostname $host" if defined $host;
     253        $command .= " -set_outroot $outroot" if defined $outroot;
     254        $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400);
     255
    166256        run(command => $command, verbose => $verbose);
    167257    }
     
    169259}
    170260
    171 END {
    172     my $exit = $?;
    173     system("sync") == 0 or die "failed to execute sync: $!";
    174     $? = $exit;
    175 }
    176 
    177261__END__
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/warp_overlap.pl

    r27718 r32630  
    5757
    5858my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $warp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    59 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $warp_id, $PS_EXIT_SYS_ERROR ) if $logfile;
     59$ipprc->redirect_to_logfile($logfile) or my_die( "Unable to redirect output", $warp_id, $PS_EXIT_SYS_ERROR ) if $logfile;
    6060
    6161&my_die("Tessellation identifier not provided: $tess_dir", $warp_id, $PS_EXIT_SYS_ERROR) unless $tess_dir ne "NULL";
  • branches/eam_branches/ipp-20110906/ippScripts/scripts/warp_skycell.pl

    r31941 r32630  
    3838
    3939my ($warp_id, $skycell_id, $warp_skyfile_id, $tess_dir, $reduction, $camera, $dbname, $outroot, $threads, $run_state, $magicked, $verbose, $no_update, $no_op, $redirect, $save_temps);
    40 my $zaplog = 0;
    4140
    4241GetOptions(
     
    5554    'no-update'           => \$no_update, # Don't update the database?
    5655    'no-op'               => \$no_op, # Don't do any operations?
    57     'zaplog'              => \$zaplog, # delete previous logfile
    5856    'redirect-output'     => \$redirect,
    5957    'save-temps'          => \$save_temps, # Save temporary files?
     
    7775my $do_stats;
    7876if ($run_state eq 'new') {
    79     $logDest = prepare_output("LOG.EXP", $outroot, $skycell_id, $zaplog);
     77    $logDest = $ipprc->filename("LOG.EXP", $outroot, $skycell_id);
    8078    $traceDest = prepare_output("TRACE.EXP", $outroot, $skycell_id, 1);
    8179    $do_stats = 1;
    8280} elsif ($run_state eq 'update')  {
    83     $logDest = prepare_output("LOG.EXP.UPDATE", $outroot, $skycell_id, 1);
     81    $logDest = $ipprc->filename("LOG.EXP.UPDATE", $outroot, $skycell_id);
    8482    $traceDest = prepare_output("TRACE.EXP.UPDATE", $outroot, $skycell_id, 1);
    8583} else {
     
    9391}
    9492
    95 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR ) if $redirect;
     93$ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR ) if $redirect;
    9694
    9795# Recipes to use based on reduction class
     
    333331            }
    334332        }
    335 
     333        print "Quality: $quality\n";
    336334        unless ($no_update) {
    337335            # XXX change -tess_id to -tess_dir when db is updated
     
    358356        }
    359357    } else {
     358
     359        my $quality = 0;
     360
     361        unless ($ipprc->file_exists($outputPSF)) {
     362            $quality = 8006; # bad data.
     363        }
     364#         if (!$quality) {
     365#             check_output($outputImage, 0);
     366#             check_output($outputMask, 0);
     367#             check_output($outputWeight, 0);
     368#             check_output($outputSources, 1);
     369#             check_output($outputPSF, 1) if metadataLookupBool($recipe, 'PSF')  ;
     370#         }
     371        print "Quality: $quality\n";
     372
    360373        # $run_state eq 'update'
    361374        unless ($no_update) {
     
    364377            $command .= " -skycell_id $skycell_id";
    365378            $command .= " -set_magicked $magicked" if $magicked;
     379            $command .= " -set_quality $quality" if $quality;
    366380            $command .= " -dbname $dbname"   if defined $dbname;
    367381
     
    407421
    408422    &my_die("Couldn't find expected output file: $file",  $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
     423
     424    # Funpack to confirm we've really made things correctly
     425    my $diskfile = $ipprc->file_resolve($file);
     426    if ($diskfile =~ /fits/) {
     427        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
     428        my $check_command = "$funpack -S $diskfile > /dev/null";
     429        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     430            run(command => $check_command, verbose => $verbose);
     431        if (!$success) {
     432            &my_die("Output file not a valid fits file: $file", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
     433        }
     434    }
     435    #####
    409436
    410437    if ($replicate and $neb) {
Note: See TracChangeset for help on using the changeset viewer.