int OutCoreInterp::update(double data_x, double data_y, double data_z)
{

    int fileNum;

    //fileNum = upper_grid_y / local_grid_size_y;
    if((fileNum = findFileNum(data_y)) < 0)
        {
            cout << "OutCoreInterp::update() findFileNum() error!" << endl;
            cout << "data_x: " << data_x << " data_y: " << data_y << " grid_y: " << (int)(data_y/GRID_DIST_Y) << " fileNum: " << fileNum << " open file: " << openFile << endl;
            return -1;
        }

    if(openFile == fileNum)
        {
            // write into memory;
            updateInterpArray(fileNum, data_x, data_y, data_z);

        }else{
	UpdateInfo ui(data_x, data_y, data_z);
	qlist[fileNum].push_back(ui);

	if(qlist[fileNum].size() == QUEUE_LIMIT)
	    {
		//cout << "erase" << endl;
		if(openFile != -1)
		    {
			// if we use mmap and write directly into disk, no need this step.
			// munmap would be enough for this step..

			// write back to disk
			gridMap[openFile]->getGridFile()->unmap();
			openFile = -1;
		    }
		// upload from disk to memory
		gridMap[fileNum]->getGridFile()->map();
		openFile = fileNum;

		// pop every update information
		list<UpdateInfo>::const_iterator iter;

		for(iter = qlist[openFile].begin(); iter!= qlist[openFile].end(); iter++){ 
		    updateInterpArray(openFile, (*iter).data_x, (*iter).data_y, (*iter).data_z);
		}
		// flush
		qlist[openFile].erase(qlist[openFile].begin(), qlist[openFile].end());
	    }
    }

    return 0;
}
Example #2
0
int OutCoreInterp::update(double data_x, double data_y, double data_z)
{
    // update()
    //	push the point info into an appropriate queue
    //	if the length of the queue exceeds a limit,
    //	then
    //		if another file is loaded, write back (lazy update)
    //		if the file we need has not opened,
    //			read a file from disk
    //		update the file (PROC1)

    //
    // find which file should be updated

    /*
      if(data_x < 0){
      cout << "4. !!!! " << data_x << endl;
      return -1;
      }
    */

    int fileNum;

    //fileNum = upper_grid_y / local_grid_size_y;
    if((fileNum = findFileNum(data_y)) < 0)
    {
        cerr << "OutCoreInterp::update() findFileNum() error!" << endl;
        cerr << "data_x: " << data_x << " data_y: " << data_y << " grid_y: " << (int)(data_y/GRID_DIST_Y) << " fileNum: " << fileNum << " open file: " << openFile << endl;
        return -1;
    }

    if(openFile == fileNum)
    {
        // write into memory;
        updateInterpArray(fileNum, data_x, data_y, data_z);

    } else {
        UpdateInfo ui(data_x, data_y, data_z);
        qlist[fileNum].push_back(ui);

        if(qlist[fileNum].size() == QUEUE_LIMIT)
        {
            //cout << "erase" << endl;
            if(openFile != -1)
            {
                // if we use mmap and write directly into disk, no need this step.
                // munmap would be enough for this step..

                // write back to disk
                gridMap[openFile]->getGridFile()->unmap();
                openFile = -1;
            }
            // upload from disk to memory
            gridMap[fileNum]->getGridFile()->map();
            openFile = fileNum;

            // pop every update information
            list<UpdateInfo>::const_iterator iter;

            for(iter = qlist[openFile].begin(); iter!= qlist[openFile].end(); iter++) {
                updateInterpArray(openFile, (*iter).data_x, (*iter).data_y, (*iter).data_z);
            }
            // flush
            qlist[openFile].erase(qlist[openFile].begin(), qlist[openFile].end());
        }
    }

    return 0;
}