IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8120


Ignore:
Timestamp:
Aug 3, 2006, 6:18:57 PM (20 years ago)
Author:
jhoblitt
Message:

large database schema change -> add airmass, ra, decl, exp_time, & background to exps
several memory leaks
add some transactions to p0search & p2search
fix p2search -done's handling of p2Done* tables

Location:
trunk/ippTools/src
Files:
12 edited

Legend:

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

    r8073 r8120  
    241241    psFree(pendingImfiles);
    242242
    243     // point of no return for p2PendingImfile -> p2DoneImfile
    244     if (!psDBCommit(config->dbh)) {
    245         psError(PS_ERR_UNKNOWN, false, "database error");
    246         return false;
    247     }
    248 
    249     // XXX make exposure state transition transactional
     243    // XXX I've decided to make the transaction cover the Exp migration as
     244    // well.  Otherwise, if the last imfile in an exp is moved and the exp
     245    // migration fails then the data base is left in a satuation where the exp
     246    // migration can't happen.
    250247
    251248    // look for pending exposures
    252249    psArray *pendingExps = p2searchPendingExp(config);
    253250    if (!pendingExps) {
     251        // rollback
     252        if (!psDBRollback(config->dbh)) {
     253            psError(PS_ERR_UNKNOWN, false, "database error");
     254        }
    254255        psError(PS_ERR_UNKNOWN, false, "no p2PendingExps found");
    255256        return false;
     
    265266        if (!pendingImfiles) {
    266267            // exp has no coresponding imfiles
    267             psArray *nukeMe = psArrayAlloc(1);
    268             nukeMe->n = 0;
    269             psArrayAdd(nukeMe, 0, pendingExp);
    270             bool status = p2PendingExpDeleteRowObjects(config->dbh, nukeMe, MAX_ROWS);
    271             psFree(nukeMe);
    272             if (!status) {
     268            psMetadata *where = psMetadataAlloc();
     269            psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", pendingExp->exp_id);
     270            long long count = p2PendingExpDelete(config->dbh, where, MAX_ROWS);
     271            psFree(where);
     272            if (count != 0) {
     273                // rollback
     274                if (!psDBRollback(config->dbh)) {
     275                    psError(PS_ERR_UNKNOWN, false, "database error");
     276                }
    273277                psError(PS_ERR_UNKNOWN, false, "dbh access failed");
     278                psFree(pendingExps);
    274279                return false;
    275280            }
    276             // XXX need a func to convert from p2PendingExp -> p2DoneExp
    277281
    278282            p2DoneExpRow *doneExp = p2pendingToDoneExp(pendingExp);
    279283            if (!doneExp) {
     284                // rollback
     285                if (!psDBRollback(config->dbh)) {
     286                    psError(PS_ERR_UNKNOWN, false, "database error");
     287                }
    280288                psError(PS_ERR_UNKNOWN, false, "p2PendingExp -> p2DoneExp failed");
     289                psFree(pendingExps);
    281290                return false;
    282291            }
    283292            if (!p2DoneExpInsertObject(config->dbh, doneExp)) {
     293                // rollback
     294                if (!psDBRollback(config->dbh)) {
     295                    psError(PS_ERR_UNKNOWN, false, "database error");
     296                }
    284297                psError(PS_ERR_UNKNOWN, false, "dbh access failed");
     298                psFree(doneExp);
     299                psFree(pendingExps);
    285300                return false;
    286301            }
    287         }
    288         // skip phase 3 for the time being
     302            psFree(doneExp);
     303        }
     304        // XXX skip phase 3 for the time being
    289305        psFree(pendingImfiles);
    290306    }
    291307
     308    psFree(pendingExps);
     309
     310    // point of no return for p2PendingImfile -> p2DoneImfile
     311    // point of no return for p2PendingExp -> p2DoneExp
     312    if (!psDBCommit(config->dbh)) {
     313        psError(PS_ERR_UNKNOWN, false, "database error");
     314        return false;
     315    }
    292316    /*
    293317    psArray *doneFrames = p2pendingToDone(config, pendingFrames);
     
    328352        uri,
    329353        "my recipe", // recipe
    330         "my stats", // stats
    331354        imfile->p1_version,
    332355        imfile->p2_version
  • trunk/ippTools/src/dettool.c

    r8076 r8120  
    422422        rawExp->imfiles,
    423423        rawExp->filter,
    424         rawExp->stats
     424        rawExp->airmass,
     425        rawExp->ra,
     426        rawExp->decl,
     427        rawExp->exp_time,
     428        rawExp->background
    425429    );
    426430}
     
    604608        return false;
    605609    }
    606     psString stats = psMetadataLookupStr(&status, config->args, "-stats");
    607     if (!status) {
    608         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
    609         return false;
    610     }
    611     if (!stats) {
    612         psError(PS_ERR_UNKNOWN, true, "-stats is required");
    613         return false;
    614     }
    615610    psString recipe = psMetadataLookupStr(&status, config->args, "-recip");
    616611    if (!status) {
     
    645640    // create a new detProcessedImfile object
    646641    detProcessedImfileRow *detRow = detProcessedImfileRowAlloc(
    647         (psS32)atol(det_id), exp_id, class_id, uri, stats, recipe
     642        (psS32)atol(det_id), exp_id, class_id, uri, recipe
    648643    );   
    649644    psFree(rawImfiles);
     
    921916    PS_ASSERT_PTR_NON_NULL(config, false);
    922917
    923     // det_id, class_id, uri, stats, & recipe are required
     918    // det_id, class_id, uri, & recipe are required
    924919    bool status = false;
    925920    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     
    948943    if (!uri) {
    949944        psError(PS_ERR_UNKNOWN, true, "-uri is required");
    950         return false;
    951     }
    952     psString stats = psMetadataLookupStr(&status, config->args, "-stats");
    953     if (!status) {
    954         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
    955         return false;
    956     }
    957     if (!stats) {
    958         psError(PS_ERR_UNKNOWN, true, "-stats is required");
    959945        return false;
    960946    }
     
    1010996    // create a new detStackedImfile object
    1011997    detStackedImfileRow *stackedImfile = detStackedImfileRowAlloc(
    1012         (psS32)atol(det_id), iteration, class_id, uri, stats, recipe
     998        (psS32)atol(det_id), iteration, class_id, uri, recipe
    1013999    );   
    10141000
     
    12701256    PS_ASSERT_PTR_NON_NULL(config, false);
    12711257 
    1272     // det_id, class_id, uri, stats, & recipe are required
     1258    // det_id, class_id, uri, & recipe are required
    12731259    bool status = false;
    12741260    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     
    12971283    if (!uri) {
    12981284        psError(PS_ERR_UNKNOWN, true, "-uri is required");
    1299         return false;
    1300     }
    1301     psString stats = psMetadataLookupStr(&status, config->args, "-stats");
    1302     if (!status) {
    1303         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
    1304         return false;
    1305     }
    1306     if (!stats) {
    1307         psError(PS_ERR_UNKNOWN, true, "-stats is required");
    13081285        return false;
    13091286    }
     
    13671344    // create a new detNormalizedImfile object
    13681345    detNormalizedImfileRow *masterImfile = detNormalizedImfileRowAlloc(
    1369         (psS32)atol(det_id), iteration, class_id, uri, stats, recipe
     1346        (psS32)atol(det_id), iteration, class_id, uri, recipe
    13701347    );   
    13711348
     
    15411518    PS_ASSERT_PTR_NON_NULL(config, false);
    15421519
    1543     // det_id, exp_id, class_id, stats, & recipe are required
     1520    // det_id, exp_id, class_id, & recipe are required
    15441521    bool status = false;
    15451522    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     
    15681545    if (!class_id) {
    15691546        psError(PS_ERR_UNKNOWN, true, "-class_id is required");
    1570         return false;
    1571     }
    1572     psString stats = psMetadataLookupStr(&status, config->args, "-stats");
    1573     if (!status) {
    1574         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
    1575         return false;
    1576     }
    1577     if (!stats) {
    1578         psError(PS_ERR_UNKNOWN, true, "-stats is required");
    15791547        return false;
    15801548    }
     
    16491617                exp_id,
    16501618                class_id,
    1651                 stats,
    16521619                recipe
    16531620            );
     
    17041671    PS_ASSERT_PTR_NON_NULL(config, false);
    17051672 
    1706     // det_id, exp_id, stats, & recipe are required
     1673    // det_id, exp_id, & recipe are required
    17071674    bool status = false;
    17081675    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     
    17221689    if (!exp_id) {
    17231690        psError(PS_ERR_UNKNOWN, true, "-exp_id is required");
    1724         return false;
    1725     }
    1726     psString stats = psMetadataLookupStr(&status, config->args, "-stats");
    1727     if (!status) {
    1728         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats");
    1729         return false;
    1730     }
    1731     if (!stats) {
    1732         psError(PS_ERR_UNKNOWN, true, "-stats is required");
    17331691        return false;
    17341692    }
     
    17891747                iteration,
    17901748                exp_id,
    1791                 stats,
    17921749                recipe,
    17931750                accept
     
    20992056            inputExp->imfiles,
    21002057            inputExp->filter,
    2101             inputExp->stats
     2058            inputExp->airmass,
     2059            inputExp->ra,
     2060            inputExp->decl,
     2061            inputExp->exp_time,
     2062            inputExp->background
    21022063        );
    21032064        psArrayAdd(newInputExps, 0, newInputExp);
  • trunk/ippTools/src/dettoolConfig.c

    r8041 r8120  
    7979    psMetadataAddStr(addprocArgs, PS_LIST_TAIL, "-uri",  0,
    8080        "define URI (required)", NULL);
    81     psMetadataAddStr(addprocArgs, PS_LIST_TAIL, "-stats",  0,
    82         "define stat (required)", NULL);
    8381    psMetadataAddStr(addprocArgs, PS_LIST_TAIL, "-recip",  0,
    8482        "define recipe (required)", NULL);
     
    111109    psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-uri",  0,
    112110        "define URI (required)", NULL);
    113     psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-stats",  0,
    114         "define stat (required)", NULL);
    115111    psMetadataAddStr(addstacArgs, PS_LIST_TAIL, "-recip",  0,
    116112        "define recipe (required)", NULL);
     
    124120    psMetadataAddStr(stacArgs, PS_LIST_TAIL, "-class_id",  0,
    125121        "search for class ID", NULL);
    126     psMetadataAddStr(stacArgs, PS_LIST_TAIL, "-stats",  0,
    127         "search for stats", NULL);
    128122    psMetadataAddStr(stacArgs, PS_LIST_TAIL, "-recip",  0,
    129123        "search for recipe", NULL);
     
    137131    psMetadataAddStr(stacframeArgs, PS_LIST_TAIL, "-class_id",  0,
    138132        "search for class ID", NULL);
    139     psMetadataAddStr(stacframeArgs, PS_LIST_TAIL, "-stats",  0,
    140         "search for stats", NULL);
    141133    psMetadataAddStr(stacframeArgs, PS_LIST_TAIL, "-recip",  0,
    142134        "search for recipe", NULL);
     
    152144    psMetadataAddStr(addnormalizedArgs, PS_LIST_TAIL, "-uri",  0,
    153145        "define URI (required)", NULL);
    154     psMetadataAddStr(addnormalizedArgs, PS_LIST_TAIL, "-stats",  0,
    155         "define stat (required)", NULL);
    156146    psMetadataAddStr(addnormalizedArgs, PS_LIST_TAIL, "-recip",  0,
    157147        "define recipe (required)", NULL);
     
    165155    psMetadataAddStr(normalizedArgs, PS_LIST_TAIL, "-class_id",  0,
    166156        "search for class ID", NULL);
    167     psMetadataAddStr(normalizedArgs, PS_LIST_TAIL, "-stats",  0,
    168         "search for stats", NULL);
    169157    psMetadataAddStr(normalizedArgs, PS_LIST_TAIL, "-recip",  0,
    170158        "search for recipe", NULL);
     
    178166    psMetadataAddStr(normalizedframeArgs, PS_LIST_TAIL, "-class_id",  0,
    179167        "search for class ID", NULL);
    180     psMetadataAddStr(normalizedframeArgs, PS_LIST_TAIL, "-stats",  0,
    181         "search for stats", NULL);
    182168    psMetadataAddStr(normalizedframeArgs, PS_LIST_TAIL, "-recip",  0,
    183169        "search for recipe", NULL);
     
    193179    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-class_id",  0,
    194180        "define class ID (required)", NULL);
    195     psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-stats",  0,
    196         "define stats (required)", NULL);
    197181    psMetadataAddStr(addresidArgs, PS_LIST_TAIL, "-recip",  0,
    198182        "define recipe (required)", NULL);
     
    208192    psMetadataAddStr(residArgs, PS_LIST_TAIL, "-class_id",  0,
    209193        "search for class ID", NULL);
    210     psMetadataAddStr(residArgs, PS_LIST_TAIL, "-stats",  0,
    211         "search for stats", NULL);
    212194    psMetadataAddStr(residArgs, PS_LIST_TAIL, "-recip",  0,
    213195        "search for recipe", NULL);
     
    221203    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,
    222204        "define detrend ID (required)", NULL);
    223     psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-stats",  0,
    224         "define stats (required)", NULL);
    225205    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-recip",  0,
    226206        "define recipe (required)", NULL);
     
    236216    psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-exp_id",  0,
    237217        "search for exp ID", NULL);
    238     psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-stats",  0,
    239         "search for stats", NULL);
    240218    psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-recip",  0,
    241219        "search for recipe", NULL);
     
    468446    }
    469447    addWhereStr(filter);
    470     addWhereStr(stats);
    471448    addWhereStr(recipe);
    472449    {
  • trunk/ippTools/src/guidetool.c

    r7038 r8120  
    1010static bool pendingMode(pxConfig *config);
    1111static bool defineMode(pxConfig *config);
    12 static p1PendingExpRow *rawScienceTop1PendingExp(pxConfig *config, rawScienceExpRow *raw);
     12static p1PendingExpRow *rawScienceTop1PendingExp(pxConfig *config, rawScienceExpRow *exp);
    1313
    1414int main(int argc, char **argv)
     
    104104}
    105105
    106 static p1PendingExpRow *rawScienceTop1PendingExp(pxConfig *config, rawScienceExpRow *raw)
     106static p1PendingExpRow *rawScienceTop1PendingExp(pxConfig *config, rawScienceExpRow *exp)
    107107{
     108    PS_ASSERT_PTR_NON_NULL(config, NULL);
     109    PS_ASSERT_PTR_NON_NULL(exp, NULL);
     110
     111    bool status = false;
     112    psString filter = psMetadataLookupStr(&status, config->args, "-filter");
     113    if (!status) {
     114        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter");
     115        return false;
     116    }
     117    if (!filter) {
     118        psError(PS_ERR_UNKNOWN, true, "-filter is required");
     119        return false;
     120    }
     121    psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass");
     122    if (!status) {
     123        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass");
     124        return false;
     125    }
     126    if (!airmass) {
     127        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     128        return false;
     129    }
     130    psF64 ra = psMetadataLookupF64(&status, config->args, "-ra");
     131    if (!status) {
     132        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra");
     133        return false;
     134    }
     135    if (!ra) {
     136        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     137        return false;
     138    }
     139    psF64 dec = psMetadataLookupF64(&status, config->args, "-dec");
     140    if (!status) {
     141        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -dec");
     142        return false;
     143    }
     144    if (!dec) {
     145        psError(PS_ERR_UNKNOWN, true, "-dec is required");
     146        return false;
     147    }
     148    psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time");
     149    if (!status) {
     150        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time");
     151        return false;
     152    }
     153    if (!exp_time) {
     154        psError(PS_ERR_UNKNOWN, true, "-exp_time is required");
     155        return false;
     156    }
     157    psF64 background = psMetadataLookupF64(&status, config->args, "-background");
     158    if (!status) {
     159        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background");
     160        return false;
     161    }
     162    if (!exp_time) {
     163        psError(PS_ERR_UNKNOWN, true, "-background is required");
     164        return false;
     165    }
     166
    108167    return p1PendingExpRowAlloc(
    109         raw->exp_id,
    110         raw->camera,
    111         raw->telescope,
    112         raw->exp_type,
    113 //        newExp->class,
    114         raw->imfiles,
    115         raw->filter,
    116         raw->stats,
    117         "my recipe",                    //recipe
    118         0xff                            // XXX calc version number
     168        exp->exp_id,
     169        exp->camera,
     170        exp->telescope,
     171        exp->exp_type,
     172        exp->imfiles,
     173        filter,
     174        airmass,
     175        ra,
     176        dec,
     177        exp_time,
     178        background,
     179        "my recipe",
     180        0xff // XXX calc version number
    119181    );
    120182}
  • trunk/ippTools/src/guidetoolConfig.c

    r7063 r8120  
    4343    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-filter",  0,
    4444        "define filter of interest", NULL);
    45     psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-stats",  0,
    46         "define stats of interest", NULL);
    4745    psMetadataAddStr(pendingArgs, PS_LIST_TAIL, "-recipe",  0,
    4846        "define recipe of interest", NULL);
     
    6462    psMetadataAddStr(defineArgs, PS_LIST_TAIL, "-filter",  0,
    6563        "define filter of interest", NULL);
    66     psMetadataAddStr(defineArgs, PS_LIST_TAIL, "-stats",  0,
    67         "define stats of interest", NULL);
    6864    // these two are inputs NOT search parameters
    6965    psMetadataAddStr(defineArgs, PS_LIST_TAIL, "-recipe",  0,
  • trunk/ippTools/src/p2insertPendingFrames.c

    r8062 r8120  
    4444            rawFrame->exposure->telescope,
    4545            rawFrame->exposure->exp_type,
    46 //            rawFrame->exposure->class,
    4746            rawFrame->exposure->imfiles,
    4847            rawFrame->exposure->filter,
    49             rawFrame->exposure->stats,
     48            rawFrame->exposure->airmass,
     49            rawFrame->exposure->ra,
     50            rawFrame->exposure->decl,
     51            rawFrame->exposure->exp_time,
     52            rawFrame->exposure->background,
    5053            "my recipe",
    5154            0xff,
     
    6265                rawImage->class_id,
    6366                rawImage->uri,
    64                 "my stats",
    6567                "my recipe",
    6668                0xff, // p1
  • trunk/ippTools/src/p2pendingToDone.c

    r8062 r8120  
    2222            pendingFrame->exposure->telescope,
    2323            pendingFrame->exposure->exp_type,
    24 //            pendingFrame->exposure->class,
    2524            pendingFrame->exposure->imfiles,
    2625            pendingFrame->exposure->filter,
    27             pendingFrame->exposure->stats,
     26            pendingFrame->exposure->airmass,
     27            pendingFrame->exposure->ra,
     28            pendingFrame->exposure->decl,
     29            pendingFrame->exposure->exp_time,
     30            pendingFrame->exposure->background,
    2831            "my recipe",
    2932            pendingFrame->exposure->p1_version,
     
    4649                pendingImage->class_id,
    4750                pendingImage->uri,
    48                 "my stats", // stats
    4951                "my recipe", // recipe
    5052                pendingImage->p1_version,
     
    7375        pendingExp->telescope,
    7476        pendingExp->exp_type,
    75 //        pendingExp->class,
    7677        pendingExp->imfiles, // XXX ndone is uneeded?
    7778        pendingExp->filter,
    78         pendingExp->stats,
     79        pendingExp->airmass,
     80        pendingExp->ra,
     81        pendingExp->decl,
     82        pendingExp->exp_time,
     83        pendingExp->background,
    7984        "my recipe",
    8085        pendingExp->p1_version,
  • trunk/ippTools/src/p2rawToPending.c

    r8062 r8120  
    2121            rawFrame->exposure->telescope,
    2222            rawFrame->exposure->exp_type,
    23 //            rawFrame->exposure->class,
    2423            rawFrame->exposure->imfiles,
    2524            rawFrame->exposure->filter,
    26             rawFrame->exposure->stats,
     25            rawFrame->exposure->airmass,
     26            rawFrame->exposure->ra,
     27            rawFrame->exposure->decl,
     28            rawFrame->exposure->exp_time,
     29            rawFrame->exposure->background,
    2730            "my recipe",
    2831            0xff,   // p1
     
    3841                rawImage->class_id,
    3942                rawImage->uri,
    40                 "my stats",      // stats
    4143                "my recipe",     // recipe
    4244                0xff,   // p1
  • trunk/ippTools/src/pxframes.c

    r8062 r8120  
    66
    77#include "pxtools.h"
     8
     9static rawDetrendExpRow *newToRawDetrendExp(pxConfig *config, newExpRow *exp);
    810
    911#define PX_FRAME_ALLOC(frametype, exptype) \
     
    7779PX_FRAME_PRINT(p2PendingFrame, p2PendingImfile);
    7880
    79 
     81// XXX fix the exposure search so that it doesn't dump the entire table
    8082#define PX_FRAME_SEARCH(frametype, exptype, imfiletype) \
    8183psArray *frametype##Search(pxConfig *config) \
     
    8385    PS_ASSERT_PTR_NON_NULL(config, NULL); \
    8486 \
    85     psArray *exposures = exptype##SelectRowObjects(config->dbh, \
    86         config->where, MAX_ROWS); \
     87    psArray *exposures = exptype##SelectRowObjects(config->dbh, NULL, MAX_ROWS); \
    8788    if (!exposures) { \
    8889        psError(PS_ERR_UNKNOWN, false, "no " #exptype " rows found"); \
     
    131132PX_FRAME_SEARCH(p2PendingFrame, p2PendingExp, p2PendingImfile);
    132133
    133 rawScienceFrame *newToRawScienceFrame(newFrame *newFrame)
    134 {
     134
     135bool rawScienceFrameInsert(pxConfig *config, rawScienceFrame *frame)
     136{
     137    PS_ASSERT_PTR_NON_NULL(config, false);
     138    PS_ASSERT_PTR_NON_NULL(config->dbh, false);
     139    PS_ASSERT_PTR_NON_NULL(frame, false);
     140
     141    psDB *dbh = config->dbh;
     142
     143    if (!rawScienceExpInsertObject(dbh, frame->exposure)) {
     144        psError(PS_ERR_UNKNOWN, false, "dbh access failed");
     145        return false;
     146    }
     147
     148    psArray *images = frame->images;
     149    for (long i = 0; i < psArrayLength(images); i++) {
     150        if (!rawImfileInsertObject(dbh, images->data[i])) {
     151            psError(PS_ERR_UNKNOWN, false, "dbh access failed");
     152            return false;
     153        }
     154    }
     155
     156    return true;
     157}
     158
     159rawDetrendFrame *newToRawDetrendFrame(pxConfig *config, newFrame *newFrame)
     160{
     161    newExpRow       *newExp = NULL;
     162
    135163    PS_ASSERT_PTR_NON_NULL(newFrame, NULL);
    136164
    137     newExpRow *newExp = newFrame->exposure;
    138     rawScienceExpRow *rawScienceExp = rawScienceExpRowAlloc(
    139         newExp->exp_id,
    140         newExp->camera,
    141         newExp->telescope,
    142         newExp->exp_type,
    143 //        newExp->class,
    144         newExp->imfiles,
    145         "my filter",
    146         "my stats"
    147     );
     165    newExp = newFrame->exposure;
     166    rawDetrendExpRow *rawDetrendExp = newToRawDetrendExp(config, newExp);
    148167
    149168    psArray *newImages = newFrame->images;
     
    155174            newImfile->class,
    156175            newImfile->class_id,
    157             newImfile->uri,
    158             "my stats"
     176            newImfile->uri
    159177        );
    160178        psArrayAdd(rawImages, 0, rawImfile);
     
    162180    }
    163181
    164     rawScienceFrame *rawScienceFrame = rawScienceFrameAlloc(rawScienceExp, rawImages);
    165     psFree(rawScienceExp);
     182    rawDetrendFrame *rawDetrendFrame = rawDetrendFrameAlloc(rawDetrendExp, rawImages);
     183    psFree(rawDetrendExp);
    166184    psFree(rawImages);
    167185
    168     return rawScienceFrame;
    169 }
    170 
    171 bool rawScienceFrameInsert(pxConfig *config, rawScienceFrame *frame)
     186    return rawDetrendFrame;
     187}
     188
     189bool rawDetrendFrameInsert(pxConfig *config, rawDetrendFrame *frame)
    172190{
    173191    PS_ASSERT_PTR_NON_NULL(config, false);
     
    177195    psDB *dbh = config->dbh;
    178196
    179     if (!rawScienceExpInsertObject(dbh, frame->exposure)) {
     197    if (!rawDetrendExpInsertObject(dbh, frame->exposure)) {
    180198        psError(PS_ERR_UNKNOWN, false, "dbh access failed");
    181199        return false;
     
    193211}
    194212
    195 rawDetrendFrame *newToRawDetrendFrame(newFrame *newFrame)
    196 {
    197     newExpRow       *newExp = NULL;
    198 
    199     PS_ASSERT_PTR_NON_NULL(newFrame, NULL);
    200 
    201     newExp = newFrame->exposure;
    202     rawDetrendExpRow *rawDetrendExp = rawDetrendExpRowAlloc(
    203         newExp->exp_id,
    204         newExp->camera,
    205         newExp->telescope,
    206         newExp->exp_type,
    207 //        newExp->class,
    208         newExp->imfiles,
    209         "my filter",
    210         "my stats"
     213static rawDetrendExpRow *newToRawDetrendExp(pxConfig *config, newExpRow *exp)
     214{
     215    PS_ASSERT_PTR_NON_NULL(config, NULL);
     216    PS_ASSERT_PTR_NON_NULL(exp, NULL);
     217
     218    bool status = false;
     219    psString filter = psMetadataLookupStr(&status, config->args, "-filter");
     220    if (!status) {
     221        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter");
     222        return false;
     223    }
     224    if (!filter) {
     225        psError(PS_ERR_UNKNOWN, true, "-filter is required");
     226        return false;
     227    }
     228    psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass");
     229    if (!status) {
     230        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass");
     231        return false;
     232    }
     233    if (isnan(airmass)) {
     234        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     235        return false;
     236    }
     237    psF64 ra = psMetadataLookupF64(&status, config->args, "-ra");
     238    if (!status) {
     239        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra");
     240        return false;
     241    }
     242    if (isnan(ra)) {
     243        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     244        return false;
     245    }
     246    psF64 decl = psMetadataLookupF64(&status, config->args, "-decl");
     247    if (!status) {
     248        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl");
     249        return false;
     250    }
     251    if (isnan(decl)) {
     252        psError(PS_ERR_UNKNOWN, true, "-decl is required");
     253        return false;
     254    }
     255    psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time");
     256    if (isnan(exp_time)) {
     257        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time");
     258        return false;
     259    }
     260    if (!exp_time) {
     261        psError(PS_ERR_UNKNOWN, true, "-exp_time is required");
     262        return false;
     263    }
     264    psF64 background = psMetadataLookupF64(&status, config->args, "-background");
     265    if (!status) {
     266        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background");
     267        return false;
     268    }
     269    if (!exp_time) {
     270        psError(PS_ERR_UNKNOWN, true, "-background is required");
     271        return false;
     272    }
     273
     274    return rawDetrendExpRowAlloc(
     275        exp->exp_id,
     276        exp->camera,
     277        exp->telescope,
     278        exp->exp_type,
     279        exp->imfiles,
     280        filter,
     281        airmass,
     282        ra,
     283        decl,
     284        exp_time,
     285        background
    211286    );
    212 
    213     psArray *newImages = newFrame->images;
    214     psArray *rawImages = psArrayAlloc(psArrayLength(newImages));
    215     for (long i = 0; i < psArrayLength(newImages); i++) {
    216         newImfileRow *newImfile = newImages->data[i];
    217         rawImfileRow *rawImfile = rawImfileRowAlloc(
    218             newImfile->exp_id,
    219             newImfile->class,
    220             newImfile->class_id,
    221             newImfile->uri,
    222             "my stats"
    223         );
    224         psArrayAdd(rawImages, 0, rawImfile);
    225         psFree(rawImfile);
    226     }
    227 
    228     rawDetrendFrame *rawDetrendFrame = rawDetrendFrameAlloc(rawDetrendExp, rawImages);
    229     psFree(rawDetrendExp);
    230     psFree(rawImages);
    231 
    232     return rawDetrendFrame;
    233 }
    234 
    235 bool rawDetrendFrameInsert(pxConfig *config, rawDetrendFrame *frame)
    236 {
    237     PS_ASSERT_PTR_NON_NULL(config, false);
    238     PS_ASSERT_PTR_NON_NULL(config->dbh, false);
    239     PS_ASSERT_PTR_NON_NULL(frame, false);
    240 
    241     psDB *dbh = config->dbh;
    242 
    243     if (!rawDetrendExpInsertObject(dbh, frame->exposure)) {
    244         psError(PS_ERR_UNKNOWN, false, "dbh access failed");
    245         return false;
    246     }
    247 
    248     psArray *images = frame->images;
    249     for (long i = 0; i < psArrayLength(images); i++) {
    250         if (!rawImfileInsertObject(dbh, images->data[i])) {
    251             psError(PS_ERR_UNKNOWN, false, "dbh access failed");
    252             return false;
    253         }
    254     }
    255 
    256     return true;
    257 }
     287}
  • trunk/ippTools/src/pxtools.h

    r8061 r8120  
    131131psArray *newFrameSearch(pxConfig *config);
    132132
    133 rawScienceFrame *newToRawScienceFrame(newFrame *newFrame);
    134133bool rawScienceFrameInsert(pxConfig *config, rawScienceFrame *frame);
    135 rawDetrendFrame *newToRawDetrendFrame(newFrame *newFrame);
     134rawDetrendFrame *newToRawDetrendFrame(pxConfig *config, newFrame *newFrame);
    136135bool rawDetrendFrameInsert(pxConfig *config, rawDetrendFrame *frame);
    137136
  • trunk/ippTools/src/regtool.c

    r8042 r8120  
    1212static psArray *newFrameSearchPending(pxConfig *config);
    1313static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp);
    14 static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp);
     14static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *newExp);
    1515static p2PendingImfileRow *newImfileToP2PendingImfile(newImfileRow *newImfile);
     16static rawScienceFrame *newToRawScienceFrame(pxConfig *config, newFrame *newFrame);
     17static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp);
     18
    1619
    1720# define MODECASE(caseName, func) \
     
    8992    // insert 'new' rawScience & detrendframes
    9093    if (psArrayLength(new) > 0) {
     94        // start a transaction so we don't end up file raw* frames but no
     95        // p2Pending*, etc.
     96        if (!psDBTransaction(config->dbh)) {
     97            psError(PS_ERR_UNKNOWN, false, "database error");
     98            psFree(exp);
     99            psFree(new);
     100            return false;
     101        }
     102
    91103        for (long i = 0; i < psArrayLength(new); i++) {
    92104            newFrame *newFrame = new->data[i];
    93105            if (detrend) {
    94106                // it's a detrend frame
    95                 rawDetrendFrame *frame = newToRawDetrendFrame(newFrame);
     107                rawDetrendFrame *frame = newToRawDetrendFrame(config, newFrame);
    96108                if (!frame) {
    97109                    psError(PS_ERR_UNKNOWN, false, "failed to convert new frame into a detrend frame");
     
    100112                }
    101113                if (!rawDetrendFrameInsert(config, frame)) {
     114                    // rollback
     115                    if (!psDBRollback(config->dbh)) {
     116                        psError(PS_ERR_UNKNOWN, false, "database error");
     117                    }
    102118                    psError(PS_ERR_UNKNOWN, false, "failed to insert frame into the database");
    103119                    psFree(frame);
     
    112128            // it's a science frame
    113129            // insert into into rawScienceExp
    114             rawScienceFrame *frame = newToRawScienceFrame(newFrame);
     130            rawScienceFrame *frame = newToRawScienceFrame(config, newFrame);
    115131            if (!frame) {
     132                // rollback
     133                if (!psDBRollback(config->dbh)) {
     134                    psError(PS_ERR_UNKNOWN, false, "database error");
     135                }
    116136                psError(PS_ERR_UNKNOWN, false, "failed to convert new frame into a science frame");
    117137                psFree(new);
     
    119139            }
    120140            if (!rawScienceFrameInsert(config, frame)) {
     141                // rollback
     142                if (!psDBRollback(config->dbh)) {
     143                    psError(PS_ERR_UNKNOWN, false, "database error");
     144                }
    121145                psError(PS_ERR_UNKNOWN, false, "failed to insert frame into the database");
    122146                psFree(frame);
     
    127151
    128152            // insert into into p2PendingExp
    129             p2PendingExpRow *exp = newToP2PendingExp(newFrame->exposure);
     153            // XXX add a newToP2PendingFrame()
     154            // XXX add a p2PendingFrameInsert()
     155            p2PendingExpRow *exp = newToP2PendingExp(config, newFrame->exposure);
    130156            if (!exp) {
     157                // rollback
     158                if (!psDBRollback(config->dbh)) {
     159                    psError(PS_ERR_UNKNOWN, false, "database error");
     160                }
    131161                psError(PS_ERR_UNKNOWN, false, "failed to convert newExp into a p2PendingExp");
    132162                psFree(new);
    133163                return false;
    134164            }
     165
    135166            if (!p2PendingExpInsertObject(config->dbh, exp)) {
     167                // rollback
     168                if (!psDBRollback(config->dbh)) {
     169                    psError(PS_ERR_UNKNOWN, false, "database error");
     170                }
    136171                psError(PS_ERR_UNKNOWN, false, "failed to insert p2PendingExp into the database");
    137172                psFree(exp);
     
    145180                p2PendingImfileRow *imfile = newImfileToP2PendingImfile(newFrame->images->data[i]);
    146181                if (!p2PendingImfileInsertObject(config->dbh, imfile)) {
    147                 psError(PS_ERR_UNKNOWN, false, "failed to insert p2PendingImfile into the database");
     182                    // rollback
     183                    if (!psDBRollback(config->dbh)) {
     184                        psError(PS_ERR_UNKNOWN, false, "database error");
     185                    }
     186                    psError(PS_ERR_UNKNOWN, false, "failed to insert p2PendingImfile into the database");
    148187                    psFree(imfile);
    149188                    psFree(new);
     
    152191                psFree(imfile);
    153192            }
     193        }
     194        // point of no return for p2Pending[Exp|Imfile]
     195        if (!psDBCommit(config->dbh)) {
     196            psError(PS_ERR_UNKNOWN, false, "database error");
     197            return false;
    154198        }
    155199    }
     
    231275        newExp->telescope,
    232276        newExp->exp_type,
    233 //        newExp->class,
    234277        newExp->imfiles,
    235278        "my filter",
    236         "my stats",
     279        0.1, // airmass
     280        0.2, // ra
     281        0.3, // dec
     282        0.4, // exp time
     283        0.5, // background
    237284        "my recipe",
    238285        0xff // XXX calc version number
     
    240287}
    241288
    242 static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp)
    243 {
     289static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *exp)
     290{
     291    PS_ASSERT_PTR_NON_NULL(config, NULL);
     292    PS_ASSERT_PTR_NON_NULL(exp, NULL);
     293
     294    bool status = false;
     295    psString filter = psMetadataLookupStr(&status, config->args, "-filter");
     296    if (!status) {
     297        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter");
     298        return false;
     299    }
     300    if (!filter) {
     301        psError(PS_ERR_UNKNOWN, true, "-filter is required");
     302        return false;
     303    }
     304    psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass");
     305    if (!status) {
     306        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass");
     307        return false;
     308    }
     309    if (isnan(airmass)) {
     310        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     311        return false;
     312    }
     313    psF64 ra = psMetadataLookupF64(&status, config->args, "-ra");
     314    if (!status) {
     315        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra");
     316        return false;
     317    }
     318    if (isnan(ra)) {
     319        psError(PS_ERR_UNKNOWN, true, "-ra is required");
     320        return false;
     321    }
     322    psF64 decl = psMetadataLookupF64(&status, config->args, "-decl");
     323    if (!status) {
     324        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl");
     325        return false;
     326    }
     327    if (isnan(decl)) {
     328        psError(PS_ERR_UNKNOWN, true, "-decl is required");
     329        return false;
     330    }
     331    psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time");
     332    if (!status) {
     333        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time");
     334        return false;
     335    }
     336    if (isnan(exp_time)) {
     337        psError(PS_ERR_UNKNOWN, true, "-exp_time is required");
     338        return false;
     339    }
     340    psF64 background = psMetadataLookupF64(&status, config->args, "-background");
     341    if (!status) {
     342        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background");
     343        return false;
     344    }
     345    if (isnan(background)) {
     346        psError(PS_ERR_UNKNOWN, true, "-background is required");
     347        return false;
     348    }
     349
    244350    return p2PendingExpRowAlloc(
    245         newExp->exp_id,
    246         newExp->camera,
    247         newExp->telescope,
    248         newExp->exp_type,
    249 //        newExp->class,
    250         newExp->imfiles,
    251         "my filter",
    252         "my stats",
     351        exp->exp_id,
     352        exp->camera,
     353        exp->telescope,
     354        exp->exp_type,
     355        exp->imfiles,
     356        filter,
     357        airmass,
     358        ra,
     359        decl,
     360        exp_time,
     361        background,
    253362        "my recipe",
    254363        0xff, // XXX calc version number
     
    263372        newImfile->class_id,
    264373        newImfile->uri,
    265         "my stats",
    266374        "my recipe",
    267375        0xff, // XXX calc version number
     
    269377    );
    270378}
     379
     380static rawScienceFrame *newToRawScienceFrame(pxConfig *config, newFrame *newFrame)
     381{
     382    PS_ASSERT_PTR_NON_NULL(config, NULL);
     383    PS_ASSERT_PTR_NON_NULL(newFrame, NULL);
     384
     385    newExpRow *newExp = newFrame->exposure;
     386    rawScienceExpRow *rawScienceExp = newToRawScienceExp(config, newExp);
     387    if (!rawScienceExp) {
     388        psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawScienceExp");
     389        return NULL;
     390    }
     391
     392    psArray *newImages = newFrame->images;
     393    psArray *rawImages = psArrayAlloc(psArrayLength(newImages));
     394    for (long i = 0; i < psArrayLength(newImages); i++) {
     395        newImfileRow *newImfile = newImages->data[i];
     396        rawImfileRow *rawImfile = rawImfileRowAlloc(
     397            newImfile->exp_id,
     398            newImfile->class,
     399            newImfile->class_id,
     400            newImfile->uri
     401        );
     402        psArrayAdd(rawImages, 0, rawImfile);
     403        psFree(rawImfile);
     404    }
     405
     406    rawScienceFrame *rawScienceFrame = rawScienceFrameAlloc(rawScienceExp, rawImages);
     407    psFree(rawScienceExp);
     408    psFree(rawImages);
     409
     410    return rawScienceFrame;
     411}
     412
     413static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp)
     414{
     415    PS_ASSERT_PTR_NON_NULL(config, NULL);
     416    PS_ASSERT_PTR_NON_NULL(exp, NULL);
     417
     418    bool status = false;
     419    psString filter = psMetadataLookupStr(&status, config->args, "-filter");
     420    if (!status) {
     421        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter");
     422        return NULL;
     423    }
     424    if (!filter) {
     425        psError(PS_ERR_UNKNOWN, true, "-filter is required");
     426        return NULL;
     427    }
     428    psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass");
     429    if (!status) {
     430        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass");
     431        return NULL;
     432    }
     433    if (isnan(airmass)) {
     434        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     435        return NULL;
     436    }
     437    psF64 ra = psMetadataLookupF64(&status, config->args, "-ra");
     438    if (!status) {
     439        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra");
     440        return NULL;
     441    }
     442    if (isnan(ra)) {
     443        psError(PS_ERR_UNKNOWN, true, "-airmass is required");
     444        return NULL;
     445    }
     446    psF64 decl = psMetadataLookupF64(&status, config->args, "-decl");
     447    if (!status) {
     448        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl");
     449        return NULL;
     450    }
     451    if (isnan(decl)) {
     452        psError(PS_ERR_UNKNOWN, true, "-decl is required");
     453        return NULL;
     454    }
     455    psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time");
     456    if (!status) {
     457        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time");
     458        return NULL;
     459    }
     460    if (isnan(exp_time)) {
     461        psError(PS_ERR_UNKNOWN, true, "-exp_time is required");
     462        return NULL;
     463    }
     464    psF64 background = psMetadataLookupF64(&status, config->args, "-background");
     465    if (!status) {
     466        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background");
     467        return NULL;
     468    }
     469    if (isnan(background)) {
     470        psError(PS_ERR_UNKNOWN, true, "-background is required");
     471        return NULL;
     472    }
     473
     474    return rawScienceExpRowAlloc(
     475        exp->exp_id,
     476        exp->camera,
     477        exp->telescope,
     478        exp->exp_type,
     479        exp->imfiles,
     480        filter,
     481        airmass,
     482        ra,
     483        decl,
     484        exp_time,
     485        background
     486    );
     487}
     488
     489
  • trunk/ippTools/src/regtoolConfig.c

    r8075 r8120  
    44
    55#include <pmConfig.h>
     6#include <math.h>
    67
    78#include "pxtools.h"
     
    3839    psMetadata *updateArgs = psMetadataAlloc();
    3940    psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-exp_id",  0,
    40         "define class", NULL);
    41     psMetadataAddBool(updateArgs, PS_LIST_TAIL, "-detrend",  0,
    42         "declare this as detrend data", false);
     41        "exp_id to operate on", NULL);
    4342    psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-filter",  0,
    44         "define filter of interest", NULL);
    45     psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-stat",  0,
    46         "define URL", NULL);
     43        "define filter ", NULL);
     44    psMetadataAddF32(updateArgs, PS_LIST_TAIL, "-airmass",  0,
     45        "define airmass", NAN);
     46    psMetadataAddF64(updateArgs, PS_LIST_TAIL, "-ra",  0,
     47        "define RA", NAN);
     48    psMetadataAddF64(updateArgs, PS_LIST_TAIL, "-decl",  0,
     49        "define DEC", NAN);
     50    psMetadataAddF32(updateArgs, PS_LIST_TAIL, "-exp_time",  0,
     51        "define exposure time", NAN);
     52    psMetadataAddF64(updateArgs, PS_LIST_TAIL, "-background",  0,
     53        "define exposue background", NAN);
     54    /*
    4755    psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-recip",  0,
    4856        "define URL", NULL);
    4957    psMetadataAddStr(updateArgs, PS_LIST_TAIL, "-mosiac",  0,
    5058        "define URL", NULL);
     59    */
     60    psMetadataAddBool(updateArgs, PS_LIST_TAIL, "-detrend",  0,
     61        "declare this as detrend data", false);
    5162
    5263#define PXTOOL_MODE(option, modeval, argset) \
Note: See TracChangeset for help on using the changeset viewer.