IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2010, 3:55:49 PM (16 years ago)
Author:
eugene
Message:

update merges from trunk

Location:
branches/eam_branches/20100225
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225

  • branches/eam_branches/20100225/ippTools/src/chiptool.c

    r26981 r27517  
    3636
    3737static bool definebyqueryMode(pxConfig *config);
     38static bool definecopyMode(pxConfig *config);
    3839static bool updaterunMode(pxConfig *config);
    3940static bool pendingimfileMode(pxConfig *config);
     
    5859static bool importrunMode(pxConfig *config);
    5960static bool runstateMode(pxConfig *config);
     61static bool setimfiletoupdateMode(pxConfig *config);
    6062
    6163# define MODECASE(caseName, func) \
     
    7779    switch (config->mode) {
    7880        MODECASE(CHIPTOOL_MODE_DEFINEBYQUERY,           definebyqueryMode);
     81        MODECASE(CHIPTOOL_MODE_DEFINECOPY,              definecopyMode);
    7982        MODECASE(CHIPTOOL_MODE_UPDATERUN,               updaterunMode);
    8083        MODECASE(CHIPTOOL_MODE_PENDINGIMFILE,           pendingimfileMode);
     
    99102        MODECASE(CHIPTOOL_MODE_IMPORTRUN,               importrunMode);
    100103        MODECASE(CHIPTOOL_MODE_RUNSTATE,                runstateMode);
     104        MODECASE(CHIPTOOL_MODE_SETIMFILETOUPDATE,       setimfiletoupdateMode);
    101105        default:
    102106            psAbort("invalid option (this should not happen)");
     
    120124}
    121125
    122 
    123 static bool definebyqueryMode(pxConfig *config)
    124 {
    125     PS_ASSERT_PTR_NON_NULL(config, NULL);
    126 
    127     PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
    128 
    129     psMetadata *where = psMetadataAlloc();
    130     pxchipGetSearchArgs (config, where); // rawExp only
    131     pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE"); // define using newExp label
    132 
    133     // psListLength(where->list) is at least 1 because exp_type defaults to "object"
    134     // so we require a list longer than 1 entry
    135     if ((psListLength(where->list) <= 1) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    136         psFree(where);
    137         psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    138         return false;
    139     }
    140 
    141     PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
    142     PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    143     PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
    144     PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false);
    145     PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
    146     PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
    147     PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
    148     PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
    149     PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
    150     PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    151 
    152     // default
    153     PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    154     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    155 
    156     // find the exp_id of all the exposures that we want to queue up.
    157     psString query = pxDataGet("chiptool_find_rawexp.sql");
    158     if (!query) {
    159         psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    160         psFree(where);
    161         return false;
    162     }
    163 
    164     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    165     psStringAppend(&query, " AND %s", whereClause);
    166 
    167     psFree(whereClause);
    168     psFree(where);
    169 
    170     if (!p_psDBRunQuery(config->dbh, query)) {
    171         psError(PS_ERR_UNKNOWN, false, "database error");
    172         psFree(query);
    173         return false;
    174     }
    175     psFree(query);
    176 
    177     psArray *output = p_psDBFetchResult(config->dbh);
    178     if (!output) {
    179         psError(PS_ERR_UNKNOWN, false, "database error");
    180         return false;
    181     }
    182     if (!psArrayLength(output)) {
    183         psTrace("chiptool", PS_LOG_INFO, "no rows found");
    184         psFree(output);
    185         return true;
    186     }
    187 
    188     if (pretend) {
    189         // negative simple so the default is true
    190         if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) {
    191             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    192             psFree(output);
    193             return false;
    194         }
    195         psFree(output);
    196         return true;
    197     }
    198 
     126// Queue exposures for chip processing
     127static bool queue_exposures(pxConfig *config,  // Configuration
     128                            const psArray *exps, // Exposures information
     129                            const char *workdir, // Working directory, or NULL to inherit
     130                            const char *label,   // Label, or NULL to inherit
     131                            const char *data_group, // Data group, or NULL to inherit
     132                            const char *dist_group, // Distribution group, or NULL to inherit
     133                            const char *reduction, // Reduction class, or NULL to inherit
     134                            const char *expgroup,  // Exposure group
     135                            const char *dvodb,     // DVO database, or NULL to inherit
     136                            const char *tess_id,   // Tessellation identifier, or NULL to inherit
     137                            const char *end_stage,  // End stage, or NULL to inherit
     138                            const char *note        // Note
     139    )
     140{
    199141    // start a transaction so we don't end up with an exp without any associted
    200142    // imfiles
    201143    if (!psDBTransaction(config->dbh)) {
    202144        psError(PS_ERR_UNKNOWN, false, "database error");
    203         psFree(output);
    204145        return false;
    205146    }
    206147
    207148    // if end_stage is warp (or NULL), check for valid tess_id
    208     for (long i = 0; i < psArrayLength(output); i++) {
    209         psMetadata *md = output->data[i];
     149    for (long i = 0; i < psArrayLength(exps); i++) {
     150        psMetadata *md = exps->data[i];
    210151
    211152        bool status;
     
    220161
    221162        if (!status) {
    222             psError(PS_ERR_UNKNOWN, false, "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64, label, exp_id);
    223             psFree(output);
     163            psError(PS_ERR_UNKNOWN, false,
     164                    "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64,
     165                    label, exp_id);
    224166            return false;
    225167        }
     
    229171# define GET_VALUE(PTYPE,CTYPE,VALUE,NAME)                              \
    230172    PTYPE VALUE;                                                        \
    231     { bool status;                                                      \
     173    {                                                                   \
     174        bool status;                                                    \
    232175        VALUE = psMetadataLookup##CTYPE(&status, md, NAME);             \
    233176        if (!status) {                                                  \
    234177            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", NAME); \
    235             psFree(output);                                             \
    236178            return false;                                               \
    237         } }
     179        }                                                               \
     180    }
    238181
    239182    // loop over our list of exp_ids
    240     for (long i = 0; i < psArrayLength(output); i++) {
    241         psMetadata *md = output->data[i];
     183    for (long i = 0; i < psArrayLength(exps); i++) {
     184        psMetadata *md = exps->data[i];
    242185
    243186        rawExpRow *row = rawExpObjectFromMetadata(md);
    244187        if (!row) {
    245188            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun");
    246             psFree(output);
    247189            return false;
    248190        }
     
    259201        if (!row->exp_id) {
    260202            psError(PS_ERR_UNKNOWN, false, "failed to find value for exp_id");
    261             psFree(output);
    262203            return false;
    263204        }
     
    284225            psError(PS_ERR_UNKNOWN, false,
    285226                    "failed to trying to queue exp_id: %" PRId64, exp_id);
     227            return false;
     228        }
     229    }
     230
     231    if (!psDBCommit(config->dbh)) {
     232        psError(PS_ERR_UNKNOWN, false, "database error");
     233        return false;
     234    }
     235
     236    return true;
     237}
     238
     239static bool definebyqueryMode(pxConfig *config)
     240{
     241    PS_ASSERT_PTR_NON_NULL(config, NULL);
     242
     243    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
     244
     245    psMetadata *where = psMetadataAlloc();
     246    pxchipGetSearchArgs (config, where); // rawExp only
     247    pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE"); // define using newExp label
     248
     249    // psListLength(where->list) is at least 1 because exp_type defaults to "object"
     250    // so we require a list longer than 1 entry
     251    if ((psListLength(where->list) <= 1) && !psMetadataLookupBool(NULL, config->args, "-all")) {
     252        psFree(where);
     253        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     254        return false;
     255    }
     256
     257    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
     258    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     259    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
     260    PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false);
     261    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
     262    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
     263    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     264    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     265    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     266    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
     267
     268    // default
     269    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     270    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     271
     272    // find the exp_id of all the exposures that we want to queue up.
     273    psString query = pxDataGet("chiptool_find_rawexp.sql");
     274    if (!query) {
     275        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     276        psFree(where);
     277        return false;
     278    }
     279
     280    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     281    psStringAppend(&query, " AND %s", whereClause);
     282
     283    psFree(whereClause);
     284    psFree(where);
     285
     286    if (!p_psDBRunQuery(config->dbh, query)) {
     287        psError(PS_ERR_UNKNOWN, false, "database error");
     288        psFree(query);
     289        return false;
     290    }
     291    psFree(query);
     292
     293    psArray *output = p_psDBFetchResult(config->dbh);
     294    if (!output) {
     295        psError(PS_ERR_UNKNOWN, false, "database error");
     296        return false;
     297    }
     298    if (!psArrayLength(output)) {
     299        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     300        psFree(output);
     301        return true;
     302    }
     303
     304    if (pretend) {
     305        // negative simple so the default is true
     306        if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) {
     307            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    286308            psFree(output);
    287309            return false;
    288310        }
     311        psFree(output);
     312        return true;
     313    }
     314
     315    if (!queue_exposures(config, output, workdir, label, data_group, dist_group, reduction, expgroup,
     316                         dvodb, tess_id, end_stage, note)) {
     317        psError(psErrorCodeLast(), false, "Unable to queue exposures for chip.");
     318        psFree(output);
     319        return false;
    289320    }
    290321    psFree(output);
    291322
    292     if (!psDBCommit(config->dbh)) {
    293         psError(PS_ERR_UNKNOWN, false, "database error");
    294         return false;
    295     }
     323    return true;
     324}
     325
     326static bool definecopyMode(pxConfig *config)
     327{
     328    PS_ASSERT_PTR_NON_NULL(config, NULL);
     329
     330    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
     331
     332    psMetadata *where = psMetadataAlloc();
     333    pxchipGetSearchArgs (config, where); // rawExp only
     334    pxAddLabelSearchArgs (config, where, "-label", "chipOld.label", "LIKE");
     335
     336    // psListLength(where->list) is at least 1 because exp_type defaults to "object"
     337    // so we require a list longer than 1 entry
     338    if ((psListLength(where->list) <= 1) && !psMetadataLookupBool(NULL, config->args, "-all")) {
     339        psFree(where);
     340        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     341        return false;
     342    }
     343
     344    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
     345    PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false);
     346    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
     347    PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false);
     348    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
     349    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
     350    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     351    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     352    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     353    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
     354
     355    // default
     356    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     357    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     358
     359    // find the exp_id of all the exposures that we want to queue up.
     360    psString query = pxDataGet("chiptool_definecopy.sql");
     361    if (!query) {
     362        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     363        psFree(where);
     364        return false;
     365    }
     366
     367    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     368    psStringAppend(&query, " AND %s", whereClause);
     369
     370    psFree(whereClause);
     371    psFree(where);
     372
     373    if (!p_psDBRunQueryF(config->dbh, query, label)) {
     374        psError(PS_ERR_UNKNOWN, false, "database error");
     375        psFree(query);
     376        return false;
     377    }
     378    psFree(query);
     379
     380    psArray *output = p_psDBFetchResult(config->dbh);
     381    if (!output) {
     382        psError(PS_ERR_UNKNOWN, false, "database error");
     383        return false;
     384    }
     385    if (!psArrayLength(output)) {
     386        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     387        psFree(output);
     388        return true;
     389    }
     390
     391    if (pretend) {
     392        // negative simple so the default is true
     393        if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) {
     394            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     395            psFree(output);
     396            return false;
     397        }
     398        psFree(output);
     399        return true;
     400    }
     401
     402    if (!queue_exposures(config, output, workdir, label, data_group, dist_group, reduction, expgroup,
     403                         dvodb, tess_id, end_stage, note)) {
     404        psError(psErrorCodeLast(), false, "Unable to queue exposures for chip.");
     405        psFree(output);
     406        return false;
     407    }
     408    psFree(output);
    296409
    297410    return true;
     
    317430        return false;
    318431    }
    319     psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id)");
     432    psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) -- join hook %s\n");
    320433
    321434    // pxUpdateRun gets parameters from config->args and updates
    322     bool result = pxUpdateRun(config, where, &query, "chipRun", true);
     435    bool result = pxUpdateRun(config, where, &query, "chipRun", "chip_id", "chipProcessedImfile", true);
    323436    if (!result) {
    324437        psError(psErrorCodeLast(), false, "pxUpdateRun failed");
     
    16091722    return true;
    16101723}
     1724
     1725// a very specfic function to queue a cleaned chipProcessedImfile to be updated
     1726static bool setimfiletoupdateMode(pxConfig *config)
     1727{
     1728    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1729
     1730    PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", true, false);
     1731    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", false, false);
     1732    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     1733
     1734    psString query = pxDataGet("chiptool_setimfiletoupdate.sql");
     1735    if (!query) {
     1736        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1737        return false;
     1738    }
     1739
     1740    psString setHook = psStringCopy("");
     1741    if (label) {
     1742        psStringAppend(&setHook, "\n , chipRun.label = '%s'", label);
     1743    }
     1744
     1745    if (class_id) {
     1746        psStringAppend(&query, " AND (chipProcessedImfile.class_id = '%s')", class_id);
     1747    }
     1748
     1749    if (!p_psDBRunQueryF(config->dbh, query, setHook, chip_id)) {
     1750        psError(PS_ERR_UNKNOWN, false, "database error");
     1751        return false;
     1752    }
     1753
     1754    psFree(setHook);
     1755    psFree(query);
     1756
     1757    return true;
     1758}
Note: See TracChangeset for help on using the changeset viewer.