]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/alimdc_main.cxx
New detector numbering scheme (common for DAQ/HLT/Offline). All the subdetectors...
[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 #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, "    (precede by - to switch off the run DB)\n");
126       fprintf(stderr, "    (precede by + to fill only the local run DB)\n");
127       fprintf(stderr, " <filter> = state of 3rd level filter (0: off, 1: transparent, 2: on)\n");
128       fprintf(stderr, " <compmode> = compression level (see TFile)\n");
129       fprintf(stderr, "    (precede by - to use RFIO, -0 is RFIO and 0 compression)\n");
130       fprintf(stderr, "    (precede by + to use rootd, +0 is rootd and 0 compression)\n");
131       fprintf(stderr, "    (precede by %% to use Castor/rootd, %%0 is Castor/rootd and 0 compression)\n");
132       fprintf(stderr, "    (precede by @ to use /dev/null as sink)\n");
133       fprintf(stderr, " [date_file] = optional input file (default reads from DATE EventBuffer)\n");
134       fprintf(stderr, "    (precede with - for endless loop on same file (use SIGUSR1 to stop)\n");
135 }
136
137 //______________________________________________________________________________
138 int main(int argc, char **argv)
139 {
140    // Convert a DATE data stream to a ROOT DB.
141
142    // Set ROOT in batch mode
143    gROOT->SetBatch();
144
145    // Set custom error handler
146    AliLog::SetHandleRootMessages(kFALSE);
147    SetErrorHandler(AliMDCErrorHandler);
148
149    // Default file system locations
150 #ifdef USE_EB
151    const char* rawDBFS[2] = { "/data1/mdc", "/data2/mdc" };
152    const char* tagDBFS    = "/data1/mdc/tags";
153    const char* runDBFS    = "/data1/mdc/meta";
154    const char* rfioFS     = "rfio:/castor/cern.ch/lcg/dc5";
155    const char* castorFS   = "castor:/castor/cern.ch/lcg/dc5";
156 #else
157    const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
158    const char* tagDBFS    = "/tmp/mdc1/tags";
159    const char* runDBFS    = "/tmp/mdc1/meta";
160    TString user(gSystem->Getenv("USER")[0] + TString("/") + 
161                 gSystem->Getenv("USER"));
162    TString rfioStr("rfio:/castor/cern.ch/user/" + user);
163    const char* rfioFS     = rfioStr.Data();
164    TString castorStr("castor:/castor/cern.ch/user/" + user);
165    const char* castorFS   = castorStr.Data();
166 #endif
167    const char* rootdFS    = "root://localhost//tmp/mdc1";
168    //   const char* alienHost  = "alien://aliens7.cern.ch:15000/?direct";
169    const char* alienHost  = NULL;
170    const char* alienDir   = "/alice_mdc/DC";
171
172    // User defined file system locations
173    if (gSystem->Getenv("ALIMDC_RAWDB1")) 
174      rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
175    if (gSystem->Getenv("ALIMDC_RAWDB2")) 
176      rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
177    if (gSystem->Getenv("ALIMDC_TAGDB")) 
178      tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
179    if (gSystem->Getenv("ALIMDC_RUNDB")) 
180      runDBFS = gSystem->Getenv("ALIMDC_RUNDB");
181    if (gSystem->Getenv("ALIMDC_RFIO")) 
182      rfioFS = gSystem->Getenv("ALIMDC_RFIO");
183    if (gSystem->Getenv("ALIMDC_CASTOR")) 
184      castorFS = gSystem->Getenv("ALIMDC_CASTOR");
185    if (gSystem->Getenv("ALIMDC_ROOTD")) 
186      rootdFS = gSystem->Getenv("ALIMDC_ROOTD");
187    if (gSystem->Getenv("ALIMDC_ALIENHOST")) 
188      alienHost = gSystem->Getenv("ALIMDC_ALIENHOST");
189    if (gSystem->Getenv("ALIMDC_ALIENDIR")) 
190     alienDir  = gSystem->Getenv("ALIMDC_ALIENDIR");
191
192    // Handle command line arguments
193    if ((argc == 2 && (!strcmp(argv[1], "-?") || !strcmp(argv[1], "-help"))) ||
194 #ifdef USE_SMI
195        argc > 7 || argc < 6) {
196 #else
197        argc > 6 || argc < 5) {
198 #endif
199       Usage(argv[0]);
200       return 1;
201    }
202
203    Int_t iarg = 1;
204 #ifdef USE_SMI
205    char smiobj[128];
206    strcpy(smiobj, argv[iarg]);
207    smi_attach(smiobj, SMI_handle_command);
208    smi_volatile();
209    smi_set_state("RUNNING");
210    iarg++;
211 #endif
212
213    AliMDC::EWriteMode wmode = AliMDC::kLOCAL;
214    Int_t    filterMode = 0;
215    Bool_t   useLoop = kFALSE;
216    Bool_t   delFiles = kFALSE;
217    Bool_t   rdbmsRunDB = kTRUE;
218    Int_t    compress;
219    Double_t maxFileSize;
220    Double_t maxTagSize;
221    const char* fs1 = NULL;
222    const char* fs2 = NULL;
223
224    // no special arg checking so don't make errors
225    if (argv[iarg][0] == '-') {
226       delFiles = kTRUE;
227       maxFileSize = atoi(argv[iarg]+1);
228    } else
229       maxFileSize = atoi(argv[iarg]);
230    if (maxFileSize < 1000 || maxFileSize > 2.e9) {
231       Error(argv[0], "unreasonable file size %f\n", maxFileSize);
232       return 1;
233    }
234    iarg++;
235
236    if (argv[iarg][0] == '-') {
237       runDBFS = NULL;
238       rdbmsRunDB = kFALSE;
239       alienHost = alienDir = NULL;
240       maxTagSize = atoi(argv[iarg]+1);
241    } else if (argv[iarg][0] == '+') {
242       rdbmsRunDB = kFALSE;
243       alienHost = alienDir = NULL;
244       maxTagSize = atoi(argv[iarg]+1);
245    } else
246       maxTagSize = atoi(argv[iarg]);
247    if (maxTagSize > 0 && (maxTagSize < 1000 || maxTagSize > 2.e9)) {
248       Error(argv[0], "unreasonable tag file size %f\n", maxTagSize);
249       return 1;
250    }
251    if (maxTagSize == 0) tagDBFS = NULL;
252    iarg++;
253
254    filterMode = atoi(argv[iarg]);
255    if (filterMode < 0 || filterMode > 2) {
256       Error(argv[0], "unreasonable filter mode %d\n", filterMode);
257       return 1;
258    }
259    iarg++;
260
261    if (argv[iarg][0] == '-') {
262       wmode = AliMDC::kRFIO;
263       compress = atoi(argv[iarg]+1);
264       fs1 = rfioFS;
265    } else if (argv[iarg][0] == '+') {
266       wmode = AliMDC::kROOTD;
267       compress = atoi(argv[iarg]+1);
268       fs1 = rootdFS;
269    } else if (argv[iarg][0] == '%') {
270       wmode = AliMDC::kCASTOR;
271       compress = atoi(argv[iarg]+1);
272       fs1 = castorFS;
273    } else if (argv[iarg][0] == '@') {
274       wmode = AliMDC::kDEVNULL;
275       compress = atoi(argv[iarg]+1);
276    } else {
277       compress = atoi(argv[iarg]);
278       fs1 = rawDBFS[0];
279       fs2 = rawDBFS[1];
280    }
281    if (compress > 9) {
282       Error(argv[0], "unreasonable compression mode %d\n", compress);
283       return 1;
284    }
285    iarg++;
286
287    char* file = NULL;
288    if (iarg < argc) {
289       file = argv[iarg];
290       if (argv[iarg][0] == '-') {
291          useLoop = kTRUE;
292          file = argv[iarg]+1;
293       }
294    }
295
296    // Create MDC processor object and process input stream
297    AliMDC mdcproc(compress, delFiles, AliMDC::EFilterMode(filterMode), 
298                   runDBFS, rdbmsRunDB, alienHost, alienDir, 
299                   maxTagSize, tagDBFS);
300
301    Int_t result = mdcproc.Run(file, useLoop, wmode, maxFileSize, fs1, fs2);
302
303    if (result == 0)
304       Info(argv[0], "normal termination of run");
305    else
306       Error(argv[0], "error termination of run, status: %d", result);
307    return result;
308 }