Пример #1
0
bool FileReader::ArchiveFiles(void)
{
#if PLATFORM == PLAT_WIN
  return WindowsRead();
#else
  return UnixRead();
#endif

}
Пример #2
0
/// Read the index contained in the file f.  This function always reads all
/// bitvectors.
int ibis::skive::read(const char* f) {
    std::string fnm;
    indexFileName(fnm, f);

    int fdes = UnixOpen(fnm.c_str(), OPEN_READONLY);
    if (fdes < 0) {
	LOGGER(ibis::gVerbose > 0)
	    << "Warning -- skive[" << col->partition()->name() << '.'
	    << col->name() << "]::read failed to open " << fnm;
	return -1; // can not do anything else
    }

    char header[8];
    IBIS_BLOCK_GUARD(UnixClose, fdes);
#if defined(_WIN32) && defined(_MSC_VER)
    (void)_setmode(fdes, _O_BINARY);
#endif
    int ierr = UnixRead(fdes, static_cast<void*>(header), 8);
    if (ierr != 8) {
	LOGGER(ibis::gVerbose > 0)
	    << "Warning -- skive[" << col->partition()->name() << '.'
	    << col->name() << "]::read failed to read 8 bytes from "
	    << fnm;
	return -2;
    }
    if (!(header[0] == '#' && header[1] == 'I' &&
	  header[2] == 'B' && header[3] == 'I' &&
	  header[4] == 'S' &&
	  (header[5] == static_cast<char>(ibis::index::SKIVE) ||
	   header[5] == static_cast<char>(ibis::index::SLICE)) &&
	  (header[6] == 8 || header[6] == 4) &&
	  header[7] == static_cast<char>(0))) {
	if (ibis::gVerbose > 0) {
	    ibis::util::logger lg;
	    lg() << "Warning -- skive[" << col->partition()->name() << '.'
		 << col->name() << "]::read the header from " << fnm << " (";
	    printHeader(lg(), header);
	    lg() << ") does not contain the expected values";
	}
	return -3;
    }

    uint32_t dim[3]; // nrows, nobs, card
    size_t begin, end;
    clear(); // clear the current content

    ierr = UnixRead(fdes, static_cast<void*>(dim), 3*sizeof(uint32_t));
    nrows = dim[0];
    // read vals
    begin = 8*((3*sizeof(uint32_t) + 15) / 8);
    end = begin + dim[2] * sizeof(double);
    {
	array_t<double> dbl(fnm.c_str(), fdes, begin, end);
	vals.swap(dbl);
    }
    // read the offsets
    begin = end;
    end += header[6] * (dim[1] + 1);
    ierr = initOffsets(fdes, header[6], begin, dim[1]);
    if (ierr < 0)
	return ierr;

    // cnts
    begin = end;
    end += sizeof(uint32_t) * dim[2];
    {
	array_t<uint32_t> szt(fnm.c_str(), fdes, begin, end);
	cnts.swap(szt);
    }
    ibis::fileManager::instance().recordPages(0, end);

    initBitmaps(fdes);
    activate();
    return 0;
} // ibis::skive::read