#include <iostream>
#include <fstream>

#include "Event.h"

using namespace std;

const Event* read( ifstream& file ) {

  Event* ev;
  int i;
  // try to read input file
  if ( file.read( reinterpret_cast<char*>( &i ), sizeof( i ) ) )
    ev = new Event( i );
  else return 0;

  // read number of particles
  int n;
  file.read( reinterpret_cast<char*>( &n ), sizeof( n ) );
  // read and store data for particles
  int j;
  float pt;
  float eta;
  float phi;
  int charge;
  int muonId;
  for ( j = 0; j < n; ++j ) {
    file.read( reinterpret_cast<char*>( &pt     ), sizeof( pt     ) );
    file.read( reinterpret_cast<char*>( &eta    ), sizeof( eta    ) );
    file.read( reinterpret_cast<char*>( &phi    ), sizeof( phi    ) );
    file.read( reinterpret_cast<char*>( &charge ), sizeof( charge ) );
    file.read( reinterpret_cast<char*>( &muonId ), sizeof( muonId ) );
    ev->add( pt, eta, phi, charge, muonId );
  }

  return ev;

}

