#include "Event.h"

Event::Event( int n ):
  evNumber( n ),
  nPart( 0 ),
  nPMax( 10 ) {
  // allocate a buffer for particle pointers
  partList = new part_ptr[nPMax];
}


Event::~Event() {
  int i;
  // delete all the particle pointers
  for ( i = 0; i < nPart; ++i ) delete partList[i];
  // delete the pointers array
  delete[] partList;
}


void Event::add( float pt, float eta, float phi, int charge, int muonId ) {

  // if buffer is full move to a bigger one
  if ( nPart == nPMax ) {
    // double the available size
    nPMax *= 2;
    // allocate a new buffer
    part_ptr* partLNew = new part_ptr[nPMax];
    // copy particle pointers to the new buffer
    int i = 0;
    for ( i = 0; i < nPart; ++i ) partLNew[i] = partList[i];
    // delete the old buffer and rename the new one
    delete[] partList;
    partList = partLNew;
  }

  // create the new particle
  Particle* p = new Particle;
  p->pt     = pt;
  p->eta    = eta;
  p->phi    = phi;
  p->charge = charge;
  p->muonId = muonId;

  // store the new particle pointer and increase counter
  partList[nPart++] = p;

  return;

}

