IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2012, 2:49:37 PM (14 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20111122/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/ippTools/src

  • branches/eam_branches/ipp-20111122/ippTools/src/addtool.c

    r32851 r33638  
    141141    pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label
    142142    PXOPT_COPY_STR(config->args, where,  "-reduction", "staticskyyRun.reduction", "==");
    143     pxAddLabelSearchArgs (config, where, "-filter",     "stackRun.filter", "=="); // define using camRun label
    144     }
    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", "==");
    150143    //no filter here
    151144    }
     
    227220    }
    228221    }
     222 
    229223    if (strcmp(stage,"staticsky") == 0) {
    230     if (dvodb ) {
    231       psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_dvo.sql\n%s\n", dvodb,stage);
    232         // find the cam_id of all the exposures that we want to queue up.
    233         bare_query = pxDataGet("addtool_find_sky_id_dvo.sql");
    234         // user supplied dvodb
    235         psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
    236     } else {
    237       psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_sky_id.sql\n%s\n",stage);
    238         // find the cam_id of all the exposures that we want to queue up.
    239         bare_query = pxDataGet("addtool_find_sky_id.sql");
    240         // inherit dvodb from camRun, avoid matching NULL
    241         psStringAppend(&dvodb_string, "(staticskyRun.dvodb IS NOT NULL AND previous_dvodb = staticskyRun.dvodb)");
    242     }
    243     }
    244 
    245     if (strcmp(stage,"staticsky_multi") == 0) {
    246224      if (dvodb ) {
    247225        psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_multi_dvo.sql\n%s\n", dvodb,stage);
     
    292270    } else {
    293271      //This picks only the unmagicked/uncensored ones
    294       if (strcmp(stage,"cam") == 0) {
    295         psStringAppend(&query, " AND (camRun.magicked = 0)");
    296       }
     272      //if (strcmp(stage,"cam") == 0) {
     273        //we can now properly handle the magicked case in ippScripts, so we queue camRuns in any magic state now if -uncensored.
     274        //psStringAppend(&query, " AND (camRun.magicked = 0)");
     275        //}
    297276      if (strcmp(stage,"stack") == 0) {
    298277        psStringAppend(&query, " AND (stackRun.magicked = 0)");
     
    309288        psStringAppend(&query, " GROUP BY stack_id");
    310289      }
     290      //   if (strcmp(stage,"staticsky") == 0) {
     291      //   psStringAppend(&query, " GROUP BY stack_id");
     292      // }
    311293    if (strcmp(stage,"staticsky") == 0) {
    312         psStringAppend(&query, " GROUP BY stack_id");
    313       }
    314     if (strcmp(stage,"staticsky_multi") == 0) {
    315294      psStringAppend(&query, " GROUP BY sky_id");  //some reason it needs this
    316295      }
     
    401380    }
    402381    }
     382   
    403383    if (strcmp(stage,"staticsky") == 0) {
    404     for (long i = 0; i < psArrayLength(output); i++) {
    405         psMetadata *md = output->data[i];
    406 
    407         staticskyRunRow *row = staticskyRunObjectFromMetadata(md);
    408        
    409         if (!row) {
    410             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
    411             psFree(output);
    412             return false;
    413         }
    414 
    415         if (!dvodb) {  //there's no staticsky.dvodb
    416             psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id);
    417             psFree(output);
    418             return false;
    419         }
    420         if (!workdir && !row->workdir) {
    421             psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id);
    422             psFree(output);
    423             return false;
    424         }
    425 
    426         psFree(row);
    427     }
    428     }
    429     if (strcmp(stage,"staticsky_multi") == 0) {
    430384    for (long i = 0; i < psArrayLength(output); i++) {
    431385        psMetadata *md = output->data[i];
     
    565519    }
    566520      }
     521   
    567522    if (strcmp(stage,"staticsky") == 0) {
    568     for (long i = 0; i < psArrayLength(output); i++) {
    569         psMetadata *md = output->data[i];
    570         psS64 stage_id =0;
    571        
    572         staticskyRunRow *row = staticskyRunObjectFromMetadata(md);
    573         stage_id = row->sky_id;
    574        
    575         if (!row) {
    576             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
    577             psFree(output);
    578             return false;
    579         }
    580 
    581         // queue the exp
    582         if (!pxaddQueueByCamID(config,
    583                                stage,
    584                                stage_id,
    585                                0,
    586                                workdir     ? workdir   : row->workdir,
    587                                reduction   ? reduction : row->reduction,
    588                                label       ? label     : row->label,
    589                                data_group  ? data_group : (row->data_group ? row->data_group :  (label ? label : row->label)),
    590                                dvodb       ? dvodb     : NULL,
    591                                note        ? note      : NULL,
    592                                image_only,
    593                                minidvodb,
    594                                minidvodb_group,
    595                                minidvodb_name
    596         )) {
    597             if (!psDBRollback(config->dbh)) {
    598                 psError(PS_ERR_UNKNOWN, false, "database error sfg");
    599             }
    600             psError(PS_ERR_UNKNOWN, false,
    601                     "failed to trying to queue stage %s %" PRId64,stage, stage_id);
    602             psFree(row);
    603             psFree(output);
    604             return false;
    605         }
    606         psFree(row);
    607     }
    608       }
    609 
    610     if (strcmp(stage,"staticsky_multi") == 0) {
    611523    for (long i = 0; i < psArrayLength(output); i++) {
    612524        psMetadata *md = output->data[i];
     
    704616    query = psStringCopy("UPDATE addRun JOIN staticskyRun on sky_id = stage_id");
    705617    }
    706     if (strcmp(stage, "staticsky_multi")==0) {
    707     query = psStringCopy("UPDATE addRun JOIN staticskyRun on sky_id = stage_id");
    708     }
     618   
    709619
    710620    // pxUpdateRun gets parameters from config->args and runs the update query
     
    744654    }
    745655    if (strcmp(stage, "staticsky")==0) {
    746     query = pxDataGet("addtool_find_pendingexp_staticsky.sql");
    747     }
    748     if (strcmp(stage, "staticsky_multi")==0) {
    749656    query = pxDataGet("addtool_find_pendingexp_staticsky_multi.sql");
    750657    }
     
    767674      psStringAppend(&query, " GROUP BY %s", "stack_id");
    768675    }
     676    //if (strcmp(stage, "staticsky") == 0) {
     677    //  //this group by is needed to join against all the warps (to get camera)
     678    //  psStringAppend(&query, " GROUP BY %s", "sky_id");
     679    //}
    769680    if (strcmp(stage, "staticsky") == 0) {
    770       //this group by is needed to join against all the warps (to get camera)
    771       psStringAppend(&query, " GROUP BY %s", "sky_id");
    772     }
    773     if (strcmp(stage, "staticsky_multi") == 0) {
    774681      //this group by is needed to join against all the warps (to get camera)
    775682      psStringAppend(&query, " GROUP BY %s", "sky_id, stage_extra1");
     
    824731    PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-minidvodb_name", false, false);
    825732    PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
    826 
     733    PXOPT_LOOKUP_S64(stage_extra1, config->args, "-stage_extra1", false, false);
    827734    // generate restrictions
    828735    psMetadata *where = psMetadataAlloc();
     
    902809      }
    903810    }
    904 
     811    //if there is a stage_extra1, set it in addRun (it's not known until it is processed)
     812    if (stage_extra1) {
     813      psString setExtra = NULL;
     814      psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1);
     815      psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id);
     816
     817      if (!p_psDBRunQuery(config->dbh, setExtra)) {
     818        if (!psDBRollback(config->dbh)) {
     819          psError(PS_ERR_UNKNOWN, false, "database error");
     820        }
     821        psError(PS_ERR_UNKNOWN, false, "database error");
     822
     823        return false;
     824      }
     825    }
    905826
    906827
     
    962883    }
    963884    if (strcmp (stage,"staticsky") == 0) {
    964     query = pxDataGet("addtool_find_processedexp_staticsky.sql");
    965     }
    966     if (strcmp (stage,"staticsky_multi") == 0) {
    967885    query = pxDataGet("addtool_find_processedexp_staticsky_multi.sql");
    968886    }
     
    1049967    PXOPT_COPY_S64(config->args, where, "-add_id",    "addRun.add_id",         "==");
    1050968    PXOPT_COPY_S64(config->args, where, "-stage_id",    "addRun.stage_id",         "==");
    1051     PXOPT_LOOKUP_STR(stage,       config->args, "-stage", false, false);
     969    PXOPT_LOOKUP_STR(stage,       config->args, "-stage", true, false);
    1052970    pxcamGetSearchArgs (config, where);
    1053971    pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     
    1075993         query = pxDataGet("addtool_revertprocessedexp_stack.sql");
    1076994      }
    1077      if (strcmp(stage, "staticsky") == 0) {
    1078          query = pxDataGet("addtool_revertprocessedexp_staticsky.sql");
    1079       }
    1080    if (strcmp(stage, "staticsky_multi") == 0) {
     995    if (strcmp(stage, "staticsky") == 0) {
    1081996         query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql");
    1082997      }
     
    12211136
    12221137  PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false);
    1223   PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-set_mergedvodb_path", true, false);
    1224 
    1225   //optional
     1138    //optional
    12261139  PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false);
    12271140  PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false);
     
    12381151  if (minidvodb_path) {
    12391152    minidvodbpath = minidvodb_path;
     1153  } else {
     1154    psError(PS_ERR_UNKNOWN, false, "require minidvodb_path");
     1155    return false;
    12401156  }
    12411157
     
    12451161            minidvodb_group,
    12461162            minidvodbpath,
    1247             mergedvodb_path,
    1248             "new",
     1163            "new",
    12491164            0
    12501165            )) {
     
    12681183    psStringAppend(&minidvodb_name, "%s.%" PRIu64,minidvodb_group,minidvodb_id);
    12691184  }
    1270 
    1271   if (!minidvodb_path) {
    1272     psStringAppend(&minidvodb_path,"%s/%s",mergedvodb_path,minidvodb_name);
    1273   }
    1274 
    12751185  if (minidvodb_path) {
    12761186    psStringAppend(&minidvodb_path,"/%s",minidvodb_name);
     
    13041214    PXOPT_COPY_STR(config->args, where, "-state",     "state", "==");
    13051215    PXOPT_COPY_STR(config->args, where, "-minidvodb_path", "minidvodb_path", "==");
    1306     PXOPT_COPY_STR(config->args, where, "-mergedvodb_path", "mergedvodb_path", "==");
    13071216    PXOPT_COPY_STR(config->args, where, "-minidvodb_group",     "minidvodb_group", "==");
    13081217
     
    13101219    PXOPT_LOOKUP_STR(minidvodb_path,  config->args, "-set_minidvodb_path", false, false);
    13111220    PXOPT_LOOKUP_STR(state,  config->args, "-set_state", false, false);
    1312     PXOPT_LOOKUP_STR(mergedvodb_path,  config->args, "-set_mergedvodb_path", false, false);
    13131221    PXOPT_LOOKUP_STR(minidvodb_group,  config->args, "-set_minidvodb_group", false, false);
    13141222
     
    13451253    }
    13461254
    1347     if (mergedvodb_path) {
    1348       if (cnt) {
    1349         psStringAppend(&query, "%s", comma);
    1350       }
    1351       psStringAppend(&query, " mergedvodb_path = '%s'", mergedvodb_path);
    1352       cnt++;
    1353     }
    1354 
    13551255    if (minidvodb_group) {
    13561256      if (cnt) {
     
    13961296  }
    13971297
    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 and mergedvodb_path IS NOT NULL");
     1298  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");
    13991299
    14001300  psString firstwhereClause = psDBGenerateWhereConditionSQL(where, NULL);
     
    14441344
    14451345  //now flip new -> active
    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 and mergedvodb_path IS NOT NULL ");
     1346  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 ");
    14471347  psStringAppend(&query2, " AND minidvodb_group = '%s' limit 1;", minidvodb_group);
    14481348  if (!p_psDBRunQuery(config->dbh, query2)) {
     
    14801380  PXOPT_COPY_STR(config->args, where, "-minidvodb_name", "minidvodbRun.minidvodb_name", "==");
    14811381  PXOPT_COPY_STR(config->args, where, "-state", "minidvodbRun.state", "==");
    1482 
    1483 
     1382  PXOPT_LOOKUP_STR(minidvodb_group,  config->args, "-minidvodb_group", false, false);
     1383 
    14841384  PXOPT_LOOKUP_U64(limit,      config->args, "-limit", false, false);
    14851385  PXOPT_LOOKUP_BOOL(all_addrun_states, config->args, "-all_addrun_states", false);
     
    14931393  }
    14941394
    1495   psString query = pxDataGet("addtool_checkminidvodbaddrun.sql");
    1496 
    1497   if (!query) {
     1395  if (!minidvodb_group) {
     1396    psError(PXTOOLS_ERR_CONFIG, false, "minidvodb_group  required");
     1397    return false;
     1398  }
     1399
     1400
     1401  psString bare_query = pxDataGet("addtool_checkminidvodbaddrun.sql");
     1402 
     1403  if (!bare_query) {
    14981404        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    14991405        return false;
    15001406  }
    15011407
    1502 
     1408  psString where_string = NULL;
    15031409  if (psListLength(where->list)) {
    15041410    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    1505         psStringAppend(&query, " WHERE %s", whereClause);
     1411        psStringAppend(&where_string, " WHERE %s", whereClause);
    15061412        psFree(whereClause);
    1507   }
    1508 
     1413        //search params are defined above
     1414  }
     1415
     1416  psString query = NULL;
     1417  psStringAppend(&query, bare_query, minidvodb_group);
     1418  psStringAppend(&query, where_string);
     1419
     1420
     1421
     1422
     1423 
    15091424  if (!all_addrun_states) {
    15101425    psStringAppend(&query, " AND (cnt2 = cnt) ");
     
    15191434
    15201435  if (!p_psDBRunQuery(config->dbh, query)) {
    1521     psError(PS_ERR_UNKNOWN, false, "database error");
     1436    psError(PS_ERR_UNKNOWN, false, "database error,\n\n%s", query);
    15221437    psFree(query);
    15231438    return false;
     
    16211536    // required
    16221537  PXOPT_LOOKUP_U64(minidvodb_id, config->args, "-minidvodb_id", true, false);
    1623   PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-mergedvodb_path", true, false);
    16241538  PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-minidvodb_group", true, false);
    16251539
    16261540    // optional
    1627   PXOPT_LOOKUP_U64(merge_order,     config->args, "-merge_order", false, false);
    16281541  PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-dtime_relphot", false, false);
    16291542  PXOPT_LOOKUP_F32(dtime_resort, config->args, "-dtime_resort", false, false);
    1630   PXOPT_LOOKUP_F32(dtime_merge, config->args, "-dtime_merge", false, false);
    1631   PXOPT_LOOKUP_F32(dtime_verify, config->args, "-dtime_verify", false, false);
    16321543  PXOPT_LOOKUP_F32(dtime_script, config->args, "-dtime_script", false, false);
    16331544 
     
    16801591  minidvodbProcessedRow *row = minidvodbProcessedRowAlloc(
    16811592               pendingRow->minidvodb_id,
    1682                merge_order,
    16831593               dtime_resort,
    16841594               dtime_relphot,
    1685                dtime_verify,
    1686                dtime_merge,
    16871595               dtime_script,
    16881596               epoch,
    1689                mergedvodb_path,
    16901597               fault
    16911598               );
     
    17021609  }
    17031610
    1704 
    1705 
    1706 
    1707   //this finds the # of merged things (for the merge order)
    1708   psString query3 = NULL;
    1709   psStringAppend(&query3, "select count(*) from minidvodbRun join minidvodbProcessed using (minidvodb_id) where state = 'merged' and minidvodb_group = '%s';", minidvodb_group);
    1710 
    1711   if (!p_psDBRunQuery(config->dbh, query3)) {
    1712     // rollback
    1713     if (!psDBRollback(config->dbh)) {
    1714       psError(PS_ERR_UNKNOWN, false, "database error");
    1715     }
    1716     psError(PS_ERR_UNKNOWN, false, "database error");
    1717     psFree(query3);
    1718     return false;
    1719   }
    1720   psArray *output2 = p_psDBFetchResult(config->dbh);
    1721   if (!output2) {
    1722     psError(PS_ERR_UNKNOWN, false, "database error");
    1723     return false;
    1724   }
    1725   if (!psArrayLength(output2)) {
    1726     psTrace("addtool", PS_LOG_INFO, "no rows found");
    1727     psFree(output);
    1728     return true;
    1729   }
    1730   bool status;
    1731   psS64 m_order = psMetadataLookupS64(&status, output2->data[0], "count(*)");
    1732   if (!status) {
    1733 
    1734     psAbort("failed to lookup value for count column");
    1735     return false;
    1736   }
    1737   psString final = NULL;
    1738   psStringAppend(&final, "%" PRIu64, m_order);
    1739     //return false;
    1740   psFree(query3);
    1741   psFree(output2);
    1742 
    1743 
    1744 
    1745   //update the merge_order
    1746 
    1747   psString query4 = NULL;
    1748   psStringAppend(&query4, "update minidvodbProcessed set merge_order = %"PRIu64,m_order);
    1749   psStringAppend(&query4," where minidvodb_id = %" PRIu64,  minidvodb_id);
    1750   //printf("%s", query4);
    1751   if (!p_psDBRunQuery(config->dbh, query4)) {
    1752     // rollback
    1753     if (!psDBRollback(config->dbh)) {
    1754       psError(PS_ERR_UNKNOWN, false, "database error");
    1755     }
    1756     psError(PS_ERR_UNKNOWN, false, "database error");
    1757     psFree(query4);
    1758     return false;
    1759   }
    1760   //
    1761 psFree(query4);
    1762 
    1763 
    1764 
    1765 // since there is only one exp per 'new' set mindvodbRun.state = 'merged'
    1766 
    17671611  psString query2 = NULL ;
    17681612  psStringAppend(&query2, "UPDATE minidvodbRun SET state = 'merged' WHERE minidvodb_id = %'" PRIu64, row->minidvodb_id);
     
    17771621    return false;
    17781622  }
    1779 
    1780 
    1781 
    1782 
    1783 
    1784 
    1785 
    1786 
    17871623  psFree(row);
    17881624  psFree(pendingRow);
     
    17971633    return false;
    17981634  }
    1799 
    1800 
    1801   //print the merge_order (why not!)
    1802   printf("%s", final);
    1803   psFree(final);
    1804 
    18051635  return true;
    18061636}
     
    19611791
    19621792  PXOPT_LOOKUP_U64(minidvodb_id,  config->args, "-minidvodb_id", true, false);
    1963   PXOPT_LOOKUP_U64(merge_order,  config->args, "-set_merge_order", false, false);
    19641793  PXOPT_LOOKUP_S16(fault,  config->args, "-set_fault", false, false);
    19651794  PXOPT_LOOKUP_F32(dtime_relphot,  config->args, "-set_dtime_relphot", false, false);
    19661795  PXOPT_LOOKUP_F32(dtime_resort,  config->args, "-set_dtime_resort", false, false);
    1967   PXOPT_LOOKUP_F32(dtime_merge,  config->args, "-set_dtime_merge", false, false);
    1968 PXOPT_LOOKUP_F32(dtime_verify,  config->args, "-set_dtime_verify", false, false);
    19691796PXOPT_LOOKUP_F32(dtime_script,  config->args, "-set_dtime_script", false, false);
    19701797  PXOPT_COPY_S64(config->args, where, "-minidvodb_id",     "minidvodbProcessed.minidvodb_id", "==");
     
    19861813  }
    19871814
    1988   if (merge_order) {
    1989     if (cnt) {
    1990       psStringAppend(&query, "%s", comma);
    1991     }
    1992 
    1993     psStringAppend(&query, " merge_order = %" PRId64, merge_order);
    1994     cnt++;
    1995   }
    1996 
    19971815  if (dtime_relphot) {
    19981816    if (cnt) {
     
    20111829  }
    20121830
    2013   if (dtime_merge) {
    2014     if (cnt) {
    2015       psStringAppend(&query, "%s", comma);
    2016     }
    2017     psStringAppend(&query, " dtime_merge = %f", dtime_merge);
    2018     cnt++;
    2019  }
    2020 if (dtime_verify) {
    2021     if (cnt) {
    2022       psStringAppend(&query, "%s", comma);
    2023     }
    2024     psStringAppend(&query, " dtime_verify = %f", dtime_verify);
    2025     cnt++;
    2026  }
    2027 if (dtime_script) {
     1831  if (dtime_script) {
    20281832    if (cnt) {
    20291833      psStringAppend(&query, "%s", comma);
Note: See TracChangeset for help on using the changeset viewer.