Changeset 37278
- Timestamp:
- Aug 21, 2014, 10:02:07 AM (12 years ago)
- Location:
- tags/ipp-pv3-20140717/ippScripts/scripts
- Files:
-
- 1 added
- 1 edited
-
sc_prepare_chip.pl (modified) (16 diffs)
-
sc_prepare_run.pl (added)
Legend:
- Unmodified
- Added
- Removed
-
tags/ipp-pv3-20140717/ippScripts/scripts/sc_prepare_chip.pl
r37126 r37278 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/'; 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 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 = (); 24 my $threads_req = 4; 34 25 35 26 # Look for programs we need 36 27 my $missing_tools; 37 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);38 28 my $chiptool = can_run('chiptool') or (warn "Can't find chiptool" and $missing_tools = 1); 39 29 my $detselect= can_run('detselect') or (warn "Can't find detselect" and $missing_tools = 1); … … 46 36 47 37 # Options 48 my ($ exp_id,$exp_name,$remote_id,$chip_id,$detrends,$camera,$dbname,$verbose,$path_base,$no_update);38 my ($remote_id,$chip_id,$camera,$dbname,$path_base,$no_update,$verbose); 49 39 GetOptions( 50 40 'remote_id=s' => \$remote_id, 41 'chip_id=s' => \$chip_id, 51 42 'camera|c=s' => \$camera, 52 43 'dbname|d=s' => \$dbname, … … 57 48 58 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 59 pod2usage( -msg => "Required options: --remote_id --c amera --dbname --path_base", -exitval => 3) unless50 pod2usage( -msg => "Required options: --remote_id --chip_id --camera --dbname --path_base", -exitval => 3) unless 60 51 defined($remote_id) and 52 defined($chip_id) and 61 53 defined($camera) and 62 54 defined($path_base) and 63 55 defined($dbname); 56 64 57 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $exp_id); 65 58 66 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 67 60 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); 61 # Detrend concept holders (name, ppImage option) 62 my %det_types = ( 63 'MASK' => '-mask', 64 'FLAT' => '-flat', 65 'DARK' => '-dark', 66 'VIDEODARK' => '-dark', 67 'LINEARITY' => '-linearity', 68 'FRINGE' => '-fringe', 69 'NOISEMAP' => '-noisemap' 70 ); 155 71 156 72 my @return_component_list = ("DBINFO.IMFILE","PPIMAGE.STATS","LOG.IMFILE","PPIMAGE.BACKMDL","PPIMAGE.PATTERN"); 157 73 158 # 159 # Step 1b: Open output files 74 # STEP 0: Open output files 160 75 my $uri_command = $path_base . ".cmd"; 161 76 my $uri_transfer= $path_base . ".transfer"; … … 174 89 my (undef, $remote_config) = uri_convert($uri_config); # Needs to be done after we've created it. 175 90 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. 91 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$chip_id, $PS_EXIT_SYS_ERROR); 92 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $chip_id, $PS_EXIT_SYS_ERROR); 93 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $chip_id, $PS_EXIT_SYS_ERROR); 94 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$chip_id, $PS_EXIT_SYS_ERROR); 95 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $chip_id, $PS_EXIT_SYS_ERROR); 96 185 97 my $job_index = 0; 186 98 my @pre_commands = (); … … 188 100 my @post_commands = (); 189 101 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 # STEP 1 : Get exposure level information for this chipRun 103 my $exp_id, $filter, $altfilt, $dateobs; 104 { 195 105 my $command = "$chiptool -listrun -chip_id $chip_id "; 196 106 $command .= " -dbname $dbname " if defined($dbname); 197 107 198 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =108 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 199 109 run(command => $command, verbose => 0); 200 110 unless ($success) { … … 205 115 } 206 116 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; 247 } 248 } 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); 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.", $chip_id,$PS_EXIT_PROG_ERROR); 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 => 0); 260 146 unless ($success) { 261 147 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 262 148 149 &my_die("No valid detrend available for this image: $det_type", $chip_id, $error_code); 150 } 151 152 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 153 &my_die("Could not parse detrend information for this image: $det_type", $chip_id,$error_code); 154 my $metadata = parse_md_list($MDlist); 155 my $detEntry = $metadata[0]; 156 157 # save det_id and iteration 158 $det_ids{$det_type} = $detEntry->{det_id}; 159 $det_iters{$det_type} = $detEntry->{iteration}; 160 } 161 162 # Step 3: Iterate over the sub-components 163 { 164 # select chipProcessedImfile entries 165 my $command = "$chiptool -pendingimfile -chip_id $chip_id"; 166 $command .= " -dbname $dbname " if defined($dbname); 167 168 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 169 run(command => $command, verbose => $verbose); 170 171 unless ($success) { 172 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 173 263 174 &my_die("Unable to run chiptool -pendingimfile", 264 175 $chip_id,$error_code); 265 176 } 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) { 177 178 my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or 179 &my_die("Unable to parse chiptool -pendingimfile information.", $chip_id,$error_code); 180 my $metadata = parse_md_list($MDlist); 181 182 # Iterate over the chipProcessedImfile level data. 183 foreach my $chipEntry (@$metadata) { 275 184 # Get information we need to pass to ppImage 276 185 my $uri = $chipEntry->{uri}; … … 283 192 284 193 # Process the image and burntool table 285 my ($ipp_uri, $remote_uri) = uri_to_outputs_raw($uri);194 my ($ipp_uri, $remote_uri) = uri_to_outputs_raw($uri); 286 195 my $btt = $uri; 287 196 $btt =~ s/fits$/burn.tbl/; 288 my ($ipp_btt, $remote_btt) = uri_to_outputs_raw($btt);197 my ($ipp_btt, $remote_btt) = uri_to_outputs_raw($btt); 289 198 290 199 # Initialize the ppI command … … 292 201 $ppImage_command .= " -burntool $remote_btt "; 293 202 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; 203 foreach my $det_type (keys (%det_types)) { 204 if (( $video_cells) && ($det_type eq 'DARK')) next; 205 if ((!$video_cells) && ($det_type eq 'VIDEODARK')) next; 206 207 my $det_id = $det_ids{$det_type}; 208 my $det_iter = $det_iters{$det_type}; 209 210 # Add detrend information to the command line 211 my $detselect_command = "detselect -select "; 212 $detselect_command .= " -det_id $det_id"; 213 $detselect_command .= " -iteration $det_iter"; 214 $detselect_command .= " -class_id $class_id"; 215 $detselect_command .= " -dbname $dbname " if defined($dbname); 216 217 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 218 run(command => $detselect_command, verbose => 0); 219 220 unless ($success) { 221 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 222 223 &my_die("No valid detrend available for this image: $det_type $det_id $det_iter", 224 $chip_id,$error_code); 299 225 } 300 my $det_code = $det_types{$det}; 301 my $duri = $detrends_to_use{$det}->{$class_id}; 226 227 my $detMDlist = $mdcParser->parse(join "", @$stdout_buf) or 228 &my_die("Could not parse detrend information for this image: $det_type $det_id $det_iter", 229 $chip_id,$error_code); 230 my $detImfileMD = parse_md_list($detMDlist); 231 my $duri = $detImfileMD[0]->{uri}; 232 233 my $det_code = $det_types{$det_type}; 302 234 my ($ipp_det_uri, $remote_det_uri) = uri_to_outputs_raw($duri); 303 235 $ppImage_command .= " $det_code $remote_det_uri "; 304 236 } 305 306 237 307 238 # Add output root … … 318 249 $ppImage_command .= " -recipe PSPHOT $recipe_psphot "; 319 250 $ppImage_command .= " -recipe PPSTATS CHIPSTATS -stats ${remote_outroot}.${class_id}.stats "; 320 $ppImage_command .= " -threads 4";251 $ppImage_command .= " -threads $threads_req "; 321 252 $ppImage_command .= " -image_id $chip_imfile_id "; 322 253 $ppImage_command .= " -tracedest ${remote_outroot}.${class_id}.trace "; … … 342 273 343 274 print CONFIG "${pre_command} && ${ppImage_command} && ${post_commandB} && ${post_commandC}"; 344 345 275 346 276 # Determine which output files need to be returned. … … 354 284 # die; 355 285 } 356 357 286 print CONFIG "\n"; 358 287 } 359 288 } 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 # }381 289 382 290 close(CONFIG); … … 386 294 close(GENERATE); 387 295 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 296 ## We're done here. The execution and handling are done elsewhere. 427 297 # Quick review: … … 429 299 # auth 430 300 unless($no_update) { 431 my $command = "remotetool -updaterun -remote_id $remote_id "; 432 $command .= " -set_state pending "; 301 my $command = "remotetool -updatecomponent -remote_id $remote_id -stage_id $chip_id "; 302 $command .= " -set_jobs $job_index"; 303 $command .= " -set_path_base $path_base"; 304 $command .= " -set_state prep_done"; 433 305 $command .= " -dbname $dbname " if defined $dbname; 434 306 … … 436 308 } 437 309 438 439 440 441 310 exit (0); 442 311 443 312 sub uri_convert { … … 537 406 carp($msg); 538 407 408 I need stage id here 409 410 539 411 if (defined $id and not $no_update) { 540 my $command = "remotetool -update run-remote_id $id";412 my $command = "remotetool -updatecomponent -remote_id $id"; 541 413 $command .= " -fault $exit_code " if defined $exit_code; 542 414 $command .= " -set_state $exit_state " if defined $exit_state;
Note:
See TracChangeset
for help on using the changeset viewer.
