- Timestamp:
- Nov 8, 2011, 2:44:12 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110906
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/videophot_process.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110906
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20110906/ippScripts/scripts/videophot_process.pl
r32125 r32630 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 34 if ($missing_tools) { 35 35 warn("Can't find required tools."); 36 36 exit($PS_EXIT_CONFIG_ERROR); 37 37 } 38 my ($vp_id, $exp_id, $camera, $outroot, $dbname, $verbose, $no_update, $no_op, $redirect); 38 my ($vp_id, $camera, $outroot, $dest_id, $dbname, $verbose, $no_update, $no_op, $redirect, $save_temps); 39 my ($product, $ds_dbname, $ds_dbhost); 39 40 40 41 GetOptions( 41 42 'vp_id=s' => \$vp_id, 42 'exp_id=s' => \$exp_id,43 43 'camera=s' => \$camera, 44 44 'outroot=s' => \$outroot, 45 'dest_id=s' => \$dest_id, 46 'product=s' => \$product, 47 'ds_dbname=s' => \$ds_dbname, 48 'ds_dbhost=s' => \$ds_dbhost, 45 49 'dbname|d=s' => \$dbname, 46 50 'verbose' => \$verbose, 51 'save-temps' => \$save_temps, 47 52 'no-update' => \$no_update, # Don't update the database? 48 53 'no-op' => \$no_op, # Don't do any operations? … … 52 57 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 53 58 pod2usage( 54 -msg => "Required options: --vp_id -- exp_id --outroot --camera",59 -msg => "Required options: --vp_id --outroot --camera", 55 60 -exitval => 3, 56 61 ) unless defined $vp_id 57 and defined $exp_id58 62 and defined $camera 59 63 and defined $outroot; 60 64 65 pod2usage( 66 -msg => " --product -ds_dbname and --dsdbhost are required if --dest_id", 67 -exitval => 3, 68 ) if ($dest_id and !( defined $product and defined $ds_dbname and defined $ds_dbhost)); 69 61 70 62 71 $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 72 $vptool .= " -dbname $dbname" if $dbname; 73 74 my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration 65 75 66 76 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 77 if ($redirect) { 78 $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $vp_id, $PS_EXIT_SYS_ERROR ); 79 80 print "\n\n"; 81 print "Starting script $0 on $host at $date\n\n"; 82 } 83 84 # Get list of chips with pending video cells 72 85 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 73 86 my $files; 74 87 { 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; 79 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 80 run(command => $command, verbose => $verbose); 81 unless ($success) { 82 $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 } 88 my $command = "$vptool -pendingimfile -vp_id $vp_id"; 89 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 90 run(command => $command, verbose => $verbose); 91 unless ($success) { 92 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 93 &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code); 94 } 95 96 my $output = join "", @$stdout_buf; 97 if ($output) { 98 my $metadata = $mdcParser->parse($output) or 99 &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR); 100 $files = parse_md_list($metadata) or 101 &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR); 102 } 103 } 104 91 105 92 106 foreach my $file (@$files) { … … 95 109 96 110 my $resolved = $ipprc->file_resolve($uri); 97 &my_die("Unable to resolve $uri", $vp_id, $ class_id, 'nocell', $PS_EXIT_UNKNOWN_ERROR) unless $resolved;111 &my_die("Unable to resolve $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless $resolved; 98 112 99 113 my $command = "$listvideocells --file $resolved"; … … 102 116 unless ($success) { 103 117 $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); 118 &my_die("Unable to perform $command: $error_code", $vp_id, $error_code); 106 119 } 107 120 108 121 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; 122 &my_die("No video cells found in $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells; 111 123 112 124 foreach my $cell_id (@video_cells) { 113 my $command = "$psvideophot $outroot"; 125 my $path_base = "$outroot.$class_id.$cell_id"; 126 my $output = $ipprc->filename("PSVIDEOPHOT.OUTPUT", $path_base); 127 my $command = "$psvideophot $output"; 114 128 $command .= " -file $uri"; 129 $command .= " -class_id $class_id"; 115 130 $command .= " -cell_id $cell_id"; 116 $command .= " -dbname $dbname" if defined $dbname;131 my $vpstart = DateTime->now->mjd; 117 132 unless ($no_op) { 118 133 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 120 135 unless ($success) { 121 136 $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);137 &my_die("Unable to perform psvideophot: $error_code", $vp_id, $error_code); 123 138 } 124 125 # check_output($outputStats, 1);126 139 } else { 127 140 print "Not executing: $command\n"; 128 141 } 142 # dump the video cell and the video table to a file 143 unless ($no_op) { 144 my $output = $path_base . ".fits"; 145 my $extname = "$cell_id"; 146 my $command = "$dumpvideo $uri $extname $output -includetable"; 147 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 148 run(command => $command, verbose => $verbose); 149 unless ($success) { 150 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 151 &my_die("Unable to perform dumpvideo: $error_code", $vp_id, $error_code); 152 } 153 } else { 154 print "Not executing: $command\n"; 155 } 156 129 157 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;158 my $command = "$vptool -addprocessedcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id"; 159 $command .= " -path_base $path_base"; 160 $command .= " -hostname $host"; 161 $command .= " -dtime_photom " . ((DateTime->now->mjd - $vpstart) * 86400); 134 162 135 163 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 138 166 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 139 167 my $err_message = "Unable to perform vptool -addvpcell"; 140 &my_die("$err_message: $error_code", $vp_id, $ class_id, $cell_id, $error_code);168 &my_die("$err_message: $error_code", $vp_id, $error_code); 141 169 } 142 170 } 171 } 172 } 173 if ($dest_id) { 174 my $command = "$vptool -processedcell -vp_id $vp_id"; 175 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 176 run(command => $command, verbose => $verbose); 177 unless ($success) { 178 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 179 &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code); 180 } 181 182 my $output = join "", @$stdout_buf; 183 my $cells; 184 if ($output) { 185 my $metadata = $mdcParser->parse($output) or 186 &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR); 187 $cells = parse_md_list($metadata) or 188 &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR); 189 } 190 my ($reglist, $reglistName) = tempfile("/tmp/filelist.$vp_id.XXXX", UNLINK => !$save_temps); 191 192 if ($redirect) { 193 print $reglist "$logDest|||text|\n"; 194 } 195 my @exts = qw( vpt fits ); 196 my @types = qw( table fits ); 197 foreach my $cell (@$cells) { 198 my $path_base = $cell->{path_base}; 199 for (my $i = 0; $i < scalar @exts; $i++) { 200 my $file = "$path_base.$exts[$i]"; 201 my $type = $types[$i]; 202 203 print $reglist "$file|||$type|\n"; 204 } 205 206 } 207 close $reglist or &my_die("failed to close $reglistName", $vp_id, $PS_EXIT_UNKNOWN_ERROR); 208 unless ($no_update or $no_op) { 209 my $fileset = basename($outroot); 210 my $command = "$dsreg --add $fileset --product $product --type dump --list $reglistName"; 211 $command .= " --abspath --link"; 212 $command .= " --dbname $ds_dbname --dbhost $ds_dbhost"; 213 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 214 run(command => $command, verbose => $verbose); 215 unless ($success) { 216 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 217 &my_die("Unable to perform $command error_code: $error_code", $vp_id, $error_code); 218 } 219 } 220 } 221 222 unless ($no_update) { 223 my $command = "$vptool -updaterun -vp_id $vp_id -set_state full"; 224 $command .= " -set_outroot $outroot"; 225 $command .= " -set_hostname $host"; 226 $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400); 227 228 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 229 run(command => $command, verbose => $verbose); 230 unless ($success) { 231 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 232 my $err_message = "Unable to perform vptool -updaterun"; 233 &my_die("$err_message: $error_code", $vp_id, $error_code); 143 234 } 144 235 } … … 149 240 { 150 241 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 242 my $vp_id = shift; # vpRun id 154 243 my $exit_code = shift; # Exit code to add 155 244 … … 157 246 158 247 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; 248 if (defined $vp_id and not $no_update) { 249 my $command = "$vptool -vp_id $vp_id"; 250 $command .= " -updaterun"; 251 $command .= " -set_fault $exit_code"; 252 $command .= " -set_hostname $host" if defined $host; 253 $command .= " -set_outroot $outroot" if defined $outroot; 254 $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400); 255 166 256 run(command => $command, verbose => $verbose); 167 257 } … … 169 259 } 170 260 171 END {172 my $exit = $?;173 system("sync") == 0 or die "failed to execute sync: $!";174 $? = $exit;175 }176 177 261 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
