- Timestamp:
- Jan 11, 2012, 11:19:21 PM (15 years ago)
- Location:
- branches/meh_branches/ppsub_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/videophot_process.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppsub_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppsub_test/ippScripts/scripts/videophot_process.pl
r32125 r33098 8 8 my $host = hostname(); 9 9 my $date = `date`; 10 print "\n\n";11 print "Starting script $0 on $host at $date\n\n";12 13 10 use DateTime; 14 11 my $mjd_start = DateTime->now->mjd; # MJD of starting script … … 25 22 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 26 23 use Pod::Usage qw( pod2usage ); 24 use File::Temp qw( tempfile ); 25 use File::Basename qw( basename ); 27 26 28 27 # Look for programs we need 29 28 my $missing_tools; 30 29 my $vptool = can_run('vptool') or (warn "Can't find vptool" and $missing_tools = 1); 31 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);32 30 my $psvideophot = can_run('psvideophot') or (warn "Can't find psvideophot" and $missing_tools = 1); 31 my $dumpvideo = can_run('dumpvideo') or (warn "Can't find dumpvideo" and $missing_tools = 1); 33 32 my $listvideocells = can_run('listvideocells.pl') or (warn "Can't find listvideocells.pl" and $missing_tools = 1); 33 my $dsreg = can_run('dsreg') or (warn "Can't find dsreg" and $missing_tools = 1); 34 my $nebrepair = can_run('neb-repair') or (warn "Can't find neb-repair" and $missing_tools = 1); 34 35 if ($missing_tools) { 35 36 warn("Can't find required tools."); 36 37 exit($PS_EXIT_CONFIG_ERROR); 37 38 } 38 my ($vp_id, $exp_id, $camera, $outroot, $dbname, $verbose, $no_update, $no_op, $redirect); 39 my ($vp_id, $camera, $outroot, $dest_id, $dbname, $verbose, $no_update, $no_op, $redirect, $save_temps); 40 my ($product, $save_video_cube, $ds_dbname, $ds_dbhost); 39 41 40 42 GetOptions( 41 43 'vp_id=s' => \$vp_id, 42 'exp_id=s' => \$exp_id,43 44 'camera=s' => \$camera, 44 45 'outroot=s' => \$outroot, 46 'dest_id=s' => \$dest_id, 47 'product=s' => \$product, 48 'save-video-cube' => \$save_video_cube, 49 'ds_dbname=s' => \$ds_dbname, 50 'ds_dbhost=s' => \$ds_dbhost, 45 51 'dbname|d=s' => \$dbname, 46 52 'verbose' => \$verbose, 53 'save-temps' => \$save_temps, 47 54 'no-update' => \$no_update, # Don't update the database? 48 55 'no-op' => \$no_op, # Don't do any operations? … … 52 59 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 53 60 pod2usage( 54 -msg => "Required options: --vp_id -- exp_id --outroot --camera",61 -msg => "Required options: --vp_id --outroot --camera", 55 62 -exitval => 3, 56 63 ) unless defined $vp_id 57 and defined $exp_id58 64 and defined $camera 59 65 and defined $outroot; 60 66 67 pod2usage( 68 -msg => " --product -ds_dbname and --dsdbhost are required if --dest_id", 69 -exitval => 3, 70 ) if ($dest_id and !( defined $product and defined $ds_dbname and defined $ds_dbhost)); 71 61 72 62 73 $no_update = 1 if $no_op; 63 64 my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, 'nochip', 'nocell', $PS_EXIT_CONFIG_ERROR ); # IPP configuration 74 $vptool .= " -dbname $dbname" if $dbname; 75 76 my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 65 77 66 78 my $logDest = $ipprc->filename("LOG.EXP", $outroot); 67 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $vp_id, 'nochip', 'nocell', $PS_EXIT_SYS_ERROR ) if $redirect; 68 69 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF); 70 71 # Get list of components for subtraction 79 if ($redirect) { 80 $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $vp_id, $PS_EXIT_SYS_ERROR ); 81 82 print "\n\n"; 83 print "Starting script $0 on $host at $date\n\n"; 84 } 85 86 # Get list of chips with pending video cells 72 87 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 73 88 my $files; 74 89 { 75 # my $command = "$vptool -pendingimfile -vp_id $vp_id"; 76 # $command .= " -dbname $dbname" if defined $dbname; 77 my $command = "$regtool -processedimfile -video_cells -exp_id $exp_id"; 78 $command .= " -dbname $dbname" if defined $dbname; 90 my $command = "$vptool -pendingimfile -vp_id $vp_id"; 79 91 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 80 92 run(command => $command, verbose => $verbose); 81 93 unless ($success) { 82 94 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 83 &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, 'nochip', 'nocell', $error_code); 84 } 85 86 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 87 &my_die("Unable to parse metadata config doc", $vp_id, 'nochip', 'nocell', $PS_EXIT_PROG_ERROR); 88 $files = parse_md_list($metadata) or 89 &my_die("Unable to parse metadata list", $vp_id, 'nochip', 'nocell', $PS_EXIT_PROG_ERROR); 90 } 95 &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code); 96 } 97 98 my $output = join "", @$stdout_buf; 99 if ($output) { 100 my $metadata = $mdcParser->parse($output) or 101 &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR); 102 $files = parse_md_list($metadata) or 103 &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR); 104 } 105 } 106 91 107 92 108 foreach my $file (@$files) { … … 95 111 96 112 my $resolved = $ipprc->file_resolve($uri); 97 &my_die("Unable to resolve $uri", $vp_id, $ class_id, 'nocell', $PS_EXIT_UNKNOWN_ERROR) unless $resolved;113 &my_die("Unable to resolve $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless $resolved; 98 114 99 115 my $command = "$listvideocells --file $resolved"; … … 101 117 run(command => $command, verbose => $verbose); 102 118 unless ($success) { 119 check_input_file($uri, $vp_id, $class_id, 'nocell'); 103 120 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 104 &my_die("Unable to perform $command: $error_code", $vp_id, $class_id, 105 'nocell', $error_code); 121 &my_die("Unable to perform $command: $error_code", $vp_id, $error_code); 106 122 } 107 123 108 124 my @video_cells = split "\n", (join "", @$stdout_buf); 109 &my_die("No video cells found in $uri", $vp_id, $class_id, 110 'nocell', $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells; 125 &my_die("No video cells found in $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells; 111 126 112 127 foreach my $cell_id (@video_cells) { 113 my $command = "$psvideophot $outroot"; 128 my $path_base = "$outroot.$class_id.$cell_id"; 129 my $error; 130 my $output = $ipprc->prepare_output("PSVIDEOPHOT.OUTPUT", $path_base, undef, 1, \$error) 131 or &my_die("failed to prepare output file for PSVIDEOPHOT.OUTPUT", $vp_id, $error); 132 my $command = "$psvideophot $output"; 114 133 $command .= " -file $uri"; 134 $command .= " -class_id $class_id"; 115 135 $command .= " -cell_id $cell_id"; 116 $command .= " -dbname $dbname" if defined $dbname;136 my $vpstart = DateTime->now->mjd; 117 137 unless ($no_op) { 118 138 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 120 140 unless ($success) { 121 141 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 122 &my_die("Unable to perform p pSub: $error_code", $vp_id, $class_id, $cell_id, $error_code);142 &my_die("Unable to perform psvideophot: $error_code", $vp_id, $error_code); 123 143 } 124 125 # check_output($outputStats, 1);126 144 } else { 127 145 print "Not executing: $command\n"; 128 146 } 147 # dump the video cell and the video table to a file 148 if ($save_video_cube) { 149 my $output = $path_base . ".fits"; 150 my $extname = "$cell_id"; 151 my $command = "$dumpvideo $uri $extname $output -includetable"; 152 unless ($no_op) { 153 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 154 run(command => $command, verbose => $verbose); 155 unless ($success) { 156 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 157 &my_die("Unable to perform dumpvideo: $error_code", $vp_id, $error_code); 158 } 159 } else { 160 print "Not executing: $command\n"; 161 } 162 } 163 129 164 unless ($no_update) { 130 my $command = "$vptool -add vpcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";131 $command .= " -path_base $ outroot";132 133 $command .= " -d bname $dbname" if defined $dbname;165 my $command = "$vptool -addprocessedcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id"; 166 $command .= " -path_base $path_base"; 167 $command .= " -hostname $host"; 168 $command .= " -dtime_photom " . ((DateTime->now->mjd - $vpstart) * 86400); 134 169 135 170 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 138 173 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 139 174 my $err_message = "Unable to perform vptool -addvpcell"; 140 &my_die("$err_message: $error_code", $vp_id, $ class_id, $cell_id, $error_code);175 &my_die("$err_message: $error_code", $vp_id, $error_code); 141 176 } 142 177 } 143 178 } 144 179 } 180 if ($dest_id) { 181 my $command = "$vptool -processedcell -vp_id $vp_id"; 182 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 183 run(command => $command, verbose => $verbose); 184 unless ($success) { 185 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 186 &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code); 187 } 188 189 my $output = join "", @$stdout_buf; 190 my $cells; 191 if ($output) { 192 my $metadata = $mdcParser->parse($output) or 193 &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR); 194 $cells = parse_md_list($metadata) or 195 &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR); 196 } 197 my ($reglist, $reglistName) = tempfile("/tmp/filelist.$vp_id.XXXX", UNLINK => !$save_temps); 198 199 if ($redirect) { 200 print $reglist "$logDest|||text|\n"; 201 } 202 # list of extensions and types for files to distribute 203 my @exts = qw( vpt ); 204 my @types = qw( table ); 205 if ($save_video_cube) { 206 push @exts, 'fits'; 207 push @types, 'fits'; 208 } 209 foreach my $cell (@$cells) { 210 my $path_base = $cell->{path_base}; 211 for (my $i = 0; $i < scalar @exts; $i++) { 212 my $file = "$path_base.$exts[$i]"; 213 my $type = $types[$i]; 214 215 print $reglist "$file|||$type|\n"; 216 } 217 } 218 close $reglist or &my_die("failed to close $reglistName", $vp_id, $PS_EXIT_UNKNOWN_ERROR); 219 unless ($no_update or $no_op) { 220 my $fileset = basename($outroot); 221 my $command = "$dsreg --add $fileset --product $product --type dump --list $reglistName"; 222 $command .= " --abspath --link"; 223 $command .= " --dbname $ds_dbname --dbhost $ds_dbhost"; 224 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 225 run(command => $command, verbose => $verbose); 226 unless ($success) { 227 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 228 &my_die("Unable to perform $command error_code: $error_code", $vp_id, $error_code); 229 } 230 } 231 } 232 233 unless ($no_update) { 234 my $command = "$vptool -updaterun -vp_id $vp_id -set_state full"; 235 $command .= " -set_outroot $outroot"; 236 $command .= " -set_hostname $host"; 237 $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400); 238 239 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 240 run(command => $command, verbose => $verbose); 241 unless ($success) { 242 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 243 my $err_message = "Unable to perform vptool -updaterun"; 244 &my_die("$err_message: $error_code", $vp_id, $error_code); 245 } 246 } 145 247 146 248 exit 0; 249 250 sub check_input_file { 251 my $uri = shift; 252 my $vp_id = shift; 253 my $class_id = shift; 254 my $cell_id = shift; 255 my $resolved = $ipprc->file_resolve($uri); 256 257 my $tryrepair = 0; 258 if (!-e $resolved) { 259 printf STDERR "instance $resolved for $uri does not exist\n"; 260 $tryrepair = 1; 261 } elsif (-s $resolved == 0) { 262 printf STDERR "instance $resolved for $uri is empty\n"; 263 $tryrepair = 1; 264 } 265 if ($tryrepair) { 266 my $scheme = file_scheme($uri); 267 if ($scheme and ($scheme = 'neb')) { 268 my $command = "$nebrepair $uri"; 269 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 270 run(command => $command, verbose => $verbose); 271 unless ($success) { 272 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 273 my $err_message = "Unable to perform nebrepair"; 274 &my_die("$err_message: $error_code", $vp_id, $error_code); 275 } 276 } 277 } 278 } 147 279 148 280 sub my_die 149 281 { 150 282 my $msg = shift; # Warning message on die 151 my $vp_id = shift; 152 my $class_id = shift; # chip identifier 153 my $cell_id = shift; # chip identifier 283 my $vp_id = shift; # vpRun id 154 284 my $exit_code = shift; # Exit code to add 155 285 … … 157 287 158 288 warn($msg); 159 if (defined $vp_id and defined $class_id and not $no_update) { 160 my $command = "$vptool -vp_id $vp_id -class_id $class_id -cell_id -fault $exit_code"; 161 $command .= " -addvpcell"; 162 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 163 $command .= " -hostname $host" if defined $host; 164 $command .= " -path_base $outroot" if defined $outroot; 165 $command .= " -dbname $dbname" if defined $dbname; 289 if (defined $vp_id and not $no_update) { 290 my $command = "$vptool -vp_id $vp_id"; 291 $command .= " -updaterun"; 292 $command .= " -set_fault $exit_code"; 293 $command .= " -set_hostname $host" if defined $host; 294 $command .= " -set_outroot $outroot" if defined $outroot; 295 $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400); 296 166 297 run(command => $command, verbose => $verbose); 167 298 } … … 169 300 } 170 301 171 END {172 my $exit = $?;173 system("sync") == 0 or die "failed to execute sync: $!";174 $? = $exit;175 }176 177 302 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
