IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 12, 2015, 12:53:36 PM (11 years ago)
Author:
eugene
Message:

merging changes from ipp-pv3-20140717 (via branches/eam_branches/ipp-pv3-20140717-merge)

Location:
trunk/ippScripts/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts

  • trunk/ippScripts/scripts/sc_prepare_camera.pl

    r37125 r37833  
    11#! /usr/bin/env perl
     2
     3# generate the input & output files lists and commands for a single camRun
    24
    35use Carp;
     
    1618use Pod::Usage qw( pod2usage );
    1719
    18 
    1920# Hard coded values
    20 # my $remote_root   = '/scratch3/watersc1/';  # Far side destination base location
    21 my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
    22 $remote_root = '/scratch3/watersc1/';
    23 my $threads       = 2;                      # How many threads are we going to use?
    24 my $job_cost      = 1700 / 60 / 60;         # Estimate of how long a job runs, in hours.
    25 my $proc_per_node = 24;                     # processors per node
    26 my $min_nodes     = 1;                      # smallest allocation to ask for
    27 my $max_nodes     = 1000;                   # largest allocation to ask for
    28 my $min_time      = 1;                      # shortest allocation to ask for
    29 my $max_time      = 8;                      # longest allocation to ask for
    30 my $remote_hostname= "LANL/Mustang";         # Name of the remote node.
    31 my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS");
     21# my $remote_root   = '/lustre/scratch1/turquoise/watersc1/ps1/'; # Far side destination base location
     22my $remote_root     = '/scratch3/watersc1/';  # Far side destination base location
     23my $remote_hostname = "LANL/Mustang";         # Name of the remote node.
     24my $threads_req     = 0;                      # How many threads are we going to use?
     25
     26my $fail_state = "prep_fail";
     27
    3228# Look for programs we need
    3329my $missing_tools;
    34 
    3530my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
    3631my $camtool    = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
     
    4136}
    4237
    43 my ($remote_id,$cam_id,,$camera,$dbname,$verbose,$path_base,$no_update);
     38my ($remote_id,$cam_id,$camera,$dbname,$verbose,$path_base,$no_update);
    4439GetOptions(
    4540    'remote_id=s'    => \$remote_id,
     41    'cam_id=s'       => \$cam_id,
    4642    'camera|c=s'     => \$camera,
    4743    'dbname|d=s'     => \$dbname,
     
    5248
    5349pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    54 pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
     50pod2usage( -msg => "Required options: --remote_id --cam_id --camera --dbname --path_base", -exitval => 3) unless
    5551    defined($remote_id) and
     52    defined($cam_id) and
    5653    defined($camera) and
    5754    defined($path_base) and
    5855    defined($dbname);
    59 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id);
     56
     57my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $cam_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    6058
    6159my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6260
    63 #
    64 # Step 1: Get a list of the components that make up this remoteRun
    65 
    66 # SHould this call listrun to ensure we're in state new?
    67 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
    68 $rt_cmd   .= " -dbname $dbname " if defined($dbname);
    69 
    70 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    71     run(command => $rt_cmd, verbose => $verbose);
    72 unless ($success) {
    73     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    74     &my_die("Unable to run remotetool to determine stage parameters.",
    75             $remote_id,$error_code);
    76 }
    77 my $compData = $mdcParser->parse(join "", @$stdout_buf) or
    78     &my_die("Unable to determine component information.",
    79             $remote_id,$PS_EXIT_PROG_ERROR);
    80 my $compData2= parse_md_list($compData);
    81 
    82 #
    83 # Step 1b: Open output files
    84 my $uri_command = $path_base . ".cmd";
     61my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS");
     62
     63# STEP 0: Open output files
    8564my $uri_transfer= $path_base . ".transfer";
    8665my $uri_check   = $path_base . ".check";
     
    8968my $uri_return  = $path_base . ".return";
    9069
    91 my $disk_command = $ipprc->file_resolve($uri_command,1);
    9270my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
    9371my $disk_check   = $ipprc->file_resolve($uri_check,1);
     
    9674my $disk_return  = $ipprc->file_resolve($uri_return,1);
    9775
    98 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
    99 
    100 open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id,$PS_EXIT_SYS_ERROR);
    101 open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$remote_id,$PS_EXIT_SYS_ERROR);
    102 open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$remote_id,$PS_EXIT_SYS_ERROR);
    103 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id,$PS_EXIT_SYS_ERROR);
    104 open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $PS_EXIT_SYS_ERROR);
     76my (undef, $remote_config) = &uri_convert($uri_config); # Needs to be done after we've created it.
     77
     78open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     79open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",   $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     80open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",  $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     81open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
     82open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",  $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
    10583my %file_filter = ();
    10684
    107 #
    108 # Step 2: Iterate over all componenets in this remote run.
    10985my $job_index = 0;
    110 my @pre_commands = ();
    111 my @main_commands = ();
    112 my @post_commands = ();
    113 
    114 foreach my $compEntry (@$compData2) {
    115     my $cam_id = $compEntry->{stage_id};
    116 
    117 # Get exposure level information from the camRun we're working from.
    118    
     86
     87# STEP 1: Get exposure level information for this camRun
     88my ($workdir,$exp_tag,$reduction);
     89{
    11990    my $command = "$camtool -pendingexp -cam_id $cam_id ";
    12091    $command   .= " -dbname $dbname " if defined($dbname);
    121    
     92
    12293    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    12394        run(command => $command, verbose => 0);
    12495    unless ($success) {
    12596        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    126        
    127         &my_die("Unable to run camtool to determine stage parameters.",
    128                 $cam_id,$error_code);
    129     }
    130 
    131     my $camData = $mdcParser->parse(join "", @$stdout_buf) or
    132         &my_die("Unable to determine cam component information.",
    133                 $cam_id,$PS_EXIT_PROG_ERROR);
    134     my $camData2= parse_md_list($camData);
    135     my $camEntry = ${ $camData2 }[0];
    136    
    137     my $workdir = $camEntry->{workdir};
    138     my $exp_tag = $camEntry->{exp_tag};
     97
     98        &my_die("Unable to run camtool to determine stage parameters.", $remote_id, $cam_id, $error_code, $fail_state);
     99    }
     100
     101    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     102        &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
     103    my $metadata = parse_md_list($MDlist);
     104    my $camEntry = $metadata->[0];
     105
     106    $workdir   = $camEntry->{workdir};
     107    $exp_tag   = $camEntry->{exp_tag};
     108    $reduction = $camEntry->{reduction};
     109    $reduction = 'DEFAULT' unless defined $reduction;
    139110    unless (defined($workdir)) {
    140         while( my ($k, $v) = each %$camEntry ) {
    141             print "key: $k, value: $v.\n";
    142         }
    143 
    144         print "%{ $camEntry }\n";
    145         die;
    146     }
    147     my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}";
    148     my $remote_outroot = uri_local_to_remote($ipp_outroot);
    149 
    150 
    151 #
     111        while( my ($k, $v) = each %$camEntry ) {
     112            print "key: $k, value: $v.\n";
     113        }
     114        print "%{ $camEntry }\n";
     115        die;
     116    }
     117}
     118
     119my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}";
     120my $remote_outroot = uri_local_to_remote($ipp_outroot);
     121
    152122# Step 3: Iterate over the sub-components
    153 
    154     my $reg_command = "$camtool -pendingimfile -cam_id $cam_id ";
    155     $reg_command   .= " -dbname $dbname " if defined($dbname);
    156 
    157     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    158         run(command => $reg_command, verbose => 0);
     123{
     124    my $command = "$camtool -pendingimfile -cam_id $cam_id ";
     125    $command   .= " -dbname $dbname " if defined($dbname);
     126
     127    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     128        run(command => $command, verbose => 0);
    159129    unless ($success) {
    160         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    161         &my_die("Unable to run camtool -pendingimfile ",
    162                 $cam_id,$error_code);
    163     }
    164    
     130        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     131        &my_die("Unable to run camtool -pendingimfile ", $remote_id, $cam_id, $error_code, $fail_state);
     132    }
    165133
    166134    # We don't actually care about the input cam data other than to know which mask files to instantiate.
    167     my $inpData = $mdcParser->parse(join "", @$stdout_buf) or
    168         &my_die("Unable to determine cam component information.",
    169                 $cam_id, $PS_EXIT_PROG_ERROR);
    170     my $inpData2=parse_md_list($inpData);
    171     my $chipProto= ${ $inpData2 }[0];
     135    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     136        &my_die("Unable to determine cam component information.", $remote_id, $cam_id, $PS_EXIT_PROG_ERROR, $fail_state);
     137
     138    my $metadata = parse_md_list($MDlist);
     139    my $chipProto = $metadata->[0];
    172140    my $chip_path = $chipProto->{path_base};
    173     my $remote_chip_path = uri_local_to_remote( $chip_path );
     141    my $remote_chip_path = &uri_local_to_remote( $chip_path );
    174142    my $pre_cmd_cmfs = "ls -1 ${remote_chip_path}*.cmf > ${remote_outroot}.cmflist";
    175143    my $pre_cmd_masks= "ls -1 ${remote_chip_path}*.mk.fits > ${remote_outroot}.masklist";
    176144
    177     my $reduction = 'DEFAULT' unless defined $camEntry->{reduction};
    178     my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use                                                                         
     145    my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
     146    if ($recipe_psastro eq "") {
     147        &my_die("Unable to determine PSASTRO recipe", $cam_id, $PS_EXIT_PROG_ERROR);
     148    }
    179149
    180150    my $psastro_command = " psastro -list ${remote_outroot}.cmflist ";
    181151    $psastro_command   .= " -masklist ${remote_outroot}.masklist ${remote_outroot} ";
    182 #    $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} "; # This is used to do edge calculations.  It should probably be smart enough to know that it can just use the masks I just specified, but it's not.
    183     # Uncomment when remote psastro supports this
     152#   $psastro_command   .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} ";
     153    $psastro_command   .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list ";
    184154    $psastro_command   .= " -kh-correct /turquoise/usr/projects/ps1/watersc1/references/khcorrect.20140606.v0.fits ";
    185     $psastro_command   .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list ";
    186 #    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
     155#   $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20080909.asm ";
    187156    $psastro_command   .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20140505.asm ";
    188157    $psastro_command   .= " -recipe PSASTRO $recipe_psastro ";
     
    190159    $psastro_command   .= " -dumpconfig ${remote_outroot}.psastro.mdc -stats ${remote_outroot}.stats ";
    191160    $psastro_command   .= " -recipe PPSTATS CAMSTATS ";
    192    
     161
    193162    my $camtool_post_cmd = "camtool -cam_id $cam_id -addprocessedexp -uri UNKNOWN ";
    194     $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname;                                                                                                            $camtool_post_cmd  .=  " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 ";
     163    $camtool_post_cmd  .=  " -dbname $dbname " if defined $dbname;
     164    $camtool_post_cmd  .=  " -path_base $ipp_outroot -hostname $remote_hostname -dtime_script 0 ";
    195165    my $post_cmd_echo = " echo -n \"$camtool_post_cmd\" > ${remote_outroot}.dbinfo ";
    196166    my $post_cmd_SfM  = " ppStatsFromMetadata ${remote_outroot}.stats - CAMERA_EXP_FPA >> ${remote_outroot}.dbinfo ";
     
    201171    # Determine which output files need to be returned
    202172    foreach my $component(@return_component_list) {
    203         my $filename = $ipprc->filename($component,$ipp_outroot);
    204         my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
    205         my $remote_outroot_dir = dirname($ipp_disk);
    206         print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    207     }
    208     foreach my $chipInfo (@{ $inpData2 }) {
    209         my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id});
    210         my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename);
    211         my $remote_outroot_dir = dirname($ipp_disk);
    212         print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     173        my $filename = $ipprc->filename($component,$ipp_outroot);
     174        my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename);
     175        my $remote_outroot_dir = dirname($ipp_disk);
     176        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     177    }
     178    foreach my $chipInfo (@{ $metadata }) {
     179        my $filename = $ipprc->filename("PSASTRO.OUTPUT.MASK",$ipp_outroot,$chipInfo->{class_id});
     180        my ($ipp_disk, $remote_disk) = &uri_to_outputs_for_return( $filename);
     181        my $remote_outroot_dir = dirname($ipp_disk);
     182        print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    213183    }
    214184    print CONFIG "\n";
     
    220190close(GENERATE);
    221191
    222 #
    223 # Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
    224 my $proc_need = $job_index * $threads;       # how many total processors do we need?
    225 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
    226 my $time_need = $job_index * $job_cost;      # How many seconds will this take?
    227 
    228 my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
    229 my ($time_req,$node_req);
    230 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
    231     $time_req = $min_time;
    232     $node_req = $min_nodes;
    233 }
    234 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
    235     $time_req = $max_time;
    236     $node_req = $max_nodes;
    237     print STDERR "You've requested the construction of a bundle that appears to need $node_need nodes and $job_cost time per job.  This exceeds the max limits ($max_nodes, $max_time).  Using those max values instead.  Good luck.\n";
    238 }
    239 else {
    240     $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
    241     $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
    242 }
    243 $time_req += 1; # Safety addition.
    244 
    245 open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$remote_id,$PS_EXIT_SYS_ERROR);
    246 print COMMAND "#!/bin/tcsh\n";
    247 print COMMAND "##### Moab controll lines\n";
    248 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
    249 print COMMAND "#MSUB -j oe\n";
    250 print COMMAND "#MSUB -V\n";
    251 print COMMAND "#MSUB -o ${remote_root}cam.${remote_id}.out\n";
    252 print COMMAND "date\n";
    253 print COMMAND 'srun -n $SLURM_JOB_NUM_NODES -m cyclic -l /bin/hostname | sort -n | awk \'{printf "%s\n", $2}\' > hosts.${SLURM_JOB_ID}' . "\n";
    254 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";
    255 print COMMAND "date\n";
    256 close(COMMAND);
    257 
    258192unless($no_update) {
    259     my $command = "remotetool -updaterun -remote_id $remote_id ";
    260     $command .= " -set_state pending ";
    261     $command .= " -dbname $dbname " if defined $dbname;
    262 
     193    my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $cam_id ";
     194    $command   .= " -set_jobs $job_index";
     195    $command   .= " -set_path_base $path_base";
     196    $command   .= " -set_state prep_done";
     197    $command   .= " -dbname $dbname " if defined $dbname;
    263198    system($command);
    264199}
    265200
     201exit (0);
    266202
    267203## Common SC routines
     
    271207    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    272208    my $remote_disk = $ipp_disk;
    273    
     209
    274210    unless(defined($ipp_disk)) {
    275         my_die();
     211        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
    276212    }
    277213
     
    287223    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
    288224    my $remote_disk = $ipp_disk;
    289    
     225
    290226    unless(defined($ipp_disk)) {
    291         my_die();
     227        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state);
    292228    }
    293229
     
    302238    my $neb_uri = shift;
    303239    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    304    
     240
    305241    unless (exists($file_filter{$neb_uri})) {
    306242        $file_filter{$neb_uri} = 1;
     
    332268    return($remote_uri);
    333269}
    334  
     270
    335271sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri);
    336272    # This needs to replace the remote root directory with the nebulous tag.
     
    338274    $remote_uri =~ s%${remote_root}%%;
    339275    my $local_uri  = "neb:///" . $remote_uri;
    340    
     276
    341277    return($local_uri);
    342278}
     
    345281sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status);
    346282    my $msg = shift;
    347     my $id  = shift;
     283    my $remote_id  = shift;
     284    my $stage_id  = shift;
    348285    my $exit_code = shift;
    349286    my $exit_state = shift;
     
    352289
    353290    carp($msg);
    354    
    355     if (defined $id and not $no_update) {
    356         my $command = "remotetool -updaterun -remote_id $id";
    357         $command .= " -fault $exit_code " if defined $exit_code;
     291
     292    if (defined $remote_id and defined $stage_id and not $no_update) {
     293        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
    358294        $command .= " -set_state $exit_state " if defined $exit_state;
    359295        $command .= " -dbname $dbname " if defined $dbname;
Note: See TracChangeset for help on using the changeset viewer.