AlcapDAQ  1
mucap_optimize.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <endian.h>
5 #include <byteswap.h>
6 #include "midas.h"
7 
8 #include "mucap_structures.h"
9 #include "mucap_compress.h"
10 
11 HNDLE hDB;
12 
13 int main(int argc, char *argv[])
14 {
15  char host_name[256], exp_name[32];
16 
17  cm_get_environment(host_name, sizeof(host_name), exp_name,
18  sizeof(exp_name));
19  cm_connect_experiment(host_name, exp_name, "Compression", NULL);
20  cm_get_experiment_database(&hDB, NULL);
21 
23 
24  if(argc != 2) {
25  printf("Usage: mucap_optimize uncompressed_input.mid\n");
26  exit(1);
27  }
28 
29  FILE *fp = fopen(argv[1], "r");
30  if (!fp) {
31  printf("Unable to open %s\n", argv[1]);
32  exit(1);
33  }
34 
35  char *input_event = new char[MAX_EVENT_SIZE];
36  char *output_event = new char[MAX_EVENT_SIZE];
37 
38  while (read_midas_event(fp, input_event) == SUCCESS) {
39  EVENT_HEADER header = *((EVENT_HEADER *) input_event);
40 
41  int event_id = header.event_id;
42 
43  if (event_id == EVENTID_BOR || event_id == EVENTID_EOR ||
44  event_id == EVENTID_MESSAGE) {
45 
46  continue;
47  }
48 
49  bk_init32(output_event);
50  compress_event(input_event + sizeof(EVENT_HEADER), output_event);
51  }
52 
54 
55  fclose(fp);
56 
57  cm_disconnect_experiment();
58 }