HPS-MC
merge_bunches.cc
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <string.h>
5 #include <stdhep_util.hh>
6 
11 int main(int argc,char** argv)
12 {
13  int nevhep;
14  vector<stdhep_entry> new_event;
15 
16  if (argc != 4)
17  {
18  printf("<input stdhep filename> <output stdhep filename> <number of events per event>\n");
19  return 1;
20  }
21  int n_events;
22  int istream = 0;
23  int ostream = 1;
24 
25  n_events = open_read(argv[1], istream);
26 
27  open_write(argv[2], ostream, n_events);
28 
29  int n_merge = atoi(argv[3]);
30  printf("Writing %d events per event\n", n_merge);
31 
32  nevhep = 0;
33 
34  while (true) {
35  for (int i = 0; i < n_merge; i++)
36  {
37  if (!read_next(istream)) {
38  close_read(istream);
39  close_write(ostream);
40  return(0);
41  }
42  read_stdhep(&new_event);
43  }
44 
45  write_stdhep(&new_event, nevhep+1);
46  write_file(ostream);
47  nevhep++;
48  }
49 }
50 
int main(int argc, char **argv)
void open_write(char *filename, int ostream, int n_events)
int open_read(char *filename, int istream, int n_events)
void write_stdhep(vector< stdhep_entry > *new_event, int nevhep)
Definition: stdhep_util.cpp:69
int read_stdhep(vector< stdhep_entry > *new_event)
Definition: stdhep_util.cpp:14
bool read_next(int istream)
void close_read(int istream)
void write_file(int ostream)
void close_write(int ostream)