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

Class that provides means for writing to a DADA ring buffer. More...

#include <cheetah/psrdada/DadaWriteClient.h>

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

Public Member Functions

 DadaWriteClient (key_t key, NewSequenceCallback const &new_sequence_callback)
 Instatiate new DadaWriteClient. More...
 
 DadaWriteClient (DadaWriteClient const &)=delete
 
template<typename Iterator , typename DataType = typename std::iterator_traits<Iterator>::value_type>
void write (Iterator &begin, Iterator const &end)
 Write to the data ring buffer. More...
 
void new_sequence ()
 Start a new writing sequence in the buffer. More...
 
void write_eod ()
 : Write an EOD marker without writing a next header
 
- 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.
 

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 writing to a DADA ring buffer.

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

// To use the DadaWriteClient class, instantiate it with a shared memory key
key_t key = 0xadeadbee;
...
SigprocHeader header;
...
DadaWriteClient client(key, [](std::ostream& out){header.write(out)});
// Write data
std::vector<char> data(1024);
client.write<char>(data.begin(), data.end());

Definition at line 59 of file DadaWriteClient.h.

Constructor & Destructor Documentation

◆ DadaWriteClient()

ska::cheetah::psrdada::DadaWriteClient::DadaWriteClient ( key_t  key,
NewSequenceCallback const &  new_sequence_callback 
)

Instatiate new DadaWriteClient.

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

Upon instantiaton the DadaWriteClient instance will connect to the DADA buffer identified by the key and open a header block for writing, this header block is passed to the new_sequence_callback in the form of a std::ostream reference.

To end writing for the current sequence and start a new sequence, use the new_sequence method.

Definition at line 34 of file DadaWriteClient.cpp.

35  : DadaClientBase(key, "write_client")
36  , _new_sequence_callback(new_sequence_callback)
37  , _current_block(nullptr)
38  , _current_writer(nullptr)
39  , _locked(false)
40 {
41  lock();
42  new_sequence_impl();
43 }
DadaClientBase(key_t key, std::string const &logger_name)
Create a new basic DADA client instance.

Member Function Documentation

◆ new_sequence()

void ska::cheetah::psrdada::DadaWriteClient::new_sequence ( )

Start a new writing sequence in the buffer.

This call will insert and end-of-data marker into the ring buffer and invoke the new_sequence_callback with a std::ostream reference into the next header block.

Definition at line 51 of file DadaWriteClient.cpp.

52 {
53  reset();
54  new_sequence_impl();
55 }
Here is the call graph for this function:

◆ write()

template<typename Iterator , typename DataType >
void ska::cheetah::psrdada::DadaWriteClient::write ( Iterator &  begin,
Iterator const &  end 
)

Write to the data ring buffer.

Parameters
beginAn iterator pointing to the start of the sequence to write.
endAn iterator pointing to the end of the sequence to write.
Template Parameters
DataTypeThe data type to be written to the buffer.
IteratorThe iterator type.

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

Definition at line 35 of file DadaWriteClient.cpp.

36 {
37  PANDA_LOG_DEBUG << "Number of elements to write " << std::distance(begin,end);
38  while (begin != end)
39  {
40  if (!_current_writer)
41  {
42  acquire_data_block();
43  }
44  else if (_current_writer->full())
45  {
46  PANDA_LOG_DEBUG << "Current writer full, acquiring new writer instance";
47  acquire_data_block();
48  }
49  begin = _current_writer->write<typename std::remove_cv<DataType>::type>(begin, end);
50  }
51 }

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