IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 14, 2006, 9:09:10 AM (19 years ago)
Author:
magnier
Message:

fixed memory issues, converted to md parsing for i/o

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmDetrendDB.c

    r10102 r10725  
    101101    unsigned int nFail;
    102102
    103     psArray *array = NULL;
    104     psMetadata *answer = NULL;
    105 
    106103    pmDetrendSelectResults *results = pmDetrendSelectResultsAlloc();
    107104
     
    110107    // XXX we need to put in the filter and other restrictions based on the recipe
    111108    // detselect -search -simple returns: DET_ID ITERATION CLASS TYPE
    112     psStringAppend (&line, "detselect -search -simple -inst %s -det_type %s", options->camera, type);
     109    // XXXXX ***** MAJOR HACK ***** Josh dropped INST from detrun, so I am using 'object' for
     110    // now ('object' is not relevant to detrun!!!)
     111    // XXX this operation is not applying the time-based selections yet.
     112    psStringAppend (&line, "detselect -search -inst %s -det_type %s", options->camera, type);
     113
     114    // psStringAppend (&line, "detselect -search -simple -object %s -det_type %s", options->camera, type);
    113115    if (options->filter) {
    114116        psStringAppend (&line, " -filter %s", options->filter);
     
    144146    psTrace("psModules.detrend", 5, "got answer: %s\n", buffer->data);
    145147
    146     array = NULL;
    147     answer = NULL;
    148148    nFail = 0;
    149     # define USE_MDPARSE 0
    150     # if (USE_MDPARSE)
    151 
    152         answer = psMetadataConfigParse (NULL, &nFail, buffer->data, false);
    153     detExp = psMetadataLookupPtr ();
    154     char *levelName = psMetadataLookupStr ();
    155     # endif
    156 
    157     // XXX need to parse the response more robustly
    158     // XXX for now, assume a single line
    159     // XXX we should expect a metadata back (if we call without -simple)
    160     // XXX we should run psMetatdataParseConfig () on the
    161     array = psStringSplitArray (buffer->data, " ", false);
    162 
    163     if (!array) {
    164         psError(PS_ERR_IO, false, "failed to split detselect answer %s\n", buffer->data);
    165         goto failure;
    166     }
    167     if (array->n != 4) {
    168         psError(PS_ERR_IO, false, "invalid number of fields in detselect answer %s (%ld)\n", buffer->data, array->n);
    169         goto failure;
    170     }
    171 
    172     pmFPALevel level = pmFPALevelFromName (array->data[2]);
    173     if (level == PM_FPA_LEVEL_NONE) {
    174         psError(PS_ERR_IO, false, "invalid file level (%s) from detselect\n", (char *)array->data[2]);
    175         goto failure;
    176     }
    177 
    178     results->level = level;
    179     psStringAppend (&results->detID, " -det_id %s -iteration %s ", (char *)array->data[0], (char *)array->data[1]);
     149    psMetadata *answer = psMetadataConfigParse (NULL, &nFail, buffer->data, false);
     150    if (!answer) {
     151        psError(PS_ERR_IO, false, "failed to parse response from detselect\n");
     152        psLogMsg ("psModule.detrend", PS_LOG_ERROR, "detselect response (%d bytes):\n %s\n", buffer->n, buffer->data);
     153        goto failure;
     154    }
     155
     156    psMetadata *md = psMetadataLookupPtr (NULL, answer, "detExp");
     157    if (!md) {
     158        psError(PS_ERR_IO, false, "detselect response is missing 'detExp' Metadata\n");
     159        psLogMsg ("psModule.detrend", PS_LOG_ERROR, "detselect response:\n %s\n", buffer->data);
     160        goto failure;
     161    }
     162
     163    bool mdstatus;
     164    results->level = 0;
     165    int detID = psMetadataLookupS32 (&mdstatus, md, "det_id");
     166    int iteration  = psMetadataLookupS32 (&mdstatus, md, "iteration");
     167
     168    results->detID = NULL; // it should be NULL already from the Alloc above
     169    psStringAppend (&results->detID, " -det_id %d -iteration %d ", detID, iteration);
    180170
    181171    psTrace("psModules.detrend", 5, "generated detID %s\n", results->detID);
    182     psTrace("psModules.detrend", 5, "fileLevel is %d (%s)\n", results->level, (char *)array->data[2]);
    183     psTrace("psModules.detrend", 5, "selected type is %s\n", (char *)array->data[3]);
    184 
    185     psFree (array);
    186     psFree (pipe);
    187     psFree (buffer);
    188     psFree (line);
     172
     173    psFree (answer);
     174    psFree (buffer);
     175    psFree (pipe);
     176    psFree (line);
     177    psFree (time);
    189178    psFree (type);
    190     psFree (time);
    191179    return results;
    192180
    193181failure:
    194     psFree (array);
    195182    psFree (results);
    196183    psFree (pipe);
     
    208195char *pmDetrendFile (const char *detID, const char *classID)
    209196{
     197    unsigned int nFail;
     198
    210199    PS_ASSERT_PTR_NON_NULL(detID, NULL);
    211200    PS_ASSERT_PTR_NON_NULL(classID, NULL);
     
    216205
    217206    // generate the detselect command
    218     psStringAppend (&line, "detselect -select -simple %s -class_id %s", detID, classID);
     207    psStringAppend (&line, "detselect -select %s -class_id %s", detID, classID);
    219208    psTrace("psModules.detrend", 5, "running %s", line);
    220209
     
    239228    psTrace("psModules.detrend", 5, "got answer: %s\n", buffer->data);
    240229
    241     // XXX need to parse the response more robustly
    242     // XXX for now, assume a single line
    243     array = psStringSplitArray (buffer->data, " ", false);
    244 
    245     if (!array) {
    246         psError(PS_ERR_IO, false, "failed to split detselect answer %s\n", buffer->data);
    247         goto failure;
    248     }
    249     if (array->n == 0) {
    250         psError(PS_ERR_IO, true, "empty result set from detselect\n");
    251         goto failure;
    252     }
    253     if (array->n < 5) {
    254         psError(PS_ERR_IO, true, "invalid result set from detselect %s\n", buffer->data);
    255         goto failure;
    256     }
    257 
    258     char *result = psStringCopy (array->data[3]);
     230    psMetadata *answer = psMetadataConfigParse (NULL, &nFail, buffer->data, false);
     231    if (!answer) {
     232        psError(PS_ERR_IO, false, "failed to parse response from detselect\n");
     233        psLogMsg ("psModule.detrend", PS_LOG_ERROR, "detselect response (%d bytes):\n %s\n", buffer->n, buffer->data);
     234        goto failure;
     235    }
     236    psMetadata *md = psMetadataLookupPtr (NULL, answer, "detNormalizedImfile");
     237    if (!md) {
     238        psError(PS_ERR_IO, false, "detselect response is missing 'detNormalizedImfile' Metadata\n");
     239        psLogMsg ("psModule.detrend", PS_LOG_ERROR, "detselect response:\n %s\n", buffer->data);
     240        goto failure;
     241    }
     242
     243    char *result = psStringCopy (psMetadataLookupStr (NULL, md, "uri"));
    259244    psTrace("psModules.detrend", 5, "detrend file: %s\n", result);
    260245
    261     psFree (array);
     246    psFree (answer);
    262247    psFree (pipe);
    263248    psFree (buffer);
Note: See TracChangeset for help on using the changeset viewer.