IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.