AlcapDAQ  1
Functions | Variables
mucap_compress.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <endian.h>
#include <byteswap.h>
#include "midas.h"
#include "mucap_structures.h"
#include "mucap_compress.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

HNDLE hDB
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 13 of file mucap_compress.cpp.

References cm_get_environment(), compress_event(), compress_load_all(), event_id, exp_name, hDB, host_name, printf(), read_midas_event(), and SUCCESS.

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, "mucap_compress", NULL);
20  cm_get_experiment_database(&hDB, NULL);
21 
23 
24  if(argc != 3) {
25  printf("Usage: mucap_compress uncompressed_input.mid compressed_output.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  FILE *output_fp = fopen(argv[2], "w");
36  if (!fp) {
37  printf("Unable to open %s\n", argv[2]);
38  exit(1);
39  }
40 
41  char *input_event = new char[MAX_EVENT_SIZE];
42  char *output_event = new char[MAX_EVENT_SIZE];
43 
44  while (read_midas_event(fp, input_event) == SUCCESS) {
45 
46  EVENT_HEADER header = *((EVENT_HEADER *) input_event);
47  int event_id = header.event_id;
48 
49  if (event_id == EVENTID_BOR || event_id == EVENTID_EOR ||
50  event_id == EVENTID_MESSAGE) {
51 
52  // For non-ordinary events, just write out the raw data
53  fwrite(input_event, 1, sizeof(EVENT_HEADER) + header.data_size,
54  output_fp);
55  } else {
56 
57  bk_init32(output_event);
58  compress_event(input_event + sizeof(EVENT_HEADER), output_event);
59  header.data_size = bk_size(output_event);
60 
61  fwrite(&header, sizeof(EVENT_HEADER), 1, output_fp);
62  fwrite(output_event, 1, header.data_size, output_fp);
63  }
64  }
65 
66  fclose(fp);
67  fclose(output_fp);
68 
69  cm_disconnect_experiment();
70 }

Variable Documentation

HNDLE hDB