Changeset 14559
- Timestamp:
- Aug 20, 2007, 11:46:10 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/ipp_serial_inject_split.pl
r14064 r14559 16 16 17 17 use IPC::Cmd 0.36 qw( can_run run ); 18 use PS::IPP::Config qw( caturi ); 18 use File::Spec; 19 use PS::IPP::Config; 20 21 my $ipprc = PS::IPP::Config->new(); # IPP configuration 19 22 20 23 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 21 24 use Pod::Usage qw( pod2usage ); 22 25 23 my ($camera, $telescope, $dbname, $workdir, $path); 26 # Parse the command-line arguments 27 my ($workdir, $dbname, $telescope, $camera, $reduction, $help); 24 28 GetOptions( 29 'workdir|w=s' => \$workdir, # working directory for output files 30 'dbname|d=s' => \$dbname, # Database name 31 'telescope|t=s' => \$telescope, # Telescope used 25 32 '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 30 35 ) or pod2usage( 2 ); 36 37 pod2usage( -msg => "inject one or many image exposures (directories) into the IPP pipeline database", 38 -exitval => 2) if 39 defined $help; 40 41 pod2usage( -msg => "Usage: $0 --telescope (name) --camera (name) [--workdir path] [--dbname dbname] (files)", 42 -exitval => 2 ) if 43 scalar @ARGV == 0; 31 44 32 45 pod2usage( 33 46 -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; 42 50 43 51 # 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); 52 my $pxinject = can_run('pxinject') or die "Can't find pxinject\n"; 46 53 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) 56 if (! $workdir) { 57 $workdir = File::Spec->rel2abs( "." ); 49 58 } 50 59 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? 60 my $num = 0; 61 foreach 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 } 55 68 56 foreach my $exp_name ( @ARGV ) { 57 my @files = <"$exp_name/*.fits">; 69 sub 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>; 58 79 my $Nfiles = scalar @files; 59 80 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"; 66 83 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; 70 99 71 my @line = split(/\s+/, $$stdout_buf [0]); # The output line, containing the exposure tag100 my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag 72 101 my $exp_id = $line[2]; # The exposure tag 73 102 74 my $class_id = 0; 75 foreach my $filename (@files) { 103 foreach my $absfile (@files) { 76 104 77 my $absfile = File::Spec->rel2abs( $filename );78 105 my $relfile = $ipprc->convert_filename_relative( $absfile ); 79 106 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 81 111 my $command_imfile = "$pxinject -newImfile"; 82 112 $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"; 86 114 $command_imfile .= " -uri $relfile"; 87 115 $command_imfile .= " -dbname $dbname" if defined ($dbname); … … 89 117 my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 ); 90 118 die "Unable to inject $exp_name imfile: $error_code_imfile\n" if not $success_imfile; 91 92 $class_id ++;93 119 } 94 120 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; 100 129 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; 104 131 } 105 132 106 END {107 my $status = $?;108 system("sync") == 0109 or die "failed to execute sync: $!" ;110 $? = $status;111 }112 113 114 133 __END__ 115 116
Note:
See TracChangeset
for help on using the changeset viewer.
