IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 5, 2012, 5:19:48 PM (14 years ago)
Author:
mhuber
Message:

merging latest r33407 trunk changes to meh_branches/ppstack_test

Location:
branches/meh_branches/ppstack_test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/ippTools/src

  • branches/meh_branches/ppstack_test/ippTools/src/addtool.c

    r31680 r33415  
    143143    pxAddLabelSearchArgs (config, where, "-filter",     "stackRun.filter", "=="); // define using camRun label
    144144    }
    145    
     145        if (strcmp(stage, "staticsky_multi")== 0) {
     146
     147    pxAddLabelSearchArgs (config, where, "-label",     "staticskyRun.label", "=="); // define using camRun label
     148    pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label
     149    PXOPT_COPY_STR(config->args, where,  "-reduction", "staticskyyRun.reduction", "==");
     150    //no filter here
     151    }
    146152    if (!psListLength(where->list)) {
    147153        psFree(where);
     
    237243    }
    238244
    239 
     245    if (strcmp(stage,"staticsky_multi") == 0) {
     246      if (dvodb ) {
     247        psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_multi_dvo.sql\n%s\n", dvodb,stage);
     248        // find the cam_id of all the exposures that we want to queue up.
     249        bare_query = pxDataGet("addtool_find_sky_id_multi_dvo.sql");
     250        // user supplied dvodb
     251        psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
     252    } else {
     253      psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_sky_id_multi.sql\n%s\n",stage);
     254        // find the cam_id of all the exposures that we want to queue up.
     255        bare_query = pxDataGet("addtool_find_sky_id_multi.sql");
     256        // inherit dvodb from camRun, avoid matching NULL
     257        psStringAppend(&dvodb_string, "(staticskyRun.dvodb IS NOT NULL AND previous_dvodb = staticskyRun.dvodb)");
     258    }
     259    }
    240260
    241261    if (!bare_query) {
     
    272292    } else {
    273293      //This picks only the unmagicked/uncensored ones
    274       if (strcmp(stage,"cam") == 0) {
    275         psStringAppend(&query, " AND (camRun.magicked = 0)");
    276       }
     294      //if (strcmp(stage,"cam") == 0) {
     295        //we can now properly handle the magicked case in ippScripts, so we queue camRuns in any magic state now if -uncensored.
     296        //psStringAppend(&query, " AND (camRun.magicked = 0)");
     297        //}
    277298      if (strcmp(stage,"stack") == 0) {
    278299        psStringAppend(&query, " AND (stackRun.magicked = 0)");
     
    280301
    281302    }
     303
     304    //if we grab a group of camRun/stackRuns that have multiple camRun/stackRun pointing to the same exp_id/stack_id, and that exp_id/stack_id has never before been added to addRun, we need to group by exp_id/stack_id to ensure that only 1 of the camRun/stackRun for that exp_id is added to the addRun stage.
     305
     306    if (strcmp(stage,"cam") == 0) {
     307        psStringAppend(&query, " GROUP BY exp_id");
     308   }
     309      if (strcmp(stage,"stack") == 0) {
     310        psStringAppend(&query, " GROUP BY stack_id");
     311      }
     312    if (strcmp(stage,"staticsky") == 0) {
     313        psStringAppend(&query, " GROUP BY stack_id");
     314      }
     315    if (strcmp(stage,"staticsky_multi") == 0) {
     316      psStringAppend(&query, " GROUP BY sky_id");  //some reason it needs this
     317      }
     318
    282319
    283320    psTrace("addtool.c", PS_LOG_INFO,"query: \n\n%s\n\n",query);
     
    391428    }
    392429    }
     430    if (strcmp(stage,"staticsky_multi") == 0) {
     431    for (long i = 0; i < psArrayLength(output); i++) {
     432        psMetadata *md = output->data[i];
     433        bool status = false;
     434        psS32 num_inputs = psMetadataLookupS32(&status, md, "num_inputs");
     435        if (!status) {
     436          psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item num_inputs");
     437          return false;
     438        }
     439        if (num_inputs < 0) {
     440          psError(PS_ERR_UNKNOWN, true, "invalid value for num_inputs");
     441          return false;
     442        }
     443
     444        staticskyRunRow *row = staticskyRunObjectFromMetadata(md);
     445       
     446        if (!row) {
     447            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
     448            psFree(output);
     449            return false;
     450        }
     451
     452        if (!dvodb) {  //there's no staticsky.dvodb
     453            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id);
     454            psFree(output);
     455            return false;
     456        }
     457        if (!workdir && !row->workdir) {
     458            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id);
     459            psFree(output);
     460            return false;
     461        }
     462
     463        psFree(row);
     464    }
     465    }
     466
     467
     468
    393469
    394470    // start a transaction so we don't end up with an exp without any associted
     
    424500                               stage,
    425501                               stage_id,
     502                               0,
    426503                               workdir     ? workdir   : row->workdir,
    427504                               reduction   ? reduction : row->reduction,
     
    465542                               stage,
    466543                               stage_id,
     544                               0,
    467545                               workdir     ? workdir   : row->workdir,
    468546                               reduction   ? reduction : row->reduction,
     
    506584                               stage,
    507585                               stage_id,
     586                               0,
    508587                               workdir     ? workdir   : row->workdir,
    509588                               reduction   ? reduction : row->reduction,
     
    530609      }
    531610
     611    if (strcmp(stage,"staticsky_multi") == 0) {
     612    for (long i = 0; i < psArrayLength(output); i++) {
     613        psMetadata *md = output->data[i];
     614        psS64 stage_id =0;
     615        bool status = false;
     616        psS32 num_inputs = psMetadataLookupS32(&status, md, "num_inputs");
     617        if (!status) {
     618          psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item num_inputs");
     619          return false;
     620        }
     621        staticskyRunRow *row = staticskyRunObjectFromMetadata(md);
     622        stage_id = row->sky_id;
     623       
     624        if (!row) {
     625            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
     626            psFree(output);
     627            return false;
     628        }
     629
     630        // queue the exp
     631        for (int filter_id = 0; filter_id < num_inputs; filter_id++) { 
     632        if (!pxaddQueueByCamID(config,
     633                               stage,
     634                               stage_id,
     635                               filter_id,
     636                               workdir     ? workdir   : row->workdir,
     637                               reduction   ? reduction : row->reduction,
     638                               label       ? label     : row->label,
     639                               data_group  ? data_group : (row->data_group ? row->data_group :  (label ? label : row->label)),
     640                               dvodb       ? dvodb     : NULL,
     641                               note        ? note      : NULL,
     642                               image_only,
     643                               minidvodb,
     644                               minidvodb_group,
     645                               minidvodb_name
     646        )) {
     647            if (!psDBRollback(config->dbh)) {
     648                psError(PS_ERR_UNKNOWN, false, "database error sfg");
     649            }
     650            psError(PS_ERR_UNKNOWN, false,
     651                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
     652            psFree(row);
     653            psFree(output);
     654            return false;
     655        }
     656        }
     657        psFree(row);
     658    }
     659      }
     660
     661
     662
     663
    532664    psFree(output);
    533665
     
    571703    }
    572704    if (strcmp(stage, "staticsky")==0) {
     705    query = psStringCopy("UPDATE addRun JOIN staticskyRun on sky_id = stage_id");
     706    }
     707    if (strcmp(stage, "staticsky_multi")==0) {
    573708    query = psStringCopy("UPDATE addRun JOIN staticskyRun on sky_id = stage_id");
    574709    }
     
    612747    query = pxDataGet("addtool_find_pendingexp_staticsky.sql");
    613748    }
    614 
     749    if (strcmp(stage, "staticsky_multi")==0) {
     750    query = pxDataGet("addtool_find_pendingexp_staticsky_multi.sql");
     751    }
     752   
    615753
    616754    if (!query) {
     
    634772      psStringAppend(&query, " GROUP BY %s", "sky_id");
    635773    }
    636 
     774    if (strcmp(stage, "staticsky_multi") == 0) {
     775      //this group by is needed to join against all the warps (to get camera)
     776      psStringAppend(&query, " GROUP BY %s", "sky_id, stage_extra1");
     777    }
    637778    // treat limit == 0 as "no limit"
    638779    if (limit) {
     
    684825    PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-minidvodb_name", false, false);
    685826    PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
    686 
     827    PXOPT_LOOKUP_S64(stage_extra1, config->args, "-stage_extra1", false, false);
    687828    // generate restrictions
    688829    psMetadata *where = psMetadataAlloc();
     
    762903      }
    763904    }
    764 
     905    //if there is a stage_extra1, set it in addRun (it's not known until it is processed)
     906    if (stage_extra1) {
     907      psString setExtra = NULL;
     908      psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1);
     909      psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id);
     910
     911      if (!p_psDBRunQuery(config->dbh, setExtra)) {
     912        if (!psDBRollback(config->dbh)) {
     913          psError(PS_ERR_UNKNOWN, false, "database error");
     914        }
     915        psError(PS_ERR_UNKNOWN, false, "database error");
     916
     917        return false;
     918      }
     919    }
    765920
    766921
     
    824979    query = pxDataGet("addtool_find_processedexp_staticsky.sql");
    825980    }
     981    if (strcmp (stage,"staticsky_multi") == 0) {
     982    query = pxDataGet("addtool_find_processedexp_staticsky_multi.sql");
     983    }
     984
    826985   
    827986    if (!query) {
     
    9051064    PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",         "==");
    9061065    PXOPT_COPY_S64(config->args, where, "-stage_id",    "addRun.stage_id",         "==");
    907     PXOPT_LOOKUP_STR(stage,       config->args, "-stage", false, false);
     1066    PXOPT_LOOKUP_STR(stage,       config->args, "-stage", true, false);
    9081067    pxcamGetSearchArgs (config, where);
    9091068    pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     
    9341093         query = pxDataGet("addtool_revertprocessedexp_staticsky.sql");
    9351094      }
     1095   if (strcmp(stage, "staticsky_multi") == 0) {
     1096         query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql");
     1097      }
     1098
     1099
     1100     
    9361101      if (!query) {
    9371102            // rollback
     
    10711236
    10721237  PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false);
    1073   PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-set_mergedvodb_path", true, false);
    1074 
    1075   //optional
     1238    //optional
    10761239  PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false);
    10771240  PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false);
     
    10881251  if (minidvodb_path) {
    10891252    minidvodbpath = minidvodb_path;
     1253  } else {
     1254    psError(PS_ERR_UNKNOWN, false, "require minidvodb_path");
     1255    return false;
    10901256  }
    10911257
     
    10951261            minidvodb_group,
    10961262            minidvodbpath,
    1097             mergedvodb_path,
    1098             "new",
     1263            "new",
    10991264            0
    11001265            )) {
     
    11181283    psStringAppend(&minidvodb_name, "%s.%" PRIu64,minidvodb_group,minidvodb_id);
    11191284  }
    1120 
    1121   if (!minidvodb_path) {
    1122     psStringAppend(&minidvodb_path,"%s/%s",mergedvodb_path,minidvodb_name);
    1123   }
    1124 
    11251285  if (minidvodb_path) {
    11261286    psStringAppend(&minidvodb_path,"/%s",minidvodb_name);
     
    11541314    PXOPT_COPY_STR(config->args, where, "-state",     "state", "==");
    11551315    PXOPT_COPY_STR(config->args, where, "-minidvodb_path", "minidvodb_path", "==");
    1156     PXOPT_COPY_STR(config->args, where, "-mergedvodb_path", "mergedvodb_path", "==");
    11571316    PXOPT_COPY_STR(config->args, where, "-minidvodb_group",     "minidvodb_group", "==");
    11581317
     
    11601319    PXOPT_LOOKUP_STR(minidvodb_path,  config->args, "-set_minidvodb_path", false, false);
    11611320    PXOPT_LOOKUP_STR(state,  config->args, "-set_state", false, false);
    1162     PXOPT_LOOKUP_STR(mergedvodb_path,  config->args, "-set_mergedvodb_path", false, false);
    11631321    PXOPT_LOOKUP_STR(minidvodb_group,  config->args, "-set_minidvodb_group", false, false);
    11641322
     
    11951353    }
    11961354
    1197     if (mergedvodb_path) {
    1198       if (cnt) {
    1199         psStringAppend(&query, "%s", comma);
    1200       }
    1201       psStringAppend(&query, " mergedvodb_path = '%s'", mergedvodb_path);
    1202       cnt++;
    1203     }
    1204 
    12051355    if (minidvodb_group) {
    12061356      if (cnt) {
     
    12461396  }
    12471397
    1248   psString firstquery = psStringCopy("SELECT * from  minidvodbRun where state = 'new' and minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL and mergedvodb_path IS NOT NULL");
     1398  psString firstquery = psStringCopy("SELECT * from  minidvodbRun where state = 'new' and minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL");
    12491399
    12501400  psString firstwhereClause = psDBGenerateWhereConditionSQL(where, NULL);
     
    12941444
    12951445  //now flip new -> active
    1296   psString query2 = psStringCopy("UPDATE minidvodbRun SET state = 'active' WHERE state = 'new' AND minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL and mergedvodb_path IS NOT NULL ");
     1446  psString query2 = psStringCopy("UPDATE minidvodbRun SET state = 'active' WHERE state = 'new' AND minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL ");
    12971447  psStringAppend(&query2, " AND minidvodb_group = '%s' limit 1;", minidvodb_group);
    12981448  if (!p_psDBRunQuery(config->dbh, query2)) {
     
    14711621    // required
    14721622  PXOPT_LOOKUP_U64(minidvodb_id, config->args, "-minidvodb_id", true, false);
    1473   PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-mergedvodb_path", true, false);
    14741623  PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-minidvodb_group", true, false);
    14751624
    14761625    // optional
    1477   PXOPT_LOOKUP_U64(merge_order,     config->args, "-merge_order", false, false);
    14781626  PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-dtime_relphot", false, false);
    14791627  PXOPT_LOOKUP_F32(dtime_resort, config->args, "-dtime_resort", false, false);
    1480   PXOPT_LOOKUP_F32(dtime_merge, config->args, "-dtime_merge", false, false);
    1481   PXOPT_LOOKUP_F32(dtime_verify, config->args, "-dtime_verify", false, false);
    14821628  PXOPT_LOOKUP_F32(dtime_script, config->args, "-dtime_script", false, false);
    14831629 
     
    15301676  minidvodbProcessedRow *row = minidvodbProcessedRowAlloc(
    15311677               pendingRow->minidvodb_id,
    1532                merge_order,
    15331678               dtime_resort,
    15341679               dtime_relphot,
    1535                dtime_verify,
    1536                dtime_merge,
    15371680               dtime_script,
    15381681               epoch,
    1539                mergedvodb_path,
    15401682               fault
    15411683               );
     
    15521694  }
    15531695
    1554 
    1555 
    1556 
    1557   //this finds the # of merged things (for the merge order)
    1558   psString query3 = NULL;
    1559   psStringAppend(&query3, "select count(*) from minidvodbRun join minidvodbProcessed using (minidvodb_id) where state = 'merged' and minidvodb_group = '%s';", minidvodb_group);
    1560 
    1561   if (!p_psDBRunQuery(config->dbh, query3)) {
    1562     // rollback
    1563     if (!psDBRollback(config->dbh)) {
    1564       psError(PS_ERR_UNKNOWN, false, "database error");
    1565     }
    1566     psError(PS_ERR_UNKNOWN, false, "database error");
    1567     psFree(query3);
    1568     return false;
    1569   }
    1570   psArray *output2 = p_psDBFetchResult(config->dbh);
    1571   if (!output2) {
    1572     psError(PS_ERR_UNKNOWN, false, "database error");
    1573     return false;
    1574   }
    1575   if (!psArrayLength(output2)) {
    1576     psTrace("addtool", PS_LOG_INFO, "no rows found");
    1577     psFree(output);
    1578     return true;
    1579   }
    1580   bool status;
    1581   psS64 m_order = psMetadataLookupS64(&status, output2->data[0], "count(*)");
    1582   if (!status) {
    1583 
    1584     psAbort("failed to lookup value for count column");
    1585     return false;
    1586   }
    1587   psString final = NULL;
    1588   psStringAppend(&final, "%" PRIu64, m_order);
    1589     //return false;
    1590   psFree(query3);
    1591   psFree(output2);
    1592 
    1593 
    1594 
    1595   //update the merge_order
    1596 
    1597   psString query4 = NULL;
    1598   psStringAppend(&query4, "update minidvodbProcessed set merge_order = %"PRIu64,m_order);
    1599   psStringAppend(&query4," where minidvodb_id = %" PRIu64,  minidvodb_id);
    1600   //printf("%s", query4);
    1601   if (!p_psDBRunQuery(config->dbh, query4)) {
    1602     // rollback
    1603     if (!psDBRollback(config->dbh)) {
    1604       psError(PS_ERR_UNKNOWN, false, "database error");
    1605     }
    1606     psError(PS_ERR_UNKNOWN, false, "database error");
    1607     psFree(query4);
    1608     return false;
    1609   }
    1610   //
    1611 psFree(query4);
    1612 
    1613 
    1614 
    1615 // since there is only one exp per 'new' set mindvodbRun.state = 'merged'
    1616 
    16171696  psString query2 = NULL ;
    16181697  psStringAppend(&query2, "UPDATE minidvodbRun SET state = 'merged' WHERE minidvodb_id = %'" PRIu64, row->minidvodb_id);
     
    16271706    return false;
    16281707  }
    1629 
    1630 
    1631 
    1632 
    1633 
    1634 
    1635 
    1636 
    16371708  psFree(row);
    16381709  psFree(pendingRow);
     
    16471718    return false;
    16481719  }
    1649 
    1650 
    1651   //print the merge_order (why not!)
    1652   printf("%s", final);
    1653   psFree(final);
    1654 
    16551720  return true;
    16561721}
     
    16611726  psMetadata *where = psMetadataAlloc();
    16621727  PXOPT_COPY_S64(config->args, where, "-minidvodb_id", "minidvodbProcessed.minidvodb_id", "==");
    1663   PXOPT_COPY_STR(config->args, where, "-minidvodb_name", "minidvodbProcessed.minidvodb_name", "==");
    1664   PXOPT_COPY_STR(config->args, where, "-minidvodb_group", "minidvodbProcessed.minidvodb_group", "==");
     1728  PXOPT_COPY_STR(config->args, where, "-minidvodb_name", "minidvodbRun.minidvodb_name", "==");
     1729  PXOPT_COPY_STR(config->args, where, "-minidvodb_group", "minidvodbRun.minidvodb_group", "==");
    16651730  PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    16661731  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     
    18111876
    18121877  PXOPT_LOOKUP_U64(minidvodb_id,  config->args, "-minidvodb_id", true, false);
    1813   PXOPT_LOOKUP_U64(merge_order,  config->args, "-set_merge_order", false, false);
    18141878  PXOPT_LOOKUP_S16(fault,  config->args, "-set_fault", false, false);
    18151879  PXOPT_LOOKUP_F32(dtime_relphot,  config->args, "-set_dtime_relphot", false, false);
    18161880  PXOPT_LOOKUP_F32(dtime_resort,  config->args, "-set_dtime_resort", false, false);
    1817   PXOPT_LOOKUP_F32(dtime_merge,  config->args, "-set_dtime_merge", false, false);
    1818 PXOPT_LOOKUP_F32(dtime_verify,  config->args, "-set_dtime_verify", false, false);
    18191881PXOPT_LOOKUP_F32(dtime_script,  config->args, "-set_dtime_script", false, false);
    18201882  PXOPT_COPY_S64(config->args, where, "-minidvodb_id",     "minidvodbProcessed.minidvodb_id", "==");
     
    18361898  }
    18371899
    1838   if (merge_order) {
    1839     if (cnt) {
    1840       psStringAppend(&query, "%s", comma);
    1841     }
    1842 
    1843     psStringAppend(&query, " merge_order = %" PRId64, merge_order);
    1844     cnt++;
    1845   }
    1846 
    18471900  if (dtime_relphot) {
    18481901    if (cnt) {
     
    18611914  }
    18621915
    1863   if (dtime_merge) {
    1864     if (cnt) {
    1865       psStringAppend(&query, "%s", comma);
    1866     }
    1867     psStringAppend(&query, " dtime_merge = %f", dtime_merge);
    1868     cnt++;
    1869  }
    1870 if (dtime_verify) {
    1871     if (cnt) {
    1872       psStringAppend(&query, "%s", comma);
    1873     }
    1874     psStringAppend(&query, " dtime_verify = %f", dtime_verify);
    1875     cnt++;
    1876  }
    1877 if (dtime_script) {
     1916  if (dtime_script) {
    18781917    if (cnt) {
    18791918      psStringAppend(&query, "%s", comma);
Note: See TracChangeset for help on using the changeset viewer.