IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2009, 10:18:19 AM (17 years ago)
Author:
bills
Message:

advance exposures using load, run style so that the proper workdir
and end stage

File:
1 edited

Legend:

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

    r21479 r23497  
    4444
    4545static bool clearcommonfaultsMode(pxConfig *config);
     46static bool toadvanceMode(pxConfig *config);
    4647static bool advanceMode(pxConfig *config);
    4748
    48 static bool copydoneCompleteExp(pxConfig *config);
     49// static bool copydoneCompleteExp(pxConfig *config);
    4950static psArray *pzGetPendingCameras(pxConfig *config);
    5051static psArray *pzArrayZip(psArray *arraySet, psS64 limit);
     
    8081        MODECASE(PZTOOL_MODE_REVERTCOPIED, revertcopiedMode);
    8182        MODECASE(PZTOOL_MODE_CLEARCOMMONFAULTS, clearcommonfaultsMode);
     83        MODECASE(PZTOOL_MODE_TOADVANCE, toadvanceMode);
    8284        MODECASE(PZTOOL_MODE_ADVANCE, advanceMode);
    8385        default:
     
    403405    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    404406
    405     // NOTE : the rest of the command-line args are parsed in copydoneCompleteExp
    406 
    407407    // start a transaction early so it will contain any row level locks
    408408    if (!psDBTransaction(config->dbh)) {
     
    463463    }
    464464
    465 #ifdef notdef
    466     // we've changed to use -advance instead
    467     if (!copydoneCompleteExp(config)) {
    468         // rollback
    469         if (!psDBRollback(config->dbh)) {
    470             psError(PS_ERR_UNKNOWN, false, "database error");
    471         }
    472         psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");
    473         return false;
    474     }
    475 #endif
    476465    // point of no return
    477466    if (!psDBCommit(config->dbh)) {
     
    487476}
    488477
    489 static bool copydoneCompleteExp(pxConfig *config)
    490 {
    491     // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!!
    492    
    493     PS_ASSERT_PTR_NON_NULL(config, false);
    494 
    495     // XXX this is an ugly hack!
    496     // we are passing exp level info to a imfile level mode (-copydone)
    497     // these options are thrown away unless we just -copydone'd the last imfile
    498     // in an exp. 
    499  
    500     // optional
    501     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
    502     PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
    503     PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false);
    504     PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false);
    505     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     478static bool toadvanceMode(pxConfig *config)
     479{
     480    PS_ASSERT_PTR_NON_NULL(config, false);
     481
     482    // optional args
     483    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    506484    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    507485
     
    517495    PXOPT_COPY_STR(config->args, where,  "-exp_name", "exp_name", "==");
    518496    PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
    519     PXOPT_COPY_STR(config->args, where,  "-telescope", "telescope", "==");
     497    PXOPT_COPY_STR(config->args, where,  "-inst", "camera", "==");
     498    PXOPT_COPY_STR(config->args, where,  "-label", "label", "==");
    520499
    521500    if (psListLength(where->list)) {
     
    525504    }
    526505    psFree(where);
     506
    527507
    528508    // treat limit == 0 as "no limit"
     
    552532    }
    553533
    554    for (long i = 0; i < psArrayLength(output); i++) {
    555         psMetadata *row = output->data[i];
    556 
    557         pzDownloadExpRow *doneExp = pzDownloadExpObjectFromMetadata(row);
    558         if (!doneExp) {
    559             psError(PS_ERR_UNKNOWN, false, "pzDownloadExpObjectFromMetadata() failed");
    560             psFree(doneExp);
    561             psFree(output);
    562             return false;
    563         }
    564 
    565         if (!newExpInsert(config->dbh,
    566                     0x0,                // exp_id
    567                     doneExp->exp_name,  // tmp_exp_name
    568                     doneExp->camera,    // tmp_camera
    569                     doneExp->telescope, // tmp_telescope
    570                     "run",              // state
    571                     workdir,            // workdir
    572                     "dirty",            // workdir state
    573                     NULL,               // reduction class
    574                     dvodb,              // dvodb
    575                     tess_id,            // tess_id
    576                     end_stage,          // end_stage
    577                     label,
    578                     NULL                // epoch
    579                 )
     534    if (!ippdbPrintMetadatas(stdout, output, "toadvance", !simple)) {
     535        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     536        psFree(output);
     537        return false;
     538    }
     539
     540    psFree(output);
     541
     542    return true;
     543}
     544
     545static bool advanceMode(pxConfig *config)
     546{
     547    PS_ASSERT_PTR_NON_NULL(config, false);
     548
     549    // required
     550    PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
     551    PXOPT_LOOKUP_STR(inst, config->args, "-inst", true, false);
     552    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
     553    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
     554
     555    // optional
     556    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
     557    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false);
     558    PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false);
     559    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     560
     561    // start a transaction so it's all rows or nothing
     562    if (!psDBTransaction(config->dbh)) {
     563        psError(PS_ERR_UNKNOWN, false, "database error");
     564        return false;
     565    }
     566
     567    if (!newExpInsert(config->dbh,
     568            0x0,        // exp_id
     569            exp_name,   // tmp_exp_name
     570            inst,       // tmp_camera
     571            telescope,  // tmp_telescope
     572            "run",      // state
     573            workdir,    // workdir
     574            "dirty",    // workdir state
     575            NULL,       // reduction class
     576            dvodb,      // dvodb
     577            tess_id,    // tess_id
     578            end_stage,  // end_stage
     579            label,      // label
     580            NULL        // epoch
     581            )
    580582        ) {
    581583            psError(PS_ERR_UNKNOWN, false, "database error");
    582             psFree(doneExp);
    583             psFree(output);
    584584            return false;
    585585        }
     
    592592                "INSERT INTO newImfile"
    593593                "   SElECT"
    594                 "       %" PRId64 "," // exp_id
     594                "       %" PRId64 ","               // exp_id
    595595                "       pzDownloadImfile.class_id," // tmp_class_id
    596                 "       pzDownloadImfile.uri," // uri
    597                 "       NULL" // epoch
     596                "       pzDownloadImfile.uri,"      // uri
     597                "       NULL"                       // epoch
    598598                "   FROM pzDownloadImfile"
    599599                "   WHERE"
     
    602602                "       AND pzDownloadImfile.telescope = '%s'";
    603603
    604             if (!p_psDBRunQueryF(config->dbh, query, exp_id, doneExp->exp_name, doneExp->camera, doneExp->telescope)) {
    605                 psError(PS_ERR_UNKNOWN, false, "database error");
    606                 psFree(doneExp);
    607                 psFree(output);
    608                 return false;
    609             }
    610 
    611             // sanity check: we should have inserted at least one row
    612             psU64 affected = psDBAffectedRows(config->dbh);
    613             if (psDBAffectedRows(config->dbh) < 1) {
    614                 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
    615                 psFree(doneExp);
    616                 psFree(output);
    617                 return false;
    618             }
    619         }
    620 
    621         // set pzDownloadExp.state to 'stop'
    622         if (!pzDownloadExpSetState(config, doneExp->exp_name, doneExp->camera, doneExp->telescope, "stop")) {
    623             psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", doneExp->exp_name, doneExp->camera, doneExp->telescope);
    624             psFree(doneExp);
    625             psFree(output);
     604        if (!p_psDBRunQueryF(config->dbh, query, exp_id, exp_name, inst, telescope)) {
     605            psError(PS_ERR_UNKNOWN, false, "database error");
    626606            return false;
    627         }
    628 
    629         psFree(doneExp);
    630     }
    631 
    632     psFree(output);
     607        }
     608
     609        // sanity check: we should have inserted at least one row
     610        psU64 affected = psDBAffectedRows(config->dbh);
     611        if (psDBAffectedRows(config->dbh) < 1) {
     612            psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected);
     613            return false;
     614        }
     615    }
     616
     617    // set pzDownloadExp.state to 'stop'
     618    if (!pzDownloadExpSetState(config, exp_name, inst, telescope, "stop")) {
     619        psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", exp_name, inst, telescope);
     620        return false;
     621    }
     622
     623    // point of no return
     624    if (!psDBCommit(config->dbh)) {
     625        // rollback
     626        if (!psDBRollback(config->dbh)) {
     627            psError(PS_ERR_UNKNOWN, false, "database error");
     628        }
     629        psError(PS_ERR_UNKNOWN, false, "database error");
     630        return false;
     631    }
     632
    633633
    634634    return true;
     
    872872}
    873873
    874 static bool advanceMode(pxConfig *config)
    875 {
    876     PS_ASSERT_PTR_NON_NULL(config, false);
    877 
    878     // NOTE : the command-line args are parsed in copydoneCompleteExp
    879 
    880     // start a transaction so it's all rows or nothing
    881     if (!psDBTransaction(config->dbh)) {
    882         psError(PS_ERR_UNKNOWN, false, "database error");
    883         return false;
    884     }
    885 
    886     if (!copydoneCompleteExp(config)) {
    887         // rollback
    888         if (!psDBRollback(config->dbh)) {
    889             psError(PS_ERR_UNKNOWN, false, "database error");
    890         }
    891         psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");
    892         return false;
    893     }
    894 
    895     // point of no return
    896     if (!psDBCommit(config->dbh)) {
    897         // rollback
    898         if (!psDBRollback(config->dbh)) {
    899             psError(PS_ERR_UNKNOWN, false, "database error");
    900         }
    901         psError(PS_ERR_UNKNOWN, false, "database error");
    902         return false;
    903     }
    904 
    905 
    906     return true;
    907 }
    908 
    909874
    910875static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)
Note: See TracChangeset for help on using the changeset viewer.