static int worker(const SeparationFlags* sf)
{
    AstronomyParameters ap;
    BackgroundParameters bgp = EMPTY_BACKGROUND_PARAMETERS;
    Streams streams = EMPTY_STREAMS;
    IntegralArea* ias = NULL;
    StreamConstants* sc = NULL;
    SeparationResults* results = NULL;
    int rc;
    CLRequest clr;

    memset(&ap, 0, sizeof(ap));
    memset(&clr, 0, sizeof(clr));

    setCLReqFlags(&clr, sf);
    ias = prepareParameters(sf, &ap, &bgp, &streams);
    if (!ias)
        return 1;

    rc = setAstronomyParameters(&ap, &bgp);
    if (rc)
    {
        mwFreeA(ias);
        freeStreams(&streams);
        return 1;
    }

    setExpStreamWeights(&ap, &streams);
    sc = getStreamConstants(&ap, &streams);
    if (!sc)
    {
        mw_printf("Failed to get stream constants\n");
        mwFreeA(ias);
        freeStreams(&streams);
        return 1;
    }

    results = newSeparationResults(ap.number_streams);

    rc = evaluate(results, &ap, ias, &streams, sc, sf->star_points_file,
                  &clr, sf->do_separation, sf->ignoreCheckpoint, sf->separation_outfile);
    if (rc)
        mw_printf("Failed to calculate likelihood\n");

    printSeparationResults(results, ap.number_streams);

    mwFreeA(ias);
    mwFreeA(sc);
    freeStreams(&streams);
    freeSeparationResults(results);

    return rc;
}
static IntegralArea* prepareParameters(const SeparationFlags* sf,
                                       AstronomyParameters* ap,
                                       BackgroundParameters* bgp,
                                       Streams* streams)
{
    IntegralArea* ias;

    ias = setupSeparation(ap, bgp, streams, sf);
    /* Try the new file first. If that doesn't work, try the old one. */
    if (!ias)
    {
        mw_printf("Error reading astronomy parameters from file '%s'\n"
                  "  Trying old parameters file\n", sf->ap_file);
        ias = readParameters(sf->ap_file, ap, bgp, streams);
    }

    if (!ias)
    {
        mw_printf("Failed to read parameters file\n");
        return NULL;
    }

    if (sf->numArgs && setParameters(ap, bgp, streams, sf->numArgs, sf->nForwardedArgs))
    {
        mwFreeA(ias);
        freeStreams(streams);
        return NULL;
    }

    return ias;
}
Пример #3
0
VegasFSRender::~VegasFSRender() {
  CloseFile();
  freeStreams();
  if (m_pTemplate) {
    m_pClassBackPointer->freeTemplate(m_pTemplate);
  }
  return;
}
//Needs to loop to account for number of WUs being crunched
static int worker(const SeparationFlags* sf)
{
    AstronomyParameters ap;
    BackgroundParameters bgp = EMPTY_BACKGROUND_PARAMETERS;
    Streams streams = EMPTY_STREAMS;
    IntegralArea* ias = NULL;
    StreamConstants* sc = NULL;
    SeparationResults* results = NULL;
    int rc;
    CLRequest clr;

    memset(&ap, 0, sizeof(ap));
    memset(&clr, 0, sizeof(clr));

    ap.modfit = sf->modfit;

    if(sf->background)
    {
    	ap.background_profile = BROKEN_POWER_LAW;
    }
    else
    {
    	ap.background_profile = FAST_HERNQUIST;
    }

    setCLReqFlags(&clr, sf);
    /*Assume we are crunching at least 1 work unit (These numbers will be properly set in prepareParameters when the parameter file is read)*/

    ias = prepareParameters(sf, &ap, &bgp, &streams);
    if (!ias)
        return 1;

    if(sf->nForwardedArgs)
    {
        ap.totalWUs = sf->nForwardedArgs/ap.params_per_workunit;
    }
    else
    {
        ap.totalWUs = 1;
    }
    mw_printf("<number_WUs> %d </number_WUs>\n", ap.totalWUs);
    mw_printf("<number_params_per_WU> %d </number_params_per_WU>\n", ap.params_per_workunit);
    int ignoreCheckpoint = sf->ignoreCheckpoint;
    for(ap.currentWU = 0; ap.currentWU < ap.totalWUs; ap.currentWU++)
    {

        if (sf->numArgs && setParameters(&ap, &bgp, &streams, &(sf->numArgs[ap.params_per_workunit * ap.currentWU]), ap.params_per_workunit))
        {
            mwFreeA(ias);
            freeStreams(&streams);
            return 1;
        }

        rc = setAstronomyParameters(&ap, &bgp);
        if (rc)
        {
            mwFreeA(ias);
            freeStreams(&streams);
            return 1;
        }

        setExpStreamWeights(&ap, &streams);
        sc = getStreamConstants(&ap, &streams);
        if (!sc)
        {
            mw_printf("Failed to get stream constants\n");
            mwFreeA(ias);
            freeStreams(&streams);
            return 1;
        }

        results = newSeparationResults(ap.number_streams);
        int currentWU = ap.currentWU;
        rc = evaluate(results, &ap, ias, &streams, sc, sf->LikelihoodToText, sf->star_points_file,
                  &clr, sf->do_separation, &ignoreCheckpoint, sf->separation_outfile);
        if (rc)
            mw_printf("Failed to calculate likelihood\n");
    }
    
    mwFreeA(ias);
    mwFreeA(sc);
    freeStreams(&streams);
    if(results) freeSeparationResults(results);

    return rc;
}