IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 3:12:59 PM (17 years ago)
Author:
eugene
Message:

defining test unthreaded versions for these functions to avoid hitting the psThreadJob array; remove eventually

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotApResid.c

    r21183 r21359  
    11# include "psphotInternal.h"
     2
     3bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal);
    24
    35# define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; }
     
    2931        nThreads = 0;
    3032    }
    31     // nThreads = 0; // XXX until testing is complete, do not thread this function
    3233
    3334    bool measureAptrend = psMetadataLookupBool (&status, recipe, "MEASURE.APTREND");
     
    9495        for (int j = 0; j < cells->n; j++) {
    9596
    96             // allocate a job -- if threads are not defined, this just runs the job
    97             psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS");
    98 
    99             psArrayAdd(job->args, 1, cells->data[j]); // sources
    100             psArrayAdd(job->args, 1, psf);
    101             PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
    102             PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    103 
    104             PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
    105             PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nfail
    106 
    107             if (!psThreadJobAddPending(job)) {
     97            if (nThreads) {
     98                // allocate a job -- if threads are not defined, this just runs the job
     99                psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS");
     100
     101                psArrayAdd(job->args, 1, cells->data[j]); // sources
     102                psArrayAdd(job->args, 1, psf);
     103                PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
     104                PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     105
     106                PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nskip
     107                PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for Nfail
     108
     109                if (!psThreadJobAddPending(job)) {
     110                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     111                    psFree (job);
     112                    return false;
     113                }
     114                psFree(job);
     115            } else {
     116                int nskip = 0;
     117                int nfail = 0;
     118
     119                if (!psphotApResidMags_Unthreaded (&nskip, &nfail, sources, psf, photMode, maskVal)) {
     120                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     121                    return false;
     122                }
     123                Nskip += nskip;
     124                Nfail += nfail;
     125            }           
     126
     127        }
     128
     129        if (nThreads) {
     130            // wait for the threads to finish and manage results
     131            if (!psThreadPoolWait (false)) {
    108132                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    109                 psFree (job);
    110133                return false;
    111134            }
    112             psFree(job);
    113 
    114         }
    115 
    116         // wait for the threads to finish and manage results
    117         if (!psThreadPoolWait (false)) {
    118             psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    119             return false;
    120         }
    121 
    122         // we have only supplied one type of job, so we can assume the types here
    123         psThreadJob *job = NULL;
    124         while ((job = psThreadJobGetDone()) != NULL) {
    125             if (job->args->n < 1) {
    126                 fprintf (stderr, "error with job\n");
    127             } else {
    128                 psScalar *scalar = NULL;
    129                 scalar = job->args->data[4];
    130                 Nskip += scalar->data.S32;
    131                 scalar = job->args->data[5];
    132                 Nfail += scalar->data.S32;
     135
     136            // we have only supplied one type of job, so we can assume the types here
     137            psThreadJob *job = NULL;
     138            while ((job = psThreadJobGetDone()) != NULL) {
     139                if (job->args->n < 1) {
     140                    fprintf (stderr, "error with job\n");
     141                } else {
     142                    psScalar *scalar = NULL;
     143                    scalar = job->args->data[4];
     144                    Nskip += scalar->data.S32;
     145                    scalar = job->args->data[5];
     146                    Nfail += scalar->data.S32;
     147                }
     148                psFree(job);
    133149            }
    134             psFree(job);
    135150        }
    136151    }
     
    493508    return true;
    494509}
     510
     511bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal) {
     512
     513    int Nskip = 0;
     514    int Nfail = 0;
     515
     516    for (int i = 0; i < sources->n; i++) {
     517        pmSource *source = (pmSource *) sources->data[i];
     518
     519        if (source->type != PM_SOURCE_TYPE_STAR) SKIPSTAR ("NOT STAR");
     520        if (source->mode &  PM_SOURCE_MODE_SATSTAR) SKIPSTAR ("SATSTAR");
     521        if (source->mode &  PM_SOURCE_MODE_BLEND) SKIPSTAR ("BLEND");
     522        if (source->mode &  PM_SOURCE_MODE_FAIL) SKIPSTAR ("FAIL STAR");
     523        if (source->mode &  PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR");
     524
     525        if (!pmSourceMagnitudes (source, psf, photMode, maskVal)) {
     526            Nskip ++;
     527            psTrace ("psphot", 3, "skip : bad source mag");
     528            continue;
     529        }
     530
     531        if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
     532            Nfail ++;
     533            psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);
     534            continue;
     535        }
     536    }
     537
     538    // change the value of a scalar on the array (wrap this and put it in psArray.h)
     539    *nskip = Nskip;
     540    *nfail = Nfail;
     541
     542    return true;
     543}
Note: See TracChangeset for help on using the changeset viewer.