IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31417


Ignore:
Timestamp:
Apr 29, 2011, 6:42:12 PM (15 years ago)
Author:
watersc1
Message:

Updates to lap code. laptool should be complete, lap.pro should function, and I'm still debugging lap_science.pl

Location:
branches/czw_branch/20110406
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20110406/ippScripts/scripts/lap_science.pl

    r31396 r31417  
    66use Carp;
    77use IPC::Cmd 0.36 qw( can_run run);
    8 use PS::IPP:Metadata::List qw( parse_md_list );
     8use PS::IPP::Metadata::List qw( parse_md_list );
    99use PS::IPP::Config 1.01 qw( :standard );
    1010use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    2525my $laptool  = can_run('laptool') or (warn "Can't find laptool" and $missing_tools = 1);
    2626
    27 my ( $camera, $dbname, $logfile, $verbose, $debug);
    28 my ( $proj_cell, $filter);
    29 my ( $chip_mode, $diff_mode, $stack_mode, $qstack_mode, $magic_mode, $clean_mode);
    30 
    31 
    32 
     27my ( $help, $verbose, $debug);
     28my ( $camera, $dbname);
     29my ( $lap_id );
     30my ( $chip_mode, $monitor_mode, $cleanup_mode);
     31
     32GetOptions(
     33    'help|h'       => \$help,
     34    'verbose'      => \$verbose,
     35    'debug'        => \$debug,
     36
     37    'camera=s'     => \$camera,
     38    'dbname=s'     => \$dbname,
     39   
     40    'lap_id=s'     => \$lap_id,
     41
     42    'chip_mode'    => \$chip_mode,
     43    'monitor_mode' => \$monitor_mode,
     44    'cleanup_mode' => \$cleanup_mode,
     45    ) or pod2usage ( 2 );
     46pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     47pod2usage(
     48    -msg => "Choose a mode: --chip_mode --monitor_mode --cleanup_mode",
     49    -exitval => 3,
     50    ) unless
     51    defined $chip_mode or defined $monitor_mode or defined $cleanup_mode;
     52pod2usage(
     53    -msg => "--lap_id is required",
     54    -exitval => 3,
     55    ) unless
     56    defined $lap_id;
     57
     58unless (defined $dbname) {
     59    $dbname = 'gpc1';
     60}
     61
     62my $mdcParser = PS::IPP::Metadata::Config->new;
     63
     64# Fetch all the information about this run
     65my %lapRunInfo = get_lapRun_info($lap_id);
     66
     67# Run the appropriate mode
     68
     69if (defined($chip_mode)) {
     70    unless ($lapRunInfo{state} eq 'new') {
     71        &my_die("Cannot run chip_mode if lapRun.state != new!",$lap_id);
     72    }
     73    my $status = chip_mode($lap_id);
     74    exit $status;
     75}
     76if (defined($monitor_mode)) {
     77    unless ($lapRunInfo{state} eq 'run') {
     78        &my_die("Cannot run monitor_mode if lapRun != run!", $lap_id);
     79    }
     80    my $status = monitor_mode($lap_id);
     81    exit $status;
     82}
     83if (defined($cleanup_mode)) {
     84    unless (($lapRunInfo{state} eq 'done')||
     85            ($lapRunInfo{state} eq 'drop')) {
     86        &my_die("Cannot run cleanup_mode if lapRun != done!", $lap_id);
     87    }
     88    my $status = cleanup_mode($lap_id);
     89    exit $status;
     90}
    3391
    3492#
    3593# Chip
    3694################################################################################
    37 # This queues a chipRun for this exposure, and records the chip_id in the exposure structure and in the database
     95
     96sub chip_mode {
     97    my $lap_id = shift;
     98    return(queue_chips($lap_id));
     99}
     100
     101# This creates the chiptool command to use for the specified parameters.
    38102sub construct_chiptool_command {
    39103    my $lap_id = shift;
     
    45109    my $exp_id = shift;
    46110
    47     my $cmd = "$chiptool ";
     111    my $cmd = "$chiptool -pretend";
     112    $cmd .= " -pretend " if defined $debug;
    48113    $cmd .= " -dbname $dbname " if defined $dbname;
    49114
     
    53118    return($cmd);
    54119}
     120
     121# retrieve the chip_id for the exposure inserted
    55122sub get_chip_id_from_metadata {
    56123    my $exp_id = shift;
     
    72139    # There should be only one.
    73140    my $chip = ${ $chips }[0];
    74     my $chip_id = $chip->{chip_id};
     141    my $chip_id = 0;
     142    if ($chip) {
     143        $chip_id = $chip->{chip_id};
     144    }
    75145   
    76146    return($chip_id);
    77147}
     148
     149sub get_lapRun_info {
     150    my $lap_id = shift;
     151    my $command = "$laptool -pendingrun -lap_id $lap_id";
     152    $command .= " -dbname $dbname " if defined $dbname;
     153    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     154        run(command => $command, verbose => $verbose);
     155    unless ($success) {
     156        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     157        &my_die("Unable to perform laptool: $error_code", $lap_id);
     158    }
     159    my $Runs = $mdcParser->parse_list(join "", @$stdout_buf) or
     160        &my_die("Unable to parse metadata from laptool", $lap_id);
     161    # There should be only one.
     162    my $Run = ${ $Runs }[0];
     163    my %info = %{ $Run };
     164    return(%info);
     165}
     166
     167
     168# Queue a chipRun for this exposure with the appropriate parameters.
    78169sub remake_this_exposure {
    79170    my $exposure = shift;
     
    82173    $utctime[5] += 1900;
    83174    $utctime[4] += 1;
     175
     176    my $label = $exposure->{label};
     177
    84178    my $date = sprintf("%4d%02d%02d",$utctime[5],$utctime[4],$utctime[3]);
    85179    my $workdir_date = sprintf("%4d/%02d/%02d",$utctime[5],$utctime[4],$utctime[3]);
     
    92186                                              $exposure->{exp_id});
    93187    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    94         run(command => $command, verbose => $verbose);
     188        run(command => $chip_cmd, verbose => $verbose);
    95189    unless ($success) {
    96190        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    98192    }
    99193   
    100     $exposure->{chip_id} = get_chip_id_from_metadata($exposure->{exp_id},$exposure->{label},$data_group); #join "", @$stdout_buf);
     194    $exposure->{chip_id} = get_chip_id_from_metadata($exposure->{exp_id},$exposure->{label},$data_group);
    101195    $exposure->{data_state} = 'new';
    102196    update_this_exposure($exposure);
     
    106200# This is the "user level" subroutine.
    107201sub queue_chips {
    108     my $proj_cell = shift;
    109 
    110     my $lap_id = get_lap_id($proj_cell);
     202    my $lap_id = shift;
    111203   
    112204    my $command = "$laptool -pendingexp -lap_id $lap_id";
     
    116208    unless ($success) {
    117209        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    118         &my_die("Unable to perform laptool: $error_code", $re_id, $proj_cell);
    119     }
    120    
    121     if ($@stdout_buf == 0) {
     210        &my_die("Unable to perform laptool: $error_code", $lap_id);
     211    }
     212   
     213    if (@$stdout_buf == 0) {
    122214        # Nothing to do.
    123215        return(0);
    124216    }
    125217   
    126     $exposures = $mdcParser->parse_list(join "", @$stdout_buf) or
    127         &my_die("Unable to parse metadata from laptool", $re_id, $proj_cell);
    128 
    129     # Preliminary scan of exposures to set up diff structures.
     218    my $exposures = $mdcParser->parse_list(join "", @$stdout_buf) or
     219        &my_die("Unable to parse metadata from laptool", $lap_id);
     220
    130221    my $counter = 0;
    131222    my %matching = ();
    132223    my %indexing = ();
    133     foreach my $exposure (@$exposures) {
    134         my $lap_id = $exposure->{lap_id};
     224    # Determine which exposures need a chipRun queued.
     225    foreach my $exposure (@$exposures) { 
     226        # $lap_id = $exposure->{lap_id};  # This should be already known.
    135227        my $tess_id = $exposure->{tess_id};
    136228        my $exp_id = $exposure->{exp_id};
     
    145237        my $comment = $exposure->{comment};
    146238
    147         if ($chip_id) { # We already have a defined chip_id
     239        if (S64_IS_NOT_NULL($chip_id)) { # We already have a defined chip_id
    148240            if (($pairwise) && !($pair_id)) {
    149241                # This is an error.
    150                 &my_die("Exposure $exp_id for $lap_id is declared pairwise without a defined pair", $lap_id, $proj_cell);
     242                &my_die("Exposure $exp_id for $lap_id is declared pairwise without a defined pair", $lap_id);
    151243            }
     244            $counter++;
     245            next;
     246        }
     247        else { # We do not already have a chip_id. 
     248            # Make a chipRun, and update the exposure.
     249            $exposure = remake_this_exposure($exposure);
     250           
     251            # Save our information for diff pairing.
     252            $matching{$object}{$comment} = $exp_id;
     253            $indexing{$exp_id} = $counter;
    152254            $counter++;
    153             next;
    154         }
    155 
    156         $exposure = remake_this_exposure($exposure);
    157 #       my $chip_cmd = construct_chiptool_command($lap_id,$proj_cell,$exp_id);
    158 #       my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    159 #           run(command => $command, verbose => $verbose);
    160 #       unless ($success) {
    161 #           $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    162 #           &my_die("Unable to perform chiptool: $error_code", $lap_id, $proj_cell);
    163 #       }
    164 
    165 #       $exposure->{chip_id} = get_chip_id_from_metadata(join "", @$stdout_buf);
    166 
    167         # We will need to define a chipRun for this exposure.  However, let's do diff matching before we do so.
    168        
    169         $matching{$object}{$comment} = $exp_id;
    170         $indexing{$exp_id} = $counter;
    171         $counter++;
    172     }
    173    
    174 #    Pair up exposures to diff.
    175     foreach my $object (keys %matching) {
     255        }
     256    }
     257
     258    # Determine which exposures have a pair for diffing.
     259    foreach my $object (keys %matching) {
    176260        my @exp_ids_to_diff = ();
    177261        foreach my $comment (keys %{ $matching{$object} }) {
     
    184268        }
    185269
    186         while ($#{ $exp_ids_to_diff } > -1) {  # Save the pair information to the opposite exposure.
     270        while ($#exp_ids_to_diff > -1) {  # Save the pair information to the opposite exposure.
    187271            my $exp_id_A = shift(@exp_ids_to_diff);
    188272            my $exp_id_B = shift(@exp_ids_to_diff);
     
    198282        }
    199283    }
    200        
    201 #    Queue chipRuns and update lapExp table.
    202     foreach my $exposure (@$exposures) {
     284
     285    # Scan all exposures, and ensure that pairwise and private are set correctly
     286    foreach my $exposure (@$exposures) { 
    203287        if ($exposure->{pairwise} && !($exposure->{pair_id})) {
    204288            $exposure->{pairwise} = 0; # We marked it for pairwise diffs, but didn't match it. Probably an error.
     
    208292        }
    209293
    210         update_this_exposure($exposure);
    211 #       my $lapE_cmd = construct_laptool_updateExp_command($lap_id,
    212 #                                                          $exposure->{exp_id},
    213 #                                                          $exposure->{chip_id},
    214 #                                                          $exposure->{private},
    215 #                                                          $exposure->{pairwise},
    216 #                                                          $exposure->{pair_id});
    217 #       my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    218 #           run(command => $command, verbose => $verbose);
    219 #       unless ($success) {
    220 #           $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    221 #           &my_die_with_fault("Unable to perform chiptool: $error_code", $lap_id, $proj_cell);
    222 #       }
     294        $exposure = update_this_exposure($exposure);
    223295    }
    224296}
     
    245317
    246318    ($defined_qstack,$have_qstack,$defined_fstack,$have_fstack) = (0,0,0,0);
    247     if ($@stdout_buf == 0) {
     319    if (@$stdout_buf == 0) {
    248320        # Nothing to do.  Possibly an error, but for now, just accept it
    249321        return($defined_qstack,$have_qstack,$defined_fstack,$have_fstack);
    250322    }
    251323
    252     $stacks = $mdcParser->parse_list(join "", @$stdout_buf) or
     324    my $stacks = $mdcParser->parse_list(join "", @$stdout_buf) or
    253325        &my_die("Unable to parse metadata from laptool", $lap_id, "");
    254326
     
    263335        }
    264336        if ($stack->{final_stack_id}) {
    265             $defiend_fstack = 1;
     337            $defined_fstack = 1;
    266338            $total_fstacks++;
    267339        }
     
    296368    unless ($success) {
    297369        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    298         &my_die("Unable to perform laptool: $error_code", $re_id, $proj_cell);
    299     }
    300    
    301     if ($@stdout_buf == 0) {
     370        &my_die("Unable to perform laptool: $error_code", $lap_id, $proj_cell);
     371    }
     372   
     373    if (@$stdout_buf == 0) {
    302374        # Nothing to do. However, this is likely an error.
    303375        return(0);
    304376    }
    305377   
    306     $exposures = $mdcParser->parse_list(join "", @$stdout_buf) or
    307         &my_die("Unable to parse metadata from laptool", $re_id, $proj_cell);
     378    my $exposures = $mdcParser->parse_list(join "", @$stdout_buf) or
     379        &my_die("Unable to parse metadata from laptool", $lap_id, $proj_cell);
    308380
    309381    # Need to prescan to see who matches whom.
    310     %match_hash = ();
     382    my %match_hash = ();
    311383    my $index = 0;
    312384    foreach my $exposure (@$exposures) {
     
    392464        unless ($success) {
    393465            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    394             &my_die("Unable to perform laptool: $error_code", $re_id, $proj_cell);
     466            &my_die("Unable to perform laptool: $error_code", $lap_id, $proj_cell);
    395467        }
    396468    }
     
    421493    unless ($success) {
    422494        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    423         &my_die("Unable to perform chiptool: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
     495        &my_die("Unable to perform chiptool: $error_code", $lap_id);
    424496    }
    425497   
     
    433505    $command .= " -dbname $dbname " if defined $dbname;
    434506
    435     my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    436         run(command => $command, verbose => $verbose);
    437     unless ($success) {
    438         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    439         &my_die("Unable to perform chiptool: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
     507    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     508        run(command => $command, verbose => $verbose);
     509    unless ($success) {
     510        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     511        &my_die("Unable to perform chiptool: $error_code", $lap_id);
    440512    }
    441513   
     
    466538    unless ($success) {
    467539        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    468         &my_die("Unable to perform chiptool: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
     540        &my_die("Unable to perform chiptool: $error_code", $lap_id);
    469541    }
    470542   
     
    478550    $command .= " -dbname $dbname " if defined $dbname;
    479551
    480     my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    481         run(command => $command, verbose => $verbose);
    482     unless ($success) {
    483         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    484         &my_die("Unable to perform chiptool: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
     552    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     553        run(command => $command, verbose => $verbose);
     554    unless ($success) {
     555        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     556        &my_die("Unable to perform chiptool: $error_code", $lap_id);
    485557    }
    486558
     
    490562   
    491563    # Need to prescan to see who matches whom.
    492     %match_hash = ();
     564    my %match_hash = ();
    493565    my $index = 0;
    494566    foreach my $exposure (@$exposures) {
     
    508580        }
    509581
    510         my $command = "$difftoool ";
    511         my $command .= " -dbname $dbname " if defined $dbname;
    512         my $command .= " -set_label $label -set_workdir $workdir -set_data_group $data_group ";
    513         my $command .= " -set_dist_group $dist_group ";
     582        my @utctime = gmtime();
     583        $utctime[5] += 1900;
     584        $utctime[4] += 1;
     585
     586        my $label = $exposure->{label};
     587        my $dist_group = $exposure->{dist_group};
     588        my $date = sprintf("%4d%02d%02d",$utctime[5],$utctime[4],$utctime[3]);
     589        my $workdir_date = sprintf("%4d/%02d/%02d",$utctime[5],$utctime[4],$utctime[3]);
     590        my $workdir = "neb://\@HOST\@.0/${dbname}/${label}/${workdir_date}";
     591        my $data_group = "${label}.${date}";
     592
     593        my $command = "$difftool ";
     594        $command .= " -dbname $dbname " if defined $dbname;
     595        $command .= " -set_label $label -set_workdir $workdir -set_data_group $data_group ";
     596        $command .= " -set_dist_group $dist_group ";
    514597       
    515598        if ($exposure->{pairwise}) { # warpwarp
    516             $companion = ${ $exposures }[$match_hash{$exposure->{chip_id}}];
     599            my $companion = ${ $exposures }[$match_hash{$exposure->{chip_id}}];
    517600            $command .= " -definewarpwarp ";
    518601            $command .= "-input_label $label -template_label $label -backwards ";
     
    539622    foreach my $exposure (@$exposures) {
    540623        $exposure->{active} = 0;
    541         $exposure = update_this_exposure($exposure);
     624        update_this_exposure($exposure);
     625    }
     626}
     627
     628
     629#
     630# Cleanup
     631################################################################################
     632
     633# sub cleanup_exposures {
     634#     my $command = "$laptool -inactive ";
     635#     $command .= " -dbname $dbname " if defined $dbname;
     636
     637#     my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     638#       run(command => $command, verbose => $verbose);
     639#     unless ($success) {
     640#       $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     641#       &my_die("Unable to perform laptool: $error_code", "none", "none");
     642#     }
     643#     if (@$stdout_buf == 0) {
     644#       # Nothing to do.
     645#       return(0);
     646#     }
     647   
     648#     my $exposures = $mdcParser->parse_list(join "", @$stdout_buf) or
     649#       &my_die("Unable to parse metadata from laptool", $lap_id);
     650
     651#     foreach my $exposure (@$exposures) {
     652#       foreach my $clean_mode (@clean_modes) {
     653#           $command = $clean_mode->{COMMAND};
     654#           $clean_id = $clean_mode->{CLEAN_ID};
     655#           $clean_state = $clean_mode->{CLEAN_STATE};
     656#           if (($exposure->{$clean_id} != 0)&&
     657#               (($exposure->{$clean_state} eq 'full')||
     658#                ($exposure->{$clean_state} eq 'drop'))) {
     659
     660#               $command =~ s/\@DBNAME\@/$dbname/g;
     661#               $command =~ s/\@CHIP_ID\@/$exposure->{chip_id}/;
     662#               $command =~ s/\@CHIP_STATE\@/$exposure->{chip_state}/;
     663#               $command =~ s/\@CHIP_LABEL\@/$exposure->{chip_label}/;
     664               
     665#               $command =~ s/\@WARP_ID\@/$exposure->{chip_id}/;
     666#               $command =~ s/\@WARP_STATE\@/$exposure->{chip_state}/;
     667#               $command =~ s/\@WARP_LABEL\@/$exposure->{chip_label}/;
     668               
     669#               $command =~ s/\@DIFF_ID\@/$exposure->{diff_id}/;
     670#               $command =~ s/\@DIFF_STATE\@/$exposure->{diff_state}/;
     671#               $command =~ s/\@DIFF_LABEL\@/$exposure->{diff_label}/;
     672               
     673#               $command =~ s/\@MAGICDS_ID\@/$exposure->{magicDS_id}/;
     674#               $command =~ s/\@MAGICDS_STATE\@/$exposure->{magicDS_state}/;
     675#               $command =~ s/\@MAGICDS_LABEL\@/$exposure->{magicDS_label}/;
     676               
     677#               ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     678#                   run(command => $command, verbose => $verbose);
     679#               unless ($success) {
     680#                   $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     681#                   &my_die("Unable to perform laptool: $error_code", "none", "none");
     682#               }
     683#           }
     684#       }
     685#       $exposure->{data_state} = 'cleaned';
     686#       update_this_exposure($exposure);
     687#     }
     688# }
     689   
     690           
     691
     692
     693#
     694# Utilities
     695################################################################################
     696
     697sub my_die {
     698    my $msg = shift; # Warning message on die
     699    my $lap_id = shift; # identifier
     700    my $optional = shift;
     701    my $exit_code = shift;
     702    unless (defined $exit_code) {
     703        $exit_code = $PS_EXIT_PROG_ERROR;
     704    }
     705    carp($msg);
     706    exit $exit_code;
     707}
     708
     709# Check to see if a 64bit integer is NULL or not.  This is probably fragile, but I don't know how to get a S64 NULL out.
     710sub S64_IS_NOT_NULL {
     711    if ($_[0] == 9223372036854775807) {
     712        return(0);
     713    }
     714    else {
     715        return(1);
    542716    }
    543717}
     
    587761        &my_die("Unable to perform laptool: $error_code", $exposure->{lap_id}, $exposure->{proj_cell});
    588762    }
    589    
    590 }
    591 
    592 #
    593 # Cleanup
    594 ################################################################################
    595 
    596 sub cleanup_exposures {
    597     my $command = "$laptool -inactive ";
    598     $command .= " -dbname $dbname " if defined $dbname;
    599 
    600     my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    601         run(command => $command, verbose => $verbose);
    602     unless ($success) {
    603         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    604         &my_die("Unable to perform laptool: $error_code", "none", "none");
    605     }
    606     if ($@stdout_buf == 0) {
    607         # Nothing to do.
    608         return(0);
    609     }
    610 
    611     foreach my $exposure (@$exposures) {
    612         foreach my $clean_mode (@clean_modes) {
    613             $command = $clean_mode->{COMMAND};
    614             $clean_id = $clean_mode->{CLEAN_ID};
    615             $clean_state = $clean_mode->{CLEAN_STATE};
    616             if (($exposure->{$clean_id} != 0)&&
    617                 (($exposure->{$clean_state} eq 'full')||
    618                  ($exposure->{$clean_state} eq 'drop'))) {
    619 
    620                 $command =~ s/@DBNAME@/$dbname/g;
    621                 $command =~ s/@CHIP_ID@/$exposure->{chip_id}/;
    622                 $command =~ s/@CHIP_STATE@/$exposure->{chip_state}/;
    623                 $command =~ s/@CHIP_LABEL@/$exposure->{chip_label}/;
    624                
    625                 $command =~ s/@WARP_ID@/$exposure->{chip_id}/;
    626                 $command =~ s/@WARP_STATE@/$exposure->{chip_state}/;
    627                 $command =~ s/@WARP_LABEL@/$exposure->{chip_label}/;
    628                
    629                 $command =~ s/@DIFF_ID@/$exposure->{diff_id}/;
    630                 $command =~ s/@DIFF_STATE@/$exposure->{diff_state}/;
    631                 $command =~ s/@DIFF_LABEL@/$exposure->{diff_label}/;
    632                
    633                 $command =~ s/@MAGICDS_ID@/$exposure->{magicDS_id}/;
    634                 $command =~ s/@MAGICDS_STATE@/$exposure->{magicDS_state}/;
    635                 $command =~ s/@MAGICDS_LABEL@/$exposure->{magicDS_label}/;
    636                
    637                 ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    638                     run(command => $command, verbose => $verbose);
    639                 unless ($success) {
    640                     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    641                     &my_die("Unable to perform laptool: $error_code", "none", "none");
    642                 }
    643             }
    644         }
    645         $exposure->{data_state} = 'cleaned';
    646         update_this_exposure($exposure);
    647     }
    648 }
    649    
    650            
    651 
    652 
    653 #
    654 # Utilities
    655 ################################################################################
    656 
     763}   
     764
  • branches/czw_branch/20110406/ippTasks/lap.pro

    r31385 r31417  
    1 ## reprocessing.pro : -*- sh -*-
     1## lap.pro : -*- sh -*-
    22
    33check.globals
    44
    5 macro reprocessing.on
    6   re.chip.on
    7   re.diff.on
    8   re.stack.on
    9   re.magic.on
    10   re.clean.on
    11 end
    12 
    13 macro reprocessing.off
    14   re.chip.off
    15   re.diff.off
    16   re.stack.off
    17   re.magic.off
    18   re.clean.off
    19 end
    20 
    21 macro re.on
    22   reprocessing.on
    23 end
    24 
    25 macro re.off
    26   reprocessing.off
    27 end
    28 
    29 macro re.chip.on
    30   task re.chip.load
    31     active true
    32   end
    33 end
    34 
    35 macro re.diff.on
    36   task re.diff.load
    37     active true
    38   end
    39 end
    40 
    41 macro re.stack.on
    42   task re.stack.load
    43     active true
    44   end
    45 end
    46 
    47 macro re.magic.on
    48   task re.magic.load
    49     active true
    50   end
    51 end
    52 
    53 macro re.clean.on
    54   task re.clean.load
    55     active true
    56   end
    57 end
    58 
    59 macro re.chip.off
    60   task re.chip.load
    61     active false
    62   end
    63 end
    64 
    65 macro re.diff.off
    66   task re.diff.load
    67     active false
    68   end
    69 end
    70 
    71 macro re.stack.off
    72   task re.stack.load
    73     active false
    74   end
    75 end
    76 
    77 macro re.magic.off
    78   task re.magic.load
    79     active false
    80   end
    81 end
    82 
    83 macro re.clean.off
    84   task re.clean.load
    85     active false
    86   end
    87 end
    88 
    89 book init reData
    90 
    91 task           re.chip.load
     5$lapSeq:n = 0
     6
     7book init lapRuns
     8
     9macro lap.add.sequence
     10  if ($0 != 2)
     11    echo "USAGE: lap.add.sequence (seq_id)"
     12    break
     13  end
     14  if ($?lapSeq:n == 0)
     15    list lapSeq -add $1
     16    return
     17  end
     18
     19  local found
     20  $found = 0
     21  for i 0 $lapSeq:n
     22    if ($lapSeq:$i == $1)
     23      $found = 1
     24      echo "$lapSeq:$i set"
     25      last
     26    end
     27  end
     28
     29  if ($found == 0)
     30    list lapSeq -add $1
     31  end
     32end
     33
     34macro lap.del.sequence
     35  if ($0 != 2)
     36    echo "USAGE: lap.del.sequence (seq_id)"
     37    break
     38  end
     39  if ($?lapSeq:n == 0)
     40    return
     41  end
     42
     43  list lapSeq -del $1
     44end
     45 
     46
     47task           lap.initial.load
    9248  host         local
    9349  periods      -poll $LOADPOLL
     
    9854  task.exec
    9955    stdout NULL
    100     stderr $LOGDEIR/re.chip.log
    101 
    102     $run = echo no command yet
    103     command $run
    104   end
    105   # success
    106   task.exit  0
    107     book delpage reData $options:0
    108     ipptool2book stdout reData -uniq -key proj
    109 
    110     if ($VERBOSE > 2)
    111       book listbook reData
    112     end
    113   end
    114   # locked list
    115   task.exit    default
    116     showcommand failure
    117   end
    118   task.exit    crash
    119     showcommand crash
    120   end
    121   #operation times out?
    122   task.exit    timeout
    123     showcommand timeout
    124   end
    125 end
    126 
    127 
    128 task           re.diff.load
     56    stderr $LOGDIR/lap.load.log
     57
     58    $run = laptool -pendingrun -state new
     59
     60    if ($lapSeq:n == 0)
     61      break
     62    else
     63      option $lapSeq:$lap_N
     64      $run = $run -seq_id $lapSeq:$lap_N
     65      $lap_N ++
     66      if ($lap_N >= $lapSeq:n) set lap_N = 0
     67    end
     68
     69    if ($DB:n == 0)
     70      option DEFAULT
     71    else
     72      option $DB:$lap_DB
     73      $run = $run -dbname $DB:$lap_DB
     74      $lap_DB ++
     75      if ($lap_DB >= $DB:n) set lap_DB = 0
     76    end
     77
     78    command $run
     79  end
     80  # success
     81  task.exit  0
     82    book delpage lapNewRuns $options:0
     83    ipptool2book stdout lapNewRuns -uniq -key proj
     84
     85    if ($VERBOSE > 2)
     86      book listbook lapNewRuns
     87    end
     88  end
     89  # locked list
     90  task.exit    default
     91    showcommand failure
     92  end
     93  task.exit    crash
     94    showcommand crash
     95  end
     96  #operation times out?
     97  task.exit    timeout
     98    showcommand timeout
     99  end
     100end
     101
     102task           lap.initial.run
     103  host         local
     104  periods      -poll $LOADPOLL
     105  periods      -exec $LOADEXEC
     106  periods      -timeout 600
     107# This can probably be increased and spread over hosts in the future.
     108  npending     1           
     109
     110  task.exec
     111    stdout NULL
     112    stderr $LOGDIR/lap.initial.log
     113
     114    book npages lapNewRuns -var N
     115    if ($N == 0) break
     116    if ($NETWORK == 0) break
     117
     118
     119    book getpage lapNewRuns 0 -var pageName -key pantaskState INIT
     120    if ("$pageName" == "NULL") break
     121
     122    book setword lapNewRuns $pageName pantaskState RUN
     123    book getword lapNewRuns $pageName lap_id -var LAP_ID
     124    book getword lapNewRuns $pageName dbname -var DBNAME
     125
     126    $run = lap_science.pl --chip_mode --dbname $DBNAME --lap_id $LAP_ID
     127
     128    command $run
     129
     130  end
     131
     132  # success
     133  task.exit  0
     134    book delpage lapNewRuns $options:0
     135    ipptool2book stdout lapNewRuns -uniq -key proj
     136
     137    if ($VERBOSE > 2)
     138      book listbook lapNewRuns
     139    end
     140  end
     141  # locked list
     142  task.exit    default
     143    showcommand failure
     144  end
     145  task.exit    crash
     146    showcommand crash
     147  end
     148  #operation times out?
     149  task.exit    timeout
     150    showcommand timeout
     151  end
     152end
     153
     154
     155
     156task           lap.monitor.load
    129157  host         local
    130158  periods      -poll $LOADPOLL
     
    135163  task.exec
    136164    stdout NULL
    137     stderr $LOGDEIR/re.diff.log
    138 
    139     $run = echo no command yet
    140     command $run
    141   end
    142   # success
    143   task.exit  0
    144     book delpage reData $options:0
    145     ipptool2book stdout reData -uniq -key proj
    146 
    147     if ($VERBOSE > 2)
    148       book listbook reData
    149     end
    150   end
    151   # locked list
    152   task.exit    default
    153     showcommand failure
    154   end
    155   task.exit    crash
    156     showcommand crash
    157   end
    158   #operation times out?
    159   task.exit    timeout
    160     showcommand timeout
    161   end
    162 end
    163 
    164 task           re.magic.load
     165    stderr $LOGDIR/lap.load.log
     166
     167    $run = laptool -pendingrun -state run
     168
     169    if ($lapSeq:n != 0)
     170      option $lapSeq:$lap_N
     171      $run = $run -seq_id $lapSeq:$lap_N
     172      $lap_N ++
     173      if ($lap_N >= $lapSeq:n) set lap_N = 0
     174    end
     175
     176    if ($DB:n == 0)
     177      option DEFAULT
     178    else
     179      option $DB:$lap_DB
     180      $run = $run -dbname $DB:$lap_DB
     181      $lap_DB ++
     182      if ($lap_DB >= $DB:n) set lap_DB = 0
     183    end
     184
     185    add_poll_labels run
     186
     187    command $run
     188  end
     189  # success
     190  task.exit  0
     191    book delpage lapRuRuns $options:0
     192    ipptool2book stdout lapRunRuns -uniq -key lap_id
     193
     194    if ($VERBOSE > 2)
     195      book listbook lapRunRuns
     196    end
     197  end
     198  # locked list
     199  task.exit    default
     200    showcommand failure
     201  end
     202  task.exit    crash
     203    showcommand crash
     204  end
     205  #operation times out?
     206  task.exit    timeout
     207    showcommand timeout
     208  end
     209end
     210
     211task           lap.monitor.run
     212  host         local
     213  periods      -poll $LOADPOLL
     214  periods      -exec $LOADEXEC
     215  periods      -timeout 600
     216# This can probably be increased and spread over hosts in the future.
     217  npending     1           
     218
     219  task.exec
     220    stdout NULL
     221    stderr $LOGDIR/lap.initial.log
     222
     223    book npages lapRunRuns -var N
     224    if ($N == 0) break
     225    if ($NETWORK == 0) break
     226
     227
     228    book getpage lapNewRuns 0 -var pageName -key pantaskState INIT
     229    if ("$pageName" == "NULL") break
     230
     231    book setword lapNewRuns $pageName pantaskState RUN
     232    book getword lapNewRuns $pageName lap_id -var LAP_ID
     233    book getword lapNewRuns $pageName dbname -var DBNAME
     234
     235    $run = lap_science.pl --monitor_mode --dbname $DBNAME --lap_id $LAP_ID
     236
     237    command $run
     238
     239  end
     240
     241  # success
     242  task.exit  0
     243    book delpage lapRunRuns $options:0
     244    ipptool2book stdout lapRunRuns -uniq -key proj
     245
     246    if ($VERBOSE > 2)
     247      book listbook lapRunRuns
     248    end
     249  end
     250  # locked list
     251  task.exit    default
     252    showcommand failure
     253  end
     254  task.exit    crash
     255    showcommand crash
     256  end
     257  #operation times out?
     258  task.exit    timeout
     259    showcommand timeout
     260  end
     261end
     262
     263
     264
     265task           lap.cleanup.load
    165266  host         local
    166267  periods      -poll $LOADPOLL
     
    171272  task.exec
    172273    stdout NULL
    173     stderr $LOGDEIR/re.magic.log
    174 
    175     $run = echo no command yet
    176     command $run
    177   end
    178   # success
    179   task.exit  0
    180     book delpage reData $options:0
    181     ipptool2book stdout reData -uniq -key proj
    182 
    183     if ($VERBOSE > 2)
    184       book listbook reData
    185     end
    186   end
    187   # locked list
    188   task.exit    default
    189     showcommand failure
    190   end
    191   task.exit    crash
    192     showcommand crash
    193   end
    194   #operation times out?
    195   task.exit    timeout
    196     showcommand timeout
    197   end
    198 end
    199 
    200 task           re.stack.load
    201   host         local
    202   periods      -poll $LOADPOLL
    203   periods      -exec $LOADEXEC
    204   periods      -timeout 30
    205   npending     1
    206 
    207   task.exec
    208     stdout NULL
    209     stderr $LOGDEIR/re.stack.log
    210 
    211     $run = echo no command yet
    212     command $run
    213   end
    214   # success
    215   task.exit  0
    216     book delpage reData $options:0
    217     ipptool2book stdout reData -uniq -key proj
    218 
    219     if ($VERBOSE > 2)
    220       book listbook reData
    221     end
    222   end
    223   # locked list
    224   task.exit    default
    225     showcommand failure
    226   end
    227   task.exit    crash
    228     showcommand crash
    229   end
    230   #operation times out?
    231   task.exit    timeout
    232     showcommand timeout
    233   end
    234 end
    235 
    236 task           re.clean.load
    237   host         local
    238   periods      -poll $LOADPOLL
    239   periods      -exec $LOADEXEC
    240   periods      -timeout 30
    241   npending     1
    242 
    243   task.exec
    244     stdout NULL
    245     stderr $LOGDEIR/re.clean.log
    246 
    247     $run = echo no command yet
    248     command $run
    249   end
    250   # success
    251   task.exit  0
    252     book delpage reData $options:0
    253     ipptool2book stdout reData -uniq -key proj
    254 
    255     if ($VERBOSE > 2)
    256       book listbook reData
    257     end
    258   end
    259   # locked list
    260   task.exit    default
    261     showcommand failure
    262   end
    263   task.exit    crash
    264     showcommand crash
    265   end
    266   #operation times out?
    267   task.exit    timeout
    268     showcommand timeout
    269   end
    270 end
     274    stderr $LOGDIR/lap.load.log
     275
     276    $run = laptool -pendingrun -state done
     277
     278    if ($lapSeq:n != 0)
     279      option $lapSeq:$lap_N
     280      $run = $run -seq_id $lapSeq:$lap_N
     281      $lap_N ++
     282      if ($lap_N >= $lapSeq:n) set lap_N = 0
     283    end
     284
     285    if ($DB:n == 0)
     286      option DEFAULT
     287    else
     288      option $DB:$lap_DB
     289      $run = $run -dbname $DB:$lap_DB
     290      $lap_DB ++
     291      if ($lap_DB >= $DB:n) set lap_DB = 0
     292    end
     293
     294    add_poll_labels run
     295
     296    command $run
     297  end
     298  # success
     299  task.exit  0
     300    book delpage lapDoneRuns $options:0
     301    ipptool2book stdout lapDoneRuns -uniq -key lap_id
     302
     303    if ($VERBOSE > 2)
     304      book listbook lapRuns
     305    end
     306  end
     307  # locked list
     308  task.exit    default
     309    showcommand failure
     310  end
     311  task.exit    crash
     312    showcommand crash
     313  end
     314  #operation times out?
     315  task.exit    timeout
     316    showcommand timeout
     317  end
     318end
     319
     320task           lap.cleanup.run
     321  host         local
     322  periods      -poll $LOADPOLL
     323  periods      -exec $LOADEXEC
     324  periods      -timeout 600
     325# This can probably be increased and spread over hosts in the future.
     326  npending     1           
     327
     328  task.exec
     329    stdout NULL
     330    stderr $LOGDIR/lap.cleanup.log
     331
     332    book npages lapNewRuns -var N
     333    if ($N == 0) break
     334    if ($NETWORK == 0) break
     335
     336
     337    book getpage lapNewRuns 0 -var pageName -key pantaskState INIT
     338    if ("$pageName" == "NULL") break
     339
     340    book setword lapDoneRuns $pageName pantaskState RUN
     341    book getword lapDoneRuns $pageName lap_id -var LAP_ID
     342    book getword lapDoneRuns $pageName dbname -var DBNAME
     343
     344    $run = lap_science.pl --cleanup_mode --dbname $DBNAME --lap_id $LAP_ID
     345
     346    command $run
     347
     348  end
     349
     350  # success
     351  task.exit  0
     352    book delpage lapDoneRuns $options:0
     353    ipptool2book stdout lapDoneRuns -uniq -key proj
     354
     355    if ($VERBOSE > 2)
     356      book listbook lapDoneRuns
     357    end
     358  end
     359  # locked list
     360  task.exit    default
     361    showcommand failure
     362  end
     363  task.exit    crash
     364    showcommand crash
     365  end
     366  #operation times out?
     367  task.exit    timeout
     368    showcommand timeout
     369  end
     370end
  • branches/czw_branch/20110406/ippTools/src/laptool.c

    r31409 r31417  
    740740    return(true);
    741741  }
    742   else {
    743     return(false);
    744   } 
     742/*   else { */
     743/*     return(false); */
     744/*   }   */
     745  return(true);
    745746}
    746747
Note: See TracChangeset for help on using the changeset viewer.