- Timestamp:
- Feb 11, 2011, 4:29:48 PM (15 years ago)
- Location:
- branches/czw_branch/20101203
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/register_imfile.pl (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20101203
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippScripts/scripts/register_imfile.pl
r30118 r30586 10 10 my $date = `date`; 11 11 print "\n\n"; 12 print "Starting script $0 on $host at $date\n\n"; 12 my $cmd_line = join ' ', @ARGV; 13 print "Starting script $0 $cmd_line on $host at $date\n\n"; 13 14 14 15 use vars qw( $VERSION ); … … 39 40 40 41 my ($cache, $exp_id, $tmp_class_id, $tmp_exp_name, $uri, $bytes, $md5sum, $dbname, $verbose, $no_update, $no_op, $logfile); 42 my ($sunrise, $sunset); 41 43 GetOptions( 42 44 'caches' => \$cache, … … 47 49 'bytes=s' => \$bytes, 48 50 'md5sum=s' => \$md5sum, 51 'sunrise=s' => \$sunrise, 52 'sunset=s' => \$sunset, 49 53 'dbname|d=s' => \$dbname, # Database name 50 54 'verbose' => \$verbose, # Print to stdout … … 54 58 ) or pod2usage( 2 ); 55 59 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 configuration57 $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;60 my $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; 58 62 59 63 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; … … 65 69 defined $uri; 66 70 71 unless (defined($sunset)) { 72 $sunset = '03:30:00'; 73 } 74 unless (defined($sunrise)) { 75 $sunrise = '17:30:00'; 76 } 67 77 68 78 my $RECIPE = "REGISTER"; # Recipe to use for ppStats … … 84 94 85 95 my $cmdflags; 86 my $burntoolStateGood; 96 my $burntoolStateTarget; 97 my $burntoolStateCurrent; 87 98 # Run ppStats on the input file 88 99 { … … 101 112 print "STDOUT:\n$out1"; 102 113 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; 104 115 105 116 print "[Running " . join(' ', @command2) . "]\n"; … … 110 121 print "STDOUT:\n$out2"; 111 122 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; 113 124 chomp $out2; 114 125 $cmdflags = $out2; 115 126 116 127 # Manually parse the burntool_state entry. 117 my $burntoolState= 0;128 $burntoolStateCurrent = 0; 118 129 my $isGPC1 = 0; 119 $burntoolState Good= 0;130 $burntoolStateTarget = 0; 120 131 foreach my $line (split /\n/, $out1) { 121 132 if ($line =~ /FPA.BURNTOOL.APPLIED/) { 122 133 $line =~ s/^\s+//; 123 $burntoolState = (split /\s+/, $line)[2];134 $burntoolStateCurrent = (split /\s+/, $line)[2]; 124 135 } 125 136 if ($line =~ /FPA.CAMERA/) { … … 131 142 } 132 143 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"; 137 148 my $ppConfigDump_cmd = "$ppConfigDump -camera GPC1 -dump-camera -"; 138 149 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 148 159 if ($line =~ /BURNTOOL.STATE.GOOD/) { 149 160 $line =~ s/^\s+//; 150 $burntoolState Good= (split /\s+/, $line)[2];161 $burntoolStateTarget = (split /\s+/, $line)[2]; 151 162 last; 152 163 } 153 164 } 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 "; 158 170 } 159 171 160 172 $now_time = localtime(); 161 173 printf STDERR "\ndone with ppStats: %s\n", $now_time if $verbose; 174 printf STDERR "\nburntool state current: %d target: %d\n", $burntoolStateCurrent, $burntoolStateTarget; 162 175 163 176 # 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); } 177 if (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); } 178 if (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); } 179 if (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); } 180 if (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); } 181 if (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); } 182 my $dateobs = &value_for_flag($cmdflags, 0.0, "-dateobs"); 169 183 170 184 my $command = "$regtool -addprocessedimfile"; … … 177 191 $command .= " -hostname $host" if defined $host; 178 192 $command .= " -dbname $dbname" if defined $dbname; 179 $command .= " -data_state check_burntool"; 193 if (abs($burntoolStateCurrent) == $burntoolStateTarget) { 194 printf STDERR "This has already been burned.\n"; 195 $command .= " -data_state full"; 196 } 197 elsif (is_daytime($dateobs,$sunrise,$sunset)) { 198 printf STDERR "This is a daytime exposure.\n"; 199 $command .= " -data_state full"; 200 } 201 else { 202 printf STDERR "Need to check burntool.\n"; 203 $command .= " -data_state check_burntool"; 204 } 180 205 $command .= " $cmdflags"; 181 206 … … 187 212 my $ra = &value_for_flag($cmdflags, 0.0, "-ra"); 188 213 my $dec = &value_for_flag($cmdflags, 0.0, "-decl"); 189 my $dateobs = &value_for_flag($cmdflags, 0.0, "-dateobs"); 214 190 215 191 216 # if the needed data is available, pass it to sunmoon: … … 216 241 # lock file? 217 242 # 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"); 219 244 220 245 $now_time = localtime(); … … 236 261 # We now have an imfile in the database, check if we can burntool it. If not, continue on. 237 262 238 { 263 if ((abs($burntoolStateCurrent) != $burntoolStateTarget)&& 264 (!is_daytime($dateobs,$sunrise,$sunset))) { 239 265 my $mdcParser = PS::IPP::Metadata::Config->new; 240 266 … … 243 269 $check_date =~ s/T.*$//; 244 270 my $exp_name = $tmp_exp_name; 245 271 246 272 247 273 my $bt_check_command = "$regtool -checkburntoolimfile "; 248 274 $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 "; 251 278 $bt_check_command .= " -exp_name $exp_name "; 252 279 $bt_check_command .= " -dbname $dbname" if defined $dbname; 253 280 254 281 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); 256 283 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); 260 287 } 261 288 … … 264 291 my $exposures; 265 292 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) unless274 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 280 307 # We only care about the final entry, as that contains the exposure we are. 281 308 282 309 my $regtool_update = "$regtool -updateprocessedimfile "; 283 310 $regtool_update .= "-dbname $dbname " if defined $dbname; … … 286 313 my $burntool_data = pop(@{ $exposures }); 287 314 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 } 300 327 } 301 328 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 } 319 346 320 347 … … 353 380 } 354 381 355 sub my_die 382 sub 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 451 sub my_die_for_add 356 452 { 357 453 my $msg = shift; # Warning message on die … … 384 480 exit $exit_code; 385 481 } 482 sub 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 } 386 504 387 505 # Pau.
Note:
See TracChangeset
for help on using the changeset viewer.
