IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19761 for trunk/PStamp


Ignore:
Timestamp:
Sep 25, 2008, 2:06:31 PM (18 years ago)
Author:
bills
Message:

get project information from database

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PStamp/lib/PStamp/Job.pm

    r19277 r19761  
    334334
    335335# splits meta data config input stream into single units to work around the pathalogically
    336 # slow parser. This is similar to and adapted from code in various of the ippScripts.
     336# slow parser. This is similar to and adapted from code in various ippScripts.
    337337sub parse_md_fast {
    338338    my $mdcParser = shift;
     
    374374# resolve_project()
    375375# get project specific information
    376 # This is a placeholder final implementation will use configuration file and database to
    377 # map from "project" to image database, dvo database, telescope, camera, etc
    378 #
    379 # For now just get the database and the class_id that will be used for image lookup
    380 
    381376sub resolve_project {
     377    my $ipprc = shift;
    382378    my $project_name = shift;
    383     my $img_type     = shift;
    384     my $class_id     = shift;
     379    my $dbname = shift;
    385380    die "project is not defined" if !$project_name;
    386381
    387     # for megacam and simtest since images are at the fpa level, leave out the
    388     # class_id at the lookup stage
    389     #
    390     # TODO: get this information from a database or a configuration file
    391 
    392     my $ret_dbname;
    393     my $ret_class_id;
    394     my $ret_inst;
    395     my $ret_magic;
    396     my $ret_camera;
    397 
    398     if ($project_name eq "megacam-mops") {
    399         $ret_dbname = "mops";
    400         $ret_class_id = "null";
    401         $ret_camera = "MEGACAM";
    402         $ret_magic = 0;
    403     } elsif ($project_name eq "simtest") {
    404         $ret_dbname = "ps_simtest";
    405         $ret_class_id = "null";
    406         $ret_camera = "SIMTEST";
    407         $ret_magic = 0;
    408     } elsif ($project_name eq "gpc1") {
    409         $ret_dbname = "gpc1";
    410         $ret_class_id = $class_id;
    411         $ret_camera = "GPC1";
    412         $ret_magic = 0; # switch this to 1 when we're ready
    413     } else {
    414         die "unknown project $project_name";
    415     }
    416 
    417     if (($img_type ne "raw") and ($img_type ne "chip")) {
    418         # don't need class_id
    419         $ret_class_id = "";
    420     }
    421 
    422     return ($ret_dbname, $ret_class_id, $ret_camera, $ret_magic);
    423 }
    424 
     382    my $verbose = 1;
     383
     384    my $missing_tools;
     385    my $pstamptool = can_run("pstamptool") or (warn "Can't find pstamptool" and $missing_tools = 1);
     386    if ($missing_tools) {
     387        warn("Can't find required tools.");
     388        exit ($PS_EXIT_CONFIG_ERROR);
     389    }
     390
     391    my $command = "$pstamptool -project -name $project_name";
     392    $command .= " -dbname $dbname" if defined $dbname;
     393    # run the tool and parse the output
     394    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     395                run(command => $command, verbose => $verbose);
     396    unless ($success) {
     397        print STDERR @$stderr_buf;
     398        return undef;
     399    }
     400
     401    my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     402
     403    my $output = join "", @$stdout_buf;
     404    if (!$output) {
     405        print STDERR "no output returned from $command\n" if $verbose;
     406        return undef;
     407    }
     408    my $proj_hash = parse_md_fast($mdcParser, $output);
     409
     410
     411    return $proj_hash->[0];
     412}
    4254131;
Note: See TracChangeset for help on using the changeset viewer.