void SamFile::init(const char* filename, OpenType mode, SamFileHeader* header) { init(); resetFile(); bool openStatus = true; if(mode == READ) { // open the file for read. openStatus = OpenForRead(filename, header); } else { // open the file for write. openStatus = OpenForWrite(filename, header); } if(!openStatus) { // Failed to open the file - print error and abort. fprintf(stderr, "%s\n", GetStatusMessage()); std::cerr << "FAILURE - EXITING!!!" << std::endl; exit(-1); } }
bool Create(const std::string &suffix) { std::error_code ec; m_ptempFilePath = fs::temp_file_path(suffix, ec); if (ec) return false; if (m_ptempFilePath.empty()) return false; OpenForWrite(m_ptempFilePath.c_str(), true); return true; }
//************************************************************************* // // TheBard is a sample application that configures a BitFunnel index based // on a small corpus of 154 Shakespeare sonnets. This standalone example // performs an end-to-end configuration, including corpus statistics // analysis and TermTable construction. // // The sonnets are incorporated into the codebase as cstrings, allowing the // example to run without touching the filesystem. // //************************************************************************* void Run(bool verbose) { // // This example uses the RAM filesystem. // auto fileSystem = BitFunnel::Factories::CreateRAMFileSystem(); auto fileManager = BitFunnel::Factories::CreateFileManager( "config", "statistics", "index", *fileSystem); // // Initialize RAM filesystem with input files. // { std::cout << "Initializing RAM filesystem." << std::endl; // Open the manifest file. auto manifest = fileSystem->OpenForWrite("manifest.txt"); // Iterate over sequence of Shakespeare sonnet chunk data. for (size_t i = 0; i < Sonnets::chunks.size(); ++i) { // Create chunk file name, and write chunk data. std::stringstream name; name << "sonnet" << i; auto out = fileSystem->OpenForWrite(name.str().c_str()); // TODO: consider checking for cast overflow? out->write(Sonnets::chunks[i].second, static_cast<std::streamsize>(Sonnets::chunks[i].first)); // Add chunk file to manifest. *manifest << name.str() << std::endl; } } // // Create the BitFunnelTool based on the RAM filesystem. // BitFunnel::BitFunnelTool tool(*fileSystem); // // Use the tool to run the statistics builder. // { std::cout << "Gathering corpus statistics." << std::endl; std::vector<char const *> argv = { "BitFunnel", "statistics", "manifest.txt", "config", "-text" }; std::stringstream ignore; std::ostream& out = (verbose) ? std::cout : ignore; tool.Main(std::cin, out, static_cast<int>(argv.size()), argv.data()); } // // Use the tool to run the TermTable builder. // { std::cout << "Building the TermTable." << std::endl; std::vector<char const *> argv = { "BitFunnel", "termtable", "config", "0.1", "PrivateSharedRank0ToN" }; std::stringstream ignore; std::ostream& out = (verbose) ? std::cout : ignore; auto result = tool.Main(std::cin, out, static_cast<int>(argv.size()), argv.data()); CHECK_EQ(result, 0) << "TermTableBuilder failed."; std::cout << "Index is now configured." << std::endl << std::endl; } // // Use the tool to run the REPL. // { std::vector<char const *> argv = { "BitFunnel", "repl", "config" }; tool.Main(std::cin, std::cout, static_cast<int>(argv.size()), argv.data()); } }