DUNE-DAQ / iomanager

Package providing a unified API
0 stars 0 forks source link
dunedaq-common dunedaq-online dunedaq-team-core-sw

iomanager

A simplified API for passing messages between DAQModules

API Description

IOManager

Using IOManager from DAQModule code

Other Notes for Framework Developers

ConnectionId, Connection, & Queue

Receiver

Sender

API Diagram

Class Diagrams

Examples

Send

  // Int sender
  std::string uid = "bar";

  int msg = 5;
  std::chrono::milliseconds timeout(100);
  auto isender = IOManager::get()->get_sender<int>(uid);
  isender->send(msg, timeout);
  isender->send(msg, timeout);

  // One line send
  IOManager::get()->get_sender<int>(uid)->send(msg, timeout);

  // Send when timeouts may occur
  bool sent = isender->try_send(msg, timeout);

Receive (direct)

// String receiver
  std::string uid = "bar";

  auto receiver = IOManager::get()->get_receiver<std::string>(uid);
  std::string got;
  try {
    got = receiver->receive(timeout);
  } catch (dunedaq::appfwk::QueueTimeoutExpired&) {
    // Deal with exception
  }

  // Alternate API for when timeouts may be allowed
  std::optional<std::string> ret = receiver->try_receive(timeout);
  if(ret) TLOG() << "Received " << *ret;

Receive (callback)

  // Callback receiver
  std::string uid = "zyx";

  // CB function
  std::function<void(std::string)> str_receiver_cb = [&](std::string data) {
    std::cout << "Str receiver callback called with data: " << data << '\n';
  };

  auto cbrec = IOManager::get()->get_receiver<std::string>(uid);
  cbrec->add_callback(str_receiver_cb);
  try {
    got = cbrec->receive(timeout);
  } catch (dunedaq::iomanager::ReceiveCallbackConflict&) {
    // This is expected
  }
  IOManager::get()->remove_callback(uid);

When to use "try_" methods

The standard send() and receive() methods will throw an ERS exception if they time out. This is ideal for cases where timeouts are an exceptional condition (this applies to most, if not all send calls, for example). In cases where the timeout condition can be safely ignored (such as the callback-driving methods which are retrying the receive in a tight loop), the try_send and try_receive methods may be used. Note that these methods are not noexcept, any non-timeout issues will result in an ERS exception.

Updating existing code to use IOManager

Please see this page for information about updating your code to use IOManager. Also, if you are interested in using dynamic connection names, look at this page

APIs used by IOManager

The API used for queues is documented here. Network connections use IPM and NetworkManager