IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 28, 2011, 6:41:17 PM (15 years ago)
Author:
watersc1
Message:

Majority of ippTools/SQL work should be complete now. Need to start queueing exposures, and testing the script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20110406/ippTools/src/laptool.c

    r31397 r31407  
    121121  }
    122122
    123   if (lapSequencePrintObject(stdout, run, !simple)) {
     123  if (!lapSequencePrintObject(stdout, run, !simple)) {
    124124    psError(PS_ERR_UNKNOWN, false, "failed to print object");
    125125    psFree(run);
     
    141141  psMetadata *where = psMetadataAlloc();
    142142  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
    143   PXOPT_COPY_STR(config->args, where, "-name",   "name",   "LIKE");
     143  PXOPT_COPY_STR(config->args, where, "-seq_name",   "name",   "LIKE");
    144144
    145145  psString query = pxDataGet("laptool_listsequence.sql");
     
    214214  PXOPT_LOOKUP_STR(label,           config->args, "-label",           false, false);
    215215  PXOPT_LOOKUP_STR(dist_group,      config->args, "-dist_group",      false, false);
     216  PXOPT_LOOKUP_BOOL(all_obsmode,    config->args, "-all_obsmode",     false);
    216217  PXOPT_LOOKUP_BOOL(simple,         config->args, "-simple",          false);
    217218
     
    226227                                  NULL, // registered
    227228                                  0,    // fault
    228                                   0,    // quick_sass_id
    229                                   0     // final_sass_id
     229                                  INT64_MAX,    // quick_sass_id
     230                                  INT64_MAX     // final_sass_id
    230231                                  );
    231232  if (!run) {
     
    248249  }
    249250
    250   // point of no return
    251   if (!psDBCommit(config->dbh)) {
    252     psError(PS_ERR_UNKNOWN, false, "database error");
    253     return false;
    254   }
    255 
    256   if (lapRunPrintObject(stdout, run, !simple)) {
     251
     252  if (!lapRunPrintObject(stdout, run, !simple)) {
     253    if (!psDBRollback(config->dbh)) {
     254      psError(PS_ERR_UNKNOWN, false, "database error");
     255    }
    257256    psError(PS_ERR_UNKNOWN, false, "failed to print object");
    258257    psFree(run);
     
    265264  psString query = pxDataGet("laptool_definerun.sql");
    266265  if (!query) {
     266    if (!psDBRollback(config->dbh)) {
     267      psError(PS_ERR_UNKNOWN, false, "database error");
     268    }
     269
    267270    psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
    268271    return(false);
    269272  }
    270   psString where = NULL;
    271   if (!pxspaceAddWhere(config, &where, "rawExp")) {
     273
     274  // Add constraints to the exposure search:
     275  psMetadata *where = psMetadataAlloc();
     276  PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "==");
     277
     278  // This seems unnecessarily clunky.
     279  if (!all_obsmode) {
     280    //    fprintf(stderr, "Not doing all obsmodes!\n");
     281    if (!psMetadataLookupStr(NULL,config->args,"-obsmode")) {
     282      //      fprintf(stderr, "Not doing all obsmodes and none specified!\n");
     283      psMetadataAddStr(where,PS_LIST_TAIL,"rawExp.obs_mode",0,"==","3PI");
     284    }
     285    pxAddLabelSearchArgs (config, where, "-obsmode", "rawExp.obsmode", "==");
     286  }
     287 
     288  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     289  if (!pxspaceAddWhere(config, &whereClause, "rawExp")) {
     290    if (!psDBRollback(config->dbh)) {
     291      psError(PS_ERR_UNKNOWN, false, "database error");
     292    }
     293
    272294    psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed");
    273295    return(false);
    274296  }
    275   psStringAppend(&query, " %s", where);
     297  psStringAppend(&query, " %s", whereClause);
    276298  psFree(where);
    277299
     300  // Fetch exposures
    278301  if (!p_psDBRunQuery(config->dbh, query)) {
     302    if (!psDBRollback(config->dbh)) {
     303      psError(PS_ERR_UNKNOWN, false, "database error");
     304    }
     305
    279306    psError(PS_ERR_UNKNOWN, false, "database error");
    280307    psFree(query);
     
    285312  psArray *output = p_psDBFetchResult(config->dbh);
    286313  if (!output) {
     314    if (!psDBRollback(config->dbh)) {
     315      psError(PS_ERR_UNKNOWN, false, "database error");
     316    }
     317
    287318    psError(PS_ERR_UNKNOWN, false, "database error");
    288319    return(false);
    289320  }
    290321  if (!psArrayLength(output)) {
     322    if (!psDBRollback(config->dbh)) {
     323      psError(PS_ERR_UNKNOWN, false, "database error");
     324    }
     325
    291326    psTrace("laptool", PS_LOG_INFO, "no rows found");
    292327    psFree(output);
     
    294329  }
    295330
    296 
    297331  // Insert the exposure data
    298332  for (long i = 0; i < output->n; i++) {
    299333    psMetadata *row = output->data[i]; // Row from select
     334    // Add default values from this run:
     335    psMetadataAddS64(row, PS_LIST_TAIL, "lap_id", 0, "", lap_id);
     336    psMetadataAddS64(row, PS_LIST_TAIL, "pair_id", 0, "", INT64_MAX);
     337    psMetadataAddStr(row, PS_LIST_TAIL, "data_state", 0, "", "new");
    300338    lapExpRow *lapExp = lapExpObjectFromMetadata(row);
    301339    lapExp->lap_id = lap_id;
    302340
    303341    if (!lapExpInsertObject(config->dbh,lapExp)) {
     342      if (!lapExpPrintObject(stdout, lapExp, !simple)) {
     343        if (!psDBRollback(config->dbh)) {
     344          psError(PS_ERR_UNKNOWN, false, "database error");
     345        }
     346        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     347        psFree(run);
     348        return false;
     349      }
     350     
    304351      if (!psDBRollback(config->dbh)) {
    305352        psError(PS_ERR_UNKNOWN, false, "database error");
     
    312359  }
    313360
     361  // point of no return
     362  if (!psDBCommit(config->dbh)) {
     363    psError(PS_ERR_UNKNOWN, false, "database error");
     364    return false;
     365  }
     366
     367 
    314368  psFree(output);
    315369  return(true); 
     
    341395    psFree(whereClause);
    342396  }
    343   psStringAppend(&query, " ORDER BY rawExp.dateobs ");
    344397 
    345398  if (!p_psDBRunQuery(config->dbh, query)) {
     
    452505    psFree(limitString);
    453506  }
     507  psStringAppend(&query, " ORDER BY rawExp.dateobs ");
     508 
    454509  if (!p_psDBRunQuery(config->dbh, query)) {
    455510    psError(PS_ERR_UNKNOWN, false, "database error");
     
    554609{
    555610  PS_ASSERT_PTR_NON_NULL(config, false);
     611  PXOPT_LOOKUP_S64(lap_id, config->args, "-lap_id", true, false);
     612
    556613  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    557614  PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    558  
     615
    559616  psMetadata *where = psMetadataAlloc();
    560617  PXOPT_COPY_S64(config->args, where, "-lap_id", "lap_id", "==");
     
    565622    return(false);
    566623  }
    567   psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    568   if (whereClause) {
     624 
     625  if (psListLength(where->list)) {
     626    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    569627    psStringPrepend(&whereClause, "\n AND ");
    570   }
    571  
    572   psString limitString = NULL;
     628    psStringSubstitute(&query,whereClause,"@WHERE@");
     629    psFree(whereClause);
     630  }
     631
    573632  if (limit) {
    574     limitString = psDBGenerateLimitSQL(limit);
    575     psStringPrepend(&limitString, "\n");
    576   }
    577 
    578   if (!p_psDBRunQueryF(config->dbh, query, whereClause, limitString ? limitString : "")) {
    579     psError(PXTOOLS_ERR_PROG, false, "database error");
     633    psString limitString = psDBGenerateLimitSQL(limit);
     634    psStringAppend(&query, " %s", limitString);
    580635    psFree(limitString);
     636  }
     637
     638
     639  if (!p_psDBRunQuery(config->dbh, query)) {
     640    psError(PS_ERR_UNKNOWN, false, "database error");
    581641    psFree(query);
    582     psFree(whereClause);
    583     return(false);
    584   }
    585   psFree(limitString);
     642    return false;
     643  }
    586644  psFree(query);
    587   psFree(whereClause);
    588  
     645
    589646  psArray *output = p_psDBFetchResult(config->dbh);
    590647  if (!output) {
    591     psError(PS_ERR_UNKNOWN, false, "database error");
    592     return(false);
     648    psErrorCode err = psErrorCodeLast();
     649    switch (err) {
     650    case PS_ERR_DB_CLIENT:
     651      psError(PXTOOLS_ERR_SYS, false, "database error");
     652    case PS_ERR_DB_SERVER:
     653      psError(PXTOOLS_ERR_PROG, false, "database error");
     654    default:
     655      psError(PXTOOLS_ERR_PROG, false, "unknown error %d",err);
     656    }
     657
     658    return false;
    593659  }
    594660  if (!psArrayLength(output)) {
    595661    psTrace("laptool", PS_LOG_INFO, "no rows found");
    596662    psFree(output);
    597     return(true);
    598   }
    599  
    600   if (!ippdbPrintMetadatas(stdout, output, "lapRunStacks", !simple)) {
    601     psError(PS_ERR_UNKNOWN, false, "failed to print array");
    602     psFree(output);
    603     return(false);
     663    return true;
     664  }
     665
     666  if (psArrayLength(output)) {
     667    if (!ippdbPrintMetadatas(stdout, output, "lapRunStacks", !simple)) {
     668      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     669      psFree(output);
     670      return false;
     671    }
    604672  }
    605673
Note: See TracChangeset for help on using the changeset viewer.