IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17655


Ignore:
Timestamp:
May 13, 2008, 11:37:57 AM (18 years ago)
Author:
jhoblitt
Message:

add pztool -advance
major pztool -copydone overhaul

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

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

    r17611 r17655  
    22 * pztool.c
    33 *
    4  * Copyright (C) 2006  Joshua Hoblitt
     4 * Copyright (C) 2006-2008  Joshua Hoblitt
    55 *
    66 * This program is free software; you can redistribute it and/or modify it
     
    2727#include <inttypes.h>
    2828
     29#include "pslib.h"
    2930#include "pxtools.h"
    3031#include "pxdata.h"
     
    4142static bool updatecopiedMode(pxConfig *config);
    4243static bool revertcopiedMode(pxConfig *config);
     44static bool advanceMode(pxConfig *config);
    4345
    4446static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope);
     
    7577        MODECASE(PZTOOL_MODE_UPDATECOPIED, updatecopiedMode);
    7678        MODECASE(PZTOOL_MODE_REVERTCOPIED, revertcopiedMode);
     79        MODECASE(PZTOOL_MODE_ADVANCE, advanceMode);
    7780        default:
    7881            psAbort("invalid option (this should not happen)");
     
    360363    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    361364
    362     // need to know exp_name, camera, telescope, class, class_id (to find the
    363     // pzDownloadImfile entry and the URI for the newImfile entry.
     365    if (!pzDownloadImfileInsert(config->dbh,
     366            exp_name,
     367            camera,
     368            telescope,
     369            class,
     370            class_id,
     371            uri,
     372            code
     373    )) {
     374        psError(PS_ERR_UNKNOWN, false, "database error");
     375        return false;
     376    }
    364377
    365378    // start a transaction so it's all rows or nothing
     
    367380        psError(PS_ERR_UNKNOWN, false, "database error");
    368381        return false;
    369     }
    370 
    371     // cp the imfile into pzDownloadImfile
    372     {
    373         char *query =
    374             "INSERT INTO pzDownloadImfile"
    375             "   SELECT"
    376             "       exp_name,"
    377             "       camera,"
    378             "       telescope,"
    379             "       class,"
    380             "       class_id,"
    381             "       '%s'," // uri of downloaded file
    382             "       '%d'" // fault code
    383             "   FROM summitImfile"
    384             "   WHERE"
    385             "       summitImfile.exp_name = '%s'"
    386             "       AND summitImfile.camera = '%s'"
    387             "       AND summitImfile.telescope = '%s'"
    388             "       AND summitImfile.class = '%s'"
    389             "       AND summitImfile.class_id = '%s'";
    390 
    391         if (!p_psDBRunQuery(config->dbh, query, uri, code, exp_name, camera, telescope, class, class_id)) {
    392             // rollback
    393             if (!psDBRollback(config->dbh)) {
    394                 psError(PS_ERR_UNKNOWN, false, "database error");
    395             }
    396             psError(PS_ERR_UNKNOWN, false, "database error");
    397             return false;
    398         }
    399 
    400         // sanity check: we should have inserted only one row
    401         psU64 affected = psDBAffectedRows(config->dbh);
    402         if (psDBAffectedRows(config->dbh) != 1) {
    403             // rollback
    404             if (!psDBRollback(config->dbh)) {
    405                 psError(PS_ERR_UNKNOWN, false, "database error");
    406             }
    407             psError(PS_ERR_UNKNOWN, false, "should have affected 1 row but %" PRIu64 " rows were modified", affected);
    408             return false;
    409         }
    410382    }
    411383
     
    434406static bool copydoneCompleteExp(pxConfig *config, const char *exp_name, const char *camera, const char *telescope)
    435407{
     408    // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!!
     409   
    436410    PS_ASSERT_PTR_NON_NULL(config, false);
    437411
     
    440414    // these options are thrown away unless we just -copydone'd the last imfile
    441415    // in an exp. 
    442     // This function MUST NOT be invoked from anywhere but copydoneMode().
    443416 
    444417    // optional
     
    457430    }
    458431
    459     psStringAppend(&query, "WHERE exp_name = '%s' AND telescope = '%s' AND camera = '%s'",
    460                           exp_name, telescope, camera);
     432    psMetadata *where = psMetadataAlloc();
     433    if (exp_name) {
     434        if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_name", 0, "==", exp_name)) {
     435            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_name");
     436            psFree(where);
     437            return false;
     438        }
     439    }
     440
     441    if (camera) {
     442        if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==", camera)) {
     443            psError(PS_ERR_UNKNOWN, false, "failed to add item camera");
     444            psFree(where);
     445            return false;
     446        }
     447    }
     448
     449    if (telescope) {
     450        if (!psMetadataAddStr(where, PS_LIST_TAIL, "telescope", 0, "==", telescope)) {
     451            psError(PS_ERR_UNKNOWN, false, "failed to add item telescope");
     452            psFree(where);
     453            return false;
     454        }
     455    }
     456
     457    if (config->where) {
     458        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     459        psStringAppend(&query, " %s", whereClause);
     460        psFree(whereClause);
     461    }
     462    psFree(where);
    461463
    462464    if (!p_psDBRunQuery(config->dbh, query)) {
     
    736738
    737739
     740static bool advanceMode(pxConfig *config)
     741{
     742    PS_ASSERT_PTR_NON_NULL(config, false);
     743
     744    // start a transaction so it's all rows or nothing
     745    if (!psDBTransaction(config->dbh)) {
     746        psError(PS_ERR_UNKNOWN, false, "database error");
     747        return false;
     748    }
     749
     750    if (!copydoneCompleteExp(config, NULL, NULL, NULL)) {
     751        // rollback
     752        if (!psDBRollback(config->dbh)) {
     753            psError(PS_ERR_UNKNOWN, false, "database error");
     754        }
     755        psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");
     756        return false;
     757    }
     758
     759    // point of no return
     760    if (!psDBCommit(config->dbh)) {
     761        // rollback
     762        if (!psDBRollback(config->dbh)) {
     763            psError(PS_ERR_UNKNOWN, false, "database error");
     764        }
     765        psError(PS_ERR_UNKNOWN, false, "database error");
     766        return false;
     767    }
     768
     769
     770    return true;
     771}
     772
     773
    738774static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)
    739775{
  • trunk/ippTools/src/pztool.h

    r16360 r17655  
    3333    PZTOOL_MODE_COPIED,
    3434    PZTOOL_MODE_UPDATECOPIED,
    35     PZTOOL_MODE_REVERTCOPIED
     35    PZTOOL_MODE_REVERTCOPIED,
     36    PZTOOL_MODE_ADVANCE
    3637} pztoolMode;
    3738
  • trunk/ippTools/src/pztoolConfig.c

    r16509 r17655  
    176176            "search by fault code", 0);
    177177
     178    // -advance
     179    psMetadata *advanceArgs = psMetadataAlloc();
     180    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-workdir",  0,
     181        "define the \"default\" workdir for this exposure", NULL);
     182    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-dvodb",  0,
     183        "define the dvodb for the next processing step", NULL);
     184    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-tess_id",  0,
     185        "define the tess_id for the next processing step", NULL);
     186    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-end_stage",  0,
     187        "define the end goal processing step", NULL);
     188    psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-label",  0,
     189        "define the label for the chip stage", NULL);
     190
    178191    psMetadata *argSets = psMetadataAlloc();
    179192    psMetadata *modes = psMetadataAlloc();
     
    188201    PXOPT_ADD_MODE("-updatecopied",    "", PZTOOL_MODE_UPDATECOPIED,updatecopiedArgs);
    189202    PXOPT_ADD_MODE("-revertcopied",    "", PZTOOL_MODE_REVERTCOPIED,revertcopiedArgs);
     203    PXOPT_ADD_MODE("-advance",          "", PZTOOL_MODE_ADVANCE,    advanceArgs);
    190204
    191205    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Note: See TracChangeset for help on using the changeset viewer.