IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19761


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

get project information from database

Location:
trunk
Files:
3 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;
  • trunk/pstamp/scripts/pstamp_finish.pl

    r19279 r19761  
    163163        # unless $exp_id is null (e.g. stack images) get the metadata for this exposure
    164164        my ($row, $req_info, $project) = get_request_info($rows, $rownum);
    165         my ($image_db) = resolve_project($project);
     165        my $proj_hash = resolve_project($project);
     166        my $image_db = $proj_hash->{dbname};
    166167        my $exp_info = get_exposure_info($image_db, $exp_id);
    167168
  • trunk/pstamp/scripts/pstampparse.pl

    r19278 r19761  
    143143
    144144    $stamp_name = "" if $stamp_name eq "null";
     145    $class_id = "" if ($class_id eq "null" or $class_id eq "all");
    145146   
    146147    # XXX: TODO: sanity check all parameters
     
    151152    # trash the request.
    152153    die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri");
    153     my ($image_db, $lookup_class_id, $camera, $magic_required ) = resolve_project($project, $img_type, $class_id);
     154
     155    my $proj_hash = resolve_project($ipprc, $project, $dbname);
     156    die "project $project not found\n" unless $proj_hash;
     157
     158    my $image_db = $proj_hash->{dbname};
     159    my $camera = $proj_hash->{camera};
     160    my $need_magic = $proj_hash->{need_magic};
    154161
    155162    my $roi_string;
     
    182189
    183190    # Call PStamp::Job's locate_images routinte to get the parameters for this request specification
    184     my $images = locate_images($ipprc, $image_db, $req_type, $img_type, $id, $lookup_class_id,
     191    my $images = locate_images($ipprc, $image_db, $req_type, $img_type, $id, $class_id,
    185192            $x, $y, $mjd_min, $mjd_max, $filter);
    186193
     
    217224    } else {
    218225        my $args = $roi_string ? $roi_string : "";
    219         $args .= " -class_id $class_id" if ($class_id and ($class_id ne "null"));
     226        $args .= " -class_id $class_id" if $class_id;
    220227
    221228        # sequence number for the the job for a request spec. Not to be confused with job_id
    222229        my $job_num = 0;
    223230
    224         # XXX for raw and chip level images and class_id "null" if there are multiple images
     231        # XXX TODO: for raw and chip level images and class_id "null" if there are multiple images
    225232        # use -list instead of -file
    226233        foreach my $image (@$images) {
     
    248255
    249256            # XXX sounds like magic will be handled outside of the postage stamp server
    250             #if ($magic_required) {
     257            #if ($need_magic) {
    251258            #    die "no magic mask available" if ! $image->{magic_mask};
    252259            #    $args .= " -magic_mask $image->{magic_mask}"
Note: See TracChangeset for help on using the changeset viewer.