IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 16, 2007, 4:42:08 PM (19 years ago)
Author:
jhoblitt
Message:

implement p6tool functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/stacktool.c

    r11851 r11866  
    9494    // required options
    9595    bool status = false;
    96     psString mode = psMetadataLookupStr(&status, config->args, "-mode");
    97     if (!status) {
    98         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -survey_mode");
    99         return false;
    100     }
    101     if (!mode) {
    102         psError(PS_ERR_UNKNOWN, true, "-mode is required");
    103         return false;
    104     }
    105 
    10696    psString workdir = psMetadataLookupStr(&status, config->args, "-workdir");
    10797    if (!status) {
     
    129119    }
    130120
    131     p4RunRow *p4Run = p4RunRowAlloc(
     121    p6RunRow *run = p6RunRowAlloc(
    132122            0,          // ID
    133             mode,
    134123            "reg",      // state
    135124            workdir,
     
    137126    );
    138127    psFree(registered);
    139     if (!p4Run) {
    140         psError(PS_ERR_UNKNOWN, false, "failed to alloc p4Run object");
     128    if (!run) {
     129        psError(PS_ERR_UNKNOWN, false, "failed to alloc p6Run object");
    141130        return true;
    142131    }
    143     if (!p4RunInsertObject(config->dbh, p4Run)) {
     132    if (!p6RunInsertObject(config->dbh, run)) {
    144133        psError(PS_ERR_UNKNOWN, false, "database error");
    145         psFree(p4Run);
     134        psFree(run);
    146135        return true;
    147136    }
    148137
    149138    // get the assigned p4_id
    150     p4Run->p4_id = psDBLastInsertID(config->dbh);
     139    run->p6_id = psDBLastInsertID(config->dbh);
    151140
    152141    bool simple = false;
     
    156145        if (!status) {
    157146            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    158             psFree(p4Run);
    159             return false;
    160         }
    161     }
    162 
    163     if (!p4RunPrintObject(stdout, p4Run, !simple)) {
     147            psFree(run);
     148            return false;
     149        }
     150    }
     151
     152    if (!p6RunPrintObject(stdout, run, !simple)) {
    164153            psError(PS_ERR_UNKNOWN, false, "failed to print object");
    165             psFree(p4Run);
    166             return false;
    167     }
    168 
    169     psFree(p4Run);
     154            psFree(run);
     155            return false;
     156    }
     157
     158    psFree(run);
    170159
    171160    return true;
     
    178167
    179168    bool status = false;
     169    psString p6_id = psMetadataLookupStr(&status, config->args, "-p6_id");
     170    if (!status) {
     171        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p6_id");
     172        return false;
     173    }
     174    if (!p6_id) {
     175        psError(PS_ERR_UNKNOWN, true, "-p6_id is required");
     176        return false;
     177    }
     178
     179    psString state = psMetadataLookupStr(&status, config->args, "-state");
     180    if (!status) {
     181        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
     182        return false;
     183    }
     184    if (!state) {
     185        psError(PS_ERR_UNKNOWN, true, "-state is required");
     186        return false;
     187    }
     188
     189    if (state) {
     190        // set detRun.state to state
     191        return setp6RunState(config, p6_id, state);
     192    }
     193
     194    return true;
     195}
     196
     197
     198static bool addinputscfileMode(pxConfig *config)
     199{
     200    PS_ASSERT_PTR_NON_NULL(config, false);
     201
     202    bool status = false;
     203    psString p6_id = psMetadataLookupStr(&status, config->args, "-p6_id");
     204    if (!status) {
     205        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p6_id");
     206        return false;
     207    }
     208    if (!p6_id) {
     209        psError(PS_ERR_UNKNOWN, true, "-p6_id is required");
     210        return false;
     211
     212    }
     213
    180214    psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");
    181215    if (!status) {
    182         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4t_id");
     216        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");
    183217        return false;
    184218    }
     
    188222    }
    189223
    190     psString state = psMetadataLookupStr(&status, config->args, "-state");
    191     if (!status) {
    192         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state");
    193         return false;
    194     }
    195     if (!state) {
    196         psError(PS_ERR_UNKNOWN, true, "-state is required");
    197         return false;
    198     }
    199 
    200     if (state) {
    201         // set detRun.state to state
    202         return setp6RunState(config, p4_id, state);
    203     }
    204 
    205     return true;
    206 }
    207 
    208 
    209 static bool addinputscfileMode(pxConfig *config)
    210 {
    211     PS_ASSERT_PTR_NON_NULL(config, false);
    212 
    213     bool status = false;
    214     psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");
    215     if (!status) {
    216         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");
    217         return false;
    218     }
    219     if (!p4_id) {
    220         psError(PS_ERR_UNKNOWN, true, "-p4_id is required");
    221         return false;
    222     }
    223 
    224     psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
    225     if (!status) {
    226         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
    227         return false;
    228     }
    229     if (!exp_tag) {
    230         psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
    231         return false;
    232     }
    233 
    234     // defaults to 0
    235     psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version");
    236     if (!status) {
    237         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");
    238         return false;
    239     }
    240 
    241     // defaults to false
    242     bool magiced = psMetadataLookupBool(&status, config->args, "-p3_version");
    243     if (!status) {
    244         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");
     224    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
     225    if (!status) {
     226        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
     227        return false;
     228    }
     229    if (!skycell_id) {
     230        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
     231        return false;
     232    }
     233
     234    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
     235    if (!status) {
     236        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
     237        return false;
     238    }
     239    if (!tess_id) {
     240        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
    245241        return false;
    246242    }
     
    249245    // XXX instead of validiting it here we should just use forgein key
    250246    // constrants
    251     if (!p4InputExpInsert(config->dbh,
     247    if (!p6InputScfileInsert(config->dbh,
     248            (psS32)atoi(p6_id),
    252249            (psS32)atoi(p4_id),
    253             exp_tag,
    254             p3_version,
    255             magiced
     250            skycell_id,
     251            tess_id
    256252        )) {
    257253        psError(PS_ERR_UNKNOWN, false, "database error");
     
    277273    psString query = psStringCopy(
    278274        "SELECT\n"
    279         "   rawImfile.*\n"
    280         " FROM p4Run\n"
    281         " JOIN p4InputExp\n"
    282         "   USING(p4_id)\n"
    283         " JOIN rawImfile\n -- is there any reason not to refer back to rawimfiles?"
    284         "   ON p4InputExp.exp_tag = rawImfile.exp_tag\n"
     275        "   p4Scfile.*\n"
     276        " FROM p6Run\n"
     277        " JOIN p6InputScfile\n"
     278        "   USING(p6_id)\n"
     279        " JOIN p4Scfile\n"
     280        "   ON p6InputScfile.p4_id = p4Scfile.p4_id\n"
     281        "   AND p6InputScfile.skycell_id = p4Scfile.skycell_id\n"
     282        "   AND p6InputScfile.tess_id = p4Scfile.tess_id\n"
    285283        " WHERE\n"
    286         "   p4Run.state = 'run'\n"
     284        "   p6Run.state = 'run'\n"
    287285    );
    288286    if (config->where) {
    289         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputExp");
     287        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p6InputScfile");
    290288        psStringAppend(&query, " AND %s", whereClause);
    291289        psFree(whereClause);
     
    321319    }
    322320    if (!psArrayLength(output)) {
    323         psError(PS_ERR_UNKNOWN, false, "no pending rawImfile rows found");
     321        psError(PS_ERR_UNKNOWN, false, "no p6InputScfile rows found");
    324322        psFree(output);
    325323        return true;
     
    338336    if (psArrayLength(output)) {
    339337        // negative simple so the default is true
    340         if (!ippdbPrintMetadatas(stdout, output, "p4InputImfile", !simple)) {
     338        if (!ippdbPrintMetadatas(stdout, output, "p6InputScfile", !simple)) {
    341339            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    342340            psFree(output);
     
    365363    psString query = psStringCopy(
    366364        "SELECT\n"
    367         "   p3ProcessedExp.*\n"
    368         " FROM p4Run\n"
    369         " JOIN p4InputExp\n"
    370         "   USING(p4_id)\n"
    371         " JOIN p3ProcessedExp\n"
    372         "   ON p4InputExp.exp_tag = p3ProcessedExp.exp_tag\n"
    373         "   AND p4InputExp.p3_version = p3ProcessedExp.p3_version\n"
    374         " LEFT JOIN p4SkyCellMap\n"
    375         "   ON p4InputExp.p4_id = p4SkyCellMap.p4_id\n"
    376         "   AND p4InputExp.exp_tag = p4SkyCellMap.exp_tag\n"
    377         "   AND p4InputExp.p3_version = p4SkyCellMap.p3_version\n"
     365        "   p6Run.p6_id\n"
     366        " FROM p6Run\n"
     367        " LEFT JOIN p4SumScfile\n"
     368        "   USING(p6_id)\n"
    378369        " WHERE\n"
    379         "   p4Run.state = 'run'\n"
    380         "   AND p3ProcessedExp.fault = 0\n"
    381         "   AND p4SkyCellMap.p4_id IS NULL\n"
    382         "   AND p4SkyCellMap.exp_tag IS NULL\n"
    383         "   AND p4SkyCellMap.p3_version IS NULL\n"
     370        "   p6Run.state = 'run'\n"
     371        "   AND p6SumScfile.p6_id IS NULL\n"
    384372    );
    385373
    386374    if (config->where) {
    387         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputExp");
     375        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p6SumScfile");
    388376        psStringAppend(&query, " AND %s", whereClause);
    389377        psFree(whereClause);
     
    419407    }
    420408    if (!psArrayLength(output)) {
    421         psError(PS_ERR_UNKNOWN, false, "no pending rawImfile rows found");
     409        psError(PS_ERR_UNKNOWN, false, "no p6SumScfile rows found");
    422410        psFree(output);
    423411        return true;
     
    436424    if (psArrayLength(output)) {
    437425        // negative simple so the default is true
    438         if (!ippdbPrintMetadatas(stdout, output, "p4InputExp", !simple)) {
     426        if (!ippdbPrintMetadatas(stdout, output, "p6SumScfile", !simple)) {
    439427            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    440428            psFree(output);
     
    454442
    455443    bool status = false;
    456     psString mapfile = psMetadataLookupStr(&status, config->args, "-mapfile");
    457     if (!status) {
    458         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -mapfile");
    459         return false;
    460     }
    461     if (!mapfile) {
    462         psError(PS_ERR_UNKNOWN, true, "-mapfile is required");
    463         return false;
    464     }
    465 
    466     if (!psDBTransaction(config->dbh)) {
    467         psError(PS_ERR_UNKNOWN, false, "database error");
    468         return false;
    469     }
    470 
    471     // point of no return
    472     if (!psDBCommit(config->dbh)) {
     444    psString p6_id = psMetadataLookupStr(&status, config->args, "-p6_id");
     445    if (!status) {
     446        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p6_id");
     447        return false;
     448    }
     449    if (!p6_id) {
     450        psError(PS_ERR_UNKNOWN, true, "-p6_id is required");
     451        return false;
     452
     453    }
     454
     455    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
     456    if (!status) {
     457        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
     458        return false;
     459    }
     460    if (!skycell_id) {
     461        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
     462        return false;
     463    }
     464
     465    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
     466    if (!status) {
     467        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
     468        return false;
     469    }
     470    if (!tess_id) {
     471        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
     472        return false;
     473    }
     474
     475    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     476    if (!status) {
     477        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
     478        return false;
     479    }
     480    if (!uri) {
     481        psError(PS_ERR_UNKNOWN, true, "-uri is required");
     482        return false;
     483    }
     484
     485    // optional
     486    psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
     487    if (!status) {
     488        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg");
     489        return false;
     490    }
     491
     492    psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev");
     493    if (!status) {
     494        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev");
     495        return false;
     496    }
     497
     498    // XXX need to validate the p6_id here
     499    // XXX instead of validiting it here we should just use forgein key
     500    // constrants
     501    if (!p6SumScfileInsert(config->dbh,
     502            (psS32)atoi(p6_id),
     503            skycell_id,
     504            tess_id,
     505            uri,
     506            bg,
     507            bg_mean_stdev
     508        )) {
    473509        psError(PS_ERR_UNKNOWN, false, "database error");
    474510        return false;
     
    493529    psString query = psStringCopy(
    494530        "SELECT\n"
    495         "   p4Scfile.*\n"
    496         " FROM p4Run\n"
    497         " JOIN p4Scfile\n"
    498         "   USING(p4_id)\n"
     531        "   p6SumScfile.*\n"
     532        " FROM p6Run\n"
     533        " JOIN p6SumScfile\n"
     534        "   USING(p6_id)\n"
    499535        " WHERE\n"
    500         "   p4Run.state = 'run'\n"
     536        "   p6Run.state = 'run'\n"
    501537    );
    502538
    503539    if (config->where) {
    504         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4Scfile");
     540        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p6SumScfile");
    505541        psStringAppend(&query, " AND %s", whereClause);
    506542        psFree(whereClause);
     
    552588
    553589    if (psArrayLength(output)) {
    554         // negative simple so the default is true
    555         if (!ippdbPrintMetadatas(stdout, output, "p4Scfile", !simple)) {
     590        if (!ippdbPrintMetadatas(stdout, output, "p6SumScfile", !simple)) {
    556591            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    557592            psFree(output);
     
    583618    }
    584619
    585     char *query = "UPDATE p4Run SET state = '%s' WHERE p4_id = '%s'";
     620    char *query = "UPDATE p6Run SET state = '%s' WHERE p6_id = '%s'";
    586621    if (!p_psDBRunQuery(config->dbh, query, state, p6_id)) {
    587622        psError(PS_ERR_UNKNOWN, false,
Note: See TracChangeset for help on using the changeset viewer.