IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 1, 2014, 11:03:38 AM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20140206
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140206

  • branches/eam_branches/ipp-20140206/ippTools/src

    • Property svn:ignore
      •  

        old new  
        4848releasetool
        4949fftool
         50remotetool
         51
  • branches/eam_branches/ipp-20140206/ippTools/src/fftool.c

    r36441 r36627  
    4444static bool updatesummaryMode(pxConfig *config);
    4545static bool summaryMode(pxConfig *config);
     46static bool exportrunMode(pxConfig *config);
     47static bool importrunMode(pxConfig *config);
     48static bool summaryMode(pxConfig *config);
    4649
    4750static bool setfullForceRunState(pxConfig *config, psS64 sky_id, const char *state);
     
    7780        MODECASE(FFTOOL_MODE_UPDATESUMMARY,     updatesummaryMode);
    7881        MODECASE(FFTOOL_MODE_SUMMARY,           summaryMode);
     82        MODECASE(FFTOOL_MODE_EXPORTRUN,         exportrunMode);
     83        MODECASE(FFTOOL_MODE_IMPORTRUN,         importrunMode);
    7984        default:
    8085            psAbort("invalid option (this should not happen)");
     
    134139
    135140    psMetadata *warpWhereMD = psMetadataAlloc();
    136     pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_label",     "warpRun.label",           "LIKE");
    137     pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_data_group","warpRun.data_group",      "LIKE");
    138     PXOPT_COPY_S64(config->args, warpWhereMD, "-select_warp_id",        "warpRun.warp_id",         "==");
     141    pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_label",     "fullForceRun.label",           "LIKE");
     142    pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_data_group","fullForceRun.data_group",      "LIKE");
     143    PXOPT_COPY_S64(config->args, warpWhereMD, "-select_warp_id",        "fullForceRun.warp_id",         "==");
    139144    if (!psListLength(warpWhereMD->list)) {
    140145        psError(PXTOOLS_ERR_CONFIG, false, "warp search parameters are required");
     
    150155    }
    151156
    152     PXOPT_COPY_STR(config->args, warpWhereMD, "-select_tess_id",       "warpRun.tess_id",         "==");
    153     pxAddLabelSearchArgs(config, warpWhereMD, "-select_filter",        "warpRun.filter",          "LIKE");
     157    PXOPT_COPY_STR(config->args, warpWhereMD, "-select_tess_id",       "fullForceRun.tess_id",         "==");
     158    pxAddLabelSearchArgs(config, warpWhereMD, "-select_filter",        "fullForceRun.filter",          "LIKE");
    154159    if (!pxskycellAddWhere(config, warpWhereMD)) {
    155160        psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");
     
    175180    psString whereClause = psDBGenerateWhereConditionSQL(skycalWhereMD, NULL);
    176181    psStringAppend(&where, "\nAND %s", whereClause);
    177     psStringAppend(&select, where);
     182    psStringAppend(&select, " %s", where);
    178183    psFree(whereClause);
    179184    psFree(skycalWhereMD);
     
    504509    PXOPT_COPY_STR(config->args, where, "-tess_id",    "stackRun.tess_id", "LIKE");
    505510    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     511    PXOPT_COPY_STR(config->args, where, "-filter",      "stackRun.filter", "LIKE");
    506512    PXOPT_COPY_S16(config->args, where, "-fault",      "staticskyResult.fault", "==");
    507513    pxskycellAddWhere(config, where);
     
    864870    PXOPT_COPY_STR(config->args, where, "-tess_id",    "stackRun.tess_id", "LIKE");
    865871    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     872    PXOPT_COPY_STR(config->args, where, "-filter",     "stackRun.filter", "LIKE");
    866873    PXOPT_COPY_S16(config->args, where, "-fault",      "staticskyResult.fault", "==");
    867874    pxskycellAddWhere(config, where);
     
    933940    return true;
    934941}
     942
     943bool exportrunMode(pxConfig *config)
     944{
     945  typedef struct ExportTable {
     946    char tableName[80];
     947    char sqlFilename[80];
     948  } ExportTable;
     949
     950    PS_ASSERT_PTR_NON_NULL(config, NULL);
     951
     952    // PXOPT_LOOKUP_S64(det_id,  config->args, "-warp_id", true,  false);
     953    PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
     954    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
     955//    PXOPT_LOOKUP_BOOL(clean,  config->args, "-clean", false);
     956
     957    FILE *f = fopen (outfile, "w");
     958    if (f == NULL) {
     959        psError(PS_ERR_UNKNOWN, false, "failed to open output file");
     960        return false;
     961    }
     962
     963    if (!pxExportVersion(config, f)) {
     964        psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     965        return false;
     966    }
     967    psMetadata *where = psMetadataAlloc();
     968    PXOPT_COPY_S64(config->args, where, "-ff_id", "ff_id", "==");
     969
     970    ExportTable tables [] = {
     971      {"fullForceRun", "fftool_export_run.sql"},
     972      {"fullForceInput", "fftool_export_input.sql"},
     973      {"fullForceResult", "fftool_export_result.sql"},
     974      {"fullForceSummary", "fftool_export_summary.sql"},
     975    };
     976
     977    int numTables = sizeof(tables)/sizeof(tables[0]);
     978
     979    for (int i=0; i < numTables; i++) {
     980      psString query = pxDataGet(tables[i].sqlFilename);
     981      if (!query) {
     982          psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     983          return false;
     984      }
     985
     986      if (where && psListLength(where->list)) {
     987          psString whereClause = psDBGenerateWhereSQL(where, NULL);
     988          psStringAppend(&query, " %s", whereClause);
     989          psFree(whereClause);
     990      }
     991
     992      // treat limit == 0 as "no limit"
     993      if (limit) {
     994        psString limitString = psDBGenerateLimitSQL(limit);
     995        psStringAppend(&query, " %s", limitString);
     996        psFree(limitString);
     997      }
     998
     999      if (!p_psDBRunQuery(config->dbh, query)) {
     1000        psError(PS_ERR_UNKNOWN, false, "database error");
     1001        psFree(query);
     1002        return false;
     1003      }
     1004      psFree(query);
     1005
     1006      psArray *output = p_psDBFetchResult(config->dbh);
     1007      if (!output) {
     1008          psError(PS_ERR_UNKNOWN, false, "database error");
     1009          return false;
     1010      }
     1011      if (!psArrayLength(output)) {
     1012        psError(PS_ERR_UNKNOWN, true, "no rows found");
     1013        psFree(output);
     1014        return false;
     1015      }
     1016
     1017      // we must write the export table in non-simple (true) format
     1018      if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
     1019        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1020        psFree(output);
     1021        return false;
     1022      }
     1023      psFree(output);
     1024    }
     1025
     1026    fclose (f);
     1027
     1028    return true;
     1029}
     1030
     1031bool importrunMode(pxConfig *config)
     1032{
     1033  unsigned int nFail;
     1034
     1035  int numImportTables = 3;
     1036
     1037  char tables[3] [80] = {"fullForceInput", "fullForceResult", "fullForceSummary"};
     1038
     1039  PS_ASSERT_PTR_NON_NULL(config, NULL);
     1040
     1041  PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
     1042
     1043  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
     1044
     1045#ifdef notdef
     1046  fprintf (stderr, "---- input ----\n");
     1047  psMetadataPrint (stderr, input, 1);
     1048#endif
     1049
     1050  if (!pxCheckImportVersion(config, input)) {
     1051      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     1052      return false;
     1053  }
     1054
     1055  psMetadataItem *item = psMetadataLookup (input, "fullForceRun");
     1056  psAssert (item, "entry not in input?");
     1057  psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
     1058
     1059  psMetadataItem *entry = psListGet (item->data.list, 0);
     1060  assert (entry);
     1061  assert (entry->type == PS_DATA_METADATA);
     1062  fullForceRunRow *fullForceRun = fullForceRunObjectFromMetadata (entry->data.md);
     1063  fullForceRunInsertObject (config->dbh, fullForceRun);
     1064
     1065  // fprintf (stdout, "---- warp run ----\n");
     1066  // psMetadataPrint (stderr, entry->data.md, 1);
     1067
     1068  for (int i = 0; i < numImportTables; i++) {
     1069    item = psMetadataLookup (input, tables[i]);
     1070    psAssert (item, "entry not in input?");
     1071    psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
     1072
     1073    switch (i) {
     1074      case 0:
     1075        for (int i = 0; i < item->data.list->n; i++) {
     1076          entry = psListGet (item->data.list, i);
     1077          assert (entry);
     1078          assert (entry->type == PS_DATA_METADATA);
     1079          fullForceInputRow *fullForceInput = fullForceInputObjectFromMetadata (entry->data.md);
     1080          fullForceInputInsertObject (config->dbh, fullForceInput);
     1081
     1082          // fprintf (stdout, "---- row %d ----\n", i);
     1083          // psMetadataPrint (stderr, entry->data.md, 1);
     1084        }
     1085        break;
     1086
     1087      case 1:
     1088        for (int i = 0; i < item->data.list->n; i++) {
     1089          entry = psListGet (item->data.list, i);
     1090          assert (entry);
     1091          assert (entry->type == PS_DATA_METADATA);
     1092          fullForceResultRow *fullForceResult = fullForceResultObjectFromMetadata (entry->data.md);
     1093          fullForceResultInsertObject (config->dbh, fullForceResult);
     1094
     1095          // fprintf (stdout, "---- row %d ----\n", i);
     1096          // psMetadataPrint (stderr, entry->data.md, 1);
     1097        }
     1098        break;
     1099
     1100      case 2:
     1101        for (int i = 0; i < item->data.list->n; i++) {
     1102          entry = psListGet (item->data.list, i);
     1103          assert (entry);
     1104          assert (entry->type == PS_DATA_METADATA);
     1105          fullForceSummaryRow *fullForceSummary = fullForceSummaryObjectFromMetadata (entry->data.md);
     1106          fullForceSummaryInsertObject (config->dbh, fullForceSummary);
     1107
     1108          // fprintf (stdout, "---- row %d ----\n", i);
     1109          // psMetadataPrint (stderr, entry->data.md, 1);
     1110        }
     1111        break;
     1112    }
     1113  }
     1114  return true;
     1115}
Note: See TracChangeset for help on using the changeset viewer.