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 | |
e10815f1 |
26 | #include <AliLog.h> |
27 | |
5ea08be4 |
28 | #ifdef USE_SMI |
29 | extern "C" { |
30 | #include <smirtl.h> |
31 | } |
32 | #endif |
33 | |
a197a4ce |
34 | #include "AliMDC.h" |
5ea08be4 |
35 | |
bf4fbefe |
36 | #ifdef __APPLE__ |
37 | // avoid loading pythia and pdf |
38 | #include <Hepevt.h> |
39 | HEPEVT_DEF HEPEVT; |
40 | #endif |
41 | |
24df3da7 |
42 | //______________________________________________________________________________ |
43 | static void AliMDCErrorHandler(int level, Bool_t abort, const char *location, |
44 | const char *msg) |
45 | { |
46 | // The default error handler function. It prints the message on stderr and |
47 | // if abort is set it aborts the application. Comapared to the default |
48 | // ROOT error handler this one also prints the date and time in front |
49 | // of each message. |
50 | |
51 | if (level < gErrorIgnoreLevel) |
52 | return; |
53 | |
54 | const char *type = 0; |
55 | |
56 | if (level >= kInfo) |
57 | type = "Info"; |
58 | if (level >= kWarning) |
59 | type = "Warning"; |
60 | if (level >= kError) |
61 | type = "Error"; |
62 | if (level >= kBreak) |
63 | type = "\n *** Break ***"; |
64 | if (level >= kSysError) |
65 | type = "SysError"; |
66 | if (level >= kFatal) |
67 | type = "Fatal"; |
68 | |
69 | TDatime dt; |
70 | |
71 | if (level >= kBreak && level < kSysError) |
72 | fprintf(stderr, "%s: %s %s\n", dt.AsSQLString(), type, msg); |
73 | else if (!location || strlen(location) == 0) |
74 | fprintf(stderr, "%s: %s: %s\n", dt.AsSQLString(), type, msg); |
75 | else |
76 | fprintf(stderr, "%s: %s in <%s>: %s\n", dt.AsSQLString(), type, location, |
77 | msg); |
78 | |
79 | fflush(stderr); |
80 | if (abort) { |
81 | fprintf(stderr, "aborting\n"); |
82 | fflush(stderr); |
83 | if (gSystem) { |
84 | gSystem->StackTrace(); |
85 | gSystem->Abort(); |
86 | } else |
87 | ::abort(); |
88 | } |
89 | } |
5ea08be4 |
90 | |
91 | #ifdef USE_SMI |
24df3da7 |
92 | static void SMI_handle_command() |
5ea08be4 |
93 | { |
94 | // Handle SMI commands |
95 | |
96 | char action[64], param[64]; |
97 | int n_params; |
98 | |
99 | smi_get_action(action, &n_params); |
100 | if (n_params >= 1) { |
101 | smi_get_par_value("PARAM", param); |
102 | } else { |
103 | strcpy(param, ""); |
104 | } |
105 | if (strcmp(action, "STOP") == 0) { |
a197a4ce |
106 | if (AliMDC::Instance()) AliMDC::Instance()->SetStopLoop(); |
5ea08be4 |
107 | } |
108 | smi_set_state("RUNNING"); |
109 | } |
110 | #endif |
111 | |
112 | //______________________________________________________________________________ |
113 | static void Usage(const char *prognam) |
114 | { |
115 | #ifdef USE_SMI |
e10815f1 |
116 | fprintf(stderr, "Usage: %s <sminame> <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n", |
5ea08be4 |
117 | prognam); |
118 | fprintf(stderr, " <sminame> = name used by SMI\n"); |
119 | #else |
e10815f1 |
120 | fprintf(stderr, "Usage: %s <dbsize> <tagdbsize> <filter> <compmode> [date_file]\n", |
5ea08be4 |
121 | prognam); |
122 | #endif |
123 | fprintf(stderr, " <dbsize> = maximum raw DB size (in bytes)\n"); |
124 | fprintf(stderr, " (precede by - to delete raw and tag databases on close)\n"); |
e10815f1 |
125 | fprintf(stderr, " <tagdbsize> = maximum tag DB size (in bytes, 0 for no tag DB)\n"); |
126 | fprintf(stderr, " (precede by - to switch off the run DB)\n"); |
127 | fprintf(stderr, " (precede by + to fill only the local run DB)\n"); |
128 | fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n"); |
5ea08be4 |
129 | fprintf(stderr, " <compmode> = compression level (see TFile)\n"); |
130 | fprintf(stderr, " (precede by - to use RFIO, -0 is RFIO and 0 compression)\n"); |
9174317d |
131 | fprintf(stderr, " (precede by + to use rootd, +0 is rootd and 0 compression)\n"); |
132 | fprintf(stderr, " (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n"); |
5ea08be4 |
133 | fprintf(stderr, " (precede by @ to use /dev/null as sink)\n"); |
5ea08be4 |
134 | fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n"); |
5ea08be4 |
135 | fprintf(stderr, " (precede with - for endless loop on same file (use SIGUSR1 to stop)\n"); |
136 | } |
137 | |
138 | //______________________________________________________________________________ |
139 | int main(int argc, char **argv) |
140 | { |
141 | // Convert a DATE data stream to a ROOT DB. |
142 | |
143 | // Set ROOT in batch mode |
144 | gROOT->SetBatch(); |
145 | |
24df3da7 |
146 | // Set custom error handler |
e10815f1 |
147 | AliLog::SetHandleRootMessages(kFALSE); |
24df3da7 |
148 | SetErrorHandler(AliMDCErrorHandler); |
149 | |
e10815f1 |
150 | // Default file system locations |
151 | #ifdef USE_EB |
152 | const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" }; |
153 | const char* tagDBFS = "/data1/mdc/tags"; |
154 | const char* runDBFS = "/data1/mdc/meta"; |
155 | const char* rfioFS = "rfio:/castor/cern.ch/lcg/dc5"; |
156 | const char* castorFS = "castor:/castor/cern.ch/lcg/dc5"; |
157 | #else |
158 | const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" }; |
159 | const char* tagDBFS = "/tmp/mdc1/tags"; |
160 | const char* runDBFS = "/tmp/mdc1/meta"; |
161 | TString user(gSystem->Getenv("USER")[0] + TString("/") + |
162 | gSystem->Getenv("USER")); |
163 | TString rfioStr("rfio:/castor/cern.ch/user/" + user); |
164 | const char* rfioFS = rfioStr.Data(); |
165 | TString castorStr("castor:/castor/cern.ch/user/" + user); |
166 | const char* castorFS = castorStr.Data(); |
167 | #endif |
168 | const char* rootdFS = "root://localhost//tmp/mdc1"; |
f07ec911 |
169 | // const char* alienHost = "alien://aliens7.cern.ch:15000/?direct"; |
170 | const char* alienHost = NULL; |
e10815f1 |
171 | const char* alienDir = "/alice_mdc/DC"; |
172 | |
173 | // User defined file system locations |
174 | if (gSystem->Getenv("ALIMDC_RAWDB1")) |
175 | rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1"); |
176 | if (gSystem->Getenv("ALIMDC_RAWDB2")) |
177 | rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2"); |
178 | if (gSystem->Getenv("ALIMDC_TAGDB")) |
179 | tagDBFS = gSystem->Getenv("ALIMDC_TAGDB"); |
180 | if (gSystem->Getenv("ALIMDC_RUNDB")) |
181 | runDBFS = gSystem->Getenv("ALIMDC_RUNDB"); |
182 | if (gSystem->Getenv("ALIMDC_RFIO")) |
183 | rfioFS = gSystem->Getenv("ALIMDC_RFIO"); |
184 | if (gSystem->Getenv("ALIMDC_CASTOR")) |
185 | castorFS = gSystem->Getenv("ALIMDC_CASTOR"); |
186 | if (gSystem->Getenv("ALIMDC_ROOTD")) |
187 | rootdFS = gSystem->Getenv("ALIMDC_ROOTD"); |
188 | if (gSystem->Getenv("ALIMDC_ALIENHOST")) |
189 | alienHost = gSystem->Getenv("ALIMDC_ALIENHOST"); |
190 | if (gSystem->Getenv("ALIMDC_ALIENDIR")) |
191 | alienDir = gSystem->Getenv("ALIMDC_ALIENDIR"); |
192 | |
193 | // Handle command line arguments |
5ea08be4 |
194 | if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) || |
e10815f1 |
195 | #ifdef USE_SMI |
196 | argc > 7 || argc < 6) { |
197 | #else |
5ea08be4 |
198 | argc > 6 || argc < 5) { |
e10815f1 |
199 | #endif |
5ea08be4 |
200 | Usage(argv[0]); |
201 | return 1; |
202 | } |
203 | |
e10815f1 |
204 | Int_t iarg = 1; |
205 | #ifdef USE_SMI |
5ea08be4 |
206 | char smiobj[128]; |
e10815f1 |
207 | strcpy(smiobj, argv[iarg]); |
5ea08be4 |
208 | smi_attach(smiobj, SMI_handle_command); |
209 | smi_volatile(); |
210 | smi_set_state("RUNNING"); |
e10815f1 |
211 | iarg++; |
5ea08be4 |
212 | #endif |
213 | |
9174317d |
214 | AliMDC::EWriteMode wmode = AliMDC::kLOCAL; |
e10815f1 |
215 | Int_t filterMode = 0; |
216 | Bool_t useLoop = kFALSE; |
5ea08be4 |
217 | Bool_t delFiles = kFALSE; |
e10815f1 |
218 | Bool_t rdbmsRunDB = kTRUE; |
219 | Int_t compress; |
5ea08be4 |
220 | Double_t maxFileSize; |
e10815f1 |
221 | Double_t maxTagSize; |
222 | const char* fs1 = NULL; |
223 | const char* fs2 = NULL; |
5ea08be4 |
224 | |
225 | // no special arg checking so don't make errors |
e10815f1 |
226 | if (argv[iarg][0] == '-') { |
5ea08be4 |
227 | delFiles = kTRUE; |
e10815f1 |
228 | maxFileSize = atoi(argv[iarg]+1); |
5ea08be4 |
229 | } else |
e10815f1 |
230 | maxFileSize = atoi(argv[iarg]); |
5ea08be4 |
231 | if (maxFileSize < 1000 || maxFileSize > 2.e9) { |
232 | Error(argv[0], "unreasonable file size %f\n", maxFileSize); |
233 | return 1; |
234 | } |
e10815f1 |
235 | iarg++; |
236 | |
237 | if (argv[iarg][0] == '-') { |
238 | runDBFS = NULL; |
239 | rdbmsRunDB = kFALSE; |
240 | alienHost = alienDir = NULL; |
241 | maxTagSize = atoi(argv[iarg]+1); |
242 | } else if (argv[iarg][0] == '+') { |
243 | rdbmsRunDB = kFALSE; |
244 | alienHost = alienDir = NULL; |
245 | maxTagSize = atoi(argv[iarg]+1); |
246 | } else |
247 | maxTagSize = atoi(argv[iarg]); |
248 | if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 2.e9)) { |
249 | Error(argv[0], "unreasonable tag file size %f\n", maxTagSize); |
250 | return 1; |
251 | } |
252 | if (maxTagSize == 0) tagDBFS = NULL; |
253 | iarg++; |
5ea08be4 |
254 | |
e10815f1 |
255 | filterMode = atoi(argv[iarg]); |
256 | if (filterMode < 0 || filterMode > 2) { |
257 | Error(argv[0], "unreasonable filter mode %d\n", filterMode); |
258 | return 1; |
259 | } |
260 | iarg++; |
5ea08be4 |
261 | |
e10815f1 |
262 | if (argv[iarg][0] == '-') { |
9174317d |
263 | wmode = AliMDC::kRFIO; |
e10815f1 |
264 | compress = atoi(argv[iarg]+1); |
265 | fs1 = rfioFS; |
266 | } else if (argv[iarg][0] == '+') { |
9174317d |
267 | wmode = AliMDC::kROOTD; |
e10815f1 |
268 | compress = atoi(argv[iarg]+1); |
269 | fs1 = rootdFS; |
270 | } else if (argv[iarg][0] == '%') { |
9174317d |
271 | wmode = AliMDC::kCASTOR; |
e10815f1 |
272 | compress = atoi(argv[iarg]+1); |
273 | fs1 = castorFS; |
274 | } else if (argv[iarg][0] == '@') { |
9174317d |
275 | wmode = AliMDC::kDEVNULL; |
e10815f1 |
276 | compress = atoi(argv[iarg]+1); |
277 | } else { |
278 | compress = atoi(argv[iarg]); |
279 | fs1 = rawDBFS[0]; |
280 | fs2 = rawDBFS[1]; |
281 | } |
5ea08be4 |
282 | if (compress > 9) { |
283 | Error(argv[0], "unreasonable compression mode %d\n", compress); |
284 | return 1; |
285 | } |
e10815f1 |
286 | iarg++; |
5ea08be4 |
287 | |
e10815f1 |
288 | char* file = NULL; |
289 | if (iarg < argc) { |
290 | file = argv[iarg]; |
291 | if (argv[iarg][0] == '-') { |
5ea08be4 |
292 | useLoop = kTRUE; |
e10815f1 |
293 | file = argv[iarg]+1; |
5ea08be4 |
294 | } |
295 | } |
296 | |
297 | // Create MDC processor object and process input stream |
e10815f1 |
298 | AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode), |
299 | runDBFS, rdbmsRunDB, alienHost, alienDir, |
300 | maxTagSize, tagDBFS); |
d67af9b1 |
301 | |
e10815f1 |
302 | Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2); |
d67af9b1 |
303 | |
304 | if (result == 0) |
305 | Info(argv[0], "normal termination of run"); |
306 | else |
307 | Error(argv[0], "error termination of run, status: %d", result); |
13d0d987 |
308 | return result; |
5ea08be4 |
309 | } |