IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 6, 2009, 12:52:22 PM (17 years ago)
Author:
bills
Message:

Add hooks for carefully reverting faulted destreaked files. Support "destreak" operation at
camera stage. (For censoring detections)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/magicdstool.c

    r24552 r24683  
    4040static bool toremoveMode(pxConfig *config);
    4141static bool torestoreMode(pxConfig *config);
     42static bool torevertMode(pxConfig *config);
    4243
    4344static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
     
    7273        MODECASE(MAGICDSTOOL_MODE_TOREMOVE,            toremoveMode);
    7374        MODECASE(MAGICDSTOOL_MODE_TORESTORE,           torestoreMode);
     75        MODECASE(MAGICDSTOOL_MODE_TOREVERT,            torevertMode);
    7476        default:
    7577            psAbort("invalid option (this should not happen)");
     
    502504    psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id");
    503505
     506    if (!strcmp(stage, "camera")) {
     507        // no there is no magicked column in camProcessedExp
     508        psFree(output);
     509        return true;
     510    }
    504511
    505512    // chose the appropriate query based on the stage
     
    570577    } else if (!strcmp(stage, "chip")) {
    571578        query = "UPDATE chipRun SET magicked = %" PRId64 " where chip_id = %" PRId64;
     579    } else if (!strcmp(stage, "camera")) {
     580        query = "UPDATE camRun SET magicked = %" PRId64 " where cam_id = %" PRId64;
    572581    } else if (!strcmp(stage, "warp")) {
    573582        query = "UPDATE warpRun SET magicked = %" PRId64 " where warp_id = %" PRId64;
     
    674683    } else if (!strcmp(stage, "chip")) {
    675684        stageNum = 1;
     685    } else if (!strcmp(stage, "camera")) {
     686        stageNum = 2;
    676687    } else if (!strcmp(stage, "warp")) {
    677         stageNum = 2;
     688        stageNum = 3;
    678689    } else {
    679690        psError(PXTOOLS_ERR_DATA, true, "%s is not a valid value for stage", stage);
     
    718729        *stage_id = psMetadataLookupS64(NULL, row, "chip_id");
    719730    } else if (stageNum == 2) {
     731        *stage_id = *cam_id;
     732    } else if (stageNum == 3) {
    720733        *stage_id = psMetadataLookupS64(NULL, row, "warp_id");
    721734    }
     
    10391052    return true;
    10401053}
     1054
     1055
     1056static bool torevertMode(pxConfig *config)
     1057{
     1058    PS_ASSERT_PTR_NON_NULL(config, false);
     1059
     1060    psMetadata *where = psMetadataAlloc();
     1061    PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
     1062
     1063    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     1064    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1065    pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
     1066
     1067    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1068    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1069
     1070    psString sql_file = NULL;
     1071    psStringAppend(&sql_file, "magicdstool_torevert_%s.sql", stage);
     1072
     1073    psString query = pxDataGet(sql_file);
     1074    if (!query) {
     1075        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", sql_file);
     1076        psFree(sql_file);
     1077        return false;
     1078    }
     1079    psFree(sql_file);
     1080
     1081    if (psListLength(where->list)) {
     1082        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1083        psStringAppend(&query, " AND %s", whereClause);
     1084        psFree(whereClause);
     1085    }
     1086    psFree(where);
     1087
     1088    // treat limit == 0 as "no limit"
     1089    if (limit) {
     1090        psString limitString = psDBGenerateLimitSQL(limit);
     1091        psStringAppend(&query, " %s", limitString);
     1092        psFree(limitString);
     1093    }
     1094
     1095    if (!p_psDBRunQuery(config->dbh, query)) {
     1096        psError(PS_ERR_UNKNOWN, false, "database error");
     1097        psFree(query);
     1098        return false;
     1099    }
     1100    psFree(query);
     1101
     1102    psArray *output = p_psDBFetchResult(config->dbh);
     1103    if (!output) {
     1104        psErrorCode err = psErrorCodeLast();
     1105        switch (err) {
     1106            case PS_ERR_DB_CLIENT:
     1107                psError(PXTOOLS_ERR_SYS, false, "database error");
     1108            case PS_ERR_DB_SERVER:
     1109                psError(PXTOOLS_ERR_PROG, false, "database error");
     1110            default:
     1111                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1112        }
     1113
     1114        return false;
     1115    }
     1116    if (!psArrayLength(output)) {
     1117        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     1118        psFree(output);
     1119        return true;
     1120    }
     1121
     1122    if (psArrayLength(output)) {
     1123        // negative simple so the default is true
     1124        if (!ippdbPrintMetadatas(stdout, output, "torevert", !simple)) {
     1125            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1126            psFree(output);
     1127            return false;
     1128        }
     1129    }
     1130
     1131    psFree(output);
     1132
     1133    return true;
     1134}
     1135
     1136
Note: See TracChangeset for help on using the changeset viewer.