#include <string>
#include <iostream>
#include <iomanip>

#include "JDAQ/JDAQTimesliceIO.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JDAQ/JDAQSummarysliceIO.hh"

#include "JDAQ/JDAQTags.hh"
#include "JNet/JLigierObjectIterator.hh"

#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"


/**
 * \file
 *
 * Example program to test JNET::JLigierObjectIterator.
 * \author mdejong
 */
int main(int argc, char* argv[])
{
  using namespace std;
  using namespace JPP;
  using namespace KM3NETDAQ;

  int  port;
  int  backlog;
  int  debug;

  try {

    JParser<> zap("Example program to test receiving of objects as Ligier server.");

    zap['P'] = make_field(port);
    zap['q'] = make_field(backlog)  = 1024;
    zap['d'] = make_field(debug)    = 1;

    zap(argc, argv);
  }
  catch(const exception &error) {
    FATAL(error.what() << endl);
  }


  setDAQLongprint(debug >= debug_t);
  
  try {

    typedef JDAQEvent          data_type;

    JLigierObjectIterator<data_type> in(port, backlog);

    while (in.hasNext()) {

      data_type* p = in.next();

      if (debug < debug_t)
	NOTICE(p->getDAQHeader() << endl);
      else
	DEBUG(*p << endl);
    }
  }
  catch(const JSocketException& error) {
    ERROR(error.what() << endl);
  }
}