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