Changeset 14021 for trunk/ippScripts/scripts/ipp_serial_inject.pl
- Timestamp:
- Jul 5, 2007, 1:32:33 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/ipp_serial_inject.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_serial_inject.pl
r13751 r14021 1 1 #!/usr/bin/env perl 2 2 3 # this program injects a list of single-file exposures into the db, taking the 4 # filename (without .fits) as the exp_tag. 3 # this program injects a list of single-file exposures into the db, 4 # taking the filename (without .fits) as the exp_tag. the user 5 # supplies a temporary telescope and instrument name. these are used 6 # for informational purposes only until the registration step can 7 # determine the true telescope and instrument name from the image 8 # headers. 9 10 # this program should not fail because of the data format or the 11 # configuration, except for the very basic database setup. 5 12 6 13 use warnings; … … 8 15 9 16 use IPC::Cmd 0.36 qw( can_run run ); 10 use PS::IPP::Metadata::Config;11 use PS::IPP::Metadata::List qw( parse_md_list );12 17 use File::Spec; 13 # use File::Find::Rule;14 18 use PS::IPP::Config; 15 my $ipprc = PS::IPP::Config->new(); 16 my $ mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files19 20 my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions 17 21 18 22 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); … … 20 24 21 25 # Parse the command-line arguments 22 my ($workdir, $dbname );26 my ($workdir, $dbname, $telescope, $instrument, $help); 23 27 GetOptions( 24 'workdir|w=s' => \$workdir, # working directory for output files 25 'dbname|d=s' => \$dbname # Database name 28 'workdir|w=s' => \$workdir, # working directory for output files 29 'dbname|d=s' => \$dbname, # Database name 30 'telescope|t=s' => \$telescope, # user-supplied telescope name 31 'instrument|i=s' => \$instrument, # user-supplied instrument name 32 'help' => \$help # give help listing 26 33 ) or pod2usage( 2 ); 27 34 28 pod2usage( -msg => "Usage: $0 [--workdir path] [--dbname dbname] (files)", -exitval => 2 ) if scalar @ARGV == 0; 35 pod2usage( -msg => "inject one or many files into the IPP pipeline database", -exitval => 2 36 37 pod2usage( -msg => "Usage: $0 --telescope (name) --instrument (name) [--workdir path] [--dbname dbname] (files)", 38 -exitval => 2 ) if 39 scalar @ARGV == 0; 40 41 pod2usage( -msg => "Required options: --telescope (name) --instrument (name)", 42 -exitval => 3) unless 43 defined $telescope and 44 defined $instrument; 29 45 30 46 my $pxinject = can_run('pxinject') or die "Can't find pxinject\n"; 31 my $ppStats = can_run('ppStats') or die "Can't find ppStats\n";32 47 33 48 # if workdir is not defined, assign the current path … … 40 55 foreach my $file ( @ARGV ) { 41 56 my $absfile = File::Spec->rel2abs( $file ); 42 inject($absfile, $workdir, $dbname );57 inject($absfile, $workdir, $dbname, $telescope, $instrument); 43 58 $num ++; 44 59 } … … 48 63 sub inject 49 64 { 50 my $absfile = shift; # absolute path for this file 51 my $workdir = shift; # absolute path for output directory 52 my $dbname = shift; 65 my $absfile = shift; # absolute path for this file 66 my $workdir = shift; # absolute path for output directory 67 my $dbname = shift; # IPP database to use 68 my $telescope = shift; # user-specified telescope 69 my $instrument = shift; # user-specified instrument 53 70 54 71 my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile ); 55 my ( $exp ) = $name =~ /(.*)\.fits/;72 my ( $exp_name ) = $name =~ /(.*)\.fits/; 56 73 57 74 my $relfile = $ipprc->convert_filename_relative( $absfile ); 58 75 59 my $command_type = "$ppStats -recipe PPSTATS INJECT $absfile"; 60 61 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command_type, verbose => 1); 62 die "Unable to perform ppStats: $error_code\n" if not $success; 63 my $metadata = $mdcParser->parse(join "", @$stdout_buf) 64 or die "unable to parse metadata config doc"; 65 66 my $type; 67 my $telescope; 68 my $instrument; 69 foreach my $row (@$metadata) { 70 if ($row->{name} eq "FPA.TELESCOPE") { $telescope = $row->{value}; } 71 if ($row->{name} eq "FPA.INSTRUMENT") { $instrument = $row->{value}; } # this entry must return the camera in the ipp/config system which we load 72 } 73 74 my $command_exp = "$pxinject -newExp -exp_id $exp -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run 76 my $command_exp = "$pxinject -newExp -exp_name $exp_name -inst $instrument -telescope $telescope -imfiles 1 -workdir $workdir" ; # Command to run 75 77 if ($dbname) { 76 78 $command_exp = "$command_exp -dbname $dbname"; … … 79 81 my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) = 80 82 run( command => $command_exp, verbose => 1 ); 81 die "Unable to inject $exp : $error_code_exp\n" if not $success_exp;83 die "Unable to inject $exp_name: $error_code_exp\n" if not $success_exp; 82 84 83 85 my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag 84 my $exp_ tag= $line[2]; # The exposure tag86 my $exp_id = $line[2]; # The exposure tag 85 87 86 my $command_imfile = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -uri $relfile"; # Command to run 88 # XXX the class_id used here should be temporary : register should replace it with the true class_id 89 my $command_imfile = "$pxinject -newImfile -exp_id $exp_id -exp_name $exp_name -class fpa -class_id fpa -uri $relfile"; # Command to run 87 90 if ($dbname) { 88 91 $command_imfile = "$command_imfile -dbname $dbname"; … … 90 93 91 94 my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 ); 92 die "Unable to inject $exp imfile: $error_code_imfile\n" if not $success_imfile;95 die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile; 93 96 94 97 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.
