Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Public Member Functions | Protected Member Functions | List of all members
ska::cheetah::psrdada::DadaReadClient Class Reference

Class that provides means for reading from a DADA ring buffer. More...

#include <cheetah/psrdada/DadaReadClient.h>

Inheritance diagram for ska::cheetah::psrdada::DadaReadClient:
Inheritance graph
Collaboration diagram for ska::cheetah::psrdada::DadaReadClient:
Collaboration graph

Public Member Functions

 DadaReadClient (key_t key, panda::Engine &engine, NextSequenceCallback const &next_sequence_callback)
 Instatiate new DadaReadClient. More...
 
 DadaReadClient (DadaReadClient const &)=delete
 
template<typename Iterator , typename DataType = typename std::iterator_traits<Iterator>::value_type>
Iterator & read (Iterator &begin, Iterator const &end)
 Read from the data ring buffer. More...
 
void next_sequence ()
 Move to the next sequence in the ring buffer. More...
 
template<typename CallBackFunctor >
void next_sequence (CallBackFunctor callback)
 Move to the next sequence in the ring buffer. More...
 
void stop ()
 
std::shared_ptr< bool > stopped () const
 
void start ()
 
- Public Member Functions inherited from ska::cheetah::psrdada::DadaClientBase
 DadaClientBase (key_t key, std::string const &logger_name)
 Create a new basic DADA client instance. More...
 
 DadaClientBase (DadaClientBase const &)=delete
 
std::size_t data_buffer_size () const
 Get the sizes of each data block in the ring buffer.
 
std::size_t header_buffer_size () const
 Get the sizes of each header block in the ring buffer.
 
std::size_t data_buffer_count () const
 Get the number of data blocks in the ring buffer.
 
std::size_t header_buffer_count () const
 Get the number of header blocks in the ring buffer.
 
void connect ()
 Connect to ring buffer.
 
void disconnect ()
 Disconnect from ring buffer.
 
void reconnect ()
 Reconnect to the ring buffer.
 
std::string const & id () const
 Return a string identifier based on the buffer key and log name.
 

Protected Member Functions

template<typename CallBack >
void do_next_sequence (std::shared_ptr< bool > destructor_flag, CallBack callback)
 

Additional Inherited Members

- Protected Attributes inherited from ska::cheetah::psrdada::DadaClientBase
key_t _key
 
dada_hdu_t * _hdu
 
bool _connected
 
detail::MultiLog _log
 
std::string _id
 

Detailed Description

Class that provides means for reading from a DADA ring buffer.

This class provides reader-like access to a ring of DADA HDU memory buffers.

// To use the DadaReadClient class, instantiate it with a shared memory key
key_t key = 0xadeadbee;
...
SigprocHeader header;
...
DadaReadClient client(key, [](std::istream& in){header.read(in)});
// Read data
std::vector<char> data(1024);
client.read<char>(data.begin(), data.end());

Definition at line 61 of file DadaReadClient.h.

Constructor & Destructor Documentation

◆ DadaReadClient()

ska::cheetah::psrdada::DadaReadClient::DadaReadClient ( key_t  key,
panda::Engine &  engine,
NextSequenceCallback const &  next_sequence_callback 
)

Instatiate new DadaReadClient.

Parameters
[in]keyHexidecimal key to DADA shared memory block
next_sequence_callbackA callback to be called on the start of each subsequent sequence in the DADA buffer.

Upon instantiaton the DadaReadClient instance will connect to the DADA buffer identified by the key and open a header block for reading, this header block is passed to the next_sequence_callback in the form of a std::istream reference.

To end reading from the current sequence and start the next sequence, use the next_sequence method. This will flush all data in the buffer until an end-of-data marker is encountered, whereupon the next header block will be opened and passed to the next_sequence_callback.

Definition at line 52 of file DadaReadClient.cpp.

53  : DadaClientBase(key, "read_client")
54  , _next_sequence_callback(next_sequence_callback)
55  , _current_block(nullptr)
56  , _current_reader(nullptr)
57  , _locked(false)
58  , _engine(engine)
59  , _destructor_flag(std::make_shared<bool>(false))
60 {
61  lock();
62  //_engine.post(std::bind(&DadaReadClient::do_next_sequence<NextSequenceCallback>
63  //, this, _destructor_flag, _next_sequence_callback));
64 }
DadaClientBase(key_t key, std::string const &logger_name)
Create a new basic DADA client instance.

Member Function Documentation

◆ next_sequence() [1/2]

void ska::cheetah::psrdada::DadaReadClient::next_sequence ( )

Move to the next sequence in the ring buffer.

This will flush all data in the buffer until an end-of-data marker is encountered, whereupon the next header block will be opened and passed to the default next_sequence_callback as passed in the constructor.

Definition at line 95 of file DadaReadClient.cpp.

96 {
97  next_sequence(_next_sequence_callback);
98 }
void next_sequence()
Move to the next sequence in the ring buffer.
Here is the call graph for this function:

◆ next_sequence() [2/2]

template<typename CallBackFunctor >
void ska::cheetah::psrdada::DadaReadClient::next_sequence ( CallBackFunctor  callback)

Move to the next sequence in the ring buffer.

same as next_sequence() but will call the provided callback when a buffer becomes availabel instead of the default callback

Definition at line 58 of file DadaReadClient.cpp.

59 {
60  flush();
61  _engine.post(std::bind(&DadaReadClient::do_next_sequence<CallBackFunctor>,this,_destructor_flag, callback));
62 }
Here is the call graph for this function:

◆ read()

template<typename Iterator , typename DataType >
Iterator & ska::cheetah::psrdada::DadaReadClient::read ( Iterator &  begin,
Iterator const &  end 
)

Read from the data ring buffer.

Parameters
beginAn iterator pointing to the start of the sequence to read into.
endAn iterator pointing to the end of the sequence to read into.
Template Parameters
DataTypeThe data type to be read from the buffer.
IteratorThe iterator type.

Data will be cast to DataType upon reading from the buffer. It is the responsibility of the caller to ensure that this cast does not result in under or overflow.

Definition at line 36 of file DadaReadClient.cpp.

37 {
38  std::shared_ptr<bool> destructor_flag(_destructor_flag);
39  while (begin != end)
40  {
41  if(*destructor_flag)
42  {
43  return begin;
44  }
45  if (!_current_reader || _current_reader->empty())
46  {
47  if (!acquire_data_block())
48  {
49  return begin;
50  }
51  }
52  begin = _current_reader->read<DataType>(begin, end);
53  }
54  return begin;
55 }

The documentation for this class was generated from the following files: