Changeset 11110 for trunk/ippScripts/scripts/inject.pl
- Timestamp:
- Jan 15, 2007, 3:17:04 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/inject.pl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/inject.pl
r10700 r11110 1 1 #!/usr/bin/env perl 2 3 # this program injects a list of single-file exposures into the db, taking the 4 # filename (without .fits) as the exp_tag. 2 5 3 6 use warnings; … … 7 10 use PS::IPP::Metadata::Config; 8 11 use PS::IPP::Metadata::List qw( parse_md_list ); 9 use Data::Dumper; 12 use File::Spec; 13 use File::Find::Rule; 14 use PS::IPP::Config; 15 my $ipprc = PS::IPP::Config->new(); 16 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 10 17 11 18 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 12 use Pod::Usage qw( pod2usage );13 19 14 my ($camera, # Camera used 15 $telescope, # Telescope used 16 $exp_type, # Type of exposure 17 $path, # Path to use 18 $inject_only # Only inject (i.e., no phase 0)? 19 ); 20 # Parse the command-line arguments 21 my ($outroot); 20 22 GetOptions( 21 'camera|c=s' => \$camera, 22 'telescope|t=s' => \$telescope, 23 'exp_type|e=s' => \$exp_type, 24 'path=s' => \$path, 25 'inject-only' => \$inject_only, 23 'outroot' => \$outroot 26 24 ) or pod2usage( 2 ); 27 25 28 pod2usage( 29 -msg => "Required options: --camera --telescope --exp_type --path", 30 -exitval => 3, 31 ) unless scalar @ARGV == 0 or (defined $camera 32 and defined $telescope 33 and defined $exp_type 34 and defined $path); 26 pod2usage( -msg => "Usage: $0 [-outroot path] (files)", -exitval => 2 ) if scalar @ARGV == 0; 35 27 36 my $mdcParser = PS::IPP::Metadata::Config->new; # Metadata config parser 28 my $pxinject = can_run('pxinject') or die "Can't find pxinject\n"; 29 my $ppStats = can_run('ppStats') or die "Can't find ppStats\n"; 37 30 38 # Look for programs we need 39 my $missing_tools; 40 my $pxinject = can_run('pxinject') or (warn "Can't find pxinject" and $missing_tools = 1); 41 my $p0tool = can_run('p0tool') or (warn "Can't find p0tool" and $missing_tools = 1); 42 my $phase0_imfile = can_run('phase0_imfile.pl') or (warn "Can't find phase0_imfile.pl" and $missing_tools = 1); 43 my $phase0_exp = can_run('phase0_exp.pl') or (warn "Can't find phase0_exp.pl" and $missing_tools = 1); 44 die "Can't find required tools.\n" if $missing_tools; 31 # if outroot is not defined, assign the current path 32 if (! $outroot) { 33 $outroot = File::Spec->rel2abs( "." ); 34 } 35 my $relroot = $ipprc->convert_filename_relative( $outroot ); 45 36 46 # Inject new data into the database 47 if (scalar @ARGV != 0) { 48 my @classes; 49 my $imfiles; 50 if ($camera eq "MEGACAM") { 51 for (my $i = 0; $i < 36; $i++) { 52 push @classes, sprintf("ccd%02d", $i); 53 } 54 } elsif ($camera eq "MCSHORT") { 55 @classes = ( 'ccd12', 'ccd13', 'ccd14', 'ccd21', 'ccd22', 'ccd23' ); 56 } elsif ($camera eq "CTIO_MOSAIC2") { 57 @classes = (); 58 } else { 59 die "Unrecognised camera name: $camera.\n"; 60 } 61 62 foreach my $exp ( @ARGV ) { 63 my $command = "$pxinject -newExp -exp_id $exp -inst $camera -telescope $telescope -exp_type $exp_type -imfiles " . (scalar @classes or 1) ; # Command to run 64 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 65 run( command => $command, verbose => 1 ); 66 die "Unable to inject $exp: $error_code\n" if not $success; 67 68 my @line = split(/\s+/, $$stdout_buf[0]); # The output line, containing the exposure tag 69 my $exp_tag = $line[2]; # The exposure tag 70 foreach my $class_id (@classes) { 71 my $command = "$pxinject -newImfile -exp_tag $exp_tag -class chip -class_id $class_id -uri $path/$exp.$class_id.fits"; # Command to run 72 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 73 run( command => $command, verbose => 1 ); 74 die "Unable to inject $exp $class_id: $error_code\n" if not $success; 75 } 76 77 if (scalar @classes == 0) { 78 my $command = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -uri $path/$exp.fits"; # Command to run 79 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 80 run( command => $command, verbose => 1 ); 81 die "Unable to inject $exp imfile: $error_code\n" if not $success; 82 } 83 84 } 37 my $num = 0; 38 foreach my $file ( @ARGV ) { 39 my $absfile = File::Spec->rel2abs( $file ); 40 inject($absfile, $relroot); 41 $num ++; 85 42 } 86 43 87 exit 0 if $inject_only;44 print "$num files injected.\n"; 88 45 89 # Phase 0 imfile processing 46 sub inject 90 47 { 91 my $command = "$p0tool -pendingimfile"; # Command to run 92 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 93 run( command => $command, verbose => 1 ); 94 die "Unable to get phase 0 imfile list: $error_code\n" if not $success; 95 my $list = parse_md_list( $mdcParser->parse( join( '', @$stdout_buf ) ) ) or 96 die "Unable to parse output from p0tool.\n"; 48 my $absfile = shift; # absolute path for this file 49 my $outroot = shift; # absolute path for output directory 97 50 98 foreach my $item (@$list) { 99 my $exp_tag = $item->{exp_tag}; 100 my $class = $item->{class}; 101 my $class_id = $item->{class_id}; 102 my $uri = $item->{uri}; 51 my ( $vol, $path, $name ) = File::Spec->splitpath( $absfile ); 52 my ( $exp ) = $name =~ /(.*)\.fits/; 103 53 104 my $command = "$phase0_imfile --exp_tag $exp_tag --class $class --class_id $class_id --uri $uri"; 105 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 106 run( command => $command, verbose => 1 ); 107 die "Unable to do phase 0 imfile processing on $exp_tag $class_id: $error_code\n" if not $success; 54 my $relfile = $ipprc->convert_filename_relative( $absfile ); 55 56 my $command_type = "$ppStats -concept FPA.OBSTYPE -concept FPA.TELESCOPE -concept FPA.INSTRUMENT $absfile"; 57 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command_type, verbose => 1); 58 die "Unable to perform ppStats: $error_code\n" if not $success; 59 my $metadata = $mdcParser->parse(join "", @$stdout_buf) 60 or die "unable to parse metadata config doc"; 61 62 my $type; 63 my $telescope; 64 my $instrument; 65 foreach my $row (@$metadata) { 66 if ($row->{name} eq "FPA.TELESCOPE") { $telescope = $row->{value}; } 67 if ($row->{name} eq "FPA.INSTRUMENT") { $instrument = $row->{value}; } # this entry must return the camera in the ipp/config system which we load 68 if ($row->{name} eq "FPA.OBSTYPE") { $type = $row->{value}; } 108 69 } 109 } 70 71 my $command_exp = "$pxinject -newExp -exp_id $exp -inst $instrument -telescope $telescope -exp_type $type -imfiles 1 -outroot $outroot" ; # Command to run 110 72 111 # Phase 0 exposure processing 112 { 113 my $command = "$p0tool -pendingexp"; # Command to run114 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =115 run( command => $command, verbose => 1 ); 116 die "Unable to get phase 0 exposure list: $error_code\n" if not $success;117 my $list = parse_md_list( $mdcParser->parse( join( '', @$stdout_buf ) ) ) or118 die "Unable to parse output from p0tool.\n"; 119 120 foreach my $item (@$list) {121 my $exp_tag = $item->{exp_tag};73 my ( $success_exp, $error_code_exp, $full_buf_exp, $stdout_buf_exp, $stderr_buf_exp ) = 74 run( command => $command_exp, verbose => 1 ); 75 die "Unable to inject $exp: $error_code_exp\n" if not $success_exp; 76 77 my @line = split(/\s+/, $$stdout_buf_exp[0]); # The output line, containing the exposure tag 78 my $exp_tag = $line[2]; # The exposure tag 79 80 my $command_imfile = "$pxinject -newImfile -exp_tag $exp_tag -class fpa -class_id fpa -uri $relfile"; # Command to run 81 82 my ( $success_imfile, $error_code_imfile, $full_buf_imfile, $stdout_buf_imfile, $stderr_buf_imfile ) = run( command => $command_imfile, verbose => 1 ); 83 die "Unable to inject $exp imfile: $error_code_imfile\n" if not $success_imfile; 122 84 123 my $command = "$phase0_exp --exp_tag $exp_tag"; 124 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 125 run( command => $command, verbose => 1 ); 126 die "Unable to do phase 0 exposure processing on $exp_tag: $error_code\n" if not $success; 127 } 128 } 129 130 END { 131 my $status = $?; 132 system("sync") == 0 133 or die "failed to execute sync: $!" ; 134 $? = $status; 85 return 1; 135 86 } 136 87 137 88 138 89 __END__ 139 140
Note:
See TracChangeset
for help on using the changeset viewer.
