IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35960


Ignore:
Timestamp:
Aug 15, 2013, 4:05:13 PM (13 years ago)
Author:
bills
Message:

various changes for support of distribution of skycal results

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/dist_advancerun.pl

    r31565 r35960  
    115115    $list_mode = "-result";
    116116    $component_key = "skycell_id";
     117} elsif ($stage eq "skycal") {
     118    $tool_cmd = "$staticskytool -skycal_id";
     119    $list_mode = "-skycalresult";
     120    $component_key = "skycell_id";
    117121} elsif ($stage eq "diff") {
    118122    $tool_cmd = "$difftool -diff_id";
     
    134138} elsif ($stage eq 'warp_bg') {
    135139    $exportarg = '-exportwarp';
     140} elsif ($stage eq 'skycal') {
     141    $exportarg = '-exportskycalrun';
    136142}
    137143
  • trunk/ippTools/share/Makefile.am

    r35955 r35960  
    410410        staticskytool_export_input.sql \
    411411        staticskytool_export_result.sql \
     412        staticskytool_export_skycalrun.sql \
     413        staticskytool_export_skycalresult.sql \
    412414        staticskytool_inputs.sql \
    413415        staticskytool_todo.sql \
  • trunk/ippTools/share/disttool_pending_skycal.sql

    r35955 r35960  
    3838JOIN chipRun
    3939    USING(chip_id)
    40     -- ON camRun.chip_id = chipRun.chip_id
    4140JOIN rawExp
    4241     USING (exp_id)
  • trunk/ippTools/share/disttool_toadvance.sql

    r32710 r35960  
    262262        AND distComponent.fault = 0
    263263UNION
     264-- skycal stage
     265-- NOTE this assumes that there is only one component per skycalRun
     266-- (one skycell)
     267SELECT
     268    distRun.dist_id,
     269    stage,
     270    stage_id,
     271    outroot,
     272    label,
     273    clean
     274    FROM distRun
     275    JOIN skycalResult on stage_id = skycal_id
     276    LEFT JOIN distComponent
     277        ON distRun.dist_id = distComponent.dist_id
     278    WHERE
     279        distRun.state = 'new'
     280        AND distRun.fault = 0
     281        AND distRun.stage = 'skycal'
     282        AND distComponent.component IS NOT NULL
     283        AND distComponent.fault = 0
     284UNION
    264285-- SSdiff stage
    265286SELECT
  • trunk/ippTools/share/staticskytool_skycalresult.sql

    r35952 r35960  
    22    skycalResult.*,
    33    skycalRun.stack_id,
     4    skycalRun.workdir,
    45    stackRun.filter,
    56    skycalRun.state,
  • trunk/ippTools/src/staticskytool.c

    r35194 r35960  
    5050static bool revertskycalresultMode(pxConfig *config);
    5151static bool updateskycalresultMode(pxConfig *config);
     52static bool exportskycalrunMode(pxConfig *config);
     53static bool importskycalrunMode(pxConfig *config);
    5254
    5355static bool setstaticskyRunState(pxConfig *config, psS64 sky_id, const char *state);
     
    8890        MODECASE(STATICSKYTOOL_MODE_REVERTSKYCALRESULT,revertskycalresultMode);
    8991        MODECASE(STATICSKYTOOL_MODE_SKYCALRESULT,      skycalresultMode);
     92        MODECASE(STATICSKYTOOL_MODE_EXPORTSKYCALRUN,   exportskycalrunMode);
     93        MODECASE(STATICSKYTOOL_MODE_IMPORTSKYCALRUN,   importskycalrunMode);
    9094        default:
    9195            psAbort("invalid option (this should not happen)");
     
    895899bool importrunMode(pxConfig *config)
    896900{
    897 # if (0)
    898   unsigned int nFail;
    899 
    900   int numImportTables = 2;
    901 
    902   char tables[2] [80] = {"stackInputSkyfile", "stackSumSkyfile"};
     901  return false;
     902}
     903
     904bool exportskycalrunMode(pxConfig *config)
     905{
     906  typedef struct ExportTable {
     907    char tableName[80];
     908    char sqlFilename[80];
     909  } ExportTable;
     910
     911  int numExportTables = 2;
    903912
    904913  PS_ASSERT_PTR_NON_NULL(config, NULL);
    905914
    906   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
    907 
    908   psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    909 
    910 #ifdef notdef
    911   fprintf (stderr, "---- input ----\n");
    912   psMetadataPrint (stderr, input, 1);
    913 #endif
    914 
    915   if (!pxCheckImportVersion(config, input)) {
    916       psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     915  // XXX unused PXOPT_LOOKUP_S64(det_id, config->args, "-sky_id", true,  false);
     916  PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
     917  PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     918  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
     919
     920  FILE *f = fopen (outfile, "w");
     921  if (f == NULL) {
     922      psError(PS_ERR_UNKNOWN, false, "failed to open output file");
    917923      return false;
    918924  }
    919   psMetadataItem *item = psMetadataLookup (input, "stackRun");
    920   psAssert (item, "entry not in input?");
    921   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    922 
    923   psMetadataItem *entry = psListGet (item->data.list, 0);
    924   assert (entry);
    925   assert (entry->type == PS_DATA_METADATA);
    926   stackRunRow *stackRun = stackRunObjectFromMetadata (entry->data.md);
    927   stackRunInsertObject (config->dbh, stackRun);
    928 
    929   // fprintf (stdout, "---- stack run ----\n");
    930   // psMetadataPrint (stderr, entry->data.md, 1);
    931 
    932   for (int i = 0; i < numImportTables; i++) {
    933     psMetadataItem *item = psMetadataLookup (input, tables[i]);
    934     psAssert (item, "entry not in input?");
    935     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    936 
    937     switch (i) {
    938       case 0:
    939         for (int i = 0; i < item->data.list->n; i++) {
    940           entry = psListGet (item->data.list, i);
    941           assert (entry);
    942           assert (entry->type == PS_DATA_METADATA);
    943           stackInputSkyfileRow *stackInputSkyfile = stackInputSkyfileObjectFromMetadata (entry->data.md);
    944           stackInputSkyfileInsertObject (config->dbh, stackInputSkyfile);
    945 
    946           // fprintf (stdout, "---- row %d ----\n", i);
    947           // psMetadataPrint (stderr, entry->data.md, 1);
    948         }
    949         break;
    950 
    951       case 1:
    952         for (int i = 0; i < item->data.list->n; i++) {
    953           entry = psListGet (item->data.list, i);
    954           assert (entry);
    955           assert (entry->type == PS_DATA_METADATA);
    956           stackSumSkyfileRow *stackSumSkyfile = stackSumSkyfileObjectFromMetadata (entry->data.md);
    957           stackSumSkyfileInsertObject (config->dbh, stackSumSkyfile);
    958 
    959           // fprintf (stdout, "---- row %d ----\n", i);
    960           // psMetadataPrint (stderr, entry->data.md, 1);
    961         }
    962         break;
    963     }
     925
     926  if (!pxExportVersion(config, f)) {
     927    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     928    return false;
    964929  }
    965 
    966 # endif
    967   return true;
     930  psMetadata *where = psMetadataAlloc();
     931  PXOPT_COPY_S64(config->args, where, "-skycal_id", "skycal_id", "==");
     932
     933  ExportTable tables [] = {
     934    {"skycalRun", "staticskytool_export_skycalrun.sql"},
     935    {"skycalResult", "staticskytool_export_skycalresult.sql"},
     936  };
     937
     938  for (int i=0; i < numExportTables; i++) {
     939    psString query = pxDataGet(tables[i].sqlFilename);
     940    if (!query) {
     941      psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     942      return false;
     943    }
     944
     945    if (where && psListLength(where->list)) {
     946      psString whereClause = psDBGenerateWhereSQL(where, NULL);
     947      psStringAppend(&query, " %s", whereClause);
     948      psFree(whereClause);
     949    }
     950
     951    // treat limit == 0 as "no limit"
     952    if (limit) {
     953      psString limitString = psDBGenerateLimitSQL(limit);
     954      psStringAppend(&query, " %s", limitString);
     955      psFree(limitString);
     956    }
     957
     958    if (!p_psDBRunQuery(config->dbh, query)) {
     959      psError(PS_ERR_UNKNOWN, false, "database error");
     960      psFree(query);
     961      return false;
     962    }
     963    psFree(query);
     964
     965    psArray *output = p_psDBFetchResult(config->dbh);
     966    if (!output) {
     967      psError(PS_ERR_UNKNOWN, false, "database error");
     968      return false;
     969    }
     970    if (!psArrayLength(output)) {
     971      psError(PS_ERR_UNKNOWN, true, "no rows found");
     972      psFree(output);
     973      return false;
     974    }
     975
     976    if (clean) {
     977        if (!strcmp(tables[i].tableName, "skycalRun")) {
     978            if (!pxSetStateCleaned("skycalRun", "state", output)) {
     979                psFree(output);
     980                psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s",  tables[i].tableName);
     981                return false;
     982            }
     983        }
     984    }
     985
     986      // we must write the export table in non-simple (true) format
     987    if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
     988        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     989        psFree(output);
     990        return false;
     991    }
     992
     993    psFree(output);
     994  }
     995
     996    fclose (f);
     997
     998    return true;
     999}
     1000
     1001bool importskycalrunMode(pxConfig *config)
     1002{
     1003  return false;
    9681004}
    9691005
     
    9861022
    9871023}
    988 
    989 # if (0)
    990         // now we need to loop over all requested filters and check that each is found
    991         // XXX is this needed?  haven't we required that we only match the requested filters
    992         // and that N unique filters are found?
    993 
    994         psVector *found = psVectorAlloc(inputs->n, PS_TYPE_U8);
    995         psVectorInit (found, 0);
    996 
    997         psMetadataItem *filter = NULL;
    998         psListIterator *iter = psListIteratorAlloc (filters->data.list, PS_LIST_HEAD, false);
    999         while ((filter = psListGetAndIncrement(iter))) {
    1000 
    1001             bool foundOne = false;
    1002 
    1003             psAssert (filter->type == PS_DATA_STR, "filter is not a string?");
    1004             for (int j = 0; !foundOne && (j < inputs->n); j++) {
    1005                 if (found->data.U8[j]) continue;
    1006                 psMetadata *inputRow = inputs->data[j]; // Row from select
    1007 
    1008                 // pull out the skycell_id, tess_id, filter
    1009                 psString inFilter = psMetadataLookupStr(&status, row, "filter");
    1010                 psAssert (status);
    1011 
    1012                 found->data.U8[j] = true;
    1013                 foundOne = true;
    1014             }
    1015             if (!foundOne) {
    1016                 // this required filter was not found in the inputs, skip the entry
    1017                 skip();
    1018             }
    1019         }           
    1020 # endif
    10211024
    10221025static bool defineskycalrunMode(pxConfig *config)
  • trunk/ippTools/src/staticskytool.h

    r32960 r35960  
    4343    STATICSKYTOOL_MODE_SKYCALRESULT,
    4444    STATICSKYTOOL_MODE_REVERTSKYCALRESULT,
     45    STATICSKYTOOL_MODE_EXPORTSKYCALRUN,
     46    STATICSKYTOOL_MODE_IMPORTSKYCALRUN,
    4547} staticskytoolMode;
    4648
  • trunk/ippTools/src/staticskytoolConfig.c

    r35197 r35960  
    269269    psMetadataAddBool(skycalresultArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
    270270
     271    // -exportskycalrun
     272    psMetadata *exportskycalrunArgs = psMetadataAlloc();
     273    psMetadataAddS64(exportskycalrunArgs, PS_LIST_TAIL, "-skycal_id", 0, "export this skycal ID (required)", 0);
     274    psMetadataAddStr(exportskycalrunArgs, PS_LIST_TAIL, "-outfile", 0, "export to this file (required)", NULL);
     275    psMetadataAddU64(exportskycalrunArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
     276    psMetadataAddBool(exportskycalrunArgs, PS_LIST_TAIL, "-clean", 0, "mark tables as cleaned", false);
     277
     278    // -importrun
     279    psMetadata *importskycalrunArgs = psMetadataAlloc();
     280    psMetadataAddStr(importskycalrunArgs, PS_LIST_TAIL, "-infile", 0, "import from this file (required)", NULL);
     281 
     282
    271283    psFree(now);
    272284
     
    291303    PXOPT_ADD_MODE("-updateskycal",  "revert faulted skycal run", STATICSKYTOOL_MODE_UPDATESKYCALRESULT, updateskycalresultArgs);
    292304    PXOPT_ADD_MODE("-skycalresult",  "Get result of skycal run",  STATICSKYTOOL_MODE_SKYCALRESULT, skycalresultArgs);
     305    PXOPT_ADD_MODE("-exportskycalrun",     "Export skycal run",   STATICSKYTOOL_MODE_EXPORTSKYCALRUN, exportskycalrunArgs);
     306    PXOPT_ADD_MODE("-importskycalrun",     "Import skycal run",   STATICSKYTOOL_MODE_IMPORTSKYCALRUN, importskycalrunArgs);
    293307
    294308    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Note: See TracChangeset for help on using the changeset viewer.