IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2009, 1:59:32 PM (17 years ago)
Author:
beaumont
Message:

merged with trunk

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3333pstamptool
        3434disttool
         35receivetool
  • branches/cnb_branches/cnb_branch_20090301/ippTools/src/chiptool.c

    r23594 r24244  
    125125    psMetadata *where = psMetadataAlloc();
    126126    pxchipGetSearchArgs (config, where); // rawExp only
    127     PXOPT_COPY_STR(config->args, where, "-label", "rawExp.label", "LIKE");
     127    pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE");
    128128
    129129    // psListLength(where->list) is at least 1 because exp_type defaults to "object"
     
    198198    }
    199199
     200    // if end_stage is warp (or NULL), check for valid tess_id
     201    for (long i = 0; i < psArrayLength(output); i++) {
     202        psMetadata *md = output->data[i];
     203
     204        bool status;
     205        char *end_stage = psMetadataLookupStr(&status, md, "end_stage");
     206        if (end_stage && strcasecmp(end_stage, "warp")) continue;
     207
     208        char *raw_tess_id   = psMetadataLookupStr(&status, md, "tess_id");
     209        if (raw_tess_id || tess_id) continue;
     210
     211        char *label  = psMetadataLookupStr(&status, md, "label");
     212        psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id");
     213
     214        if (!status) {
     215            psError(PS_ERR_UNKNOWN, false, "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64, label, exp_id);
     216            psFree(output);
     217            return false;
     218        }
     219    }
     220
     221
     222# define GET_VALUE(PTYPE,CTYPE,VALUE,NAME)                              \
     223    PTYPE VALUE;                                                        \
     224    { bool status;                                                      \
     225        VALUE = psMetadataLookup##CTYPE(&status, md, NAME);             \
     226        if (!status) {                                                  \
     227            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", NAME); \
     228            psFree(output);                                             \
     229            return false;                                               \
     230        } }
     231
    200232    // loop over our list of exp_ids
    201233    for (long i = 0; i < psArrayLength(output); i++) {
    202234        psMetadata *md = output->data[i];
    203235
    204         bool status;
    205         psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id");
    206         if (!status) {
    207             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id");
     236        rawExpRow *row = rawExpObjectFromMetadata(md);
     237        if (!row) {
     238            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun");
    208239            psFree(output);
    209240            return false;
    210241        }
    211         //
     242
     243        GET_VALUE (psS64,    S64, exp_id,        "exp_id");
     244        GET_VALUE (psString, Str, raw_workdir,   "workdir");
     245        GET_VALUE (psString, Str, raw_label,     "label");
     246        GET_VALUE (psString, Str, raw_reduction, "reduction");
     247        // GET_VALUE (psString, Str, raw_expgroup,  "expgroup");
     248        GET_VALUE (psString, Str, raw_dvodb,     "dvodb");
     249        GET_VALUE (psString, Str, raw_tess_id,   "tess_id");
     250        GET_VALUE (psString, Str, raw_end_stage, "end_stage");
     251
     252        if (!row->exp_id) {
     253            psError(PS_ERR_UNKNOWN, false, "failed to find value for exp_id");
     254            psFree(output);
     255            return false;
     256        }
     257
    212258        // queue the exp
    213         if (!pxchipQueueByExpTag(config, exp_id, workdir, label, reduction, expgroup, dvodb, tess_id, end_stage)) {
     259        if (!pxchipQueueByExpTag(config,
     260                                 exp_id,
     261                                 workdir     ? workdir   : raw_workdir,
     262                                 label       ? label     : raw_label,
     263                                 reduction   ? reduction : raw_reduction,
     264                                 // expgroup    ? expgroup  : raw_expgroup,
     265                                 // XXX how does expgroup get defined?
     266                                 expgroup,
     267                                 dvodb       ? dvodb     : raw_dvodb,
     268                                 tess_id     ? tess_id   : raw_tess_id,
     269                                 end_stage   ? end_stage : raw_end_stage
     270                                 )) {
    214271            if (!psDBRollback(config->dbh)) {
    215272                psError(PS_ERR_UNKNOWN, false, "database error");
     
    239296    pxchipGetSearchArgs (config, where); // rawExp, chipRun
    240297    PXOPT_COPY_S64(config->args,  where, "-chip_id", "chipRun.chip_id", "==");
     298    // we only allow a single label to match (do not use pxAddLabelSearchArgs here)
    241299    PXOPT_COPY_STR(config->args,  where, "-label",   "chipRun.label",   "==");
    242300    PXOPT_COPY_STR(config->args,  where, "-state",   "chipRun.state",   "==");
    243301
    244     if (!psListLength(where->list)
    245         && !psMetadataLookupBool(NULL, config->args, "-all")) {
     302    if (!psListLength(where->list) &&
     303        !psMetadataLookupBool(NULL, config->args, "-all")) {
    246304        psFree(where);
    247305        where = NULL;
     
    291349    pxchipGetSearchArgs (config, where); //chipRun, rawExp
    292350    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
    293     PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "==");
     351    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "==");
    294352
    295353    psString query = pxDataGet("chiptool_pendingimfile.sql");
     
    409467    PXOPT_LOOKUP_F32(dtime_script, config->args,   "-dtime_script", false, false);
    410468    PXOPT_LOOKUP_STR(hostname, config->args,       "-hostname", false, false);
    411     PXOPT_LOOKUP_F32(n_stars, config->args,        "-n_stars", false, false);
    412     PXOPT_LOOKUP_F32(n_psfstars, config->args,     "-n_psfstars", false, false);
    413     PXOPT_LOOKUP_F32(n_iqstars, config->args,      "-n_iqstars", false, false);
    414     PXOPT_LOOKUP_F32(n_extended, config->args,     "-n_extended", false, false);
    415     PXOPT_LOOKUP_F32(n_cr, config->args,           "-n_cr", false, false);
    416     PXOPT_LOOKUP_STR(path_base, config->args,      "-path_base", false, false);
    417     PXOPT_LOOKUP_BOOL(magicked, config->args,      "-magicked", false);
     469    PXOPT_LOOKUP_F32(n_stars, config->args,        "-n_stars", false, false);
     470    PXOPT_LOOKUP_F32(n_psfstars, config->args,     "-n_psfstars", false, false);
     471    PXOPT_LOOKUP_F32(n_iqstars, config->args,      "-n_iqstars", false, false);
     472    PXOPT_LOOKUP_F32(n_extended, config->args,     "-n_extended", false, false);
     473    PXOPT_LOOKUP_F32(n_cr, config->args,           "-n_cr", false, false);
     474    PXOPT_LOOKUP_STR(path_base, config->args,      "-path_base", false, false);
     475    PXOPT_LOOKUP_BOOL(magicked, config->args,      "-magicked", false);
    418476
    419477    // default values
    420     PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
     478    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     479    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
    421480
    422481    if (!psDBTransaction(config->dbh)) {
     
    449508                                   fwhm_minor_uq,
    450509
    451                                    iq_fwhm_major,
    452                                    iq_fwhm_major_err,
    453                                    iq_fwhm_minor,
    454                                    iq_fwhm_minor_err,
    455 
    456                                    iq_m2,
    457                                    iq_m2_err,
    458                                    iq_m2_lq,
    459                                    iq_m2_uq,
    460 
    461                                    iq_m2c,
    462                                    iq_m2c_err,
    463                                    iq_m2c_lq,
    464                                    iq_m2c_uq,
    465 
    466                                    iq_m2s,
    467                                    iq_m2s_err,
    468                                    iq_m2s_lq,
    469                                    iq_m2s_uq,
    470 
    471                                    iq_m3,
    472                                    iq_m3_err,
    473                                    iq_m3_lq,
    474                                    iq_m3_uq,
    475 
    476                                    iq_m4,
    477                                    iq_m4_err,
    478                                    iq_m4_lq,
    479                                    iq_m4_uq,
     510                                   iq_fwhm_major,
     511                                   iq_fwhm_major_err,
     512                                   iq_fwhm_minor,
     513                                   iq_fwhm_minor_err,
     514
     515                                   iq_m2,
     516                                   iq_m2_err,
     517                                   iq_m2_lq,
     518                                   iq_m2_uq,
     519
     520                                   iq_m2c,
     521                                   iq_m2c_err,
     522                                   iq_m2c_lq,
     523                                   iq_m2c_uq,
     524
     525                                   iq_m2s,
     526                                   iq_m2s_err,
     527                                   iq_m2s_lq,
     528                                   iq_m2s_uq,
     529
     530                                   iq_m3,
     531                                   iq_m3_err,
     532                                   iq_m3_lq,
     533                                   iq_m3_uq,
     534
     535                                   iq_m4,
     536                                   iq_m4_err,
     537                                   iq_m4_lq,
     538                                   iq_m4_uq,
    480539
    481540                                   dtime_detrend,
     
    490549                                   n_cr,
    491550                                   path_base,
    492                                    code,
     551                                   fault,
     552                                   quality,
    493553                                   magicked
    494554            )) {
     
    540600    PXOPT_COPY_STR(config->args, where, "-class_id", "chipProcessedImfile.class_id", "==");
    541601    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
    542     PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "LIKE");
     602    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE");
    543603    PXOPT_COPY_S32(config->args, where, "-magicked", "chipRun.magicked", "==");
     604
     605    if (!psListLength(where->list) &&
     606        !psMetadataLookupBool(NULL, config->args, "-all")) {
     607        psFree(where);
     608        psError(PXTOOLS_ERR_DATA, false, "search parameters (or -all) are required");
     609        return false;
     610    }
    544611
    545612    psString query = pxDataGet("chiptool_processedimfile.sql");
     
    609676    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
    610677    PXOPT_COPY_STR(config->args, where, "-class_id", "chipProcessedImfile.class_id", "==");
    611     PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "LIKE");
     678    // require a single label
     679    PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "==");
    612680    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
    613     PXOPT_COPY_S16(config->args, where, "-code", "chipProcessedImfile.fault", "==");
     681    PXOPT_COPY_S16(config->args, where, "-fault", "chipProcessedImfile.fault", "==");
    614682
    615683    if (!psListLength(where->list)
     
    652720    PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
    653721    PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "==");
    654     PXOPT_LOOKUP_S16(code, config->args, "-code", true, false);
    655 
    656     if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, code)) {
     722    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
     723
     724    if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) {
    657725        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    658726        return false;
     
    835903
    836904    psMetadata *where = psMetadataAlloc();
    837     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     905    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    838906
    839907    psString query = pxDataGet("chiptool_pendingcleanuprun.sql");
     
    899967        PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
    900968    }
    901     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     969    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    902970
    903971    psString query = pxDataGet("chiptool_pendingcleanupimfile.sql");
     
    10271095
    10281096    psMetadata *where = psMetadataAlloc();
    1029     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1097    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    10301098    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
    10311099
     
    10881156
    10891157    psMetadata *where = psMetadataAlloc();
    1090     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1158    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    10911159
    10921160    // look for completed chipPendingExp
     
    12731341    char sqlFilename[80];
    12741342  } ExportTable;
    1275  
     1343
    12761344  int numExportTables = 3;
    12771345
    12781346  PS_ASSERT_PTR_NON_NULL(config, NULL);
    12791347
    1280   PXOPT_LOOKUP_S64(det_id, config->args, "-chip_id", true,  false);
     1348  PXOPT_LOOKUP_S64(dummy, config->args, "-chip_id", true,  false);
    12811349  PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
    12821350  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
     1351  PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     1352
    12831353
    12841354  FILE *f = fopen (outfile, "w");
     
    13311401    }
    13321402    if (!psArrayLength(output)) {
    1333       psTrace("regtool", PS_LOG_INFO, "no rows found");
     1403      psTrace("chiptool", PS_LOG_INFO, "no rows found");
    13341404      psFree(output);
    1335       return true;
     1405      return false;
     1406    }
     1407
     1408    if (clean) {
     1409        bool success = true;
     1410        if (!strcmp(tables[i].tableName, "chipRun")) {
     1411            success = pxSetStateCleaned("chipRun", "state", output);
     1412        } else if (!strcmp(tables[i].tableName, "chipProcessedImfile")) {
     1413            success = pxSetStateCleaned("chipProcessedImfile", "data_state", output);
     1414        }
     1415        if (!success) {
     1416            psFree(output);
     1417            psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s",  tables[i].tableName);
     1418            return false;
     1419        }
    13361420    }
    13371421
     
    13521436bool importrunMode(pxConfig *config)
    13531437{
    1354   unsigned int nFail;
    1355  
    1356   int numImportTables = 2;
    1357  
    1358   char tables[2] [80] = {"chipImfile", "chipProcessedImfile"};
    1359 
    1360   PS_ASSERT_PTR_NON_NULL(config, NULL);
    1361  
    1362   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
    1363 
    1364   psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    1365 
    1366   fprintf (stdout, "---- input ----\n");
    1367   psMetadataPrint (stderr, input, 1);
    1368 
    1369   psMetadataItem *item = psMetadataLookup (input, "chipRun");
    1370   psAssert (item, "entry not in input?");
    1371   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    1372 
    1373   psMetadataItem *entry = psListGet (item->data.list, 0);
    1374   assert (entry);
    1375   assert (entry->type == PS_DATA_METADATA);
    1376   chipRunRow *chipRun = chipRunObjectFromMetadata (entry->data.md);
    1377   chipRunInsertObject (config->dbh, chipRun);
    1378 
    1379   // fprintf (stdout, "---- chip run ----\n");
    1380   // psMetadataPrint (stderr, entry->data.md, 1);
    1381  
    1382   for (int i = 0; i < numImportTables; i++) {
    1383     psMetadataItem *item = psMetadataLookup (input, tables[i]);
    1384     psAssert (item, "entry not in input?");
    1385     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    1386  
    1387     switch (i) {
    1388       case 0:
    1389         for (int i = 0; i < item->data.list->n; i++) {
    1390           psMetadataItem *entry = psListGet (item->data.list, i);
    1391           assert (entry);
    1392           assert (entry->type == PS_DATA_METADATA);
    1393           chipImfileRow *chipImfile = chipImfileObjectFromMetadata (entry->data.md);
    1394           chipImfileInsertObject (config->dbh, chipImfile);
    1395 
    1396           // fprintf (stdout, "---- row %d ----\n", i);
    1397           // psMetadataPrint (stderr, entry->data.md, 1);
    1398         }
    1399         break;
    1400        
    1401       case 1:
    1402         for (int i = 0; i < item->data.list->n; i++) {
    1403           psMetadataItem *entry = psListGet (item->data.list, i);
    1404           assert (entry);
    1405           assert (entry->type == PS_DATA_METADATA);
    1406           chipProcessedImfileRow *chipProcessedImfile = chipProcessedImfileObjectFromMetadata (entry->data.md);
    1407           chipProcessedImfileInsertObject (config->dbh, chipProcessedImfile);
    1408 
    1409           // fprintf (stdout, "---- row %d ----\n", i);
    1410           // psMetadataPrint (stderr, entry->data.md, 1);
    1411         }
    1412         break;
    1413     }
    1414   }
    1415 
    1416   return true;
    1417 }
    1418 
    1419 
     1438    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1439
     1440    PXOPT_LOOKUP_STR(infile, config->args, "-infile", true, false);
     1441    unsigned int nFail = 0;               // Number of failed lines
     1442    psMetadata *input = psMetadataConfigRead(NULL, &nFail, infile, false);
     1443    if (nFail) {
     1444        psError(PS_ERR_IO, false, "%d failed lines in input", nFail);
     1445        psFree(input);
     1446        return false;
     1447    }
     1448
     1449    psVector *identifiers = psVectorAllocEmpty(16, PS_TYPE_U64); // Identifiers inserted
     1450
     1451    if (!psDBTransaction(config->dbh)) {
     1452        psError(PS_ERR_UNKNOWN, false, "database error");
     1453        return false;
     1454    }
     1455
     1456    psMetadataIterator *iter = psMetadataIteratorAlloc(input, PS_LIST_HEAD, NULL);       // Iterator
     1457    psMetadataItem *item;               // Item from iteration
     1458    while ((item = psMetadataGetAndIncrement(iter))) {
     1459        PXMIRROR_PRIMARY(item, "chipRun", chipRunRow, chipRunObjectFromMetadata, identifiers, chip_id,
     1460                         chipRunInsertObject, config->dbh,
     1461                         { psFree(iter); psFree(identifiers); psFree(input); });
     1462
     1463        PXMIRROR_OTHER(item, "chipImfile", chipImfileRow, chipImfileObjectFromMetadata, identifiers, chip_id,
     1464                       chipImfileInsertObject, config->dbh,
     1465                       { psFree(iter); psFree(identifiers); psFree(input); });
     1466
     1467        PXMIRROR_OTHER(item, "chipProcessedImfile", chipProcessedImfileRow,
     1468                       chipProcessedImfileObjectFromMetadata, identifiers, chip_id,
     1469                       chipProcessedImfileInsertObject, config->dbh,
     1470                       { psFree(iter); psFree(identifiers); psFree(input); });
     1471    }
     1472    psFree(iter);
     1473    psFree(input);
     1474
     1475    if (!psDBCommit(config->dbh)) {
     1476        psError(PS_ERR_UNKNOWN, false, "database error");
     1477        return false;
     1478    }
     1479
     1480    psLogMsg("chiptool", PS_LOG_INFO, "%ld chipRuns added", identifiers->n);
     1481    psFree(identifiers);
     1482
     1483    return true;
     1484}
Note: See TracChangeset for help on using the changeset viewer.