IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 5, 2007, 1:32:33 PM (19 years ago)
Author:
eugene
Message:

remove all header examination from inject; use new Stats.pm APIs in register; rework of exp_tag, exp_id, exp_name; newImfile:class_id,telescope,inst are now temporary info; register supplies real telescope,inst,class_id

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/ipp_serial_inject.pl

    r13751 r14021  
    11#!/usr/bin/env perl
    22
    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.
    512
    613use warnings;
     
    815
    916use IPC::Cmd 0.36 qw( can_run run );
    10 use PS::IPP::Metadata::Config;
    11 use PS::IPP::Metadata::List qw( parse_md_list );
    1217use File::Spec;
    13 # use File::Find::Rule;
    1418use PS::IPP::Config;
    15 my $ipprc = PS::IPP::Config->new();
    16 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     19
     20my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions
    1721
    1822use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    2024
    2125# Parse the command-line arguments
    22 my ($workdir, $dbname);
     26my ($workdir, $dbname, $telescope, $instrument, $help);
    2327GetOptions(
    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
    2633) or pod2usage( 2 );
    2734
    28 pod2usage( -msg => "Usage: $0 [--workdir path] [--dbname dbname] (files)", -exitval => 2 ) if scalar @ARGV == 0;
     35pod2usage( -msg => "inject one or many files into the IPP pipeline database", -exitval => 2
     36
     37pod2usage( -msg => "Usage: $0 --telescope (name) --instrument (name) [--workdir path] [--dbname dbname] (files)",
     38           -exitval => 2 ) if
     39           scalar @ARGV == 0;
     40
     41pod2usage( -msg => "Required options: --telescope (name) --instrument (name)",
     42           -exitval => 3) unless
     43           defined $telescope and
     44           defined $instrument;
    2945
    3046my $pxinject = can_run('pxinject') or die "Can't find pxinject\n";
    31 my $ppStats = can_run('ppStats') or die "Can't find ppStats\n";
    3247
    3348# if workdir is not defined, assign the current path
     
    4055foreach my $file ( @ARGV ) {
    4156    my $absfile = File::Spec->rel2abs( $file );
    42     inject($absfile, $workdir, $dbname);
     57    inject($absfile, $workdir, $dbname, $telescope, $instrument);
    4358    $num ++;
    4459}
     
    4863sub inject
    4964{
    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
    5370
    5471    my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile );
    55     my ( $exp ) = $name =~ /(.*)\.fits/;
     72    my ( $exp_name ) = $name =~ /(.*)\.fits/;
    5673
    5774    my $relfile = $ipprc->convert_filename_relative( $absfile );
    5875
    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
    7577    if ($dbname) {
    7678        $command_exp = "$command_exp -dbname $dbname";
     
    7981    my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) =
    8082        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;
    8284   
    8385    my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag
    84     my $exp_tag = $line[2];     # The exposure tag
     86    my $exp_id = $line[2];      # The exposure tag
    8587   
    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
    8790    if ($dbname) {
    8891        $command_imfile = "$command_imfile -dbname $dbname";
     
    9093   
    9194    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;
    9396
    9497    return 1;
Note: See TracChangeset for help on using the changeset viewer.