HPS-MC
 
Loading...
Searching...
No Matches
merge_files.cc
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <stdhep_util.hh>
6
10int main(int argc, char** argv)
11{
12 vector<stdhep_entry> new_event;
13
14 if (argc < 3)
15 {
16 printf("<input stdhep filenames> <output stdhep filename>\n");
17 return 1;
18 }
19 int n_events = 500000;
20
21 int n_inputs = argc - 2;
22 for (int i = 0; i < n_inputs; i++) {
23 open_read(argv[i+1], i);
24 }
25
26 int ostream = n_inputs;
27 open_write(argv[argc-1], ostream, n_events);
28
29 int nevhep = 1;
30 bool end_of_files = false;
31
32 while (true) {
33 for (int i = 0; i < n_inputs; i++)
34 {
35 if (!read_next(i)) {
36 printf("End of file %s\n", argv[i+1]);
37 close_read(i);
38 if (!end_of_files && i != 0) {
39 printf("fail; %s has fewer events than %s\n", argv[i+1], argv[1]);
40 }
41 end_of_files = true;
42 }
43 else {
44 if (end_of_files) {
45 printf("fail; %s has too many events\n", argv[i+1]);
46 }
47 int new_nevhep = read_stdhep(&new_event);
48 if (nevhep != new_nevhep) printf("Expected nevhep = %d, got %d in file %s\n", nevhep, new_nevhep, argv[i+1]);
49 }
50 }
51
52 if (end_of_files) {
53 close_write(ostream);
54 return(0);
55 }
56
57 write_stdhep(&new_event,nevhep);
58 write_file(ostream);
59 nevhep++;
60 }
61}
62
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)
int read_stdhep(vector< stdhep_entry > *new_event)
bool read_next(int istream)
void close_read(int istream)
void write_file(int ostream)
void close_write(int ostream)