IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2007, 11:46:10 AM (19 years ago)
Author:
eugene
Message:

update to handle split directories

File:
1 edited

Legend:

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

    r14064 r14559  
    1616
    1717use IPC::Cmd 0.36 qw( can_run run );
    18 use PS::IPP::Config qw( caturi );
     18use File::Spec;
     19use PS::IPP::Config;
     20
     21my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1922
    2023use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2124use Pod::Usage qw( pod2usage );
    2225
    23 my ($camera, $telescope, $dbname, $workdir, $path);
     26# Parse the command-line arguments
     27my ($workdir, $dbname, $telescope, $camera, $reduction, $help);
    2428GetOptions(
     29           'workdir|w=s'   => \$workdir, # working directory for output files
     30           'dbname|d=s'    => \$dbname, # Database name
     31           'telescope|t=s' => \$telescope, # Telescope used     
    2532           'camera|c=s'    => \$camera,    # Camera used             
    26            'telescope|t=s' => \$telescope, # Telescope used     
    27            'workdir=s'     => \$workdir,   # Database name           
    28            'path=s'        => \$path,      # Working directory   
    29            'dbname=s'      => \$dbname,    # Path to data       
     33           'reduction=s'   => \$reduction, # user-supplied camera name
     34           'help'          => \$help # give help listing
    3035) or pod2usage( 2 );
     36
     37pod2usage( -msg => "inject one or many image exposures (directories) into the IPP pipeline database",
     38           -exitval => 2) if
     39    defined $help;
     40
     41pod2usage( -msg => "Usage: $0 --telescope (name) --camera (name) [--workdir path] [--dbname dbname] (files)",
     42           -exitval => 2 ) if
     43    scalar @ARGV == 0;
    3144
    3245pod2usage(
    3346          -msg => "Required options: --camera --telescope --workdir --path --dbname",
    34           -exitval => 3,
    35           ) unless defined $camera
    36     and defined $telescope
    37     and defined $workdir
    38     and defined $path
    39     and defined $dbname;
    40 
    41 my $ipprc = PS::IPP::Config->new(); # IPP configuration
     47          -exitval => 3) unless
     48    defined $telescope and
     49    defined $camera;
    4250
    4351# Look for programs we need
    44 my $missing_tools;
    45 my $pxinject = can_run('pxinject')  or (warn "Can't find pxinject" and $missing_tools = 1);
     52my $pxinject = can_run('pxinject') or die "Can't find pxinject\n";
    4653
    47 if (scalar @ARGV == 0) {
    48     die "No exposures provided.\n";
     54# if workdir is not defined, assign the current path
     55# XXX we need to handle relative paths for workdir (not allowed)
     56if (! $workdir) {
     57    $workdir = File::Spec->rel2abs( "." );
    4958}
    5059
    51 # Inject new data into the database
    52 my @classes;                    # Names of the classes
    53 my @files;                      # What to add to the filename for each class
    54 my $add_dir;                    # Add directory name to get file name?
     60my $num = 0;
     61foreach my $filedir ( @ARGV ) {
     62    # check for filedir existence
     63    if (! -e $filedir) { die "file dir $filedir not found\n"; }
     64    my $absfiledir = File::Spec->rel2abs( $filedir );
     65    inject($absfiledir, $workdir, $dbname, $telescope, $camera);
     66    $num ++;
     67}
    5568
    56 foreach my $exp_name ( @ARGV ) {
    57     my @files = <"$exp_name/*.fits">;
     69sub inject
     70{
     71    my $absfiledir = shift;     # absolute path for this file
     72    my $workdir  = shift;       # absolute path for output directory
     73    my $dbname = shift;         # IPP database to use
     74    my $telescope = shift;      # user-specified telescope
     75    my $camera = shift; # user-specified camera
     76
     77    # XXX provide an option for an alternative extension
     78    my @files = <$absfiledir/*.fits>;
    5879    my $Nfiles = scalar @files;
    5980
    60     my $command = "$pxinject -newExp";
    61     $command .= " -exp_name $exp_name";
    62     $command .= " -inst $camera";
    63     $command .= " -telescope $telescope";
    64     $command .= " -workdir $workdir";
    65     $command .= " -dbname $dbname" if defined $dbname;
     81    print "absfiledir: $absfiledir\n";
     82    print "Nfiles: $Nfiles\n";
    6683
    67     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    68         run( command => $command, verbose => 1 );
    69     die "Unable to inject $exp: $error_code\n" if not $success;
     84    # the absfiledir is of the form path://PATH/data/foo/expname
     85    my ( $vol, $path, $exp_name ) = File::Spec->splitpath( $absfiledir );
     86
     87    # the telescope, instrument, and exp_name used here are temporary : register replaces them with the true values
     88    my $command_exp = "$pxinject -newExp";
     89    $command_exp .= " -tmp_exp_name $exp_name";
     90    $command_exp .= " -tmp_inst $camera";
     91    $command_exp .= " -tmp_telescope $telescope";
     92    $command_exp .= " -workdir $workdir";
     93    $command_exp .= " -dbname $dbname" if defined $dbname;
     94    $command_exp .= " -reduction $reduction" if defined $reduction;
     95
     96    my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) =
     97        run( command => $command_exp, verbose => 1 );
     98    die "Unable to inject $exp_name: $error_code_exp\n" if not $success_exp;
    7099   
    71     my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag
     100    my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag
    72101    my $exp_id = $line[2];      # The exposure tag
    73102
    74     my $class_id = 0;
    75     foreach my $filename (@files) {
     103    foreach my $absfile (@files) {
    76104
    77         my $absfile = File::Spec->rel2abs( $filename );
    78105        my $relfile = $ipprc->convert_filename_relative( $absfile );
    79106
    80         # XXX the class_id used here should be temporary : register should replace it with the true class_id
     107        my ( $tmpvol, $tmppath, $filename ) = File::Spec->splitpath( $absfile );
     108        my ( $class_name ) = $filename =~ /(.*)\.fits/;
     109
     110        # the class_id used here is temporary : register replaces it with the true class_id
    81111        my $command_imfile = "$pxinject -newImfile";
    82112        $command_imfile .= " -exp_id $exp_id";
    83         $command_imfile .= " -exp_name $exp_name";
    84         $command_imfile .= " -class chip";
    85         $command_imfile .= " -class_id $class_id";
     113        $command_imfile .= " -tmp_class_id $class_name";
    86114        $command_imfile .= " -uri $relfile";
    87115        $command_imfile .= " -dbname $dbname" if defined ($dbname);
     
    89117        my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 );
    90118        die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile;
    91 
    92         $class_id ++;
    93119    }
    94120
    95     # finalize the exposure
    96     $command  = "$pxinject -updatenewExp";
    97     $command .= " -exp_id $exp_id";
    98     $command .= " -state run";
    99     $command .= " -dbname $dbname" if defined $dbname;
     121    # the class_id used here is temporary : register replaces it with the true class_id
     122    my $command_update = "$pxinject -updatenewExp";
     123    $command_update .= " -exp_id $exp_id";
     124    $command_update .= " -state run";
     125    $command_update .= " -dbname $dbname" if defined ($dbname);
     126   
     127    my ( $success_update, $error_code_update, $full_buf_update, $stdout_buf_update, $stderr_buf_update ) = run( command => $command_update, verbose => 1 );
     128    die "Unable to update $exp_name: $error_code_update\n" if not $success_update;
    100129
    101     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    102         run( command => $command, verbose => 1 );
    103     die "Unable to inject $exp: $error_code\n" if not $success;
     130    return 1;
    104131}
    105132
    106 END {
    107     my $status = $?;
    108 system("sync") == 0
    109     or die "failed to execute sync: $!" ;
    110 $? = $status;
    111 }
    112 
    113 
    114133__END__
    115 
    116 
Note: See TracChangeset for help on using the changeset viewer.