/* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
* This file is part of XPIR.
*
* XPIR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XPIR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XPIR. If not, see .
*/
#include "DBDirectoryProcessor.hpp"
/************************************************/
/* Default constructor : no splitting */
/* -> 1 input file -> 1 output stream */
/************************************************/
DBDirectoryProcessor::DBDirectoryProcessor() : filesSplitting(false) {
// TODO(feature) deal with sub-directories in the database !
directory=std::string(DEFAULT_DIR_NAME);
maxFileBytesize=0;
// Create the pool of ifstream
for(int i=0;id_name, ".") > 0 && strcmp(ent->d_name, ".."))
{
// Count processed files (one out of 2**7?)
if ((i << 25)==0) std::cout << "DBDirectoryProcessor: " << i+1 << " entries processed\r" << std::flush;i++;
// Add File object on the file list
std::string fileName= std::string( ent->d_name );
file_list.push_back( fileName );
uint64_t fileSize = getFileSize(directory + fileName);
if (fileSize > maxFileBytesize)
maxFileBytesize = fileSize;
}
}
std::cout << "DBDirectoryProcessor: " << i << " entries processed" << std::endl;
closedir (dir);
}
else // If there was a problem opening the directory
{
std::cout << "DBDirectoryProcessor: Error opening database directory" << std::endl;
}
std::cout << "DBDirectoryProcessor: The size of the database is " << maxFileBytesize*file_list.size() << " bytes" << std::endl;
std::cout << "DBDirectoryProcessor: The number of elements in the catalog is " << file_list.size() << std::endl;
}
// This constructor is called when we need File-splitting
DBDirectoryProcessor::DBDirectoryProcessor(uint64_t nbStreams) : filesSplitting(true) {
directory=std::string(DEFAULT_DIR_NAME);
maxFileBytesize=0;
// Create the pool of ifstream
for(int i=0;id_name == NULL || ent->d_type != DT_REG) {
ent = readdir (dir);
}
// Add File object on the file list
std::string fileName=directory + std::string( ent->d_name );
realFileName=fileName;
uint64_t realFileSize = getFileSize(realFileName);
maxFileBytesize = realFileSize/nbStreams;
if(maxFileBytesize==0) {
std::cout << "DBDirectoryProcessor: ERROR cannot split a file en less than one byte elements!" << std::endl;
std::cout << "DBDirectoryProcessor: file " << realFileName << " is only "<< realFileSize << " long" << std::endl;
exit(1);
}
closedir (dir);
for(int i=0;iopen( local_directory + file_list[streamNb], std::ios::binary );
is->seekg(requested_offset);
} else {
// But when we are doing file splitting, we just need to position the ifstream at the correct position
uint64_t splitting_offset=streamNb*getmaxFileBytesize();
is->open( realFileName, std::ios::binary );
is->seekg(splitting_offset + requested_offset);
}
return is;
}
uint64_t DBDirectoryProcessor::readStream(std::ifstream* s, char * buf, uint64_t size) {
uint64_t sizeRead=0;
//std::cout << "sizeRead = "<