void CalpontSelectExecutionPlan::columnMap (const ColumnMap& columnMap)
{
	ColumnMap::const_iterator map_it1, map_it2;
	fColumnMap.erase(fColumnMap.begin(), fColumnMap.end());

	SRCP srcp;
	for (map_it2 = columnMap.begin(); map_it2 != columnMap.end(); ++map_it2)
	{
		srcp.reset(map_it2->second->clone());
		fColumnMap.insert(ColumnMap::value_type(map_it2->first, srcp));
	}
}
void CopyFileEfficiently(const string &Filename, const int nExtra, const string &OutputFilename, const float fraction)
{
    map<int, string> ImageTypes;
    ImageTypes[8] = "Unsigned integer";
    ImageTypes[16] = "Signed integer";
    ImageTypes[32] = "Long integer";
    ImageTypes[64] = "Long long integer";
    ImageTypes[-32] = "Floating point";
    ImageTypes[-64] = "Double precision";



    /*  deal with the system memory */
    long TotalSystemMemory = getTotalSystemMemory();
    cout << "System memory: " << TotalSystemMemory / 1024. / 1024. << " MB" << endl;


    float AllowedSystemMemory = fraction * TotalSystemMemory;
    cout << "Using " << AllowedSystemMemory / 1024. / 1024. << " MB (" << fraction * 100 << "%)" << endl;
    


    auto_ptr<FITS> pInfile(new FITS(Filename.c_str(), Read));

    /*  this constructor copies the primary hdu across
     *
     *  which is handy */
    auto_ptr<FITS> pOutfile(new FITS(OutputFilename.c_str(), *(pInfile.get())));

    /* Set the transinj keyword to true */
    pOutfile->pHDU().addKey("TRANSINJ", true, "Contains false transits");


    /*  need to get the dimensions of the data set */
    ExtHDU &CatalogueHDU = pInfile->extension("CATALOGUE");
    ExtHDU &ImagelistHDU = pInfile->extension("IMAGELIST");

    const long nObjects = CatalogueHDU.rows();
    const long nFrames = ImagelistHDU.rows();
    cout << nObjects << " objects found" << endl;
    cout << nFrames << " frames found" << endl;

    const long nTotal = nObjects + nExtra;

    cout << nExtra << " objects will be appended making a total of " << nTotal << " objects" << endl;

    /*  creating the Catalogue HDU */
    /*  ******************************************************************************** */
    /*  get a list of the columns in the catalogue hdu */
    const ColumnMap Columns = CatalogueHDU.column();
    StringVector ColumnNames, ColumnFormats, ColumnUnits;
    for (ColumnMap::const_iterator i=Columns.begin();
            i!=Columns.end();
            ++i)
    {
        //cout << "Found column: " << i->first << endl;
        ColumnNames.push_back(i->first);
        ColumnFormats.push_back(i->second->format());
        ColumnUnits.push_back(i->second->unit());
    }

    /* Need to add the skipdet column */
    ColumnNames.push_back("SKIPDET");
    ColumnFormats.push_back("1I");
    ColumnUnits.push_back("");

    /* Also add the fake transits columns
     *
     * need:
     *  rplanet
     *  rstar
     *  -> depth
     *  separation
     *  inclination
     *  period (sec)
     *  -> width (sec)
     *  -> epoch (sec)
     *
     * */

    /* Start with the already defined ones */
    ColumnNames.push_back("FAKE_PERIOD");
    ColumnNames.push_back("FAKE_WIDTH");
    ColumnNames.push_back("FAKE_DEPTH");
    ColumnNames.push_back("FAKE_EPOCH");

    ColumnFormats.push_back("1D");
    ColumnFormats.push_back("1D");
    ColumnFormats.push_back("1D");
    ColumnFormats.push_back("1J");

    ColumnUnits.push_back("sec");
    ColumnUnits.push_back("sec");
    ColumnUnits.push_back("");
    ColumnUnits.push_back("sec");

    /* And now the extra ones */
    ColumnNames.push_back("FAKE_RP");
    ColumnNames.push_back("FAKE_RS");
    ColumnNames.push_back("FAKE_A");
    ColumnNames.push_back("FAKE_I");

    ColumnFormats.push_back("1D");
    ColumnFormats.push_back("1D");
    ColumnFormats.push_back("1D");
    ColumnFormats.push_back("1D");

    ColumnUnits.push_back("m");
    ColumnUnits.push_back("m");
    ColumnUnits.push_back("m");
    ColumnUnits.push_back("deg");


    /*  create the new hdu */
    Table *NewCatalogueHDU = pOutfile->addTable("CATALOGUE", nTotal, ColumnNames, ColumnFormats, ColumnUnits);
    
//    /* Create a new hdu for the false parameters 
//     
//     Re-use the previous variables  */
//    ColumnNames.resize(0);
//    ColumnFormats.resize(0);
//    ColumnUnits.resize(0);
//    
//    ColumnNames.push_back("ORIGID");
//    ColumnNames.push_back("RPLANET");
//    ColumnNames.push_back("RSTAR");
//    ColumnNames.push_back("INCLINATION");
//    ColumnNames.push_back("PERIOD");
//    ColumnNames.push_back("EPOCH");
//
//    ColumnFormats.push_back("1J");
//    
//    for (int i=0; i<5; ++i)
//        ColumnFormats.push_back("1D");
//    
//    ColumnUnits.push_back("");
//    ColumnUnits.push_back("RJ");
//    ColumnUnits.push_back("RSun");
//    ColumnUnits.push_back("Degrees");
//    ColumnUnits.push_back("Days");
//    ColumnUnits.push_back("JD");
//    
//    pOutfile->addTable("SYNTHETICS", nTotal, ColumnNames, ColumnFormats, ColumnUnits);
    
    



    /*  copy the data across */
    for (ColumnMap::const_iterator i=Columns.begin();
            i!=Columns.end();
            ++i)
    {
        Column &NewColumn = NewCatalogueHDU->column(i->first);

        /*  get the data type */
        string Format = i->second->format();

        if (Format == "1J")
        {
            /*  data type is long */
            vector<long> data;
            i->second->read(data, 1, nObjects);
            NewColumn.write(data, 1);

        }
        else if (Format == "1I")
        {
            /*  data type is int */
            vector<int> data;
            i->second->read(data, 1, nObjects);
            NewColumn.write(data, 1);
        }
        else if (Format == "1E")
        {
            /*  data type is float */
            vector<float> data;
            i->second->read(data, 1, nObjects);
            NewColumn.write(data, 1);
        }
        else if (Format == "26A")
        {
            /*  data type is string */
            vector<string> data;
            i->second->read(data, 1, nObjects);
            NewColumn.write(data, 1);
        }
        else if (Format == "1D")
        {
            /*  data type is double */
            vector<double> data;
            i->second->read(data, 1, nObjects);
            NewColumn.write(data, 1);
        }
        else
        {
            cerr << "Unknown data type: " << Format << endl;
        }
    }

















    /* Creating the imagelist hdu */
    /*  ******************************************************************************** */
    /*  can just copy the hdu directly across */
    pOutfile->copy(ImagelistHDU);

    /*  now copy the image hdus one by one */
    StringVector ImageHDUNames;
    ImageHDUNames.push_back("HJD");
    ImageHDUNames.push_back("FLUX");
    ImageHDUNames.push_back("FLUXERR");
    ImageHDUNames.push_back("CCDX");
    ImageHDUNames.push_back("CCDY");
    ImageHDUNames.push_back("QUALITY");
    ImageHDUNames.push_back("SKYBKG");

    vector<long> naxes(2);
    naxes[0] = nFrames;
    naxes[1] = nTotal;


    for (StringVector::const_iterator i=ImageHDUNames.begin();
            i!=ImageHDUNames.end();
            ++i)
    {
        /*  get the bitpix of the original hdu */
        cout << "Creating the " << *i << " HDU" << endl;
        const long bitpix = pInfile->extension(*i).bitpix();
        cout << "HDU Format: " << ImageTypes[bitpix] << endl;


        /*  add the hdu */
        ExtHDU *NewHDU = pOutfile->addImage(*i, bitpix, naxes);
        ExtHDU &OldHDU = pInfile->extension(*i);
        fitsfile *infptr = pInfile->fitsPointer();
        fitsfile *outfptr = pOutfile->fitsPointer();

        /*  copy the data across one line at a time */
        switch (bitpix)
        {
            case BYTE_IMG:
                CopyImageData<unsigned int>(OldHDU, *NewHDU, infptr, outfptr, AllowedSystemMemory);
                break;
            case SHORT_IMG:
                CopyImageData<int>(OldHDU, *NewHDU, infptr, outfptr, AllowedSystemMemory);
                break;
            case LONG_IMG:
                CopyImageData<long>(OldHDU, *NewHDU, infptr, outfptr, AllowedSystemMemory);
                break;
            case LONGLONG_IMG:
                CopyImageData<long long>(OldHDU, *NewHDU, infptr, outfptr, AllowedSystemMemory);
                break;
            case FLOAT_IMG:
                CopyImageData<float>(OldHDU, *NewHDU, infptr, outfptr, AllowedSystemMemory);
                break;
            case DOUBLE_IMG:
                CopyImageData<double>(OldHDU, *NewHDU, infptr, outfptr, AllowedSystemMemory);
                break;
            default:
                cerr << "Unknown HDU type encountered: " << bitpix << endl;
        }

    }




}
예제 #3
0
파일: table.hpp 프로젝트: Plaristote/crails
 Table& column(const std::string& name, ColumnCallback callback) { _columns.push_back(std::pair<std::string, ColumnCallback>(name, callback)); return *this; }