Changeset 38578
- Timestamp:
- Jul 7, 2015, 4:53:55 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/addstar_multi_run.pl (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/addstar_multi_run.pl
r38479 r38578 39 39 my $minidvodb_path; 40 40 41 my ( $ add_id, $camera, $stage, $stage_id, $stage_extra1, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update,41 my ( $label,$camera, $stage, $stage_id, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update, 42 42 $no_op, $redirect, $save_temps); 43 43 GetOptions( 44 ' add_id=s' => \$add_id, # Camtool identifier44 'label=s' => \$label, #addstar label 45 45 'camera|c=s' => \$camera, # Camera 46 46 'stage|s=s' => \$stage, # Camera 47 47 'stage_id|w=s' => \$stage_id, 48 'stage_extra1|w=s' => \$stage_extra1, # the number for a staticskymulti (for finding cmf), or stack_id49 48 'dbname|d=s' => \$dbname, # Database name 50 49 'outroot|w=s' => \$outroot, # output file base name … … 65 64 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 66 65 pod2usage( 67 -msg => "Required options: -- add_id --camera --outroot --dvodb --stageroot --stage",66 -msg => "Required options: --label --stage_id --stage --camera --outroot --dvodb --stageroot", 68 67 -exitval => 3, 69 68 ) unless 70 69 defined $stage and 71 defined $add_id and 70 defined $stage_id and 71 defined $label and 72 72 defined $outroot and 73 73 defined $stageroot and 74 74 defined $dvodb and 75 75 defined $camera; 76 if ($stage =~ /cam/ && !defined $stage_id) { 77 my_die("cam stage requires -stage_id", $add_id, 3); 78 79 } 76 80 77 if ($minidvodb && !defined($minidvodb_group)) { 81 my_die( "missing minidvodb_group", $ add_id, 3 );78 my_die( "missing minidvodb_group", $stage_id, $stage, $label, 3 ); 82 79 } 83 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $add_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 84 85 my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 86 80 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $stage_id, $stage, $label, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 81 82 my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $stage_id, $stage, $label, $PS_EXIT_CONFIG_ERROR); 83 84 #my $logDest = "stuff.txt"; 87 85 if ($redirect) { 88 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $ add_id, $PS_EXIT_SYS_ERROR );86 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $stage_id,$stage, $label, $PS_EXIT_SYS_ERROR ); 89 87 print "\n\n"; 90 88 print "Starting script $0 on $host\n\n"; … … 94 92 # Recipes to use based on reduction class 95 93 $reduction = 'DEFAULT' unless defined $reduction; 96 #if ($stage =~/diff/) {97 # $reduction = 'ADDSTAR';98 #}99 #if ($stage =~/fullforce/) {100 # $reduction = 'ADDSTAR';101 #}102 94 103 95 if ($stage =~/fullforce/) { … … 111 103 112 104 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); 113 # XXX This is now not used: do we still need it? 114 if ($stage =~/cam/) { 115 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use 116 } 117 if ($stage =~/stack/) { 118 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STACK'); # Recipe to use 119 } 120 #if ($stage =~/staticsky/) { 121 # $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STATICSKY'); # Recipe to use 122 #} 123 if ($stage =~/skycal/) { 124 $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use 125 } 126 127 128 129 &my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar; 105 106 &my_die("Unrecognised ADDSTAR recipe", $stage_id, $stage, $label, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar; 130 107 131 108 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 132 109 133 # Output products 134 $ipprc->outroot_prepare($outroot); 135 136 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs 137 138 # it was PSASTRO.OUTPUT 139 140 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT", $stageroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 141 my $fpaObjectsAlt = $fpaObjects; 142 143 if ($stage =~ /skycal/) { 144 #should be ok for skycal? 145 print "using $fpaObjects for $stage\n"; 146 } 147 if ($stage =~/diff/) { 148 print "using $fpaObjects for $stage\n"; 149 } 150 if ($stage =~/fullforce/) { 151 print "using $fpaObjects for $stage\n"; 152 } 153 154 155 156 if ($stage =~ /cam/) { 157 # if it is cam stage we need to be careful when grabbing the filename. 158 # This breaks down into a few steps: 159 160 #get info about the cam_id 161 my $magicked; 162 { 163 my $mdcParser = PS::IPP::Metadata::Config->new; 164 my $command = "$camtool -processedexp -cam_id " . $stage_id; 165 $command .= " -dbname $dbname" if defined $dbname; 110 my $temp_file = $outroot.".log.".$label.".".$stage.".".$stage_id.".list"; 111 my $temp_file = "/tmp/addstar.list"; 112 113 print "using $temp_file for list\n"; 114 115 open( TEMPLIST, ">$temp_file") or &my_die( "Can't open $temp_file\n", $stage_id,$stage,$label, $PS_EXIT_UNKNOWN_ERROR); 116 117 { 118 my $mdcParser = PS::IPP::Metadata::Config->new; 119 my $command = "$addtool -pendingexp -stage_id ".$stage_id; 120 $command .= " -stage $stage -label $label"; 121 $command .= " -dbname $dbname" if defined $dbname; 122 166 123 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 167 124 run(command => $command, verbose => $verbose); 168 &my_die( "Unable to get info on camRun", $add_id, $PS_EXIT_SYS_ERROR) unless $success; 169 if (scalar @$stdout_buf == 0 ) { #it lists nothing if it is the first 170 &my_die( "empty camRun", $add_id, $PS_EXIT_SYS_ERROR); 171 print "listing nothing\n"; 172 } else { 173 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 174 &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR); 175 #this fails if there is nothing listed. I checked. 176 my $components = parse_md_list($metadata) or 177 &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR); 178 my $comp = $$components[0]; 179 my $mparsed = $comp->{magicked}; 180 181 if (!defined($mparsed)) { 182 &my_die("Unable to parse magicked", $add_id, $PS_EXIT_PROG_ERROR); 183 } #but just to make sure, have it grab a minidvodb_name, to make sure it's not junk. 184 print "found a value for magicked:$mparsed\n"; 185 $magicked = $mparsed; 186 } 187 188 #is this cam_id magicked or not? 189 if ($magicked) { 190 $stage_extra1 = $magicked; 191 $fpaObjects = $ipprc->destreaked_filename("$fpaObjects") or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 192 print "cam_id is magicked, using $fpaObjects for the cam smf\n"; 193 } else { 194 print "cam_id is NOT magicked, using $fpaObjects for the cam smf\n"; 195 } 196 } 197 } 198 199 if (($stage =~/stack/ || $stage =~ /skycal/ || $stage =~/diff/ || $stage=~/fullforce/)) { 200 $fpaObjects =~ s/smf$/cmf/; 201 $fpaObjectsAlt =~ s/smf$/cmf/; 202 203 } 204 205 my $fpaObjects1; 206 my $fpaObjects2; 207 my $checkalt = 0; 208 if ($stage =~/staticsky/) { 209 $checkalt = 1; 210 my $sources = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $stageroot); #this is mostly rigtht except the .cmf needs either 211 # .000.cmf or .stk.xxxxx.cmf 212 print "$sources\n\n\n"; 213 &my_die( "can't find the filter_num for staticsky_multi, giving up.", $add_id, $PS_EXIT_SYS_ERROR) unless (defined $stage_extra1); 214 215 216 $fpaObjects1 = $sources; 217 $fpaObjects2 = $sources; 218 $fpaObjects = $sources; 219 220 my $nice_num = sprintf ("%03d", $stage_extra1); 221 222 $fpaObjects1 =~ s/cmf$/stk.$stage_extra1.cmf/; 223 $fpaObjects2 =~ s/cmf$/$nice_num.cmf/; #this make it look for .001.cmf, etc 224 # we have 3 of them to try 225 my $realFile = $ipprc->file_resolve($fpaObjects); 226 my $realFile1 = $ipprc->file_resolve($fpaObjects1); 227 my $realFile2 = $ipprc->file_resolve($fpaObjects2); 228 if (!defined($realFile1)) { 229 if (!defined($realFile2)) { 230 print "using $fpaObjects\n"; 231 232 } else { 233 print "using $fpaObjects2\n"; 234 $fpaObjects = $fpaObjects2; 235 } 125 &my_die( "Unable to get info on addRun", $stage_id,$stage, $label, $PS_EXIT_SYS_ERROR) unless $success; 126 if (scalar @$stdout_buf == 0 ) { #it lists nothing if it is the first 127 &my_die( "empty addRun", $stage_id,$stage,$label, $PS_EXIT_SYS_ERROR); 236 128 237 129 } else { 238 print "using $fpaObjects1\n"; 239 $fpaObjects = $fpaObjects1; 240 } 241 242 243 } 244 245 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 246 130 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 131 &my_die("Unable to parse metadata config", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 132 #this fails if there is nothing listed. I checked. 133 my $components = parse_md_list($metadata) or 134 &my_die("Unable to parse metadata list", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 135 my $num_components = scalar @$components; 136 print "there are $num_components\n"; 137 foreach my $comp (@$components) { 138 my $mparsed = $comp->{stageroot}; 139 140 if (!defined($mparsed)) { 141 &my_die("Unable to parse stageroot", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 142 } #but just to make sure, have it grab a minidvodb_name, to make sure it's not junk. 143 print "found a value for stageroot:$mparsed\n"; 144 my $fpaObjects = $mparsed.'.cmf'; 145 my $realFile = $ipprc->file_resolve($fpaObjects); 146 if (!defined($realFile)) { 147 &my_die("unable to resolve real file from $mparsed",$stage_id, $stage, $label, 7); 148 } 149 printf TEMPLIST "$realFile = $fpaObjects\n"; 150 } 151 } 152 153 } 154 155 close(TEMPLIST); 156 print "saved $temp_file here\n"; 157 247 158 # convert supplied DVO database name to UNIX filename 248 159 my $dvodbReal; 249 160 if (defined $dvodb) { 250 161 $dvodbReal = $ipprc->dvo_catdir( $dvodb ); # catdir for DVO 251 $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $ add_id, $PS_EXIT_CONFIG_ERROR);162 $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $stage_id,$stage,$label, $PS_EXIT_CONFIG_ERROR); 252 163 } 253 164 my $dtime_addstar = 0; … … 262 173 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 263 174 run(command => $command, verbose => $verbose); 264 &my_die( "Unable to get active minidvodb_name", $ add_id, $PS_EXIT_SYS_ERROR) unless $success;175 &my_die( "Unable to get active minidvodb_name", $stage_id,$stage,$label, $PS_EXIT_SYS_ERROR) unless $success; 265 176 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 266 &my_die("Unable to parse metadata config", $ add_id, $PS_EXIT_PROG_ERROR);177 &my_die("Unable to parse metadata config", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 267 178 268 179 my $components = parse_md_list($metadata) or 269 &my_die("Unable to parse metadata list", $ add_id, $PS_EXIT_PROG_ERROR);180 &my_die("Unable to parse metadata list", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 270 181 my $comp = $$components[0]; 271 182 $minidvodb_path = $comp->{minidvodb_path}; … … 273 184 274 185 if (!defined($minidvodb_path)) { 275 &my_die("Unable to parse minidvodb_path", $ add_id, $PS_EXIT_PROG_ERROR);186 &my_die("Unable to parse minidvodb_path", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 276 187 } 277 188 if (!defined($minidvodb_name)) { 278 &my_die("Unable to parse minidvodb_name", $ add_id, $PS_EXIT_PROG_ERROR);189 &my_die("Unable to parse minidvodb_name", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR); 279 190 } 280 191 } … … 296 207 my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar 297 208 298 my $realFile = $ipprc->file_resolve($fpaObjects) or &my_die("Unable to resolve $fpaObjects", $add_id, $PS_EXIT_SYS_ERROR);209 # my $realFile = $ipprc->file_resolve($fpaObjects) or &my_die("Unable to resolve $fpaObjects", $stage_id,$stage,$label, $PS_EXIT_SYS_ERROR); 299 210 300 211 # most cameras use CHIP_HEADER. other exceptions: … … 316 227 $command .= " -D CATDIR $minidvodb_path"; 317 228 $command .= " -D ZERO_POINT_OPTION $zeroPointOption"; 318 $command .= " $realFile"; 319 $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference 229 $command .= " -list $temp_file"; 320 230 $command .= " -image" if $image_only; 321 231 if ($stage =~ /staticsky/) { … … 338 248 unless ($success) { 339 249 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 340 &my_die("Unable to perform addstar: $error_code", $ add_id, $error_code);250 &my_die("Unable to perform addstar: $error_code", $stage_id,$stage,$label, $error_code); 341 251 } 342 252 $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start); # MJD of starting script … … 344 254 } 345 255 346 # This needs to be updated when addtool is written. BROKEN 347 my $fpaCommand = "$addtool -add_id $add_id"; 256 257 my $fpaCommand = "$addtool -multiadd -stage_id $stage_id"; 258 $fpaCommand .= " -stage $stage"; 259 $fpaCommand .= " -multiaddlabel $label"; 348 260 $fpaCommand .= " -addprocessedexp"; 349 261 $fpaCommand .= " -path_base $outroot"; … … 351 263 $fpaCommand .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path; 352 264 $fpaCommand .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; 353 $fpaCommand .= " -stage_extra1 $stage_extra1" if defined $stage_extra1;354 265 $fpaCommand .= " -dbname $dbname" if defined $dbname; 355 266 print $fpaCommand; … … 371 282 { 372 283 my $msg = shift; # Warning message on die 373 my $add_id = shift; # Camtool identifier 284 my $stage_id = shift; # Camtool identifier 285 my $stage = shift; 286 my $label = shift; 374 287 my $exit_code = shift; # Exit code to add 375 288 … … 377 290 378 291 carp($msg); 379 if (defined $ add_id and not $no_update) {380 my $command = "$addtool - add_id $add_id";292 if (defined $stage_id and not $no_update) { 293 my $command = "$addtool -stage_id $stage_id"; 381 294 $command .= " -addprocessedexp"; 382 295 $command .= " -fault $exit_code"; 296 $command .= " -stage $stage"; 297 $command .= " -label $label"; 383 298 $command .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path; 384 299 $command .= " -path_base $outroot" if defined $outroot; 385 300 $command .= (" -dtime_addstar " . ((DateTime->now->mjd - $mjd_start) * 86400)); 386 301 # $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; don't think we want it recorded (not sure) 387 $command .= " -stage_extra1 $stage_extra1" if defined $stage_extra1;388 302 $command .= " -dbname $dbname" if defined $dbname; 389 303 print $command;
Note:
See TracChangeset
for help on using the changeset viewer.
