Skip to content
Snippets Groups Projects
Commit 4cecf1b8 authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Merged + Fixed unused return value error

parents 4252c7a9 875c4977
No related branches found
No related tags found
No related merge requests found
Showing
with 1356 additions and 47 deletions
File changed. Contains only whitespace changes. Show whitespace changes.
......@@ -19,6 +19,7 @@ set(psrdada_cpp_src
src/simple_file_writer.cpp
src/sigprocheader.cpp
src/psrdadaheader.cpp
src/file_to_dada_cli.cpp
)
set(psrdada_cpp_inc
......@@ -38,6 +39,7 @@ set(psrdada_cpp_inc
sigprocheader.hpp
psrdadaheader.hpp
psrdada_to_sigproc_header.hpp
file_input_stream.hpp
)
# -- the main library target
......@@ -55,6 +57,11 @@ target_link_libraries (syncdb ${PSRDADA_CPP_LIBRARIES})
add_executable(fbfuse_output_db examples/fbfuse_output_db.cpp)
target_link_libraries (fbfuse_output_db ${PSRDADA_CPP_LIBRARIES})
#file_to_dada_cli
add_executable(file_to_dada src/file_to_dada_cli.cpp)
target_link_libraries (file_to_dada ${PSRDADA_CPP_LIBRARIES})
#dbnull
add_executable(dbnull examples/dbnull.cpp)
target_link_libraries (dbnull ${PSRDADA_CPP_LIBRARIES})
......
......
......@@ -23,9 +23,9 @@ namespace psrdada_cpp
RawBytes header(junk_header.data(),header_size,header_size,false);
handler.init(header);
std::size_t bytes_written = 0;
std::vector<char> junk_block(total_bytes,0);
std::vector<char> junk_block(nbytes_per_write,0);
srand(0);
for (std::uint32_t ii=0; ii < total_bytes; ++ii)
for (std::uint32_t ii=0; ii < nbytes_per_write; ++ii)
{
junk_block[ii] = rand()%255 + 1;
}
......
......
#include "psrdada_cpp/file_input_stream.hpp"
namespace psrdada_cpp {
template <class HandlerType>
FileInputStream<HandlerType>::FileInputStream(std::string fileName, std::size_t headersize, std::size_t nbytes, HandlerType& handler)
: _headersize(headersize)
, _nbytes(nbytes)
, _handler(handler)
, _stop(false)
, _running(false)
{
const char *filename = fileName.c_str();
_filestream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
_filestream.open(filename, std::ifstream::in | std::ifstream::binary);
if (!_filestream.is_open())
{
throw std::runtime_error("File could not be opened");
}
}
template <class HandlerType>
FileInputStream<HandlerType>::~FileInputStream()
{
_filestream.close();
}
template <class HandlerType>
void FileInputStream<HandlerType>::start()
{
if (_running)
{
throw std::runtime_error("Stream is already running");
}
_running = true;
// Get the header
char* header_ptr = new char[4096];
char* data_ptr = new char[_nbytes];
RawBytes header_block(header_ptr, 4096, 0, false);
_filestream.read(header_ptr, _headersize);
header_block.used_bytes(4096);
_handler.init(header_block);
// Continue to stream data until the end
while (!_stop)
{
BOOST_LOG_TRIVIAL(info) << "Reading data from the file";
// Read data from file here
RawBytes data_block(data_ptr, _nbytes, 0, false);
while (!_stop)
{
if (_filestream.eof())
{
BOOST_LOG_TRIVIAL(info) << "Reached end of file";
_filestream.close();
break;
}
_filestream.read(data_ptr, _nbytes);
data_block.used_bytes(data_block.total_bytes());
_handler(data_block);
}
data_block.~RawBytes();
}
_running = false;
}
template <class HandlerType>
void FileInputStream<HandlerType>::stop()
{
_stop = true;
}
} //psrdada_cpp
#ifndef PSRDADA_CPP_FILE_INPUT_STREAM_HPP
#define PSRDADA_CPP_FILE_INPUT_STREAM_HPP
#include <fstream>
#include <cstdlib>
#include "psrdada_cpp/raw_bytes.hpp"
/**
* @detail: A simple file input stream. Will go through one entire file.
* Will assume there is some amount of header to the file.
*/
namespace psrdada_cpp
{
template <class HandlerType>
class FileInputStream
{
public:
FileInputStream(std::string filename, std::size_t headersize, std::size_t nbytes, HandlerType& handler);
~FileInputStream();
void start();
void stop();
private:
std::size_t _headersize;
std::size_t _nbytes;
std::ifstream _filestream;
HandlerType& _handler;
bool _stop;
bool _running;
};
} //psrdada_cpp
#include "psrdada_cpp/detail/file_input_stream.cpp"
#endif //PSRDADA_CPP_FILE_INPUT_STREAM_HPP
......@@ -20,6 +20,11 @@ target_link_libraries (transpose_to_file_cli ${PSRDADA_CPP_MEERKAT_TUSE_LIBRARIE
#transpose_to_null_cli
add_executable(transpose_to_null_cli src/transpose_to_null_cli.cpp)
target_link_libraries (transpose_to_null_cli ${PSRDADA_CPP_MEERKAT_TUSE_LIBRARIES})
#dada_dbevent
add_executable(dada_dbevent src/dada_dbevent.cpp)
target_link_libraries (dada_dbevent ${PSRDADA_CPP_MEERKAT_TUSE_LIBRARIES})
install (TARGETS transpose_to_null_cli transpose_to_file_cli transpose_to_dada_cli DESTINATION bin)
install(FILES transpose_to_dada.hpp DESTINATION include/psrdada_cpp/meerkat/tuse)
add_subdirectory(test)
This diff is collapsed.
File changed. Contains only whitespace changes. Show whitespace changes.
......@@ -99,13 +99,13 @@ int main(int argc, char** argv)
{
nullsinks.emplace_back(std::make_shared<NullSink>());
}
meerkat::tuse::TransposeToDada<NullSink> transpose(nbeams,std::move(nullsinks));
transpose.set_nsamples(nsamples);
transpose.set_nchans(nchans);
transpose.set_nfreq(nfreq);
transpose.set_ngroups(ngroups);
transpose.set_nbeams(nbeams);
PsrDadaToSigprocHeader<decltype(transpose)> ptos(transpose);
MultiLog log1("instream");
DadaInputStream<decltype(ptos)> input(input_key,log1,ptos);
......
......
#ifndef PSRDADA_CPP_MEERKAT_TUSE_TRANSPOSETEST_H
#define PSRDADA_CPP_MEERKAT_TUSE_TRANSPOSETEST_H
#include "psrdada_cpp/meerkat/tuse/transpose_to_dada.hpp"
#include <gtest/gtest.h>
namespace psrdada_cpp {
namespace meerkat {
namespace tuse {
namespace test {
class TransposeTest: public ::testing::Test
{
protected:
void SetUp() override;
void TearDown() override;
public:
TransposeTest();
~TransposeTest();
};
} //namespace test
} //namespace tuse
} //namespace meerkat
} //namespace psrdada_cpp
#endif //PSRDADA_CPP_MEERKAT_TUSE_TRANSPOSETEST_H
#include "psrdada_cpp/meerkat/tuse/test/TransposeTest.h"
#include "psrdada_cpp/meerkat/tuse/transpose_to_dada.h"
namespace psrdada_cpp {
namespace meerkat {
namespace tuse {
namespace test {
TransposeTest::TransposeTest()
: ::testing::Test()
{
}
TransposeTest::~TransposeTest()
{
}
void TransposeTest::SetUp()
{
}
void TransposeTest::TearDown()
{
}
TEST_F(TransposeTest, test_attributes)
{
}
} //namespace test
} //namespace tuse
} //namespace meerkat
} //namespace psrdada_cpp
File changed. Contains only whitespace changes. Show whitespace changes.
#include "psrdada_cpp/cli_utils.hpp"
#include "psrdada_cpp/common.hpp"
#include "psrdada_cpp/file_input_stream.hpp"
#include "psrdada_cpp/dada_output_stream.hpp"
#include <memory>
#include <fstream>
#include "boost/program_options.hpp"
#include <ctime>
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
int main(int argc, char** argv)
{
try
{
key_t output_key;
std::size_t headersize;
std::size_t nbytes;
std::string filename;
/** Define and parse the program options
* */
namespace po = boost::program_options;
po::options_description desc("Options");
desc.add_options()
("output_key,k", po::value<std::string>()
->default_value("dada")
->notifier([&output_key](std::string in)
{
output_key = string_to_key(in);
}),
"The shared memory key for the output dada buffer to connect to (hex string)")
("help,h", "Print help messages")
("input_file,f", po::value<std::string>(&filename)->required(),
"Input file to read")
("nbytes,n", po::value<std::size_t>(&nbytes)->required(),
"Number of bytes to read in one DADA block")
("header_size,s", po::value<std::size_t>(&headersize)->required(),
"size of header to read");
/* Catch Error and program description */
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
if ( vm.count("help") )
{
std::cout << "Transpose2Dada -- read MeerKAT beamformed dada from DADA buffer, transpose per beam and write to an output DADA 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;
}
/* Application Code */
MultiLog log("outstream");
/* Setting up the pipeline based on the type of sink*/
DadaOutputStream outstream(output_key, log);
FileInputStream<decltype(outstream)> input(filename, headersize, nbytes, outstream);
input.start();
/* End 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;
}
File changed. Contains only whitespace changes. Show whitespace changes.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment