Changeset 37833 for trunk/ippScripts/scripts/sc_prepare_camera.pl
- Timestamp:
- Jan 12, 2015, 12:53:36 PM (11 years ago)
- Location:
- trunk/ippScripts/scripts
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
sc_prepare_camera.pl (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts
- Property svn:mergeinfo set to
-
trunk/ippScripts/scripts/sc_prepare_camera.pl
r37125 r37833 1 1 #! /usr/bin/env perl 2 3 # generate the input & output files lists and commands for a single camRun 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 $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 22 my $remote_root = '/scratch3/watersc1/'; # Far side destination base location 23 my $remote_hostname = "LANL/Mustang"; # Name of the remote node. 24 my $threads_req = 0; # How many threads are we going to use? 25 26 my $fail_state = "prep_fail"; 27 32 28 # Look for programs we need 33 29 my $missing_tools; 34 35 30 my $remotetool = can_run('remotetool') or (warn "Can't find remotetool" and $missing_tools = 1); 36 31 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); … … 41 36 } 42 37 43 my ($remote_id,$cam_id, ,$camera,$dbname,$verbose,$path_base,$no_update);38 my ($remote_id,$cam_id,$camera,$dbname,$verbose,$path_base,$no_update); 44 39 GetOptions( 45 40 'remote_id=s' => \$remote_id, 41 'cam_id=s' => \$cam_id, 46 42 'camera|c=s' => \$camera, 47 43 'dbname|d=s' => \$dbname, … … 52 48 53 49 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 54 pod2usage( -msg => "Required options: --remote_id --cam era --dbname --path_base", -exitval => 3) unless50 pod2usage( -msg => "Required options: --remote_id --cam_id --camera --dbname --path_base", -exitval => 3) unless 55 51 defined($remote_id) and 52 defined($cam_id) and 56 53 defined($camera) and 57 54 defined($path_base) and 58 55 defined($dbname); 59 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $remote_id); 56 57 my $ipprc = PS::IPP::Config->new( $camera ) or &my_die( "Unable to set up", $remote_id, $cam_id, $PS_EXIT_CONFIG_ERROR, $fail_state); 60 58 61 59 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 62 60 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"; 61 my @return_component_list = ("DBINFO.EXP", "PSASTRO.CONFIG", "PSASTRO.OUTPUT", "LOG.EXP", "PSASTRO.STATS"); 62 63 # STEP 0: Open output files 85 64 my $uri_transfer= $path_base . ".transfer"; 86 65 my $uri_check = $path_base . ".check"; … … 89 68 my $uri_return = $path_base . ".return"; 90 69 91 my $disk_command = $ipprc->file_resolve($uri_command,1);92 70 my $disk_transfer= $ipprc->file_resolve($uri_transfer,1); 93 71 my $disk_check = $ipprc->file_resolve($uri_check,1); … … 96 74 my $disk_return = $ipprc->file_resolve($uri_return,1); 97 75 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);76 my (undef, $remote_config) = &uri_convert($uri_config); # Needs to be done after we've created it. 77 78 open(TRANSFER, ">$disk_transfer") || &my_die("Couldn't open file? $disk_transfer",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 79 open(CHECK, ">$disk_check") || &my_die("Couldn't open file? $disk_check", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 80 open(CONFIG, ">$disk_config") || &my_die("Couldn't open file? $disk_config", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 81 open(GENERATE, ">$disk_generate") || &my_die("Couldn't open file? $disk_generate",$remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 82 open(RETURN, ">$disk_return") || &my_die("Couldn't open file? $disk_return", $remote_id, $cam_id, $PS_EXIT_SYS_ERROR, $fail_state); 105 83 my %file_filter = (); 106 84 107 #108 # Step 2: Iterate over all componenets in this remote run.109 85 my $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 88 my ($workdir,$exp_tag,$reduction); 89 { 119 90 my $command = "$camtool -pendingexp -cam_id $cam_id "; 120 91 $command .= " -dbname $dbname " if defined($dbname); 121 92 122 93 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 123 94 run(command => $command, verbose => 0); 124 95 unless ($success) { 125 96 $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) or132 &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; 139 110 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 119 my $ipp_outroot = "${workdir}/${exp_tag}/${exp_tag}.cm.${cam_id}"; 120 my $remote_outroot = uri_local_to_remote($ipp_outroot); 121 152 122 # 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); 159 129 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 } 165 133 166 134 # 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) or168 &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]; 172 140 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 ); 174 142 my $pre_cmd_cmfs = "ls -1 ${remote_chip_path}*.cmf > ${remote_outroot}.cmflist"; 175 143 my $pre_cmd_masks= "ls -1 ${remote_chip_path}*.mk.fits > ${remote_outroot}.masklist"; 176 144 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 } 179 149 180 150 my $psastro_command = " psastro -list ${remote_outroot}.cmflist "; 181 151 $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 this152 # $psastro_command .= " -refmasklist ${remote_outroot}.masklist ${remote_outroot} "; 153 $psastro_command .= " -refmasklist /turquoise/usr/projects/ps1/watersc1/references/gpc1.refmask.list "; 184 154 $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 "; 187 156 $psastro_command .= " -astrommodel /turquoise/usr/projects/ps1/watersc1/references/gpc1.20140505.asm "; 188 157 $psastro_command .= " -recipe PSASTRO $recipe_psastro "; … … 190 159 $psastro_command .= " -dumpconfig ${remote_outroot}.psastro.mdc -stats ${remote_outroot}.stats "; 191 160 $psastro_command .= " -recipe PPSTATS CAMSTATS "; 192 161 193 162 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 "; 195 165 my $post_cmd_echo = " echo -n \"$camtool_post_cmd\" > ${remote_outroot}.dbinfo "; 196 166 my $post_cmd_SfM = " ppStatsFromMetadata ${remote_outroot}.stats - CAMERA_EXP_FPA >> ${remote_outroot}.dbinfo "; … … 201 171 # Determine which output files need to be returned 202 172 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 "; 213 183 } 214 184 print CONFIG "\n"; … … 220 190 close(GENERATE); 221 191 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 fill229 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 RESOURCES249 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 258 192 unless($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; 263 198 system($command); 264 199 } 265 200 201 exit (0); 266 202 267 203 ## Common SC routines … … 271 207 my $ipp_disk= $ipprc->file_resolve( $neb_uri ); 272 208 my $remote_disk = $ipp_disk; 273 209 274 210 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); 276 212 } 277 213 … … 287 223 my $ipp_disk= $ipprc->file_resolve( $neb_uri , 1); 288 224 my $remote_disk = $ipp_disk; 289 225 290 226 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); 292 228 } 293 229 … … 302 238 my $neb_uri = shift; 303 239 my ($ipp_disk, $remote_disk) = uri_convert( $neb_uri ); 304 240 305 241 unless (exists($file_filter{$neb_uri})) { 306 242 $file_filter{$neb_uri} = 1; … … 332 268 return($remote_uri); 333 269 } 334 270 335 271 sub uri_remote_to_local { #(local_neb_uri) = uri_remote_to_local(remote_uri); 336 272 # This needs to replace the remote root directory with the nebulous tag. … … 338 274 $remote_uri =~ s%${remote_root}%%; 339 275 my $local_uri = "neb:///" . $remote_uri; 340 276 341 277 return($local_uri); 342 278 } … … 345 281 sub my_die { # exit with status; my_die(message,stage_id,exit_code,exit_status); 346 282 my $msg = shift; 347 my $id = shift; 283 my $remote_id = shift; 284 my $stage_id = shift; 348 285 my $exit_code = shift; 349 286 my $exit_state = shift; … … 352 289 353 290 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"; 358 294 $command .= " -set_state $exit_state " if defined $exit_state; 359 295 $command .= " -dbname $dbname " if defined $dbname;
Note:
See TracChangeset
for help on using the changeset viewer.
