#include "DFInterface.hh"
#include "log.hh"

/**
 * \author cpellegrino
 */

void DFInterface::operator ()()
{
  Frame frame;

  while (isRunning())
  {
    // wait for and get data
    m_farm.getFrame(frame);

    if (frame.size()) {

      benchmark::chrono_set(frame);

      #ifdef DEBUG_DAQ_HEADER
      DAQHeaderPrinter const daq_head(frame.data());
      LOG_DEBUG << "DFInterface: Got this from the queue " << daq_head;
      #endif

      if (!frame.getNItems())
      {
        DAQHeaderPrinter const daq_head(frame.data());
        LOG_NOTICE << "DFInterface: No data to transmit: " << daq_head;
        continue;
      }

      #ifdef DEBUG_FRAME_LENGHT
      static unsigned int nframes = 0;
      ++nframes;
      if (!(nframes % 10000))
      {
        LOG_DEBUG << "DFInterface: FrameLenght(): " << frame.getFrameLength();
      }
      #endif

      m_recipients.send(frame);

      benchmark::chrono_set(frame);
      benchmark::chrono_dump(frame);
    }
  }
}