Changeset 27304 for trunk/ippTools/src/dqstatstool.c
- Timestamp:
- Mar 16, 2010, 6:28:29 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/dqstatstool.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/dqstatstool.c
r26981 r27304 45 45 } 46 46 47 psFree(config);47 //psFree(config); 48 48 pmConfigDone(); 49 49 psLibFinalize(); … … 54 54 int exit_status = pxerrorGetExitStatus(); 55 55 56 psFree(config);56 // psFree(config); 57 57 pmConfigDone(); 58 58 psLibFinalize(); … … 88 88 } 89 89 // use psDBGenerateWhereConditionSQL because the SQL ends in a WHERE 90 if (force) { 91 psStringAppend(&query, " AND (invalid IS NULL OR invalid = 1 OR invalid = 0) "); 92 } 93 else { 94 psStringAppend(&query, " AND (invalid IS NULL OR invalid = 1) "); 95 } 96 90 97 if (where && psListLength(where->list)) { 91 98 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 92 99 psStringAppend(&query, " AND %s", whereClause); 93 100 psFree(whereClause); 94 }95 if (force) {96 psStringAppend(&query, " OR invalid = 0");97 101 } 98 102 … … 103 107 psFree(limitString); 104 108 } 105 109 psTrace("debug",3,">> %s",query); 106 110 if (!p_psDBRunQuery(config->dbh, query)) { 107 111 psError(PS_ERR_UNKNOWN, false, "database error"); … … 325 329 psFree(output); // This held the information about the Run. 326 330 327 // Read column list from config file .331 // Read column list from config file 328 332 psMetadata *recipe = psMetadataLookupPtr(&status, config->modules->recipes, "DQSTATS"); 329 333 psMetadata *columns = psMetadataLookupMetadata(&status,recipe,"STATS.COLUMNS"); … … 342 346 psMetadata *colTypes = psMetadataAlloc(); 343 347 while ((colItem = psMetadataGetAndIncrement(iter))) { 348 if (strcmp(colItem->name, "COLUMN")) continue; 349 if (colItem->type != PS_DATA_METADATA) { 350 psError(PS_ERR_UNKNOWN, false, "dqstatstool COLUMN not of type METADATA\n"); 351 return(NULL); 352 } 353 344 354 bool status; 345 355 psMetadata *coldef = colItem->data.md; … … 369 379 return(false); 370 380 } 381 382 // Read decision engine settings from config file. 383 psMetadata *engine = psMetadataLookupMetadata(&status,recipe,"DECISION.ENGINE"); 384 if (!engine) { 385 psError(PS_ERR_UNKNOWN, false, "Could not read DECISION.ENGINE metadata"); 386 psFree(whereClause); 387 return(false); 388 } 389 psArray *decisionRules = psArrayAllocEmpty(4); // list of screened and verified rules. 390 psMetadataIterator *iterEngine = psMetadataIteratorAlloc(engine, PS_LIST_HEAD,NULL); 391 psMetadataItem *engineItem = NULL; 392 393 while ((engineItem = psMetadataGetAndIncrement(iterEngine))) { 394 if (strcmp(engineItem->name, "RULE")) continue; 395 if (engineItem->type != PS_DATA_METADATA) { 396 psError(PS_ERR_UNKNOWN, false, "dqstatstool RULE not of type METADATA\n"); 397 return(NULL); 398 } 399 400 bool status; 401 psMetadata *enginedef = engineItem->data.md; 402 403 if (psMetadataLookupStr(&status,enginedef,"COLNAME")&& 404 isfinite(psMetadataLookupF32(&status,enginedef,"MINIMUM"))&& 405 isfinite(psMetadataLookupF32(&status,enginedef,"MAXIMUM"))) { 406 psArrayAdd(decisionRules,decisionRules->n,enginedef); 407 } 408 else { 409 psError(PS_ERR_UNKNOWN, false, "Rule invalid."); 410 } 411 } 412 psFree(iterEngine); 413 414 if (decisionRules->n < 1) { 415 psError(PS_ERR_UNKNOWN, false, "Failed to generate a decision engine"); 416 psFree(decisionRules); 417 psFree(engine); 418 return(false); 419 } 420 psFree(engine); 371 421 372 422 // Find the contents that comprise this run … … 439 489 bool status; 440 490 psString MYquery = psStringCopy(query); 491 if (!MYquery) { 492 psTrace("debug",4,"Failed to copy, trying again."); 493 MYquery = psStringCopy(query); 494 } 495 441 496 psMetadata *where = psMetadataAlloc(); 442 497 … … 445 500 psMetadataAddS64(where,PS_LIST_TAIL, "camRun.cam_id", 0, "==", psMetadataLookupS64(&status,row,"cam_id")); 446 501 // This may not be real, so we need to check first. Is there a better way to check for a null here? 447 if (psMetadataLookupS64(&status,row,"warp_id") && (psMetadataLookupS64(&status,row,"warp_id") != 9223372036854775807)) {502 if (psMetadataLookupS64(&status,row,"warp_id") && (psMetadataLookupS64(&status,row,"warp_id") != PS_MAX_S64)) { 448 503 psMetadataAddS64(where,PS_LIST_TAIL, "warpRun.warp_id", 0, "==", psMetadataLookupS64(&status,row,"warp_id")); 449 504 } 450 505 451 506 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 507 if (!whereClause) { 508 psError(PS_ERR_UNKNOWN, false, "Unable to generate Where Condition"); 509 return(false); 510 } 452 511 psStringAppend(&MYquery, " WHERE %s", whereClause); 453 psFree(whereClause); 454 psFree(where); 512 513 /* psTrace("debug",2,"%ld %ld %ld %ld %s\n",psMetadataLookupS64(&status,row,"exp_id"), */ 514 /* psMetadataLookupS64(&status,row,"chip_id"), */ 515 /* psMetadataLookupS64(&status,row,"cam_id"), */ 516 /* psMetadataLookupS64(&status,row,"warp_id"), */ 517 /* whereClause); */ 518 519 /* psFree(whereClause); */ 520 /* psFree(where); */ 455 521 // printf("%s\n",MYquery); 456 522 … … 465 531 return(false); 466 532 } 467 psFree(MYquery);468 533 469 534 psArray *statsoutput = p_psDBFetchResult(config->dbh); … … 478 543 } 479 544 if (!psArrayLength(statsoutput)) { 480 psWarning("dqstatstool No stats rows found ");545 psWarning("dqstatstool No stats rows found: %ld %s %s",i,MYquery,query); 481 546 psFree(colNames); 482 547 psFree(colTypes); … … 487 552 return(false); 488 553 } 554 psFree(MYquery); 555 psFree(whereClause); 556 psFree(where); 489 557 490 558 // Magic happens and the fits table is filled. … … 546 614 success = psMetadataAddStr(tableRow,PS_LIST_TAIL,colName,0,"",rowItem->data.str); 547 615 } 548 616 else if (!strcmp(colType,"PS_DATA_TIME")) { 617 psString timeString = psTimeToISO(rowItem->data.V); 618 success = psMetadataAddStr(tableRow,PS_LIST_TAIL,colName,0,"",timeString); 619 psFree(timeString); 620 } 621 549 622 if (!success) { 550 psError(PS_ERR_UNKNOWN,false, "Error constructing fits table row. ");623 psError(PS_ERR_UNKNOWN,false, "Error constructing fits table row. %s %s",colType,colName); 551 624 psFree(colNames); 552 625 psFree(colTypes); … … 562 635 } 563 636 } 564 637 // Calculate if this exposure was "good" or not. 638 bool accept = true; 639 for (long j = 0; j < decisionRules->n; j++) { 640 psMetadata *rule = decisionRules->data[j]; 641 bool status = true; 642 psString colname = psMetadataLookupStr(&status,rule,"COLNAME"); 643 if (!status) { 644 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find column name"); 645 return(false); 646 } 647 psF32 min_value = psMetadataLookupF32(&status,rule,"MINIMUM"); 648 if (!status) { 649 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find min value for %s",colname); 650 return(false); 651 } 652 psF32 max_value = psMetadataLookupF32(&status,rule,"MAXIMUM"); 653 if (!status) { 654 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find max value for %s",colname); 655 return(false); 656 } 657 // Not happy with this being set to a F32. Can this ever be something else? 658 psF32 value = psMetadataLookupF32(&status,tableRow,colname); 659 if (!status) { 660 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find column %s (%f %f %f) in compare with rule.",colname,min_value,max_value,value); 661 psFree(colNames); 662 psFree(colTypes); 663 psFree(contents); 664 psFree(query); 665 psFree(outTable); 666 psFree(tableRow); 667 return(false); 668 } 669 if ((value > max_value)||(value < min_value)) { 670 accept = false; 671 } 672 } 673 bool success; 674 success = psMetadataAddBool(tableRow,PS_LIST_TAIL,"ACCEPT",0,"",accept); 675 if (!success) { 676 psError(PS_ERR_UNKNOWN,false, "Error adding exposure quality to fits table row."); 677 psFree(colNames); 678 psFree(colTypes); 679 psFree(contents); 680 psFree(query); 681 psFree(outTable); 682 psFree(statsoutput); 683 psFree(statIter); 684 psFree(tableRow); 685 return(false); 686 } 687 688 // Add the row to the table array. 565 689 psArrayAdd(outTable,0,tableRow); 566 690 psFree(tableRow); … … 600 724 static bool updaterunMode(pxConfig *config) { 601 725 PS_ASSERT_PTR_NON_NULL(config,false); 602 PXOPT_LOOKUP_S64(dqstats_id, config->args, "-dqstats_id", "dqstatsRun.dqstats_id", "==");603 PXOPT_LOOKUP_STR(state, config->args, "-set_state", "state", "==");604 PXOPT_LOOKUP_S16(fault, config->args, "-fault", "fault", "==");726 PXOPT_LOOKUP_S64(dqstats_id, config->args, "-dqstats_id", true, false); 727 PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false); 728 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 605 729 606 730 if (state && ! pxIsValidState(state)) {
Note:
See TracChangeset
for help on using the changeset viewer.
