#include <string.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>

#include <TFile.h>
#include <TTree.h>
#include <TSystemDirectory.h>

#include "beammon.h"

using namespace std;

int main(int argc, char **argv)
{

  const char *dirname = "/mnt/g/HIT/time_aligned/20170508/pin/";
  const char *ext = ".root";
  gROOT->ProcessLine(".x lhcbStyle.C");

  TSystemDirectory dir(dirname, dirname);

  TList *files = dir.GetListOfFiles();
  if (files)
  {
    TSystemFile *file;
    TString fname;
    TIter next(files);

    while ((file = (TSystemFile *)next()))
    {
      fname = file->GetName();
      if (!file->IsDirectory() && fname.EndsWith(ext) && !fname.BeginsWith("SAVE"))
      {
        Beammon *mon = new Beammon();

        printf("File name: %s \n", fname.Data());
        mon->Initialize(dirname, fname.Data(), 10000, 10000, 1., true, 1000., 100.);
        mon->Save();

        delete mon;
      }
    }
  }
  return 0;
}