]>
Commit | Line | Data |
---|---|---|
5ea08be4 | 1 | // @(#)alimdc:$Name$:$Id$ |
2 | // Author: Fons Rademakers 26/11/99 | |
3 | ||
4 | ////////////////////////////////////////////////////////////////////////// | |
5 | // // | |
6 | // alimdc // | |
7 | // // | |
8 | // Main program used to create application that reads a data stream // | |
9 | // from the DATE DAQ system and that creates a ROOT database. // | |
10 | // // | |
11 | // Written by: Fons Rademakers, 1/4/99. // | |
12 | // // | |
13 | ////////////////////////////////////////////////////////////////////////// | |
14 | ||
15 | #include <sys/types.h> | |
16 | #include <sys/stat.h> | |
17 | #include <unistd.h> | |
18 | #include <stdlib.h> | |
19 | #include <fcntl.h> | |
20 | #include <errno.h> | |
21 | ||
22 | #include <TROOT.h> | |
23 | #include <TSystem.h> | |
24 | #include <TError.h> | |
25 | ||
26 | #ifdef USE_SMI | |
27 | extern "C" { | |
28 | #include <smirtl.h> | |
29 | } | |
30 | #endif | |
31 | ||
32 | #include "AliRawEvent.h" | |
33 | ||
34 | ||
35 | #ifdef USE_SMI | |
36 | void SMI_handle_command() | |
37 | { | |
38 | // Handle SMI commands | |
39 | ||
40 | char action[64], param[64]; | |
41 | int n_params; | |
42 | ||
43 | smi_get_action(action, &n_params); | |
44 | if (n_params >= 1) { | |
45 | smi_get_par_value("PARAM", param); | |
46 | } else { | |
47 | strcpy(param, ""); | |
48 | } | |
49 | if (strcmp(action, "STOP") == 0) { | |
50 | gAliMDC->StopLoop(); | |
51 | } | |
52 | smi_set_state("RUNNING"); | |
53 | } | |
54 | #endif | |
55 | ||
56 | //______________________________________________________________________________ | |
57 | static void Usage(const char *prognam) | |
58 | { | |
59 | #ifdef USE_SMI | |
60 | fprintf(stderr, "Usage: %s <sminame> <dbsize> <filter> <compmode> [date_file]\n", | |
61 | prognam); | |
62 | fprintf(stderr, " <sminame> = name used by SMI\n"); | |
63 | #else | |
64 | fprintf(stderr, "Usage: %s <dbsize> <filter> <compmode> [date_file]\n", | |
65 | prognam); | |
66 | #endif | |
67 | fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n"); | |
68 | fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n"); | |
69 | fprintf(stderr, " <filter> = state of 3rd level filter (0 or 1)\n"); | |
70 | fprintf(stderr, " <compmode> = compression level (see TFile)\n"); | |
71 | fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n"); | |
72 | fprintf(stderr, " (precede by + to use rootd, -0 is rootd and 0 compression)\n"); | |
73 | fprintf(stderr, " (precede by @ to use /dev/null as sink)\n"); | |
74 | #ifdef USE_EB | |
75 | fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n"); | |
76 | #else | |
77 | fprintf(stderr, " [date_file] = optional input file (default reads from pipe /tmp/alimdc.fifo)\n"); | |
78 | #endif | |
79 | fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n"); | |
80 | } | |
81 | ||
82 | //______________________________________________________________________________ | |
83 | int main(int argc, char **argv) | |
84 | { | |
85 | // Convert a DATE data stream to a ROOT DB. | |
86 | ||
87 | // Set ROOT in batch mode | |
88 | gROOT->SetBatch(); | |
89 | ||
90 | #ifdef USE_SMI | |
91 | // Handle command line arguments | |
92 | if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || | |
93 | argc > 6 || argc < 5) { | |
94 | Usage(argv[0]); | |
95 | return 1; | |
96 | } | |
97 | ||
98 | char smiobj[128]; | |
99 | strcpy(smiobj, argv[1]); | |
100 | smi_attach(smiobj, SMI_handle_command); | |
101 | smi_volatile(); | |
102 | smi_set_state("RUNNING"); | |
103 | ||
104 | for (int i = 1; i < argc-1; i++) | |
105 | argv[i] = argv[i+1]; | |
106 | argc--; | |
107 | ||
108 | #else | |
109 | // Handle command line arguments | |
110 | if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || | |
111 | argc > 5 || argc < 4) { | |
112 | Usage(argv[0]); | |
113 | return 1; | |
114 | } | |
115 | #endif | |
116 | ||
117 | Bool_t useRFIO = kFALSE, useROOTD = kFALSE, useDEVNULL = kFALSE; | |
118 | Bool_t useFilter = kFALSE, useLoop = kFALSE; | |
119 | Bool_t delFiles = kFALSE; | |
120 | Int_t fd = -1, compress; | |
121 | Double_t maxFileSize; | |
122 | ||
123 | // no special arg checking so don't make errors | |
124 | if (argv[1][0] == '-') { | |
125 | delFiles = kTRUE; | |
126 | maxFileSize = atoi(argv[1]+1); | |
127 | } else | |
128 | maxFileSize = atoi(argv[1]); | |
129 | if (maxFileSize < 1000 || maxFileSize > 2.e9) { | |
130 | Error(argv[0], "unreasonable file size %f\n", maxFileSize); | |
131 | return 1; | |
132 | } | |
133 | ||
134 | int filter = atoi(argv[2]); | |
135 | if (filter != 0) | |
136 | useFilter = kTRUE; | |
137 | ||
138 | if (argv[3][0] == '-') { | |
139 | useRFIO = kTRUE; | |
140 | compress = atoi(argv[3]+1); | |
141 | } else if (argv[3][0] == '+') { | |
142 | useROOTD = kTRUE; | |
143 | compress = atoi(argv[3]+1); | |
144 | } else if (argv[3][0] == '@') { | |
145 | useDEVNULL = kTRUE; | |
146 | compress = atoi(argv[3]+1); | |
147 | } else | |
148 | compress = atoi(argv[3]); | |
149 | if (compress > 9) { | |
150 | Error(argv[0], "unreasonable compression mode %d\n", compress); | |
151 | return 1; | |
152 | } | |
153 | ||
154 | if (argc == 5) { | |
155 | char *file = argv[4]; | |
156 | if (argv[4][0] == '-') { | |
157 | useLoop = kTRUE; | |
158 | file = argv[4]+1; | |
159 | } | |
160 | if ((fd = open(file, O_RDONLY)) == -1) { | |
161 | Error(argv[0], "cannot open input file %s", argv[4]); | |
162 | return 1; | |
163 | } | |
164 | } | |
165 | ||
166 | // Create MDC processor object and process input stream | |
167 | AliMDC mdcproc(fd, compress, maxFileSize, useFilter, useRFIO, useROOTD, | |
168 | useDEVNULL, useLoop, delFiles); | |
169 | ||
170 | #ifdef USE_DEBUG | |
171 | mdcproc.SetDebugLevel(3); | |
172 | #endif | |
173 | ||
174 | return mdcproc.Run(); | |
175 | } |