Changeset 37833 for trunk/ippScripts/scripts/sc_prepare_chip.pl
- Timestamp:
- Jan 12, 2015, 12:53:36 PM (11 years ago)
- Location:
- trunk/ippScripts/scripts
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
sc_prepare_chip.pl (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts
- Property svn:mergeinfo set to
-
trunk/ippScripts/scripts/sc_prepare_chip.pl
r37125 r37833 1 1 #! /usr/bin/env perl 2 3 # generate the input & output files lists and commands for a single chipRun 2 4 3 5 use Carp; … … 16 18 use Pod::Usage qw( pod2usage ); 17 19 18 19 20 # 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 22 my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 23 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 24 my $remote_raw = "${remote_root}/tmp/"; # Directory to find raw data in. 25 my $threads_req = 4; 26 27 my $fail_state = "prep_fail"; 28 my $hard_fail_state = "fail"; 34 29 35 30 # Look for programs we need 36 31 my $missing_tools; 37 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);38 32 my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1); 39 33 my $detselect= can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1); 40 34 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 35 my $ipp_burntool_fix = can_run('ipp_apply_burntool_fix.pl') or (warn "Can't find ipp_apply_burntool_fix.pl" and $missing_tools = 1); 41 36 42 37 if ($missing_tools) { … … 46 41 47 42 # Options 48 my ($ exp_id,$exp_name,$remote_id,$chip_id,$detrends,$camera,$dbname,$verbose,$path_base,$no_update);43 my ($remote_id,$chip_id,$camera,$dbname,$path_base,$no_update,$verbose,$dbverbose); 49 44 GetOptions( 50 45 'remote_id=s' => \$remote_id, 46 'chip_id=s' => \$chip_id, 51 47 'camera|c=s' => \$camera, 52 48 'dbname|d=s' => \$dbname, … … 54 50 'no_update' => \$no_update, 55 51 'verbose' => \$verbose, 52 'dbverbose' => \$dbverbose, 56 53 ) or pod2usage( 2 ); 57 54 58 55 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 59 pod2usage( -msg => "Required options: --remote_id --c amera --dbname --path_base", -exitval => 3) unless56 pod2usage( -msg => "Required options: --remote_id --chip_id --camera --dbname --path_base", -exitval => 3) unless 60 57 defined($remote_id) and 58 defined($chip_id) and 61 59 defined($camera) and 62 60 defined($path_base) and 63 61 defined($dbname); 64 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $exp_id); 62 63 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $chip_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 65 64 66 65 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 67 66 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) 68 my %det_types = ( 69 'MASK' => '-mask', 70 'FLAT' => '-flat', 71 'DARK' => '-dark', 72 'VIDEODARK' => '-dark', 73 'LINEARITY' => '-linearity', 74 'FRINGE' => '-fringe', 75 'NOISEMAP' => '-noisemap' 76 ); 155 77 156 78 my @return_component_list = ("DBINFO.IMFILE","PPIMAGE.STATS","LOG.IMFILE","PPIMAGE.BACKMDL","PPIMAGE.PATTERN"); 157 79 158 # 159 # Step 1b: Open output files 160 my $uri_command = $path_base . ".cmd"; 80 # STEP 0: Open output files 161 81 my $uri_transfer= $path_base . ".transfer"; 162 82 my $uri_check = $path_base . ".check"; … … 165 85 my $uri_return = $path_base . ".return"; 166 86 167 my $disk_command = $ipprc->file_resolve($uri_command,1);168 87 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1); 169 88 my $disk_check = $ipprc->file_resolve($uri_check,1); … … 174 93 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it. 175 94 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. 95 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 96 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 97 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 98 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 99 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $chip_id, $PS_EXIT_SYS_ERROR, $fail_state); 100 185 101 my $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 104 my ($exp_id, $filter, $altfilt, $dateobs); 105 { 195 106 my $command = "$chiptool -listrun -chip_id $chip_id "; 196 107 $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); 200 111 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) 131 my %det_ids = (); 132 my %det_iters = (); 133 134 foreach 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); 247 208 } 248 209 } 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); 299 231 } 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 ";304 232 } 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 } 381 321 382 322 close(CONFIG); … … 386 326 close(GENERATE); 387 327 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 fill395 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 RESOURCES415 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 426 328 ## We're done here. The execution and handling are done elsewhere. 427 329 # Quick review: … … 429 331 # auth 430 332 unless($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"; 433 337 $command .= " -dbname $dbname " if defined $dbname; 434 338 435 339 system($command); 436 340 } 437 438 439 440 441 341 exit (0); 442 342 443 343 sub uri_convert { … … 445 345 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 446 346 my $remote_disk = $ipp_disk; 447 347 448 348 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); 450 350 } 451 351 … … 461 361 my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1); 462 362 my $remote_disk = $ipp_disk; 463 363 464 364 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); 466 366 } 467 367 … … 476 376 my $neb_uri = shift; 477 377 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"; 484 381 return($ipp_disk,$remote_disk); 485 382 } … … 489 386 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 490 387 $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"; 496 391 return($ipp_disk,$remote_disk); 497 392 } … … 500 395 my $neb_uri = shift; 501 396 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"; 507 399 return($ipp_disk,$remote_disk); 508 400 } … … 518 410 return($remote_uri); 519 411 } 520 412 521 413 sub uri_remote_to_local { 522 414 # This needs to replace the remote root directory with the nebulous tag. … … 524 416 $remote_uri =~ s%${remote_root}%%; 525 417 my $local_uri = "neb:///" . $remote_uri; 526 418 527 419 return($local_uri); 528 420 } 421 529 422 sub my_die { 530 423 my $msg = shift; 531 my $id = shift; 424 my $remote_id = shift; 425 my $stage_id = shift; 532 426 my $exit_code = shift; 533 427 my $exit_state = shift; … … 536 430 537 431 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); 546 439 } 547 440
Note:
See TracChangeset
for help on using the changeset viewer.
