Commit 4cecf1b8 authored by Tobias Winchen's avatar Tobias Winchen
Browse files

Merged + Fixed unused return value error

parents 4252c7a9 875c4977
......@@ -34,4 +34,4 @@ ENDIF(NOT PSRDADA_FOUND)
LIST(APPEND PSRDADA_INCLUDE_DIR "${PSRDADA_INCLUDE_DIR}")
MARK_AS_ADVANCED(PSRDADA_LIBRARIES PSRDADA_TEST_LIBRARIES PSRDADA_INCLUDE_DIR)
\ No newline at end of file
MARK_AS_ADVANCED(PSRDADA_LIBRARIES PSRDADA_TEST_LIBRARIES PSRDADA_INCLUDE_DIR)
......@@ -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.
......@@ -90,7 +90,7 @@ int main(int argc, char** argv)
{
std::string filename = "beam" + std::to_string(ii) + ".fil";
files.emplace_back(std::make_shared<SimpleFileWriter>(filename));
}
}
meerkat::tuse::TransposeToDada<SimpleFileWriter> transpose(nbeams,std::move(files));
transpose.set_nsamples(nsamples);
transpose.set_nchans(nchans);
......@@ -109,7 +109,7 @@ int main(int argc, char** argv)
std::cerr << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit" << std::endl;
return ERROR_UNHANDLED_EXCEPTION;
}
return SUCCESS;
}
return SUCCESS;
}
......@@ -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
......@@ -58,53 +58,53 @@ public:
void set_ngroups(const int ngroups);
/**
* @brief Setter for frequency channels
*/
/**
* @brief Setter for frequency channels
*/
void set_nchans(const int nchans);
void set_nchans(const int nchans);
/**
* @brief Setter of number of time samples
*/
/**
* @brief Setter of number of time samples
*/
void set_nsamples(const int nsamples);
void set_nsamples(const int nsamples);
/**
* @brief Setter for number of frequency blocks
*/
/**
* @brief Setter for number of frequency blocks
*/
void set_nfreq(const int _nfreq);
void set_nfreq(const int _nfreq);
/**
* @brief getter for number of channels
*/
/**
* @brief getter for number of channels
*/
std::uint32_t nchans();
std::uint32_t nchans();
/**
* @brief getter for number of time samples
*/
/**
* @brief getter for number of time samples
*/
std::uint32_t nsamples();
std::uint32_t nsamples();
/**
* @brief getter for frequency blocks
*/
/**
* @brief getter for frequency blocks
*/
std::uint32_t nfreq();
std::uint32_t nfreq();
/**
*@brief: getter for ngroups
*/
/**
*@brief: getter for ngroups
*/
std::uint32_t ngroups();
std::uint32_t ngroups();
/**
*@brief: getter for nbeams
*/
/**
*@brief: getter for nbeams
*/
std::uint32_t nbeams();
std::uint32_t nbeams();
private:
std::uint32_t _numbeams;
......
#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;
}
......@@ -21,20 +21,20 @@ namespace psrdada_cpp
{
int len = str.size();
std::memcpy(ptr,(char*)&len,sizeof(len));
ptr += sizeof(len);
ptr += sizeof(len);
std::copy(str.begin(),str.end(),ptr);
ptr += len;
ptr += len;
}
void SigprocHeader::header_write(char*& ptr, std::string const& str, std::string const& name)
{
header_write(ptr,str);
header_write(ptr,name);
header_write(ptr,str);
header_write(ptr,name);
}
void SigprocHeader::write_header(RawBytes& block, PsrDadaHeader ph)
{
auto ptr = block.ptr();
auto ptr = block.ptr();
header_write(ptr,"HEADER_START");
header_write<std::uint32_t>(ptr,"telescope_id",0);
header_write<std::uint32_t>(ptr,"machine_id",11);
......@@ -44,8 +44,8 @@ namespace psrdada_cpp
// RA DEC
auto ra_val = ph.ra();
auto dec_val =ph.dec();
std::vector<std::string> ra_s;
std::vector<std::string> dec_s;
std::vector<std::string> ra_s;
std::vector<std::string> dec_s;
boost::split(ra_s,ra_val,boost::is_any_of(":"));
boost::split(dec_s,dec_val,boost::is_any_of(":"));
double ra = stod(boost::join(ra_s,""));
......@@ -65,7 +65,7 @@ namespace psrdada_cpp
std::size_t SigprocHeader::header_size() const
{
return _header_size;
return _header_size;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment