#ifndef __JACOUSTICS__JSUPEREVTTOOLKIT__
#define __JACOUSTICS__JSUPEREVTTOOLKIT__

#include "JAcoustics/JModel.hh"
#include "JAcoustics/JEvt.hh"
#include "JAcoustics/JSuperEvt.hh"
#include "JAcoustics/JEvtToolkit.hh"


/**
 * \file
 *
 * Acoustic super event fit toolkit.
 * \author mdejong
 */
namespace JACOUSTICS {}
namespace JPP { using namespace JACOUSTICS; }

namespace JACOUSTICS {

  
  /**
   * Get model of detector.
   *
   * \param  evt           super event
   */
  template<>
  inline
  getModel::getModel(const JSuperEvt& evt) :
    getModel(static_cast<const JEvt&>(evt))
  {
    for (JSuperEvt::tx_type::const_iterator i = evt.tx.begin(); i != evt.tx.end(); ++i) {
      this->emission[JEKey(i->id,i->counter)] = JMODEL::JEmission(i->toe);
    }
  }


  /**
   * Auxiliary data structure to convert model to super event.
   */
  struct getSuperEvt :
    public JSuperEvt
  {
    /**
     * Constructor.
     *
     * \param  header        header
     * \param  model         model
     * \param  begin         begin of hit data
     * \param  end           end   of hit data
     */
    template<class T>
    getSuperEvt(const JHead&  header,
		const JModel& model,
		T             begin,
		T             end) :
      JSuperEvt(getEvt(header, model))
    {
      for (JModel::emission_type::const_iterator i = model.emission.begin(); i != model.emission.end(); ++i) {
	this->tx.push_back(JSuperEvt::tx_t(i->first.getID(), i->first.getCounter(), i->second.t1));
      }

      for (T i = begin; i != end; ++i) {
	this->rx.push_back(JSuperEvt::rx_t(i->getID(), i->getCounter(), i->getString(), i->getFloor(), i->getValue(), i->getWeight()));
      }
    }
  };
}

#endif