Changeset 27838 for branches/tap_branches/tools/gpc1_find_images.pl
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tools/gpc1_find_images.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/tools/gpc1_find_images.pl
r25853 r27838 3 3 use DBI; 4 4 use Getopt::Std; 5 getopts('h FARCPp:BMDWvx:n:c:w:O:S:',\%opt);5 getopts('hEFARCPp:BLMDWIJVYTvx:n:c:w:s:d:e:O:S:N:',\%opt); 6 6 #getopt('xncwOS:hARCW',\%opt); 7 7 unless (exists($opt{O})) { … … 34 34 } 35 35 36 # abcdefghijklmnopqrstuvwxyz 37 #used: 38 # ABCDEF LMNOP RST W Y 39 # c h n s vwx 36 40 if (exists($opt{h})) { 37 41 print "USAGE find_images.pl ... \n"; 38 42 print " -h This help\n"; 39 print " -R Return raw data.\n"; 40 print " -C Return chip stage data.\n"; 41 print " -W Return warp stage data.\n"; 43 print " -R Return Raw data.\n"; 44 print " -C Return Chip stage data.\n"; 45 print " -E Return camEra stage data.\n"; 46 print " -W Return Warp stage data.\n"; 47 print " -T Get the sTacks for a given input.\n"; 48 print " -J Get the dIff stage data (warps only for now).\n"; 42 49 print " -A Return not just fits images.\n"; 43 50 print " -F Convert to real filenames.\n"; … … 45 52 print " -B Return burntool table.\n"; 46 53 print " -M Include masks in results.\n"; 54 print " -L Return the log files from this stage.\n"; 47 55 print " -D Return only pre-destreaked images.\n"; 56 print " -Y Yes, I want the raw, even if it's not been processed.\n"; 57 print " -V Return the cmf or smf files.\n"; 48 58 print " -v Be verbose on output.\n"; 49 59 print " \n"; 50 60 print " -x <exp_id> Specify a exp_id.\n"; 51 61 print " -c <chip_id> ...\n"; 62 print " -e <cam_id> ...\n"; 52 63 print " -w <warp_id> ...\n"; 64 print " -s <stack_id> ...\n"; 65 print " -d <diff_id> ...\n"; 53 66 print " -n <exp_name> ...\n"; 54 67 print " \n"; … … 63 76 $dbname = 'gpc1'; 64 77 $dbserver = 'ippdb01'; 65 $dbuser = 'ipp ';66 $dbpass = 'ipp ';78 $dbuser = 'ippuser'; 79 $dbpass = 'ippuser'; 67 80 $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" . 68 81 "mysql_socket=" . DB_SOCKET(), … … 71 84 ) or die "Unable to connect to database $DBI::errstr\n"; 72 85 73 $sth_base = "SELECT warp_id,warpRun.workdir,chipRun.chip_id,chipRun.workdir,rawExp.exp_name,rawExp.exp_id,rawExp.workdir,rawExp.dateobs,rawExp.pon_time from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING (exp_id)"; 86 if ($opt{Y}) { 87 $sth_base = "SELECT warp_id,warpRun.workdir,chipRun.chip_id,chipRun.workdir,rawExp.exp_name,rawExp.exp_id,rawExp.workdir,rawExp.dateobs,rawExp.pon_time,0,'nostack',camRun.cam_id,camRun.workdir,0,'nodiff' from warpRun RIGHT OUTER JOIN fakeRun USING(fake_id) RIGHT OUTER JOIN camRun USING(cam_id) RIGHT OUTER JOIN chipRun USING(chip_id) RIGHT OUTER JOIN rawExp USING (exp_id)"; 88 } 89 else { 90 $sth_base = "SELECT warp_id,warpRun.workdir,chipRun.chip_id,chipRun.workdir,rawExp.exp_name,rawExp.exp_id,rawExp.workdir,rawExp.dateobs,rawExp.pon_time,0,'nostack',camRun.cam_id,camRun.workdir,0,'nodiff' from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING (exp_id)"; 91 } 92 74 93 # What do we have? 75 94 @sth_adds = (); … … 86 105 if (exists($opt{w})) { 87 106 push @sth_adds, "warpRun.warp_id = $opt{w}"; 107 } 108 if (exists($opt{e})) { 109 push @sth_adds, "camRun.cam_id = $opt{e}"; 110 } 111 if (exists($opt{s})||exists($opt{T})) { 112 # print "$opt{s}!\n"; 113 if (exists($opt{s})&&($opt{s} != 0)) { 114 push @sth_adds, "stackRun.stack_id = $opt{s}"; 115 } 116 $sth_base =~ s/0,'nostack'/stack_id,stackSumSkyfile.uri/; 117 if (exists($opt{T})) { 118 $sth_base .= ' RIGHT OUTER '; 119 } 120 $sth_base .= ' JOIN stackInputSkyfile USING (warp_id) JOIN stackSumSkyfile USING (stack_id) JOIN stackRun USING (stack_id)'; 121 # print "$sth_base\n"; 122 } 123 if (exists($opt{J})||(exists($opt{d}))) { 124 if (exists($opt{d})&&($opt{d} != 0)) { 125 push @sth_adds, "diffRun.diff_id = $opt{d}"; 126 } 127 $sth_base =~ s/0,'nodiff'/diffRun.diff_id,diffSkyfile.path_base/; 128 if (exists($opt{J})) { 129 # $sth_base .= ' RIGHT OUTER '; 130 } 131 $sth_base .= ' JOIN diffInputSkyfile ON (warpRun.warp_id = diffInputSkyfile.warp1 OR warpRun.warp_id = diffInputSkyfile.warp2) JOIN diffRun USING (diff_id) JOIN diffSkyfile USING (diff_id)'; 88 132 } 89 133 if ($#sth_adds != -1) { … … 97 141 $dr = $db->selectall_arrayref( $sth ); 98 142 143 144 %uniq = (); 145 $found = 0; 99 146 foreach $rr (@{ $dr }) { 100 147 ($warp_id, $warp_workdir, $chip_id, $chip_workdir, 101 $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime) = @{ $rr }; 102 # print (join "\t", @{ $rr }) . "\n"; 103 $exp_pontime = 0; # To stop warnings, but I want this around. 148 $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime, 149 $stack_id, $stack_sumfile_uri, 150 $cam_id, $cam_workdir, 151 $diff_id, $diff_workdir 152 ) = @{ $rr }; 153 if ($stack_id == 0) { 154 $stack_sumfile_uri = ''; 155 } 156 # print (join "\t", @{ $rr }) . "\n" . "\n"; 157 # $exp_pontime = 0; # To stop warnings, but I want this around. 158 if (exists($opt{I})) { 159 $stack_id = 0; # Ditto. 160 $cam_id = 0; 161 $diff_id = 0; 162 } 163 if (exists($opt{N})) { 164 if ($found > $opt{N}) { 165 last; 166 } 167 } 104 168 if (exists($opt{P})) { 105 169 $sth_previous = "SELECT exp_name from rawExp where dateobs < '$exp_dateobs' order by dateobs desc limit 1"; … … 112 176 if (exists($opt{B})) { $previous_cmd .= ' -B '; } 113 177 if (exists($opt{v})) { $previous_cmd .= ' -v '; } 178 if (exists($opt{F})) { $previous_cmd .= ' -F '; } 114 179 if ($opt{A}) { $previous_cmd .= ' -A '; } 115 180 if ($opt{M}) { $previous_cmd .= ' -M '; } … … 127 192 # exit(0); 128 193 } 129 130 131 194 195 %mapping = (); 196 unless (exists($opt{Y})) { 197 if ((exists($opt{C})&&(exists($opt{S})))|| 198 (exists($opt{W})&&(exists($opt{O})))|| 199 exists($opt{I})) { 200 $sth_mapping = "SELECT skycell_id,class_id from warpSkyCellMap WHERE warp_id = $warp_id"; 201 $mr = $db->selectall_arrayref( $sth_mapping ); 202 foreach $mrr (@{ $mr }) { 203 my ($skycell,$class) = @{ $mrr }; 204 my $raw_class = $class; 205 $raw_class =~ s/xy/ota/i; 206 push @{ $mapping{$skycell} }, $class; 207 push @{ $mapping{$skycell} }, $raw_class; 208 push @{ $mapping{$class} }, $skycell; 209 push @{ $mapping{$raw_class} }, $skycell; 210 # print STDERR "$raw_class $class $skycell\n"; 211 } 212 } 213 } 214 215 if (exists($opt{I})) { 216 if ($warp_id eq '') { 217 $warp_id = 'NULL'; 218 } 219 if ($stack_id eq '') { 220 $stack_id = 'NULL'; 221 } 222 $line = "$exp_name $exp_id $exp_dateobs $exp_pontime $chip_id $warp_id\t"; 223 if (exists($opt{O})) { 224 foreach $sky (@{ $mapping{$opt{O}} }) { 225 $line .= "$sky\t"; 226 } 227 } 228 if (exists($opt{S})) { 229 foreach $sky (@{ $mapping{$opt{S}} }) { 230 $line .= "$sky\t"; 231 } 232 } 233 $line .= "\n"; 234 unless (exists($uniq{$line})) { 235 print $line; 236 $uniq{$line} = 1; 237 } 238 next; 239 } 132 240 @scan = (); 133 241 if (exists($opt{R})||exists($opt{B})) { 242 # print STDERR "$exp_workdir $exp_name\n"; 134 243 open(NLS,"neb-ls $exp_workdir/${exp_name}/ |") || die "can't neb-ls"; 135 244 while (<NLS>) { 136 245 chomp; 137 if (($_ =~ /${opt{O}}/)&&((($opt{A})) || ($_ =~ /fits/))) { 138 if (exists($opt{B})) { 139 $_ =~ s/.fits$/.burn.tbl/; 140 } 246 if (is_valid_raw($_)) { 141 247 push @scan, $_; 248 $found++; 142 249 } 143 250 } … … 148 255 while (<NLS>) { 149 256 chomp; 150 if (($_ =~ /${exp_id}.ch/)&&($_ =~ /$chip_id/)&&($_ =~ /$opt{O}/)&& 151 ((($opt{A})) || (($_ =~ /fits/) && 152 ($opt{M} || ($_ !~ /mk.fits/)) && 153 ($_ !~ /wt.fits/)))) { 154 if ($opt{D} && ($_ !~ /SR/)) { 155 next; 156 } 257 if (is_valid_chip($_)) { 157 258 push @scan, $_; 158 259 $found++; 260 } 261 } 262 close(NLS); 263 } 264 if (exists($opt{E})) { 265 open(NLS,"neb-ls $cam_workdir/${exp_name}.${exp_id}/ |") || die "can't neb-ls"; 266 while (<NLS>) { 267 chomp; 268 if (is_valid_cam($_)) { 269 push @scan, $_; 270 $found++; 159 271 } 160 272 } … … 165 277 while (<NLS>) { 166 278 chomp; 167 # print "$_\n"; 168 if (($_ =~ /wrp.${warp_id}.$opt{S}/) && ((($opt{A})) || (($_ =~ /fits/) && 169 ($opt{M} || ($_ !~ /mask/)) && 170 ($_ !~ /wt/)))) { 171 if ($opt{D} && ($_ !~ /SR/)) { 172 next; 173 } 279 if (is_valid_warp($_)) { 174 280 push @scan, $_; 175 } 176 } 177 } 178 %uniq = (); 281 $found++; 282 } 283 } 284 } 285 if (exists($opt{J})) { 286 @diff_tmp = split /\//, $diff_workdir; 287 $diff_prefix = pop(@diff_tmp); 288 $diff_true_dir = join '/',@diff_tmp; 289 290 open(NLS,"neb-ls $diff_true_dir |") || die "can't neb-ls"; 291 while (<NLS>) { 292 chomp; 293 if (is_valid_diff($_)) { 294 push @scan, $_; 295 $found++; 296 } 297 } 298 } 299 if (exists($opt{s})||exists($opt{T})) { 300 if (defined($stack_sumfile_uri)) { 301 push @scan, $stack_sumfile_uri; 302 $found++; 303 } 304 } 305 179 306 foreach $f (@scan) { 180 307 unless (exists($uniq{$f})) { … … 190 317 } 191 318 } 319 320 sub is_mapped { 321 my ($key,$map_string) = @_; 322 323 unless (exists($mapping{$map_string})) { 324 return(0); 325 } 326 327 foreach $v (@{ $mapping{$map_string} }) { 328 if ($key =~ /$v/) { 329 return(1); 330 } 331 } 332 return(0); 333 } 334 335 sub is_valid_raw { 336 my $key = shift; 337 338 if ($opt{A}) { 339 return(1); 340 } 341 elsif ($opt{L}) { 342 if ($key =~ /log/) { 343 return(1); 344 } 345 else { 346 return(0); 347 } 348 } 349 elsif ($opt{B}) { 350 if ($key =~ /burn.tbl/) { 351 if (($opt{O} ne '')&&($key !~ /$opt{O}/)) { 352 return(0); # Not the requested OTA 353 } 354 if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) { 355 return(0); # Not the remapped skycell requested 356 } 357 return(1); 358 } 359 else { 360 return(0); 361 } 362 } 363 elsif ($key !~ /fits/) { 364 return(0); 365 } 366 else { 367 if (($opt{O} ne '')&&($key !~ /$opt{O}/)) { 368 return(0); # Not the requested OTA 369 } 370 if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) { 371 return(0); # Not the remapped skycell requested 372 } 373 if ($key =~ /burn.fits/) { 374 return(0); 375 } 376 return(1); 377 } 378 } 379 380 sub is_valid_chip { 381 my $key = shift; 382 383 384 if ($opt{D} && ($key !~ /SR/)) { 385 return(0); # Not destreaked when required 386 } 387 elsif ($key !~ /${exp_id}.ch/) { 388 return(0); # Not a chip from this exposure 389 } 390 elsif ($key !~ /${chip_id}/) { 391 return(0); # Not from this chip_id 392 } 393 394 if (($opt{O} ne '')&&($key !~ /$opt{O}/)) { 395 return(0); # Not the requested OTA 396 } 397 if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) { 398 return(0); # Not the remapped skycell requested 399 } 400 401 if ($opt{A}) { 402 return(1); # You asked for all, 403 } 404 elsif ($opt{L}) { 405 if ($key =~ /log/) { 406 return(1); 407 } 408 else { 409 return(0); 410 } 411 } 412 elsif ($opt{V} && ($key =~ /cmf/)) { 413 return(1); 414 } 415 elsif ($key !~ /fits/) { 416 return(0); # Not a fits 417 } 418 elsif ($key =~ /wt.fits/) { 419 return(0); # No handler for weight right now. 420 } 421 elsif ($key =~ /mk/) { 422 if ($opt{M}) { 423 return(1); # Requested mask 424 } 425 else { 426 return(0); 427 } 428 } 429 elsif ($key =~ /ch.fits/) { 430 return(1); # Should be just the chip 431 } 432 return(0); 433 434 } 435 436 sub is_valid_cam { 437 my $key = shift; 438 if ($key =~ /\.cm\./) { 439 if ($opt{A}) { 440 return(1); 441 } 442 elsif ($opt{L} && ($key =~ /log/)) { 443 return(1); 444 } 445 elsif ($opt{V} && ($key =~ /smf/)) { 446 return(1); 447 } 448 elsif ($opt{M} && ($key =~ /mk.fits/)) { 449 if (($opt{O} ne '')&&($key !~ /$opt{O}/)) { 450 return(0); # Not the requested OTA 451 } 452 if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) { 453 return(0); # Not the remapped skycell requested 454 } 455 return(1); 456 } 457 458 } 459 return(0); 460 } 461 462 sub is_valid_diff { 463 my $key = shift; 464 if ($key =~ /$diff_prefix/) { 465 if ($opt{D} && ($key !~ /SR/)) { 466 return(0); # Not destreaked when required 467 } 468 if (($opt{S} ne '')&&($key !~ /$opt{S}/)) { 469 return(0); # Not the requested skycell 470 } 471 if (($opt{O} ne '')&& !(is_mapped($key,$opt{O}))) { 472 return(0); # Not the remapped OTA requested 473 } 474 475 if ($opt{A}) { 476 return(1); # You asked for all, 477 } 478 elsif ($opt{L}) { 479 if ($key =~ /log/) { 480 return(1); 481 } 482 else { 483 return(0); 484 } 485 } 486 elsif ($opt{V} && ($key =~ /cmf/)) { 487 return(1); 488 } 489 elsif ($key !~ /fits/) { 490 return(0); # Not a fits 491 } 492 elsif ($key =~ /refConv/) { 493 return(0); 494 } 495 elsif ($key =~ /inConv/) { 496 return(0); 497 } 498 elsif ($key =~ /inv/) { 499 return(0); 500 } 501 elsif ($key =~ /wt.fits/) { 502 return(0); # No handler for weight right now. 503 } 504 505 elsif ($key =~ /mask/) { 506 if ($opt{M}) { 507 return(1); # Requested mask 508 } 509 else { 510 return(0); 511 } 512 } 513 else { 514 return(1); # Should be just the warp. 515 } 516 } 517 518 return(0); 519 } 520 sub is_valid_warp { 521 my $key = shift; 522 523 if ($opt{D} && ($key !~ /SR/)) { 524 return(0); # Not destreaked when required 525 } 526 elsif ($key !~ /wrp.${warp_id}/) { 527 return(0); # Not a warp from this warp_id 528 } 529 if (($opt{S} ne '')&&($key !~ /$opt{S}/)) { 530 return(0); # Not the requested skycell 531 } 532 if (($opt{O} ne '')&& !(is_mapped($key,$opt{O}))) { 533 return(0); # Not the remapped OTA requested 534 } 535 536 if ($opt{A}) { 537 return(1); # You asked for all, 538 } 539 elsif ($opt{L}) { 540 if ($key =~ /log/) { 541 return(1); 542 } 543 else { 544 return(0); 545 } 546 } 547 elsif ($opt{V} && ($key =~ /cmf/)) { 548 return(1); 549 } 550 elsif ($key !~ /fits/) { 551 return(0); # Not a fits 552 } 553 elsif ($key =~ /wt.fits/) { 554 return(0); # No handler for weight right now. 555 } 556 elsif ($key =~ /mask/) { 557 if ($opt{M}) { 558 return(1); # Requested mask 559 } 560 else { 561 return(0); 562 } 563 } 564 else { 565 return(1); # Should be just the warp. 566 } 567 return(0); 568 }
Note:
See TracChangeset
for help on using the changeset viewer.
