IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 12, 2006, 10:12:14 AM (20 years ago)
Author:
Paul Price
Message:

Adding rejection settings for detrend creation. Involves looking up
the camera configuration given a camera name (need to search the path)
and getting the line that matches the detrend type and filter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r9168 r9504  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.1 2006-10-04 01:45:47 price Exp $
     3# $Id: Config.pm,v 1.2 2006-10-12 20:12:14 price Exp $
    44
    55package PS::IPP::Config;
     
    1111
    1212use Carp qw( carp croak );
    13 use PS::IPP::Metadata::Config;
     13use File::Spec;
     14use PS::IPP::Metadata::Config 0.07;
    1415use Getopt::Long qw( GetOptions :config gnu_getopt pass_through ); # Set pass_through so we don't kill @ARGV
    1516
    1617use base qw( Class::Accessor::Fast );
    1718__PACKAGE__->mk_accessors( qw( path workdir ) );
     19
     20our $parser = PS::IPP::Metadata::Config->new; # Metadata parser
     21$parser->overwrite(0);          # Turn off overwrite
    1822
    1923#$::RD_TRACE = 1;
     
    2428sub new {
    2529    my $class = shift;          # Class name
     30    my $camera = shift;         # Camera name
    2631
    2732    # Get location of ipprc file
     
    3540    close $file;
    3641
    37     my $parser = PS::IPP::Metadata::Config->new; # Parser for ipprc file
    3842    my $mdc = $parser->parse( join '', @contents); # The parsed metadata config
    3943
    4044    my $path = _mdLookupStr($mdc, 'PATH'); # The path
    4145    my $workdir = _mdLookupStr($mdc, 'WORKDIR'); # The working directory
    42 
    4346    croak "PATH is not set in $name\n" unless defined $path;
    4447    croak "WORKDIR is not set in $name\n" unless defined $workdir;
     
    4750        path => $path,          # Path
    4851        workdir => $workdir,    # Working directory
     52        camera => undef,        # Camera configuration
    4953        _ipprc => $mdc          # The parsed configuration
    5054        };
     55    bless $self, $class;
    5156
    52     bless $self, $class;
     57    $self->define_camera($camera) if defined $camera;
     58
    5359    return $self;
    54 
    5560}
    5661
    57 # Lookup the metadata, checking the type
     62# Define a camera to use
     63sub define_camera
     64{
     65    my $self = shift;           # Configuration object
     66    my $name = shift;           # Camera name
     67
     68    my $camera_list = _mdLookupMD($self->{_ipprc}, 'CAMERAS'); # List of cameras
     69    my $filename = _mdLookupStr($camera_list, $name); # Filename of camera configuration
     70    my @path = split /:/, $self->{path}; # List of paths to try
     71    my $found;                  # Found it?
     72    foreach my $path (@path) {
     73        my $test = File::Spec->rel2abs( $filename, $path );
     74        if (-f $test) {
     75            $found = $test;
     76            last;
     77        }
     78    }
     79    croak "Unable to find camera configuration file $filename\n" if not defined $found;
     80
     81    # Read the file
     82    open my $file, $found or croak "Unable to open camera configuration file $found: $!";
     83    my @contents = <$file>;
     84    close $file;
     85    $self->{camera} = $parser->parse( join '', @contents); # The parsed metadata config
     86
     87    return defined $self->{camera};
     88}
     89
     90
     91# Return a rejection limit from the camera configuration
     92sub rejection
     93{
     94    my $self = shift;           # Configuration object
     95    my $name = shift;           # Name of limit
     96    my $type = lc(shift);       # Type of frame
     97    my $filter = shift;         # Filter name, for extra qualification; optional
     98
     99    my $camera = $self->{camera}; # Camera configuration
     100    unless (defined $camera) {
     101        carp "Camera has not yet been defined.\n";
     102        return undef;
     103    }
     104
     105    my $rejection = _mdLookupMD($camera, 'REJECTION');  # Rejection list
     106    unless (defined $rejection) {
     107        carp "Can't find REJECTION list in camera configuration.\n";
     108        return undef;
     109    }
     110
     111  TYPES: foreach my $item (@$rejection) {
     112      if (lc($item->{name}) eq $type) {
     113          croak "$name within REJECTION is not of type METADATA" unless $item->{class} eq "metadata";
     114          my $limits = $item->{value}; # List of rejection limits
     115
     116          # Check the FILTER first
     117          foreach my $limit (@$limits) {
     118              if ($limit->{name} eq 'FILTER') {
     119                  if ($limit->{value} eq '*' or
     120                      (defined $filter and
     121                       $limit->{value} eq $filter)) {
     122                      last;
     123                  }
     124                  next TYPES; # Doesn't match --- look at the next one
     125              }
     126          }
     127         
     128          foreach my $limit (@$limits) {
     129              return $limit->{value} if $limit->{name} eq $name;
     130          }
     131          carp "Unable to find limit $name in REJECTION list for $type.\n";
     132          return undef;
     133      }
     134  }
     135
     136    if (not defined $filter) {
     137        carp "Unable to find type $type with no FILTER in REJECTION list.\n";
     138    } else {
     139        carp "Unable to find type $type with FILTER $filter in REJECTION list.\n";
     140    }
     141    return undef;
     142}
     143
     144
     145# Lookup the metadata, checking the type is STR
    58146sub _mdLookupStr
    59147{
     
    73161}
    74162
     163# Lookup the metadata, checking the type is MD
     164sub _mdLookupMD
     165{
     166    my $mdc = shift;            # Metadata config to look up
     167    my $name = shift;           # Name of item to look ip
     168
     169    # Iterate through the array of hashes
     170    foreach my $item (@$mdc) {
     171        if ($item->{name} eq $name) {
     172            carp "$name within metadata is not of type METADATA.\n" unless $item->{class} eq "metadata";
     173            return $item->{value};
     174        }
     175    }
     176
     177    carp "Unable to find $name within metadata.\n";
     178    return undef;
     179}
     180
    75181
    761821;
Note: See TracChangeset for help on using the changeset viewer.