- Timestamp:
- Mar 30, 2012, 2:49:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/ippScripts/scripts/addstar_run.pl
r32851 r33638 30 30 my $missing_tools; 31 31 my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1); 32 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1); 32 33 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 33 34 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1); … … 37 38 } 38 39 my $minidvodb_path; 39 my ( $add_id, $camera, $stage, $multi_num, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update, 40 my $stage_extra1 ; 41 my ( $add_id, $camera, $stage, $stage_id, $multi_num, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update, 40 42 $no_op, $redirect, $save_temps); 41 43 GetOptions( … … 43 45 'camera|c=s' => \$camera, # Camera 44 46 'stage|s=s' => \$stage, # Camera 47 'stage_id|w=s' => \$stage_id, 45 48 'multi_num|w=s' => \$multi_num, # the number for a staticskymulti (for finding cmf) 46 49 'dbname|d=s' => \$dbname, # Database name … … 71 74 defined $dvodb and 72 75 defined $camera; 76 if ($stage =~ /cam/ && !defined $stage_id) { 77 my_die("cam stage requires -stage_id", $add_id, 3); 78 79 } 73 80 if ($minidvodb && !defined($minidvodb_group)) { 74 81 my_die( "missing minidvodb_group", $add_id, 3 ); … … 108 115 109 116 # it was PSASTRO.OUTPUT 110 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT", $stageroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 111 117 118 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT", $stageroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 119 my $fpaObjectsAlt = $fpaObjects; 120 121 122 if ($stage =~ /cam/) { 123 # if it is cam stage we need to be careful when grabbing the filename. 124 # This breaks down into a few steps: 125 126 #get info about the cam_id 127 my $magicked; 128 { 129 my $mdcParser = PS::IPP::Metadata::Config->new; 130 my $command = "$camtool -processedexp -cam_id " . $stage_id; 131 $command .= " -dbname $dbname" if defined $dbname; 132 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 133 run(command => $command, verbose => $verbose); 134 &my_die( "Unable to get info on camRun", $add_id, $PS_EXIT_SYS_ERROR) unless $success; 135 if (scalar @$stdout_buf == 0 ) { #it lists nothing if it is the first 136 &my_die( "empty camRun", $add_id, $PS_EXIT_SYS_ERROR); 137 print "listing nothing\n"; 138 } else { 139 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 140 &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR); 141 #this fails if there is nothing listed. I checked. 142 my $components = parse_md_list($metadata) or 143 &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR); 144 my $comp = $$components[0]; 145 my $mparsed = $comp->{magicked}; 146 147 if (!defined($mparsed)) { 148 &my_die("Unable to parse magicked", $add_id, $PS_EXIT_PROG_ERROR); 149 } #but just to make sure, have it grab a minidvodb_name, to make sure it's not junk. 150 print "found a value for magicked:$mparsed\n"; 151 $magicked = $mparsed; 152 } 153 154 #is this cam_id magicked or not? 155 if ($magicked) { 156 $stage_extra1 = $magicked; 157 $fpaObjects = $ipprc->destreaked_filename("$fpaObjects") or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 158 print "cam_id is magicked, using $fpaObjects for the cam smf\n"; 159 } else { 160 print "cam_id is NOT magicked, using $fpaObjects for the cam smf\n"; 161 } 162 } 163 } 112 164 if (($stage =~/staticsky/) || ($stage =~/stack/)) { 113 165 $fpaObjects =~ s/smf$/cmf/; 114 115 } 116 117 if ($stage =~/staticsky _multi/) {166 $fpaObjectsAlt =~ s/smf$/cmf/; 167 } 168 my $checkalt = 0; 169 if ($stage =~/staticsky/) { 118 170 $fpaObjects =~ s/smf$/cmf/; #this should do nothing because it was already modded above 119 171 &my_die( "can't find the filter_num for staticsky_multi, giving up.", $add_id, $PS_EXIT_SYS_ERROR) unless (defined $multi_num); 120 172 my $nice_num = sprintf ("%03d", $multi_num); 121 173 $fpaObjects =~ s/cmf$/$nice_num.cmf/; #this make it look for .001.cmf, etc 122 174 if ($multi_num == 0) { 175 $checkalt =1 ; #if it's staticsky and multi_num = 0 there's an alternate file to try if this one doesn't work 176 } 123 177 } 124 178 125 179 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR); 126 180 127 181 # convert supplied DVO database name to UNIX filename 128 182 my $dvodbReal; … … 131 185 $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $add_id, $PS_EXIT_CONFIG_ERROR); 132 186 } 133 134 135 136 137 187 my $dtime_addstar = 0; 138 139 188 if (defined $dvodbReal) { 140 if ($minidvodb) { 141 142 #if (!defined($minidvodb_name)) { 143 #take the active one, if it's not defined on the command line 144 #reverts would have this already set, for example. 145 my $command = "addtool -listminidvodbrun "; 146 $command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group; 147 $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; 148 $command .= " -state 'active' -limit 1"; 149 $command .= " -dbname $dbname" if defined $dbname; 150 print $command; 151 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 152 run(command => $command, verbose => $verbose); 153 &my_die( "Unable to get active minidvodb_name", $add_id, $PS_EXIT_SYS_ERROR) unless $success; 154 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 155 &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR); 156 157 my $components = parse_md_list($metadata) or 158 &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR); 159 my $comp = $$components[0]; 160 $minidvodb_path = $comp->{minidvodb_path}; 161 $minidvodb_name = $comp->{minidvodb_name}; 162 163 if (!defined($minidvodb_path)) { 164 &my_die("Unable to parse minidvodb_path", $add_id, $PS_EXIT_PROG_ERROR); 165 } 166 if (!defined($minidvodb_name)) { 167 &my_die("Unable to parse minidvodb_name", $add_id, $PS_EXIT_PROG_ERROR); 168 } 169 #} 170 # tack on the minidvodb part to the db. 171 # $dvodbReal = $dvodbReal . '/' . $minidvodb_name . '/'; 172 #we don't need this now that I fixed the paths 173 174 } 175 else { 176 177 $minidvodb_path = $dvodbReal; 178 } 179 180 unless ($no_op) { 189 if ($minidvodb) { 190 my $command = "addtool -listminidvodbrun "; 191 $command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group; 192 $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; 193 $command .= " -state 'active' -limit 1"; 194 $command .= " -dbname $dbname" if defined $dbname; 195 print $command; 196 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 197 run(command => $command, verbose => $verbose); 198 &my_die( "Unable to get active minidvodb_name", $add_id, $PS_EXIT_SYS_ERROR) unless $success; 199 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 200 &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR); 201 202 my $components = parse_md_list($metadata) or 203 &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR); 204 my $comp = $$components[0]; 205 $minidvodb_path = $comp->{minidvodb_path}; 206 $minidvodb_name = $comp->{minidvodb_name}; 207 208 if (!defined($minidvodb_path)) { 209 &my_die("Unable to parse minidvodb_path", $add_id, $PS_EXIT_PROG_ERROR); 210 } 211 if (!defined($minidvodb_name)) { 212 &my_die("Unable to parse minidvodb_name", $add_id, $PS_EXIT_PROG_ERROR); 213 } 214 } 215 else { 216 $minidvodb_path = $dvodbReal; 217 } 218 219 unless ($no_op) { 181 220 print $dvodbReal; 182 183 ## addstar can either save the full set of detections, or just 184 ## the image metadata, in the dvodb. this is set in the 185 ## database table addRun 186 187 # addstar requires the user to have a valid .ptolemyrc which 188 # in turn points at ippconfig/dvo.site 189 190 # get the names for the camera and the real input file 191 my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar 192 my $realFile = $ipprc->file_resolve($fpaObjects) or &my_die("Unable to resolve $fpaObjects", $add_id, $PS_EXIT_SYS_ERROR); 193 194 # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default) 195 my $command = "$addstar -update"; # XXX optionally set -update? 196 $command .= " -D CAMERA $camdir"; 197 $command .= " -D CATDIR $minidvodb_path"; 198 $command .= " $realFile"; 199 $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference 221 222 ## addstar can either save the full set of detections, or just 223 ## the image metadata, in the dvodb. this is set in the 224 ## database table addRun 225 226 # addstar requires the user to have a valid .ptolemyrc which 227 # in turn points at ippconfig/dvo.site 228 229 # get the names for the camera and the real input file 230 my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar 231 232 my $realFile = $ipprc->file_resolve($fpaObjects); 233 if (!defined($realFile)) { 234 print "can't find $fpaObjects\n"; 235 if ($checkalt) { 236 $realFile = $ipprc->file_resolve($fpaObjectsAlt) or &my_die("Unable to resolve $fpaObjectsAlt", $add_id, $PS_EXIT_SYS_ERROR); 237 $fpaObjects = $fpaObjectsAlt; # want to make sure the correct value is used. 238 } else { 239 # try the 'good one' again and fail i 240 #$realFile = $ipprc->file_resolve($fpaObjects) or 241 &my_die("Unable to resolve $fpaObjects", $add_id, $PS_EXIT_SYS_ERROR); 242 } 243 244 } 245 246 # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default) 247 my $command = "$addstar -update"; # XXX optionally set -update? 248 $command .= " -D CAMERA $camdir"; 249 $command .= " -D CATDIR $minidvodb_path"; 250 $command .= " $realFile"; 251 $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference 200 252 $command .= " -image" if $image_only; 201 253 if ($stage =~ /staticsky/) { 202 254 $command .= " -accept-astrom "; 203 255 } #careful here - this matches staticsky and staticsky_multi 204 my $mjd_addstar_start = DateTime->now->mjd; # MJD of starting script205 206 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =207 run(command => $command, verbose => $verbose);208 unless ($success) {209 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);210 &my_die("Unable to perform addstar: $error_code", $add_id, $error_code);211 }212 $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start); # MJD of starting script256 my $mjd_addstar_start = DateTime->now->mjd; # MJD of starting script 257 258 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 259 run(command => $command, verbose => $verbose); 260 unless ($success) { 261 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 262 &my_die("Unable to perform addstar: $error_code", $add_id, $error_code); 263 } 264 $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start); # MJD of starting script 213 265 } 214 266 } … … 221 273 $fpaCommand .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path; 222 274 $fpaCommand .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; 275 $fpaCommand .= " -stage_extra1 $stage_extra1" if defined $stage_extra1; 223 276 $fpaCommand .= " -dbname $dbname" if defined $dbname; 224 277 print $fpaCommand; … … 253 306 $command .= " -path_base $outroot" if defined $outroot; 254 307 $command .= (" -dtime_addstar " . ((DateTime->now->mjd - $mjd_start) * 86400)); 255 $fpaCommand .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; 308 # $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; don't think we want it recorded (not sure) 309 $command .= " -stage_extra1 $stage_extra1" if defined $stage_extra1; 256 310 $command .= " -dbname $dbname" if defined $dbname; 311 print $command; 257 312 system ($command); 258 313 }
Note:
See TracChangeset
for help on using the changeset viewer.
