IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 11, 2011, 4:29:48 PM (15 years ago)
Author:
watersc1
Message:

Trying to merge back into trunk.

Location:
branches/czw_branch/20101203
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/ippScripts/scripts/register_imfile.pl

    r30118 r30586  
    1010my $date = `date`;
    1111print "\n\n";
    12 print "Starting script $0 on $host at $date\n\n";
     12my $cmd_line = join ' ', @ARGV;
     13print "Starting script $0 $cmd_line on $host at $date\n\n";
    1314
    1415use vars qw( $VERSION );
     
    3940
    4041my ($cache, $exp_id, $tmp_class_id, $tmp_exp_name, $uri, $bytes, $md5sum, $dbname, $verbose, $no_update, $no_op, $logfile);
     42my ($sunrise, $sunset);
    4143GetOptions(
    4244    'caches'           => \$cache,
     
    4749    'bytes=s'          => \$bytes,
    4850    'md5sum=s'         => \$md5sum,
     51    'sunrise=s'        => \$sunrise,
     52    'sunset=s'         => \$sunset,
    4953    'dbname|d=s'       => \$dbname,    # Database name
    5054    'verbose'          => \$verbose,   # Print to stdout
     
    5458) or pod2usage( 2 );
    5559
    56 my $ipprc = PS::IPP::Config->new() or my_die( "Unable to set up", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    57 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_SYS_ERROR ) if $logfile;
     60my $ipprc = PS::IPP::Config->new() or my_die_for_add( "Unable to set up", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     61$ipprc->redirect_output($logfile) or my_die_for_add( "Unable to redirect output", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_SYS_ERROR ) if $logfile;
    5862
    5963pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     
    6569    defined $uri;
    6670
     71unless (defined($sunset)) {
     72    $sunset = '03:30:00';
     73}
     74unless (defined($sunrise)) {
     75    $sunrise = '17:30:00';
     76}
    6777
    6878my $RECIPE = "REGISTER"; # Recipe to use for ppStats
     
    8494
    8595my $cmdflags;
    86 my $burntoolStateGood;
     96my $burntoolStateTarget;
     97my $burntoolStateCurrent;
    8798# Run ppStats on the input file
    8899{
     
    101112    print "STDOUT:\n$out1";
    102113    print "STDERR:\n$err1";
    103     &my_die("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h1->result() or $PS_EXIT_PROG_ERROR) ) unless $result1;
     114    &my_die_for_add("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h1->result() or $PS_EXIT_PROG_ERROR) ) unless $result1;
    104115
    105116    print "[Running " . join(' ', @command2) . "]\n";
     
    110121    print "STDOUT:\n$out2";
    111122    print "STDERR:\n$err2";
    112     &my_die("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h2->result() or $PS_EXIT_PROG_ERROR) ) unless $result2;
     123    &my_die_for_add("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, ($h2->result() or $PS_EXIT_PROG_ERROR) ) unless $result2;
    113124    chomp $out2;
    114125    $cmdflags = $out2;
    115126
    116127    # Manually parse the burntool_state entry.
    117     my $burntoolState = 0;
     128    $burntoolStateCurrent = 0;
    118129    my $isGPC1 = 0;
    119     $burntoolStateGood = 0;
     130    $burntoolStateTarget = 0;
    120131    foreach my $line (split /\n/, $out1) {
    121132        if ($line =~ /FPA.BURNTOOL.APPLIED/) {
    122133            $line =~ s/^\s+//;
    123             $burntoolState = (split /\s+/, $line)[2];
     134            $burntoolStateCurrent = (split /\s+/, $line)[2];
    124135        }
    125136        if ($line =~ /FPA.CAMERA/) {
     
    131142    }
    132143    if ($isGPC1 != 1) {
    133         $burntoolState = 0; # If it's not GPC1, you shouldn't have run burntool.
    134     }
    135     elsif (($isGPC1 == 1) && ($burntoolState == 1)) {
    136 #       print STDERR "In the good region: >>$burntoolState<<\n";
     144        $burntoolStateCurrent = 0; # If it's not GPC1, you shouldn't have run burntool.
     145    }
     146    elsif (($isGPC1 == 1) && ($burntoolStateCurrent == 1)) {
     147#       print STDERR "In the good region: >>$burntoolStateCurrent<<\n";
    137148        my $ppConfigDump_cmd = "$ppConfigDump -camera GPC1 -dump-camera -";
    138149        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    148159            if ($line =~ /BURNTOOL.STATE.GOOD/) {
    149160                $line =~ s/^\s+//;
    150                 $burntoolStateGood = (split /\s+/, $line)[2];
     161                $burntoolStateTarget = (split /\s+/, $line)[2];
    151162                last;
    152163            }
    153164        }
    154         $burntoolState = $burntoolStateGood; # Positive because this has the header table.
    155 
    156     }
    157     $cmdflags .= " -burntool_state $burntoolState ";
     165        # XXX why was this being equated??
     166        # $burntoolState = $burntoolStateGood; # Positive because this has the header table.
     167
     168    }
     169    $cmdflags .= " -burntool_state $burntoolStateTarget ";
    158170}
    159171
    160172$now_time = localtime();
    161173printf STDERR "\ndone with ppStats: %s\n", $now_time if $verbose;
     174printf STDERR "\nburntool state current: %d target: %d\n", $burntoolStateCurrent, $burntoolStateTarget;
    162175
    163176# we require at a minimum: -telescope, -inst, -filelevel, -class_id, -exp_type
    164 if (uc(&value_for_flag ($cmdflags, "NULL", "-telescope")) eq "NULL") { &my_die ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    165 if (uc(&value_for_flag ($cmdflags, "NULL", "-inst"))      eq "NULL") { &my_die ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    166 if (uc(&value_for_flag ($cmdflags, "NULL", "-filelevel")) eq "NULL") { &my_die ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    167 if (uc(&value_for_flag ($cmdflags, "NULL", "-class_id"))  eq "NULL") { &my_die ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
    168 if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     177if (uc(&value_for_flag ($cmdflags, "NULL", "-telescope")) eq "NULL") { &my_die_for_add ("telescope not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     178if (uc(&value_for_flag ($cmdflags, "NULL", "-inst"))      eq "NULL") { &my_die_for_add ("inst      not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     179if (uc(&value_for_flag ($cmdflags, "NULL", "-filelevel")) eq "NULL") { &my_die_for_add ("filelevel not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     180if (uc(&value_for_flag ($cmdflags, "NULL", "-class_id"))  eq "NULL") { &my_die_for_add ("class_id  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     181if (uc(&value_for_flag ($cmdflags, "NULL", "-exp_type"))  eq "NULL") { &my_die_for_add ("exp_type  not found", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $PS_EXIT_CONFIG_ERROR); }
     182my $dateobs   = &value_for_flag($cmdflags, 0.0, "-dateobs");
    169183
    170184my $command = "$regtool -addprocessedimfile";
     
    177191$command .= " -hostname $host" if defined $host;
    178192$command .= " -dbname $dbname" if defined $dbname;
    179 $command .= " -data_state check_burntool";
     193if (abs($burntoolStateCurrent) == $burntoolStateTarget) {
     194    printf STDERR "This has already been burned.\n";
     195    $command .= " -data_state full";
     196}
     197elsif (is_daytime($dateobs,$sunrise,$sunset)) {
     198    printf STDERR "This is a daytime exposure.\n";
     199    $command .= " -data_state full";
     200}
     201else {
     202    printf STDERR "Need to check burntool.\n";
     203    $command .= " -data_state check_burntool";
     204}
    180205$command .= " $cmdflags";
    181206
     
    187212my $ra        = &value_for_flag($cmdflags, 0.0, "-ra");
    188213my $dec       = &value_for_flag($cmdflags, 0.0, "-decl");
    189 my $dateobs   = &value_for_flag($cmdflags, 0.0, "-dateobs");
     214
    190215
    191216# if the needed data is available, pass it to sunmoon:
     
    216241# lock file?
    217242# if exp_type = DARK and date > MIDNIGHT HST { wait }
    218 # system("ipp_apply_burntool.pl --class_id $class_id --dateobs_begin $date_start --dateobs_end $date_end --dbname gpc1 --logfile /data/$host.0/burntool_logs/$class_id.$start_date.log"); 
     243# system("ipp_apply_burntool.pl --class_id $class_id --dateobs_begin $date_start --dateobs_end $date_end --dbname gpc1 --logfile /data/$host.0/burntool_logs/$class_id.$start_date.log");
    219244
    220245$now_time = localtime();
     
    236261# We now have an imfile in the database, check if we can burntool it.  If not, continue on.
    237262
    238 {
     263if ((abs($burntoolStateCurrent) != $burntoolStateTarget)&&
     264    (!is_daytime($dateobs,$sunrise,$sunset))) {
    239265    my $mdcParser  = PS::IPP::Metadata::Config->new;
    240266
     
    243269    $check_date =~ s/T.*$//;
    244270    my $exp_name   = $tmp_exp_name;
    245    
     271
    246272
    247273    my $bt_check_command = "$regtool -checkburntoolimfile ";
    248274    $bt_check_command .= " -class_id $class_id ";
    249     $bt_check_command .= " -date $check_date ";
    250     $bt_check_command .= " -valid_burntool $burntoolStateGood ";
     275    $bt_check_command .= " -dateobs_begin ${check_date}T${sunset} ";
     276    $bt_check_command .= " -dateobs_end ${check_date}T${sunrise} ";
     277    $bt_check_command .= " -valid_burntool $burntoolStateTarget ";
    251278    $bt_check_command .= " -exp_name $exp_name ";
    252279    $bt_check_command .= " -dbname $dbname" if defined $dbname;
    253280
    254281    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    255         run ( command => $bt_check_command, verbose => $verbose);
     282        run ( command => $bt_check_command, verbose => $verbose);
    256283    unless ($success) {
    257         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    258         &my_die("Unable to perform regtool: $error_code",
    259                 $class_id, $exp_name, $date, $PS_EXIT_SYS_ERROR);
     284        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     285        &my_die_for_update("Unable to perform regtool: $error_code",
     286                           $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
    260287    }
    261288
     
    264291    my $exposures;
    265292    while ( scalar @whole > 0 ) {
    266         my $value = shift @whole;
    267         push @single, $value;
    268         if ($value =~ /^\s*END\s*$/) {
    269             push @single, "\n";
    270            
    271             my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
    272             &my_die("Unable to parse output from regtool",
    273                     $class_id, $exp_name, $date, $PS_EXIT_SYS_ERROR) unless
    274                         defined $list;
    275             push @{ $exposures }, @$list;
    276             @single = ();
    277         }
    278     }
    279    
     293        my $value = shift @whole;
     294        push @single, $value;
     295        if ($value =~ /^\s*END\s*$/) {
     296            push @single, "\n";
     297
     298            my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
     299            &my_die_for_update("Unable to parse output from regtool",
     300                               $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless
     301                                   defined $list;
     302            push @{ $exposures }, @$list;
     303            @single = ();
     304        }
     305    }
     306
    280307    # We only care about the final entry, as that contains the exposure we are.
    281    
     308
    282309    my $regtool_update = "$regtool -updateprocessedimfile ";
    283310    $regtool_update .= "-dbname $dbname " if defined $dbname;
     
    286313    my $burntool_data = pop(@{ $exposures });
    287314    if ($burntool_data->{burnable} == 0) {
    288         $regtool_update .= " -burntool_state 0 -set_state pending_burntool ";
    289         unless ($no_update) {
    290             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    291                 IPC::Cmd::run(command => $regtool_update, verbose => $verbose);
    292             unless ($success) {
    293                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    294                 warn ("Unable to perform regtool -addprocessedimfile: $error_code");
    295                 exit($error_code);
    296             }
    297         } else {
    298             print "skipping command: $command\n";
    299         }
     315        $regtool_update .= " -burntool_state 0 -set_state pending_burntool ";
     316        unless ($no_update) {
     317            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     318                IPC::Cmd::run(command => $regtool_update, verbose => $verbose);
     319            unless ($success) {
     320                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     321                warn ("Unable to perform regtool -addprocessedimfile: $error_code");
     322                exit($error_code);
     323            }
     324        } else {
     325            print "skipping command: $command\n";
     326        }
    300327    }
    301328    else {
    302         my $apply_command = "$ippApplyBurntoolSingle --dbname $dbname ";
    303         $apply_command .= " --class_id $class_id --exp_id $exp_id ";
    304         $apply_command .= " --this_uri $burntool_data->{uri} ";
    305         $apply_command .= " --previous_uri $burntool_data->{previous_uri} " if defined $burntool_data->{previous_uri};
    306         $apply_command .= " --imfile_state $burntool_data->{imfile_state} ";
    307         $apply_command .= " --verbose " if $verbose;
    308         print "$apply_command\n";
    309         unless ($no_update) {
    310             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    311                 IPC::Cmd::run(command => $apply_command, verbose => $verbose);
    312             unless ($success) {
    313                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    314                 warn ("Unable to perform ipp_apply_burntool_single.pl: $error_code");
    315                 exit($error_code);
    316             }
    317         }
    318     }   
     329        my $apply_command = "$ippApplyBurntoolSingle --dbname $dbname ";
     330        $apply_command .= " --class_id $class_id --exp_id $exp_id ";
     331        $apply_command .= " --this_uri $burntool_data->{uri} ";
     332        $apply_command .= " --previous_uri $burntool_data->{previous_uri} " if defined $burntool_data->{previous_uri};
     333        $apply_command .= " --imfile_state $burntool_data->{imfile_state} ";
     334        $apply_command .= " --verbose " if $verbose;
     335        print "$apply_command\n";
     336        unless ($no_update) {
     337            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     338                IPC::Cmd::run(command => $apply_command, verbose => $verbose);
     339            unless ($success) {
     340                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     341                &my_die_for_update("Unable to perform ipp_apply_burntool_single.pl: $error_code",
     342                               $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
     343            }
     344        }
     345    }
    319346
    320347
     
    353380}
    354381
    355 sub my_die
     382sub is_daytime
     383{
     384    my $dateobs = shift;
     385    my $sunset  = shift;
     386    my $sunrise = shift;
     387
     388    my ($date,$time);
     389
     390    if ($dateobs =~ /T/) {
     391        ($date,$time) = split /T/, $dateobs;
     392    }
     393    else {
     394        ($date,$time) = split / /, $dateobs;
     395    }
     396    my ($hour,$minute,$second) = split /\:/, $time; # /;
     397    my ($ss_hour,$ss_minute,$ss_second) = split /\:/, $sunset; # /;
     398    my ($sr_hour,$sr_minute,$sr_second) = split /\:/, $sunrise; # /;
     399    if ($second =~ /Z/) {
     400        $second =~ s/Z//;
     401    }
     402#     print "this exposure: $hour $minute $second\n";
     403#     print "sunset:        $ss_hour $ss_minute $ss_second\n";
     404#     print "sunrise:       $sr_hour $sr_minute $sr_second\n";
     405#     printf "Hss: %d Mss: %d Sss: %d\n",($hour >= $ss_hour),($minute >= $ss_minute),($second >= $ss_second);
     406#     printf "Hsr: %d Msr: %d Ssr: %d\n",($hour <= $sr_hour),($minute <= $sr_minute),($second <= $sr_second);
     407
     408    if (($hour > $ss_hour)&&($hour <= 24)) {
     409        return(1); # After sunset by more than an hour, before midnight
     410    }
     411    elsif ($hour == $ss_hour) {
     412        if ($minute > $ss_minute) {
     413            return(1); # After sunset by more than a minute
     414        }
     415        elsif ($minute == $ss_minute) {
     416            if ($second >= $ss_second) {
     417                return(1); # After sunset by more than a second
     418            }
     419            else {
     420                return(0);
     421            }
     422        }
     423        else {
     424            return(0);
     425        }
     426    }
     427    elsif (($hour < $sr_hour)&&($hour >= 0)) {
     428        return(1); # Before sunrise by more than an hour, but after midnight
     429    }
     430    elsif ($hour == $sr_hour) {
     431        if ($minute < $sr_minute) {
     432            return(1); # Before sunrise by more than a minute
     433        }
     434        elsif ($minute == $sr_minute) {
     435            if ($second <= $sr_second) {
     436                return(1); # Before sunrise by more than a second
     437            }
     438            else {
     439                return(0);
     440            }
     441        }
     442        else {
     443            return(0);
     444        }
     445    }
     446    else {
     447        return(0); # We should never get here.
     448    }
     449}
     450
     451sub my_die_for_add
    356452{
    357453    my $msg = shift; # Warning message on die
     
    384480    exit $exit_code;
    385481}
     482sub my_die_for_update
     483{
     484    my $msg = shift; # Warning message on die
     485    my $exp_id = shift;
     486    my $class_id = shift;
     487    my $exit_code = shift;
     488
     489    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
     490
     491    carp($msg);
     492    if (defined $exp_id && defined $tmp_class_id and not $no_update) {
     493        my $command = "$regtool -updateprocessedimfile";
     494        $command .= " -exp_id $exp_id";
     495        $command .= " -class_id $class_id";
     496        $command .= " -fault $exit_code";
     497        $command .= " -hostname $host" if defined $host;
     498        $command .= " -dbname $dbname" if defined $dbname;
     499        print "Running: $command\n";
     500        system($command);
     501    }
     502    exit $exit_code;
     503}
    386504
    387505# Pau.
Note: See TracChangeset for help on using the changeset viewer.