- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/flatcorr.c (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippTools/src
- Property svn:ignore
-
old new 1 *.la 2 *.lo 1 3 .deps 2 4 .gdb_history … … 4 6 Makefile 5 7 Makefile.in 8 addtool 9 caltool 10 camtool 11 chiptool 6 12 config.h 7 13 config.h.in 8 stamp-h1 9 *.la 10 *.lo 14 detselect 15 dettool 16 difftool 17 disttool 18 dqstatstool 19 faketool 20 flatcorr 21 guidetool 22 magicdstool 23 magictool 24 pstamptool 25 pubtool 26 pxadmin 27 pxdata.c 28 pxinject 11 29 pxtoolsErrorCodes.c 12 30 pxtoolsErrorCodes.h 13 pxadmin14 pxinject15 pztool16 31 pzgetexp 17 32 pzgetimfiles 33 pztool 34 receivetool 18 35 regtool 19 guidetool 20 chiptool 21 camtool 36 stacktool 37 stamp-h1 22 38 warptool 23 difftool24 stacktool25 faketool26 dettool27 detselect28 pxdata.c29 magictool30 magicdstool31 caltool32 flatcorr33 pstamptool34 disttool35 receivetool36 37 pubtool
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ippTools/src/flatcorr.c
r24140 r27840 33 33 #include "pxtools.h" 34 34 #include "pxchip.h" 35 #include "pxcam.h" 36 #include "pxadd.h" 35 37 #include "flatcorr.h" 36 38 … … 38 40 static bool definerunMode(pxConfig *config); 39 41 static bool addchipMode(pxConfig *config); 42 static bool dropchipMode(pxConfig *config); 40 43 static bool addcameraMode(pxConfig *config); 41 static bool dropchipMode(pxConfig *config);42 44 static bool dropcameraMode(pxConfig *config); 45 static bool advancecameraMode(pxConfig *config); 46 static bool advanceaddstarMode(pxConfig *config); 43 47 static bool pendingprocessMode(pxConfig *config); 44 48 static bool addprocessMode(pxConfig *config); … … 46 50 static bool inputexpMode(pxConfig *config); 47 51 static bool inputimfileMode(pxConfig *config); 48 static bool exportrunMode(pxConfig *config);49 static bool importrunMode(pxConfig *config);50 52 51 53 static bool setflatcorrRunState(pxConfig *config, psS64 corr_id, const char *state); … … 72 74 MODECASE(FLATCORR_MODE_DEFINERUN, definerunMode); 73 75 MODECASE(FLATCORR_MODE_ADDCHIP, addchipMode); 76 MODECASE(FLATCORR_MODE_DROPCHIP, dropchipMode); 74 77 MODECASE(FLATCORR_MODE_ADDCAMERA, addcameraMode); 75 MODECASE(FLATCORR_MODE_DROPCHIP, dropchipMode);76 78 MODECASE(FLATCORR_MODE_DROPCAMERA, dropcameraMode); 79 MODECASE(FLATCORR_MODE_ADVANCECAMERA, advancecameraMode); 80 MODECASE(FLATCORR_MODE_ADVANCEADDSTAR, advanceaddstarMode); 77 81 MODECASE(FLATCORR_MODE_PENDINGPROCESS, pendingprocessMode); 78 82 MODECASE(FLATCORR_MODE_ADDPROCESS, addprocessMode); … … 80 84 MODECASE(FLATCORR_MODE_INPUTEXP, inputexpMode); 81 85 MODECASE(FLATCORR_MODE_INPUTIMFILE, inputimfileMode); 82 MODECASE(FLATCORR_MODE_EXPORTRUN, exportrunMode);83 MODECASE(FLATCORR_MODE_IMPORTRUN, importrunMode);84 86 default: 85 87 psAbort("invalid option (this should not happen)"); … … 113 115 if (!psListLength(where->list)) { 114 116 psFree(where); 115 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");116 return false; 117 } 118 119 // require the camera to be defined: this analysis does not make sense 117 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 118 return false; 119 } 120 121 // require the camera to be defined: this analysis does not make sense 120 122 // across multiple cameras 121 123 PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false); … … 131 133 PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false); 132 134 PXOPT_LOOKUP_STR(region, config->args, "-set_region", false, false); 135 PXOPT_LOOKUP_BOOL(make_correction, config->args, "-make_correction", false); 136 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 133 137 134 138 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); … … 138 142 psString query = pxDataGet("chiptool_find_rawexp.sql"); 139 143 if (!query) { 140 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");144 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 141 145 psFree(where); 142 146 return false; … … 169 173 170 174 if (pretend) { 171 for (long i = 0; i < psArrayLength(output); i++) {172 // negative simple so the default is true173 if (!ippdbPrintMetadataRaw(stdout, output->data[i], !simple)) {174 psError(PS_ERR_UNKNOWN, false, "failed to print array");175 psFree(output);176 return false;177 }178 }175 for (long i = 0; i < psArrayLength(output); i++) { 176 // negative simple so the default is true 177 if (!ippdbPrintMetadataRaw(stdout, output->data[i], !simple)) { 178 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 179 psFree(output); 180 return false; 181 } 182 } 179 183 psFree(output); 180 184 return true; … … 191 195 // create a new flatcorrRun 192 196 if (!flatcorrRunInsert( 193 config->dbh,197 config->dbh, 194 198 0, // corr_id 195 det_type,199 det_type, 196 200 dvodb, 197 camera,198 telescope,199 NULL,201 camera, 202 telescope, 203 NULL, 200 204 filter, 201 205 "reg", // state 206 make_correction, 202 207 workdir, 203 208 label, 204 209 reduction, 205 region,206 NULL,207 0210 region, 211 NULL, 212 0 208 213 )) { 209 214 if (!psDBRollback(config->dbh)) { … … 233 238 234 239 // queue the exp : force this to stop at the chip stage 235 psS64 chip_id = pxchipQueueByExpTag(config, exp_id, workdir, label, reduction, expgroup, dvodb, tess_id, "chip");240 psS64 chip_id = pxchipQueueByExpTag(config, exp_id, workdir, label, label, NULL, reduction, expgroup, dvodb, tess_id, "chip", note); 236 241 if (!chip_id) { 237 242 if (!psDBRollback(config->dbh)) { … … 291 296 PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false); 292 297 PXOPT_LOOKUP_STR(region, config->args, "-set_region", false, false); 298 PXOPT_LOOKUP_BOOL(make_correction, config->args, "-make_correction", false); 293 299 // XXX probably should make the region in -set_region match ra_min, ra_max, etc 294 300 … … 297 303 // start a transaction so we don't end up with an exp without any associted 298 304 // imfiles 299 if (!psDBTransaction(config->dbh)) {300 psError(PS_ERR_UNKNOWN, false, "database error");301 return false;302 }305 // if (!psDBTransaction(config->dbh)) { 306 // psError(PS_ERR_UNKNOWN, false, "database error"); 307 // return false; 308 // } 303 309 304 310 // create a new flatcorrRun 305 311 flatcorrRunRow *row = flatcorrRunRowAlloc( 306 0, // corr_id 307 det_type, 308 dvodb, 309 camera, 310 telescope, 311 NULL, 312 filter, 313 "reg", // state 314 workdir, 315 label, 316 reduction, 317 region, 318 NULL, // hostname 319 0 // fault 312 0, // corr_id 313 det_type, 314 dvodb, 315 camera, 316 telescope, 317 NULL, 318 filter, 319 "reg", // state 320 make_correction, 321 workdir, 322 label, 323 reduction, 324 region, 325 NULL, // hostname 326 0 // fault 320 327 ); 321 328 … … 328 335 return false; 329 336 } 330 337 331 338 // figure out the ID of the flatcorrRun we just created 332 339 psS64 corr_id = psDBLastInsertID(config->dbh); 333 340 row->corr_id = corr_id; 334 341 342 // if (!psDBCommit(config->dbh)) { 343 // psError(PS_ERR_UNKNOWN, false, "database error"); 344 // return false; 345 // } 346 335 347 flatcorrRunPrintObject (stdout, row, !simple); 336 348 return true; … … 365 377 psString query = pxDataGet("flatcorr_dropchip.sql"); 366 378 if (!query) { 367 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");368 return false;379 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 380 return false; 369 381 } 370 382 371 383 if (!p_psDBRunQueryF(config->dbh, query, (long long) corr_id, (long long) chip_id)) { 384 psError(PS_ERR_UNKNOWN, false, "database error"); 385 psFree(query); 386 return false; 387 } 388 389 return true; 390 } 391 392 static bool addcameraMode(pxConfig *config) 393 { 394 PS_ASSERT_PTR_NON_NULL(config, false); 395 396 // required 397 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 398 PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", true, false); 399 PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false); 400 401 // add a flatcorrCamLink (initial state has include = TRUE) 402 // XXX should add checks that the chip_id and corr_id are in ChipLink 403 if (!flatcorrCamLinkInsert(config->dbh, corr_id, chip_id, cam_id, 1)) { 404 psError(PS_ERR_UNKNOWN, false, "database error"); 405 return false; 406 } 407 408 return true; 409 } 410 411 static bool dropcameraMode(pxConfig *config) 412 { 413 PS_ASSERT_PTR_NON_NULL(config, false); 414 415 // required 416 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 417 PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false); 418 419 // UPDATE flatcorrCamLink set include = 0 where corr_id = %lld AND cam_id = %lld 420 psString query = pxDataGet("flatcorr_dropcamera.sql"); 421 if (!query) { 422 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 423 return false; 424 } 425 426 if (!p_psDBRunQueryF(config->dbh, query, (long long) corr_id, (long long) cam_id)) { 372 427 psError(PS_ERR_UNKNOWN, false, "database error"); 373 428 psFree(query); … … 380 435 // select the flatcorr chip runs that have completed and for which there is no camera entry 381 436 // queue a new camera run for them 382 static bool ad dcameraMode(pxConfig *config)437 static bool advancecameraMode(pxConfig *config) 383 438 { 384 439 PS_ASSERT_PTR_NON_NULL(config, false); … … 388 443 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 389 444 445 psMetadata *where = psMetadataAlloc(); 446 pxAddLabelSearchArgs (config, where, "-label", "flatcorrRun.label", "=="); 447 390 448 psString query = pxDataGet("flatcorr_chiprundone.sql"); 391 449 if (!query) { 392 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 393 return false; 394 } 450 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 451 return false; 452 } 453 454 if (where && psListLength(where->list)) { 455 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 456 psStringAppend(&query, " AND %s", whereClause); 457 psFree(whereClause); 458 } 459 psFree(where); 395 460 396 461 // treat limit == 0 as "no limit" 397 462 if (limit) { 398 psString limitString = psDBGenerateLimitSQL(limit);399 psStringAppend(&query, " %s", limitString);400 psFree(limitString);463 psString limitString = psDBGenerateLimitSQL(limit); 464 psStringAppend(&query, " %s", limitString); 465 psFree(limitString); 401 466 } 402 467 … … 459 524 // queue the exp 460 525 if (!pxcamQueueByChipID( 461 config, 462 row->chip_id, 463 row->workdir, 464 row->label, 465 row->reduction, 466 row->expgroup, 467 row->dvodb, 468 row->tess_id, 469 "camera")) { 526 config, 527 row->chip_id, 528 row->workdir, 529 row->label, 530 row->data_group, 531 row->dist_group, 532 row->reduction, 533 row->expgroup, 534 row->dvodb, 535 row->tess_id, 536 "camera", 537 row->magicked, 538 NULL // note does not propragate 539 )) { 470 540 if (!psDBRollback(config->dbh)) { 471 541 psError(PS_ERR_UNKNOWN, false, "database error"); … … 478 548 } 479 549 480 // figure out the ID of the flatcorrRun we just created481 psS64 cam_id = psDBLastInsertID(config->dbh);482 483 // add the camRun entry to the flatcorrCamLink table (include is TRUE)550 // figure out the ID of the flatcorrRun we just created 551 psS64 cam_id = psDBLastInsertID(config->dbh); 552 553 // add the camRun entry to the flatcorrCamLink table (include is TRUE) 484 554 if (!flatcorrCamLinkInsert(config->dbh, corr_id, row->chip_id, cam_id, 1)) { 485 555 if (!psDBRollback(config->dbh)) { … … 489 559 return false; 490 560 } 491 561 492 562 psFree(row); 493 563 } … … 502 572 } 503 573 504 static bool dropcameraMode(pxConfig *config) 505 { 506 PS_ASSERT_PTR_NON_NULL(config, false); 507 508 // required 509 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 510 PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", true, false); 511 512 // UPDATE flatcorrCamLink set include = 0 where corr_id = %lld AND cam_id = %lld 513 psString query = pxDataGet("flatcorr_dropcamera.sql"); 514 if (!query) { 515 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 516 return false; 517 } 518 519 if (!p_psDBRunQueryF(config->dbh, query, (long long) corr_id, (long long) cam_id)) { 520 psError(PS_ERR_UNKNOWN, false, "database error"); 521 psFree(query); 522 return false; 523 } 524 525 return true; 526 } 527 528 // select the flatcorr chip runs that have completed and for which there is no camera entry 529 // queue a new camera run for them 530 static bool pendingprocessMode(pxConfig *config) 574 // Select the flatcorr camera runs that have completed and for which there is no addstar 575 // entry. Queue a new addstar run for them 576 static bool advanceaddstarMode(pxConfig *config) 531 577 { 532 578 PS_ASSERT_PTR_NON_NULL(config, false); … … 534 580 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 535 581 PXOPT_LOOKUP_BOOL(limit, config->args, "-limit", false); 582 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 536 583 537 584 psMetadata *where = psMetadataAlloc(); 538 pxAddLabelSearchArgs (config, where, "-label", " label", "==");539 540 psString query = pxDataGet("flatcorr_ pendingprocess.sql");585 pxAddLabelSearchArgs (config, where, "-label", "flatcorrRun.label", "=="); 586 587 psString query = pxDataGet("flatcorr_camerarundone.sql"); 541 588 if (!query) { 542 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");543 return false;589 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 590 return false; 544 591 } 545 592 … … 553 600 // treat limit == 0 as "no limit" 554 601 if (limit) { 555 psString limitString = psDBGenerateLimitSQL(limit);556 psStringAppend(&query, " %s", limitString);557 psFree(limitString);602 psString limitString = psDBGenerateLimitSQL(limit); 603 psStringAppend(&query, " %s", limitString); 604 psFree(limitString); 558 605 } 559 606 … … 575 622 } 576 623 624 if (pretend) { 625 // negative simple so the default is true 626 if (!ippdbPrintMetadatas(stdout, output, "flatcorr_addcamera", !simple)) { 627 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 628 psFree(output); 629 return false; 630 } 631 } 632 633 // start a transaction so we don't end up with an exp without any associted 634 // imfiles 635 if (!psDBTransaction(config->dbh)) { 636 psError(PS_ERR_UNKNOWN, false, "database error"); 637 psFree(output); 638 return false; 639 } 640 641 // loop over our list of chipRun rows 642 for (long i = 0; i < psArrayLength(output); i++) { 643 psMetadata *md = output->data[i]; 644 645 bool status; 646 psS64 corr_id = psMetadataLookupS64(&status, md, "corr_id"); 647 if (!status) { 648 if (!psDBRollback(config->dbh)) { 649 psError(PS_ERR_UNKNOWN, false, "database error"); 650 } 651 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for corr_id"); 652 psFree(output); 653 return false; 654 } 655 656 camRunRow *row = camRunObjectFromMetadata(md); 657 if (!row) { 658 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun"); 659 psFree(output); 660 return false; 661 } 662 663 // queue the exp : force image_only to be false (flatcorr is meaningless with just image info) 664 if (!pxaddQueueByCamID( 665 config, 666 row->cam_id, 667 row->workdir, 668 row->reduction, 669 row->label, 670 row->data_group, 671 row->dvodb, 672 NULL, // note is not propagated 673 0)) { 674 if (!psDBRollback(config->dbh)) { 675 psError(PS_ERR_UNKNOWN, false, "database error"); 676 } 677 psError(PS_ERR_UNKNOWN, false, 678 "failed to trying to queue cam_id: %" PRId64, row->cam_id); 679 psFree(row); 680 psFree(output); 681 return false; 682 } 683 684 // figure out the ID of the flatcorrRun we just created 685 psS64 add_id = psDBLastInsertID(config->dbh); 686 687 // add the addRun entry to the flatcorrAddstarLink table (include is TRUE) 688 if (!flatcorrAddstarLinkInsert(config->dbh, corr_id, row->cam_id, add_id, 1)) { 689 if (!psDBRollback(config->dbh)) { 690 psError(PS_ERR_UNKNOWN, false, "database error"); 691 } 692 psError(PS_ERR_UNKNOWN, false, "database error"); 693 return false; 694 } 695 psFree(row); 696 } 697 psFree(output); 698 699 if (!psDBCommit(config->dbh)) { 700 psError(PS_ERR_UNKNOWN, false, "database error"); 701 return false; 702 } 703 704 return false; 705 } 706 707 // select the flatcorr chip runs that have completed and for which there is no camera entry 708 // queue a new camera run for them 709 static bool pendingprocessMode(pxConfig *config) 710 { 711 PS_ASSERT_PTR_NON_NULL(config, false); 712 713 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 714 PXOPT_LOOKUP_BOOL(limit, config->args, "-limit", false); 715 716 psMetadata *where = psMetadataAlloc(); 717 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 718 719 psString query = pxDataGet("flatcorr_pendingprocess.sql"); 720 if (!query) { 721 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 722 return false; 723 } 724 725 if (where && psListLength(where->list)) { 726 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 727 psStringAppend(&query, " AND %s", whereClause); 728 psFree(whereClause); 729 } 730 psFree(where); 731 732 // treat limit == 0 as "no limit" 733 if (limit) { 734 psString limitString = psDBGenerateLimitSQL(limit); 735 psStringAppend(&query, " %s", limitString); 736 psFree(limitString); 737 } 738 739 if (!p_psDBRunQuery(config->dbh, query)) { 740 psError(PS_ERR_UNKNOWN, false, "database error"); 741 psFree(query); 742 return false; 743 } 744 745 psArray *output = p_psDBFetchResult(config->dbh); 746 if (!output) { 747 psError(PS_ERR_UNKNOWN, false, "database error"); 748 return false; 749 } 750 if (!psArrayLength(output)) { 751 psTrace("flatcorr", PS_LOG_INFO, "no rows found"); 752 psFree(output); 753 return true; 754 } 755 577 756 if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) { 578 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 579 psFree(output); 580 return false; 757 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 758 psFree(output); 759 return false; 760 } 761 762 return true; 763 } 764 765 // XXX need a fault state 766 static bool addprocessMode(pxConfig *config) 767 { 768 PS_ASSERT_PTR_NON_NULL(config, false); 769 770 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 771 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); 772 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 773 774 char *query = "UPDATE flatcorrRun SET state = 'full', hostname = '%s', fault = '%hd' WHERE corr_id = %" PRId64; 775 776 if (!p_psDBRunQueryF(config->dbh, query, hostname, code, corr_id)) { 777 psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id); 778 return false; 779 } 780 781 return true; 782 } 783 784 static bool updaterunMode(pxConfig *config) 785 { 786 PS_ASSERT_PTR_NON_NULL(config, false); 787 788 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 789 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 790 791 if (!setflatcorrRunState(config, corr_id, state)) { 792 if (!psDBRollback(config->dbh)) { 793 psError(PS_ERR_UNKNOWN, false, "database error"); 794 } 795 psError(PS_ERR_UNKNOWN, false, "failed to set run state"); 796 return false; 581 797 } 582 798 … … 598 814 // treat limit == 0 as "no limit" 599 815 if (limit) { 600 psString limitString = psDBGenerateLimitSQL(limit);601 psStringAppend(&query, " %s", limitString);602 psFree(limitString);816 psString limitString = psDBGenerateLimitSQL(limit); 817 psStringAppend(&query, " %s", limitString); 818 psFree(limitString); 603 819 } 604 820 … … 621 837 622 838 if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) { 623 psError(PS_ERR_UNKNOWN, false, "failed to print array");624 psFree(output);625 return false;839 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 840 psFree(output); 841 return false; 626 842 } 627 843 … … 638 854 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 639 855 PXOPT_LOOKUP_BOOL(limit, config->args, "-limit", false); 640 856 641 857 psMetadata *where = psMetadataAlloc(); 642 858 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipProcessedImfile.chip_id", "=="); … … 644 860 psString query = pxDataGet("flatcorr_inputimfile.sql"); 645 861 if (!query) { 646 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");862 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 647 863 return false; 648 864 } … … 657 873 // treat limit == 0 as "no limit" 658 874 if (limit) { 659 psString limitString = psDBGenerateLimitSQL(limit);660 psStringAppend(&query, " %s", limitString);661 psFree(limitString);875 psString limitString = psDBGenerateLimitSQL(limit); 876 psStringAppend(&query, " %s", limitString); 877 psFree(limitString); 662 878 } 663 879 … … 680 896 681 897 if (!ippdbPrintMetadatas(stdout, output, "flatcorrPending", !simple)) { 682 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 683 psFree(output); 684 return false; 685 } 686 687 return true; 688 } 689 690 // XXX need a fault state 691 static bool addprocessMode(pxConfig *config) 692 { 693 PS_ASSERT_PTR_NON_NULL(config, false); 694 695 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 696 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); 697 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 698 699 char *query = "UPDATE flatcorrRun SET state = 'full', hostname = '%s', fault = '%hd' WHERE corr_id = %" PRId64; 700 701 if (!p_psDBRunQueryF(config->dbh, query, hostname, code, corr_id)) { 702 psError(PS_ERR_UNKNOWN, false, "failed to change state for corr_id %" PRId64, corr_id); 703 return false; 704 } 705 706 return true; 707 } 708 709 static bool updaterunMode(pxConfig *config) 710 { 711 PS_ASSERT_PTR_NON_NULL(config, false); 712 713 PXOPT_LOOKUP_S64(corr_id, config->args, "-corr_id", true, false); 714 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false); 715 716 if (!setflatcorrRunState(config, corr_id, state)) { 717 if (!psDBRollback(config->dbh)) { 718 psError(PS_ERR_UNKNOWN, false, "database error"); 719 } 720 psError(PS_ERR_UNKNOWN, false, "failed to set run state"); 898 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 899 psFree(output); 721 900 return false; 722 901 } … … 731 910 732 911 // check that state is a valid string value 733 if (!strcmp(state, "reg") && 734 !strcmp(state, "new") && 735 !strcmp(state, "full"))912 if (!strcmp(state, "reg") && 913 !strcmp(state, "new") && 914 !strcmp(state, "full")) 736 915 { 737 916 psError(PS_ERR_UNKNOWN, false, "invalid state: %s", state); … … 748 927 return true; 749 928 } 750 751 bool exportrunMode(pxConfig *config)752 {753 typedef struct ExportTable {754 char tableName[80];755 char sqlFilename[80];756 } ExportTable;757 758 int numExportTables = 3;759 760 PS_ASSERT_PTR_NON_NULL(config, NULL);761 762 PXOPT_LOOKUP_S64(det_id, config->args, "-corr_id", true, false);763 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false);764 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);765 766 FILE *f = fopen (outfile, "w");767 if (f == NULL) {768 psError(PS_ERR_UNKNOWN, false, "failed to open output file");769 return false;770 }771 772 psMetadata *where = psMetadataAlloc();773 PXOPT_COPY_S64(config->args, where, "-corr_id", "corr_id", "==");774 775 ExportTable tables [] = {776 {"flatcorrRun", "flatcorr_export_run.sql"},777 {"flatcorrCamLink", "flatcorr_export_cam_link.sql"},778 {"flatcorrChipLink", "flatcorr_export_chip_link.sql"},779 };780 781 for (int i=0; i < numExportTables; i++) {782 psString query = pxDataGet(tables[i].sqlFilename);783 if (!query) {784 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");785 return false;786 }787 788 if (where && psListLength(where->list)) {789 psString whereClause = psDBGenerateWhereSQL(where, NULL);790 psStringAppend(&query, " %s", whereClause);791 psFree(whereClause);792 }793 794 // treat limit == 0 as "no limit"795 if (limit) {796 psString limitString = psDBGenerateLimitSQL(limit);797 psStringAppend(&query, " %s", limitString);798 psFree(limitString);799 }800 801 if (!p_psDBRunQuery(config->dbh, query)) {802 psError(PS_ERR_UNKNOWN, false, "database error");803 psFree(query);804 return false;805 }806 psFree(query);807 808 psArray *output = p_psDBFetchResult(config->dbh);809 if (!output) {810 psError(PS_ERR_UNKNOWN, false, "database error");811 return false;812 }813 if (!psArrayLength(output)) {814 psTrace("regtool", PS_LOG_INFO, "no rows found");815 psFree(output);816 return true;817 }818 819 // we must write the export table in non-simple (true) format820 if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {821 psError(PS_ERR_UNKNOWN, false, "failed to print array");822 psFree(output);823 return false;824 }825 psFree(output);826 }827 828 fclose (f);829 830 return true;831 }832 833 bool importrunMode(pxConfig *config)834 {835 unsigned int nFail;836 psMetadataItem *item, *entry;837 838 int numImportTables = 3;839 840 char tables[3] [80] = {"flatcorrRun", "flatcorrCamLink", "flatcorrChipLink"};841 842 PS_ASSERT_PTR_NON_NULL(config, NULL);843 844 PXOPT_LOOKUP_STR(infile, config->args, "-infile", true, false);845 846 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);847 848 fprintf (stdout, "---- input ----\n");849 psMetadataPrint (stderr, input, 1);850 851 for (int i = 0; i < numImportTables; i++) {852 item = psMetadataLookup (input, tables[i]);853 psAssert (item, "entry not in input?");854 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");855 856 entry = psListGet (item->data.list, 0);857 assert (entry);858 assert (entry->type == PS_DATA_METADATA);859 860 switch (i) {861 case 0:862 {863 flatcorrRunRow *flatcorrRun = flatcorrRunObjectFromMetadata (entry->data.md);864 flatcorrRunInsertObject (config->dbh, flatcorrRun);865 866 // fprintf (stdout, "---- flatcorr run ----\n");867 // psMetadataPrint (stderr, entry->data.md, 1);868 break;869 }870 case 1:871 {872 flatcorrCamLinkRow *flatcorrCamLink = flatcorrCamLinkObjectFromMetadata (entry->data.md);873 flatcorrCamLinkInsertObject (config->dbh, flatcorrCamLink);874 875 // fprintf (stdout, "---- flatcorr cam link ----\n");876 // psMetadataPrint (stderr, entry->data.md, 1);877 break;878 }879 case 2:880 {881 flatcorrChipLinkRow *flatcorrChipLink = flatcorrChipLinkObjectFromMetadata (entry->data.md);882 flatcorrChipLinkInsertObject (config->dbh, flatcorrChipLink);883 884 // fprintf (stdout, "---- flatcorr chip link ----\n");885 // psMetadataPrint (stderr, entry->data.md, 1);886 break;887 }888 }889 }890 return true;891 }
Note:
See TracChangeset
for help on using the changeset viewer.
