Skip to content
Snippets Groups Projects
Commit 46506465 authored by Niclas Esser's avatar Niclas Esser
Browse files

Merge branch 'devel' into 'devel'

diskdb

See merge request !20
parents e340bb11 ae965fea
No related branches found
No related tags found
1 merge request!20diskdb
Pipeline #137008 passed
......@@ -78,7 +78,11 @@ target_link_libraries (dbreset ${PSRDADA_CPP_LIBRARIES})
#add_executable(dbdisk examples/dbdisk.cpp)
#target_link_libraries (dbdisk ${PSRDADA_CPP_LIBRARIES})
install (TARGETS junkdb dbnull syncdb dbreset fbfuse_output_db DESTINATION bin)
#diskdb
add_executable(diskdb examples/diskdb.cpp)
target_link_libraries (diskdb ${PSRDADA_CPP_LIBRARIES})
install (TARGETS junkdb dbnull syncdb dbreset fbfuse_output_db diskdb DESTINATION bin)
install (TARGETS ${CMAKE_PROJECT_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
......
#include "psrdada_cpp/multilog.hpp"
#include "psrdada_cpp/raw_bytes.hpp"
#include "psrdada_cpp/dada_output_stream.hpp"
#include "psrdada_cpp/cli_utils.hpp"
#include "boost/program_options.hpp"
#include <sys/types.h>
#include <iostream>
#include <string>
#include <ios>
#include <vector>
#include <fstream>
using namespace psrdada_cpp;
namespace
{
const size_t ERROR_IN_COMMAND_LINE = 1;
const size_t SUCCESS = 0;
const size_t ERROR_UNHANDLED_EXCEPTION = 2;
} // namespace
namespace psrdada_cpp
{
template <class Handler>
void diskdb(Handler& handler,
std::size_t header_size,
std::size_t block_size,
std::size_t nfile_read,
std::string header_file,
std::string data_file)
{
std::vector<char> header(header_size);
std::vector<char> data(block_size);
std::ifstream hinput;
std::ifstream dinput;
hinput.open(header_file, std::ios::in | std::ios::binary);
hinput.read(header.data(), header_size);
dinput.open(data_file, std::ios::in | std::ios::binary);
dinput.read(data.data(), block_size);
RawBytes header_bytes(header.data(), header_size, header_size, false);
handler.init(header_bytes);
for(std::size_t i = 0; i < nfile_read; i++)
{
RawBytes data_bytes(data.data(), block_size, block_size, false);
handler(data_bytes);
}
}
}
int main(int argc, char** argv)
{
try
{
std::size_t reads;
key_t key;
std::string header_file;
std::string data_file;
/** Define and parse the program options
*/
namespace po = boost::program_options;
po::options_description desc("Options");
desc.add_options()
("help,h", "Print help messages")
("data_file,d", po::value<std::string>(&data_file)->required(),"File containing the data to write to dada buffer")
("header_file,f", po::value<std::string>(&header_file)->required(), "Header file to write header block")
("reads,r", po::value<std::size_t>(&reads)->default_value(1), "Number of file reads")
("key,k", po::value<std::string>()->default_value("dada")->notifier([&key](std::string in){key = string_to_key(in);}),
"The shared memory key for the dada buffer to connect to (hex string)")
("log_level", po::value<std::string>()->default_value("info")->notifier([](std::string level){set_log_level(level);}),"The logging level to use (debug, info, warning, error)");
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
if ( vm.count("help") )
{
std::cout << "diskdb -- write file contents into DADA ring buffer" << std::endl
<< desc << std::endl;
return SUCCESS;
}
po::notify(vm);
}
catch(po::error& e)
{
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << desc << std::endl;
return ERROR_IN_COMMAND_LINE;
}
/**
* All the application code goes here
*/
MultiLog log("diskdb");
DadaOutputStream out_stream(key, log);
diskdb<decltype(out_stream)>(
out_stream, out_stream.client().header_buffer_size(),
out_stream.client().data_buffer_size(),
reads,
header_file,
data_file);
/**
* End of application code
*/
}
catch(std::exception& e)
{
std::cerr << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit" << std::endl;
return ERROR_UNHANDLED_EXCEPTION;
}
return SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment