IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38578


Ignore:
Timestamp:
Jul 7, 2015, 4:53:55 PM (11 years ago)
Author:
heather
Message:

addstar multimode works - needs better stuff for logging, but its tested, it works, addstar is happy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/addstar_multi_run.pl

    r38479 r38578  
    3939my $minidvodb_path;
    4040
    41 my ( $add_id, $camera, $stage, $stage_id, $stage_extra1, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update,
     41my ( $label,$camera, $stage, $stage_id, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update,
    4242     $no_op, $redirect, $save_temps);
    4343GetOptions(
    44     'add_id=s'          => \$add_id, # Camtool identifier
     44    'label=s'          => \$label, #addstar label
    4545    'camera|c=s'        => \$camera, # Camera
    4646    'stage|s=s'        => \$stage, # Camera
    4747    'stage_id|w=s'   => \$stage_id,
    48     'stage_extra1|w=s'    => \$stage_extra1, # the number for a staticskymulti (for finding cmf), or stack_id
    4948    'dbname|d=s'        => \$dbname, # Database name
    5049    'outroot|w=s'       => \$outroot, # output file base name
     
    6564pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    6665pod2usage(
    67           -msg => "Required options: --add_id --camera --outroot --dvodb --stageroot --stage",
     66          -msg => "Required options: --label --stage_id --stage  --camera --outroot --dvodb --stageroot",
    6867          -exitval => 3,
    6968          ) unless
    7069    defined $stage and
    71     defined $add_id and
     70    defined $stage_id and
     71    defined $label and
    7272    defined $outroot and
    7373    defined $stageroot and
    7474    defined $dvodb and
    7575    defined $camera;
    76 if ($stage =~ /cam/ && !defined $stage_id) {
    77     my_die("cam stage requires -stage_id", $add_id, 3);
    78 
    79 }
     76
    8077if ($minidvodb && !defined($minidvodb_group)) {
    81                 my_die( "missing minidvodb_group", $add_id, 3 );
     78                my_die( "missing minidvodb_group", $stage_id, $stage, $label, 3 );
    8279            }
    83 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $add_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    84 
    85 my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    86 
     80my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $stage_id, $stage, $label, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     81
     82my $logDest = $ipprc->filename("LOG.EXP", $outroot) or &my_die("Missing entry from camera config", $stage_id, $stage, $label, $PS_EXIT_CONFIG_ERROR);
     83
     84#my $logDest = "stuff.txt";
    8785if ($redirect) {
    88     $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $add_id, $PS_EXIT_SYS_ERROR );
     86    $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $stage_id,$stage, $label, $PS_EXIT_SYS_ERROR );
    8987    print "\n\n";
    9088    print "Starting script $0 on $host\n\n";
     
    9492# Recipes to use based on reduction class
    9593$reduction = 'DEFAULT' unless defined $reduction;
    96 #if ($stage =~/diff/) {
    97 #    $reduction = 'ADDSTAR';
    98 #}
    99 #if ($stage =~/fullforce/) {
    100 #    $reduction = 'ADDSTAR';
    101 #}
    10294
    10395if ($stage =~/fullforce/) {
     
    111103
    112104my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR');
    113 # XXX This is now not used: do we still need it?
    114 if ($stage =~/cam/) {
    115   $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
    116 }
    117 if ($stage =~/stack/) {
    118   $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STACK'); # Recipe to use
    119 }
    120 #if ($stage =~/staticsky/) {
    121 #  $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STATICSKY'); # Recipe to use
    122 #}
    123 if ($stage =~/skycal/) {
    124     $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use                                                             
    125 }
    126 
    127 
    128 
    129 &my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
     105
     106&my_die("Unrecognised ADDSTAR recipe", $stage_id, $stage, $label, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
    130107
    131108my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    132109
    133 # Output products
    134 $ipprc->outroot_prepare($outroot);
    135 
    136 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
    137 
    138 # it was PSASTRO.OUTPUT
    139 
    140 my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT", $stageroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    141 my $fpaObjectsAlt = $fpaObjects;
    142 
    143 if ($stage =~ /skycal/) {
    144     #should be ok for skycal?
    145     print "using $fpaObjects for $stage\n";
    146 }
    147 if ($stage =~/diff/) {
    148     print "using $fpaObjects for $stage\n";
    149 }
    150 if ($stage =~/fullforce/)  {
    151     print "using $fpaObjects for $stage\n";
    152 }
    153 
    154 
    155 
    156 if ($stage =~ /cam/) {
    157     # if it is cam stage we need to be careful when grabbing the filename.
    158     # This breaks down into a few steps:
    159    
    160     #get info about the cam_id
    161     my $magicked;
    162     {
    163         my $mdcParser = PS::IPP::Metadata::Config->new;
    164         my $command = "$camtool -processedexp -cam_id " . $stage_id;
    165         $command .= " -dbname $dbname" if defined $dbname;
     110my $temp_file = $outroot.".log.".$label.".".$stage.".".$stage_id.".list";
     111my $temp_file = "/tmp/addstar.list";
     112
     113print "using $temp_file for list\n";
     114
     115open( TEMPLIST, ">$temp_file") or &my_die( "Can't open $temp_file\n", $stage_id,$stage,$label, $PS_EXIT_UNKNOWN_ERROR);
     116
     117{
     118    my $mdcParser = PS::IPP::Metadata::Config->new;
     119    my $command = "$addtool -pendingexp -stage_id ".$stage_id;
     120    $command .= " -stage $stage -label $label";
     121    $command .= " -dbname $dbname" if defined $dbname;
     122
    166123        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    167124            run(command => $command, verbose => $verbose);
    168         &my_die( "Unable to get info on camRun", $add_id, $PS_EXIT_SYS_ERROR) unless $success;
    169         if (scalar @$stdout_buf == 0 ) { #it lists nothing if it is the first
    170             &my_die( "empty camRun", $add_id, $PS_EXIT_SYS_ERROR);
    171             print "listing nothing\n";
    172         } else {
    173             my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    174                 &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR);
    175             #this fails if there is nothing listed. I checked.
    176             my $components = parse_md_list($metadata) or
    177                 &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);
    178             my $comp = $$components[0];
    179             my  $mparsed = $comp->{magicked};
    180            
    181             if (!defined($mparsed)) {
    182                 &my_die("Unable to parse magicked", $add_id, $PS_EXIT_PROG_ERROR);
    183             } #but just to make sure, have it grab a minidvodb_name, to make sure it's not junk.
    184             print "found a value for magicked:$mparsed\n";
    185             $magicked = $mparsed;
    186         }
    187        
    188         #is this cam_id magicked or not?
    189         if ($magicked) {
    190             $stage_extra1 = $magicked;
    191             $fpaObjects = $ipprc->destreaked_filename("$fpaObjects") or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    192             print "cam_id is magicked, using $fpaObjects for the cam smf\n";
    193         } else {
    194             print "cam_id is NOT magicked, using $fpaObjects for the cam smf\n";
    195         }
    196     }
    197 }
    198 
    199 if (($stage =~/stack/ || $stage =~ /skycal/ || $stage =~/diff/ || $stage=~/fullforce/)) {
    200     $fpaObjects =~ s/smf$/cmf/;
    201     $fpaObjectsAlt =~ s/smf$/cmf/;
    202 
    203 }
    204 
    205 my $fpaObjects1;
    206 my $fpaObjects2;
    207 my $checkalt = 0;
    208 if ($stage =~/staticsky/) {
    209     $checkalt = 1;
    210     my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $stageroot); #this is mostly rigtht except the .cmf needs either
    211     # .000.cmf or .stk.xxxxx.cmf
    212     print "$sources\n\n\n";
    213     &my_die( "can't find the filter_num for staticsky_multi, giving up.", $add_id, $PS_EXIT_SYS_ERROR) unless (defined $stage_extra1);
    214 
    215    
    216     $fpaObjects1 = $sources;
    217     $fpaObjects2 = $sources;
    218     $fpaObjects = $sources;
    219 
    220     my $nice_num = sprintf ("%03d", $stage_extra1);
    221 
    222     $fpaObjects1 =~ s/cmf$/stk.$stage_extra1.cmf/;
    223     $fpaObjects2 =~ s/cmf$/$nice_num.cmf/;  #this make it look for .001.cmf, etc
    224  # we have 3 of them to try
    225     my $realFile = $ipprc->file_resolve($fpaObjects);
    226     my $realFile1 = $ipprc->file_resolve($fpaObjects1);
    227     my $realFile2 = $ipprc->file_resolve($fpaObjects2);
    228     if (!defined($realFile1)) {
    229         if (!defined($realFile2)) {
    230             print "using $fpaObjects\n";
    231            
    232         } else {
    233             print "using $fpaObjects2\n";
    234             $fpaObjects = $fpaObjects2;
    235         }
     125    &my_die( "Unable to get info on addRun", $stage_id,$stage, $label, $PS_EXIT_SYS_ERROR) unless $success;
     126    if (scalar @$stdout_buf == 0 ) { #it lists nothing if it is the first
     127        &my_die( "empty addRun", $stage_id,$stage,$label, $PS_EXIT_SYS_ERROR);
    236128       
    237129    } else {
    238         print "using $fpaObjects1\n";
    239         $fpaObjects = $fpaObjects1;
    240     }
    241      
    242 
    243 }
    244 
    245 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
    246        
     130            my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     131                &my_die("Unable to parse metadata config", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
     132            #this fails if there is nothing listed. I checked.
     133            my $components = parse_md_list($metadata) or
     134                &my_die("Unable to parse metadata list", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
     135            my $num_components = scalar @$components;
     136            print "there are $num_components\n";
     137            foreach my $comp  (@$components) {
     138            my  $mparsed = $comp->{stageroot};
     139           
     140            if (!defined($mparsed)) {
     141                &my_die("Unable to parse stageroot", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
     142            } #but just to make sure, have it grab a minidvodb_name, to make sure it's not junk.
     143            print "found a value for stageroot:$mparsed\n";
     144            my $fpaObjects = $mparsed.'.cmf';
     145            my $realFile = $ipprc->file_resolve($fpaObjects);
     146            if (!defined($realFile)) {
     147                &my_die("unable to resolve real file from $mparsed",$stage_id, $stage, $label, 7);
     148            }
     149            printf TEMPLIST "$realFile = $fpaObjects\n";
     150            }
     151    }
     152
     153}
     154
     155close(TEMPLIST);
     156print "saved $temp_file here\n";
     157
    247158# convert supplied DVO database name to UNIX filename
    248159my $dvodbReal;
    249160if (defined $dvodb) {
    250161    $dvodbReal = $ipprc->dvo_catdir( $dvodb ); # catdir for DVO
    251     $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $add_id, $PS_EXIT_CONFIG_ERROR);
     162    $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $stage_id,$stage,$label, $PS_EXIT_CONFIG_ERROR);
    252163}
    253164my $dtime_addstar = 0;
     
    262173        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    263174            run(command => $command, verbose => $verbose);
    264         &my_die( "Unable to get active minidvodb_name", $add_id, $PS_EXIT_SYS_ERROR) unless $success;
     175        &my_die( "Unable to get active minidvodb_name", $stage_id,$stage,$label, $PS_EXIT_SYS_ERROR) unless $success;
    265176        my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    266             &my_die("Unable to parse metadata config", $add_id, $PS_EXIT_PROG_ERROR);
     177            &my_die("Unable to parse metadata config", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
    267178
    268179        my $components = parse_md_list($metadata) or
    269             &my_die("Unable to parse metadata list", $add_id, $PS_EXIT_PROG_ERROR);
     180            &my_die("Unable to parse metadata list", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
    270181        my $comp = $$components[0];
    271182        $minidvodb_path = $comp->{minidvodb_path};
     
    273184       
    274185        if (!defined($minidvodb_path)) {
    275             &my_die("Unable to parse minidvodb_path", $add_id, $PS_EXIT_PROG_ERROR);
     186            &my_die("Unable to parse minidvodb_path", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
    276187        }
    277188        if (!defined($minidvodb_name)) {
    278             &my_die("Unable to parse minidvodb_name", $add_id, $PS_EXIT_PROG_ERROR);
     189            &my_die("Unable to parse minidvodb_name", $stage_id,$stage,$label, $PS_EXIT_PROG_ERROR);
    279190        }
    280191    }
     
    296207            my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
    297208           
    298             my $realFile = $ipprc->file_resolve($fpaObjects) or  &my_die("Unable to resolve $fpaObjects", $add_id, $PS_EXIT_SYS_ERROR);
     209#           my $realFile = $ipprc->file_resolve($fpaObjects) or  &my_die("Unable to resolve $fpaObjects", $stage_id,$stage,$label, $PS_EXIT_SYS_ERROR);
    299210
    300211            # most cameras use CHIP_HEADER.  other exceptions:
     
    316227            $command .= " -D CATDIR $minidvodb_path";
    317228            $command .= " -D ZERO_POINT_OPTION $zeroPointOption";
    318             $command .= " $realFile";
    319             $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
     229            $command .= " -list $temp_file";
    320230            $command .= " -image" if $image_only;
    321231            if ($stage =~ /staticsky/) {
     
    338248            unless ($success) {
    339249                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    340                 &my_die("Unable to perform addstar: $error_code", $add_id, $error_code);
     250                &my_die("Unable to perform addstar: $error_code", $stage_id,$stage,$label, $error_code);
    341251            }
    342252            $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
     
    344254}
    345255
    346 # This needs to be updated when addtool is written. BROKEN
    347 my $fpaCommand = "$addtool -add_id $add_id";
     256
     257my $fpaCommand = "$addtool -multiadd -stage_id $stage_id";
     258$fpaCommand .= " -stage $stage";
     259$fpaCommand .= " -multiaddlabel $label";
    348260$fpaCommand .= " -addprocessedexp";
    349261$fpaCommand .= " -path_base $outroot";
     
    351263$fpaCommand .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path;
    352264$fpaCommand .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name;
    353 $fpaCommand .= " -stage_extra1 $stage_extra1" if defined $stage_extra1;
    354265$fpaCommand .= " -dbname $dbname" if defined $dbname;
    355266print $fpaCommand;
     
    371282{
    372283    my $msg = shift; # Warning message on die
    373     my $add_id = shift; # Camtool identifier
     284    my $stage_id = shift; # Camtool identifier
     285    my $stage = shift;
     286    my $label = shift;
    374287    my $exit_code = shift; # Exit code to add
    375288
     
    377290
    378291    carp($msg);
    379     if (defined $add_id and not $no_update) {
    380         my $command = "$addtool -add_id $add_id";
     292    if (defined $stage_id and not $no_update) {
     293        my $command = "$addtool -stage_id $stage_id";
    381294        $command .= " -addprocessedexp";
    382295        $command .= " -fault $exit_code";
     296        $command .= " -stage $stage";
     297        $command .= " -label $label";
    383298        $command .= " -dvodb_path $minidvodb_path" if defined $minidvodb_path;
    384299        $command .= " -path_base $outroot" if defined $outroot;
    385300        $command .= (" -dtime_addstar " . ((DateTime->now->mjd - $mjd_start) * 86400));
    386301   #     $command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name; don't think we want it recorded (not sure)
    387         $command .= " -stage_extra1 $stage_extra1" if defined $stage_extra1;
    388302        $command .= " -dbname $dbname" if defined $dbname;
    389303        print $command;
Note: See TracChangeset for help on using the changeset viewer.