IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 1, 2006, 12:23:04 PM (20 years ago)
Author:
jhoblitt
Message:

change -pending to only return 'pending' frames
implement -update

File:
1 edited

Legend:

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

    r6262 r6286  
    55static bool pendingMode(pxConfig *config);
    66static bool updateMode(pxConfig *config);
     7static psArray *newFrameSearchPending(pxConfig *config);
    78
    89int main(int argc, char **argv)
     
    3233static bool pendingMode(pxConfig *config)
    3334{
    34     psArray *pendingFrames = newFrameSearch(config);
    35     if (!pendingFrames) {
     35    PS_ASSERT_PTR_NON_NULL(config, false);
     36
     37    psArray *new = newFrameSearchPending(config);
     38    if (!new) {
    3639        psError(PS_ERR_UNKNOWN, false, "no newFrames found");
    3740        return false;
    3841    }
    39     bool status = newFramePrint(stdout, config, pendingFrames);
     42
     43    bool status = newFramePrint(stdout, config, new);
    4044    if (!status) {
    4145        psError(PS_ERR_UNKNOWN, false,"newFramePrint() failed");
     
    4852static bool updateMode(pxConfig *config)
    4953{
    50     // get exp_id/class/class_id/url from the CLI // add the completed imfile to
    51     // the p2DoneImfile tables // remove corresponding entries from the
    52     // p2PendingImfile table // check to see if any p2PendingExps have no
    53     // associated p2PendingImfiles //    if so move the p2PendingExp(s) to
    54     // p2DoneExp
     54    PS_ASSERT_PTR_NON_NULL(config, false);
    5555
    56     // find pending
    57     psArray *pendingImfiles = p2searchPendingImfiles(config);
    58     if (!pendingImfiles) {
    59         psError(PS_ERR_UNKNOWN, false, "no p2PendingImfiles found");
    60         return false;
    61     }
    62     // insert into done
    63     psArray *doneImfiles = p2pendingToDoneImfile(pendingImfiles);
    64     for (int i = 0; i < doneImfiles->n; i++) {
    65         if (!p2DoneImfileInsertObject(config->database, doneImfiles->data[i])) {
    66             psError(PS_ERR_UNKNOWN, false, "database access failed");
    67             return false;
     56    psArray *new = newFrameSearchPending(config);
     57
     58    // insert 'new' rawScience & detrendframes
     59    if (new->n > 0) {
     60        for (long i = 0; i < new->n; i++) {
     61            newFrame *newFrame = new->data[i];
     62            if (strcmp(newFrame->exposure->exp_type, "object") == 0) {
     63                // it's a science frame
     64                rawScienceFrame *rawScienceFrame = newToRawScienceFrame(newFrame);
     65                if (!rawScienceFrameInsert(config, rawScienceFrame)) {
     66                    // error
     67                }
     68            } else {
     69                // it's a detrend frame
     70                rawDetrendFrame *rawDetrendFrame = newToRawDetrendFrame(newFrame);
     71                if (!rawDetrendFrameInsert(config, rawDetrendFrame)) {
     72                    // error
     73                }
     74            }
    6875        }
    6976    }
    70     // delete from pending
    71     if (p2PendingImfileDeleteRowObjects(config->database, pendingImfiles, MAX_ROWS) < 0) {
    72         // there must be atleast 1 Imfile to get this far
    73         psError(PS_ERR_UNKNOWN, false, "database access failed");
     77
     78    return true;
     79}
     80
     81static psArray *newFrameSearchPending(pxConfig *config)
     82{
     83    PS_ASSERT_PTR_NON_NULL(config, NULL);
     84
     85    psArray *new = newFrameSearch(config);
     86    if (!new) {
     87        psError(PS_ERR_UNKNOWN, false, "no newFrames found");
    7488        return false;
    7589    }
    7690
    77     // look for pending exposures
    78     psArray *pendingExps = p2searchPendingExp(config);
    79     if (!pendingExps) {
    80         psError(PS_ERR_UNKNOWN, false, "no p2PendingExps found");
    81         return false;
     91    psArray *raw = rawScienceFrameSearch(config);
     92    if (!raw) {
     93        psError(PS_ERR_UNKNOWN, false, "no rawScienceFrames found");
     94    //    return false;
    8295    }
    8396
    84     for (int i = 0; i < pendingExps->n; i++) {
    85         p2PendingExpRow *pendingExp = pendingExps->data[i];
     97    psArray *rawDetrend = rawDetrendFrameSearch(config);
     98    if (!rawDetrend) {
     99        psError(PS_ERR_UNKNOWN, false, "no rawDetrendFrames found");
     100    //    return false;
     101    }
    86102
    87         psMetadata *where = psMetadataAlloc();
    88         psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", pendingExp->exp_id);
    89         psArray *pendingImfiles = p2PendingImfileSelectRowObjects(config->database, where, MAX_ROWS);
    90         psFree(where)
    91         if (!pendingImfiles) {
    92             // exp has no coresponding imfiles
    93             psArray *nukeMe = psArrayAlloc(1);
    94             nukeMe->n = 0;
    95             psArrayAdd(nukeMe, 0, pendingExp);
    96             bool status = p2PendingExpDeleteRowObjects(config->database, nukeMe, MAX_ROWS);
    97             psFree(nukeMe);
    98             if (!status) {
    99                 psError(PS_ERR_UNKNOWN, false, "database access failed");
    100                 return false;
    101             }
    102             // XXX need a func to convert from p2PendingExp -> p2DoneExp
    103 
    104             p2DoneExpRow *doneExp = p2pendingToDoneExp(pendingExp);
    105             if (!doneExp) {
    106                 psError(PS_ERR_UNKNOWN, false, "p2PendingExp -> p2DoneExp failed");
    107                 return false;
    108             }
    109             if (!p2DoneExpInsertObject(config->database, doneExp)) {
    110                 psError(PS_ERR_UNKNOWN, false, "database access failed");
    111                 return false;
     103    // ignore duplicate raw frames
     104    if (raw) {
     105        for (long i = 0; i < new->n; i++) {
     106            newFrame *newFrame = new->data[i];
     107            for (long j = 0; j < raw->n; j++) {
     108                rawScienceFrame *rawScienceFrame = raw->data[j];
     109                if (strcmp(newFrame->exposure->exp_id,
     110                           rawScienceFrame->exposure->exp_id) == 0) {
     111                    psArrayRemove(new, newFrame);
     112                    // dec the counter as the array just got shorter
     113                    //and we don't want to skip elemnts
     114                    i--;
     115                    break;
     116                }
    112117            }
    113118        }
    114         // skip phase 3 for the time being
    115         psFree(pendingImfiles);
     119        psFree(raw);
    116120    }
    117121
    118     /*
    119     psArray *doneFrames = p2pendingToDone(config, pendingFrames);
    120     if (!doneFrames) {
    121         psError(PS_ERR_UNKNOWN, false, "p2pendingToDone() failed");
    122         return false;
     122    // ignore duplicate rawDetrend frames
     123    if (rawDetrend) {
     124        for (long i = 0; i < new->n; i++) {
     125            newFrame *newFrame = new->data[i];
     126            for (long j = 0; j < rawDetrend->n; j++) {
     127                rawDetrendFrame *rawDetrendFrame = rawDetrend->data[j];
     128                if (strcmp(newFrame->exposure->exp_id,
     129                           rawDetrendFrame->exposure->exp_id) == 0) {
     130                    psArrayRemove(new, newFrame);
     131                    // dec the counter as the array just got shorter
     132                    //and we don't want to skip elemnts
     133                    i--;
     134                    break;
     135                }
     136            }
     137        }
     138        psFree(rawDetrend);
    123139    }
    124     bool status = p2insertDoneFrames(config, doneFrames);
    125     if (!status) {
    126         psError(PS_ERR_UNKNOWN, false, "p2insertDoneFrames() failed");
    127         return false;
    128     }
    129     */
    130140
    131     return true;
     141    return new;
    132142}
Note: See TracChangeset for help on using the changeset viewer.