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