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_chip.pl

    r37125 r37833  
    11#! /usr/bin/env perl
     2
     3# generate the input & output files lists and commands for a single chipRun
    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 $remote_raw    = "${remote_root}/raw/";  # Directory to find raw data in.
    24 my $threads       = 2;                      # How many threads are we going to use?
    25 my $job_cost      = 150 / 60 / 60;          # Estimate of how long a job runs, in hours.
    26 my $proc_per_node = 24;                     # processors per node
    27 my $min_nodes     = 1;                      # smallest allocation to ask for
    28 my $max_nodes     = 1000;                   # largest allocation to ask for
    29 my $min_time      = 1;                      # shortest allocation to ask for
    30 my $max_time      = 8;                      # longest allocation to ask for
    31 
    32 # We need to ensure we only ever try to transfer a file once.
    33 my %file_filter = ();
     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 $remote_raw      = "${remote_root}/tmp/";  # Directory to find raw data in.
     25my $threads_req     = 4;
     26
     27my $fail_state = "prep_fail";
     28my $hard_fail_state = "fail";
    3429
    3530# Look for programs we need
    3631my $missing_tools;
    37 my $regtool  = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
    3832my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1);
    3933my $detselect= can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1);
    4034my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1);
     35my $ipp_burntool_fix = can_run('ipp_apply_burntool_fix.pl') or (warn "Can't find ipp_apply_burntool_fix.pl" and $missing_tools = 1);
    4136
    4237if ($missing_tools) {
     
    4641
    4742# Options
    48 my ($exp_id,$exp_name,$remote_id,$chip_id,$detrends,$camera,$dbname,$verbose,$path_base,$no_update);
     43my ($remote_id,$chip_id,$camera,$dbname,$path_base,$no_update,$verbose,$dbverbose);
    4944GetOptions(
    5045    'remote_id=s'    => \$remote_id,
     46    'chip_id=s'      => \$chip_id,
    5147    'camera|c=s'     => \$camera,
    5248    'dbname|d=s'     => \$dbname,
     
    5450    'no_update'      => \$no_update,
    5551    'verbose'        => \$verbose,
     52    'dbverbose'      => \$dbverbose,
    5653    ) or pod2usage( 2 );
    5754
    5855pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    59 pod2usage( -msg => "Required options: --remote_id --camera --dbname --path_base", -exitval => 3) unless
     56pod2usage( -msg => "Required options: --remote_id --chip_id --camera --dbname --path_base", -exitval => 3) unless
    6057    defined($remote_id) and
     58    defined($chip_id) and
    6159    defined($camera) and
    6260    defined($path_base) and
    6361    defined($dbname);
    64 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $exp_id);
     62
     63my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
    6564
    6665my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6766
    68 #
    69 # Step 1: Get a list of the components that make up this remoteRun
    70 
    71 # SHould this call listrun to ensure we're in state new?
    72 my $rt_cmd = "$remotetool -listcomponent -remote_id $remote_id";
    73 $rt_cmd   .= " -dbname $dbname " if defined($dbname);
    74 
    75 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    76     run(command => $rt_cmd, verbose => $verbose);
    77 unless ($success) {
    78     $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    79    
    80     &my_die("Unable to run chiptool to determine stage parameters.",
    81             $remote_id,$error_code);
    82 }
    83 my $compData = $mdcParser->parse(join "", @$stdout_buf) or
    84     &my_die("Unable to determine component information.",
    85             $remote_id,$PS_EXIT_PROG_ERROR);
    86 my $compData2= parse_md_list($compData);
    87 
    88 #
    89 # Step 1a: Load up the catalog of detrends
    90 # Detrend concept holders
    91 my %detrends = ();
    92 my %det_types = ('MASK' => '-mask',
    93                  'FLAT' => '-flat',
    94                  'DARK' => '-dark',
    95                  'VIDEODARK' => '-dark',
    96                  'LINEARITY' => '-linearity',
    97                  'FRINGE'    => '-fringe',
    98                  'NOISEMAP'  => '-noisemap');
    99 
    100 foreach my $det_type (keys (%det_types)) {
    101     my $dt_cmd = "$detselect -show -camera $camera -det_type $det_type ";
    102     $dt_cmd   .= " -dbname $dbname " if defined($dbname);
    103 
    104     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    105         run(command => $dt_cmd, verbose => $verbose);
    106     unless ($success) {
    107         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    108         &my_die("UNable to run detselect to determine detrend catalog",
    109                 $remote_id,$error_code);
    110     }
    111     my $detData = $mdcParser->parse(join "", @$stdout_buf) or
    112         &my_die("Unable to determine detrend information.",
    113                 $remote_id,$PS_EXIT_PROG_ERROR);
    114     my $detData2= parse_md_list($detData);
    115 
    116     # Data structure for this:
    117     # $detrend{NAME} = \@list_of_detselect_shows
    118     # $detrend{NAME}[0] = \%hash_of_detselect_constraint_results (first element)
    119     # $detrend{NAME}[0]{class_id} = uri
    120 
    121     # At this point, I have the list of detselect shows, assign it
    122     $detrends{$det_type} = $detData2;
    123 
    124     for (my $dd = 0; $dd <= $#{ @{ $detrends{$det_type} } }; $dd++) {
    125         my $det_id = ${ $detrends{$det_type} }[$dd]->{det_id};
    126         my $det_iter=${ $detrends{$det_type} }[$dd]->{iteration};
    127 
    128         my $detselect_command2 = "detselect -select ";
    129         $detselect_command2   .= " -det_id $det_id ";
    130         $detselect_command2   .= " -iteration $det_iter ";
    131         $detselect_command2   .= " -dbname $dbname " if defined($dbname);
    132         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    133             run(command => $detselect_command2, verbose => 0);
    134         unless ($success) {
    135             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    136            
    137             &my_die("No valid detrend available for this image: $det_type $det_id $det_iter",
    138                     $chip_id,$error_code);
    139         }
    140        
    141         my $detImfile = $mdcParser->parse(join "", @$stdout_buf) or
    142             &my_die("Could not parse detrend information for this image: $det_type $det_id $det_iter",
    143                     $chip_id,$error_code);
    144         my $detImfile2= parse_md_list($detImfile);
    145         foreach $detImfile (@$detImfile2) {
    146             my $class_id = $detImfile->{class_id};
    147             my $duri = $detImfile->{uri};
    148            
    149             ${ $detrends{$det_type} }[$dd]->{$class_id} = $duri;
    150         }
    151     }
    152 }
    153 
    154 #print Dumper(%detrends);
     67# Detrend concept holders (name, ppImage option)
     68my %det_types = (
     69    'MASK'      => '-mask',
     70    'FLAT'      => '-flat',
     71    'DARK'      => '-dark',
     72    'VIDEODARK' => '-dark',
     73    'LINEARITY' => '-linearity',
     74    'FRINGE'    => '-fringe',
     75    'NOISEMAP'  => '-noisemap'
     76    );
    15577
    15678my @return_component_list = ("DBINFO.IMFILE","PPIMAGE.STATS","LOG.IMFILE","PPIMAGE.BACKMDL","PPIMAGE.PATTERN");
    15779
    158 #
    159 # Step 1b: Open output files
    160 my $uri_command = $path_base . ".cmd";
     80# STEP 0: Open output files
    16181my $uri_transfer= $path_base . ".transfer";
    16282my $uri_check   = $path_base . ".check";
     
    16585my $uri_return  = $path_base . ".return";
    16686
    167 my $disk_command = $ipprc->file_resolve($uri_command,1);
    16887my $disk_transfer= $ipprc->file_resolve($uri_transfer,1);
    16988my $disk_check   = $ipprc->file_resolve($uri_check,1);
     
    17493my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it.
    17594
    176 open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer",$chip_id,$PS_EXIT_SYS_ERROR);
    177 open(CHECK,    ">$disk_check")  || &my_die("Couldn't open file? $disk_check",$chip_id,$PS_EXIT_SYS_ERROR);
    178 open(CONFIG,   ">$disk_config")  || &my_die("Couldn't open file? $disk_config",$chip_id,$PS_EXIT_SYS_ERROR);
    179 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$chip_id,$PS_EXIT_SYS_ERROR);
    180 open(RETURN,   ">$disk_return") || &my_die("Couldn't open file? $disk_return", $chip_id, $PS_EXIT_SYS_ERROR);
    181 
    182 
    183 #
    184 # Step 2: Iterate over all componenets in this remote run.
     95open(TRANSFER, ">$disk_transfer")  || &my_die("Couldn't open file? $disk_transfer", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     96open(CHECK,    ">$disk_check")     || &my_die("Couldn't open file? $disk_check",    $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     97open(CONFIG,   ">$disk_config")    || &my_die("Couldn't open file? $disk_config",   $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     98open(GENERATE, ">$disk_generate")  || &my_die("Couldn't open file? $disk_generate", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     99open(RETURN,   ">$disk_return")    || &my_die("Couldn't open file? $disk_return",   $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
     100
    185101my $job_index = 0;
    186 my @pre_commands = ();
    187 my @main_commands = ();
    188 my @post_commands = ();
    189 
    190 foreach my $compEntry (@$compData2) {
    191 
    192     my $chip_id = $compEntry->{stage_id};
    193     my $exp_id ;
    194 # Get exposure level information from the chipRun we're working from.
     102
     103# STEP 1 : Get exposure level information for this chipRun
     104my ($exp_id, $filter, $altfilt, $dateobs);
     105{
    195106    my $command = "$chiptool -listrun -chip_id $chip_id ";
    196107    $command   .= " -dbname $dbname " if defined($dbname);
    197    
    198     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    199         run(command => $command, verbose => 0);
     108
     109    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     110        run(command => $command, verbose => $dbverbose);
    200111    unless ($success) {
    201         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    202        
    203         &my_die("Unable to run chiptool to determine stage parameters.",
    204                 $chip_id,$error_code);
    205     }
    206    
    207 # Parse chipRun level data to determine detrend information
    208     my %detrends_to_use = ();
    209     {
    210         my $chipData = $mdcParser->parse(join "", @$stdout_buf) or
    211             &my_die("Unable to determine chip component information.",
    212                     $chip_id,$PS_EXIT_PROG_ERROR);
    213         my $chipData2= parse_md_list($chipData);
    214         my $chipEntry = ${ $chipData2 }[0];
    215        
    216         $exp_id = $chipEntry->{exp_id};   
    217         my $filter = $chipEntry->{filter};
    218         my $altfilt= $filter;
    219         $altfilt =~ s/.00000//;
    220         my $dateobs= $chipEntry->{dateobs};
    221         my ($date, $time) = split /T/, $dateobs;
    222         my ($year,$month,$day) = split /-/, $date;
    223         my ($hour,$minute,$second) = split /:/, $time; #/;
    224         my $dateobs_obj = DateTime->new(year => $year, month => $month, day => $day, hour => $hour, minute => $minute, second => $second);
    225 
    226         foreach my $det_type (%detrends) {
    227             if (($filter !~ /y/)&&($det_type eq 'FRINGE')) { next; } # We can skip fringe for all but y
    228 
    229             foreach my $det_obj (@{ $detrends{$det_type} }) { # Iterate over the available options
    230                 if (defined($det_obj->{filter})) {
    231                     if (($det_obj->{filter} ne $filter)&&($det_obj->{filter} ne $altfilt)) {
    232                         next; # Skip detrends with a filter that we can't use.
    233                     }
    234                 }
    235                 if (defined($det_obj->{time_begin})) {
    236                     if (DateTime->compare($dateobs_obj,$det_obj->{time_begin}) == -1) {
    237                         next; # Skip detrends that come into effect after this exposure (d1 < d2)
    238                     }
    239                 }
    240                 if (defined($det_obj->{time_end})) {
    241                     if (DateTime->compare($dateobs_obj,$det_obj->{time_end}) == 1) {
    242                         next; # Skip detrends that stop working before this exposure (d1 > d2)
    243                     }
    244                 }
    245                 $detrends_to_use{$det_type} = $det_obj;
    246                 last;
     112        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     113
     114        &my_die("Unable to run chiptool to determine stage parameters.", $remote_id, $chip_id, $error_code, $fail_state);
     115    }
     116
     117    # Parse chipRun level data to determine exposure information
     118    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     119        &my_die("Unable to determine chip component information.", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
     120    my $metadata = parse_md_list($MDlist);
     121    my $chipEntry = $metadata->[0];
     122
     123    $exp_id  = $chipEntry->{exp_id};
     124    $filter  = $chipEntry->{filter};
     125    $altfilt = $filter;
     126    $altfilt =~ s/.00000//;
     127    $dateobs = $chipEntry->{dateobs};
     128}
     129
     130# STEP 2 : select the det_ids for each desired det_type (appropriate to this exposure)
     131my %det_ids = ();
     132my %det_iters = ();
     133
     134foreach my $det_type (keys (%det_types)) {
     135    if (($filter !~ /y/) && ($det_type eq 'FRINGE')) { next; } # We can skip fringe for all but y
     136
     137    my $command = "detselect -search -det_type $det_type -time $dateobs";
     138    $command   .= " -dbname $dbname " if defined($dbname);
     139
     140    if (($det_type eq 'FLAT') || ($det_type eq 'FRINGE')) {
     141        $command .= " -filter $altfilt";
     142    }
     143
     144    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     145        run(command => $command, verbose => $dbverbose);
     146    unless ($success) {
     147        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     148
     149        &my_die("No valid detrend available for this image: $det_type", $remote_id, $chip_id, $error_code, $fail_state);
     150    }
     151
     152    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     153        &my_die("Could not parse detrend information for this image: $det_type", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
     154    my $metadata = parse_md_list($MDlist);
     155    my $detEntry = $metadata->[0];
     156
     157    if ($verbose) {
     158        print STDERR "det_id: $detEntry->{det_id}\n";
     159        print STDERR "det_iter: $detEntry->{iteration}\n";
     160    }
     161
     162    # save det_id and iteration
     163    $det_ids{$det_type} = $detEntry->{det_id};
     164    $det_iters{$det_type} = $detEntry->{iteration};
     165}
     166
     167# Step 3: Iterate over the sub-components
     168{
     169    # select chipProcessedImfile entries
     170    my $command = "$chiptool -pendingimfile -chip_id $chip_id";
     171    $command   .= " -dbname $dbname "   if defined($dbname);
     172
     173    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     174        run(command => $command, verbose => $dbverbose);
     175
     176    unless ($success) {
     177        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     178
     179        &my_die("Unable to run chiptool -pendingimfile", $remote_id, $chip_id, $error_code, $fail_state);
     180    }
     181
     182    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
     183        &my_die("Unable to parse chiptool -pendingimfile information.", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
     184    my $metadata = parse_md_list($MDlist);
     185
     186    # Iterate over the chipProcessedImfile level data.
     187    foreach my $chipEntry (@$metadata) {
     188        # Get information we need to pass to ppImage
     189        my $uri            = $chipEntry->{uri};
     190        my $class_id       = $chipEntry->{class_id};
     191        my $video_cells    = $chipEntry->{video_cells};
     192        my $reduction      = $chipEntry->{reduction};
     193        my $exp_tag        = $chipEntry->{exp_tag};
     194        my $workdir        = $chipEntry->{workdir};
     195        my $chip_imfile_id = $chipEntry->{chip_imfile_id};
     196
     197        # Process the image and burntool table
     198        # IMAGE CHECK: Look up the image location, prove it exists, and if not, abort the prep for this object.
     199        my ($ipp_uri, $remote_uri) = uri_convert($uri);
     200        unless (-e $ipp_uri) {
     201            # Try to fix it.
     202            system("neb-repair $uri");
     203            ($ipp_uri, $remote_uri) = uri_convert($uri);
     204            unless (-e $ipp_uri) {
     205                # This image file is missing, so it will require manual intervention.
     206                &my_die("Required image file $ipp_uri ($chip_id, $class_id) not found.  Stopping this prep.",
     207                        $remote_id,$chip_id,$PS_EXIT_CONFIG_ERROR,$hard_fail_state);
    247208            }
    248209        }
    249     }
    250 
    251 #
    252 # Step 3: Iterate over the sub-components
    253 # Iterate over the chipProcessedImfile level data.
    254     my $reg_command = "$chiptool -pendingimfile ";
    255     $reg_command   .= " -chip_id $chip_id " if defined($chip_id);
    256     $reg_command   .= " -dbname $dbname "   if defined($dbname);
    257    
    258     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    259         run(command => $reg_command, verbose => $verbose);
    260     unless ($success) {
    261         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    262        
    263         &my_die("Unable to run chiptool -pendingimfile",
    264                 $chip_id,$error_code);
    265     }
    266    
    267     my $chipData = $mdcParser->parse(join "", @$stdout_buf) or
    268         next;
    269 #       &my_die("Unable to parse chiptool -pendingimfile information.",
    270 #               $chip_id,$error_code);
    271     my $chipData2= parse_md_list($chipData);
    272 
    273    
    274     foreach my $chipEntry (@$chipData2) {
    275         # Get information we need to pass to ppImage
    276         my $uri            = $chipEntry->{uri};
    277         my $class_id       = $chipEntry->{class_id};
    278         my $video_cells    = $chipEntry->{video_cells};
    279         my $reduction      = $chipEntry->{reduction};
    280         my $exp_tag        = $chipEntry->{exp_tag};
    281         my $workdir        = $chipEntry->{workdir};
    282         my $chip_imfile_id = $chipEntry->{chip_imfile_id};
    283        
    284         # Process the image and burntool table
    285         my ($ipp_uri,$remote_uri) = uri_to_outputs_raw($uri);
    286         my $btt = $uri;
    287         $btt =~ s/fits$/burn.tbl/;
    288         my ($ipp_btt,$remote_btt) = uri_to_outputs_raw($btt);
    289        
    290         # Initialize the ppI command
    291         my $ppImage_command = "ppImage -file $remote_uri";
    292         $ppImage_command   .= " -burntool $remote_btt ";
    293        
    294         # Add detrend information to the command line
    295         foreach my $det (keys %detrends_to_use) {
    296             if ((($video_cells)&&($det eq 'DARK'))||
    297                 ((!$video_cells)&&($det eq 'VIDEODARK'))) {
    298                 next;
     210
     211        # The image exists, so continue.  This resets the variables, but also outputs the file locations.
     212        ($ipp_uri, $remote_uri) = uri_to_outputs_raw($uri);
     213        my $btt = $uri;
     214        $btt =~ s/fits$/burn.tbl/;
     215
     216        # Check burntool table for existance, and if it doesn't, regenerate it.
     217        my ($ipp_btt, $remote_btt) = uri_convert($btt);
     218        unless (-e $ipp_btt) {
     219            my $exp_name = $chipEntry->{exp_name};
     220            my $burntool_command = "$ipp_burntool_fix --exp_name $exp_name --class_id $class_id";
     221            $burntool_command   .= " -dbname $dbname" if defined($dbname);
     222            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     223                run(command => $burntool_command, verbose => $dbverbose);
     224            # That command repairs the tables, but the instance we learned about may not be correct. 
     225            # Look up the new one.
     226            ($ipp_btt, $remote_btt) = uri_convert($btt);
     227           
     228            unless (-e $ipp_btt) {
     229                &my_die("Attempted regeneration of burntool table ($chip_id, $class_id) has failed.  Stopping this prep.",
     230                        $remote_id,$chip_id, $PS_EXIT_CONFIG_ERROR, $hard_fail_state);
    299231            }
    300             my $det_code = $det_types{$det};
    301             my $duri = $detrends_to_use{$det}->{$class_id};
    302             my ($ipp_det_uri, $remote_det_uri) = uri_to_outputs_raw($duri);
    303             $ppImage_command .= " $det_code $remote_det_uri ";
    304232        }
    305            
    306        
    307         # Add output root
    308         my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.ch.${chip_id}";
    309         my $remote_outroot = uri_local_to_remote($ipp_outroot);
    310         $ppImage_command .= " $remote_outroot ";
    311         print STDERR "$remote_outroot $ipp_outroot $class_id\n";
    312         # Complete reduction information.
    313         $reduction = 'DEFAULT' unless defined $reduction;
    314         my $recipe_ppImage = $ipprc->reduction($reduction, 'CHIP_PPIMAGE'); # Recipe to use for ppImage
    315         my $recipe_psphot  = $ipprc->reduction($reduction, 'CHIP_PSPHOT'); # Recipe to use for psphot
    316        
    317         $ppImage_command .= " -recipe PPIMAGE $recipe_ppImage ";
    318         $ppImage_command .= " -recipe PSPHOT $recipe_psphot ";
    319         $ppImage_command .= " -recipe PPSTATS CHIPSTATS -stats ${remote_outroot}.${class_id}.stats ";
    320         $ppImage_command .= " -threads 4 ";
    321         $ppImage_command .= " -image_id $chip_imfile_id ";
    322         $ppImage_command .= " -tracedest ${remote_outroot}.${class_id}.trace ";
    323         $ppImage_command .= " -log ${remote_outroot}.${class_id}.log ";
    324 
    325 #       push @main_commands, $ppImage_command;
    326 
    327         # Calculate pre and post commands
    328         my $remote_outroot_dir = dirname($remote_outroot);
    329         my $pre_command =  "mkdir -p $remote_outroot_dir";
    330        
    331         my $post_commandA = "chiptool -addprocessedimfile -exp_id $exp_id -chip_id $chip_id -class_id $class_id ";
    332         $post_commandA   .= " -uri ${ipp_outroot}.ch.${class_id}.ch.fits -path_base $ipp_outroot ";
    333         $post_commandA   .= " -magicked 0 -hostname REMOTE -dtime_script 0 ";
    334         $post_commandA   .= " -dbname $dbname " if defined $dbname;
    335 
    336         my $post_commandB = "echo -n \"$post_commandA\" > ${remote_outroot}.${class_id}.dbinfo  ";
    337         my $post_commandC = "ppStatsFromMetadata ${remote_outroot}.${class_id}.stats - CHIP_IMFILE >> ${remote_outroot}.${class_id}.dbinfo";
    338        
    339 #       push @post_commands, "$post_commandB $post_commandC";
    340 
    341         $job_index++;
    342 
    343         print CONFIG "${pre_command} && ${ppImage_command} && ${post_commandB} && ${post_commandC}";
    344 
    345 
    346         # Determine which output files need to be returned.
    347         foreach my $component (@return_component_list) {
    348 #           uri_convert_and_create( $ipprc->filename($component, $ipp_outroot, $class_id) );
    349             my $filename = $ipprc->filename($component, $ipp_outroot, $class_id);
    350             my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename );
    351             my $remote_outroot_dir = dirname($ipp_disk);
    352             print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
    353 #           print "  $filename $ipp_disk $remote_disk\n";
    354 #           die;
    355         }
    356 
    357         print CONFIG "\n";
    358     }
    359 }
    360 
    361 # Actually put the commands into the output file.
    362 # my %unique_cmds = ();
    363 # foreach my $cmd (@pre_commands) {
    364 #     unless(exists($unique_cmds{$cmd})) {
    365 #       print CONFIG $cmd . "\n";
    366 #       $unique_cmds{$cmd} = 1;
    367 #     }
    368 # }
    369 # foreach my $cmd (@main_commands) {
    370 #     unless(exists($unique_cmds{$cmd})) {
    371 #       print CONFIG $cmd . "\n";
    372 #       $unique_cmds{$cmd} = 1;
    373 #     }
    374 # }
    375 # foreach my $cmd (@post_commands) {
    376 #     unless(exists($unique_cmds{$cmd})) {
    377 #       print CONFIG $cmd . "\n";
    378 #       $unique_cmds{$cmd} = 1;
    379 #     }
    380 # }
     233        ($ipp_btt, $remote_btt) = uri_to_outputs_raw($btt);
     234
     235        # Initialize the ppI command
     236        my $ppImage_command = "ppImage -file $remote_uri";
     237        $ppImage_command   .= " -burntool $remote_btt ";
     238
     239        foreach my $det_type (keys (%det_types)) {
     240            if (( $video_cells) && ($det_type eq 'DARK')) { next; }
     241            if ((!$video_cells) && ($det_type eq 'VIDEODARK')) { next; }
     242
     243            my $det_id   = $det_ids{$det_type};
     244            my $det_iter = $det_iters{$det_type};
     245
     246            if (not defined $det_id) { next; }
     247
     248            if ($verbose) { print STDERR "det_type, det_id, det_iter: $det_type, $det_id, $det_iter\n"; }
     249
     250            # Add detrend information to the command line
     251            my $detselect_command = "detselect -select ";
     252            $detselect_command   .= " -det_id $det_id";
     253            $detselect_command   .= " -iteration $det_iter";
     254            $detselect_command   .= " -class_id $class_id";
     255            $detselect_command   .= " -dbname $dbname " if defined($dbname);
     256
     257            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     258                run(command => $detselect_command, verbose => $dbverbose);
     259
     260            unless ($success) {
     261                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     262
     263                &my_die("No valid detrend available for this image: $det_type $det_id $det_iter", $remote_id, $chip_id, $error_code, $fail_state);
     264            }
     265
     266            my $detMDlist = $mdcParser->parse(join "", @$stdout_buf) or
     267                &my_die("Could not parse detrend information for this image: $det_type $det_id $det_iter", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state);
     268            my $detImfileMD = parse_md_list($detMDlist);
     269            my $detImfile = $detImfileMD->[0];
     270            my $duri = $detImfile->{uri};
     271
     272            my $det_code = $det_types{$det_type};
     273            my ($ipp_det_uri, $remote_det_uri) = uri_to_outputs_raw($duri);
     274            $ppImage_command .= " $det_code $remote_det_uri ";
     275        }
     276
     277        # Add output root
     278        my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.ch.${chip_id}";
     279        my $remote_outroot = uri_local_to_remote($ipp_outroot);
     280        $ppImage_command .= " $remote_outroot ";
     281        print STDERR "$remote_outroot $ipp_outroot $class_id\n";
     282        # Complete reduction information.
     283        $reduction = 'DEFAULT' unless defined $reduction;
     284        my $recipe_ppImage = $ipprc->reduction($reduction, 'CHIP_PPIMAGE'); # Recipe to use for ppImage
     285        my $recipe_psphot  = $ipprc->reduction($reduction, 'CHIP_PSPHOT'); # Recipe to use for psphot
     286
     287        $ppImage_command .= " -recipe PPIMAGE $recipe_ppImage ";
     288        $ppImage_command .= " -recipe PSPHOT $recipe_psphot ";
     289        $ppImage_command .= " -recipe PPSTATS CHIPSTATS -stats ${remote_outroot}.${class_id}.stats ";
     290        $ppImage_command .= " -threads $threads_req ";
     291        $ppImage_command .= " -image_id $chip_imfile_id ";
     292        $ppImage_command .= " -tracedest ${remote_outroot}.${class_id}.trace ";
     293        $ppImage_command .= " -log ${remote_outroot}.${class_id}.log ";
     294
     295        # Calculate pre and post commands
     296        my $remote_outroot_dir = dirname($remote_outroot);
     297        my $pre_command =  "mkdir -p $remote_outroot_dir";
     298
     299        my $post_commandA = "chiptool -addprocessedimfile -exp_id $exp_id -chip_id $chip_id -class_id $class_id ";
     300        $post_commandA   .= " -uri ${ipp_outroot}.ch.${class_id}.ch.fits -path_base $ipp_outroot ";
     301        $post_commandA   .= " -magicked 0 -hostname $remote_hostname -dtime_script 0 ";
     302        $post_commandA   .= " -dbname $dbname " if defined $dbname;
     303
     304        my $post_commandB = "echo -n \"$post_commandA\" > ${remote_outroot}.${class_id}.dbinfo  ";
     305        my $post_commandC = "ppStatsFromMetadata ${remote_outroot}.${class_id}.stats - CHIP_IMFILE >> ${remote_outroot}.${class_id}.dbinfo";
     306
     307        $job_index++;
     308
     309        print CONFIG "${pre_command} && ${ppImage_command} && ${post_commandB} && ${post_commandC}";
     310
     311        # Determine which output files need to be returned.
     312        foreach my $component (@return_component_list) {
     313            my $filename = $ipprc->filename($component, $ipp_outroot, $class_id);
     314            my ($ipp_disk, $remote_disk) = uri_to_outputs_for_return( $filename );
     315            my $remote_outroot_dir = dirname($ipp_disk);
     316            print CONFIG " && mkdir -p ${remote_root}/tmp/${remote_outroot_dir} && ln -sf $remote_disk ${remote_root}/tmp/${ipp_disk} && touch $remote_disk ";
     317        }
     318        print CONFIG "\n";
     319    }
     320}
    381321
    382322close(CONFIG);
     
    386326close(GENERATE);
    387327
    388 #
    389 # Construct the moab command last, so we can use the job_index counter to estimate resources.  Somehow.
    390 my $proc_need = $job_index * $threads;       # how many total processors do we need?
    391 my $node_need = $proc_need / $proc_per_node; # this equals how many nodes?
    392 my $time_need = $job_index * $job_cost;      # How many seconds will this take?
    393 
    394 my $fill_factor = 0.8;  # This is the factor of how much of the time allocation we'd like to fill
    395 my ($time_req,$node_req);
    396 if ($node_need * $job_cost < $fill_factor * $min_nodes * $min_time) {
    397     $time_req = $min_time;
    398     $node_req = $min_nodes;
    399 }
    400 elsif ($node_need * $job_cost > $fill_factor * $max_nodes * $max_time) {
    401     $time_req = $max_time;
    402     $node_req = $max_nodes;
    403     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";
    404 }
    405 else {
    406     $time_req = int(($node_need * $job_cost) / ($fill_factor * $max_nodes)) + 1;
    407     $node_req = int(($node_need * $job_cost) / ($fill_factor * $time_req)) + 1;
    408 }
    409 $time_req += 1; # Safety addition.
    410 
    411 open(COMMAND,  ">$disk_command") || &my_die("Couldn't open file? $disk_command",$chip_id,$PS_EXIT_SYS_ERROR);
    412 print COMMAND "#!/bin/tcsh\n";
    413 print COMMAND "##### Moab controll lines\n";
    414 print COMMAND "#MSUB -l nodes=${node_req}:ppn=${proc_per_node},walltime=${time_req}:00:00\n"; ## CHECK RESOURCES
    415 print COMMAND "#MSUB -j oe\n";
    416 print COMMAND "#MSUB -V\n";
    417 print COMMAND "#MSUB -o ${remote_root}chip.${remote_id}.out\n";
    418 print COMMAND "date\n";
    419 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";
    420 print COMMAND "${remote_root}/stask_chip.py $remote_config " . 'hosts.${SLURM_JOB_ID} 1' . "\n";
    421 #print COMMAND "validate_processing.pl ${remote_root}chip.${remote_id}.out\n";
    422 print COMMAND "date\n";
    423 close(COMMAND);
    424 
    425 
    426328## We're done here. The execution and handling are done elsewhere.
    427329# Quick review:
     
    429331# auth
    430332unless($no_update) {
    431     my $command = "remotetool -updaterun -remote_id $remote_id ";
    432     $command .= " -set_state pending ";
     333    my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $chip_id ";
     334    $command .= " -set_jobs $job_index";
     335    $command .= " -set_path_base $path_base";
     336    $command .= " -set_state prep_done";
    433337    $command .= " -dbname $dbname " if defined $dbname;
    434338
    435339    system($command);
    436340}
    437 
    438 
    439    
    440 
    441 
     341exit (0);
    442342
    443343sub uri_convert {
     
    445345    my $ipp_disk= $ipprc->file_resolve( $neb_uri );
    446346    my $remote_disk = $ipp_disk;
    447    
     347
    448348    unless(defined($ipp_disk)) {
    449         my_die();
     349        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
    450350    }
    451351
     
    461361    my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1);
    462362    my $remote_disk = $ipp_disk;
    463    
     363
    464364    unless(defined($ipp_disk)) {
    465         my_die();
     365        &my_die( "Unable to generate file for $neb_uri ", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state);
    466366    }
    467367
     
    476376    my $neb_uri = shift;
    477377    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    478    
    479     unless (exists($file_filter{$neb_uri})) {
    480         $file_filter{$neb_uri} = 1;
    481         print TRANSFER "$ipp_disk\n";
    482         print CHECK    "$remote_disk\n";
    483     }
     378
     379    print TRANSFER "$ipp_disk\n";
     380    print CHECK    "$remote_disk\n";
    484381    return($ipp_disk,$remote_disk);
    485382}
     
    489386    my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri );
    490387    $remote_disk = $remote_raw . $ipp_disk;
    491     unless (exists($file_filter{$neb_uri})) {
    492         $file_filter{$neb_uri} = 1;
    493         print TRANSFER "$ipp_disk\n";
    494         print CHECK    "$remote_disk\n";
    495     }
     388
     389    print TRANSFER "$ipp_disk\n";
     390    print CHECK    "$remote_disk\n";
    496391    return($ipp_disk,$remote_disk);
    497392}
     
    500395    my $neb_uri = shift;
    501396    my ($ipp_disk, $remote_disk) = uri_convert_and_create( $neb_uri );
    502     unless (exists($file_filter{$neb_uri})) {
    503         $file_filter{$neb_uri} = 1;
    504         print RETURN "$ipp_disk\n";
    505         print GENERATE "$remote_disk\n";
    506     }
     397    print RETURN "$ipp_disk\n";
     398    print GENERATE "$remote_disk\n";
    507399    return($ipp_disk,$remote_disk);
    508400}
     
    518410    return($remote_uri);
    519411}
    520  
     412
    521413sub uri_remote_to_local {
    522414    # This needs to replace the remote root directory with the nebulous tag.
     
    524416    $remote_uri =~ s%${remote_root}%%;
    525417    my $local_uri  = "neb:///" . $remote_uri;
    526    
     418
    527419    return($local_uri);
    528420}
     421
    529422sub my_die {
    530423    my $msg = shift;
    531     my $id  = shift;
     424    my $remote_id  = shift;
     425    my $stage_id  = shift;
    532426    my $exit_code = shift;
    533427    my $exit_state = shift;
     
    536430
    537431    carp($msg);
    538    
    539     if (defined $id and not $no_update) {
    540         my $command = "remotetool -updaterun -remote_id $id";
    541         $command .= " -fault $exit_code " if defined $exit_code;
    542         $command .= " -set_state $exit_state " if defined $exit_state;
    543         $command .= " -dbname $dbname " if defined $dbname;
    544 
    545         system($command);
     432
     433    if (defined $remote_id and defined $stage_id and not $no_update) {
     434        my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $stage_id";
     435        $command .= " -set_state $exit_state " if defined $exit_state;
     436        $command .= " -dbname $dbname " if defined $dbname;
     437
     438        system($command);
    546439    }
    547440
Note: See TracChangeset for help on using the changeset viewer.